Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1997-07-23 |
2 | // Created by: Henri JEANNIN | |
3 | // Copyright (c) 1997-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. | |
7fd59977 | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
7fd59977 | 17 | #include <Standard_Stream.hxx> |
18 | ||
19 | #include <ViewerTest.hxx> | |
189f85a3 | 20 | #include <ViewerTest_CmdParser.hxx> |
1a96d253 | 21 | #include <ViewerTest_AutoUpdater.hxx> |
4e18052b | 22 | |
3a4a3962 | 23 | #include <Draw.hxx> |
7fd59977 | 24 | #include <TopLoc_Location.hxx> |
25 | #include <TopTools_HArray1OfShape.hxx> | |
26 | #include <TColStd_HArray1OfTransient.hxx> | |
b6d587e3 | 27 | #include <TColStd_SequenceOfAsciiString.hxx> |
900f7229 | 28 | #include <TColStd_HSequenceOfAsciiString.hxx> |
b6d587e3 | 29 | #include <TColStd_MapOfTransient.hxx> |
7fd59977 | 30 | #include <OSD_Timer.hxx> |
31 | #include <Geom_Axis2Placement.hxx> | |
32 | #include <Geom_Axis1Placement.hxx> | |
33 | #include <gp_Trsf.hxx> | |
34 | #include <TopExp_Explorer.hxx> | |
35 | #include <BRepAdaptor_Curve.hxx> | |
36 | #include <StdSelect_ShapeTypeFilter.hxx> | |
ad3217cd | 37 | #include <AIS_ColoredShape.hxx> |
7fd59977 | 38 | #include <AIS_InteractiveObject.hxx> |
39 | #include <AIS_Trihedron.hxx> | |
40 | #include <AIS_Axis.hxx> | |
7fd59977 | 41 | #include <AIS_TypeFilter.hxx> |
42 | #include <AIS_SignatureFilter.hxx> | |
43 | #include <AIS_ListOfInteractive.hxx> | |
44 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
99c56d44 | 45 | #include <Aspect_InteriorStyle.hxx> |
34db9c00 | 46 | #include <Aspect_Window.hxx> |
1a96d253 | 47 | #include <Aspect_XRSession.hxx> |
99c56d44 | 48 | #include <Graphic3d_AspectFillArea3d.hxx> |
1c88cbaf | 49 | #include <Graphic3d_AspectLine3d.hxx> |
a1954302 | 50 | #include <Graphic3d_CStructure.hxx> |
a6dee93d | 51 | #include <Graphic3d_Texture2Dmanual.hxx> |
cc8cbabe | 52 | #include <Graphic3d_GraphicDriver.hxx> |
98e6c6d1 | 53 | #include <Graphic3d_MediaTextureSet.hxx> |
692613e5 | 54 | #include <Image_AlienPixMap.hxx> |
23fe70ec | 55 | #include <Message.hxx> |
a6dee93d | 56 | #include <OSD_File.hxx> |
6262338c | 57 | #include <Prs3d_Drawer.hxx> |
99c56d44 | 58 | #include <Prs3d_ShadingAspect.hxx> |
1c88cbaf | 59 | #include <Prs3d_IsoAspect.hxx> |
6262338c | 60 | #include <Prs3d_PointAspect.hxx> |
1a96d253 | 61 | #include <PrsDim.hxx> |
62 | #include <PrsDim_Relation.hxx> | |
8e7c8ccf | 63 | #include <Select3D_SensitiveWire.hxx> |
8b9a309b | 64 | #include <Select3D_SensitivePrimitiveArray.hxx> |
73dc2d3a | 65 | #include <Select3D_SensitiveTriangulation.hxx> |
8e7c8ccf | 66 | #include <SelectMgr_EntityOwner.hxx> |
67 | #include <StdSelect_BRepOwner.hxx> | |
68 | #include <StdSelect_ViewerSelector3d.hxx> | |
cb78155f | 69 | #include <TopTools_MapOfShape.hxx> |
1a96d253 | 70 | #include <V3d_Viewer.hxx> |
7fd59977 | 71 | |
7fd59977 | 72 | #include <stdio.h> |
7fd59977 | 73 | |
74 | #include <Draw_Interpretor.hxx> | |
75 | #include <TCollection_AsciiString.hxx> | |
76 | #include <Draw_PluginMacro.hxx> | |
7fd59977 | 77 | |
7fd59977 | 78 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); |
79 | ||
7fd59977 | 80 | #include <Quantity_Color.hxx> |
81 | #include <Quantity_NameOfColor.hxx> | |
82 | ||
83 | #include <Graphic3d_NameOfMaterial.hxx> | |
84 | ||
6262338c | 85 | #define DEFAULT_COLOR Quantity_NOC_GOLDENROD |
86 | #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN | |
a966542b | 87 | #define DEFAULT_MATERIAL Graphic3d_NameOfMaterial_Brass |
7fd59977 | 88 | |
792c785c | 89 | //======================================================================= |
f9b30c0d | 90 | // function : GetColorFromName |
91 | // purpose : get the Quantity_NameOfColor from a string | |
792c785c | 92 | //======================================================================= |
7fd59977 | 93 | |
792c785c | 94 | Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName) |
95 | { | |
8316c618 | 96 | Quantity_NameOfColor aColor = DEFAULT_COLOR; |
97 | Quantity_Color::ColorFromName (theName, aColor); | |
98 | return aColor; | |
7fd59977 | 99 | } |
100 | ||
536d98e2 | 101 | //======================================================================= |
dae2a922 | 102 | // function : ParseColor |
f9b30c0d | 103 | // purpose : |
536d98e2 | 104 | //======================================================================= |
dae2a922 | 105 | Standard_Integer ViewerTest::ParseColor (const Standard_Integer theArgNb, |
f9b30c0d | 106 | const char* const* const theArgVec, |
dae2a922 | 107 | Quantity_ColorRGBA& theColor) |
536d98e2 | 108 | { |
dae2a922 | 109 | return Draw::ParseColor (theArgNb, theArgVec, theColor); |
110 | } | |
111 | ||
112 | //======================================================================= | |
113 | // function : ParseColor | |
114 | // purpose : | |
115 | //======================================================================= | |
116 | Standard_Integer ViewerTest::ParseColor (const Standard_Integer theArgNb, | |
117 | const char* const* const theArgVec, | |
118 | Quantity_Color& theColor) | |
119 | { | |
120 | return Draw::ParseColor (theArgNb, theArgVec, theColor); | |
536d98e2 | 121 | } |
122 | ||
a5565a3c | 123 | //======================================================================= |
124 | //function : ParseOnOff | |
125 | //purpose : | |
126 | //======================================================================= | |
127 | Standard_Boolean ViewerTest::ParseOnOff (Standard_CString theArg, | |
128 | Standard_Boolean& theIsOn) | |
129 | { | |
dae2a922 | 130 | return Draw::ParseOnOff (theArg, theIsOn); |
a5565a3c | 131 | } |
132 | ||
404c8936 | 133 | //======================================================================= |
134 | //function : GetSelectedShapes | |
135 | //purpose : | |
136 | //======================================================================= | |
137 | void ViewerTest::GetSelectedShapes (TopTools_ListOfShape& theSelectedShapes) | |
138 | { | |
139 | for (GetAISContext()->InitSelected(); GetAISContext()->MoreSelected(); GetAISContext()->NextSelected()) | |
140 | { | |
141 | TopoDS_Shape aShape = GetAISContext()->SelectedShape(); | |
142 | if (!aShape.IsNull()) | |
143 | { | |
144 | theSelectedShapes.Append (aShape); | |
145 | } | |
146 | } | |
147 | } | |
148 | ||
3a4a3962 | 149 | //======================================================================= |
150 | //function : ParseLineType | |
151 | //purpose : | |
152 | //======================================================================= | |
3f1675c9 | 153 | Standard_Boolean ViewerTest::ParseLineType (Standard_CString theArg, |
154 | Aspect_TypeOfLine& theType, | |
155 | uint16_t& thePattern) | |
3a4a3962 | 156 | { |
157 | TCollection_AsciiString aTypeStr (theArg); | |
158 | aTypeStr.LowerCase(); | |
3f1675c9 | 159 | if (aTypeStr == "empty" |
160 | || aTypeStr == "-1") | |
3a4a3962 | 161 | { |
162 | theType = Aspect_TOL_EMPTY; | |
3f1675c9 | 163 | thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType); |
3a4a3962 | 164 | } |
3f1675c9 | 165 | else if (aTypeStr == "solid" |
166 | || aTypeStr == "0") | |
3a4a3962 | 167 | { |
168 | theType = Aspect_TOL_SOLID; | |
3f1675c9 | 169 | thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType); |
3a4a3962 | 170 | } |
3f1675c9 | 171 | else if (aTypeStr == "dot" |
172 | || aTypeStr == "2") | |
3a4a3962 | 173 | { |
174 | theType = Aspect_TOL_DOT; | |
3f1675c9 | 175 | thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType); |
3a4a3962 | 176 | } |
3f1675c9 | 177 | else if (aTypeStr == "dash" |
178 | || aTypeStr == "1") | |
3a4a3962 | 179 | { |
180 | theType = Aspect_TOL_DASH; | |
3f1675c9 | 181 | thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType); |
3a4a3962 | 182 | } |
3f1675c9 | 183 | else if (aTypeStr == "dotdash" |
184 | || aTypeStr == "3") | |
3a4a3962 | 185 | { |
186 | theType = Aspect_TOL_DOTDASH; | |
3f1675c9 | 187 | thePattern = Graphic3d_Aspects::DefaultLinePatternForType (theType); |
3a4a3962 | 188 | } |
3f1675c9 | 189 | else |
3a4a3962 | 190 | { |
3f1675c9 | 191 | if (aTypeStr.StartsWith ("0x")) |
192 | { | |
193 | aTypeStr = aTypeStr.SubString (3, aTypeStr.Length()); | |
194 | } | |
195 | ||
196 | if (aTypeStr.Length() != 4 | |
197 | || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (1))) | |
198 | || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (2))) | |
199 | || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (3))) | |
200 | || !std::isxdigit (static_cast<unsigned char> (aTypeStr.Value (4)))) | |
3a4a3962 | 201 | { |
202 | return Standard_False; | |
203 | } | |
3f1675c9 | 204 | |
205 | std::stringstream aStream; | |
206 | aStream << std::setbase (16) << aTypeStr.ToCString(); | |
207 | if (aStream.fail()) | |
208 | { | |
209 | return Standard_False; | |
210 | } | |
211 | ||
212 | Standard_Integer aNumber = -1; | |
213 | aStream >> aNumber; | |
214 | if (aStream.fail()) | |
215 | { | |
216 | return Standard_False; | |
217 | } | |
218 | ||
219 | thePattern = (uint16_t )aNumber; | |
220 | theType = Graphic3d_Aspects::DefaultLineTypeForPattern (thePattern); | |
2a332745 | 221 | } |
3a4a3962 | 222 | return Standard_True; |
223 | } | |
224 | ||
33cc703b | 225 | //======================================================================= |
226 | //function : ParseMarkerType | |
227 | //purpose : | |
228 | //======================================================================= | |
229 | Standard_Boolean ViewerTest::ParseMarkerType (Standard_CString theArg, | |
230 | Aspect_TypeOfMarker& theType, | |
231 | Handle(Image_PixMap)& theImage) | |
232 | { | |
233 | theImage.Nullify(); | |
234 | TCollection_AsciiString aTypeStr (theArg); | |
235 | aTypeStr.LowerCase(); | |
236 | if (aTypeStr == "empty") | |
237 | { | |
238 | theType = Aspect_TOM_EMPTY; | |
239 | } | |
240 | else if (aTypeStr == "point" | |
241 | || aTypeStr == "dot" | |
242 | || aTypeStr == ".") | |
243 | { | |
244 | theType = Aspect_TOM_POINT; | |
245 | } | |
246 | else if (aTypeStr == "plus" | |
247 | || aTypeStr == "+") | |
248 | { | |
249 | theType = Aspect_TOM_PLUS; | |
250 | } | |
251 | else if (aTypeStr == "star" | |
252 | || aTypeStr == "*") | |
253 | { | |
254 | theType = Aspect_TOM_STAR; | |
255 | } | |
256 | else if (aTypeStr == "cross" | |
257 | || aTypeStr == "x") | |
258 | { | |
259 | theType = Aspect_TOM_X; | |
260 | } | |
261 | else if (aTypeStr == "circle" | |
262 | || aTypeStr == "o") | |
263 | { | |
264 | theType = Aspect_TOM_O; | |
265 | } | |
266 | else if (aTypeStr == "pointincircle") | |
267 | { | |
268 | theType = Aspect_TOM_O_POINT; | |
269 | } | |
270 | else if (aTypeStr == "plusincircle") | |
271 | { | |
272 | theType = Aspect_TOM_O_PLUS; | |
273 | } | |
274 | else if (aTypeStr == "starincircle") | |
275 | { | |
276 | theType = Aspect_TOM_O_STAR; | |
277 | } | |
278 | else if (aTypeStr == "crossincircle" | |
279 | || aTypeStr == "xcircle") | |
280 | { | |
281 | theType = Aspect_TOM_O_X; | |
282 | } | |
283 | else if (aTypeStr == "ring1") | |
284 | { | |
285 | theType = Aspect_TOM_RING1; | |
286 | } | |
287 | else if (aTypeStr == "ring2") | |
288 | { | |
289 | theType = Aspect_TOM_RING2; | |
290 | } | |
291 | else if (aTypeStr == "ring" | |
292 | || aTypeStr == "ring3") | |
293 | { | |
294 | theType = Aspect_TOM_RING3; | |
295 | } | |
296 | else if (aTypeStr == "ball") | |
297 | { | |
298 | theType = Aspect_TOM_BALL; | |
299 | } | |
300 | else if (aTypeStr.IsIntegerValue()) | |
301 | { | |
302 | const int aTypeInt = aTypeStr.IntegerValue(); | |
303 | if (aTypeInt < -1 || aTypeInt >= Aspect_TOM_USERDEFINED) | |
304 | { | |
305 | return Standard_False; | |
306 | } | |
307 | theType = (Aspect_TypeOfMarker )aTypeInt; | |
308 | } | |
309 | else | |
310 | { | |
311 | theType = Aspect_TOM_USERDEFINED; | |
312 | Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); | |
313 | if (!anImage->Load (theArg)) | |
314 | { | |
315 | return Standard_False; | |
316 | } | |
317 | if (anImage->Format() == Image_Format_Gray) | |
318 | { | |
319 | anImage->SetFormat (Image_Format_Alpha); | |
320 | } | |
321 | else if (anImage->Format() == Image_Format_GrayF) | |
322 | { | |
323 | anImage->SetFormat (Image_Format_AlphaF); | |
324 | } | |
325 | theImage = anImage; | |
326 | } | |
327 | return Standard_True; | |
328 | } | |
329 | ||
dc89236f | 330 | //======================================================================= |
331 | //function : ParseShadingModel | |
332 | //purpose : | |
333 | //======================================================================= | |
334 | Standard_Boolean ViewerTest::ParseShadingModel (Standard_CString theArg, | |
335 | Graphic3d_TypeOfShadingModel& theModel) | |
336 | { | |
337 | TCollection_AsciiString aTypeStr (theArg); | |
338 | aTypeStr.LowerCase(); | |
339 | if (aTypeStr == "unlit" | |
340 | || aTypeStr == "color" | |
341 | || aTypeStr == "none") | |
342 | { | |
343 | theModel = Graphic3d_TOSM_UNLIT; | |
344 | } | |
345 | else if (aTypeStr == "flat" | |
346 | || aTypeStr == "facet") | |
347 | { | |
348 | theModel = Graphic3d_TOSM_FACET; | |
349 | } | |
350 | else if (aTypeStr == "gouraud" | |
351 | || aTypeStr == "vertex" | |
352 | || aTypeStr == "vert") | |
353 | { | |
354 | theModel = Graphic3d_TOSM_VERTEX; | |
355 | } | |
356 | else if (aTypeStr == "phong" | |
357 | || aTypeStr == "fragment" | |
358 | || aTypeStr == "frag" | |
359 | || aTypeStr == "pixel") | |
360 | { | |
361 | theModel = Graphic3d_TOSM_FRAGMENT; | |
362 | } | |
67312b79 | 363 | else if (aTypeStr == "pbr") |
364 | { | |
365 | theModel = Graphic3d_TOSM_PBR; | |
366 | } | |
367 | else if (aTypeStr == "pbr_facet") | |
368 | { | |
369 | theModel = Graphic3d_TOSM_PBR_FACET; | |
370 | } | |
dc89236f | 371 | else if (aTypeStr == "default" |
372 | || aTypeStr == "def") | |
373 | { | |
374 | theModel = Graphic3d_TOSM_DEFAULT; | |
375 | } | |
376 | else if (aTypeStr.IsIntegerValue()) | |
377 | { | |
378 | const int aTypeInt = aTypeStr.IntegerValue(); | |
379 | if (aTypeInt <= Graphic3d_TOSM_DEFAULT || aTypeInt >= Graphic3d_TypeOfShadingModel_NB) | |
380 | { | |
381 | return Standard_False; | |
382 | } | |
383 | theModel = (Graphic3d_TypeOfShadingModel)aTypeInt; | |
384 | } | |
385 | else | |
386 | { | |
387 | return Standard_False; | |
388 | } | |
389 | return Standard_True; | |
390 | } | |
391 | ||
55c8f0f7 BB |
392 | //======================================================================= |
393 | //function : parseZLayer | |
394 | //purpose : | |
395 | //======================================================================= | |
396 | Standard_Boolean ViewerTest::parseZLayer (Standard_CString theArg, | |
397 | Standard_Boolean theToAllowInteger, | |
398 | Graphic3d_ZLayerId& theLayer) | |
399 | { | |
400 | TCollection_AsciiString aName (theArg); | |
401 | aName.LowerCase(); | |
402 | if (aName == "default" | |
403 | || aName == "def") | |
404 | { | |
405 | theLayer = Graphic3d_ZLayerId_Default; | |
406 | } | |
407 | else if (aName == "top") | |
408 | { | |
409 | theLayer = Graphic3d_ZLayerId_Top; | |
410 | } | |
411 | else if (aName == "topmost") | |
412 | { | |
413 | theLayer = Graphic3d_ZLayerId_Topmost; | |
414 | } | |
415 | else if (aName == "overlay" | |
416 | || aName == "toposd") | |
417 | { | |
418 | theLayer = Graphic3d_ZLayerId_TopOSD; | |
419 | } | |
420 | else if (aName == "underlay" | |
421 | || aName == "botosd") | |
422 | { | |
423 | theLayer = Graphic3d_ZLayerId_BotOSD; | |
424 | } | |
425 | else if (aName == "undefined") | |
426 | { | |
427 | theLayer = Graphic3d_ZLayerId_UNKNOWN; | |
428 | } | |
429 | else if (!GetAISContext().IsNull()) | |
430 | { | |
431 | const Handle(V3d_Viewer)& aViewer = ViewerTest::GetAISContext()->CurrentViewer(); | |
432 | TColStd_SequenceOfInteger aLayers; | |
433 | aViewer->GetAllZLayers (aLayers); | |
434 | for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next()) | |
435 | { | |
436 | Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value()); | |
437 | if (TCollection_AsciiString::IsSameString (aSettings.Name(), aName, Standard_False)) | |
438 | { | |
439 | theLayer = aLayeriter.Value(); | |
440 | return true; | |
441 | } | |
442 | } | |
443 | ||
444 | if (!theToAllowInteger | |
445 | || !aName.IsIntegerValue()) | |
446 | { | |
447 | return false; | |
448 | } | |
449 | Graphic3d_ZLayerId aLayer = aName.IntegerValue(); | |
450 | if (aLayer == Graphic3d_ZLayerId_UNKNOWN | |
451 | || std::find (aLayers.begin(), aLayers.end(), aLayer) != aLayers.end()) | |
452 | { | |
453 | theLayer = aLayer; | |
454 | return true; | |
455 | } | |
456 | return false; | |
457 | } | |
458 | return true; | |
459 | } | |
460 | ||
7fd59977 | 461 | //======================================================================= |
462 | //function : GetTypeNames | |
463 | //purpose : | |
464 | //======================================================================= | |
465 | static const char** GetTypeNames() | |
466 | { | |
467 | static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane", | |
468 | "Shape","ConnectedShape","MultiConn.Shape", | |
469 | "ConnectedInter.","MultiConn.", | |
470 | "Constraint","Dimension"}; | |
471 | static const char** ThePointer = names; | |
472 | return ThePointer; | |
473 | } | |
474 | ||
475 | //======================================================================= | |
476 | //function : GetTypeAndSignfromString | |
477 | //purpose : | |
478 | //======================================================================= | |
82b856b8 | 479 | static void GetTypeAndSignfromString (const char* theName, |
480 | AIS_KindOfInteractive& theType, | |
481 | Standard_Integer& theSign) | |
7fd59977 | 482 | { |
82b856b8 | 483 | const char** aFullNames = GetTypeNames(); |
484 | Standard_Integer anIndex = -1; | |
485 | for (Standard_Integer i = 0; i <= 13 && anIndex == -1; ++i) | |
486 | { | |
487 | if (strcasecmp (theName, aFullNames[i]) == 0) | |
488 | { | |
489 | anIndex = i; | |
490 | } | |
491 | } | |
7fd59977 | 492 | |
82b856b8 | 493 | if (anIndex ==-1) |
494 | { | |
495 | theType = AIS_KindOfInteractive_None; | |
496 | theSign = -1; | |
7fd59977 | 497 | return; |
498 | } | |
499 | ||
82b856b8 | 500 | if (anIndex <= 6) |
501 | { | |
502 | theType = AIS_KindOfInteractive_Datum; | |
503 | theSign = anIndex+1; | |
7fd59977 | 504 | } |
82b856b8 | 505 | else if (anIndex <= 9) |
506 | { | |
507 | theType = AIS_KindOfInteractive_Shape; | |
508 | theSign = anIndex - 7; | |
7fd59977 | 509 | } |
82b856b8 | 510 | else if (anIndex <= 11) |
511 | { | |
512 | theType = AIS_KindOfInteractive_Object; | |
513 | theSign = anIndex - 10; | |
7fd59977 | 514 | } |
82b856b8 | 515 | else |
516 | { | |
517 | theType = AIS_KindOfInteractive_Relation; | |
518 | theSign = anIndex - 12; | |
7fd59977 | 519 | } |
7fd59977 | 520 | } |
521 | ||
7fd59977 | 522 | #include <string.h> |
523 | #include <Draw_Interpretor.hxx> | |
524 | #include <Draw.hxx> | |
525 | #include <Draw_Appli.hxx> | |
526 | #include <DBRep.hxx> | |
527 | ||
528 | ||
529 | #include <TCollection_AsciiString.hxx> | |
530 | #include <V3d_Viewer.hxx> | |
531 | #include <V3d_View.hxx> | |
532 | #include <V3d.hxx> | |
533 | ||
534 | #include <AIS_InteractiveContext.hxx> | |
535 | #include <AIS_Shape.hxx> | |
7fd59977 | 536 | #include <AIS_DisplayMode.hxx> |
537 | #include <TColStd_MapOfInteger.hxx> | |
538 | #include <AIS_MapOfInteractive.hxx> | |
539 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> | |
540 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
541 | #include <ViewerTest_EventManager.hxx> | |
542 | ||
543 | #include <TopoDS_Solid.hxx> | |
544 | #include <BRepTools.hxx> | |
545 | #include <BRep_Builder.hxx> | |
546 | #include <TopAbs_ShapeEnum.hxx> | |
547 | ||
548 | #include <TopoDS.hxx> | |
549 | #include <BRep_Tool.hxx> | |
550 | ||
551 | ||
552 | #include <Draw_Window.hxx> | |
553 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
554 | #include <AIS_ListOfInteractive.hxx> | |
555 | #include <AIS_DisplayMode.hxx> | |
556 | #include <TopTools_ListOfShape.hxx> | |
557 | #include <BRepOffsetAPI_MakeThickSolid.hxx> | |
7fd59977 | 558 | |
7fd59977 | 559 | //============================================================================== |
560 | // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES | |
561 | //============================================================================== | |
562 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){ | |
563 | static ViewerTest_DoubleMapOfInteractiveAndName TheMap; | |
564 | return TheMap; | |
565 | } | |
566 | ||
29e2c6d2 | 567 | //======================================================================= |
568 | //function : Display | |
569 | //purpose : | |
570 | //======================================================================= | |
571 | Standard_Boolean ViewerTest::Display (const TCollection_AsciiString& theName, | |
572 | const Handle(AIS_InteractiveObject)& theObject, | |
573 | const Standard_Boolean theToUpdate, | |
574 | const Standard_Boolean theReplaceIfExists) | |
9558a876 A |
575 | { |
576 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
29e2c6d2 | 577 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
578 | if (aCtx.IsNull()) | |
9558a876 | 579 | { |
23fe70ec | 580 | Message::SendFail ("Error: AIS context is not available."); |
9558a876 A |
581 | return Standard_False; |
582 | } | |
583 | ||
584 | if (aMap.IsBound2 (theName)) | |
585 | { | |
586 | if (!theReplaceIfExists) | |
587 | { | |
23fe70ec | 588 | Message::SendFail() << "Error: other interactive object has been already registered with name: " << theName << ".\n" |
589 | << "Please use another name."; | |
9558a876 A |
590 | return Standard_False; |
591 | } | |
592 | ||
8f521168 | 593 | if (Handle(AIS_InteractiveObject) anOldObj = aMap.Find2 (theName)) |
29e2c6d2 | 594 | { |
1beb58d7 | 595 | aCtx->Remove (anOldObj, theObject.IsNull() && theToUpdate); |
29e2c6d2 | 596 | } |
9558a876 A |
597 | aMap.UnBind2 (theName); |
598 | } | |
599 | ||
29e2c6d2 | 600 | if (theObject.IsNull()) |
208e6839 | 601 | { |
29e2c6d2 | 602 | // object with specified name has been already unbound |
208e6839 | 603 | return Standard_True; |
604 | } | |
605 | ||
29e2c6d2 | 606 | // unbind AIS object if it was bound with another name |
607 | aMap.UnBind1 (theObject); | |
9558a876 A |
608 | |
609 | // can be registered without rebinding | |
29e2c6d2 | 610 | aMap.Bind (theObject, theName); |
611 | aCtx->Display (theObject, theToUpdate); | |
9558a876 A |
612 | return Standard_True; |
613 | } | |
614 | ||
29e2c6d2 | 615 | //! Alias for ViewerTest::Display(), compatibility with old code. |
616 | Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, | |
617 | const Handle(AIS_InteractiveObject)& theObject, | |
618 | Standard_Boolean theReplaceIfExists = Standard_True) | |
619 | { | |
620 | return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists); | |
621 | } | |
622 | ||
49582f9d | 623 | static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs; |
7fd59977 | 624 | |
24de79c3 | 625 | static Handle(V3d_View)& a3DView() |
626 | { | |
7fd59977 | 627 | static Handle(V3d_View) Viou; |
628 | return Viou; | |
629 | } | |
630 | ||
24de79c3 | 631 | |
7fd59977 | 632 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){ |
633 | static Handle(AIS_InteractiveContext) aContext; | |
634 | return aContext; | |
635 | } | |
636 | ||
24de79c3 | 637 | const Handle(V3d_View)& ViewerTest::CurrentView() |
7fd59977 | 638 | { |
639 | return a3DView(); | |
640 | } | |
641 | void ViewerTest::CurrentView(const Handle(V3d_View)& V) | |
642 | { | |
643 | a3DView() = V; | |
644 | } | |
645 | ||
24de79c3 | 646 | const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext() |
7fd59977 | 647 | { |
648 | return TheAISContext(); | |
649 | } | |
650 | ||
651 | void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx) | |
652 | { | |
653 | TheAISContext() = aCtx; | |
654 | ViewerTest::ResetEventManager(); | |
655 | } | |
656 | ||
657 | Handle(V3d_Viewer) ViewerTest::GetViewerFromContext() | |
658 | { | |
4952a30a | 659 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
7fd59977 | 660 | } |
661 | ||
662 | Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext() | |
663 | { | |
4952a30a | 664 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
7fd59977 | 665 | } |
666 | ||
667 | ||
668 | void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){ | |
669 | theEventMgrs.Prepend(EM); | |
670 | } | |
671 | ||
672 | void ViewerTest::UnsetEventManager() | |
673 | { | |
674 | theEventMgrs.RemoveFirst(); | |
675 | } | |
676 | ||
677 | ||
678 | void ViewerTest::ResetEventManager() | |
679 | { | |
49582f9d | 680 | theEventMgrs.Clear(); |
681 | theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext())); | |
7fd59977 | 682 | } |
683 | ||
684 | Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager() | |
685 | { | |
49582f9d | 686 | return !theEventMgrs.IsEmpty() |
687 | ? theEventMgrs.First() | |
688 | : Handle(ViewerTest_EventManager)(); | |
7fd59977 | 689 | } |
690 | ||
7fd59977 | 691 | //======================================================================= |
34db9c00 | 692 | //function : Get Context and active view |
7fd59977 | 693 | //purpose : |
694 | //======================================================================= | |
34db9c00 | 695 | static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx, |
696 | Handle(V3d_View)& theView) | |
7fd59977 | 697 | { |
34db9c00 | 698 | theCtx = ViewerTest::GetAISContext(); |
699 | theView = ViewerTest::CurrentView(); | |
700 | if (theCtx.IsNull() | |
701 | || theView.IsNull()) | |
7fd59977 | 702 | { |
23fe70ec | 703 | Message::SendFail ("Error: cannot find an active view!"); |
34db9c00 | 704 | return Standard_False; |
7fd59977 | 705 | } |
34db9c00 | 706 | return Standard_True; |
7fd59977 | 707 | } |
708 | ||
7fd59977 | 709 | //============================================================================== |
710 | //function : Clear | |
711 | //purpose : Remove all the object from the viewer | |
712 | //============================================================================== | |
713 | void ViewerTest::Clear() | |
714 | { | |
851dacdb | 715 | if (a3DView().IsNull()) |
716 | { | |
717 | return; | |
718 | } | |
719 | ||
720 | NCollection_Sequence<Handle(AIS_InteractiveObject)> aListRemoved; | |
721 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); anObjIter.More(); anObjIter.Next()) | |
722 | { | |
8f521168 | 723 | const Handle(AIS_InteractiveObject) anObj = anObjIter.Key1(); |
851dacdb | 724 | if (anObj->GetContext() != TheAISContext()) |
725 | { | |
726 | continue; | |
7fd59977 | 727 | } |
851dacdb | 728 | |
23fe70ec | 729 | Message::SendInfo() << "Remove " << anObjIter.Key2(); |
851dacdb | 730 | TheAISContext()->Remove (anObj, Standard_False); |
731 | aListRemoved.Append (anObj); | |
732 | } | |
733 | ||
734 | TheAISContext()->RebuildSelectionStructs(); | |
735 | TheAISContext()->UpdateCurrentViewer(); | |
736 | if (aListRemoved.Size() == GetMapOfAIS().Extent()) | |
737 | { | |
7fd59977 | 738 | GetMapOfAIS().Clear(); |
739 | } | |
851dacdb | 740 | else |
741 | { | |
742 | for (NCollection_Sequence<Handle(AIS_InteractiveObject)>::Iterator anObjIter (aListRemoved); anObjIter.More(); anObjIter.Next()) | |
743 | { | |
744 | GetMapOfAIS().UnBind1 (anObjIter.Value()); | |
745 | } | |
746 | } | |
7fd59977 | 747 | } |
748 | ||
1c88cbaf | 749 | //============================================================================== |
750 | //function : CopyIsoAspect | |
751 | //purpose : Returns copy Prs3d_IsoAspect with new number of isolines. | |
752 | //============================================================================== | |
753 | static Handle(Prs3d_IsoAspect) CopyIsoAspect | |
754 | (const Handle(Prs3d_IsoAspect) &theIsoAspect, | |
755 | const Standard_Integer theNbIsos) | |
756 | { | |
b6472664 | 757 | Quantity_Color aColor = theIsoAspect->Aspect()->Color(); |
758 | Aspect_TypeOfLine aType = theIsoAspect->Aspect()->Type(); | |
759 | Standard_Real aWidth = theIsoAspect->Aspect()->Width(); | |
1c88cbaf | 760 | |
761 | Handle(Prs3d_IsoAspect) aResult = | |
762 | new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos); | |
763 | ||
764 | return aResult; | |
765 | } | |
766 | ||
767 | //============================================================================== | |
768 | //function : visos | |
769 | //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag | |
770 | //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)] | |
771 | //============================================================================== | |
772 | static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
773 | { | |
774 | if (TheAISContext().IsNull()) { | |
775 | di << argv[0] << " Call 'vinit' before!\n"; | |
776 | return 1; | |
777 | } | |
778 | ||
779 | if (argc <= 1) { | |
780 | di << "Current number of isos : " << | |
781 | TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " << | |
782 | TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n"; | |
783 | di << "IsoOnPlane mode is " << | |
784 | (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n"; | |
5ad8c033 | 785 | di << "IsoOnTriangulation mode is " << |
786 | (TheAISContext()->IsoOnTriangulation() ? "ON" : "OFF") << "\n"; | |
1c88cbaf | 787 | return 0; |
788 | } | |
789 | ||
790 | Standard_Integer aLastInd = argc - 1; | |
791 | Standard_Boolean isChanged = Standard_False; | |
1d47d8d0 | 792 | Standard_Integer aNbUIsos = 0; |
793 | Standard_Integer aNbVIsos = 0; | |
1c88cbaf | 794 | |
795 | if (aLastInd >= 3) { | |
796 | Standard_Boolean isIsoOnPlane = Standard_False; | |
797 | ||
798 | if (strcmp(argv[aLastInd], "1") == 0) { | |
799 | isIsoOnPlane = Standard_True; | |
800 | isChanged = Standard_True; | |
801 | } else if (strcmp(argv[aLastInd], "0") == 0) { | |
802 | isIsoOnPlane = Standard_False; | |
803 | isChanged = Standard_True; | |
804 | } | |
805 | ||
806 | if (isChanged) { | |
807 | aNbVIsos = Draw::Atoi(argv[aLastInd - 1]); | |
808 | aNbUIsos = Draw::Atoi(argv[aLastInd - 2]); | |
809 | aLastInd -= 3; | |
810 | ||
811 | di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n"; | |
812 | di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n"; | |
813 | ||
814 | TheAISContext()->IsoOnPlane(isIsoOnPlane); | |
815 | ||
816 | if (aLastInd == 0) { | |
817 | // If there are no shapes provided set the default numbers. | |
818 | TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU); | |
819 | TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV); | |
820 | } | |
821 | } | |
822 | } | |
823 | ||
824 | Standard_Integer i; | |
825 | ||
8f521168 | 826 | for (i = 1; i <= aLastInd; i++) |
827 | { | |
1c88cbaf | 828 | TCollection_AsciiString name(argv[i]); |
8f521168 | 829 | Handle(AIS_InteractiveObject) aShape; |
830 | GetMapOfAIS().Find2(name, aShape); | |
831 | if (aShape.IsNull()) | |
832 | { | |
23fe70ec | 833 | Message::SendFail() << "Syntax error: object '" << name << "' is not found"; |
8f521168 | 834 | return 1; |
835 | } | |
836 | ||
837 | Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes(); | |
838 | Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect(); | |
839 | Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect(); | |
840 | if (isChanged) | |
841 | { | |
842 | CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos)); | |
843 | CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos)); | |
844 | TheAISContext()->SetLocalAttributes (aShape, CurDrawer, Standard_False); | |
845 | TheAISContext()->Redisplay (aShape, Standard_False); | |
846 | } | |
847 | else | |
848 | { | |
849 | di << "Number of isos for " << argv[i] << " : " | |
850 | << aUIso->Number() << " " << aVIso->Number() << "\n"; | |
1c88cbaf | 851 | } |
852 | } | |
853 | ||
854 | if (isChanged) { | |
855 | TheAISContext()->UpdateCurrentViewer(); | |
856 | } | |
857 | ||
858 | return 0; | |
859 | } | |
860 | ||
34db9c00 | 861 | static Standard_Integer VDispSensi (Draw_Interpretor& , |
862 | Standard_Integer theArgNb, | |
863 | Standard_CString* ) | |
7fd59977 | 864 | { |
34db9c00 | 865 | if (theArgNb > 1) |
866 | { | |
23fe70ec | 867 | Message::SendFail ("Error: wrong syntax!"); |
34db9c00 | 868 | return 1; |
869 | } | |
870 | ||
871 | Handle(AIS_InteractiveContext) aCtx; | |
872 | Handle(V3d_View) aView; | |
873 | if (!getCtxAndView (aCtx, aView)) | |
874 | { | |
875 | return 1; | |
876 | } | |
877 | ||
878 | aCtx->DisplayActiveSensitive (aView); | |
7fd59977 | 879 | return 0; |
880 | ||
881 | } | |
34db9c00 | 882 | |
883 | static Standard_Integer VClearSensi (Draw_Interpretor& , | |
884 | Standard_Integer theArgNb, | |
885 | Standard_CString* ) | |
7fd59977 | 886 | { |
34db9c00 | 887 | if (theArgNb > 1) |
888 | { | |
23fe70ec | 889 | Message::SendFail ("Error: wrong syntax!"); |
34db9c00 | 890 | return 1; |
891 | } | |
892 | ||
893 | Handle(AIS_InteractiveContext) aCtx; | |
894 | Handle(V3d_View) aView; | |
895 | if (!getCtxAndView (aCtx, aView)) | |
896 | { | |
897 | return 1; | |
898 | } | |
899 | aCtx->ClearActiveSensitive (aView); | |
7fd59977 | 900 | return 0; |
901 | } | |
902 | ||
903 | //============================================================================== | |
519d35d8 | 904 | //function : VDir |
7fd59977 | 905 | //purpose : To list the displayed object with their attributes |
7fd59977 | 906 | //============================================================================== |
519d35d8 | 907 | static int VDir (Draw_Interpretor& theDI, |
ab1f4580 | 908 | Standard_Integer theNbArgs, |
909 | const char** theArgVec) | |
519d35d8 | 910 | { |
ab1f4580 | 911 | TCollection_AsciiString aMatch; |
912 | Standard_Boolean toFormat = Standard_False; | |
913 | for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) | |
519d35d8 | 914 | { |
ab1f4580 | 915 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
916 | anArgCase.LowerCase(); | |
917 | if (anArgCase == "-list" | |
918 | || anArgCase == "-format") | |
919 | { | |
920 | toFormat = Standard_True; | |
921 | } | |
922 | else if (aMatch.IsEmpty()) | |
923 | { | |
924 | aMatch = theArgVec[anArgIter]; | |
925 | } | |
926 | else | |
927 | { | |
23fe70ec | 928 | Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'"; |
ab1f4580 | 929 | return 1; |
930 | } | |
931 | } | |
932 | ||
933 | TCollection_AsciiString aRes; | |
934 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next()) | |
935 | { | |
936 | if (!aMatch.IsEmpty()) | |
937 | { | |
938 | const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aMatch + "' '" + anIter.Key2() + "'"; | |
939 | if (theDI.Eval (aCheck.ToCString()) == 0 | |
940 | && *theDI.Result() != '1') | |
941 | { | |
942 | continue; | |
943 | } | |
944 | } | |
945 | ||
946 | if (toFormat) | |
947 | { | |
948 | aRes += TCollection_AsciiString("\t") + anIter.Key2() + "\n"; | |
949 | } | |
950 | else | |
951 | { | |
952 | aRes += anIter.Key2() + " "; | |
953 | } | |
519d35d8 | 954 | } |
ab1f4580 | 955 | theDI.Reset(); |
956 | theDI << aRes; | |
7fd59977 | 957 | return 0; |
958 | } | |
959 | ||
f978241f | 960 | //! Auxiliary enumeration |
961 | enum ViewerTest_StereoPair | |
962 | { | |
963 | ViewerTest_SP_Single, | |
964 | ViewerTest_SP_SideBySide, | |
965 | ViewerTest_SP_OverUnder | |
966 | }; | |
967 | ||
7fd59977 | 968 | //============================================================================== |
969 | //function : VDump | |
970 | //purpose : To dump the active view snapshot to image file | |
7fd59977 | 971 | //============================================================================== |
34db9c00 | 972 | static Standard_Integer VDump (Draw_Interpretor& theDI, |
973 | Standard_Integer theArgNb, | |
974 | Standard_CString* theArgVec) | |
7fd59977 | 975 | { |
b40cdc2b | 976 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
34db9c00 | 977 | if (theArgNb < 2) |
7fd59977 | 978 | { |
23fe70ec | 979 | Message::SendFail ("Error: wrong number of arguments! Image file name should be specified at least."); |
7fd59977 | 980 | return 1; |
981 | } | |
b40cdc2b | 982 | if (aView.IsNull()) |
983 | { | |
984 | Message::SendFail() << "Error: cannot find an active view!"; | |
985 | return 1; | |
986 | } | |
7fd59977 | 987 | |
34db9c00 | 988 | Standard_Integer anArgIter = 1; |
989 | Standard_CString aFilePath = theArgVec[anArgIter++]; | |
f978241f | 990 | ViewerTest_StereoPair aStereoPair = ViewerTest_SP_Single; |
3bffef55 | 991 | V3d_ImageDumpOptions aParams; |
b40cdc2b | 992 | Handle(Graphic3d_Camera) aCustomCam; |
3bffef55 | 993 | aParams.BufferType = Graphic3d_BT_RGB; |
994 | aParams.StereoOptions = V3d_SDO_MONO; | |
34db9c00 | 995 | for (; anArgIter < theArgNb; ++anArgIter) |
7fd59977 | 996 | { |
34db9c00 | 997 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
998 | anArg.LowerCase(); | |
f978241f | 999 | if (anArg == "-buffer") |
7fd59977 | 1000 | { |
f978241f | 1001 | if (++anArgIter >= theArgNb) |
1002 | { | |
23fe70ec | 1003 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
f978241f | 1004 | return 1; |
1005 | } | |
1006 | ||
1007 | TCollection_AsciiString aBufArg (theArgVec[anArgIter]); | |
1008 | aBufArg.LowerCase(); | |
1009 | if (aBufArg == "rgba") | |
1010 | { | |
3bffef55 | 1011 | aParams.BufferType = Graphic3d_BT_RGBA; |
f978241f | 1012 | } |
1013 | else if (aBufArg == "rgb") | |
1014 | { | |
3bffef55 | 1015 | aParams.BufferType = Graphic3d_BT_RGB; |
f978241f | 1016 | } |
4eff0c04 | 1017 | else if (aBufArg == "red") |
1018 | { | |
1019 | aParams.BufferType = Graphic3d_BT_Red; | |
1020 | } | |
f978241f | 1021 | else if (aBufArg == "depth") |
1022 | { | |
3bffef55 | 1023 | aParams.BufferType = Graphic3d_BT_Depth; |
f978241f | 1024 | } |
1025 | else | |
1026 | { | |
23fe70ec | 1027 | Message::SendFail() << "Error: unknown buffer '" << aBufArg << "'"; |
f978241f | 1028 | return 1; |
1029 | } | |
7fd59977 | 1030 | } |
b40cdc2b | 1031 | else if (anArgIter + 1 < theArgNb |
1032 | && anArg == "-xrpose") | |
1033 | { | |
1034 | TCollection_AsciiString anXRArg (theArgVec[++anArgIter]); | |
1035 | anXRArg.LowerCase(); | |
1036 | if (anXRArg == "base") | |
1037 | { | |
1038 | aCustomCam = aView->View()->BaseXRCamera(); | |
1039 | } | |
1040 | else if (anXRArg == "head") | |
1041 | { | |
1042 | aCustomCam = aView->View()->PosedXRCamera(); | |
1043 | } | |
1044 | else if (anXRArg == "handleft" | |
1045 | || anXRArg == "handright") | |
1046 | { | |
1047 | if (aView->View()->IsActiveXR()) | |
1048 | { | |
1049 | aCustomCam = new Graphic3d_Camera(); | |
1050 | aView->View()->ComputeXRPosedCameraFromBase (*aCustomCam, anXRArg == "handleft" | |
1051 | ? aView->View()->XRSession()->LeftHandPose() | |
1052 | : aView->View()->XRSession()->RightHandPose()); | |
1053 | } | |
1054 | } | |
1055 | else | |
1056 | { | |
1057 | Message::SendFail() << "Syntax error: unknown XR pose '" << anXRArg << "'"; | |
1058 | return 1; | |
1059 | } | |
1060 | if (aCustomCam.IsNull()) | |
1061 | { | |
1062 | Message::SendFail() << "Error: undefined XR pose"; | |
1063 | return 0; | |
1064 | } | |
1065 | } | |
f978241f | 1066 | else if (anArg == "-stereo") |
7fd59977 | 1067 | { |
f978241f | 1068 | if (++anArgIter >= theArgNb) |
1069 | { | |
23fe70ec | 1070 | Message::SendFail() << "Error: wrong syntax at '" << anArg << "'"; |
f978241f | 1071 | return 1; |
1072 | } | |
1073 | ||
1074 | TCollection_AsciiString aStereoArg (theArgVec[anArgIter]); | |
1075 | aStereoArg.LowerCase(); | |
1076 | if (aStereoArg == "l" | |
1077 | || aStereoArg == "left") | |
1078 | { | |
3bffef55 | 1079 | aParams.StereoOptions = V3d_SDO_LEFT_EYE; |
f978241f | 1080 | } |
1081 | else if (aStereoArg == "r" | |
1082 | || aStereoArg == "right") | |
1083 | { | |
3bffef55 | 1084 | aParams.StereoOptions = V3d_SDO_RIGHT_EYE; |
f978241f | 1085 | } |
1086 | else if (aStereoArg == "mono") | |
1087 | { | |
3bffef55 | 1088 | aParams.StereoOptions = V3d_SDO_MONO; |
f978241f | 1089 | } |
1090 | else if (aStereoArg == "blended" | |
1091 | || aStereoArg == "blend" | |
1092 | || aStereoArg == "stereo") | |
1093 | { | |
3bffef55 | 1094 | aParams.StereoOptions = V3d_SDO_BLENDED; |
f978241f | 1095 | } |
1096 | else if (aStereoArg == "sbs" | |
1097 | || aStereoArg == "sidebyside") | |
1098 | { | |
1099 | aStereoPair = ViewerTest_SP_SideBySide; | |
1100 | } | |
1101 | else if (aStereoArg == "ou" | |
1102 | || aStereoArg == "overunder") | |
1103 | { | |
1104 | aStereoPair = ViewerTest_SP_OverUnder; | |
1105 | } | |
1106 | else | |
1107 | { | |
23fe70ec | 1108 | Message::SendFail() << "Error: unknown stereo format '" << aStereoArg << "'"; |
f978241f | 1109 | return 1; |
1110 | } | |
7fd59977 | 1111 | } |
f978241f | 1112 | else if (anArg == "-rgba" |
1113 | || anArg == "rgba") | |
34db9c00 | 1114 | { |
3bffef55 | 1115 | aParams.BufferType = Graphic3d_BT_RGBA; |
34db9c00 | 1116 | } |
f978241f | 1117 | else if (anArg == "-rgb" |
1118 | || anArg == "rgb") | |
34db9c00 | 1119 | { |
3bffef55 | 1120 | aParams.BufferType = Graphic3d_BT_RGB; |
34db9c00 | 1121 | } |
4eff0c04 | 1122 | else if (anArg == "-red" |
1123 | || anArg == "red") | |
1124 | { | |
1125 | aParams.BufferType = Graphic3d_BT_Red; | |
1126 | } | |
f978241f | 1127 | else if (anArg == "-depth" |
1128 | || anArg == "depth") | |
34db9c00 | 1129 | { |
3bffef55 | 1130 | aParams.BufferType = Graphic3d_BT_Depth; |
34db9c00 | 1131 | } |
f978241f | 1132 | else if (anArg == "-width" |
1133 | || anArg == "width" | |
1134 | || anArg == "sizex") | |
34db9c00 | 1135 | { |
3bffef55 | 1136 | if (aParams.Width != 0) |
34db9c00 | 1137 | { |
23fe70ec | 1138 | Message::SendFail() << "Error: wrong syntax at " << theArgVec[anArgIter]; |
34db9c00 | 1139 | return 1; |
1140 | } | |
1141 | else if (++anArgIter >= theArgNb) | |
1142 | { | |
23fe70ec | 1143 | Message::SendFail() << "Error: integer value is expected right after 'width'"; |
34db9c00 | 1144 | return 1; |
1145 | } | |
3bffef55 | 1146 | aParams.Width = Draw::Atoi (theArgVec[anArgIter]); |
34db9c00 | 1147 | } |
f978241f | 1148 | else if (anArg == "-height" |
1149 | || anArg == "height" | |
1150 | || anArg == "-sizey") | |
34db9c00 | 1151 | { |
3bffef55 | 1152 | if (aParams.Height != 0) |
34db9c00 | 1153 | { |
23fe70ec | 1154 | Message::SendFail() << "Error: wrong syntax at " << theArgVec[anArgIter]; |
34db9c00 | 1155 | return 1; |
1156 | } | |
34db9c00 | 1157 | else if (++anArgIter >= theArgNb) |
1158 | { | |
23fe70ec | 1159 | Message::SendFail() << "Error: integer value is expected right after 'height'"; |
34db9c00 | 1160 | return 1; |
1161 | } | |
3bffef55 | 1162 | aParams.Height = Draw::Atoi (theArgVec[anArgIter]); |
1163 | } | |
1164 | else if (anArg == "-tile" | |
1165 | || anArg == "-tilesize") | |
1166 | { | |
1167 | if (++anArgIter >= theArgNb) | |
1168 | { | |
23fe70ec | 1169 | Message::SendFail() << "Error: integer value is expected right after 'tileSize'"; |
3bffef55 | 1170 | return 1; |
1171 | } | |
1172 | aParams.TileSize = Draw::Atoi (theArgVec[anArgIter]); | |
34db9c00 | 1173 | } |
1174 | else | |
1175 | { | |
23fe70ec | 1176 | Message::SendFail() << "Error: unknown argument '" << theArgVec[anArgIter] << "'"; |
34db9c00 | 1177 | return 1; |
1178 | } | |
7fd59977 | 1179 | } |
3bffef55 | 1180 | if ((aParams.Width <= 0 && aParams.Height > 0) |
1181 | || (aParams.Width > 0 && aParams.Height <= 0)) | |
7fd59977 | 1182 | { |
23fe70ec | 1183 | Message::SendFail() << "Error: dimensions " << aParams.Width << "x" << aParams.Height << " are incorrect"; |
85e096c3 | 1184 | return 1; |
1185 | } | |
1186 | ||
3bffef55 | 1187 | if (aParams.Width <= 0 || aParams.Height <= 0) |
b5ac8292 | 1188 | { |
3bffef55 | 1189 | aView->Window()->Size (aParams.Width, aParams.Height); |
f978241f | 1190 | } |
1191 | ||
1192 | Image_AlienPixMap aPixMap; | |
dc858f4c | 1193 | Image_Format aFormat = Image_Format_UNKNOWN; |
3bffef55 | 1194 | switch (aParams.BufferType) |
f978241f | 1195 | { |
38d90bb3 | 1196 | case Graphic3d_BT_RGB: aFormat = Image_Format_RGB; break; |
1197 | case Graphic3d_BT_RGBA: aFormat = Image_Format_RGBA; break; | |
1198 | case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break; | |
1199 | case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF; break; | |
4eff0c04 | 1200 | case Graphic3d_BT_Red: aFormat = Image_Format_Gray; break; |
f978241f | 1201 | } |
1202 | ||
b40cdc2b | 1203 | const bool wasImmUpdate = aView->SetImmediateUpdate (false); |
1204 | Handle(Graphic3d_Camera) aCamBack = aView->Camera(); | |
1205 | if (!aCustomCam.IsNull()) | |
1206 | { | |
1207 | aView->SetCamera (aCustomCam); | |
1208 | } | |
f978241f | 1209 | switch (aStereoPair) |
1210 | { | |
1211 | case ViewerTest_SP_Single: | |
b5ac8292 | 1212 | { |
3bffef55 | 1213 | if (!aView->ToPixMap (aPixMap, aParams)) |
f978241f | 1214 | { |
1215 | theDI << "Fail: view dump failed!\n"; | |
1216 | return 0; | |
1217 | } | |
3bffef55 | 1218 | else if (aPixMap.SizeX() != Standard_Size(aParams.Width) |
1219 | || aPixMap.SizeY() != Standard_Size(aParams.Height)) | |
f978241f | 1220 | { |
1221 | theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY() | |
3bffef55 | 1222 | << " are lesser than requested " << aParams.Width << "x" << aParams.Height << "\n"; |
f978241f | 1223 | } |
1224 | break; | |
b5ac8292 | 1225 | } |
f978241f | 1226 | case ViewerTest_SP_SideBySide: |
b5ac8292 | 1227 | { |
3bffef55 | 1228 | if (!aPixMap.InitZero (aFormat, aParams.Width * 2, aParams.Height)) |
f978241f | 1229 | { |
1230 | theDI << "Fail: not enough memory for image allocation!\n"; | |
1231 | return 0; | |
1232 | } | |
1233 | ||
1234 | Image_PixMap aPixMapL, aPixMapR; | |
1235 | aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(), | |
3bffef55 | 1236 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); |
1237 | aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizePixelBytes() * aParams.Width, | |
1238 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); | |
1239 | ||
1240 | aParams.StereoOptions = V3d_SDO_LEFT_EYE; | |
1241 | Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams); | |
1242 | aParams.StereoOptions = V3d_SDO_RIGHT_EYE; | |
1243 | isOk = isOk && aView->ToPixMap (aPixMapR, aParams); | |
1244 | if (!isOk) | |
34db9c00 | 1245 | { |
1246 | theDI << "Fail: view dump failed!\n"; | |
f978241f | 1247 | return 0; |
34db9c00 | 1248 | } |
f978241f | 1249 | break; |
b5ac8292 | 1250 | } |
f978241f | 1251 | case ViewerTest_SP_OverUnder: |
1252 | { | |
3bffef55 | 1253 | if (!aPixMap.InitZero (aFormat, aParams.Width, aParams.Height * 2)) |
f978241f | 1254 | { |
1255 | theDI << "Fail: not enough memory for image allocation!\n"; | |
1256 | return 0; | |
1257 | } | |
b5ac8292 | 1258 | |
f978241f | 1259 | Image_PixMap aPixMapL, aPixMapR; |
f9f740d6 | 1260 | aPixMapL.InitWrapper (aPixMap.Format(), aPixMap.ChangeData(), |
3bffef55 | 1261 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); |
f9f740d6 | 1262 | aPixMapR.InitWrapper (aPixMap.Format(), aPixMap.ChangeData() + aPixMap.SizeRowBytes() * aParams.Height, |
3bffef55 | 1263 | aParams.Width, aParams.Height, aPixMap.SizeRowBytes()); |
1264 | ||
1265 | aParams.StereoOptions = V3d_SDO_LEFT_EYE; | |
1266 | Standard_Boolean isOk = aView->ToPixMap (aPixMapL, aParams); | |
1267 | aParams.StereoOptions = V3d_SDO_RIGHT_EYE; | |
1268 | isOk = isOk && aView->ToPixMap (aPixMapR, aParams); | |
1269 | if (!isOk) | |
f978241f | 1270 | { |
1271 | theDI << "Fail: view dump failed!\n"; | |
1272 | return 0; | |
1273 | } | |
1274 | break; | |
1275 | } | |
7fd59977 | 1276 | } |
b40cdc2b | 1277 | if (!aCustomCam.IsNull()) |
1278 | { | |
1279 | aView->SetCamera (aCamBack); | |
1280 | } | |
1281 | aView->SetImmediateUpdate (wasImmUpdate); | |
85e096c3 | 1282 | |
34db9c00 | 1283 | if (!aPixMap.Save (aFilePath)) |
85e096c3 | 1284 | { |
34db9c00 | 1285 | theDI << "Fail: image can not be saved!\n"; |
85e096c3 | 1286 | } |
1287 | return 0; | |
7fd59977 | 1288 | } |
1289 | ||
dde68833 | 1290 | enum TypeOfDispOperation |
7fd59977 | 1291 | { |
dde68833 | 1292 | TypeOfDispOperation_SetDispMode, |
1293 | TypeOfDispOperation_UnsetDispMode | |
1294 | }; | |
7fd59977 | 1295 | |
dde68833 | 1296 | //! Displays,Erase... |
1297 | static void VwrTst_DispErase (const Handle(AIS_InteractiveObject)& thePrs, | |
1298 | const Standard_Integer theMode, | |
1299 | const TypeOfDispOperation theType, | |
1300 | const Standard_Boolean theToUpdate) | |
1301 | { | |
1302 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1303 | switch (theType) | |
1304 | { | |
1305 | case TypeOfDispOperation_SetDispMode: | |
1306 | { | |
1307 | if (!thePrs.IsNull()) | |
1308 | { | |
1309 | aCtx->SetDisplayMode (thePrs, theMode, theToUpdate); | |
1310 | } | |
1311 | else | |
1312 | { | |
1313 | aCtx->SetDisplayMode ((AIS_DisplayMode )theMode, theToUpdate); | |
1314 | } | |
1315 | break; | |
1316 | } | |
1317 | case TypeOfDispOperation_UnsetDispMode: | |
1318 | { | |
1319 | if (!thePrs.IsNull()) | |
1320 | { | |
1321 | aCtx->UnsetDisplayMode (thePrs, theToUpdate); | |
1322 | } | |
1323 | else | |
1324 | { | |
1325 | aCtx->SetDisplayMode (AIS_WireFrame, theToUpdate); | |
1326 | } | |
1327 | break; | |
1328 | } | |
7fd59977 | 1329 | } |
7fd59977 | 1330 | } |
1331 | ||
1332 | //======================================================================= | |
1333 | //function : | |
1334 | //purpose : | |
1335 | //======================================================================= | |
1336 | static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
1337 | { | |
dde68833 | 1338 | if (argc < 1 |
1339 | || argc > 3) | |
1340 | { | |
23fe70ec | 1341 | Message::SendFail() << "Syntax error: wrong number of arguments"; |
7fd59977 | 1342 | return 1; |
dde68833 | 1343 | } |
7fd59977 | 1344 | |
dde68833 | 1345 | TypeOfDispOperation aType = TCollection_AsciiString (argv[0]) == "vunsetdispmode" |
1346 | ? TypeOfDispOperation_UnsetDispMode | |
1347 | : TypeOfDispOperation_SetDispMode; | |
1348 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
f41fd243 | 1349 | if (aCtx.IsNull()) |
1350 | { | |
1351 | Message::SendFail ("Error: no active viewer"); | |
1352 | return 1; | |
1353 | } | |
1354 | ||
dde68833 | 1355 | if (aType == TypeOfDispOperation_UnsetDispMode) |
1356 | { | |
1357 | if (argc == 1) | |
1358 | { | |
1359 | if (aCtx->NbSelected() == 0) | |
1360 | { | |
1361 | VwrTst_DispErase (Handle(AIS_InteractiveObject)(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False); | |
1362 | } | |
1363 | else | |
1364 | { | |
1365 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) | |
1366 | { | |
1367 | VwrTst_DispErase (aCtx->SelectedInteractive(), -1, TypeOfDispOperation_UnsetDispMode, Standard_False); | |
1368 | } | |
7fd59977 | 1369 | } |
dde68833 | 1370 | aCtx->UpdateCurrentViewer(); |
7fd59977 | 1371 | } |
dde68833 | 1372 | else |
1373 | { | |
1374 | TCollection_AsciiString aName = argv[1]; | |
8f521168 | 1375 | Handle(AIS_InteractiveObject) aPrs; |
1376 | if (GetMapOfAIS().Find2 (aName, aPrs) | |
1377 | && !aPrs.IsNull()) | |
dde68833 | 1378 | { |
8f521168 | 1379 | VwrTst_DispErase (aPrs, -1, TypeOfDispOperation_UnsetDispMode, Standard_True); |
7fd59977 | 1380 | } |
1381 | } | |
1382 | } | |
dde68833 | 1383 | else if (argc == 2) |
1384 | { | |
1385 | Standard_Integer aDispMode = Draw::Atoi (argv[1]); | |
1386 | if (aCtx->NbSelected() == 0 | |
1387 | && aType == TypeOfDispOperation_SetDispMode) | |
1388 | { | |
1389 | VwrTst_DispErase (Handle(AIS_InteractiveObject)(), aDispMode, TypeOfDispOperation_SetDispMode, Standard_True); | |
7fd59977 | 1390 | } |
dde68833 | 1391 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
1392 | { | |
1393 | VwrTst_DispErase (aCtx->SelectedInteractive(), aDispMode, aType, Standard_False); | |
7fd59977 | 1394 | } |
dde68833 | 1395 | aCtx->UpdateCurrentViewer(); |
7fd59977 | 1396 | } |
dde68833 | 1397 | else |
1398 | { | |
1399 | Handle(AIS_InteractiveObject) aPrs; | |
1400 | TCollection_AsciiString aName (argv[1]); | |
8f521168 | 1401 | if (GetMapOfAIS().Find2 (aName, aPrs) |
1402 | && !aPrs.IsNull()) | |
dde68833 | 1403 | { |
1404 | VwrTst_DispErase (aPrs, Draw::Atoi(argv[2]), aType, Standard_True); | |
1405 | } | |
7fd59977 | 1406 | } |
1407 | return 0; | |
1408 | } | |
1409 | ||
1410 | ||
1411 | //======================================================================= | |
1412 | //function : | |
1413 | //purpose : | |
1414 | //======================================================================= | |
1415 | static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1416 | { | |
1417 | if(argc==1) return 1; | |
91322f44 | 1418 | Standard_Integer On = Draw::Atoi(argv[1]); |
7fd59977 | 1419 | const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext(); |
f41fd243 | 1420 | if (Ctx.IsNull()) |
1421 | { | |
1422 | Message::SendFail ("Error: no active viewer"); | |
1423 | return 1; | |
1424 | } | |
7fd59977 | 1425 | |
c3282ec1 | 1426 | if(argc==2) |
1427 | { | |
1428 | TCollection_AsciiString isOnOff = On == 1 ? "on" : "off"; | |
1429 | di << "Sub intensite is turned " << isOnOff << " for " << Ctx->NbSelected() << "objects\n"; | |
1430 | for (Ctx->InitSelected(); Ctx->MoreSelected(); Ctx->NextSelected()) | |
1431 | { | |
1432 | if(On==1) | |
1433 | { | |
1434 | Ctx->SubIntensityOn (Ctx->SelectedInteractive(), Standard_False); | |
7fd59977 | 1435 | } |
c3282ec1 | 1436 | else |
1437 | { | |
1438 | Ctx->SubIntensityOff (Ctx->SelectedInteractive(), Standard_False); | |
7fd59977 | 1439 | } |
1440 | } | |
c3282ec1 | 1441 | |
7fd59977 | 1442 | Ctx->UpdateCurrentViewer(); |
1443 | } | |
1444 | else { | |
1445 | Handle(AIS_InteractiveObject) IO; | |
1446 | TCollection_AsciiString name = argv[2]; | |
8f521168 | 1447 | if (GetMapOfAIS().Find2 (name, IO) |
1448 | && !IO.IsNull()) | |
1449 | { | |
1450 | if(On==1) | |
1451 | Ctx->SubIntensityOn(IO, Standard_True); | |
1452 | else | |
1453 | Ctx->SubIntensityOff(IO, Standard_True); | |
7fd59977 | 1454 | } |
1455 | else return 1; | |
1456 | } | |
1457 | return 0; | |
7fd59977 | 1458 | } |
7fd59977 | 1459 | |
ad3217cd | 1460 | //! Auxiliary class to iterate presentations from different collections. |
1461 | class ViewTest_PrsIter | |
1462 | { | |
1463 | public: | |
7fd59977 | 1464 | |
ad3217cd | 1465 | //! Create and initialize iterator object. |
1466 | ViewTest_PrsIter (const TCollection_AsciiString& theName) | |
1467 | : mySource (IterSource_All) | |
1468 | { | |
1469 | NCollection_Sequence<TCollection_AsciiString> aNames; | |
1470 | if (!theName.IsEmpty()) | |
1471 | aNames.Append (theName); | |
1472 | Init (aNames); | |
7fd59977 | 1473 | } |
ad3217cd | 1474 | |
1475 | //! Create and initialize iterator object. | |
1476 | ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames) | |
1477 | : mySource (IterSource_All) | |
1478 | { | |
1479 | Init (theNames); | |
7fd59977 | 1480 | } |
1481 | ||
ad3217cd | 1482 | //! Initialize the iterator. |
1483 | void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames) | |
1484 | { | |
1485 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1486 | mySeq = theNames; | |
1487 | mySelIter.Nullify(); | |
1488 | myCurrent.Nullify(); | |
1489 | myCurrentTrs.Nullify(); | |
1490 | if (!mySeq.IsEmpty()) | |
1491 | { | |
1492 | mySource = IterSource_List; | |
1493 | mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq); | |
7fd59977 | 1494 | } |
c3282ec1 | 1495 | else if (aCtx->NbSelected() > 0) |
ad3217cd | 1496 | { |
1497 | mySource = IterSource_Selected; | |
1498 | mySelIter = aCtx; | |
c3282ec1 | 1499 | mySelIter->InitSelected(); |
ad3217cd | 1500 | } |
1501 | else | |
1502 | { | |
1503 | mySource = IterSource_All; | |
1504 | myMapIter.Initialize (GetMapOfAIS()); | |
1505 | } | |
1506 | initCurrent(); | |
1507 | } | |
7fd59977 | 1508 | |
ad3217cd | 1509 | const TCollection_AsciiString& CurrentName() const |
1510 | { | |
1511 | return myCurrentName; | |
1512 | } | |
7fd59977 | 1513 | |
ad3217cd | 1514 | const Handle(AIS_InteractiveObject)& Current() const |
1515 | { | |
1516 | return myCurrent; | |
1517 | } | |
7fd59977 | 1518 | |
ad3217cd | 1519 | const Handle(Standard_Transient)& CurrentTrs() const |
1520 | { | |
1521 | return myCurrentTrs; | |
1522 | } | |
1523 | ||
1524 | //! @return true if iterator points to valid object within collection | |
1525 | Standard_Boolean More() const | |
1526 | { | |
1527 | switch (mySource) | |
1528 | { | |
1529 | case IterSource_All: return myMapIter.More(); | |
1530 | case IterSource_List: return mySeqIter.More(); | |
c3282ec1 | 1531 | case IterSource_Selected: return mySelIter->MoreSelected(); |
ad3217cd | 1532 | } |
1533 | return Standard_False; | |
1534 | } | |
1535 | ||
1536 | //! Go to the next item. | |
1537 | void Next() | |
1538 | { | |
1539 | myCurrentName.Clear(); | |
1540 | myCurrentTrs.Nullify(); | |
1541 | myCurrent.Nullify(); | |
1542 | switch (mySource) | |
1543 | { | |
1544 | case IterSource_All: | |
1545 | { | |
1546 | myMapIter.Next(); | |
1547 | break; | |
1548 | } | |
1549 | case IterSource_List: | |
1550 | { | |
1551 | mySeqIter.Next(); | |
1552 | break; | |
1553 | } | |
1554 | case IterSource_Selected: | |
1555 | { | |
c3282ec1 | 1556 | mySelIter->NextSelected(); |
ad3217cd | 1557 | break; |
7fd59977 | 1558 | } |
1559 | } | |
ad3217cd | 1560 | initCurrent(); |
1561 | } | |
7fd59977 | 1562 | |
ad3217cd | 1563 | private: |
7fd59977 | 1564 | |
ad3217cd | 1565 | void initCurrent() |
1566 | { | |
1567 | switch (mySource) | |
1568 | { | |
1569 | case IterSource_All: | |
7fd59977 | 1570 | { |
ad3217cd | 1571 | if (myMapIter.More()) |
1572 | { | |
1573 | myCurrentName = myMapIter.Key2(); | |
1574 | myCurrentTrs = myMapIter.Key1(); | |
1575 | myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); | |
eafb234b | 1576 | } |
ad3217cd | 1577 | break; |
1578 | } | |
1579 | case IterSource_List: | |
1580 | { | |
1581 | if (mySeqIter.More()) | |
1582 | { | |
1583 | if (!GetMapOfAIS().IsBound2 (mySeqIter.Value())) | |
1584 | { | |
23fe70ec | 1585 | Message::SendFail() << "Error: object " << mySeqIter.Value() << " is not displayed!"; |
ad3217cd | 1586 | return; |
1587 | } | |
1588 | myCurrentName = mySeqIter.Value(); | |
1589 | myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value()); | |
1590 | myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); | |
1591 | } | |
1592 | break; | |
1593 | } | |
1594 | case IterSource_Selected: | |
1595 | { | |
c3282ec1 | 1596 | if (mySelIter->MoreSelected()) |
ad3217cd | 1597 | { |
c3282ec1 | 1598 | myCurrentName = GetMapOfAIS().Find1 (mySelIter->SelectedInteractive()); |
1599 | myCurrent = mySelIter->SelectedInteractive(); | |
ad3217cd | 1600 | } |
1601 | break; | |
7fd59977 | 1602 | } |
7fd59977 | 1603 | } |
1604 | } | |
ad3217cd | 1605 | |
1606 | private: | |
1607 | ||
1608 | enum IterSource | |
1609 | { | |
1610 | IterSource_All, | |
1611 | IterSource_List, | |
1612 | IterSource_Selected | |
1613 | }; | |
1614 | ||
1615 | private: | |
1616 | ||
1617 | Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected) | |
1618 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All) | |
1619 | NCollection_Sequence<TCollection_AsciiString> mySeq; | |
1620 | NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter; | |
1621 | ||
1622 | TCollection_AsciiString myCurrentName;//!< current item name | |
1623 | Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object) | |
1624 | Handle(AIS_InteractiveObject) myCurrent; //!< current item | |
1625 | ||
1626 | IterSource mySource; //!< iterated collection | |
1627 | ||
1628 | }; | |
7fd59977 | 1629 | |
2a332745 | 1630 | //! Parse interior style name. |
1631 | static bool parseInteriorStyle (const TCollection_AsciiString& theArg, | |
1632 | Aspect_InteriorStyle& theStyle) | |
7fd59977 | 1633 | { |
2a332745 | 1634 | TCollection_AsciiString anArg (theArg); |
1635 | anArg.LowerCase(); | |
1636 | if (anArg == "empty") | |
ad3217cd | 1637 | { |
2a332745 | 1638 | theStyle = Aspect_IS_EMPTY; |
ad3217cd | 1639 | } |
2a332745 | 1640 | else if (anArg == "hollow") |
ad3217cd | 1641 | { |
2a332745 | 1642 | theStyle = Aspect_IS_HOLLOW; |
ad3217cd | 1643 | } |
2a332745 | 1644 | else if (anArg == "solid") |
ad3217cd | 1645 | { |
2a332745 | 1646 | theStyle = Aspect_IS_SOLID; |
ad3217cd | 1647 | } |
2a332745 | 1648 | else if (anArg == "hatch") |
ad3217cd | 1649 | { |
2a332745 | 1650 | theStyle = Aspect_IS_HATCH; |
ad3217cd | 1651 | } |
2a332745 | 1652 | else if (anArg == "hiddenline" |
1653 | || anArg == "hidden-line" | |
1654 | || anArg == "hidden_line") | |
ad3217cd | 1655 | { |
2a332745 | 1656 | theStyle = Aspect_IS_HIDDENLINE; |
ad3217cd | 1657 | } |
2a332745 | 1658 | else if (anArg == "point") |
ad3217cd | 1659 | { |
2a332745 | 1660 | theStyle = Aspect_IS_POINT; |
ad3217cd | 1661 | } |
2a332745 | 1662 | else if (theArg.IsIntegerValue()) |
ad3217cd | 1663 | { |
2a332745 | 1664 | const Standard_Integer anIntStyle = theArg.IntegerValue(); |
1665 | if (anIntStyle < Aspect_IS_EMPTY || anIntStyle > Aspect_IS_POINT) | |
ec7c343f | 1666 | { |
2a332745 | 1667 | return false; |
ec7c343f | 1668 | } |
2a332745 | 1669 | theStyle = (Aspect_InteriorStyle)anIntStyle; |
7fd59977 | 1670 | } |
2a332745 | 1671 | else |
ad3217cd | 1672 | { |
2a332745 | 1673 | return false; |
ad3217cd | 1674 | } |
2a332745 | 1675 | return true; |
ad3217cd | 1676 | } |
7fd59977 | 1677 | |
ad3217cd | 1678 | //! Auxiliary structure for VAspects |
1679 | struct ViewerTest_AspectsChangeSet | |
1680 | { | |
dc89236f | 1681 | Standard_Integer ToSetVisibility; |
1682 | Standard_Integer Visibility; | |
5bffb882 | 1683 | |
dc89236f | 1684 | Standard_Integer ToSetColor; |
1685 | Quantity_Color Color; | |
6b9b7e3c | 1686 | Standard_Integer ToSetBackFaceColor; |
1687 | Quantity_Color BackFaceColor; | |
ad3217cd | 1688 | |
dc89236f | 1689 | Standard_Integer ToSetLineWidth; |
1690 | Standard_Real LineWidth; | |
ad3217cd | 1691 | |
dc89236f | 1692 | Standard_Integer ToSetTypeOfLine; |
3f1675c9 | 1693 | uint16_t StippleLinePattern; |
e0b24437 | 1694 | uint16_t StippleLineFactor; |
ac116c22 | 1695 | |
dc89236f | 1696 | Standard_Integer ToSetTypeOfMarker; |
1697 | Aspect_TypeOfMarker TypeOfMarker; | |
1698 | Handle(Image_PixMap) MarkerImage; | |
33cc703b | 1699 | |
dc89236f | 1700 | Standard_Integer ToSetMarkerSize; |
1701 | Standard_Real MarkerSize; | |
33cc703b | 1702 | |
dc89236f | 1703 | Standard_Integer ToSetTransparency; |
1704 | Standard_Real Transparency; | |
ad3217cd | 1705 | |
c40eb6b9 | 1706 | Standard_Integer ToSetAlphaMode; |
1707 | Graphic3d_AlphaMode AlphaMode; | |
1708 | Standard_ShortReal AlphaCutoff; | |
1709 | ||
dc89236f | 1710 | Standard_Integer ToSetMaterial; |
1711 | Graphic3d_NameOfMaterial Material; | |
1712 | TCollection_AsciiString MatName; | |
ad3217cd | 1713 | |
1714 | NCollection_Sequence<TopoDS_Shape> SubShapes; | |
1715 | ||
dc89236f | 1716 | Standard_Integer ToSetShowFreeBoundary; |
1717 | Standard_Integer ToSetFreeBoundaryWidth; | |
1718 | Standard_Real FreeBoundaryWidth; | |
1719 | Standard_Integer ToSetFreeBoundaryColor; | |
1720 | Quantity_Color FreeBoundaryColor; | |
6262338c | 1721 | |
dc89236f | 1722 | Standard_Integer ToEnableIsoOnTriangulation; |
5ad8c033 | 1723 | |
0493ffd0 | 1724 | Standard_Integer ToSetFaceBoundaryDraw; |
1725 | Standard_Integer ToSetFaceBoundaryUpperContinuity; | |
1726 | GeomAbs_Shape FaceBoundaryUpperContinuity; | |
1727 | ||
1728 | Standard_Integer ToSetFaceBoundaryColor; | |
1729 | Quantity_Color FaceBoundaryColor; | |
1730 | ||
1731 | Standard_Integer ToSetFaceBoundaryWidth; | |
1732 | Standard_Real FaceBoundaryWidth; | |
1733 | ||
1734 | Standard_Integer ToSetTypeOfFaceBoundaryLine; | |
1735 | Aspect_TypeOfLine TypeOfFaceBoundaryLine; | |
1736 | ||
dc89236f | 1737 | Standard_Integer ToSetMaxParamValue; |
1738 | Standard_Real MaxParamValue; | |
5ad8c033 | 1739 | |
dc89236f | 1740 | Standard_Integer ToSetSensitivity; |
1741 | Standard_Integer SelectionMode; | |
1742 | Standard_Integer Sensitivity; | |
8a1170ad | 1743 | |
dc89236f | 1744 | Standard_Integer ToSetHatch; |
1745 | Standard_Integer StdHatchStyle; | |
1746 | TCollection_AsciiString PathToHatchPattern; | |
1747 | ||
1748 | Standard_Integer ToSetShadingModel; | |
1749 | Graphic3d_TypeOfShadingModel ShadingModel; | |
1750 | TCollection_AsciiString ShadingModelName; | |
640d5fe2 | 1751 | |
2a332745 | 1752 | Standard_Integer ToSetInterior; |
1753 | Aspect_InteriorStyle InteriorStyle; | |
1754 | ||
6ef0d6f1 | 1755 | Standard_Integer ToSetDrawSilhouette; |
1756 | ||
2a332745 | 1757 | Standard_Integer ToSetDrawEdges; |
1758 | Standard_Integer ToSetQuadEdges; | |
1759 | ||
1760 | Standard_Integer ToSetEdgeColor; | |
1761 | Quantity_ColorRGBA EdgeColor; | |
1762 | ||
1763 | Standard_Integer ToSetEdgeWidth; | |
1764 | Standard_Real EdgeWidth; | |
1765 | ||
1766 | Standard_Integer ToSetTypeOfEdge; | |
1767 | Aspect_TypeOfLine TypeOfEdge; | |
1768 | ||
ad3217cd | 1769 | //! Empty constructor |
1770 | ViewerTest_AspectsChangeSet() | |
5bffb882 | 1771 | : ToSetVisibility (0), |
1772 | Visibility (1), | |
1773 | ToSetColor (0), | |
ad3217cd | 1774 | Color (DEFAULT_COLOR), |
6b9b7e3c | 1775 | ToSetBackFaceColor(0), |
1776 | BackFaceColor (DEFAULT_COLOR), | |
ad3217cd | 1777 | ToSetLineWidth (0), |
1778 | LineWidth (1.0), | |
ac116c22 | 1779 | ToSetTypeOfLine (0), |
3f1675c9 | 1780 | StippleLinePattern(0xFFFF), |
e0b24437 | 1781 | StippleLineFactor (1), |
33cc703b | 1782 | ToSetTypeOfMarker (0), |
1783 | TypeOfMarker (Aspect_TOM_PLUS), | |
1784 | ToSetMarkerSize (0), | |
1785 | MarkerSize (1.0), | |
ad3217cd | 1786 | ToSetTransparency (0), |
1787 | Transparency (0.0), | |
c40eb6b9 | 1788 | ToSetAlphaMode (0), |
1789 | AlphaMode (Graphic3d_AlphaMode_BlendAuto), | |
1790 | AlphaCutoff (0.5f), | |
ad3217cd | 1791 | ToSetMaterial (0), |
a966542b | 1792 | Material (Graphic3d_NameOfMaterial_DEFAULT), |
5ad8c033 | 1793 | ToSetShowFreeBoundary (0), |
1794 | ToSetFreeBoundaryWidth (0), | |
1795 | FreeBoundaryWidth (1.0), | |
1796 | ToSetFreeBoundaryColor (0), | |
1797 | FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR), | |
0493ffd0 | 1798 | ToEnableIsoOnTriangulation (0), |
1799 | // | |
1800 | ToSetFaceBoundaryDraw (0), | |
1801 | ToSetFaceBoundaryUpperContinuity (0), | |
1802 | FaceBoundaryUpperContinuity(GeomAbs_CN), | |
1803 | ToSetFaceBoundaryColor (0), | |
1804 | FaceBoundaryColor (Quantity_NOC_BLACK), | |
1805 | ToSetFaceBoundaryWidth (0), | |
1806 | FaceBoundaryWidth (1.0f), | |
1807 | ToSetTypeOfFaceBoundaryLine(0), | |
1808 | TypeOfFaceBoundaryLine (Aspect_TOL_SOLID), | |
1809 | // | |
dc89236f | 1810 | ToSetMaxParamValue (0), |
1811 | MaxParamValue (500000), | |
1812 | ToSetSensitivity (0), | |
1813 | SelectionMode (-1), | |
1814 | Sensitivity (-1), | |
1815 | ToSetHatch (0), | |
1816 | StdHatchStyle (-1), | |
1817 | ToSetShadingModel (0), | |
2a332745 | 1818 | ShadingModel (Graphic3d_TOSM_DEFAULT), |
1819 | ToSetInterior (0), | |
1820 | InteriorStyle (Aspect_IS_SOLID), | |
6ef0d6f1 | 1821 | ToSetDrawSilhouette (0), |
2a332745 | 1822 | ToSetDrawEdges (0), |
1823 | ToSetQuadEdges (0), | |
1824 | ToSetEdgeColor (0), | |
1825 | ToSetEdgeWidth (0), | |
1826 | EdgeWidth (1.0), | |
1827 | ToSetTypeOfEdge (0), | |
1828 | TypeOfEdge (Aspect_TOL_SOLID) | |
640d5fe2 | 1829 | {} |
ad3217cd | 1830 | |
1831 | //! @return true if no changes have been requested | |
1832 | Standard_Boolean IsEmpty() const | |
1833 | { | |
6262338c | 1834 | return ToSetVisibility == 0 |
1835 | && ToSetLineWidth == 0 | |
1836 | && ToSetTransparency == 0 | |
c40eb6b9 | 1837 | && ToSetAlphaMode == 0 |
6262338c | 1838 | && ToSetColor == 0 |
6b9b7e3c | 1839 | && ToSetBackFaceColor == 0 |
6262338c | 1840 | && ToSetMaterial == 0 |
1841 | && ToSetShowFreeBoundary == 0 | |
1842 | && ToSetFreeBoundaryColor == 0 | |
5ad8c033 | 1843 | && ToSetFreeBoundaryWidth == 0 |
0493ffd0 | 1844 | && ToEnableIsoOnTriangulation == 0 |
1845 | && ToSetFaceBoundaryDraw == 0 | |
1846 | && ToSetFaceBoundaryUpperContinuity == 0 | |
1847 | && ToSetFaceBoundaryColor == 0 | |
1848 | && ToSetFaceBoundaryWidth == 0 | |
1849 | && ToSetTypeOfFaceBoundaryLine == 0 | |
8a1170ad | 1850 | && ToSetMaxParamValue == 0 |
640d5fe2 | 1851 | && ToSetSensitivity == 0 |
dc89236f | 1852 | && ToSetHatch == 0 |
2a332745 | 1853 | && ToSetShadingModel == 0 |
1854 | && ToSetInterior == 0 | |
6ef0d6f1 | 1855 | && ToSetDrawSilhouette == 0 |
2a332745 | 1856 | && ToSetDrawEdges == 0 |
1857 | && ToSetQuadEdges == 0 | |
1858 | && ToSetEdgeColor == 0 | |
1859 | && ToSetEdgeWidth == 0 | |
1860 | && ToSetTypeOfEdge == 0; | |
ad3217cd | 1861 | } |
1862 | ||
1863 | //! @return true if properties are valid | |
c1197a15 | 1864 | Standard_Boolean Validate() const |
ad3217cd | 1865 | { |
1866 | Standard_Boolean isOk = Standard_True; | |
5bffb882 | 1867 | if (Visibility != 0 && Visibility != 1) |
1868 | { | |
23fe70ec | 1869 | Message::SendFail() << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")"; |
5bffb882 | 1870 | isOk = Standard_False; |
1871 | } | |
ad3217cd | 1872 | if (LineWidth <= 0.0 |
1873 | || LineWidth > 10.0) | |
1874 | { | |
23fe70ec | 1875 | Message::SendFail() << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")"; |
ad3217cd | 1876 | isOk = Standard_False; |
7fd59977 | 1877 | } |
ad3217cd | 1878 | if (Transparency < 0.0 |
1879 | || Transparency > 1.0) | |
1880 | { | |
23fe70ec | 1881 | Message::SendFail() << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")"; |
ad3217cd | 1882 | isOk = Standard_False; |
1883 | } | |
c40eb6b9 | 1884 | if (ToSetAlphaMode == 1 |
1885 | && (AlphaCutoff <= 0.0f || AlphaCutoff >= 1.0f)) | |
1886 | { | |
23fe70ec | 1887 | Message::SendFail() << "Error: alpha cutoff value should be within (0; 1) range (specified " << AlphaCutoff << ")"; |
c40eb6b9 | 1888 | isOk = Standard_False; |
1889 | } | |
6262338c | 1890 | if (FreeBoundaryWidth <= 0.0 |
1891 | || FreeBoundaryWidth > 10.0) | |
1892 | { | |
23fe70ec | 1893 | Message::SendFail() << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")"; |
6262338c | 1894 | isOk = Standard_False; |
1895 | } | |
5ad8c033 | 1896 | if (MaxParamValue < 0.0) |
1897 | { | |
23fe70ec | 1898 | Message::SendFail() << "Error: the max parameter value should be greater than zero (specified " << MaxParamValue << ")"; |
5ad8c033 | 1899 | isOk = Standard_False; |
1900 | } | |
0038de11 | 1901 | if (Sensitivity < 0 && ToSetSensitivity) |
8a1170ad | 1902 | { |
0038de11 | 1903 | Message::SendFail() << "Error: sensitivity parameter value should not be negative (specified " << Sensitivity << ")"; |
8a1170ad | 1904 | isOk = Standard_False; |
1905 | } | |
640d5fe2 | 1906 | if (ToSetHatch == 1 && StdHatchStyle < 0 && PathToHatchPattern == "") |
1907 | { | |
23fe70ec | 1908 | Message::SendFail ("Error: hatch style must be specified"); |
640d5fe2 | 1909 | isOk = Standard_False; |
1910 | } | |
dc89236f | 1911 | if (ToSetShadingModel == 1 |
67312b79 | 1912 | && (ShadingModel < Graphic3d_TOSM_DEFAULT || ShadingModel > Graphic3d_TOSM_PBR_FACET)) |
dc89236f | 1913 | { |
23fe70ec | 1914 | Message::SendFail() << "Error: unknown shading model " << ShadingModelName << "."; |
dc89236f | 1915 | isOk = Standard_False; |
1916 | } | |
ad3217cd | 1917 | return isOk; |
7fd59977 | 1918 | } |
7fd59977 | 1919 | |
2a332745 | 1920 | //! Apply aspects to specified drawer. |
1921 | bool Apply (const Handle(Prs3d_Drawer)& theDrawer) | |
1922 | { | |
1923 | bool toRecompute = false; | |
1924 | const Handle(Prs3d_Drawer)& aDefDrawer = ViewerTest::GetAISContext()->DefaultDrawer(); | |
1925 | if (ToSetShowFreeBoundary != 0) | |
1926 | { | |
1927 | theDrawer->SetFreeBoundaryDraw (ToSetShowFreeBoundary == 1); | |
1928 | toRecompute = true; | |
1929 | } | |
1930 | if (ToSetFreeBoundaryWidth != 0) | |
1931 | { | |
1932 | if (ToSetFreeBoundaryWidth != -1 | |
1933 | || theDrawer->HasOwnFreeBoundaryAspect()) | |
1934 | { | |
1935 | if (!theDrawer->HasOwnFreeBoundaryAspect()) | |
1936 | { | |
1937 | Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0); | |
1938 | *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect(); | |
1939 | theDrawer->SetFreeBoundaryAspect (aBoundaryAspect); | |
1940 | toRecompute = true; | |
1941 | } | |
1942 | theDrawer->FreeBoundaryAspect()->SetWidth (FreeBoundaryWidth); | |
1943 | } | |
1944 | } | |
1945 | if (ToSetFreeBoundaryColor != 0) | |
1946 | { | |
1947 | Handle(Prs3d_LineAspect) aBoundaryAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0); | |
1948 | *aBoundaryAspect->Aspect() = *theDrawer->FreeBoundaryAspect()->Aspect(); | |
1949 | aBoundaryAspect->SetColor (FreeBoundaryColor); | |
1950 | theDrawer->SetFreeBoundaryAspect (aBoundaryAspect); | |
1951 | toRecompute = true; | |
1952 | } | |
1953 | if (ToSetTypeOfLine != 0) | |
1954 | { | |
1955 | if (ToSetTypeOfLine != -1 | |
1956 | || theDrawer->HasOwnLineAspect() | |
1957 | || theDrawer->HasOwnWireAspect() | |
1958 | || theDrawer->HasOwnFreeBoundaryAspect() | |
1959 | || theDrawer->HasOwnUnFreeBoundaryAspect() | |
1960 | || theDrawer->HasOwnSeenLineAspect()) | |
1961 | { | |
1962 | toRecompute = theDrawer->SetOwnLineAspects() || toRecompute; | |
3f1675c9 | 1963 | theDrawer->LineAspect()->Aspect()->SetLinePattern (StippleLinePattern); |
e0b24437 | 1964 | theDrawer->LineAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor); |
3f1675c9 | 1965 | theDrawer->WireAspect()->Aspect()->SetLinePattern (StippleLinePattern); |
e0b24437 | 1966 | theDrawer->WireAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor); |
3f1675c9 | 1967 | theDrawer->FreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern); |
e0b24437 | 1968 | theDrawer->FreeBoundaryAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor); |
3f1675c9 | 1969 | theDrawer->UnFreeBoundaryAspect()->Aspect()->SetLinePattern (StippleLinePattern); |
e0b24437 | 1970 | theDrawer->UnFreeBoundaryAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor); |
3f1675c9 | 1971 | theDrawer->SeenLineAspect()->Aspect()->SetLinePattern (StippleLinePattern); |
e0b24437 | 1972 | theDrawer->SeenLineAspect()->Aspect()->SetLineStippleFactor (StippleLineFactor); |
2a332745 | 1973 | } |
1974 | } | |
1975 | if (ToSetTypeOfMarker != 0) | |
1976 | { | |
1977 | if (ToSetTypeOfMarker != -1 | |
1978 | || theDrawer->HasOwnPointAspect()) | |
1979 | { | |
1980 | toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute; | |
1981 | theDrawer->PointAspect()->SetTypeOfMarker (TypeOfMarker); | |
1982 | theDrawer->PointAspect()->Aspect()->SetMarkerImage (MarkerImage.IsNull() ? Handle(Graphic3d_MarkerImage)() : new Graphic3d_MarkerImage (MarkerImage)); | |
1983 | } | |
1984 | } | |
1985 | if (ToSetMarkerSize != 0) | |
1986 | { | |
1987 | if (ToSetMarkerSize != -1 | |
1988 | || theDrawer->HasOwnPointAspect()) | |
1989 | { | |
1990 | toRecompute = theDrawer->SetupOwnPointAspect (aDefDrawer) || toRecompute; | |
1991 | theDrawer->PointAspect()->SetScale (MarkerSize); | |
1992 | toRecompute = true; | |
1993 | } | |
1994 | } | |
1995 | if (ToSetMaxParamValue != 0) | |
1996 | { | |
1997 | if (ToSetMaxParamValue != -1 | |
1998 | || theDrawer->HasOwnMaximalParameterValue()) | |
1999 | { | |
2000 | theDrawer->SetMaximalParameterValue (MaxParamValue); | |
2001 | toRecompute = true; | |
2002 | } | |
2003 | } | |
0493ffd0 | 2004 | if (ToSetFaceBoundaryDraw != 0) |
2005 | { | |
2006 | if (ToSetFaceBoundaryDraw != -1 | |
2007 | || theDrawer->HasOwnFaceBoundaryDraw()) | |
2008 | { | |
2009 | toRecompute = true; | |
2010 | theDrawer->SetFaceBoundaryDraw (ToSetFaceBoundaryDraw == 1); | |
2011 | } | |
2012 | } | |
2013 | if (ToSetFaceBoundaryUpperContinuity != 0) | |
2014 | { | |
2015 | if (ToSetFaceBoundaryUpperContinuity != -1 | |
2016 | || theDrawer->HasOwnFaceBoundaryUpperContinuity()) | |
2017 | { | |
2018 | toRecompute = true; | |
2019 | if (ToSetFaceBoundaryUpperContinuity == -1) | |
2020 | { | |
2021 | theDrawer->UnsetFaceBoundaryUpperContinuity(); | |
2022 | } | |
2023 | else | |
2024 | { | |
2025 | theDrawer->SetFaceBoundaryUpperContinuity (FaceBoundaryUpperContinuity); | |
2026 | } | |
2027 | } | |
2028 | } | |
2029 | if (ToSetFaceBoundaryColor != 0) | |
2030 | { | |
2031 | if (ToSetFaceBoundaryColor != -1 | |
2032 | || theDrawer->HasOwnFaceBoundaryAspect()) | |
2033 | { | |
2034 | if (ToSetFaceBoundaryColor == -1) | |
2035 | { | |
2036 | toRecompute = true; | |
2037 | theDrawer->SetFaceBoundaryAspect (Handle(Prs3d_LineAspect)()); | |
2038 | } | |
2039 | else | |
2040 | { | |
2041 | toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute; | |
2042 | theDrawer->FaceBoundaryAspect()->SetColor (FaceBoundaryColor); | |
2043 | } | |
2044 | } | |
2045 | } | |
2046 | if (ToSetFaceBoundaryWidth != 0) | |
2047 | { | |
2048 | if (ToSetFaceBoundaryWidth != -1 | |
2049 | || theDrawer->HasOwnFaceBoundaryAspect()) | |
2050 | { | |
2051 | toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute; | |
2052 | theDrawer->FaceBoundaryAspect()->SetWidth (FaceBoundaryWidth); | |
2053 | } | |
2054 | } | |
2055 | if (ToSetTypeOfFaceBoundaryLine != 0) | |
2056 | { | |
2057 | if (ToSetTypeOfFaceBoundaryLine != -1 | |
2058 | || theDrawer->HasOwnFaceBoundaryAspect()) | |
2059 | { | |
2060 | toRecompute = theDrawer->SetupOwnFaceBoundaryAspect (aDefDrawer) || toRecompute; | |
2061 | theDrawer->FaceBoundaryAspect()->SetTypeOfLine (TypeOfFaceBoundaryLine); | |
2062 | } | |
2063 | } | |
2a332745 | 2064 | if (ToSetShadingModel != 0) |
2065 | { | |
2066 | if (ToSetShadingModel != -1 | |
2067 | || theDrawer->HasOwnShadingAspect()) | |
2068 | { | |
2069 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2070 | theDrawer->ShadingAspect()->Aspect()->SetShadingModel (ShadingModel); | |
2071 | } | |
2072 | } | |
6b9b7e3c | 2073 | if (ToSetBackFaceColor != 0) |
2074 | { | |
2075 | if (ToSetBackFaceColor != -1 | |
2076 | || theDrawer->HasOwnShadingAspect()) | |
2077 | { | |
2078 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2079 | theDrawer->ShadingAspect()->SetColor (BackFaceColor, Aspect_TOFM_BACK_SIDE); | |
2080 | } | |
2081 | } | |
2a332745 | 2082 | if (ToSetAlphaMode != 0) |
2083 | { | |
2084 | if (ToSetAlphaMode != -1 | |
2085 | || theDrawer->HasOwnShadingAspect()) | |
2086 | { | |
2087 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2088 | theDrawer->ShadingAspect()->Aspect()->SetAlphaMode (AlphaMode, AlphaCutoff); | |
2089 | } | |
2090 | } | |
2091 | if (ToSetHatch != 0) | |
2092 | { | |
2093 | if (ToSetHatch != -1 | |
2094 | || theDrawer->HasOwnShadingAspect()) | |
2095 | { | |
2096 | theDrawer->SetupOwnShadingAspect (aDefDrawer); | |
2097 | Handle(Graphic3d_AspectFillArea3d) anAsp = theDrawer->ShadingAspect()->Aspect(); | |
2098 | if (ToSetHatch == -1) | |
2099 | { | |
2100 | anAsp->SetInteriorStyle (Aspect_IS_SOLID); | |
2101 | } | |
2102 | else | |
2103 | { | |
2104 | anAsp->SetInteriorStyle (Aspect_IS_HATCH); | |
2105 | if (!PathToHatchPattern.IsEmpty()) | |
2106 | { | |
2107 | Handle(Image_AlienPixMap) anImage = new Image_AlienPixMap(); | |
2108 | if (anImage->Load (TCollection_AsciiString (PathToHatchPattern.ToCString()))) | |
2109 | { | |
2110 | anAsp->SetHatchStyle (new Graphic3d_HatchStyle (anImage)); | |
2111 | } | |
2112 | else | |
2113 | { | |
23fe70ec | 2114 | Message::SendFail() << "Error: cannot load the following image: " << PathToHatchPattern; |
2a332745 | 2115 | } |
2116 | } | |
2117 | else if (StdHatchStyle != -1) | |
2118 | { | |
2119 | anAsp->SetHatchStyle (new Graphic3d_HatchStyle ((Aspect_HatchStyle)StdHatchStyle)); | |
2120 | } | |
2121 | } | |
2122 | toRecompute = true; | |
2123 | } | |
2124 | } | |
2125 | if (ToSetInterior != 0) | |
2126 | { | |
2127 | if (ToSetInterior != -1 | |
2128 | || theDrawer->HasOwnShadingAspect()) | |
2129 | { | |
2130 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2131 | theDrawer->ShadingAspect()->Aspect()->SetInteriorStyle (InteriorStyle); | |
2132 | if (InteriorStyle == Aspect_IS_HATCH | |
2133 | && theDrawer->ShadingAspect()->Aspect()->HatchStyle().IsNull()) | |
2134 | { | |
2135 | theDrawer->ShadingAspect()->Aspect()->SetHatchStyle (Aspect_HS_VERTICAL); | |
2136 | } | |
2137 | } | |
2138 | } | |
6ef0d6f1 | 2139 | if (ToSetDrawSilhouette != 0) |
2140 | { | |
2141 | if (ToSetDrawSilhouette != -1 | |
2142 | || theDrawer->HasOwnShadingAspect()) | |
2143 | { | |
2144 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2145 | theDrawer->ShadingAspect()->Aspect()->SetDrawSilhouette (ToSetDrawSilhouette == 1); | |
2146 | } | |
2147 | } | |
2a332745 | 2148 | if (ToSetDrawEdges != 0) |
2149 | { | |
2150 | if (ToSetDrawEdges != -1 | |
2151 | || theDrawer->HasOwnShadingAspect()) | |
2152 | { | |
2153 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2154 | theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetDrawEdges == 1); | |
2155 | } | |
2156 | } | |
2157 | if (ToSetQuadEdges != 0) | |
2158 | { | |
2159 | if (ToSetQuadEdges != -1 | |
2160 | || theDrawer->HasOwnShadingAspect()) | |
2161 | { | |
2162 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2163 | theDrawer->ShadingAspect()->Aspect()->SetSkipFirstEdge (ToSetQuadEdges == 1); | |
2164 | } | |
2165 | } | |
2166 | if (ToSetEdgeWidth != 0) | |
2167 | { | |
2168 | if (ToSetEdgeWidth != -1 | |
2169 | || theDrawer->HasOwnShadingAspect()) | |
2170 | { | |
2171 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2172 | theDrawer->ShadingAspect()->Aspect()->SetEdgeWidth (EdgeWidth); | |
2173 | } | |
2174 | } | |
2175 | if (ToSetTypeOfEdge != 0) | |
2176 | { | |
2177 | if (ToSetTypeOfEdge != -1 | |
2178 | || theDrawer->HasOwnShadingAspect()) | |
2179 | { | |
2180 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2181 | theDrawer->ShadingAspect()->Aspect()->SetEdgeLineType (TypeOfEdge); | |
2182 | if (ToSetInterior == 0) | |
2183 | { | |
2184 | theDrawer->ShadingAspect()->Aspect()->SetDrawEdges (ToSetTypeOfEdge == 1 | |
2185 | && TypeOfEdge != Aspect_TOL_EMPTY); | |
2186 | } | |
2187 | } | |
2188 | } | |
2189 | if (ToSetEdgeColor != 0) | |
2190 | { | |
2191 | if (ToSetEdgeColor != -1 | |
2192 | || theDrawer->HasOwnShadingAspect()) | |
2193 | { | |
2194 | toRecompute = theDrawer->SetupOwnShadingAspect (aDefDrawer) || toRecompute; | |
2195 | if (ToSetEdgeColor == -1) | |
2196 | { | |
2197 | theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (theDrawer->ShadingAspect()->Aspect()->InteriorColor()); | |
2198 | } | |
2199 | else | |
2200 | { | |
2201 | theDrawer->ShadingAspect()->Aspect()->SetEdgeColor (EdgeColor); | |
2202 | } | |
2203 | } | |
2204 | } | |
2205 | return toRecompute; | |
2206 | } | |
ad3217cd | 2207 | }; |
7fd59977 | 2208 | |
2209 | //============================================================================== | |
ad3217cd | 2210 | //function : VAspects |
2211 | //purpose : | |
7fd59977 | 2212 | //============================================================================== |
0904aa63 | 2213 | static Standard_Integer VAspects (Draw_Interpretor& theDI, |
ad3217cd | 2214 | Standard_Integer theArgNb, |
2215 | const char** theArgVec) | |
7fd59977 | 2216 | { |
ad3217cd | 2217 | TCollection_AsciiString aCmdName (theArgVec[0]); |
2218 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
4e18052b | 2219 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
ad3217cd | 2220 | if (aCtx.IsNull()) |
2221 | { | |
23fe70ec | 2222 | Message::SendFail ("Error: no active view!"); |
ad3217cd | 2223 | return 1; |
2224 | } | |
7fd59977 | 2225 | |
4e18052b | 2226 | Standard_Integer anArgIter = 1; |
6262338c | 2227 | Standard_Boolean isDefaults = Standard_False; |
ad3217cd | 2228 | NCollection_Sequence<TCollection_AsciiString> aNames; |
2229 | for (; anArgIter < theArgNb; ++anArgIter) | |
2230 | { | |
2231 | TCollection_AsciiString anArg = theArgVec[anArgIter]; | |
4e18052b | 2232 | if (anUpdateTool.parseRedrawMode (anArg)) |
ad3217cd | 2233 | { |
2234 | continue; | |
2235 | } | |
2236 | else if (!anArg.IsEmpty() | |
2237 | && anArg.Value (1) != '-') | |
2238 | { | |
2239 | aNames.Append (anArg); | |
2240 | } | |
2241 | else | |
2242 | { | |
6262338c | 2243 | if (anArg == "-defaults") |
2244 | { | |
2245 | isDefaults = Standard_True; | |
2246 | ++anArgIter; | |
2247 | } | |
ad3217cd | 2248 | break; |
2249 | } | |
2250 | } | |
2251 | ||
6262338c | 2252 | if (!aNames.IsEmpty() && isDefaults) |
2253 | { | |
23fe70ec | 2254 | Message::SendFail ("Error: wrong syntax. If -defaults is used there should not be any objects' names!"); |
6262338c | 2255 | return 1; |
2256 | } | |
2257 | ||
ad3217cd | 2258 | NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges; |
2259 | aChanges.Append (ViewerTest_AspectsChangeSet()); | |
2260 | ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast(); | |
7fd59977 | 2261 | |
ad3217cd | 2262 | // parse syntax of legacy commands |
2a332745 | 2263 | bool toParseAliasArgs = false; |
0904aa63 | 2264 | Standard_Boolean toDump = 0; |
2265 | Standard_Boolean toCompactDump = 0; | |
2266 | Standard_Integer aDumpDepth = -1; | |
ad3217cd | 2267 | if (aCmdName == "vsetwidth") |
2268 | { | |
2269 | if (aNames.IsEmpty() | |
d45edf24 | 2270 | || !aNames.Last().IsRealValue (Standard_True)) |
ad3217cd | 2271 | { |
23fe70ec | 2272 | Message::SendFail ("Error: not enough arguments!"); |
ad3217cd | 2273 | return 1; |
2274 | } | |
2275 | aChangeSet->ToSetLineWidth = 1; | |
2276 | aChangeSet->LineWidth = aNames.Last().RealValue(); | |
2277 | aNames.Remove (aNames.Length()); | |
7fd59977 | 2278 | } |
ad3217cd | 2279 | else if (aCmdName == "vunsetwidth") |
2280 | { | |
2281 | aChangeSet->ToSetLineWidth = -1; | |
2282 | } | |
2283 | else if (aCmdName == "vsetcolor") | |
2284 | { | |
2285 | if (aNames.IsEmpty()) | |
2286 | { | |
23fe70ec | 2287 | Message::SendFail ("Error: not enough arguments!"); |
ad3217cd | 2288 | return 1; |
2289 | } | |
2290 | aChangeSet->ToSetColor = 1; | |
8316c618 | 2291 | |
2292 | Quantity_NameOfColor aColor = Quantity_NOC_BLACK; | |
2293 | Standard_Boolean isOk = Standard_False; | |
2294 | if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor)) | |
2295 | { | |
2296 | aChangeSet->Color = aColor; | |
2297 | aNames.Remove (aNames.Length()); | |
9196ea9d | 2298 | isOk = Standard_True; |
2299 | } | |
2300 | else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color)) | |
2301 | { | |
2302 | aNames.Remove (aNames.Length()); | |
8316c618 | 2303 | isOk = Standard_True; |
2304 | } | |
2305 | else if (aNames.Length() >= 3) | |
2306 | { | |
2a332745 | 2307 | const char* anArgVec[3] = |
8316c618 | 2308 | { |
2a332745 | 2309 | aNames.Value (aNames.Upper() - 2).ToCString(), |
2310 | aNames.Value (aNames.Upper() - 1).ToCString(), | |
2311 | aNames.Value (aNames.Upper() - 0).ToCString(), | |
8316c618 | 2312 | }; |
2a332745 | 2313 | |
dae2a922 | 2314 | Standard_Integer aNbParsed = Draw::ParseColor (3, anArgVec, aChangeSet->Color); |
2a332745 | 2315 | isOk = aNbParsed == 3; |
2316 | aNames.Remove (aNames.Length()); | |
2317 | aNames.Remove (aNames.Length()); | |
2318 | aNames.Remove (aNames.Length()); | |
8316c618 | 2319 | } |
2320 | if (!isOk) | |
2321 | { | |
23fe70ec | 2322 | Message::SendFail ("Error: not enough arguments!"); |
8316c618 | 2323 | return 1; |
2324 | } | |
ad3217cd | 2325 | } |
2326 | else if (aCmdName == "vunsetcolor") | |
2327 | { | |
2328 | aChangeSet->ToSetColor = -1; | |
2329 | } | |
2330 | else if (aCmdName == "vsettransparency") | |
2331 | { | |
2332 | if (aNames.IsEmpty() | |
d45edf24 | 2333 | || !aNames.Last().IsRealValue (Standard_True)) |
ad3217cd | 2334 | { |
23fe70ec | 2335 | Message::SendFail ("Error: not enough arguments!"); |
ad3217cd | 2336 | return 1; |
2337 | } | |
2338 | aChangeSet->ToSetTransparency = 1; | |
2339 | aChangeSet->Transparency = aNames.Last().RealValue(); | |
2340 | aNames.Remove (aNames.Length()); | |
2341 | } | |
2342 | else if (aCmdName == "vunsettransparency") | |
2343 | { | |
2344 | aChangeSet->ToSetTransparency = -1; | |
2345 | } | |
2346 | else if (aCmdName == "vsetmaterial") | |
2347 | { | |
2348 | if (aNames.IsEmpty()) | |
2349 | { | |
23fe70ec | 2350 | Message::SendFail ("Error: not enough arguments!"); |
ad3217cd | 2351 | return 1; |
2352 | } | |
2353 | aChangeSet->ToSetMaterial = 1; | |
61168418 | 2354 | aChangeSet->MatName = aNames.Last(); |
ad3217cd | 2355 | aNames.Remove (aNames.Length()); |
61168418 | 2356 | if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material)) |
2357 | { | |
23fe70ec | 2358 | Message::SendFail() << "Syntax error: unknown material '" << aChangeSet->MatName << "'."; |
61168418 | 2359 | return 1; |
2360 | } | |
ad3217cd | 2361 | } |
2362 | else if (aCmdName == "vunsetmaterial") | |
2363 | { | |
2364 | aChangeSet->ToSetMaterial = -1; | |
2365 | } | |
2a332745 | 2366 | else if (aCmdName == "vsetinteriorstyle") |
2367 | { | |
2368 | if (aNames.IsEmpty() | |
d45edf24 | 2369 | || !aNames.Last().IsRealValue (Standard_True)) |
2a332745 | 2370 | { |
23fe70ec | 2371 | Message::SendFail ("Error: not enough arguments!"); |
2a332745 | 2372 | return 1; |
2373 | } | |
2374 | aChangeSet->ToSetInterior = 1; | |
2375 | if (!parseInteriorStyle (aNames.Last(), aChangeSet->InteriorStyle)) | |
2376 | { | |
23fe70ec | 2377 | Message::SendFail() << "Error: wrong syntax at " << aNames.Last(); |
2a332745 | 2378 | return 1; |
2379 | } | |
2380 | aNames.Remove (aNames.Length()); | |
2381 | } | |
2382 | else if (aCmdName == "vsetedgetype") | |
2383 | { | |
2384 | aChangeSet->ToSetDrawEdges = 1; | |
2385 | toParseAliasArgs = true; | |
2386 | } | |
2387 | else if (aCmdName == "vunsetedgetype") | |
2388 | { | |
2389 | aChangeSet->ToSetDrawEdges = -1; | |
2390 | aChangeSet->ToSetEdgeColor = -1; | |
2391 | aChangeSet->ToSetTypeOfEdge = -1; | |
2392 | aChangeSet->TypeOfEdge = Aspect_TOL_SOLID; | |
2393 | } | |
0493ffd0 | 2394 | else if (aCmdName == "vshowfaceboundary") |
2395 | { | |
2396 | aChangeSet->ToSetFaceBoundaryDraw = 1; | |
2397 | toParseAliasArgs = true; | |
2398 | if (aNames.Size() >= 2 | |
2399 | && aNames.Value (2).IsIntegerValue()) | |
2400 | { | |
2401 | if (aNames.Size() == 7) | |
2402 | { | |
2403 | if (ViewerTest::ParseLineType (aNames.Value (7).ToCString(), aChangeSet->TypeOfFaceBoundaryLine)) | |
2404 | { | |
2405 | aChangeSet->ToSetTypeOfFaceBoundaryLine = 1; | |
2406 | aNames.Remove (7); | |
2407 | } | |
2408 | } | |
2409 | if (aNames.Size() == 6 | |
d45edf24 | 2410 | && aNames.Value (6).IsRealValue (Standard_True)) |
0493ffd0 | 2411 | { |
2412 | aChangeSet->ToSetFaceBoundaryWidth = 1; | |
2413 | aChangeSet->FaceBoundaryWidth = aNames.Value (6).RealValue(); | |
2414 | aNames.Remove (6); | |
2415 | } | |
2416 | if (aNames.Size() == 5 | |
2417 | && aNames.Value (3).IsIntegerValue() | |
2418 | && aNames.Value (4).IsIntegerValue() | |
2419 | && aNames.Value (5).IsIntegerValue()) | |
2420 | { | |
2421 | aChangeSet->ToSetFaceBoundaryColor = 1; | |
2422 | aChangeSet->FaceBoundaryColor = Quantity_Color (aNames.Value (3).IntegerValue() / 255.0, | |
2423 | aNames.Value (4).IntegerValue() / 255.0, | |
2424 | aNames.Value (5).IntegerValue() / 255.0, | |
ba00aab7 | 2425 | Quantity_TOC_sRGB); |
0493ffd0 | 2426 | aNames.Remove (5); |
2427 | aNames.Remove (4); | |
2428 | aNames.Remove (3); | |
2429 | } | |
2430 | if (aNames.Size() == 2) | |
2431 | { | |
2432 | toParseAliasArgs = false; | |
2433 | aChangeSet->ToSetFaceBoundaryDraw = aNames.Value (2).IntegerValue() == 1 ? 1 : -1; | |
2434 | aNames.Remove (2); | |
2435 | } | |
2436 | } | |
2437 | } | |
ad3217cd | 2438 | else if (anArgIter >= theArgNb) |
2439 | { | |
23fe70ec | 2440 | Message::SendFail ("Error: not enough arguments!"); |
ad3217cd | 2441 | return 1; |
7fd59977 | 2442 | } |
2443 | ||
2a332745 | 2444 | if (!aChangeSet->IsEmpty() |
2445 | && !toParseAliasArgs) | |
ad3217cd | 2446 | { |
2447 | anArgIter = theArgNb; | |
2448 | } | |
2449 | for (; anArgIter < theArgNb; ++anArgIter) | |
2450 | { | |
2451 | TCollection_AsciiString anArg = theArgVec[anArgIter]; | |
2452 | anArg.LowerCase(); | |
2453 | if (anArg == "-setwidth" | |
2a332745 | 2454 | || anArg == "-width" |
2455 | || anArg == "-setlinewidth" | |
2456 | || anArg == "-linewidth" | |
2457 | || anArg == "-setedgewidth" | |
2458 | || anArg == "-setedgeswidth" | |
2459 | || anArg == "-edgewidth" | |
0493ffd0 | 2460 | || anArg == "-edgeswidth" |
2461 | || anArg == "-setfaceboundarywidth" | |
2462 | || anArg == "-setboundarywidth" | |
2463 | || anArg == "-faceboundarywidth" | |
2464 | || anArg == "-boundarywidth") | |
ad3217cd | 2465 | { |
2466 | if (++anArgIter >= theArgNb) | |
2467 | { | |
23fe70ec | 2468 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
ad3217cd | 2469 | return 1; |
2470 | } | |
0493ffd0 | 2471 | |
2472 | const Standard_Real aWidth = Draw::Atof (theArgVec[anArgIter]); | |
2a332745 | 2473 | if (anArg == "-setedgewidth" |
2474 | || anArg == "-setedgeswidth" | |
2475 | || anArg == "-edgewidth" | |
2476 | || anArg == "-edgeswidth" | |
2477 | || aCmdName == "vsetedgetype") | |
2478 | { | |
2479 | aChangeSet->ToSetEdgeWidth = 1; | |
0493ffd0 | 2480 | aChangeSet->EdgeWidth = aWidth; |
2481 | } | |
2482 | else if (anArg == "-setfaceboundarywidth" | |
2483 | || anArg == "-setboundarywidth" | |
2484 | || anArg == "-faceboundarywidth" | |
2485 | || anArg == "-boundarywidth" | |
2486 | || aCmdName == "vshowfaceboundary") | |
2487 | { | |
2488 | aChangeSet->ToSetFaceBoundaryWidth = 1; | |
2489 | aChangeSet->FaceBoundaryWidth = aWidth; | |
2a332745 | 2490 | } |
2491 | else | |
2492 | { | |
2493 | aChangeSet->ToSetLineWidth = 1; | |
0493ffd0 | 2494 | aChangeSet->LineWidth = aWidth; |
2a332745 | 2495 | } |
7fd59977 | 2496 | } |
ad3217cd | 2497 | else if (anArg == "-unsetwidth" |
2a332745 | 2498 | || anArg == "-unsetlinewidth" |
2499 | || anArg == "-unsetedgewidth") | |
ad3217cd | 2500 | { |
2a332745 | 2501 | if (anArg == "-unsetedgewidth") |
2502 | { | |
2503 | aChangeSet->ToSetEdgeWidth = -1; | |
2504 | aChangeSet->EdgeWidth = 1.0; | |
2505 | } | |
2506 | else | |
2507 | { | |
2508 | aChangeSet->ToSetLineWidth = -1; | |
2509 | aChangeSet->LineWidth = 1.0; | |
2510 | } | |
ad3217cd | 2511 | } |
2512 | else if (anArg == "-settransp" | |
2a332745 | 2513 | || anArg == "-settransparency" |
2514 | || anArg == "-transparency" | |
2515 | || anArg == "-transp") | |
ad3217cd | 2516 | { |
2517 | if (++anArgIter >= theArgNb) | |
2518 | { | |
23fe70ec | 2519 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
ad3217cd | 2520 | return 1; |
2521 | } | |
2522 | aChangeSet->ToSetTransparency = 1; | |
2523 | aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); | |
2524 | if (aChangeSet->Transparency >= 0.0 | |
2525 | && aChangeSet->Transparency <= Precision::Confusion()) | |
2526 | { | |
2527 | aChangeSet->ToSetTransparency = -1; | |
2528 | aChangeSet->Transparency = 0.0; | |
eafb234b | 2529 | } |
7fd59977 | 2530 | } |
2a332745 | 2531 | else if (anArg == "-setalphamode" |
2532 | || anArg == "-alphamode") | |
c40eb6b9 | 2533 | { |
2534 | if (++anArgIter >= theArgNb) | |
2535 | { | |
23fe70ec | 2536 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
c40eb6b9 | 2537 | return 1; |
2538 | } | |
2539 | aChangeSet->ToSetAlphaMode = 1; | |
2540 | aChangeSet->AlphaCutoff = 0.5f; | |
2541 | { | |
2542 | TCollection_AsciiString aParam (theArgVec[anArgIter]); | |
2543 | aParam.LowerCase(); | |
2544 | if (aParam == "opaque") | |
2545 | { | |
2546 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_Opaque; | |
2547 | } | |
2548 | else if (aParam == "mask") | |
2549 | { | |
2550 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_Mask; | |
2551 | } | |
2552 | else if (aParam == "blend") | |
2553 | { | |
2554 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_Blend; | |
2555 | } | |
33425a46 | 2556 | else if (aParam == "maskblend" |
2557 | || aParam == "blendmask") | |
2558 | { | |
2559 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_MaskBlend; | |
2560 | } | |
c40eb6b9 | 2561 | else if (aParam == "blendauto" |
2562 | || aParam == "auto") | |
2563 | { | |
2564 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto; | |
2565 | } | |
2566 | else | |
2567 | { | |
23fe70ec | 2568 | Message::SendFail() << "Error: wrong syntax at " << aParam; |
c40eb6b9 | 2569 | return 1; |
2570 | } | |
2571 | } | |
2572 | ||
2573 | if (anArgIter + 1 < theArgNb | |
2574 | && theArgVec[anArgIter + 1][0] != '-') | |
2575 | { | |
2576 | TCollection_AsciiString aParam2 (theArgVec[anArgIter + 1]); | |
d45edf24 | 2577 | if (aParam2.IsRealValue (Standard_True)) |
c40eb6b9 | 2578 | { |
2579 | aChangeSet->AlphaCutoff = (float )aParam2.RealValue(); | |
2580 | ++anArgIter; | |
2581 | } | |
2582 | } | |
2583 | } | |
5bffb882 | 2584 | else if (anArg == "-setvis" |
2a332745 | 2585 | || anArg == "-setvisibility" |
2586 | || anArg == "-visibility") | |
5bffb882 | 2587 | { |
2588 | if (++anArgIter >= theArgNb) | |
2589 | { | |
23fe70ec | 2590 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
5bffb882 | 2591 | return 1; |
2592 | } | |
2593 | ||
2594 | aChangeSet->ToSetVisibility = 1; | |
2595 | aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]); | |
2596 | } | |
2a332745 | 2597 | else if (anArg == "-setalpha" |
2598 | || anArg == "-alpha") | |
ad3217cd | 2599 | { |
2600 | if (++anArgIter >= theArgNb) | |
7fd59977 | 2601 | { |
23fe70ec | 2602 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
ad3217cd | 2603 | return 1; |
2604 | } | |
2605 | aChangeSet->ToSetTransparency = 1; | |
2606 | aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); | |
2607 | if (aChangeSet->Transparency < 0.0 | |
2608 | || aChangeSet->Transparency > 1.0) | |
2609 | { | |
23fe70ec | 2610 | Message::SendFail() << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")"; |
ad3217cd | 2611 | return 1; |
2612 | } | |
2613 | aChangeSet->Transparency = 1.0 - aChangeSet->Transparency; | |
2614 | if (aChangeSet->Transparency >= 0.0 | |
2615 | && aChangeSet->Transparency <= Precision::Confusion()) | |
2616 | { | |
2617 | aChangeSet->ToSetTransparency = -1; | |
2618 | aChangeSet->Transparency = 0.0; | |
7fd59977 | 2619 | } |
7fd59977 | 2620 | } |
ad3217cd | 2621 | else if (anArg == "-unsettransp" |
0ae61cf3 | 2622 | || anArg == "-unsettransparency" |
ad3217cd | 2623 | || anArg == "-unsetalpha" |
2624 | || anArg == "-opaque") | |
2625 | { | |
2626 | aChangeSet->ToSetTransparency = -1; | |
2627 | aChangeSet->Transparency = 0.0; | |
2628 | } | |
2a332745 | 2629 | else if (anArg == "-setcolor" |
0493ffd0 | 2630 | || anArg == "-color" |
6b9b7e3c | 2631 | || anArg == "-setbackfacecolor" |
2632 | || anArg == "-backfacecolor" | |
2633 | || anArg == "-setbackcolor" | |
2634 | || anArg == "-backcolor" | |
0493ffd0 | 2635 | || anArg == "-setfaceboundarycolor" |
2636 | || anArg == "-setboundarycolor" | |
2637 | || anArg == "-faceboundarycolor" | |
2638 | || anArg == "-boundarycolor") | |
ad3217cd | 2639 | { |
2a332745 | 2640 | Quantity_Color aColor; |
dae2a922 | 2641 | Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1, |
2642 | theArgVec + anArgIter + 1, | |
2643 | aColor); | |
2a332745 | 2644 | if (aNbParsed == 0) |
ad3217cd | 2645 | { |
23fe70ec | 2646 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
2a332745 | 2647 | return 1; |
8316c618 | 2648 | } |
2a332745 | 2649 | anArgIter += aNbParsed; |
2650 | if (aCmdName == "vsetedgetype") | |
8316c618 | 2651 | { |
2a332745 | 2652 | aChangeSet->ToSetEdgeColor = 1; |
2653 | aChangeSet->EdgeColor = Quantity_ColorRGBA (aColor); | |
2654 | } | |
0493ffd0 | 2655 | else if (aCmdName == "vshowfaceboundary" |
2656 | || anArg == "-setfaceboundarycolor" | |
2657 | || anArg == "-setboundarycolor" | |
2658 | || anArg == "-faceboundarycolor" | |
2659 | || anArg == "-boundarycolor") | |
2660 | { | |
2661 | aChangeSet->ToSetFaceBoundaryColor = 1; | |
2662 | aChangeSet->FaceBoundaryColor = aColor; | |
2663 | } | |
6b9b7e3c | 2664 | else if (anArg == "-setbackfacecolor" |
2665 | || anArg == "-backfacecolor" | |
2666 | || anArg == "-setbackcolor" | |
2667 | || anArg == "-backcolor") | |
2668 | { | |
2669 | aChangeSet->ToSetBackFaceColor = 1; | |
2670 | aChangeSet->BackFaceColor = aColor; | |
2671 | } | |
2a332745 | 2672 | else |
2673 | { | |
2674 | aChangeSet->ToSetColor = 1; | |
2675 | aChangeSet->Color = aColor; | |
7fd59977 | 2676 | } |
7fd59977 | 2677 | } |
2a332745 | 2678 | else if (anArg == "-setlinetype" |
2679 | || anArg == "-linetype" | |
2680 | || anArg == "-setedgetype" | |
2681 | || anArg == "-setedgestype" | |
2682 | || anArg == "-edgetype" | |
2683 | || anArg == "-edgestype" | |
0493ffd0 | 2684 | || anArg == "-setfaceboundarystyle" |
2685 | || anArg == "-faceboundarystyle" | |
2686 | || anArg == "-boundarystyle" | |
2687 | || anArg == "-setfaceboundarytype" | |
2688 | || anArg == "-faceboundarytype" | |
2689 | || anArg == "-setboundarytype" | |
2690 | || anArg == "-boundarytype" | |
2a332745 | 2691 | || anArg == "-type") |
ac116c22 | 2692 | { |
2693 | if (++anArgIter >= theArgNb) | |
2694 | { | |
23fe70ec | 2695 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
ac116c22 | 2696 | return 1; |
2697 | } | |
2a332745 | 2698 | Aspect_TypeOfLine aLineType = Aspect_TOL_EMPTY; |
3f1675c9 | 2699 | uint16_t aLinePattern = 0xFFFF; |
2700 | if (!ViewerTest::ParseLineType (theArgVec[anArgIter], aLineType, aLinePattern)) | |
ac116c22 | 2701 | { |
23fe70ec | 2702 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
ac116c22 | 2703 | return 1; |
2704 | } | |
3f1675c9 | 2705 | |
2a332745 | 2706 | if (anArg == "-setedgetype" |
2707 | || anArg == "-setedgestype" | |
2708 | || anArg == "-edgetype" | |
2709 | || anArg == "-edgestype" | |
2710 | || aCmdName == "vsetedgetype") | |
2711 | { | |
3f1675c9 | 2712 | aChangeSet->TypeOfEdge = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern); |
2a332745 | 2713 | aChangeSet->ToSetTypeOfEdge = 1; |
2714 | } | |
0493ffd0 | 2715 | else if (anArg == "-setfaceboundarystyle" |
2716 | || anArg == "-faceboundarystyle" | |
2717 | || anArg == "-boundarystyle" | |
2718 | || anArg == "-setfaceboundarytype" | |
2719 | || anArg == "-faceboundarytype" | |
2720 | || anArg == "-setboundarytype" | |
2721 | || anArg == "-boundarytype" | |
2722 | || aCmdName == "vshowfaceboundary") | |
2723 | { | |
3f1675c9 | 2724 | aChangeSet->TypeOfFaceBoundaryLine = Graphic3d_Aspects::DefaultLineTypeForPattern (aLinePattern); |
0493ffd0 | 2725 | aChangeSet->ToSetTypeOfFaceBoundaryLine = 1; |
2726 | } | |
2a332745 | 2727 | else |
2728 | { | |
3f1675c9 | 2729 | aChangeSet->StippleLinePattern = aLinePattern; |
2a332745 | 2730 | aChangeSet->ToSetTypeOfLine = 1; |
2731 | } | |
ac116c22 | 2732 | } |
2a332745 | 2733 | else if (anArg == "-unsetlinetype" |
2734 | || anArg == "-unsetedgetype" | |
2735 | || anArg == "-unsetedgestype") | |
ac116c22 | 2736 | { |
2a332745 | 2737 | if (anArg == "-unsetedgetype" |
2738 | || anArg == "-unsetedgestype") | |
2739 | { | |
2740 | aChangeSet->ToSetTypeOfEdge = -1; | |
2741 | } | |
2742 | else | |
2743 | { | |
2744 | aChangeSet->ToSetTypeOfLine = -1; | |
2745 | } | |
ac116c22 | 2746 | } |
e0b24437 | 2747 | else if (anArg == "-setstipplelinefactor" |
2748 | || anArg == "-setstipplefactor" | |
2749 | || anArg == "-setlinefactor" | |
2750 | || anArg == "-stipplelinefactor" | |
2751 | || anArg == "-stipplefactor" | |
2752 | || anArg == "-linefactor") | |
2753 | { | |
2754 | if (aChangeSet->ToSetTypeOfLine == -1) | |
2755 | { | |
2756 | Message::SendFail() << "Error: -setStippleLineFactor requires -setLineType"; | |
2757 | return 1; | |
2758 | } | |
2759 | if (++anArgIter >= theArgNb) | |
2760 | { | |
2761 | Message::SendFail() << "Error: wrong syntax at " << anArg; | |
2762 | return 1; | |
2763 | } | |
2764 | aChangeSet->StippleLineFactor = (uint16_t )Draw::Atoi (theArgVec[anArgIter]); | |
2765 | } | |
33cc703b | 2766 | else if (anArg == "-setmarkertype" |
2a332745 | 2767 | || anArg == "-markertype" |
2768 | || anArg == "-setpointtype" | |
2769 | || anArg == "-pointtype") | |
33cc703b | 2770 | { |
2771 | if (++anArgIter >= theArgNb) | |
2772 | { | |
23fe70ec | 2773 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
33cc703b | 2774 | return 1; |
2775 | } | |
2776 | if (!ViewerTest::ParseMarkerType (theArgVec[anArgIter], aChangeSet->TypeOfMarker, aChangeSet->MarkerImage)) | |
2777 | { | |
23fe70ec | 2778 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
33cc703b | 2779 | return 1; |
2780 | } | |
2781 | ||
2782 | aChangeSet->ToSetTypeOfMarker = 1; | |
2783 | } | |
2784 | else if (anArg == "-unsetmarkertype" | |
2785 | || anArg == "-unsetpointtype") | |
2786 | { | |
2787 | aChangeSet->ToSetTypeOfMarker = -1; | |
2788 | } | |
2789 | else if (anArg == "-setmarkersize" | |
2a332745 | 2790 | || anArg == "-markersize" |
2791 | || anArg == "-setpointsize" | |
2792 | || anArg == "-pointsize") | |
33cc703b | 2793 | { |
2794 | if (++anArgIter >= theArgNb) | |
2795 | { | |
23fe70ec | 2796 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
33cc703b | 2797 | return 1; |
2798 | } | |
2799 | aChangeSet->ToSetMarkerSize = 1; | |
2800 | aChangeSet->MarkerSize = Draw::Atof (theArgVec[anArgIter]); | |
2801 | } | |
2802 | else if (anArg == "-unsetmarkersize" | |
2803 | || anArg == "-unsetpointsize") | |
2804 | { | |
2805 | aChangeSet->ToSetMarkerSize = -1; | |
2806 | aChangeSet->MarkerSize = 1.0; | |
2807 | } | |
ad3217cd | 2808 | else if (anArg == "-unsetcolor") |
2809 | { | |
2810 | aChangeSet->ToSetColor = -1; | |
2811 | aChangeSet->Color = DEFAULT_COLOR; | |
2812 | } | |
2813 | else if (anArg == "-setmat" | |
2a332745 | 2814 | || anArg == "-mat" |
2815 | || anArg == "-setmaterial" | |
2816 | || anArg == "-material") | |
ad3217cd | 2817 | { |
2818 | if (++anArgIter >= theArgNb) | |
2819 | { | |
23fe70ec | 2820 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
ad3217cd | 2821 | return 1; |
2822 | } | |
2823 | aChangeSet->ToSetMaterial = 1; | |
61168418 | 2824 | aChangeSet->MatName = theArgVec[anArgIter]; |
2825 | if (!Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString(), aChangeSet->Material)) | |
2826 | { | |
23fe70ec | 2827 | Message::SendFail() << "Syntax error: unknown material '" << aChangeSet->MatName << "'."; |
61168418 | 2828 | return 1; |
2829 | } | |
ad3217cd | 2830 | } |
2831 | else if (anArg == "-unsetmat" | |
2832 | || anArg == "-unsetmaterial") | |
2833 | { | |
2834 | aChangeSet->ToSetMaterial = -1; | |
a966542b | 2835 | aChangeSet->Material = Graphic3d_NameOfMaterial_DEFAULT; |
ad3217cd | 2836 | } |
2837 | else if (anArg == "-subshape" | |
2838 | || anArg == "-subshapes") | |
2839 | { | |
6262338c | 2840 | if (isDefaults) |
2841 | { | |
23fe70ec | 2842 | Message::SendFail() << "Error: wrong syntax. -subshapes can not be used together with -defaults call!"; |
6262338c | 2843 | return 1; |
2844 | } | |
2845 | ||
ad3217cd | 2846 | if (aNames.IsEmpty()) |
2847 | { | |
23fe70ec | 2848 | Message::SendFail() << "Error: main objects should specified explicitly when -subshapes is used!"; |
ad3217cd | 2849 | return 1; |
2850 | } | |
7fd59977 | 2851 | |
ad3217cd | 2852 | aChanges.Append (ViewerTest_AspectsChangeSet()); |
2853 | aChangeSet = &aChanges.ChangeLast(); | |
7fd59977 | 2854 | |
ad3217cd | 2855 | for (++anArgIter; anArgIter < theArgNb; ++anArgIter) |
2856 | { | |
2857 | Standard_CString aSubShapeName = theArgVec[anArgIter]; | |
2858 | if (*aSubShapeName == '-') | |
2859 | { | |
2860 | --anArgIter; | |
2861 | break; | |
2862 | } | |
7fd59977 | 2863 | |
ad3217cd | 2864 | TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName); |
2865 | if (aSubShape.IsNull()) | |
2866 | { | |
23fe70ec | 2867 | Message::SendFail() << "Error: shape " << aSubShapeName << " doesn't found!"; |
ad3217cd | 2868 | return 1; |
2869 | } | |
2870 | aChangeSet->SubShapes.Append (aSubShape); | |
2871 | } | |
7fd59977 | 2872 | |
ad3217cd | 2873 | if (aChangeSet->SubShapes.IsEmpty()) |
2874 | { | |
23fe70ec | 2875 | Message::SendFail() << "Error: empty list is specified after -subshapes!"; |
ad3217cd | 2876 | return 1; |
2877 | } | |
2878 | } | |
2a332745 | 2879 | else if (anArg == "-setfreeboundary" |
2880 | || anArg == "-freeboundary" | |
2881 | || anArg == "-setfb" | |
6262338c | 2882 | || anArg == "-fb") |
2883 | { | |
0493ffd0 | 2884 | bool toEnable = true; |
dae2a922 | 2885 | if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable)) |
6262338c | 2886 | { |
23fe70ec | 2887 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
6262338c | 2888 | return 1; |
2889 | } | |
0493ffd0 | 2890 | ++anArgIter; |
2891 | aChangeSet->ToSetShowFreeBoundary = toEnable ? 1 : -1; | |
6262338c | 2892 | } |
2893 | else if (anArg == "-setfreeboundarywidth" | |
2a332745 | 2894 | || anArg == "-freeboundarywidth" |
2895 | || anArg == "-setfbwidth" | |
2896 | || anArg == "-fbwidth") | |
6262338c | 2897 | { |
2898 | if (++anArgIter >= theArgNb) | |
2899 | { | |
23fe70ec | 2900 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
6262338c | 2901 | return 1; |
2902 | } | |
2903 | aChangeSet->ToSetFreeBoundaryWidth = 1; | |
2904 | aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]); | |
2905 | } | |
2906 | else if (anArg == "-unsetfreeboundarywidth" | |
2907 | || anArg == "-unsetfbwidth") | |
2908 | { | |
2909 | aChangeSet->ToSetFreeBoundaryWidth = -1; | |
2910 | aChangeSet->FreeBoundaryWidth = 1.0; | |
2911 | } | |
2912 | else if (anArg == "-setfreeboundarycolor" | |
2a332745 | 2913 | || anArg == "-freeboundarycolor" |
2914 | || anArg == "-setfbcolor" | |
2915 | || anArg == "-fbcolor") | |
6262338c | 2916 | { |
dae2a922 | 2917 | Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1, |
2918 | theArgVec + anArgIter + 1, | |
2919 | aChangeSet->FreeBoundaryColor); | |
2a332745 | 2920 | if (aNbParsed == 0) |
6262338c | 2921 | { |
23fe70ec | 2922 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
2a332745 | 2923 | return 1; |
6262338c | 2924 | } |
2a332745 | 2925 | anArgIter += aNbParsed; |
6262338c | 2926 | aChangeSet->ToSetFreeBoundaryColor = 1; |
6262338c | 2927 | } |
2928 | else if (anArg == "-unsetfreeboundarycolor" | |
2929 | || anArg == "-unsetfbcolor") | |
2930 | { | |
2931 | aChangeSet->ToSetFreeBoundaryColor = -1; | |
2932 | aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR; | |
2933 | } | |
2a332745 | 2934 | else if (anArg == "-setisoontriangulation" |
2935 | || anArg == "-isoontriangulation" | |
2936 | || anArg == "-setisoontriang" | |
5ad8c033 | 2937 | || anArg == "-isoontriang") |
2938 | { | |
0493ffd0 | 2939 | bool toEnable = true; |
dae2a922 | 2940 | if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable)) |
5ad8c033 | 2941 | { |
23fe70ec | 2942 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
5ad8c033 | 2943 | return 1; |
2944 | } | |
0493ffd0 | 2945 | ++anArgIter; |
2946 | aChangeSet->ToEnableIsoOnTriangulation = toEnable ? 1 : -1; | |
2947 | } | |
2948 | else if (anArg == "-setfaceboundarydraw" | |
2949 | || anArg == "-setdrawfaceboundary" | |
2950 | || anArg == "-setdrawfaceboundaries" | |
2951 | || anArg == "-setshowfaceboundary" | |
2952 | || anArg == "-setshowfaceboundaries" | |
2953 | || anArg == "-setdrawfaceedges" | |
2954 | || anArg == "-faceboundarydraw" | |
2955 | || anArg == "-drawfaceboundary" | |
2956 | || anArg == "-drawfaceboundaries" | |
2957 | || anArg == "-showfaceboundary" | |
2958 | || anArg == "-showfaceboundaries" | |
2959 | || anArg == "-drawfaceedges" | |
2960 | || anArg == "-faceboundary" | |
2961 | || anArg == "-faceboundaries" | |
2962 | || anArg == "-faceedges") | |
2963 | { | |
2964 | bool toEnable = true; | |
dae2a922 | 2965 | if (!Draw::ParseOnOff (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : "", toEnable)) |
0493ffd0 | 2966 | { |
23fe70ec | 2967 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
0493ffd0 | 2968 | return 1; |
2969 | } | |
2970 | ++anArgIter; | |
2971 | aChangeSet->ToSetFaceBoundaryDraw = toEnable ? 1 : -1; | |
2972 | } | |
2973 | else if (anArg == "-unsetfaceboundary" | |
2974 | || anArg == "-unsetboundary") | |
2975 | { | |
2976 | aChangeSet->ToSetFaceBoundaryDraw = -1; | |
2977 | aChangeSet->ToSetFaceBoundaryColor = -1; | |
2978 | } | |
2979 | else if (anArg == "-setmostcontinuity" | |
2980 | || anArg == "-mostcontinuity") | |
2981 | { | |
2982 | TCollection_AsciiString aClassArg (anArgIter + 1 < theArgNb ? theArgVec[anArgIter + 1] : ""); | |
2983 | aClassArg.LowerCase(); | |
2984 | GeomAbs_Shape aClass = GeomAbs_CN; | |
2985 | if (aClassArg == "c0" | |
2986 | || aClassArg == "0") | |
5ad8c033 | 2987 | { |
0493ffd0 | 2988 | aClass = GeomAbs_C0; |
5ad8c033 | 2989 | } |
9f9490e1 | 2990 | else if (aClassArg == "g1") |
2991 | { | |
2992 | aClass = GeomAbs_G1; | |
2993 | } | |
0493ffd0 | 2994 | else if (aClassArg == "c1" |
2995 | || aClassArg == "1") | |
5ad8c033 | 2996 | { |
0493ffd0 | 2997 | aClass = GeomAbs_C1; |
2998 | } | |
9f9490e1 | 2999 | else if (aClassArg == "g2") |
3000 | { | |
3001 | aClass = GeomAbs_G2; | |
3002 | } | |
0493ffd0 | 3003 | else if (aClassArg == "c2" |
3004 | || aClassArg == "2") | |
3005 | { | |
3006 | aClass = GeomAbs_C2; | |
3007 | } | |
3008 | else if (aClassArg == "c3" | |
3009 | || aClassArg == "3") | |
3010 | { | |
3011 | aClass = GeomAbs_C3; | |
3012 | } | |
3013 | else if (aClassArg == "cn" | |
3014 | || aClassArg == "n") | |
3015 | { | |
3016 | aClass = GeomAbs_CN; | |
5ad8c033 | 3017 | } |
3018 | else | |
3019 | { | |
23fe70ec | 3020 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
5ad8c033 | 3021 | return 1; |
3022 | } | |
0493ffd0 | 3023 | |
3024 | ++anArgIter; | |
3025 | aChangeSet->ToSetFaceBoundaryUpperContinuity = 1; | |
3026 | aChangeSet->FaceBoundaryUpperContinuity = aClass; | |
5ad8c033 | 3027 | } |
2a332745 | 3028 | else if (anArg == "-setmaxparamvalue" |
3029 | || anArg == "-maxparamvalue") | |
5ad8c033 | 3030 | { |
3031 | if (++anArgIter >= theArgNb) | |
3032 | { | |
23fe70ec | 3033 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
5ad8c033 | 3034 | return 1; |
3035 | } | |
3036 | aChangeSet->ToSetMaxParamValue = 1; | |
3037 | aChangeSet->MaxParamValue = Draw::Atof (theArgVec[anArgIter]); | |
3038 | } | |
2a332745 | 3039 | else if (anArg == "-setsensitivity" |
3040 | || anArg == "-sensitivity") | |
8a1170ad | 3041 | { |
3042 | if (isDefaults) | |
3043 | { | |
23fe70ec | 3044 | Message::SendFail() << "Error: wrong syntax. -setSensitivity can not be used together with -defaults call!"; |
8a1170ad | 3045 | return 1; |
3046 | } | |
3047 | ||
3048 | if (aNames.IsEmpty()) | |
3049 | { | |
23fe70ec | 3050 | Message::SendFail() << "Error: object and selection mode should specified explicitly when -setSensitivity is used!"; |
8a1170ad | 3051 | return 1; |
3052 | } | |
3053 | ||
3054 | if (anArgIter + 2 >= theArgNb) | |
3055 | { | |
23fe70ec | 3056 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
8a1170ad | 3057 | return 1; |
3058 | } | |
3059 | aChangeSet->ToSetSensitivity = 1; | |
3060 | aChangeSet->SelectionMode = Draw::Atoi (theArgVec[++anArgIter]); | |
3061 | aChangeSet->Sensitivity = Draw::Atoi (theArgVec[++anArgIter]); | |
3062 | } | |
2a332745 | 3063 | else if (anArg == "-sethatch" |
3064 | || anArg == "-hatch") | |
640d5fe2 | 3065 | { |
3066 | if (isDefaults) | |
3067 | { | |
23fe70ec | 3068 | Message::SendFail() << "Error: wrong syntax. -setHatch can not be used together with -defaults call!"; |
640d5fe2 | 3069 | return 1; |
3070 | } | |
3071 | ||
3072 | if (aNames.IsEmpty()) | |
3073 | { | |
23fe70ec | 3074 | Message::SendFail() << "Error: object should be specified explicitly when -setHatch is used!"; |
640d5fe2 | 3075 | return 1; |
3076 | } | |
3077 | ||
3078 | aChangeSet->ToSetHatch = 1; | |
eadea5ea | 3079 | TCollection_AsciiString anArgHatch (theArgVec[++anArgIter]); |
3080 | if (anArgHatch.Length() <= 2) | |
640d5fe2 | 3081 | { |
ec7c343f | 3082 | const Standard_Integer anIntStyle = Draw::Atoi (anArgHatch.ToCString()); |
3083 | if (anIntStyle < 0 | |
3084 | || anIntStyle >= Aspect_HS_NB) | |
3085 | { | |
23fe70ec | 3086 | Message::SendFail() << "Error: hatch style is out of range [0, " << (Aspect_HS_NB - 1) << "]!"; |
ec7c343f | 3087 | return 1; |
3088 | } | |
3089 | aChangeSet->StdHatchStyle = anIntStyle; | |
640d5fe2 | 3090 | } |
3091 | else | |
3092 | { | |
eadea5ea | 3093 | aChangeSet->PathToHatchPattern = anArgHatch; |
640d5fe2 | 3094 | } |
3095 | } | |
2a332745 | 3096 | else if (anArg == "-setshadingmodel" |
3097 | || anArg == "-setshading" | |
3098 | || anArg == "-shadingmodel" | |
3099 | || anArg == "-shading") | |
dc89236f | 3100 | { |
3101 | if (++anArgIter >= theArgNb) | |
3102 | { | |
23fe70ec | 3103 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
dc89236f | 3104 | return 1; |
3105 | } | |
3106 | aChangeSet->ToSetShadingModel = 1; | |
3107 | aChangeSet->ShadingModelName = theArgVec[anArgIter]; | |
3108 | if (!ViewerTest::ParseShadingModel (theArgVec[anArgIter], aChangeSet->ShadingModel)) | |
3109 | { | |
23fe70ec | 3110 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
dc89236f | 3111 | return 1; |
3112 | } | |
3113 | } | |
3114 | else if (anArg == "-unsetshadingmodel") | |
3115 | { | |
3116 | aChangeSet->ToSetShadingModel = -1; | |
3117 | aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT; | |
3118 | } | |
2a332745 | 3119 | else if (anArg == "-setinterior" |
3120 | || anArg == "-setinteriorstyle" | |
3121 | || anArg == "-interior" | |
3122 | || anArg == "-interiorstyle") | |
3123 | { | |
3124 | if (++anArgIter >= theArgNb) | |
3125 | { | |
23fe70ec | 3126 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
2a332745 | 3127 | return 1; |
3128 | } | |
3129 | aChangeSet->ToSetInterior = 1; | |
3130 | if (!parseInteriorStyle (theArgVec[anArgIter], aChangeSet->InteriorStyle)) | |
3131 | { | |
23fe70ec | 3132 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
2a332745 | 3133 | return 1; |
3134 | } | |
3135 | } | |
3136 | else if (anArg == "-unsetinterior") | |
3137 | { | |
3138 | aChangeSet->ToSetInterior = -1; | |
3139 | aChangeSet->InteriorStyle = Aspect_IS_SOLID; | |
3140 | } | |
6ef0d6f1 | 3141 | else if (anArg == "-setdrawoutline" |
3142 | || anArg == "-setdrawsilhouette" | |
3143 | || anArg == "-setoutline" | |
3144 | || anArg == "-setsilhouette" | |
3145 | || anArg == "-outline" | |
3146 | || anArg == "-outlined" | |
3147 | || anArg == "-silhouette") | |
3148 | { | |
3149 | bool toDrawOutline = true; | |
3150 | if (anArgIter + 1 < theArgNb | |
dae2a922 | 3151 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], toDrawOutline)) |
6ef0d6f1 | 3152 | { |
3153 | ++anArgIter; | |
3154 | } | |
3155 | aChangeSet->ToSetDrawSilhouette = toDrawOutline ? 1 : -1; | |
3156 | } | |
2a332745 | 3157 | else if (anArg == "-setdrawedges" |
3158 | || anArg == "-setdrawedge" | |
3159 | || anArg == "-drawedges" | |
3160 | || anArg == "-drawedge" | |
3161 | || anArg == "-edges") | |
3162 | { | |
3163 | bool toDrawEdges = true; | |
3164 | if (anArgIter + 1 < theArgNb | |
dae2a922 | 3165 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], toDrawEdges)) |
2a332745 | 3166 | { |
3167 | ++anArgIter; | |
3168 | } | |
3169 | aChangeSet->ToSetDrawEdges = toDrawEdges ? 1 : -1; | |
3170 | } | |
3171 | else if (anArg == "-setquadedges" | |
3172 | || anArg == "-setquads" | |
3173 | || anArg == "-quads" | |
3174 | || anArg == "-skipfirstedge") | |
3175 | { | |
3176 | bool isQuadMode = true; | |
3177 | if (anArgIter + 1 < theArgNb | |
dae2a922 | 3178 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], isQuadMode)) |
2a332745 | 3179 | { |
3180 | ++anArgIter; | |
3181 | } | |
3182 | aChangeSet->ToSetQuadEdges = isQuadMode ? 1 : -1; | |
3183 | } | |
3184 | else if (anArg == "-setedgecolor" | |
3185 | || anArg == "-setedgescolor" | |
3186 | || anArg == "-edgecolor" | |
3187 | || anArg == "-edgescolor") | |
3188 | { | |
dae2a922 | 3189 | Standard_Integer aNbParsed = Draw::ParseColor (theArgNb - anArgIter - 1, |
3190 | theArgVec + anArgIter + 1, | |
3191 | aChangeSet->EdgeColor); | |
2a332745 | 3192 | if (aNbParsed == 0) |
3193 | { | |
23fe70ec | 3194 | Message::SendFail() << "Syntax error at '" << anArg << "'"; |
2a332745 | 3195 | return 1; |
3196 | } | |
3197 | anArgIter += aNbParsed; | |
3198 | aChangeSet->ToSetEdgeColor = 1; | |
3199 | } | |
3200 | else if (anArg == "-unset") | |
3201 | { | |
3202 | aChangeSet->ToSetVisibility = 1; | |
3203 | aChangeSet->Visibility = 1; | |
3204 | aChangeSet->ToSetLineWidth = -1; | |
3205 | aChangeSet->LineWidth = 1.0; | |
3206 | aChangeSet->ToSetTypeOfLine = -1; | |
3f1675c9 | 3207 | aChangeSet->StippleLinePattern = 0xFFFF; |
e0b24437 | 3208 | aChangeSet->StippleLineFactor = 1; |
2a332745 | 3209 | aChangeSet->ToSetTypeOfMarker = -1; |
3210 | aChangeSet->TypeOfMarker = Aspect_TOM_PLUS; | |
3211 | aChangeSet->ToSetMarkerSize = -1; | |
3212 | aChangeSet->MarkerSize = 1.0; | |
3213 | aChangeSet->ToSetTransparency = -1; | |
3214 | aChangeSet->Transparency = 0.0; | |
3215 | aChangeSet->ToSetAlphaMode = -1; | |
3216 | aChangeSet->AlphaMode = Graphic3d_AlphaMode_BlendAuto; | |
3217 | aChangeSet->AlphaCutoff = 0.5f; | |
3218 | aChangeSet->ToSetColor = -1; | |
3219 | aChangeSet->Color = DEFAULT_COLOR; | |
6b9b7e3c | 3220 | //aChangeSet->ToSetBackFaceColor = -1; // should be reset by ToSetColor |
3221 | //aChangeSet->BackFaceColor = DEFAULT_COLOR; | |
2a332745 | 3222 | aChangeSet->ToSetMaterial = -1; |
a966542b | 3223 | aChangeSet->Material = Graphic3d_NameOfMaterial_DEFAULT; |
2a332745 | 3224 | aChangeSet->ToSetShowFreeBoundary = -1; |
3225 | aChangeSet->ToSetFreeBoundaryColor = -1; | |
3226 | aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR; | |
3227 | aChangeSet->ToSetFreeBoundaryWidth = -1; | |
3228 | aChangeSet->FreeBoundaryWidth = 1.0; | |
0493ffd0 | 3229 | aChangeSet->ToEnableIsoOnTriangulation = -1; |
3230 | // | |
3231 | aChangeSet->ToSetFaceBoundaryDraw = -1; | |
3232 | aChangeSet->ToSetFaceBoundaryUpperContinuity = -1; | |
3233 | aChangeSet->FaceBoundaryUpperContinuity = GeomAbs_CN; | |
3234 | aChangeSet->ToSetFaceBoundaryColor = -1; | |
3235 | aChangeSet->FaceBoundaryColor = Quantity_NOC_BLACK; | |
3236 | aChangeSet->ToSetFaceBoundaryWidth = -1; | |
3237 | aChangeSet->FaceBoundaryWidth = 1.0f; | |
3238 | aChangeSet->ToSetTypeOfFaceBoundaryLine = -1; | |
3239 | aChangeSet->TypeOfFaceBoundaryLine = Aspect_TOL_SOLID; | |
3240 | // | |
2a332745 | 3241 | aChangeSet->ToSetHatch = -1; |
3242 | aChangeSet->StdHatchStyle = -1; | |
3243 | aChangeSet->PathToHatchPattern.Clear(); | |
3244 | aChangeSet->ToSetShadingModel = -1; | |
3245 | aChangeSet->ShadingModel = Graphic3d_TOSM_DEFAULT; | |
3246 | aChangeSet->ToSetInterior = -1; | |
3247 | aChangeSet->InteriorStyle = Aspect_IS_SOLID; | |
6ef0d6f1 | 3248 | aChangeSet->ToSetDrawSilhouette = -1; |
2a332745 | 3249 | aChangeSet->ToSetDrawEdges = -1; |
3250 | aChangeSet->ToSetQuadEdges = -1; | |
3251 | aChangeSet->ToSetEdgeColor = -1; | |
3252 | aChangeSet->EdgeColor = Quantity_ColorRGBA (DEFAULT_COLOR); | |
3253 | aChangeSet->ToSetEdgeWidth = -1; | |
3254 | aChangeSet->EdgeWidth = 1.0; | |
3255 | aChangeSet->ToSetTypeOfEdge = -1; | |
3256 | aChangeSet->TypeOfEdge = Aspect_TOL_SOLID; | |
3257 | } | |
0904aa63 | 3258 | else if (anArg == "-dumpjson") |
3259 | { | |
3260 | toDump = Standard_True; | |
3261 | } | |
3262 | else if (anArg == "-dumpcompact") | |
3263 | { | |
3264 | toCompactDump = Standard_False; | |
dae2a922 | 3265 | if (++anArgIter >= theArgNb && Draw::ParseOnOff (theArgVec[anArgIter + 1], toCompactDump)) |
0904aa63 | 3266 | ++anArgIter; |
3267 | } | |
3268 | else if (anArg == "-dumpdepth") | |
3269 | { | |
3270 | if (++anArgIter >= theArgNb) | |
3271 | { | |
23fe70ec | 3272 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
0904aa63 | 3273 | return 1; |
3274 | } | |
3275 | aDumpDepth = Draw::Atoi (theArgVec[anArgIter]); | |
3276 | } | |
7fd59977 | 3277 | else |
ad3217cd | 3278 | { |
23fe70ec | 3279 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
ad3217cd | 3280 | return 1; |
3281 | } | |
7fd59977 | 3282 | } |
99c56d44 | 3283 | |
ad3217cd | 3284 | for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges); |
3285 | aChangesIter.More(); aChangesIter.Next()) | |
3286 | { | |
c1197a15 | 3287 | if (!aChangesIter.Value().Validate()) |
ad3217cd | 3288 | { |
3289 | return 1; | |
3290 | } | |
99c56d44 | 3291 | } |
99c56d44 | 3292 | |
6262338c | 3293 | // special case for -defaults parameter. |
3294 | // all changed values will be set to DefaultDrawer. | |
3295 | if (isDefaults) | |
3296 | { | |
3297 | const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer(); | |
2a332745 | 3298 | aChangeSet->Apply (aDrawer); |
6262338c | 3299 | if (aChangeSet->ToSetLineWidth != 0) |
3300 | { | |
3301 | aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth); | |
3302 | aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth); | |
3303 | aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth); | |
3304 | aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth); | |
3305 | } | |
3306 | if (aChangeSet->ToSetColor != 0) | |
3307 | { | |
3308 | aDrawer->ShadingAspect()->SetColor (aChangeSet->Color); | |
3309 | aDrawer->LineAspect()->SetColor (aChangeSet->Color); | |
3310 | aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color); | |
3311 | aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color); | |
3312 | aDrawer->WireAspect()->SetColor (aChangeSet->Color); | |
3313 | aDrawer->PointAspect()->SetColor (aChangeSet->Color); | |
3314 | } | |
3315 | if (aChangeSet->ToSetTransparency != 0) | |
3316 | { | |
3317 | aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency); | |
3318 | } | |
3319 | if (aChangeSet->ToSetMaterial != 0) | |
3320 | { | |
3321 | aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material); | |
3322 | } | |
0493ffd0 | 3323 | if (aChangeSet->ToEnableIsoOnTriangulation != 0) |
5ad8c033 | 3324 | { |
3325 | aDrawer->SetIsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1); | |
3326 | } | |
6262338c | 3327 | |
3328 | // redisplay all objects in context | |
3329 | for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next()) | |
3330 | { | |
3331 | Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current(); | |
3332 | if (!aPrs.IsNull()) | |
3333 | { | |
3334 | aCtx->Redisplay (aPrs, Standard_False); | |
3335 | } | |
3336 | } | |
0904aa63 | 3337 | if (toDump) |
3338 | { | |
3339 | Standard_SStream aStream; | |
3340 | aDrawer->DumpJson (aStream, aDumpDepth); | |
3341 | ||
3342 | if (toCompactDump) | |
3343 | theDI << Standard_Dump::Text (aStream); | |
3344 | else | |
3345 | theDI << Standard_Dump::FormatJson (aStream); | |
3346 | } | |
6262338c | 3347 | return 0; |
3348 | } | |
3349 | ||
ad3217cd | 3350 | for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next()) |
3351 | { | |
25c35042 | 3352 | const TCollection_AsciiString& aName = aPrsIter.CurrentName(); |
3353 | Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current(); | |
3354 | if (aPrs.IsNull()) | |
3355 | { | |
3356 | return 1; | |
3357 | } | |
3358 | ||
6262338c | 3359 | Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes(); |
ad3217cd | 3360 | Handle(AIS_ColoredShape) aColoredPrs; |
3361 | Standard_Boolean toDisplay = Standard_False; | |
6262338c | 3362 | Standard_Boolean toRedisplay = Standard_False; |
5bffb882 | 3363 | if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1) |
ad3217cd | 3364 | { |
3365 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs); | |
3366 | if (aShapePrs.IsNull()) | |
3367 | { | |
23fe70ec | 3368 | Message::SendFail() << "Error: an object " << aName << " is not an AIS_Shape presentation!"; |
ad3217cd | 3369 | return 1; |
3370 | } | |
3371 | aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs); | |
3372 | if (aColoredPrs.IsNull()) | |
3373 | { | |
3374 | aColoredPrs = new AIS_ColoredShape (aShapePrs); | |
3e05329c | 3375 | if (aShapePrs->HasDisplayMode()) |
3376 | { | |
3377 | aColoredPrs->SetDisplayMode (aShapePrs->DisplayMode()); | |
3378 | } | |
3379 | aColoredPrs->SetLocalTransformation (aShapePrs->LocalTransformation()); | |
ad3217cd | 3380 | aCtx->Remove (aShapePrs, Standard_False); |
3381 | GetMapOfAIS().UnBind2 (aName); | |
3382 | GetMapOfAIS().Bind (aColoredPrs, aName); | |
3383 | toDisplay = Standard_True; | |
3384 | aShapePrs = aColoredPrs; | |
3385 | aPrs = aColoredPrs; | |
3386 | } | |
3387 | } | |
99c56d44 | 3388 | |
ad3217cd | 3389 | if (!aPrs.IsNull()) |
3390 | { | |
3391 | NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges); | |
3392 | aChangeSet = &aChangesIter.ChangeValue(); | |
5bffb882 | 3393 | if (aChangeSet->ToSetVisibility == 1) |
3394 | { | |
3395 | Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape()); | |
3396 | aColDrawer->SetHidden (aChangeSet->Visibility == 0); | |
3397 | } | |
3398 | else if (aChangeSet->ToSetMaterial == 1) | |
ad3217cd | 3399 | { |
3400 | aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False); | |
3401 | } | |
3402 | else if (aChangeSet->ToSetMaterial == -1) | |
3403 | { | |
3404 | aCtx->UnsetMaterial (aPrs, Standard_False); | |
3405 | } | |
3406 | if (aChangeSet->ToSetColor == 1) | |
3407 | { | |
3408 | aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False); | |
3409 | } | |
3410 | else if (aChangeSet->ToSetColor == -1) | |
3411 | { | |
3412 | aCtx->UnsetColor (aPrs, Standard_False); | |
3413 | } | |
3414 | if (aChangeSet->ToSetTransparency == 1) | |
3415 | { | |
3416 | aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False); | |
3417 | } | |
3418 | else if (aChangeSet->ToSetTransparency == -1) | |
3419 | { | |
3420 | aCtx->UnsetTransparency (aPrs, Standard_False); | |
3421 | } | |
3422 | if (aChangeSet->ToSetLineWidth == 1) | |
3423 | { | |
3424 | aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False); | |
3425 | } | |
3426 | else if (aChangeSet->ToSetLineWidth == -1) | |
3427 | { | |
3428 | aCtx->UnsetWidth (aPrs, Standard_False); | |
3429 | } | |
0493ffd0 | 3430 | else if (aChangeSet->ToEnableIsoOnTriangulation != 0) |
5ad8c033 | 3431 | { |
3432 | aCtx->IsoOnTriangulation (aChangeSet->ToEnableIsoOnTriangulation == 1, aPrs); | |
3433 | toRedisplay = Standard_True; | |
3434 | } | |
8a1170ad | 3435 | else if (aChangeSet->ToSetSensitivity != 0) |
3436 | { | |
3437 | aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity); | |
3438 | } | |
6262338c | 3439 | if (!aDrawer.IsNull()) |
3440 | { | |
2a332745 | 3441 | toRedisplay = aChangeSet->Apply (aDrawer) || toRedisplay; |
6262338c | 3442 | } |
99c56d44 | 3443 | |
ad3217cd | 3444 | for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next()) |
3445 | { | |
3446 | aChangeSet = &aChangesIter.ChangeValue(); | |
3447 | for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes); | |
3448 | aSubShapeIter.More(); aSubShapeIter.Next()) | |
3449 | { | |
3450 | const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); | |
2a332745 | 3451 | if (!aChangeSet->IsEmpty()) |
3452 | { | |
3453 | Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape); | |
3454 | aChangeSet->Apply (aCurColDrawer); | |
3455 | } | |
5bffb882 | 3456 | if (aChangeSet->ToSetVisibility == 1) |
3457 | { | |
3458 | Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape); | |
3459 | aCurColDrawer->SetHidden (aChangeSet->Visibility == 0); | |
3460 | } | |
ad3217cd | 3461 | if (aChangeSet->ToSetColor == 1) |
3462 | { | |
3463 | aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color); | |
3464 | } | |
c1197a15 | 3465 | if (aChangeSet->ToSetTransparency == 1) |
3466 | { | |
3467 | aColoredPrs->SetCustomTransparency (aSubShape, aChangeSet->Transparency); | |
3468 | } | |
ad3217cd | 3469 | if (aChangeSet->ToSetLineWidth == 1) |
3470 | { | |
3471 | aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth); | |
3472 | } | |
3473 | if (aChangeSet->ToSetColor == -1 | |
3474 | || aChangeSet->ToSetLineWidth == -1) | |
3475 | { | |
3476 | aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True); | |
3477 | } | |
8a1170ad | 3478 | if (aChangeSet->ToSetSensitivity != 0) |
3479 | { | |
3480 | aCtx->SetSelectionSensitivity (aPrs, aChangeSet->SelectionMode, aChangeSet->Sensitivity); | |
3481 | } | |
ad3217cd | 3482 | } |
3483 | } | |
3484 | if (toDisplay) | |
3485 | { | |
3486 | aCtx->Display (aPrs, Standard_False); | |
3487 | } | |
6262338c | 3488 | if (toRedisplay) |
3489 | { | |
3490 | aCtx->Redisplay (aPrs, Standard_False); | |
3491 | } | |
ad3217cd | 3492 | else if (!aColoredPrs.IsNull()) |
3493 | { | |
36132a2e | 3494 | aCtx->Redisplay (aColoredPrs, Standard_False); |
ad3217cd | 3495 | } |
2a332745 | 3496 | else |
3497 | { | |
3498 | aPrs->SynchronizeAspects(); | |
3499 | } | |
0904aa63 | 3500 | |
3501 | if (toDump) | |
3502 | { | |
3503 | Standard_SStream aStream; | |
3504 | aDrawer->DumpJson (aStream); | |
3505 | ||
3506 | theDI << aName << ": \n"; | |
3507 | theDI << Standard_Dump::FormatJson (aStream); | |
3508 | theDI << "\n"; | |
3509 | } | |
99c56d44 | 3510 | } |
ad3217cd | 3511 | } |
99c56d44 | 3512 | return 0; |
3513 | } | |
3514 | ||
7fd59977 | 3515 | //============================================================================== |
3516 | //function : VDonly2 | |
3517 | //author : ege | |
3518 | //purpose : Display only a selected or named object | |
519d35d8 | 3519 | // if there is no selected or named object s, nothing is done |
7fd59977 | 3520 | //============================================================================== |
519d35d8 | 3521 | static int VDonly2 (Draw_Interpretor& , |
3522 | Standard_Integer theArgNb, | |
3523 | const char** theArgVec) | |
7fd59977 | 3524 | { |
519d35d8 | 3525 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
4e18052b | 3526 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
519d35d8 | 3527 | if (aCtx.IsNull()) |
3528 | { | |
23fe70ec | 3529 | Message::SendFail ("Error: no active view!"); |
7fd59977 | 3530 | return 1; |
519d35d8 | 3531 | } |
7fd59977 | 3532 | |
519d35d8 | 3533 | Standard_Integer anArgIter = 1; |
3534 | for (; anArgIter < theArgNb; ++anArgIter) | |
3535 | { | |
4e18052b | 3536 | if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) |
519d35d8 | 3537 | { |
3538 | break; | |
3539 | } | |
3540 | } | |
7fd59977 | 3541 | |
519d35d8 | 3542 | NCollection_Map<Handle(Standard_Transient)> aDispSet; |
3543 | if (anArgIter >= theArgNb) | |
3544 | { | |
3545 | // display only selected objects | |
c3282ec1 | 3546 | if (aCtx->NbSelected() < 1) |
519d35d8 | 3547 | { |
3548 | return 0; | |
7fd59977 | 3549 | } |
3550 | ||
c3282ec1 | 3551 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
519d35d8 | 3552 | { |
c3282ec1 | 3553 | aDispSet.Add (aCtx->SelectedInteractive()); |
519d35d8 | 3554 | } |
3555 | } | |
3556 | else | |
3557 | { | |
3558 | // display only specified objects | |
3559 | for (; anArgIter < theArgNb; ++anArgIter) | |
3560 | { | |
3561 | TCollection_AsciiString aName = theArgVec[anArgIter]; | |
8f521168 | 3562 | Handle(AIS_InteractiveObject) aShape; |
3563 | if (GetMapOfAIS().Find2 (aName, aShape) | |
3564 | && !aShape.IsNull()) | |
519d35d8 | 3565 | { |
8f521168 | 3566 | aCtx->Display (aShape, Standard_False); |
3567 | aDispSet.Add (aShape); | |
7fd59977 | 3568 | } |
3569 | } | |
7fd59977 | 3570 | } |
519d35d8 | 3571 | |
3572 | // weed out other objects | |
3573 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next()) | |
3574 | { | |
3575 | if (aDispSet.Contains (anIter.Key1())) | |
3576 | { | |
3577 | continue; | |
3578 | } | |
3579 | ||
8f521168 | 3580 | if (Handle(AIS_InteractiveObject) aShape = anIter.Key1()) |
519d35d8 | 3581 | { |
519d35d8 | 3582 | aCtx->Erase (aShape, Standard_False); |
3583 | } | |
519d35d8 | 3584 | } |
7fd59977 | 3585 | return 0; |
3586 | } | |
3587 | ||
eef7fc64 | 3588 | //============================================================================== |
3589 | //function : VRemove | |
3590 | //purpose : Removes selected or named objects. | |
3591 | // If there is no selected or named objects, | |
3592 | // all objects in the viewer can be removed with argument -all. | |
3593 | // If -context is in arguments, the object is not deleted from the map of | |
3594 | // objects (deleted only from the current context). | |
3595 | //============================================================================== | |
3596 | int VRemove (Draw_Interpretor& theDI, | |
519d35d8 | 3597 | Standard_Integer theArgNb, |
3598 | const char** theArgVec) | |
eef7fc64 | 3599 | { |
4e18052b | 3600 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
3601 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); | |
3602 | if (aCtx.IsNull()) | |
eef7fc64 | 3603 | { |
23fe70ec | 3604 | Message::SendFail ("Error: no active view!"); |
eef7fc64 | 3605 | return 1; |
3606 | } | |
3607 | ||
4e18052b | 3608 | Standard_Boolean isContextOnly = Standard_False; |
3609 | Standard_Boolean toRemoveAll = Standard_False; | |
3610 | Standard_Boolean toPrintInfo = Standard_True; | |
ab1f4580 | 3611 | Standard_Boolean toFailOnError = Standard_True; |
519d35d8 | 3612 | |
3613 | Standard_Integer anArgIter = 1; | |
3614 | for (; anArgIter < theArgNb; ++anArgIter) | |
3615 | { | |
3616 | TCollection_AsciiString anArg = theArgVec[anArgIter]; | |
3617 | anArg.LowerCase(); | |
3618 | if (anArg == "-context") | |
3619 | { | |
3620 | isContextOnly = Standard_True; | |
3621 | } | |
3622 | else if (anArg == "-all") | |
3623 | { | |
3624 | toRemoveAll = Standard_True; | |
3625 | } | |
b7cd4ba7 | 3626 | else if (anArg == "-noinfo") |
3627 | { | |
3628 | toPrintInfo = Standard_False; | |
3629 | } | |
ab1f4580 | 3630 | else if (anArg == "-noerror" |
3631 | || anArg == "-nofail") | |
3632 | { | |
3633 | toFailOnError = Standard_False; | |
3634 | } | |
b6d587e3 | 3635 | else if (anUpdateTool.parseRedrawMode (anArg)) |
3636 | { | |
3637 | continue; | |
3638 | } | |
3639 | else | |
519d35d8 | 3640 | { |
3641 | break; | |
3642 | } | |
3643 | } | |
3644 | if (toRemoveAll | |
3645 | && anArgIter < theArgNb) | |
3646 | { | |
23fe70ec | 3647 | Message::SendFail ("Error: wrong syntax!"); |
b6d587e3 | 3648 | return 1; |
3649 | } | |
3650 | ||
eef7fc64 | 3651 | NCollection_List<TCollection_AsciiString> anIONameList; |
519d35d8 | 3652 | if (toRemoveAll) |
eef7fc64 | 3653 | { |
3654 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
3655 | anIter.More(); anIter.Next()) | |
3656 | { | |
3657 | anIONameList.Append (anIter.Key2()); | |
3658 | } | |
3659 | } | |
519d35d8 | 3660 | else if (anArgIter < theArgNb) // removed objects names are in argument list |
eef7fc64 | 3661 | { |
519d35d8 | 3662 | for (; anArgIter < theArgNb; ++anArgIter) |
eef7fc64 | 3663 | { |
ab1f4580 | 3664 | const TCollection_AsciiString aName (theArgVec[anArgIter]); |
3665 | if (aName.Search ("*") != -1) | |
eef7fc64 | 3666 | { |
ab1f4580 | 3667 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next()) |
3668 | { | |
3669 | if (aPrsIter.Key1()->GetContext() != aCtx) | |
3670 | { | |
3671 | continue; | |
3672 | } | |
3673 | const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'"; | |
3674 | if (theDI.Eval (aCheck.ToCString()) == 0 | |
3675 | && *theDI.Result() == '1') | |
3676 | { | |
3677 | anIONameList.Append (aPrsIter.Key2()); | |
3678 | } | |
3679 | } | |
3680 | theDI.Reset(); | |
eef7fc64 | 3681 | continue; |
3682 | } | |
3683 | ||
ab1f4580 | 3684 | Handle(AIS_InteractiveObject) anIO; |
3685 | if (!GetMapOfAIS().Find2 (aName, anIO)) | |
eef7fc64 | 3686 | { |
ab1f4580 | 3687 | if (toFailOnError) |
3688 | { | |
23fe70ec | 3689 | Message::SendFail() << "Syntax error: '" << aName << "' was not bound to some object."; |
ab1f4580 | 3690 | return 1; |
3691 | } | |
3692 | } | |
3693 | else if (anIO->GetContext() != aCtx) | |
3694 | { | |
3695 | if (toFailOnError) | |
3696 | { | |
23fe70ec | 3697 | Message::SendFail() << "Syntax error: '" << aName << "' was not displayed in current context.\n" |
3698 | << "Please activate view with this object displayed and try again."; | |
ab1f4580 | 3699 | return 1; |
3700 | } | |
3701 | } | |
3702 | else | |
3703 | { | |
3704 | anIONameList.Append (aName); | |
eef7fc64 | 3705 | } |
eef7fc64 | 3706 | } |
3707 | } | |
c3282ec1 | 3708 | else if (aCtx->NbSelected() > 0) |
eef7fc64 | 3709 | { |
3710 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
3711 | anIter.More(); anIter.Next()) | |
3712 | { | |
8f521168 | 3713 | if (!aCtx->IsSelected (anIter.Key1())) |
eef7fc64 | 3714 | { |
eef7fc64 | 3715 | continue; |
3716 | } | |
3717 | ||
d09dda09 | 3718 | anIONameList.Append (anIter.Key2()); |
3719 | continue; | |
eef7fc64 | 3720 | } |
3721 | } | |
3722 | ||
3723 | // Unbind all removed objects from the map of displayed IO. | |
3724 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList); | |
3725 | anIter.More(); anIter.Next()) | |
3726 | { | |
8f521168 | 3727 | const Handle(AIS_InteractiveObject) anIO = GetMapOfAIS().Find2 (anIter.Value()); |
d09dda09 | 3728 | aCtx->Remove (anIO, Standard_False); |
3729 | if (toPrintInfo) | |
519d35d8 | 3730 | { |
ab1f4580 | 3731 | theDI << anIter.Value() << " "; |
519d35d8 | 3732 | } |
519d35d8 | 3733 | if (!isContextOnly) |
3734 | { | |
3735 | GetMapOfAIS().UnBind2 (anIter.Value()); | |
3736 | } | |
3737 | } | |
eef7fc64 | 3738 | return 0; |
3739 | } | |
3740 | ||
7fd59977 | 3741 | //============================================================================== |
b514beda | 3742 | //function : VErase |
3743 | //purpose : Erase some selected or named objects | |
7fd59977 | 3744 | // if there is no selected or named objects, the whole viewer is erased |
7fd59977 | 3745 | //============================================================================== |
b514beda | 3746 | int VErase (Draw_Interpretor& theDI, |
3747 | Standard_Integer theArgNb, | |
3748 | const char** theArgVec) | |
7fd59977 | 3749 | { |
a1954302 | 3750 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
3751 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
3752 | ViewerTest_AutoUpdater anUpdateTool (aCtx, aView); | |
4e18052b | 3753 | if (aCtx.IsNull()) |
b514beda | 3754 | { |
23fe70ec | 3755 | Message::SendFail ("Error: no active view!"); |
7fd59977 | 3756 | return 1; |
b514beda | 3757 | } |
519d35d8 | 3758 | |
519d35d8 | 3759 | const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall"; |
3760 | ||
3761 | Standard_Integer anArgIter = 1; | |
a272ed94 | 3762 | Standard_Boolean toEraseInView = Standard_False; |
ab1f4580 | 3763 | Standard_Boolean toFailOnError = Standard_True; |
b6d587e3 | 3764 | TColStd_SequenceOfAsciiString aNamesOfEraseIO; |
519d35d8 | 3765 | for (; anArgIter < theArgNb; ++anArgIter) |
3766 | { | |
b6d587e3 | 3767 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
3768 | anArgCase.LowerCase(); | |
3769 | if (anUpdateTool.parseRedrawMode (anArgCase)) | |
519d35d8 | 3770 | { |
b6d587e3 | 3771 | continue; |
3772 | } | |
a272ed94 | 3773 | else if (anArgCase == "-view" |
3774 | || anArgCase == "-inview") | |
3775 | { | |
3776 | toEraseInView = Standard_True; | |
3777 | } | |
ab1f4580 | 3778 | else if (anArgCase == "-noerror" |
3779 | || anArgCase == "-nofail") | |
3780 | { | |
3781 | toFailOnError = Standard_False; | |
3782 | } | |
b6d587e3 | 3783 | else |
3784 | { | |
3785 | aNamesOfEraseIO.Append (theArgVec[anArgIter]); | |
519d35d8 | 3786 | } |
3787 | } | |
3788 | ||
b6d587e3 | 3789 | if (!aNamesOfEraseIO.IsEmpty() && toEraseAll) |
b514beda | 3790 | { |
23fe70ec | 3791 | Message::SendFail() << "Error: wrong syntax, " << theArgVec[0] << " too much arguments."; |
b6d587e3 | 3792 | return 1; |
3793 | } | |
7fd59977 | 3794 | |
b6d587e3 | 3795 | if (!aNamesOfEraseIO.IsEmpty()) |
3796 | { | |
3797 | // Erase named objects | |
ab1f4580 | 3798 | NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString> aPrsList; |
3799 | for (TColStd_SequenceOfAsciiString::Iterator anIter (aNamesOfEraseIO); anIter.More(); anIter.Next()) | |
b514beda | 3800 | { |
ab1f4580 | 3801 | const TCollection_AsciiString& aName = anIter.Value(); |
3802 | if (aName.Search ("*") != -1) | |
b514beda | 3803 | { |
ab1f4580 | 3804 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName aPrsIter (GetMapOfAIS()); aPrsIter.More(); aPrsIter.Next()) |
3805 | { | |
3806 | const TCollection_AsciiString aCheck = TCollection_AsciiString ("string match '") + aName + "' '" + aPrsIter.Key2() + "'"; | |
3807 | if (theDI.Eval (aCheck.ToCString()) == 0 | |
3808 | && *theDI.Result() == '1') | |
3809 | { | |
3810 | aPrsList.Add (aPrsIter.Key1(), aPrsIter.Key2()); | |
3811 | } | |
3812 | } | |
3813 | theDI.Reset(); | |
b514beda | 3814 | } |
ab1f4580 | 3815 | else |
b514beda | 3816 | { |
ab1f4580 | 3817 | Handle(AIS_InteractiveObject) anIO; |
3818 | if (!GetMapOfAIS().Find2 (aName, anIO)) | |
a272ed94 | 3819 | { |
ab1f4580 | 3820 | if (toFailOnError) |
3821 | { | |
23fe70ec | 3822 | Message::SendFail() << "Syntax error: '" << aName << "' is not found"; |
ab1f4580 | 3823 | return 1; |
3824 | } | |
a272ed94 | 3825 | } |
3826 | else | |
3827 | { | |
ab1f4580 | 3828 | aPrsList.Add (anIO, aName); |
a272ed94 | 3829 | } |
b514beda | 3830 | } |
7fd59977 | 3831 | } |
ab1f4580 | 3832 | |
3833 | for (NCollection_IndexedDataMap<Handle(AIS_InteractiveObject), TCollection_AsciiString>::Iterator anIter (aPrsList); anIter.More(); anIter.Next()) | |
3834 | { | |
3835 | theDI << anIter.Value() << " "; | |
3836 | if (toEraseInView) | |
3837 | { | |
3838 | aCtx->SetViewAffinity (anIter.Key(), aView, Standard_False); | |
3839 | } | |
3840 | else | |
3841 | { | |
3842 | aCtx->Erase (anIter.Key(), Standard_False); | |
3843 | } | |
3844 | } | |
7fd59977 | 3845 | } |
c3282ec1 | 3846 | else if (!toEraseAll && aCtx->NbSelected() > 0) |
b514beda | 3847 | { |
b6d587e3 | 3848 | // Erase selected objects |
b514beda | 3849 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
3850 | anIter.More(); anIter.Next()) | |
3851 | { | |
8f521168 | 3852 | const Handle(AIS_InteractiveObject) anIO = anIter.Key1(); |
b514beda | 3853 | if (!anIO.IsNull() |
c3282ec1 | 3854 | && aCtx->IsSelected (anIO)) |
b514beda | 3855 | { |
8f521168 | 3856 | theDI << anIter.Key2() << " "; |
a272ed94 | 3857 | if (toEraseInView) |
3858 | { | |
3859 | aCtx->SetViewAffinity (anIO, aView, Standard_False); | |
3860 | } | |
7fd59977 | 3861 | } |
3862 | } | |
671b6fe0 | 3863 | |
3864 | if (!toEraseInView) | |
3865 | { | |
3866 | aCtx->EraseSelected (Standard_False); | |
3867 | } | |
b514beda | 3868 | } |
519d35d8 | 3869 | else |
b514beda | 3870 | { |
b6d587e3 | 3871 | // Erase all objects |
519d35d8 | 3872 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
3873 | anIter.More(); anIter.Next()) | |
b514beda | 3874 | { |
8f521168 | 3875 | Handle(AIS_InteractiveObject) anIO = anIter.Key1(); |
519d35d8 | 3876 | if (!anIO.IsNull()) |
3877 | { | |
a272ed94 | 3878 | if (toEraseInView) |
3879 | { | |
3880 | aCtx->SetViewAffinity (anIO, aView, Standard_False); | |
3881 | } | |
3882 | else | |
3883 | { | |
3884 | aCtx->Erase (anIO, Standard_False); | |
3885 | } | |
519d35d8 | 3886 | } |
7fd59977 | 3887 | } |
7fd59977 | 3888 | } |
b6d587e3 | 3889 | |
7fd59977 | 3890 | return 0; |
3891 | } | |
3892 | ||
7fd59977 | 3893 | //============================================================================== |
3894 | //function : VDisplayAll | |
7fd59977 | 3895 | //purpose : Display all the objects of the Map |
7fd59977 | 3896 | //============================================================================== |
519d35d8 | 3897 | static int VDisplayAll (Draw_Interpretor& , |
3898 | Standard_Integer theArgNb, | |
3899 | const char** theArgVec) | |
7fd59977 | 3900 | |
3901 | { | |
4e18052b | 3902 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
3903 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); | |
3904 | if (aCtx.IsNull()) | |
519d35d8 | 3905 | { |
23fe70ec | 3906 | Message::SendFail ("Error: no active view!"); |
519d35d8 | 3907 | return 1; |
3908 | } | |
3909 | ||
519d35d8 | 3910 | Standard_Integer anArgIter = 1; |
3911 | for (; anArgIter < theArgNb; ++anArgIter) | |
3912 | { | |
b6d587e3 | 3913 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
3914 | anArgCase.LowerCase(); | |
68dcee02 | 3915 | if (anUpdateTool.parseRedrawMode (anArgCase)) |
b6d587e3 | 3916 | { |
3917 | continue; | |
3918 | } | |
3919 | else | |
519d35d8 | 3920 | { |
3921 | break; | |
7fd59977 | 3922 | } |
519d35d8 | 3923 | } |
3924 | if (anArgIter < theArgNb) | |
3925 | { | |
23fe70ec | 3926 | Message::SendFail() << theArgVec[0] << "Error: wrong syntax"; |
519d35d8 | 3927 | return 1; |
3928 | } | |
3929 | ||
519d35d8 | 3930 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
3931 | anIter.More(); anIter.Next()) | |
3932 | { | |
8f521168 | 3933 | aCtx->Erase (anIter.Key1(), Standard_False); |
519d35d8 | 3934 | } |
3935 | ||
3936 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
3937 | anIter.More(); anIter.Next()) | |
3938 | { | |
8f521168 | 3939 | aCtx->Display (anIter.Key1(), Standard_False); |
7fd59977 | 3940 | } |
3941 | return 0; | |
3942 | } | |
3943 | ||
8e5fb5ea | 3944 | //! Auxiliary method to check if presentation exists |
3945 | inline Standard_Integer checkMode (const Handle(AIS_InteractiveContext)& theCtx, | |
3946 | const Handle(AIS_InteractiveObject)& theIO, | |
3947 | const Standard_Integer theMode) | |
c2a388f8 | 3948 | { |
8e5fb5ea | 3949 | if (theIO.IsNull() || theCtx.IsNull()) |
c2a388f8 | 3950 | { |
8e5fb5ea | 3951 | return -1; |
c2a388f8 | 3952 | } |
3953 | ||
3954 | if (theMode != -1) | |
3955 | { | |
3956 | if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode)) | |
3957 | { | |
8e5fb5ea | 3958 | return theMode; |
c2a388f8 | 3959 | } |
3960 | } | |
3961 | else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode())) | |
3962 | { | |
8e5fb5ea | 3963 | return theIO->DisplayMode(); |
c2a388f8 | 3964 | } |
3965 | else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode())) | |
3966 | { | |
8e5fb5ea | 3967 | return theCtx->DisplayMode(); |
c2a388f8 | 3968 | } |
8e5fb5ea | 3969 | |
3970 | return -1; | |
c2a388f8 | 3971 | } |
3972 | ||
3973 | enum ViewerTest_BndAction | |
3974 | { | |
3975 | BndAction_Hide, | |
3976 | BndAction_Show, | |
3977 | BndAction_Print | |
3978 | }; | |
3979 | ||
3980 | //! Auxiliary method to print bounding box of presentation | |
8e5fb5ea | 3981 | inline void bndPresentation (Draw_Interpretor& theDI, |
3982 | const Handle(PrsMgr_PresentationManager)& theMgr, | |
3983 | const Handle(AIS_InteractiveObject)& theObj, | |
3984 | const Standard_Integer theDispMode, | |
3985 | const TCollection_AsciiString& theName, | |
3986 | const ViewerTest_BndAction theAction, | |
f838dac4 | 3987 | const Handle(Prs3d_Drawer)& theStyle) |
c2a388f8 | 3988 | { |
3989 | switch (theAction) | |
3990 | { | |
3991 | case BndAction_Hide: | |
3992 | { | |
f838dac4 | 3993 | theMgr->Unhighlight (theObj); |
c2a388f8 | 3994 | break; |
3995 | } | |
3996 | case BndAction_Show: | |
3997 | { | |
8e5fb5ea | 3998 | theMgr->Color (theObj, theStyle, theDispMode); |
c2a388f8 | 3999 | break; |
4000 | } | |
4001 | case BndAction_Print: | |
4002 | { | |
8e5fb5ea | 4003 | Bnd_Box aBox; |
4004 | for (PrsMgr_Presentations::Iterator aPrsIter (theObj->Presentations()); aPrsIter.More(); aPrsIter.Next()) | |
4005 | { | |
7dd7c146 | 4006 | if (aPrsIter.Value()->Mode() != theDispMode) |
8e5fb5ea | 4007 | continue; |
4008 | ||
7dd7c146 | 4009 | aBox = aPrsIter.Value()->MinMaxValues(); |
8e5fb5ea | 4010 | } |
ed063270 | 4011 | gp_Pnt aMin = aBox.CornerMin(); |
4012 | gp_Pnt aMax = aBox.CornerMax(); | |
c2a388f8 | 4013 | theDI << theName << "\n" |
ed063270 | 4014 | << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " " |
4015 | << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n"; | |
c2a388f8 | 4016 | break; |
4017 | } | |
4018 | } | |
4019 | } | |
4020 | ||
4021 | //============================================================================== | |
4022 | //function : VBounding | |
4023 | //purpose : | |
4024 | //============================================================================== | |
4025 | int VBounding (Draw_Interpretor& theDI, | |
4026 | Standard_Integer theArgNb, | |
4027 | const char** theArgVec) | |
4028 | { | |
4029 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
4e18052b | 4030 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
c2a388f8 | 4031 | if (aCtx.IsNull()) |
4032 | { | |
23fe70ec | 4033 | Message::SendFail ("Error: no active view!"); |
c2a388f8 | 4034 | return 1; |
4035 | } | |
4036 | ||
4e18052b | 4037 | ViewerTest_BndAction anAction = BndAction_Show; |
4038 | Standard_Integer aMode = -1; | |
c2a388f8 | 4039 | |
f838dac4 | 4040 | Handle(Prs3d_Drawer) aStyle; |
8e5fb5ea | 4041 | |
c2a388f8 | 4042 | Standard_Integer anArgIter = 1; |
4043 | for (; anArgIter < theArgNb; ++anArgIter) | |
4044 | { | |
4045 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4046 | anArg.LowerCase(); | |
4047 | if (anArg == "-print") | |
4048 | { | |
4049 | anAction = BndAction_Print; | |
4050 | } | |
4051 | else if (anArg == "-show") | |
4052 | { | |
4053 | anAction = BndAction_Show; | |
4054 | } | |
4055 | else if (anArg == "-hide") | |
4056 | { | |
4057 | anAction = BndAction_Hide; | |
4058 | } | |
4059 | else if (anArg == "-mode") | |
4060 | { | |
4061 | if (++anArgIter >= theArgNb) | |
4062 | { | |
23fe70ec | 4063 | Message::SendFail() << "Error: wrong syntax at " << anArg; |
c2a388f8 | 4064 | return 1; |
4065 | } | |
4066 | aMode = Draw::Atoi (theArgVec[anArgIter]); | |
4067 | } | |
4e18052b | 4068 | else if (!anUpdateTool.parseRedrawMode (anArg)) |
c2a388f8 | 4069 | { |
4070 | break; | |
4071 | } | |
4072 | } | |
4073 | ||
8e5fb5ea | 4074 | if (anAction == BndAction_Show) |
f838dac4 | 4075 | { |
4076 | aStyle = new Prs3d_Drawer(); | |
4077 | aStyle->SetMethod (Aspect_TOHM_BOUNDBOX); | |
4078 | aStyle->SetColor (Quantity_NOC_GRAY99); | |
4079 | } | |
8e5fb5ea | 4080 | |
4081 | Standard_Integer aHighlightedMode = -1; | |
c2a388f8 | 4082 | if (anArgIter < theArgNb) |
4083 | { | |
4084 | // has a list of names | |
4085 | for (; anArgIter < theArgNb; ++anArgIter) | |
4086 | { | |
4087 | TCollection_AsciiString aName = theArgVec[anArgIter]; | |
8f521168 | 4088 | Handle(AIS_InteractiveObject) anIO; |
4089 | if (!GetMapOfAIS().Find2 (aName, anIO)) | |
c2a388f8 | 4090 | { |
23fe70ec | 4091 | Message::SendFail() << "Error: presentation " << aName << " does not exist"; |
c2a388f8 | 4092 | return 1; |
4093 | } | |
4094 | ||
8e5fb5ea | 4095 | aHighlightedMode = checkMode (aCtx, anIO, aMode); |
4096 | if (aHighlightedMode == -1) | |
c2a388f8 | 4097 | { |
23fe70ec | 4098 | Message::SendFail() << "Error: object " << aName << " has no presentation with mode " << aMode; |
c2a388f8 | 4099 | return 1; |
4100 | } | |
8e5fb5ea | 4101 | bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, aName, anAction, aStyle); |
c2a388f8 | 4102 | } |
4103 | } | |
c3282ec1 | 4104 | else if (aCtx->NbSelected() > 0) |
c2a388f8 | 4105 | { |
4106 | // remove all currently selected objects | |
c3282ec1 | 4107 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
c2a388f8 | 4108 | { |
c3282ec1 | 4109 | Handle(AIS_InteractiveObject) anIO = aCtx->SelectedInteractive(); |
8e5fb5ea | 4110 | aHighlightedMode = checkMode (aCtx, anIO, aMode); |
4111 | if (aHighlightedMode != -1) | |
c2a388f8 | 4112 | { |
8e5fb5ea | 4113 | bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, |
4114 | GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction, aStyle); | |
c2a388f8 | 4115 | } |
4116 | } | |
4117 | } | |
4118 | else | |
4119 | { | |
4120 | // all objects | |
4121 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
4122 | anIter.More(); anIter.Next()) | |
4123 | { | |
8f521168 | 4124 | Handle(AIS_InteractiveObject) anIO = anIter.Key1(); |
8e5fb5ea | 4125 | aHighlightedMode = checkMode (aCtx, anIO, aMode); |
4126 | if (aHighlightedMode != -1) | |
c2a388f8 | 4127 | { |
8e5fb5ea | 4128 | bndPresentation (theDI, aCtx->MainPrsMgr(), anIO, aHighlightedMode, anIter.Key2(), anAction, aStyle); |
c2a388f8 | 4129 | } |
4130 | } | |
4131 | } | |
c2a388f8 | 4132 | return 0; |
4133 | } | |
4134 | ||
d399d3c3 | 4135 | //============================================================================== |
4136 | //function : VTexture | |
4137 | //purpose : | |
4138 | //============================================================================== | |
a6dee93d | 4139 | Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgVec) |
7fd59977 | 4140 | { |
a6dee93d | 4141 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
4142 | if (aCtx.IsNull()) | |
4143 | { | |
23fe70ec | 4144 | Message::SendFail() << "Error: no active view!"; |
a6dee93d | 4145 | return 1; |
4146 | } | |
4147 | ||
4148 | int toModulate = -1; | |
4149 | bool toSetFilter = false; | |
4150 | bool toSetAniso = false; | |
4151 | bool toSetTrsfAngle = false; | |
4152 | bool toSetTrsfTrans = false; | |
4153 | bool toSetTrsfScale = false; | |
4154 | Standard_ShortReal aTrsfRotAngle = 0.0f; | |
4155 | Graphic3d_Vec2 aTrsfTrans (0.0f, 0.0f); | |
4156 | Graphic3d_Vec2 aTrsfScale (1.0f, 1.0f); | |
4157 | Graphic3d_TypeOfTextureFilter aFilter = Graphic3d_TOTF_NEAREST; | |
4158 | Graphic3d_LevelOfTextureAnisotropy anAnisoFilter = Graphic3d_LOTA_OFF; | |
4159 | ||
c84c2ef7 | 4160 | Handle(AIS_InteractiveObject) aTexturedIO; |
4161 | Handle(AIS_Shape) aTexturedShape; | |
cc8cbabe | 4162 | Handle(Graphic3d_TextureSet) aTextureSetOld; |
4163 | NCollection_Vector<Handle(Graphic3d_Texture2Dmanual)> aTextureVecNew; | |
a6dee93d | 4164 | bool toSetGenRepeat = false; |
4165 | bool toSetGenScale = false; | |
4166 | bool toSetGenOrigin = false; | |
4167 | bool toSetImage = false; | |
cc8cbabe | 4168 | bool toComputeUV = false; |
a6dee93d | 4169 | |
4170 | const TCollection_AsciiString aCommandName (theArgVec[0]); | |
4171 | bool toSetDefaults = aCommandName == "vtexdefault"; | |
7fd59977 | 4172 | |
a6dee93d | 4173 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
4174 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) | |
d399d3c3 | 4175 | { |
a6dee93d | 4176 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
4177 | TCollection_AsciiString aNameCase = aName; | |
4178 | aNameCase.LowerCase(); | |
4179 | if (anUpdateTool.parseRedrawMode (aName)) | |
7fd59977 | 4180 | { |
a6dee93d | 4181 | continue; |
7fd59977 | 4182 | } |
a6dee93d | 4183 | else if (aTexturedIO.IsNull()) |
d399d3c3 | 4184 | { |
a6dee93d | 4185 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS(); |
4186 | if (aMapOfIO.IsBound2 (aName)) | |
d399d3c3 | 4187 | { |
c84c2ef7 | 4188 | aTexturedIO = aMapOfIO.Find2 (aName); |
4189 | aTexturedShape = Handle(AIS_Shape)::DownCast (aTexturedIO); | |
d399d3c3 | 4190 | } |
a6dee93d | 4191 | if (aTexturedIO.IsNull()) |
d399d3c3 | 4192 | { |
23fe70ec | 4193 | Message::SendFail() << "Syntax error: shape " << aName << " does not exists in the viewer."; |
a6dee93d | 4194 | return 1; |
d399d3c3 | 4195 | } |
4196 | ||
a6dee93d | 4197 | if (aTexturedIO->Attributes()->HasOwnShadingAspect()) |
4198 | { | |
cc8cbabe | 4199 | aTextureSetOld = aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureSet(); |
a6dee93d | 4200 | } |
d399d3c3 | 4201 | } |
c84c2ef7 | 4202 | else if (!aTexturedShape.IsNull() |
4203 | && (aNameCase == "-scale" | |
4204 | || aNameCase == "-setscale" | |
4205 | || aCommandName == "vtexscale")) | |
7fd59977 | 4206 | { |
a6dee93d | 4207 | if (aCommandName != "vtexscale") |
4208 | { | |
4209 | ++anArgIter; | |
4210 | } | |
4211 | if (anArgIter < theArgsNb) | |
4212 | { | |
4213 | TCollection_AsciiString aValU (theArgVec[anArgIter]); | |
4214 | TCollection_AsciiString aValUCase = aValU; | |
4215 | aValUCase.LowerCase(); | |
4216 | toSetGenScale = true; | |
4217 | if (aValUCase == "off") | |
4218 | { | |
c84c2ef7 | 4219 | aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0)); |
a6dee93d | 4220 | continue; |
4221 | } | |
4222 | else if (anArgIter + 1 < theArgsNb) | |
4223 | { | |
4224 | TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); | |
d45edf24 | 4225 | if (aValU.IsRealValue (Standard_True) |
4226 | && aValV.IsRealValue (Standard_True)) | |
a6dee93d | 4227 | { |
c84c2ef7 | 4228 | aTexturedShape->SetTextureScaleUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); |
a6dee93d | 4229 | ++anArgIter; |
4230 | continue; | |
4231 | } | |
4232 | } | |
4233 | } | |
23fe70ec | 4234 | Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'"; |
31160f80 | 4235 | return 1; |
7fd59977 | 4236 | } |
c84c2ef7 | 4237 | else if (!aTexturedShape.IsNull() |
4238 | && (aNameCase == "-origin" | |
4239 | || aNameCase == "-setorigin" | |
4240 | || aCommandName == "vtexorigin")) | |
d399d3c3 | 4241 | { |
a6dee93d | 4242 | if (aCommandName != "vtexorigin") |
4243 | { | |
4244 | ++anArgIter; | |
4245 | } | |
4246 | if (anArgIter < theArgsNb) | |
4247 | { | |
4248 | TCollection_AsciiString aValU (theArgVec[anArgIter]); | |
4249 | TCollection_AsciiString aValUCase = aValU; | |
4250 | aValUCase.LowerCase(); | |
4251 | toSetGenOrigin = true; | |
4252 | if (aValUCase == "off") | |
4253 | { | |
c84c2ef7 | 4254 | aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0)); |
a6dee93d | 4255 | continue; |
4256 | } | |
4257 | else if (anArgIter + 1 < theArgsNb) | |
4258 | { | |
4259 | TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); | |
d45edf24 | 4260 | if (aValU.IsRealValue (Standard_True) |
4261 | && aValV.IsRealValue (Standard_True)) | |
a6dee93d | 4262 | { |
c84c2ef7 | 4263 | aTexturedShape->SetTextureOriginUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); |
a6dee93d | 4264 | ++anArgIter; |
4265 | continue; | |
4266 | } | |
4267 | } | |
4268 | } | |
23fe70ec | 4269 | Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'"; |
a6dee93d | 4270 | return 1; |
d399d3c3 | 4271 | } |
c84c2ef7 | 4272 | else if (!aTexturedShape.IsNull() |
4273 | && (aNameCase == "-repeat" | |
4274 | || aNameCase == "-setrepeat" | |
4275 | || aCommandName == "vtexrepeat")) | |
d399d3c3 | 4276 | { |
a6dee93d | 4277 | if (aCommandName != "vtexrepeat") |
4278 | { | |
4279 | ++anArgIter; | |
4280 | } | |
4281 | if (anArgIter < theArgsNb) | |
4282 | { | |
4283 | TCollection_AsciiString aValU (theArgVec[anArgIter]); | |
4284 | TCollection_AsciiString aValUCase = aValU; | |
4285 | aValUCase.LowerCase(); | |
4286 | toSetGenRepeat = true; | |
4287 | if (aValUCase == "off") | |
4288 | { | |
c84c2ef7 | 4289 | aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0)); |
a6dee93d | 4290 | continue; |
4291 | } | |
4292 | else if (anArgIter + 1 < theArgsNb) | |
4293 | { | |
4294 | TCollection_AsciiString aValV (theArgVec[anArgIter + 1]); | |
d45edf24 | 4295 | if (aValU.IsRealValue (Standard_True) |
4296 | && aValV.IsRealValue (Standard_True)) | |
a6dee93d | 4297 | { |
c84c2ef7 | 4298 | aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (aValU.RealValue(), aValV.RealValue())); |
a6dee93d | 4299 | ++anArgIter; |
4300 | continue; | |
4301 | } | |
4302 | } | |
4303 | } | |
23fe70ec | 4304 | Message::SendFail() << "Syntax error: unexpected argument '" << aName << "'"; |
a6dee93d | 4305 | return 1; |
d399d3c3 | 4306 | } |
a6dee93d | 4307 | else if (aNameCase == "-modulate") |
d399d3c3 | 4308 | { |
a6dee93d | 4309 | bool toModulateBool = true; |
4310 | if (anArgIter + 1 < theArgsNb | |
dae2a922 | 4311 | && Draw::ParseOnOff (theArgVec[anArgIter + 1], toModulateBool)) |
a6dee93d | 4312 | { |
4313 | ++anArgIter; | |
4314 | } | |
4315 | toModulate = toModulateBool ? 1 : 0; | |
d399d3c3 | 4316 | } |
a6dee93d | 4317 | else if ((aNameCase == "-setfilter" |
4318 | || aNameCase == "-filter") | |
4319 | && anArgIter + 1 < theArgsNb) | |
d399d3c3 | 4320 | { |
a6dee93d | 4321 | TCollection_AsciiString aValue (theArgVec[anArgIter + 1]); |
4322 | aValue.LowerCase(); | |
4323 | ++anArgIter; | |
4324 | toSetFilter = true; | |
4325 | if (aValue == "nearest") | |
4326 | { | |
4327 | aFilter = Graphic3d_TOTF_NEAREST; | |
4328 | } | |
4329 | else if (aValue == "bilinear") | |
4330 | { | |
4331 | aFilter = Graphic3d_TOTF_BILINEAR; | |
4332 | } | |
4333 | else if (aValue == "trilinear") | |
4334 | { | |
4335 | aFilter = Graphic3d_TOTF_TRILINEAR; | |
4336 | } | |
4337 | else | |
4338 | { | |
23fe70ec | 4339 | Message::SendFail() << "Syntax error: unexpected argument '" << aValue << "'"; |
a6dee93d | 4340 | return 1; |
4341 | } | |
d399d3c3 | 4342 | } |
a6dee93d | 4343 | else if ((aNameCase == "-setaniso" |
4344 | || aNameCase == "-setanisofilter" | |
4345 | || aNameCase == "-aniso" | |
4346 | || aNameCase == "-anisofilter") | |
4347 | && anArgIter + 1 < theArgsNb) | |
d399d3c3 | 4348 | { |
a6dee93d | 4349 | TCollection_AsciiString aValue (theArgVec[anArgIter + 1]); |
4350 | aValue.LowerCase(); | |
4351 | ++anArgIter; | |
4352 | toSetAniso = true; | |
4353 | if (aValue == "off") | |
4354 | { | |
4355 | anAnisoFilter = Graphic3d_LOTA_OFF; | |
4356 | } | |
4357 | else if (aValue == "fast") | |
4358 | { | |
4359 | anAnisoFilter = Graphic3d_LOTA_FAST; | |
4360 | } | |
4361 | else if (aValue == "middle") | |
4362 | { | |
4363 | anAnisoFilter = Graphic3d_LOTA_MIDDLE; | |
4364 | } | |
4365 | else if (aValue == "quality" | |
4366 | || aValue == "high") | |
4367 | { | |
4368 | anAnisoFilter = Graphic3d_LOTA_QUALITY; | |
4369 | } | |
4370 | else | |
4371 | { | |
23fe70ec | 4372 | Message::SendFail() << "Syntax error: unexpected argument '" << aValue << "'"; |
a6dee93d | 4373 | return 1; |
4374 | } | |
d399d3c3 | 4375 | } |
a6dee93d | 4376 | else if ((aNameCase == "-rotateangle" |
4377 | || aNameCase == "-rotangle" | |
4378 | || aNameCase == "-rotate" | |
4379 | || aNameCase == "-angle" | |
4380 | || aNameCase == "-trsfangle") | |
4381 | && anArgIter + 1 < theArgsNb) | |
7fd59977 | 4382 | { |
a6dee93d | 4383 | aTrsfRotAngle = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); |
4384 | toSetTrsfAngle = true; | |
4385 | ++anArgIter; | |
7fd59977 | 4386 | } |
a6dee93d | 4387 | else if ((aNameCase == "-trsftrans" |
4388 | || aNameCase == "-trsftranslate" | |
4389 | || aNameCase == "-translate" | |
4390 | || aNameCase == "-translation") | |
4391 | && anArgIter + 2 < theArgsNb) | |
d399d3c3 | 4392 | { |
a6dee93d | 4393 | aTrsfTrans.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); |
4394 | aTrsfTrans.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2])); | |
4395 | toSetTrsfTrans = true; | |
4396 | anArgIter += 2; | |
d399d3c3 | 4397 | } |
a6dee93d | 4398 | else if ((aNameCase == "-trsfscale") |
4399 | && anArgIter + 2 < theArgsNb) | |
d399d3c3 | 4400 | { |
a6dee93d | 4401 | aTrsfScale.x() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 1])); |
4402 | aTrsfScale.y() = Standard_ShortReal (Draw::Atof (theArgVec[anArgIter + 2])); | |
4403 | toSetTrsfScale = true; | |
4404 | anArgIter += 2; | |
d399d3c3 | 4405 | } |
a6dee93d | 4406 | else if (aNameCase == "-default" |
4407 | || aNameCase == "-defaults") | |
16420da1 | 4408 | { |
a6dee93d | 4409 | toSetDefaults = true; |
16420da1 | 4410 | } |
98e6c6d1 | 4411 | else if ((aNameCase == "-video") |
4412 | && anArgIter + 1 < theArgsNb) | |
4413 | { | |
4414 | const TCollection_AsciiString anInput (theArgVec[++anArgIter]); | |
4415 | Handle(Graphic3d_MediaTextureSet) aMedia = Handle(Graphic3d_MediaTextureSet)::DownCast (aTextureSetOld); | |
4416 | if (aMedia.IsNull()) | |
4417 | { | |
4418 | aMedia = new Graphic3d_MediaTextureSet(); | |
4419 | } | |
4420 | if (aMedia->Input() != anInput) | |
4421 | { | |
4422 | aMedia->OpenInput (anInput, false); | |
4423 | } | |
4424 | else | |
4425 | { | |
4426 | if (aMedia->SwapFrames() | |
4427 | && !aCtx->CurrentViewer()->ZLayerSettings (aTexturedIO->ZLayer()).IsImmediate()) | |
4428 | { | |
4429 | ViewerTest::CurrentView()->Invalidate(); | |
4430 | } | |
4431 | } | |
4432 | if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer()) | |
4433 | && aTexturedShape.IsNull()) | |
4434 | { | |
4435 | aTexturedIO->SetToUpdate(); | |
4436 | } | |
4437 | ||
4438 | toComputeUV = aTextureSetOld.IsNull(); | |
4439 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (true); | |
4440 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aMedia); | |
4441 | aTextureSetOld.Nullify(); | |
4442 | } | |
cc8cbabe | 4443 | else if (aCommandName == "vtexture" |
4444 | && (aTextureVecNew.IsEmpty() | |
4445 | || aNameCase.StartsWith ("-tex"))) | |
7fd59977 | 4446 | { |
cc8cbabe | 4447 | Standard_Integer aTexIndex = 0; |
4448 | TCollection_AsciiString aTexName = aName; | |
4449 | if (aNameCase.StartsWith ("-tex")) | |
4450 | { | |
4451 | if (anArgIter + 1 >= theArgsNb | |
4452 | || aNameCase.Length() < 5) | |
4453 | { | |
23fe70ec | 4454 | Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'"; |
cc8cbabe | 4455 | return 1; |
4456 | } | |
4457 | ||
4458 | TCollection_AsciiString aTexIndexStr = aNameCase.SubString (5, aNameCase.Length()); | |
4459 | if (!aTexIndexStr.IsIntegerValue()) | |
4460 | { | |
23fe70ec | 4461 | Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'"; |
cc8cbabe | 4462 | return 1; |
4463 | } | |
4464 | ||
4465 | aTexIndex = aTexIndexStr.IntegerValue(); | |
4466 | aTexName = theArgVec[anArgIter + 1]; | |
4467 | ++anArgIter; | |
4468 | } | |
4469 | if (aTexIndex >= Graphic3d_TextureUnit_NB | |
4470 | || aTexIndex >= aCtx->CurrentViewer()->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxCombinedTextureUnits)) | |
4471 | { | |
23fe70ec | 4472 | Message::SendFail ("Error: too many textures specified"); |
cc8cbabe | 4473 | return 1; |
4474 | } | |
4475 | ||
a6dee93d | 4476 | toSetImage = true; |
cc8cbabe | 4477 | if (aTexName.IsIntegerValue()) |
d399d3c3 | 4478 | { |
cc8cbabe | 4479 | const Standard_Integer aValue = aTexName.IntegerValue(); |
a6dee93d | 4480 | if (aValue < 0 || aValue >= Graphic3d_Texture2D::NumberOfTextures()) |
4481 | { | |
23fe70ec | 4482 | Message::SendFail() << "Syntax error: texture with ID " << aValue << " is undefined!"; |
a6dee93d | 4483 | return 1; |
4484 | } | |
cc8cbabe | 4485 | aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (Graphic3d_NameOfTexture2D (aValue))); |
d399d3c3 | 4486 | } |
cc8cbabe | 4487 | else if (aTexName == "?") |
d399d3c3 | 4488 | { |
a6dee93d | 4489 | const TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder(); |
7fd59977 | 4490 | |
586db386 | 4491 | theDi << "\n Files in current directory : \n\n"; |
d399d3c3 | 4492 | theDi.Eval ("glob -nocomplain *"); |
7fd59977 | 4493 | |
d399d3c3 | 4494 | TCollection_AsciiString aCmnd ("glob -nocomplain "); |
4495 | aCmnd += aTextureFolder; | |
4496 | aCmnd += "/* "; | |
7fd59977 | 4497 | |
a6dee93d | 4498 | theDi << "Files in " << aTextureFolder << " : \n\n"; |
d399d3c3 | 4499 | theDi.Eval (aCmnd.ToCString()); |
4500 | return 0; | |
4501 | } | |
cc8cbabe | 4502 | else if (aTexName != "off") |
d399d3c3 | 4503 | { |
cc8cbabe | 4504 | if (!OSD_File (aTexName).Exists()) |
a6dee93d | 4505 | { |
23fe70ec | 4506 | Message::SendFail() << "Syntax error: non-existing image file has been specified '" << aTexName << "'."; |
a6dee93d | 4507 | return 1; |
4508 | } | |
cc8cbabe | 4509 | aTextureVecNew.SetValue (aTexIndex, new Graphic3d_Texture2Dmanual (aTexName)); |
4510 | } | |
4511 | else | |
4512 | { | |
4513 | aTextureVecNew.SetValue (aTexIndex, Handle(Graphic3d_Texture2Dmanual)()); | |
d399d3c3 | 4514 | } |
7373e19f | 4515 | |
4516 | if (aTextureVecNew.Value (aTexIndex)) | |
4517 | { | |
4518 | aTextureVecNew.ChangeValue(aTexIndex)->GetParams()->SetTextureUnit((Graphic3d_TextureUnit)aTexIndex); | |
4519 | } | |
cc8cbabe | 4520 | } |
4521 | else | |
4522 | { | |
23fe70ec | 4523 | Message::SendFail() << "Syntax error: invalid argument '" << theArgVec[anArgIter] << "'"; |
cc8cbabe | 4524 | return 1; |
4525 | } | |
4526 | } | |
7fd59977 | 4527 | |
cc8cbabe | 4528 | if (toSetImage) |
4529 | { | |
4530 | // check if new image set is equal to already set one | |
4531 | Standard_Integer aNbChanged = 0; | |
4532 | Handle(Graphic3d_TextureSet) aTextureSetNew; | |
4533 | if (!aTextureVecNew.IsEmpty()) | |
4534 | { | |
4535 | aNbChanged = aTextureVecNew.Size(); | |
4536 | aTextureSetNew = new Graphic3d_TextureSet (aTextureVecNew.Size()); | |
4537 | for (Standard_Integer aTexIter = 0; aTexIter < aTextureSetNew->Size(); ++aTexIter) | |
d399d3c3 | 4538 | { |
cc8cbabe | 4539 | Handle(Graphic3d_Texture2Dmanual)& aTextureNew = aTextureVecNew.ChangeValue (aTexIter); |
4540 | Handle(Graphic3d_TextureRoot) aTextureOld; | |
4541 | if (!aTextureSetOld.IsNull() | |
4542 | && aTexIter < aTextureSetOld->Size()) | |
4543 | { | |
4544 | aTextureOld = aTextureSetOld->Value (aTexIter); | |
4545 | } | |
4546 | ||
4547 | if (!aTextureOld.IsNull() | |
4548 | && !aTextureNew.IsNull()) | |
a6dee93d | 4549 | { |
4550 | *aTextureNew->GetParams() = *aTextureOld->GetParams(); | |
4551 | if (Handle(Graphic3d_Texture2Dmanual) anOldManualTex = Handle(Graphic3d_Texture2Dmanual)::DownCast (aTextureOld)) | |
4552 | { | |
4553 | TCollection_AsciiString aFilePathOld, aFilePathNew; | |
4554 | aTextureOld->Path().SystemName (aFilePathOld); | |
4555 | aTextureNew->Path().SystemName (aFilePathNew); | |
4556 | if (aTextureNew->Name() == anOldManualTex->Name() | |
4557 | && aFilePathOld == aFilePathNew | |
4558 | && (!aFilePathNew.IsEmpty() || aTextureNew->Name() != Graphic3d_NOT_2D_UNKNOWN)) | |
4559 | { | |
cc8cbabe | 4560 | --aNbChanged; |
a6dee93d | 4561 | aTextureNew = anOldManualTex; |
4562 | } | |
4563 | } | |
4564 | } | |
cc8cbabe | 4565 | aTextureSetNew->SetValue (aTexIter, aTextureNew); |
d399d3c3 | 4566 | } |
4567 | } | |
cc8cbabe | 4568 | if (aNbChanged == 0 |
4569 | && ((aTextureSetOld.IsNull() && aTextureSetNew.IsNull()) | |
4570 | || (aTextureSetOld->Size() == aTextureSetNew->Size()))) | |
a6dee93d | 4571 | { |
cc8cbabe | 4572 | aTextureSetNew = aTextureSetOld; |
4573 | } | |
4574 | ||
2a332745 | 4575 | if (aTexturedIO->Attributes()->SetupOwnShadingAspect (aCtx->DefaultDrawer()) |
4576 | && aTexturedShape.IsNull()) | |
cc8cbabe | 4577 | { |
2a332745 | 4578 | aTexturedIO->SetToUpdate(); |
a6dee93d | 4579 | } |
cc8cbabe | 4580 | |
4581 | toComputeUV = !aTextureSetNew.IsNull() && aTextureSetOld.IsNull(); | |
4582 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn (!aTextureSetNew.IsNull()); | |
4583 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (aTextureSetNew); | |
4584 | aTextureSetOld.Nullify(); | |
a6dee93d | 4585 | } |
7fd59977 | 4586 | |
a6dee93d | 4587 | if (toSetDefaults) |
4588 | { | |
4589 | if (toModulate != -1) | |
d399d3c3 | 4590 | { |
a6dee93d | 4591 | toModulate = 1; |
7fd59977 | 4592 | } |
a6dee93d | 4593 | if (!toSetFilter) |
4594 | { | |
4595 | toSetFilter = true; | |
4596 | aFilter = Graphic3d_TOTF_BILINEAR; | |
4597 | } | |
4598 | if (!toSetAniso) | |
4599 | { | |
4600 | toSetAniso = true; | |
4601 | anAnisoFilter = Graphic3d_LOTA_OFF; | |
4602 | } | |
4603 | if (!toSetTrsfAngle) | |
4604 | { | |
4605 | toSetTrsfAngle = true; | |
4606 | aTrsfRotAngle = 0.0f; | |
4607 | } | |
4608 | if (!toSetTrsfTrans) | |
4609 | { | |
4610 | toSetTrsfTrans = true; | |
4611 | aTrsfTrans = Graphic3d_Vec2 (0.0f, 0.0f); | |
4612 | } | |
4613 | if (!toSetTrsfScale) | |
4614 | { | |
4615 | toSetTrsfScale = true; | |
4616 | aTrsfScale = Graphic3d_Vec2 (1.0f, 1.0f); | |
4617 | } | |
4618 | } | |
7fd59977 | 4619 | |
a6dee93d | 4620 | if (aCommandName == "vtexture" |
4621 | && theArgsNb == 2) | |
4622 | { | |
cc8cbabe | 4623 | if (!aTextureSetOld.IsNull()) |
7fd59977 | 4624 | { |
cc8cbabe | 4625 | //toComputeUV = true; // we can keep UV vertex attributes |
a6dee93d | 4626 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff(); |
cc8cbabe | 4627 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->SetTextureSet (Handle(Graphic3d_TextureSet)()); |
4628 | aTextureSetOld.Nullify(); | |
7fd59977 | 4629 | } |
d399d3c3 | 4630 | } |
4631 | ||
a6dee93d | 4632 | if (aTexturedIO->Attributes()->HasOwnShadingAspect() |
4633 | && !aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap().IsNull()) | |
d399d3c3 | 4634 | { |
a6dee93d | 4635 | if (toModulate != -1) |
4636 | { | |
4637 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetModulate (toModulate == 1); | |
4638 | } | |
4639 | if (toSetTrsfAngle) | |
4640 | { | |
4641 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetRotation (aTrsfRotAngle); // takes degrees | |
4642 | } | |
4643 | if (toSetTrsfTrans) | |
4644 | { | |
4645 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetTranslation (aTrsfTrans); | |
4646 | } | |
4647 | if (toSetTrsfScale) | |
4648 | { | |
4649 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetScale (aTrsfScale); | |
4650 | } | |
4651 | if (toSetFilter) | |
4652 | { | |
4653 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetFilter (aFilter); | |
4654 | } | |
4655 | if (toSetAniso) | |
4656 | { | |
4657 | aTexturedIO->Attributes()->ShadingAspect()->Aspect()->TextureMap()->GetParams()->SetAnisoFilter (anAnisoFilter); | |
4658 | } | |
d399d3c3 | 4659 | } |
a6dee93d | 4660 | |
4661 | // set default values if requested | |
4662 | if (!toSetGenRepeat | |
4663 | && (aCommandName == "vtexrepeat" | |
4664 | || toSetDefaults)) | |
4665 | { | |
c84c2ef7 | 4666 | if (!aTexturedShape.IsNull()) |
4667 | { | |
4668 | aTexturedShape->SetTextureRepeatUV (gp_Pnt2d (1.0, 1.0)); | |
4669 | } | |
a6dee93d | 4670 | toSetGenRepeat = true; |
4671 | } | |
4672 | if (!toSetGenOrigin | |
4673 | && (aCommandName == "vtexorigin" | |
4674 | || toSetDefaults)) | |
4675 | { | |
c84c2ef7 | 4676 | if (!aTexturedShape.IsNull()) |
4677 | { | |
4678 | aTexturedShape->SetTextureOriginUV (gp_Pnt2d (0.0, 0.0)); | |
4679 | } | |
a6dee93d | 4680 | toSetGenOrigin = true; |
4681 | } | |
4682 | if (!toSetGenScale | |
4683 | && (aCommandName == "vtexscale" | |
4684 | || toSetDefaults)) | |
d399d3c3 | 4685 | { |
c84c2ef7 | 4686 | if (!aTexturedShape.IsNull()) |
4687 | { | |
4688 | aTexturedShape->SetTextureScaleUV (gp_Pnt2d (1.0, 1.0)); | |
4689 | } | |
a6dee93d | 4690 | toSetGenScale = true; |
d399d3c3 | 4691 | } |
4692 | ||
cc8cbabe | 4693 | if (toSetGenRepeat || toSetGenOrigin || toSetGenScale || toComputeUV) |
a6dee93d | 4694 | { |
c84c2ef7 | 4695 | if (!aTexturedShape.IsNull()) |
a6dee93d | 4696 | { |
c84c2ef7 | 4697 | aTexturedShape->SetToUpdate (AIS_Shaded); |
4698 | if (toSetImage) | |
a6dee93d | 4699 | { |
c84c2ef7 | 4700 | if ((aTexturedIO->HasDisplayMode() && aTexturedIO->DisplayMode() != AIS_Shaded) |
4701 | || aCtx->DisplayMode() != AIS_Shaded) | |
4702 | { | |
4703 | aCtx->SetDisplayMode (aTexturedIO, AIS_Shaded, false); | |
4704 | } | |
a6dee93d | 4705 | } |
4706 | } | |
4707 | } | |
4708 | aCtx->Display (aTexturedIO, false); | |
4709 | aTexturedIO->SynchronizeAspects(); | |
31160f80 | 4710 | return 0; |
7fd59977 | 4711 | } |
4712 | ||
af65fb19 | 4713 | //! Auxiliary method to parse transformation persistence flags |
4714 | inline Standard_Boolean parseTrsfPersFlag (const TCollection_AsciiString& theFlagString, | |
778cd667 | 4715 | Graphic3d_TransModeFlags& theFlags) |
af65fb19 | 4716 | { |
778cd667 | 4717 | if (theFlagString == "zoom") |
af65fb19 | 4718 | { |
778cd667 | 4719 | theFlags = Graphic3d_TMF_ZoomPers; |
af65fb19 | 4720 | } |
4721 | else if (theFlagString == "rotate") | |
4722 | { | |
778cd667 | 4723 | theFlags = Graphic3d_TMF_RotatePers; |
af65fb19 | 4724 | } |
778cd667 | 4725 | else if (theFlagString == "zoomrotate") |
af65fb19 | 4726 | { |
778cd667 | 4727 | theFlags = Graphic3d_TMF_ZoomRotatePers; |
af65fb19 | 4728 | } |
778cd667 | 4729 | else if (theFlagString == "trihedron" |
4730 | || theFlagString == "triedron") | |
af65fb19 | 4731 | { |
778cd667 | 4732 | theFlags = Graphic3d_TMF_TriedronPers; |
af65fb19 | 4733 | } |
4734 | else if (theFlagString == "none") | |
4735 | { | |
4736 | theFlags = Graphic3d_TMF_None; | |
4737 | } | |
4738 | else | |
4739 | { | |
4740 | return Standard_False; | |
4741 | } | |
4742 | ||
4743 | return Standard_True; | |
4744 | } | |
4745 | ||
778cd667 | 4746 | //! Auxiliary method to parse transformation persistence flags |
4747 | inline Standard_Boolean parseTrsfPersCorner (const TCollection_AsciiString& theString, | |
4748 | Aspect_TypeOfTriedronPosition& theCorner) | |
4749 | { | |
4750 | TCollection_AsciiString aString (theString); | |
4751 | aString.LowerCase(); | |
4752 | if (aString == "center") | |
4753 | { | |
4754 | theCorner = Aspect_TOTP_CENTER; | |
4755 | } | |
4756 | else if (aString == "top" | |
4757 | || aString == "upper") | |
4758 | { | |
4759 | theCorner = Aspect_TOTP_TOP; | |
4760 | } | |
4761 | else if (aString == "bottom" | |
4762 | || aString == "lower") | |
4763 | { | |
4764 | theCorner = Aspect_TOTP_BOTTOM; | |
4765 | } | |
4766 | else if (aString == "left") | |
4767 | { | |
4768 | theCorner = Aspect_TOTP_LEFT; | |
4769 | } | |
4770 | else if (aString == "right") | |
4771 | { | |
4772 | theCorner = Aspect_TOTP_RIGHT; | |
4773 | } | |
4774 | else if (aString == "topleft" | |
4775 | || aString == "leftupper" | |
4776 | || aString == "upperleft") | |
4777 | { | |
4778 | theCorner = Aspect_TOTP_LEFT_UPPER; | |
4779 | } | |
4780 | else if (aString == "bottomleft" | |
4781 | || aString == "leftlower" | |
4782 | || aString == "lowerleft") | |
4783 | { | |
4784 | theCorner = Aspect_TOTP_LEFT_LOWER; | |
4785 | } | |
4786 | else if (aString == "topright" | |
4787 | || aString == "rightupper" | |
4788 | || aString == "upperright") | |
4789 | { | |
4790 | theCorner = Aspect_TOTP_RIGHT_UPPER; | |
4791 | } | |
4792 | else if (aString == "bottomright" | |
4793 | || aString == "lowerright" | |
4794 | || aString == "rightlower") | |
4795 | { | |
4796 | theCorner = Aspect_TOTP_RIGHT_LOWER; | |
4797 | } | |
4798 | else | |
4799 | { | |
4800 | return Standard_False; | |
4801 | } | |
4802 | ||
4803 | return Standard_True; | |
4804 | } | |
4805 | ||
7fd59977 | 4806 | //============================================================================== |
4807 | //function : VDisplay2 | |
4808 | //author : ege | |
4809 | //purpose : Display an object from its name | |
7fd59977 | 4810 | //============================================================================== |
519d35d8 | 4811 | static int VDisplay2 (Draw_Interpretor& theDI, |
4812 | Standard_Integer theArgNb, | |
4813 | const char** theArgVec) | |
7fd59977 | 4814 | { |
519d35d8 | 4815 | if (theArgNb < 2) |
4816 | { | |
23fe70ec | 4817 | Message::SendFail ("Syntax error: wrong number of arguments."); |
519d35d8 | 4818 | return 1; |
4819 | } | |
ab1f4580 | 4820 | if (theArgNb == 2 |
4821 | && TCollection_AsciiString (theArgVec[1]) == "*") | |
4822 | { | |
4823 | // alias | |
4824 | return VDisplayAll (theDI, 1, theArgVec); | |
4825 | } | |
b6d587e3 | 4826 | |
4827 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
4828 | if (aCtx.IsNull()) | |
519d35d8 | 4829 | { |
7fd59977 | 4830 | ViewerTest::ViewerInit(); |
4e18052b | 4831 | aCtx = ViewerTest::GetAISContext(); |
7fd59977 | 4832 | } |
4833 | ||
b6d587e3 | 4834 | // Parse input arguments |
4e18052b | 4835 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
a1954302 | 4836 | Standard_Integer isMutable = -1; |
4837 | Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN; | |
a1954302 | 4838 | Standard_Boolean toReDisplay = Standard_False; |
af65fb19 | 4839 | Standard_Integer isSelectable = -1; |
4840 | Standard_Integer anObjDispMode = -2; | |
4841 | Standard_Integer anObjHighMode = -2; | |
4842 | Standard_Boolean toSetTrsfPers = Standard_False; | |
e816dce3 | 4843 | Standard_Boolean toEcho = Standard_True; |
778cd667 | 4844 | Handle(Graphic3d_TransformPers) aTrsfPers; |
b6d587e3 | 4845 | TColStd_SequenceOfAsciiString aNamesOfDisplayIO; |
a1954302 | 4846 | AIS_DisplayStatus aDispStatus = AIS_DS_None; |
a272ed94 | 4847 | Standard_Integer toDisplayInView = Standard_False; |
519d35d8 | 4848 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
4849 | { | |
b7cd4ba7 | 4850 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
4851 | TCollection_AsciiString aNameCase = aName; | |
4852 | aNameCase.LowerCase(); | |
4e18052b | 4853 | if (anUpdateTool.parseRedrawMode (aName)) |
519d35d8 | 4854 | { |
4855 | continue; | |
4856 | } | |
b7cd4ba7 | 4857 | else if (aNameCase == "-mutable") |
4858 | { | |
4859 | isMutable = 1; | |
b7cd4ba7 | 4860 | } |
a1954302 | 4861 | else if (aNameCase == "-neutral") |
4862 | { | |
4863 | aDispStatus = AIS_DS_Displayed; | |
4864 | } | |
4865 | else if (aNameCase == "-immediate" | |
4866 | || aNameCase == "-top") | |
4867 | { | |
4868 | aZLayer = Graphic3d_ZLayerId_Top; | |
4869 | } | |
4870 | else if (aNameCase == "-topmost") | |
4871 | { | |
4872 | aZLayer = Graphic3d_ZLayerId_Topmost; | |
4873 | } | |
4874 | else if (aNameCase == "-osd" | |
af65fb19 | 4875 | || aNameCase == "-toposd" |
4876 | || aNameCase == "-overlay") | |
a1954302 | 4877 | { |
4878 | aZLayer = Graphic3d_ZLayerId_TopOSD; | |
4879 | } | |
af65fb19 | 4880 | else if (aNameCase == "-botosd" |
4881 | || aNameCase == "-underlay") | |
4882 | { | |
4883 | aZLayer = Graphic3d_ZLayerId_BotOSD; | |
4884 | } | |
4885 | else if (aNameCase == "-select" | |
4886 | || aNameCase == "-selectable") | |
4887 | { | |
4888 | isSelectable = 1; | |
4889 | } | |
4890 | else if (aNameCase == "-noselect" | |
4891 | || aNameCase == "-noselection") | |
4892 | { | |
4893 | isSelectable = 0; | |
4894 | } | |
4895 | else if (aNameCase == "-dispmode" | |
4896 | || aNameCase == "-displaymode") | |
4897 | { | |
4898 | if (++anArgIter >= theArgNb) | |
4899 | { | |
23fe70ec | 4900 | Message::SendFail() << "Error: wrong syntax at " << aName << "."; |
af65fb19 | 4901 | return 1; |
4902 | } | |
4903 | ||
4904 | anObjDispMode = Draw::Atoi (theArgVec [anArgIter]); | |
4905 | } | |
ab1f4580 | 4906 | else if (aNameCase == "-himode" |
4907 | || aNameCase == "-highmode" | |
af65fb19 | 4908 | || aNameCase == "-highlightmode") |
4909 | { | |
4910 | if (++anArgIter >= theArgNb) | |
4911 | { | |
23fe70ec | 4912 | Message::SendFail() << "Error: wrong syntax at " << aName << "."; |
af65fb19 | 4913 | return 1; |
4914 | } | |
4915 | ||
4916 | anObjHighMode = Draw::Atoi (theArgVec [anArgIter]); | |
4917 | } | |
4918 | else if (aNameCase == "-3d") | |
4919 | { | |
4920 | toSetTrsfPers = Standard_True; | |
778cd667 | 4921 | aTrsfPers.Nullify(); |
af65fb19 | 4922 | } |
778cd667 | 4923 | else if (aNameCase == "-2d" |
4924 | || aNameCase == "-trihedron" | |
4925 | || aNameCase == "-triedron") | |
af65fb19 | 4926 | { |
4927 | toSetTrsfPers = Standard_True; | |
778cd667 | 4928 | aTrsfPers = new Graphic3d_TransformPers (aNameCase == "-2d" ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER); |
4929 | ||
4930 | if (anArgIter + 1 < theArgNb) | |
4931 | { | |
4932 | Aspect_TypeOfTriedronPosition aCorner = Aspect_TOTP_CENTER; | |
4933 | if (parseTrsfPersCorner (theArgVec[anArgIter + 1], aCorner)) | |
4934 | { | |
4935 | ++anArgIter; | |
4936 | aTrsfPers->SetCorner2d (aCorner); | |
4937 | ||
4938 | if (anArgIter + 2 < theArgNb) | |
4939 | { | |
4940 | TCollection_AsciiString anX (theArgVec[anArgIter + 1]); | |
4941 | TCollection_AsciiString anY (theArgVec[anArgIter + 2]); | |
4942 | if (anX.IsIntegerValue() | |
4943 | && anY.IsIntegerValue()) | |
4944 | { | |
4945 | anArgIter += 2; | |
4946 | aTrsfPers->SetOffset2d (Graphic3d_Vec2i (anX.IntegerValue(), anY.IntegerValue())); | |
4947 | } | |
4948 | } | |
4949 | } | |
4950 | } | |
af65fb19 | 4951 | } |
af65fb19 | 4952 | else if (aNameCase == "-trsfpers" |
4953 | || aNameCase == "-pers") | |
4954 | { | |
778cd667 | 4955 | if (++anArgIter >= theArgNb |
4956 | || !aTrsfPers.IsNull()) | |
af65fb19 | 4957 | { |
23fe70ec | 4958 | Message::SendFail() << "Error: wrong syntax at " << aName << "."; |
af65fb19 | 4959 | return 1; |
4960 | } | |
4961 | ||
4962 | toSetTrsfPers = Standard_True; | |
778cd667 | 4963 | Graphic3d_TransModeFlags aTrsfPersFlags = Graphic3d_TMF_None; |
af65fb19 | 4964 | TCollection_AsciiString aPersFlags (theArgVec [anArgIter]); |
4965 | aPersFlags.LowerCase(); | |
778cd667 | 4966 | if (!parseTrsfPersFlag (aPersFlags, aTrsfPersFlags)) |
af65fb19 | 4967 | { |
23fe70ec | 4968 | Message::SendFail() << "Error: wrong transform persistence flags " << theArgVec [anArgIter] << "."; |
778cd667 | 4969 | return 1; |
4970 | } | |
af65fb19 | 4971 | |
778cd667 | 4972 | if (aTrsfPersFlags == Graphic3d_TMF_TriedronPers) |
4973 | { | |
4974 | aTrsfPers = new Graphic3d_TransformPers (Graphic3d_TMF_TriedronPers, Aspect_TOTP_LEFT_LOWER); | |
4975 | } | |
4976 | else if (aTrsfPersFlags != Graphic3d_TMF_None) | |
4977 | { | |
4978 | aTrsfPers = new Graphic3d_TransformPers (aTrsfPersFlags, gp_Pnt()); | |
af65fb19 | 4979 | } |
4980 | } | |
4981 | else if (aNameCase == "-trsfperspos" | |
4982 | || aNameCase == "-perspos") | |
4983 | { | |
778cd667 | 4984 | if (anArgIter + 2 >= theArgNb |
4985 | || aTrsfPers.IsNull()) | |
af65fb19 | 4986 | { |
23fe70ec | 4987 | Message::SendFail() << "Error: wrong syntax at " << aName << "."; |
af65fb19 | 4988 | return 1; |
4989 | } | |
4990 | ||
4991 | TCollection_AsciiString aX (theArgVec[++anArgIter]); | |
4992 | TCollection_AsciiString aY (theArgVec[++anArgIter]); | |
4993 | TCollection_AsciiString aZ = "0"; | |
d45edf24 | 4994 | if (!aX.IsRealValue (Standard_True) |
4995 | || !aY.IsRealValue (Standard_True)) | |
af65fb19 | 4996 | { |
23fe70ec | 4997 | Message::SendFail() << "Error: wrong syntax at " << aName << "."; |
af65fb19 | 4998 | return 1; |
4999 | } | |
5000 | if (anArgIter + 1 < theArgNb) | |
5001 | { | |
5002 | TCollection_AsciiString aTemp = theArgVec[anArgIter + 1]; | |
d45edf24 | 5003 | if (aTemp.IsRealValue (Standard_True)) |
af65fb19 | 5004 | { |
5005 | aZ = aTemp; | |
5006 | ++anArgIter; | |
5007 | } | |
5008 | } | |
778cd667 | 5009 | |
778cd667 | 5010 | if (aTrsfPers->IsZoomOrRotate()) |
5011 | { | |
f4e7c307 | 5012 | aTrsfPers->SetAnchorPoint (gp_Pnt (aX.RealValue(), aY.RealValue(), aZ.RealValue())); |
778cd667 | 5013 | } |
5014 | else if (aTrsfPers->IsTrihedronOr2d()) | |
5015 | { | |
f4e7c307 | 5016 | Standard_Integer aCorner = Aspect_TOTP_CENTER; |
5017 | if (aX.RealValue() > 0.0) { aCorner |= Aspect_TOTP_RIGHT; } | |
5018 | else if (aX.RealValue() < 0.0) { aCorner |= Aspect_TOTP_LEFT; } | |
5019 | if (aY.RealValue() > 0.0) { aCorner |= Aspect_TOTP_TOP; } | |
5020 | else if (aY.RealValue() < 0.0) { aCorner |= Aspect_TOTP_BOTTOM; } | |
5021 | aTrsfPers = new Graphic3d_TransformPers (aTrsfPers->Mode(), Aspect_TypeOfTriedronPosition (aCorner), Graphic3d_Vec2i (aZ.IntegerValue())); | |
778cd667 | 5022 | } |
af65fb19 | 5023 | } |
55c8f0f7 BB |
5024 | else if (aNameCase == "-layer" |
5025 | || aNameCase == "-zlayer") | |
a1954302 | 5026 | { |
55c8f0f7 BB |
5027 | ++anArgIter; |
5028 | if (anArgIter >= theArgNb | |
5029 | || !ViewerTest::ParseZLayer (theArgVec[anArgIter], aZLayer) | |
5030 | || aZLayer == Graphic3d_ZLayerId_UNKNOWN) | |
a1954302 | 5031 | { |
23fe70ec | 5032 | Message::SendFail() << "Error: wrong syntax at " << aName << "."; |
a1954302 | 5033 | return 1; |
5034 | } | |
a1954302 | 5035 | } |
a272ed94 | 5036 | else if (aNameCase == "-view" |
5037 | || aNameCase == "-inview") | |
5038 | { | |
5039 | toDisplayInView = Standard_True; | |
5040 | } | |
a1954302 | 5041 | else if (aNameCase == "-redisplay") |
5042 | { | |
5043 | toReDisplay = Standard_True; | |
5044 | } | |
6194ee76 | 5045 | else if (aNameCase == "-erased" |
5046 | || aNameCase == "-load") | |
5047 | { | |
5048 | aDispStatus = AIS_DS_Erased; | |
5049 | } | |
e816dce3 | 5050 | else if (aNameCase == "-noecho") |
5051 | { | |
5052 | toEcho = false; | |
5053 | } | |
b6d587e3 | 5054 | else |
5055 | { | |
5056 | aNamesOfDisplayIO.Append (aName); | |
5057 | } | |
5058 | } | |
5059 | ||
5060 | if (aNamesOfDisplayIO.IsEmpty()) | |
5061 | { | |
23fe70ec | 5062 | Message::SendFail ("Syntax error: wrong number of arguments."); |
b6d587e3 | 5063 | return 1; |
5064 | } | |
5065 | ||
b6d587e3 | 5066 | // Display interactive objects |
5067 | for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter) | |
5068 | { | |
1c8fc6be | 5069 | const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value (anIter); |
8f521168 | 5070 | Handle(AIS_InteractiveObject) aShape; |
5071 | if (!GetMapOfAIS().Find2 (aName, aShape)) | |
519d35d8 | 5072 | { |
5073 | // create the AIS_Shape from a name | |
1c8fc6be | 5074 | TopoDS_Shape aDrawShape = DBRep::GetExisting (aName); |
5075 | if (!aDrawShape.IsNull()) | |
519d35d8 | 5076 | { |
1c8fc6be | 5077 | aShape = new AIS_Shape (aDrawShape); |
b7cd4ba7 | 5078 | if (isMutable != -1) |
5079 | { | |
5080 | aShape->SetMutable (isMutable == 1); | |
5081 | } | |
a1954302 | 5082 | if (aZLayer != Graphic3d_ZLayerId_UNKNOWN) |
5083 | { | |
5084 | aShape->SetZLayer (aZLayer); | |
5085 | } | |
af65fb19 | 5086 | if (toSetTrsfPers) |
5087 | { | |
778cd667 | 5088 | aCtx->SetTransformPersistence (aShape, aTrsfPers); |
af65fb19 | 5089 | } |
5090 | if (anObjDispMode != -2) | |
5091 | { | |
ab1f4580 | 5092 | if (anObjDispMode == -1) |
5093 | { | |
5094 | aShape->UnsetDisplayMode(); | |
5095 | } | |
5096 | if (!aShape->AcceptDisplayMode (anObjDispMode)) | |
5097 | { | |
23fe70ec | 5098 | Message::SendFail() << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjDispMode << " display mode"; |
ab1f4580 | 5099 | return 1; |
5100 | } | |
5101 | else | |
5102 | { | |
5103 | aShape->SetDisplayMode (anObjDispMode); | |
5104 | } | |
af65fb19 | 5105 | } |
5106 | if (anObjHighMode != -2) | |
5107 | { | |
ab1f4580 | 5108 | if (anObjHighMode != -1 |
5109 | && !aShape->AcceptDisplayMode (anObjHighMode)) | |
5110 | { | |
23fe70ec | 5111 | Message::SendFail() << "Syntax error: " << aShape->DynamicType()->Name() << " rejects " << anObjHighMode << " display mode"; |
ab1f4580 | 5112 | return 1; |
5113 | } | |
af65fb19 | 5114 | aShape->SetHilightMode (anObjHighMode); |
5115 | } | |
a1954302 | 5116 | |
68dcee02 | 5117 | GetMapOfAIS().Bind (aShape, aName); |
a1954302 | 5118 | Standard_Integer aDispMode = aShape->HasDisplayMode() |
5119 | ? aShape->DisplayMode() | |
5120 | : (aShape->AcceptDisplayMode (aCtx->DisplayMode()) | |
5121 | ? aCtx->DisplayMode() | |
5122 | : 0); | |
af65fb19 | 5123 | Standard_Integer aSelMode = -1; |
825aa485 | 5124 | if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection())) |
af65fb19 | 5125 | { |
c3282ec1 | 5126 | aSelMode = aShape->GlobalSelectionMode(); |
af65fb19 | 5127 | } |
a1954302 | 5128 | |
68dcee02 | 5129 | aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus); |
a272ed94 | 5130 | if (toDisplayInView) |
5131 | { | |
6a24c6de | 5132 | for (V3d_ListOfViewIterator aViewIter (aCtx->CurrentViewer()->DefinedViewIterator()); aViewIter.More(); aViewIter.Next()) |
a272ed94 | 5133 | { |
6a24c6de | 5134 | aCtx->SetViewAffinity (aShape, aViewIter.Value(), Standard_False); |
a272ed94 | 5135 | } |
5136 | aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True); | |
5137 | } | |
519d35d8 | 5138 | } |
af65fb19 | 5139 | else |
5140 | { | |
23fe70ec | 5141 | Message::SendFail() << "Error: object with name '" << aName << "' does not exist!"; |
af65fb19 | 5142 | } |
519d35d8 | 5143 | continue; |
5144 | } | |
7fd59977 | 5145 | |
d09dda09 | 5146 | if (isMutable != -1) |
519d35d8 | 5147 | { |
d09dda09 | 5148 | aShape->SetMutable (isMutable == 1); |
5149 | } | |
5150 | if (aZLayer != Graphic3d_ZLayerId_UNKNOWN) | |
5151 | { | |
5152 | aShape->SetZLayer (aZLayer); | |
5153 | } | |
5154 | if (toSetTrsfPers) | |
5155 | { | |
778cd667 | 5156 | aCtx->SetTransformPersistence (aShape, aTrsfPers); |
d09dda09 | 5157 | } |
5158 | if (anObjDispMode != -2) | |
5159 | { | |
5160 | aShape->SetDisplayMode (anObjDispMode); | |
5161 | } | |
5162 | if (anObjHighMode != -2) | |
5163 | { | |
5164 | aShape->SetHilightMode (anObjHighMode); | |
5165 | } | |
5166 | Standard_Integer aDispMode = aShape->HasDisplayMode() | |
5167 | ? aShape->DisplayMode() | |
5168 | : (aShape->AcceptDisplayMode (aCtx->DisplayMode()) | |
5169 | ? aCtx->DisplayMode() | |
5170 | : 0); | |
5171 | Standard_Integer aSelMode = -1; | |
825aa485 | 5172 | if (isSelectable == 1 || (isSelectable == -1 && aCtx->GetAutoActivateSelection())) |
d09dda09 | 5173 | { |
c3282ec1 | 5174 | aSelMode = aShape->GlobalSelectionMode(); |
d09dda09 | 5175 | } |
5176 | ||
82b856b8 | 5177 | if (aShape->Type() == AIS_KindOfInteractive_Datum) |
d09dda09 | 5178 | { |
5179 | aCtx->Display (aShape, Standard_False); | |
5180 | } | |
5181 | else | |
5182 | { | |
e816dce3 | 5183 | if (toEcho) |
5184 | { | |
5185 | theDI << "Display " << aName << "\n"; | |
5186 | } | |
d09dda09 | 5187 | |
5188 | // update the Shape in the AIS_Shape | |
1c8fc6be | 5189 | TopoDS_Shape aNewShape = DBRep::GetExisting (aName); |
d09dda09 | 5190 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape); |
5191 | if (!aShapePrs.IsNull()) | |
af65fb19 | 5192 | { |
d09dda09 | 5193 | if (!aShapePrs->Shape().IsEqual (aNewShape)) |
5194 | { | |
5195 | toReDisplay = Standard_True; | |
5196 | } | |
5197 | aShapePrs->Set (aNewShape); | |
af65fb19 | 5198 | } |
d09dda09 | 5199 | if (toReDisplay) |
af65fb19 | 5200 | { |
d09dda09 | 5201 | aCtx->Redisplay (aShape, Standard_False); |
af65fb19 | 5202 | } |
b7cd4ba7 | 5203 | |
d09dda09 | 5204 | if (aSelMode == -1) |
519d35d8 | 5205 | { |
0577ae8c | 5206 | aCtx->Erase (aShape, Standard_False); |
519d35d8 | 5207 | } |
68dcee02 | 5208 | aCtx->Display (aShape, aDispMode, aSelMode, Standard_False, aDispStatus); |
d09dda09 | 5209 | if (toDisplayInView) |
519d35d8 | 5210 | { |
d09dda09 | 5211 | aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True); |
7fd59977 | 5212 | } |
5213 | } | |
7fd59977 | 5214 | } |
b6d587e3 | 5215 | |
7fd59977 | 5216 | return 0; |
5217 | } | |
5218 | ||
bc001a40 | 5219 | //======================================================================= |
5220 | //function : VNbDisplayed | |
5221 | //purpose : Returns number of displayed objects | |
5222 | //======================================================================= | |
5223 | static Standard_Integer VNbDisplayed (Draw_Interpretor& theDi, | |
5224 | Standard_Integer theArgsNb, | |
5225 | const char** theArgVec) | |
5226 | { | |
5227 | if(theArgsNb != 1) | |
5228 | { | |
5229 | theDi << "Usage : " << theArgVec[0] << "\n"; | |
5230 | return 1; | |
5231 | } | |
5232 | ||
5233 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5234 | if (aContextAIS.IsNull()) | |
5235 | { | |
23fe70ec | 5236 | Message::SendFail ("Syntax error: AIS context is not available."); |
bc001a40 | 5237 | return 1; |
5238 | } | |
5239 | ||
5240 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5241 | if(aContext.IsNull()) | |
5242 | { | |
5243 | theDi << "use 'vinit' command before " << theArgVec[0] << "\n"; | |
5244 | return 1; | |
5245 | } | |
5246 | ||
5247 | AIS_ListOfInteractive aListOfIO; | |
68dcee02 | 5248 | aContextAIS->DisplayedObjects (aListOfIO); |
bc001a40 | 5249 | |
5250 | theDi << aListOfIO.Extent() << "\n"; | |
5251 | return 0; | |
5252 | } | |
5253 | ||
f3889691 | 5254 | //=============================================================================================== |
5255 | //function : VUpdate | |
5256 | //purpose : | |
5257 | //=============================================================================================== | |
5258 | static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) | |
5259 | { | |
5260 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
5261 | if (aContextAIS.IsNull()) | |
5262 | { | |
23fe70ec | 5263 | Message::SendFail ("Syntax error: AIS context is not available."); |
f3889691 | 5264 | return 1; |
5265 | } | |
5266 | ||
5267 | if (theArgsNb < 2) | |
5268 | { | |
23fe70ec | 5269 | Message::SendFail ("Syntax error: insufficient arguments. Type help for more information."); |
f3889691 | 5270 | return 1; |
5271 | } | |
5272 | ||
f3889691 | 5273 | AIS_ListOfInteractive aListOfIO; |
f3889691 | 5274 | for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) |
5275 | { | |
5276 | TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]); | |
5277 | ||
5278 | Handle(AIS_InteractiveObject) anAISObj; | |
8f521168 | 5279 | GetMapOfAIS().Find2 (aName, anAISObj); |
f3889691 | 5280 | if (anAISObj.IsNull()) |
5281 | { | |
23fe70ec | 5282 | Message::SendFail() << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\"."; |
f3889691 | 5283 | return 1; |
5284 | } | |
5285 | ||
5286 | aListOfIO.Append (anAISObj); | |
5287 | } | |
5288 | ||
5289 | AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); | |
5290 | for (; anIOIt.More(); anIOIt.Next()) | |
5291 | { | |
5292 | aContextAIS->Update (anIOIt.Value(), Standard_False); | |
5293 | } | |
5294 | ||
5295 | aContextAIS->UpdateCurrentViewer(); | |
5296 | ||
5297 | return 0; | |
5298 | } | |
5299 | ||
7fd59977 | 5300 | //============================================================================== |
5301 | //function : VShading | |
5302 | //purpose : Sharpen or roughten the quality of the shading | |
5303 | //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg | |
5304 | //============================================================================== | |
5cbef0fe S |
5305 | static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) |
5306 | { | |
7fd59977 | 5307 | Standard_Real myDevCoef; |
5308 | Handle(AIS_InteractiveObject) TheAisIO; | |
5309 | ||
5310 | // Verifications | |
5cbef0fe | 5311 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0); |
7fd59977 | 5312 | if (argc < 3) { |
5313 | myDevCoef = 0.0008; | |
5314 | } else { | |
91322f44 | 5315 | myDevCoef =Draw::Atof(argv[2]); |
7fd59977 | 5316 | } |
5317 | ||
7fd59977 | 5318 | TCollection_AsciiString name=argv[1]; |
8f521168 | 5319 | GetMapOfAIS().Find2(name, TheAisIO); |
7fd59977 | 5320 | if (TheAisIO.IsNull()) |
1c8fc6be | 5321 | { |
5322 | TopoDS_Shape aDrawShape = DBRep::GetExisting (name); | |
5323 | if (!aDrawShape.IsNull()) | |
5324 | { | |
5325 | TheAisIO = new AIS_Shape (aDrawShape); | |
5326 | } | |
5327 | } | |
7fd59977 | 5328 | |
5cbef0fe | 5329 | if (HaveToSet) |
7fd59977 | 5330 | TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True); |
5cbef0fe | 5331 | else |
7fd59977 | 5332 | TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True); |
5333 | ||
0577ae8c | 5334 | TheAISContext()->Redisplay (TheAisIO, Standard_True); |
7fd59977 | 5335 | return 0; |
5336 | } | |
7fd59977 | 5337 | |
cb78155f | 5338 | //! Auxiliary method to print Interactive Object information |
5339 | static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected, | |
8f521168 | 5340 | const Handle(AIS_InteractiveObject)& theObj, |
cb78155f | 5341 | Draw_Interpretor& theDI) |
5342 | { | |
8f521168 | 5343 | if (theObj.IsNull()) |
cb78155f | 5344 | { |
8f521168 | 5345 | theDI << "NULL presentation\n"; |
cb78155f | 5346 | return; |
5347 | } | |
7fd59977 | 5348 | |
8f521168 | 5349 | theDI << (TheAISContext()->IsDisplayed (theObj) ? "Displayed" : "Hidden ") |
5350 | << (TheAISContext()->IsSelected (theObj) ? " Selected" : " ") | |
5351 | << (theDetected.Contains (theObj) ? " Detected" : " ") | |
cb78155f | 5352 | << " Type: "; |
82b856b8 | 5353 | if (theObj->Type() == AIS_KindOfInteractive_Datum) |
cb78155f | 5354 | { |
5355 | // AIS_Datum | |
8f521168 | 5356 | if (theObj->Signature() == 3) { theDI << " AIS_Trihedron"; } |
5357 | else if (theObj->Signature() == 2) { theDI << " AIS_Axis"; } | |
5358 | else if (theObj->Signature() == 6) { theDI << " AIS_Circle"; } | |
5359 | else if (theObj->Signature() == 5) { theDI << " AIS_Line"; } | |
5360 | else if (theObj->Signature() == 7) { theDI << " AIS_Plane"; } | |
5361 | else if (theObj->Signature() == 1) { theDI << " AIS_Point"; } | |
5362 | else if (theObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; } | |
7fd59977 | 5363 | } |
5364 | // AIS_Shape | |
82b856b8 | 5365 | else if (theObj->Type() == AIS_KindOfInteractive_Shape |
8f521168 | 5366 | && theObj->Signature() == 0) |
cb78155f | 5367 | { |
5368 | theDI << " AIS_Shape"; | |
7fd59977 | 5369 | } |
82b856b8 | 5370 | else if (theObj->Type() == AIS_KindOfInteractive_Relation) |
cb78155f | 5371 | { |
4551e1be | 5372 | // PrsDim_Dimension and AIS_Relation |
787ff240 | 5373 | Handle(PrsDim_Relation) aRelation = Handle(PrsDim_Relation)::DownCast (theObj); |
cb78155f | 5374 | switch (aRelation->KindOfDimension()) |
5375 | { | |
787ff240 | 5376 | case PrsDim_KOD_PLANEANGLE: theDI << " PrsDim_AngleDimension"; break; |
5377 | case PrsDim_KOD_LENGTH: theDI << " PrsDim_Chamf2/3dDimension/PrsDim_LengthDimension"; break; | |
5378 | case PrsDim_KOD_DIAMETER: theDI << " PrsDim_DiameterDimension"; break; | |
5379 | case PrsDim_KOD_ELLIPSERADIUS: theDI << " PrsDim_EllipseRadiusDimension"; break; | |
5380 | //case PrsDim_KOD_FILLETRADIUS: theDI << " PrsDim_FilletRadiusDimension "; break; | |
5381 | case PrsDim_KOD_OFFSET: theDI << " PrsDim_OffsetDimension"; break; | |
5382 | case PrsDim_KOD_RADIUS: theDI << " PrsDim_RadiusDimension"; break; | |
cb78155f | 5383 | default: theDI << " UNKNOWN dimension"; break; |
5384 | } | |
5385 | } | |
5386 | else | |
5387 | { | |
5388 | theDI << " UserPrs"; | |
5389 | } | |
8f521168 | 5390 | theDI << " (" << theObj->DynamicType()->Name() << ")"; |
7fd59977 | 5391 | } |
5392 | ||
cb78155f | 5393 | //! Print information about locally selected sub-shapes |
23963a92 | 5394 | template <typename T> |
5395 | static void printLocalSelectionInfo (const T& theContext, Draw_Interpretor& theDI) | |
cb78155f | 5396 | { |
a9dde4a3 | 5397 | const Standard_Boolean isGlobalCtx = (theContext->DynamicType() == STANDARD_TYPE(AIS_InteractiveContext)); |
cb78155f | 5398 | TCollection_AsciiString aPrevName; |
23963a92 | 5399 | for (theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected()) |
cb78155f | 5400 | { |
23963a92 | 5401 | const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (theContext->SelectedInteractive()); |
5402 | const Handle(SelectMgr_EntityOwner) anOwner = theContext->SelectedOwner(); | |
5403 | if (aShapeIO.IsNull() || anOwner.IsNull()) | |
5404 | continue; | |
5405 | if (isGlobalCtx) | |
5406 | { | |
5407 | if (anOwner == aShapeIO->GlobalSelOwner()) | |
5408 | continue; | |
5409 | } | |
5410 | const TopoDS_Shape aSubShape = theContext->SelectedShape(); | |
cb78155f | 5411 | if (aSubShape.IsNull() |
5412 | || aShapeIO.IsNull() | |
5413 | || !GetMapOfAIS().IsBound1 (aShapeIO)) | |
5414 | { | |
5415 | continue; | |
5416 | } | |
5417 | ||
5418 | const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO); | |
5419 | TopTools_MapOfShape aFilter; | |
5420 | Standard_Integer aNumber = 0; | |
5421 | const TopoDS_Shape aShape = aShapeIO->Shape(); | |
5422 | for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType()); | |
5423 | anIter.More(); anIter.Next()) | |
5424 | { | |
5425 | if (!aFilter.Add (anIter.Current())) | |
5426 | { | |
5427 | continue; // filter duplicates | |
5428 | } | |
5429 | ||
5430 | ++aNumber; | |
5431 | if (!anIter.Current().IsSame (aSubShape)) | |
5432 | { | |
5433 | continue; | |
5434 | } | |
5435 | ||
5436 | Standard_CString aShapeName = NULL; | |
5437 | switch (aSubShape.ShapeType()) | |
5438 | { | |
5439 | case TopAbs_COMPOUND: aShapeName = " Compound"; break; | |
5440 | case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break; | |
5441 | case TopAbs_SOLID: aShapeName = " Solid"; break; | |
5442 | case TopAbs_SHELL: aShapeName = " Shell"; break; | |
5443 | case TopAbs_FACE: aShapeName = " Face"; break; | |
5444 | case TopAbs_WIRE: aShapeName = " Wire"; break; | |
5445 | case TopAbs_EDGE: aShapeName = " Edge"; break; | |
5446 | case TopAbs_VERTEX: aShapeName = " Vertex"; break; | |
5447 | default: | |
5448 | case TopAbs_SHAPE: aShapeName = " Shape"; break; | |
5449 | } | |
5450 | ||
5451 | if (aParentName != aPrevName) | |
5452 | { | |
5453 | theDI << "Locally selected sub-shapes within " << aParentName << ":\n"; | |
5454 | aPrevName = aParentName; | |
5455 | } | |
5456 | theDI << " " << aShapeName << " #" << aNumber << "\n"; | |
5457 | break; | |
5458 | } | |
5459 | } | |
5460 | } | |
7fd59977 | 5461 | |
5462 | //============================================================================== | |
5463 | //function : VState | |
5464 | //purpose : | |
7fd59977 | 5465 | //============================================================================== |
cb78155f | 5466 | static Standard_Integer VState (Draw_Interpretor& theDI, |
5467 | Standard_Integer theArgNb, | |
5468 | Standard_CString* theArgVec) | |
7fd59977 | 5469 | { |
cb78155f | 5470 | Handle(AIS_InteractiveContext) aCtx = TheAISContext(); |
5471 | if (aCtx.IsNull()) | |
5472 | { | |
23fe70ec | 5473 | Message::SendFail ("Error: No opened viewer!"); |
cb78155f | 5474 | return 1; |
7fd59977 | 5475 | } |
cb78155f | 5476 | |
51023771 | 5477 | Standard_Boolean toPrintEntities = Standard_False; |
5478 | Standard_Boolean toCheckSelected = Standard_False; | |
5479 | ||
5480 | for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx) | |
5481 | { | |
5482 | TCollection_AsciiString anOption (theArgVec[anArgIdx]); | |
5483 | anOption.LowerCase(); | |
5484 | if (anOption == "-detectedentities" | |
5485 | || anOption == "-entities") | |
5486 | { | |
5487 | toPrintEntities = Standard_True; | |
5488 | } | |
5489 | else if (anOption == "-hasselected") | |
5490 | { | |
5491 | toCheckSelected = Standard_True; | |
5492 | } | |
5493 | } | |
5494 | ||
5495 | if (toCheckSelected) | |
5496 | { | |
5497 | aCtx->InitSelected(); | |
5498 | TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape())); | |
5499 | theDI << "Check if context has selected shape: " << hasSelected << "\n"; | |
5500 | ||
5501 | return 0; | |
5502 | } | |
5503 | ||
5504 | if (toPrintEntities) | |
8e7c8ccf | 5505 | { |
5506 | theDI << "Detected entities:\n"; | |
68dcee02 | 5507 | Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->MainSelector(); |
5508 | ||
7479f643 | 5509 | SelectMgr_SelectingVolumeManager aMgr = aSelector->GetManager(); |
aa75c0cf | 5510 | for (Standard_Integer aPickIter = 1; aPickIter <= aSelector->NbPicked(); ++aPickIter) |
8e7c8ccf | 5511 | { |
0ef04197 | 5512 | const SelectMgr_SortCriterion& aPickData = aSelector->PickedData (aPickIter); |
5513 | const Handle(Select3D_SensitiveEntity)& anEntity = aSelector->PickedEntity (aPickIter); | |
5514 | const Handle(SelectMgr_EntityOwner)& anOwner = anEntity->OwnerId(); | |
5515 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
ab1f4580 | 5516 | |
5517 | TCollection_AsciiString aName; | |
5518 | GetMapOfAIS().Find1 (anObj, aName); | |
8e7c8ccf | 5519 | aName.LeftJustify (20, ' '); |
5520 | char anInfoStr[512]; | |
2615c2d7 | 5521 | if (aPickData.Normal.SquareModulus() > ShortRealEpsilon()) |
5522 | { | |
5523 | Sprintf (anInfoStr, | |
5524 | " Depth: %g Distance: %g Point: %g %g %g Normal: %g %g %g", | |
5525 | aPickData.Depth, | |
5526 | aPickData.MinDist, | |
5527 | aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z(), | |
5528 | aPickData.Normal.x(), aPickData.Normal.y(), aPickData.Normal.z()); | |
5529 | } | |
5530 | else | |
5531 | { | |
5532 | Sprintf (anInfoStr, | |
5533 | " Depth: %g Distance: %g Point: %g %g %g", | |
5534 | aPickData.Depth, | |
5535 | aPickData.MinDist, | |
5536 | aPickData.Point.X(), aPickData.Point.Y(), aPickData.Point.Z()); | |
5537 | } | |
8e7c8ccf | 5538 | theDI << " " << aName |
5539 | << anInfoStr | |
5540 | << " (" << anEntity->DynamicType()->Name() << ")" | |
5541 | << "\n"; | |
5542 | ||
73dc2d3a | 5543 | if (Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner)) |
8e7c8ccf | 5544 | { |
5545 | theDI << " Detected Shape: " | |
5546 | << aBRepOwner->Shape().TShape()->DynamicType()->Name() | |
5547 | << "\n"; | |
5548 | } | |
5549 | ||
73dc2d3a | 5550 | if (Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity)) |
8e7c8ccf | 5551 | { |
5552 | Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected(); | |
5553 | theDI << " Detected Child: " | |
5554 | << aSen->DynamicType()->Name() | |
5555 | << "\n"; | |
5556 | } | |
73dc2d3a | 5557 | else if (Handle(Select3D_SensitivePrimitiveArray) aPrimArr = Handle(Select3D_SensitivePrimitiveArray)::DownCast (anEntity)) |
8b9a309b | 5558 | { |
5559 | theDI << " Detected Element: " | |
5560 | << aPrimArr->LastDetectedElement() | |
5561 | << "\n"; | |
5562 | } | |
73dc2d3a | 5563 | else if (Handle(Select3D_SensitiveTriangulation) aTriSens = Handle(Select3D_SensitiveTriangulation)::DownCast (anEntity)) |
5564 | { | |
5565 | theDI << " Detected Triangle: " | |
5566 | << aTriSens->LastDetectedTriangleIndex() | |
5567 | << "\n"; | |
5568 | } | |
8e7c8ccf | 5569 | } |
5570 | return 0; | |
5571 | } | |
5572 | ||
cb78155f | 5573 | NCollection_Map<Handle(AIS_InteractiveObject)> aDetected; |
5574 | for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected()) | |
5575 | { | |
68dcee02 | 5576 | aDetected.Add (Handle(AIS_InteractiveObject)::DownCast (aCtx->DetectedCurrentOwner()->Selectable())); |
cb78155f | 5577 | } |
5578 | ||
5579 | const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*'); | |
5580 | if (theArgNb >= 2 | |
5581 | && !toShowAll) | |
5582 | { | |
5583 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7fd59977 | 5584 | { |
cb78155f | 5585 | const TCollection_AsciiString anObjName = theArgVec[anArgIter]; |
8f521168 | 5586 | Handle(AIS_InteractiveObject) anObj; |
5587 | if (!GetMapOfAIS().Find2 (anObjName, anObj)) | |
cb78155f | 5588 | { |
5589 | theDI << anObjName << " doesn't exist!\n"; | |
5590 | continue; | |
7fd59977 | 5591 | } |
5592 | ||
cb78155f | 5593 | TCollection_AsciiString aName = anObjName; |
5594 | aName.LeftJustify (20, ' '); | |
5595 | theDI << " " << aName << " "; | |
8f521168 | 5596 | objInfo (aDetected, anObj, theDI); |
cb78155f | 5597 | theDI << "\n"; |
7fd59977 | 5598 | } |
cb78155f | 5599 | return 0; |
7fd59977 | 5600 | } |
cb78155f | 5601 | |
68dcee02 | 5602 | if (aCtx->NbSelected() > 0 && !toShowAll) |
cb78155f | 5603 | { |
23963a92 | 5604 | NCollection_DataMap<Handle(SelectMgr_EntityOwner), TopoDS_Shape> anOwnerShapeMap; |
c3282ec1 | 5605 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected()) |
cb78155f | 5606 | { |
23963a92 | 5607 | const Handle(SelectMgr_EntityOwner) anOwner = aCtx->SelectedOwner(); |
5608 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
5609 | // handle whole object selection | |
5610 | if (anOwner == anObj->GlobalSelOwner()) | |
5611 | { | |
ab1f4580 | 5612 | TCollection_AsciiString aName; |
5613 | GetMapOfAIS().Find1 (anObj, aName); | |
23963a92 | 5614 | aName.LeftJustify (20, ' '); |
5615 | theDI << aName << " "; | |
5616 | objInfo (aDetected, anObj, theDI); | |
5617 | theDI << "\n"; | |
5618 | } | |
7fd59977 | 5619 | } |
23963a92 | 5620 | |
5621 | // process selected sub-shapes | |
5622 | printLocalSelectionInfo (aCtx, theDI); | |
5623 | ||
cb78155f | 5624 | return 0; |
7fd59977 | 5625 | } |
5626 | ||
cb78155f | 5627 | theDI << "Neutral-point state:\n"; |
5628 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); | |
5629 | anObjIter.More(); anObjIter.Next()) | |
5630 | { | |
8f521168 | 5631 | if (anObjIter.Key1().IsNull()) |
cb78155f | 5632 | { |
5633 | continue; | |
5634 | } | |
5635 | ||
5636 | TCollection_AsciiString aName = anObjIter.Key2(); | |
5637 | aName.LeftJustify (20, ' '); | |
5638 | theDI << " " << aName << " "; | |
8f521168 | 5639 | objInfo (aDetected, anObjIter.Key1(), theDI); |
cb78155f | 5640 | theDI << "\n"; |
5641 | } | |
23963a92 | 5642 | printLocalSelectionInfo (aCtx, theDI); |
7fd59977 | 5643 | return 0; |
5644 | } | |
5645 | ||
7fd59977 | 5646 | //======================================================================= |
5647 | //function : PickShape | |
5648 | //purpose : First Activate the rightmode + Put Filters to be able to | |
5649 | // pick objets that are of type <TheType>... | |
5650 | //======================================================================= | |
5651 | ||
8c088c52 | 5652 | TopoDS_Shape ViewerTest::PickShape (const TopAbs_ShapeEnum theShapeType, |
5653 | const Standard_Integer theMaxPick) | |
7fd59977 | 5654 | { |
8c088c52 | 5655 | Handle(TopTools_HArray1OfShape) aResArray = new TopTools_HArray1OfShape (1, 1); |
5656 | PickShapes (theShapeType, aResArray, theMaxPick); | |
5657 | return aResArray->First(); | |
7fd59977 | 5658 | } |
5659 | ||
7fd59977 | 5660 | //======================================================================= |
5661 | //function : PickShapes | |
5662 | //purpose : | |
5663 | //======================================================================= | |
8c088c52 | 5664 | Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum theShapeType, |
5665 | Handle(TopTools_HArray1OfShape)& theResArray, | |
5666 | const Standard_Integer theMaxPick) | |
7fd59977 | 5667 | { |
8c088c52 | 5668 | const Standard_Integer aNbToReach = theResArray->Length(); |
5669 | if (aNbToReach > 1) | |
5670 | { | |
23fe70ec | 5671 | Message::SendWarning ("WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"); |
8c088c52 | 5672 | } |
7fd59977 | 5673 | |
5674 | // step 1: prepare the data | |
8c088c52 | 5675 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); |
f41fd243 | 5676 | if (aCtx.IsNull()) |
5677 | { | |
5678 | Message::SendFail ("Error: no active viewer"); | |
5679 | return Standard_False; | |
5680 | } | |
5681 | ||
8c088c52 | 5682 | aCtx->RemoveFilters(); |
5683 | AIS_ListOfInteractive aDispObjects; | |
5684 | aCtx->DisplayedObjects (aDispObjects); | |
5685 | if (theShapeType == TopAbs_SHAPE) | |
5686 | { | |
82b856b8 | 5687 | aCtx->AddFilter (new AIS_TypeFilter (AIS_KindOfInteractive_Shape)); |
7fd59977 | 5688 | } |
8c088c52 | 5689 | else |
5690 | { | |
5691 | aCtx->AddFilter (new StdSelect_ShapeTypeFilter (theShapeType)); | |
5692 | } | |
5693 | ||
5694 | const Standard_Integer aSelMode = AIS_Shape::SelectionMode (theShapeType); | |
5695 | for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next()) | |
5696 | { | |
5697 | if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value())) | |
5698 | { | |
5699 | aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single); | |
5700 | } | |
7fd59977 | 5701 | } |
5702 | ||
5703 | // step 2 : wait for the selection... | |
8c088c52 | 5704 | Standard_Integer aNbPickGood = 0, aNbPickFail = 0; |
7fd59977 | 5705 | Standard_Integer argccc = 5; |
8c088c52 | 5706 | const char *bufff[] = { "A", "B", "C", "D", "E" }; |
5707 | const char **argvvv = (const char** )bufff; | |
5708 | for (; aNbPickGood < aNbToReach && aNbPickFail <= theMaxPick; ) | |
5709 | { | |
5710 | while (ViewerMainLoop (argccc, argvvv)) {} | |
5711 | Standard_Integer aNbStored = aCtx->NbSelected(); | |
5712 | if (aNbStored != aNbPickGood) | |
5713 | { | |
5714 | aNbPickGood = aNbStored; | |
5715 | } | |
7fd59977 | 5716 | else |
8c088c52 | 5717 | { |
5718 | ++aNbPickFail; | |
5719 | } | |
23fe70ec | 5720 | Message::SendInfo() << "NbPicked = " << aNbPickGood << " | Nb Pick Fail :" << aNbPickFail; |
7fd59977 | 5721 | } |
5722 | ||
5723 | // step3 get result. | |
8c088c52 | 5724 | if (aNbPickFail >= aNbToReach) |
5725 | { | |
76363522 | 5726 | return Standard_False; |
8c088c52 | 5727 | } |
7fd59977 | 5728 | |
8c088c52 | 5729 | Standard_Integer anIndex = theResArray->Lower(); |
5730 | for (aCtx->InitSelected(); aCtx->MoreSelected(); aCtx->NextSelected(), ++anIndex) | |
5731 | { | |
5732 | if (aCtx->HasSelectedShape()) | |
5733 | { | |
5734 | theResArray->SetValue (anIndex, aCtx->SelectedShape()); | |
5735 | } | |
5736 | else | |
5737 | { | |
5738 | Handle(AIS_InteractiveObject) IO = aCtx->SelectedInteractive(); | |
5739 | theResArray->SetValue (anIndex, Handle(AIS_Shape)::DownCast (IO)->Shape()); | |
7fd59977 | 5740 | } |
5741 | } | |
5742 | ||
8c088c52 | 5743 | aCtx->RemoveFilters(); |
5744 | if (theShapeType != TopAbs_SHAPE) | |
5745 | { | |
5746 | for (AIS_ListOfInteractive::Iterator anObjIter (aDispObjects); anObjIter.More(); anObjIter.Next()) | |
5747 | { | |
5748 | if (Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (anObjIter.Value())) | |
5749 | { | |
5750 | aCtx->SetSelectionModeActive (aShapePrs, aSelMode, true, AIS_SelectionModesConcurrency_Single); | |
5751 | } | |
5752 | } | |
5753 | } | |
7fd59977 | 5754 | return Standard_True; |
5755 | } | |
5756 | ||
7fd59977 | 5757 | //======================================================================= |
5758 | //function : VPickShape | |
5759 | //purpose : | |
5760 | //======================================================================= | |
5761 | static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
5762 | { | |
8c088c52 | 5763 | TopAbs_ShapeEnum aShapeType = TopAbs_SHAPE; |
5764 | if (argc != 1) | |
5765 | { | |
5766 | TCollection_AsciiString aShapeArg (argv[1]); | |
5767 | aShapeArg.LowerCase(); | |
5768 | aShapeType = TopAbs_COMPOUND; | |
5769 | if (aShapeArg == "v" | |
5770 | || aShapeArg == "vertex") aShapeType = TopAbs_VERTEX; | |
5771 | else if (aShapeArg == "e" | |
5772 | || aShapeArg == "edge") aShapeType = TopAbs_EDGE; | |
5773 | else if (aShapeArg == "w" | |
5774 | || aShapeArg == "wire") aShapeType = TopAbs_WIRE; | |
5775 | else if (aShapeArg == "f" | |
5776 | || aShapeArg == "face") aShapeType = TopAbs_FACE; | |
5777 | else if (aShapeArg == "shape") aShapeType = TopAbs_SHAPE; | |
5778 | else if (aShapeArg == "shell") aShapeType = TopAbs_SHELL; | |
5779 | else if (aShapeArg == "solid") aShapeType = TopAbs_SOLID; | |
5780 | else | |
5781 | { | |
23fe70ec | 5782 | Message::SendFail() << "Syntax error at '" << argv[1] << "'"; |
8c088c52 | 5783 | return 1; |
5784 | } | |
7fd59977 | 5785 | } |
5786 | ||
8c088c52 | 5787 | static Standard_Integer THE_NB_SHAPES_OF_TYPE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
5788 | static const TCollection_AsciiString THE_NAME_TYPE[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"}; | |
7fd59977 | 5789 | |
8c088c52 | 5790 | const Standard_Integer aNbToPick = argc > 2 ? argc - 2 : 1; |
5791 | if (aNbToPick == 1) | |
5792 | { | |
5793 | TopoDS_Shape aPickedShape = ViewerTest::PickShape (aShapeType); | |
5794 | if (aPickedShape.IsNull()) | |
5795 | { | |
7fd59977 | 5796 | return 1; |
7fd59977 | 5797 | } |
7fd59977 | 5798 | |
8c088c52 | 5799 | TCollection_AsciiString aName; |
5800 | if (argc > 2) | |
5801 | { | |
5802 | aName = argv[2]; | |
5803 | } | |
5804 | else | |
5805 | { | |
5806 | const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)]; | |
5807 | aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex; | |
7fd59977 | 5808 | } |
7fd59977 | 5809 | |
8c088c52 | 5810 | DBRep::Set (aName.ToCString(), aPickedShape); |
5811 | Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape); | |
5812 | ViewerTest::Display (aName, aShapePrs, false, true); | |
5813 | di << "Name of picked shape: " << aName <<"\n"; | |
7fd59977 | 5814 | } |
8c088c52 | 5815 | else |
5816 | { | |
5817 | TCollection_AsciiString aName (argv[2]); | |
5818 | aName.LowerCase(); | |
5819 | const Standard_Boolean isAutoNaming = aName == "."; | |
5820 | Handle(TopTools_HArray1OfShape) aPickedArray = new TopTools_HArray1OfShape (1, aNbToPick); | |
5821 | if (ViewerTest::PickShapes (aShapeType, aPickedArray)) | |
5822 | { | |
5823 | for (Standard_Integer aPickedIter = aPickedArray->Lower(); aPickedIter <= aPickedArray->Upper(); ++aPickedIter) | |
5824 | { | |
5825 | TopoDS_Shape aPickedShape = aPickedArray->Value (aPickedIter); | |
5826 | aName.Clear(); | |
5827 | if (!aPickedShape.IsNull() | |
5828 | && isAutoNaming) | |
5829 | { | |
5830 | const int aShapeIndex = ++THE_NB_SHAPES_OF_TYPE[Standard_Integer(aShapeType)]; | |
5831 | aName = TCollection_AsciiString ("Picked_") + THE_NAME_TYPE[Standard_Integer(aShapeType)] + "_" + aShapeIndex; | |
5832 | } | |
5833 | else | |
5834 | { | |
5835 | aName = argv[1 + aPickedIter]; | |
5836 | } | |
7fd59977 | 5837 | |
8c088c52 | 5838 | DBRep::Set (aName.ToCString(), aPickedShape); |
5839 | Handle(AIS_Shape) aShapePrs = new AIS_Shape (aPickedShape); | |
5840 | di << "Display of picked shape #" << aPickedIter << " - name: " << aName <<"\n"; | |
5841 | ViewerTest::Display (aName, aShapePrs, false, true); | |
5842 | } | |
7fd59977 | 5843 | } |
5844 | } | |
8c088c52 | 5845 | TheAISContext()->UpdateCurrentViewer(); |
7fd59977 | 5846 | return 0; |
7fd59977 | 5847 | } |
7fd59977 | 5848 | |
4d901cde | 5849 | //======================================================================= |
d2e60688 | 5850 | //function : VSelFilter |
4d901cde | 5851 | //purpose : |
5852 | //======================================================================= | |
d2e60688 | 5853 | static int VSelFilter(Draw_Interpretor& , Standard_Integer theArgc, |
4d901cde | 5854 | const char** theArgv) |
5855 | { | |
4d901cde | 5856 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); |
5857 | if (aContext.IsNull()) | |
5858 | { | |
23fe70ec | 5859 | Message::SendFail ("Error: AIS context is not available."); |
4d901cde | 5860 | return 1; |
5861 | } | |
5862 | ||
d2e60688 | 5863 | for (Standard_Integer anArgIter = 1; anArgIter < theArgc; ++anArgIter) |
5864 | { | |
5865 | TCollection_AsciiString anArg (theArgv[anArgIter]); | |
5866 | anArg.LowerCase(); | |
5867 | if (anArg == "-clear") | |
5868 | { | |
5869 | aContext->RemoveFilters(); | |
4d901cde | 5870 | } |
897aeb20 | 5871 | else if (anArg == "-contextfilter" && anArgIter + 1 < theArgc) |
5872 | { | |
5873 | TCollection_AsciiString aVal (theArgv[++anArgIter]); | |
5874 | aVal.LowerCase(); | |
5875 | if (aVal == "and") | |
5876 | { | |
5877 | aContext->SetFilterType (SelectMgr_FilterType_AND); | |
5878 | } | |
5879 | else if (aVal == "or") | |
5880 | { | |
5881 | aContext->SetFilterType (SelectMgr_FilterType_OR); | |
5882 | } | |
5883 | else | |
5884 | { | |
5885 | Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'"; | |
5886 | return 1; | |
5887 | } | |
5888 | } | |
d2e60688 | 5889 | else if (anArg == "-type" |
5890 | && anArgIter + 1 < theArgc) | |
5891 | { | |
5892 | TCollection_AsciiString aVal (theArgv[++anArgIter]); | |
5893 | TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND; | |
5894 | if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType)) | |
5895 | { | |
23fe70ec | 5896 | Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'"; |
d2e60688 | 5897 | return 1; |
5898 | } | |
4d901cde | 5899 | |
d2e60688 | 5900 | Handle(SelectMgr_Filter) aFilter; |
5901 | if (aShapeType == TopAbs_SHAPE) | |
5902 | { | |
82b856b8 | 5903 | aFilter = new AIS_TypeFilter (AIS_KindOfInteractive_Shape); |
d2e60688 | 5904 | } |
5905 | else | |
5906 | { | |
5907 | aFilter = new StdSelect_ShapeTypeFilter (aShapeType); | |
5908 | } | |
5909 | aContext->AddFilter (aFilter); | |
4d901cde | 5910 | } |
897aeb20 | 5911 | else if (anArg == "-secondtype" |
5912 | && anArgIter + 1 < theArgc) | |
5913 | { | |
5914 | TCollection_AsciiString aVal (theArgv[++anArgIter]); | |
5915 | TopAbs_ShapeEnum aShapeType = TopAbs_COMPOUND; | |
5916 | if (!TopAbs::ShapeTypeFromString (aVal.ToCString(), aShapeType)) | |
5917 | { | |
5918 | Message::SendFail() << "Syntax error: wrong command attribute value '" << aVal << "'"; | |
5919 | return 1; | |
5920 | } | |
5921 | ||
5922 | Handle(SelectMgr_Filter) aFilter; | |
5923 | if (aShapeType == TopAbs_SHAPE) | |
5924 | { | |
82b856b8 | 5925 | aFilter = new AIS_TypeFilter (AIS_KindOfInteractive_Shape); |
897aeb20 | 5926 | } |
5927 | else | |
5928 | { | |
5929 | aFilter = new StdSelect_ShapeTypeFilter (aShapeType); | |
5930 | } | |
5931 | aContext->AddFilter (aFilter); | |
5932 | } | |
d2e60688 | 5933 | else |
5934 | { | |
23fe70ec | 5935 | Message::SendFail() << "Syntax error: unknown argument '" << theArgv[anArgIter] << "'"; |
d2e60688 | 5936 | return 1; |
4d901cde | 5937 | } |
5938 | } | |
5939 | return 0; | |
5940 | } | |
5941 | ||
d8110103 | 5942 | //======================================================================= |
5943 | //function : VPickSelected | |
5944 | //purpose : | |
5945 | //======================================================================= | |
5946 | static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs) | |
5947 | { | |
5948 | static Standard_Integer aCount = 0; | |
5949 | TCollection_AsciiString aName = "PickedShape_"; | |
5950 | ||
5951 | if (theArgNb > 1) | |
5952 | { | |
5953 | aName = theArgs[1]; | |
5954 | } | |
5955 | else | |
5956 | { | |
5957 | aName = aName + aCount++ + "_"; | |
5958 | } | |
5959 | ||
5960 | Standard_Integer anIdx = 0; | |
5961 | for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx) | |
5962 | { | |
5963 | TopoDS_Shape aShape; | |
5964 | if (TheAISContext()->HasSelectedShape()) | |
5965 | { | |
5966 | aShape = TheAISContext()->SelectedShape(); | |
5967 | } | |
5968 | else | |
5969 | { | |
5970 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); | |
c5f3a425 | 5971 | aShape = Handle(AIS_Shape)::DownCast (IO)->Shape(); |
d8110103 | 5972 | } |
5973 | ||
5974 | TCollection_AsciiString aCurrentName = aName; | |
5975 | if (anIdx > 0) | |
5976 | { | |
5977 | aCurrentName += anIdx; | |
5978 | } | |
5979 | ||
5980 | DBRep::Set ((aCurrentName).ToCString(), aShape); | |
5981 | ||
5982 | Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape); | |
5983 | GetMapOfAIS().Bind (aNewShape, aCurrentName); | |
0577ae8c | 5984 | TheAISContext()->Display (aNewShape, Standard_False); |
d8110103 | 5985 | } |
5986 | ||
0577ae8c | 5987 | TheAISContext()->UpdateCurrentViewer(); |
5988 | ||
d8110103 | 5989 | return 0; |
5990 | } | |
5991 | ||
7fd59977 | 5992 | //======================================================================= |
5993 | //function : list of known objects | |
5994 | //purpose : | |
5995 | //======================================================================= | |
5996 | static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** ) | |
5997 | { | |
5998 | // 1234567890 12345678901234567 123456789 | |
5999 | TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"}; | |
6000 | TCollection_AsciiString BlankLine(64,'_'); | |
6001 | Standard_Integer i ; | |
6002 | ||
6003 | di<<"/n"<<BlankLine.ToCString()<<"\n"; | |
6004 | ||
6005 | for( i =0;i<=2;i++) | |
6006 | Colum[i].Center(20,' '); | |
6007 | for(i=0;i<=2;i++) | |
6008 | di<<"|"<<Colum[i].ToCString(); | |
586db386 | 6009 | di<<"|\n"; |
7fd59977 | 6010 | |
6011 | di<<BlankLine.ToCString()<<"\n"; | |
6012 | ||
6013 | // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"}; | |
6014 | const char ** names = GetTypeNames(); | |
6015 | ||
6016 | TCollection_AsciiString curstring; | |
6017 | TCollection_AsciiString curcolum[3]; | |
6018 | ||
6019 | ||
6020 | // les objets de type Datum.. | |
6021 | curcolum[1]+="Datum"; | |
6022 | for(i =0;i<=6;i++){ | |
6023 | curcolum[0].Clear(); | |
6024 | curcolum[0] += names[i]; | |
6025 | ||
6026 | curcolum[2].Clear(); | |
6027 | curcolum[2]+=TCollection_AsciiString(i+1); | |
6028 | ||
6029 | for(Standard_Integer j =0;j<=2;j++){ | |
6030 | curcolum[j].Center(20,' '); | |
6031 | di<<"|"<<curcolum[j].ToCString(); | |
6032 | } | |
586db386 | 6033 | di<<"|\n"; |
7fd59977 | 6034 | } |
6035 | di<<BlankLine.ToCString()<<"\n"; | |
6036 | ||
6037 | // les objets de type shape | |
6038 | curcolum[1].Clear(); | |
6039 | curcolum[1]+="Shape"; | |
6040 | curcolum[1].Center(20,' '); | |
6041 | ||
6042 | for(i=0;i<=2;i++){ | |
6043 | curcolum[0].Clear(); | |
6044 | curcolum[0] += names[7+i]; | |
6045 | curcolum[2].Clear(); | |
6046 | curcolum[2]+=TCollection_AsciiString(i); | |
6047 | ||
6048 | for(Standard_Integer j =0;j<=2;j++){ | |
6049 | curcolum[j].Center(20,' '); | |
6050 | di<<"|"<<curcolum[j].ToCString(); | |
6051 | } | |
586db386 | 6052 | di<<"|\n"; |
7fd59977 | 6053 | } |
6054 | di<<BlankLine.ToCString()<<"\n"; | |
6055 | // les IO de type objet... | |
6056 | curcolum[1].Clear(); | |
6057 | curcolum[1]+="Object"; | |
6058 | curcolum[1].Center(20,' '); | |
6059 | for(i=0;i<=1;i++){ | |
6060 | curcolum[0].Clear(); | |
6061 | curcolum[0] += names[10+i]; | |
6062 | curcolum[2].Clear(); | |
6063 | curcolum[2]+=TCollection_AsciiString(i); | |
6064 | ||
6065 | for(Standard_Integer j =0;j<=2;j++){ | |
6066 | curcolum[j].Center(20,' '); | |
6067 | di<<"|"<<curcolum[j].ToCString(); | |
6068 | } | |
586db386 | 6069 | di<<"|\n"; |
7fd59977 | 6070 | } |
6071 | di<<BlankLine.ToCString()<<"\n"; | |
6072 | // les contraintes et dimensions. | |
6073 | // pour l'instant on separe juste contraintes et dimensions... | |
6074 | // plus tard, on detaillera toutes les sortes... | |
6075 | curcolum[1].Clear(); | |
6076 | curcolum[1]+="Relation"; | |
6077 | curcolum[1].Center(20,' '); | |
6078 | for(i=0;i<=1;i++){ | |
6079 | curcolum[0].Clear(); | |
6080 | curcolum[0] += names[12+i]; | |
6081 | curcolum[2].Clear(); | |
6082 | curcolum[2]+=TCollection_AsciiString(i); | |
6083 | ||
6084 | for(Standard_Integer j =0;j<=2;j++){ | |
6085 | curcolum[j].Center(20,' '); | |
6086 | di<<"|"<<curcolum[j].ToCString(); | |
6087 | } | |
586db386 | 6088 | di<<"|\n"; |
7fd59977 | 6089 | } |
6090 | di<<BlankLine.ToCString()<<"\n"; | |
6091 | ||
6092 | ||
6093 | return 0; | |
6094 | } | |
6095 | ||
6096 | ||
6097 | static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
6098 | { | |
4952a30a | 6099 | if(argc!=2) return 1; |
7fd59977 | 6100 | |
6101 | AIS_KindOfInteractive TheType; | |
6102 | Standard_Integer TheSign(-1); | |
6103 | GetTypeAndSignfromString(argv[1],TheType,TheSign); | |
6104 | ||
6105 | ||
6106 | AIS_ListOfInteractive LIO; | |
6107 | ||
6108 | // en attendant l'amelioration ais pour les dimensions... | |
6109 | // | |
6110 | Standard_Integer dimension_status(-1); | |
82b856b8 | 6111 | if (TheType==AIS_KindOfInteractive_Relation) |
6112 | { | |
6113 | dimension_status = TheSign == 1 ? 1 : 0; | |
6114 | TheSign = -1; | |
7fd59977 | 6115 | } |
6116 | ||
6117 | TheAISContext()->DisplayedObjects(TheType,TheSign,LIO); | |
6118 | Handle(AIS_InteractiveObject) curio; | |
6119 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ | |
6120 | curio = it.Value(); | |
6121 | ||
6122 | if(dimension_status == -1) | |
6123 | TheAISContext()->Erase(curio,Standard_False); | |
6124 | else { | |
787ff240 | 6125 | PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension(); |
6126 | if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)|| | |
6127 | (dimension_status==1 && KOD != PrsDim_KOD_NONE)) | |
7fd59977 | 6128 | TheAISContext()->Erase(curio,Standard_False); |
6129 | } | |
6130 | } | |
6131 | TheAISContext()->UpdateCurrentViewer(); | |
6132 | return 0; | |
6133 | } | |
6134 | static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
6135 | { | |
6136 | if(argc!=2) return 1; | |
6137 | ||
6138 | AIS_KindOfInteractive TheType; | |
6139 | Standard_Integer TheSign(-1); | |
6140 | GetTypeAndSignfromString(argv[1],TheType,TheSign); | |
6141 | ||
6142 | // en attendant l'amelioration ais pour les dimensions... | |
6143 | // | |
6144 | Standard_Integer dimension_status(-1); | |
82b856b8 | 6145 | if (TheType==AIS_KindOfInteractive_Relation) |
6146 | { | |
6147 | dimension_status = TheSign == 1 ? 1 : 0; | |
6148 | TheSign = -1; | |
7fd59977 | 6149 | } |
6150 | ||
6151 | AIS_ListOfInteractive LIO; | |
6152 | TheAISContext()->ObjectsInside(LIO,TheType,TheSign); | |
6153 | Handle(AIS_InteractiveObject) curio; | |
6154 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ | |
6155 | curio = it.Value(); | |
6156 | if(dimension_status == -1) | |
6157 | TheAISContext()->Display(curio,Standard_False); | |
6158 | else { | |
787ff240 | 6159 | PrsDim_KindOfDimension KOD = Handle(PrsDim_Relation)::DownCast (curio)->KindOfDimension(); |
6160 | if ((dimension_status==0 && KOD == PrsDim_KOD_NONE)|| | |
6161 | (dimension_status==1 && KOD != PrsDim_KOD_NONE)) | |
7fd59977 | 6162 | TheAISContext()->Display(curio,Standard_False); |
6163 | } | |
6164 | ||
6165 | } | |
6166 | ||
6167 | TheAISContext()->UpdateCurrentViewer(); | |
6168 | return 0; | |
6169 | } | |
6170 | ||
7fd59977 | 6171 | static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a) |
6172 | { | |
04232180 | 6173 | std::ifstream s(a[1]); |
7fd59977 | 6174 | BRep_Builder builder; |
6175 | TopoDS_Shape shape; | |
6176 | BRepTools::Read(shape, s, builder); | |
6177 | DBRep::Set(a[1], shape); | |
6178 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
6179 | Handle(AIS_Shape) ais = new AIS_Shape(shape); | |
0577ae8c | 6180 | Ctx->Display (ais, Standard_True); |
7fd59977 | 6181 | return 0; |
6182 | } | |
7fd59977 | 6183 | |
189f85a3 | 6184 | //=============================================================================================== |
6185 | //function : VBsdf | |
6186 | //purpose : | |
6187 | //=============================================================================================== | |
05aa616d | 6188 | static int VBsdf (Draw_Interpretor& theDI, |
189f85a3 | 6189 | Standard_Integer theArgsNb, |
6190 | const char** theArgVec) | |
6191 | { | |
6192 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
6193 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
6194 | if (aView.IsNull() | |
6195 | || aViewer.IsNull()) | |
6196 | { | |
23fe70ec | 6197 | Message::SendFail ("Error: No active viewer!"); |
189f85a3 | 6198 | return 1; |
6199 | } | |
6200 | ||
6201 | ViewerTest_CmdParser aCmd; | |
6202 | ||
293211ae | 6203 | aCmd.SetDescription ("Adjusts parameters of material BSDF:"); |
189f85a3 | 6204 | |
05aa616d | 6205 | aCmd.AddOption ("print|echo|p", "Prints BSDF"); |
189f85a3 | 6206 | |
05aa616d | 6207 | aCmd.AddOption ("noupdate|update", "Suppresses viewer redraw call"); |
189f85a3 | 6208 | |
05aa616d | 6209 | aCmd.AddOption ("kc", "Weight of coat specular/glossy BRDF"); |
6210 | aCmd.AddOption ("kd", "Weight of base diffuse BRDF"); | |
6211 | aCmd.AddOption ("ks", "Weight of base specular/glossy BRDF"); | |
6212 | aCmd.AddOption ("kt", "Weight of base specular/glossy BTDF"); | |
6213 | aCmd.AddOption ("le", "Radiance emitted by surface"); | |
189f85a3 | 6214 | |
05aa616d | 6215 | aCmd.AddOption ("coatFresnel|cf", "Fresnel reflectance of coat layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K"); |
6216 | aCmd.AddOption ("baseFresnel|bf", "Fresnel reflectance of base layer. Allowed formats: Constant R, Schlick R G B, Dielectric N, Conductor N K"); | |
6217 | ||
6218 | aCmd.AddOption ("coatRoughness|cr", "Roughness of coat glossy BRDF"); | |
6219 | aCmd.AddOption ("baseRoughness|br", "Roughness of base glossy BRDF"); | |
6220 | ||
6221 | aCmd.AddOption ("absorpCoeff|af", "Absorption coeff of base transmission BTDF"); | |
6222 | aCmd.AddOption ("absorpColor|ac", "Absorption color of base transmission BTDF"); | |
6223 | ||
6224 | aCmd.AddOption ("normalize|n", "Normalizes BSDF to ensure energy conservation"); | |
189f85a3 | 6225 | |
6226 | aCmd.Parse (theArgsNb, theArgVec); | |
6227 | ||
6228 | if (aCmd.HasOption ("help")) | |
6229 | { | |
05aa616d | 6230 | theDI.PrintHelp (theArgVec[0]); |
189f85a3 | 6231 | return 0; |
6232 | } | |
6233 | ||
05aa616d | 6234 | // check viewer update mode |
6235 | ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), ViewerTest::CurrentView()); | |
05aa616d | 6236 | for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) |
6237 | { | |
6238 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
6239 | { | |
6240 | break; | |
6241 | } | |
6242 | } | |
6243 | ||
189f85a3 | 6244 | // find object |
293211ae | 6245 | TCollection_AsciiString aName (aCmd.Arg (ViewerTest_CmdParser::THE_UNNAMED_COMMAND_OPTION_KEY, 0).c_str()); |
8f521168 | 6246 | Handle(AIS_InteractiveObject) anIObj; |
6247 | if (!GetMapOfAIS().Find2 (aName, anIObj)) | |
189f85a3 | 6248 | { |
23fe70ec | 6249 | Message::SendFail ("Error: no active viewer"); |
189f85a3 | 6250 | return 1; |
6251 | } | |
6252 | ||
189f85a3 | 6253 | Graphic3d_MaterialAspect aMaterial = anIObj->Attributes()->ShadingAspect()->Material(); |
6254 | Graphic3d_BSDF aBSDF = aMaterial.BSDF(); | |
6255 | ||
6256 | if (aCmd.HasOption ("print")) | |
6257 | { | |
05aa616d | 6258 | theDI << "\n" |
6259 | << "Kc: " << aBSDF.Kc.r() << ", " << aBSDF.Kc.g() << ", " << aBSDF.Kc.b() << "\n" | |
189f85a3 | 6260 | << "Kd: " << aBSDF.Kd.r() << ", " << aBSDF.Kd.g() << ", " << aBSDF.Kd.b() << "\n" |
189f85a3 | 6261 | << "Ks: " << aBSDF.Ks.r() << ", " << aBSDF.Ks.g() << ", " << aBSDF.Ks.b() << "\n" |
05aa616d | 6262 | << "Kt: " << aBSDF.Kt.r() << ", " << aBSDF.Kt.g() << ", " << aBSDF.Kt.b() << "\n" |
6263 | << "Le: " << aBSDF.Le.r() << ", " << aBSDF.Le.g() << ", " << aBSDF.Le.b() << "\n"; | |
189f85a3 | 6264 | |
05aa616d | 6265 | for (int aLayerID = 0; aLayerID < 2; ++aLayerID) |
189f85a3 | 6266 | { |
05aa616d | 6267 | const Graphic3d_Vec4 aFresnel = aLayerID < 1 ? aBSDF.FresnelCoat.Serialize() |
6268 | : aBSDF.FresnelBase.Serialize(); | |
189f85a3 | 6269 | |
05aa616d | 6270 | theDI << (aLayerID < 1 ? "Coat Fresnel: " |
6271 | : "Base Fresnel: "); | |
6272 | ||
6273 | if (aFresnel.x() >= 0.f) | |
6274 | { | |
6275 | theDI << "Schlick " << "R = " << aFresnel.r() << ", " | |
6276 | << "G = " << aFresnel.g() << ", " | |
6277 | << "B = " << aFresnel.b() << "\n"; | |
6278 | } | |
6279 | else if (aFresnel.x() >= -1.5f) | |
6280 | { | |
6281 | theDI << "Constant " << aFresnel.z() << "\n"; | |
6282 | } | |
6283 | else if (aFresnel.x() >= -2.5f) | |
6284 | { | |
6285 | theDI << "Conductor " << "N = " << aFresnel.y() << ", " | |
6286 | << "K = " << aFresnel.z() << "\n"; | |
6287 | } | |
6288 | else | |
6289 | { | |
6290 | theDI << "Dielectric " << "N = " << aFresnel.y() << "\n"; | |
6291 | } | |
6292 | } | |
189f85a3 | 6293 | |
05aa616d | 6294 | theDI << "Coat roughness: " << aBSDF.Kc.w() << "\n" |
6295 | << "Base roughness: " << aBSDF.Ks.w() << "\n" | |
6296 | << "Absorption coeff: " << aBSDF.Absorption.w() << "\n" | |
6297 | << "Absorption color: " << aBSDF.Absorption.r() << ", " | |
6298 | << aBSDF.Absorption.g() << ", " | |
6299 | << aBSDF.Absorption.b() << "\n"; | |
189f85a3 | 6300 | |
6301 | return 0; | |
6302 | } | |
6303 | ||
05aa616d | 6304 | if (aCmd.HasOption ("coatRoughness", 1, Standard_True)) |
6305 | { | |
6306 | aBSDF.Kc.w() = aCmd.ArgFloat ("coatRoughness"); | |
6307 | } | |
6308 | ||
6309 | if (aCmd.HasOption ("baseRoughness", 1, Standard_True)) | |
189f85a3 | 6310 | { |
05aa616d | 6311 | aBSDF.Ks.w () = aCmd.ArgFloat ("baseRoughness"); |
189f85a3 | 6312 | } |
6313 | ||
6314 | if (aCmd.HasOption ("absorpCoeff", 1, Standard_True)) | |
6315 | { | |
05aa616d | 6316 | aBSDF.Absorption.w() = aCmd.ArgFloat ("absorpCoeff"); |
189f85a3 | 6317 | } |
6318 | ||
6319 | if (aCmd.HasOption ("absorpColor", 3, Standard_True)) | |
6320 | { | |
05aa616d | 6321 | const Graphic3d_Vec3 aRGB = aCmd.ArgVec3f ("absorpColor"); |
6322 | ||
6323 | aBSDF.Absorption.r() = aRGB.r(); | |
6324 | aBSDF.Absorption.g() = aRGB.g(); | |
6325 | aBSDF.Absorption.b() = aRGB.b(); | |
6326 | } | |
6327 | ||
6328 | if (aCmd.HasOption ("kc", 3) || aCmd.HasOption ("kc", 1, Standard_True)) | |
6329 | { | |
6330 | Graphic3d_Vec3 aKc; | |
6331 | ||
6332 | if (aCmd.HasOption ("kc", 3)) | |
6333 | { | |
6334 | aKc = aCmd.ArgVec3f ("kc"); | |
6335 | } | |
6336 | else | |
6337 | { | |
6338 | aKc = Graphic3d_Vec3 (aCmd.ArgFloat ("kc")); | |
6339 | } | |
6340 | ||
6341 | aBSDF.Kc.r() = aKc.r(); | |
6342 | aBSDF.Kc.g() = aKc.g(); | |
6343 | aBSDF.Kc.b() = aKc.b(); | |
189f85a3 | 6344 | } |
6345 | ||
6346 | if (aCmd.HasOption ("kd", 3)) | |
6347 | { | |
6348 | aBSDF.Kd = aCmd.ArgVec3f ("kd"); | |
6349 | } | |
6350 | else if (aCmd.HasOption ("kd", 1, Standard_True)) | |
6351 | { | |
6352 | aBSDF.Kd = Graphic3d_Vec3 (aCmd.ArgFloat ("kd")); | |
6353 | } | |
6354 | ||
05aa616d | 6355 | if (aCmd.HasOption ("ks", 3) || aCmd.HasOption ("ks", 1, Standard_True)) |
189f85a3 | 6356 | { |
05aa616d | 6357 | Graphic3d_Vec3 aKs; |
6358 | ||
6359 | if (aCmd.HasOption ("ks", 3)) | |
6360 | { | |
6361 | aKs = aCmd.ArgVec3f ("ks"); | |
6362 | } | |
6363 | else | |
6364 | { | |
6365 | aKs = Graphic3d_Vec3 (aCmd.ArgFloat ("ks")); | |
6366 | } | |
6367 | ||
6368 | aBSDF.Ks.r() = aKs.r(); | |
6369 | aBSDF.Ks.g() = aKs.g(); | |
6370 | aBSDF.Ks.b() = aKs.b(); | |
189f85a3 | 6371 | } |
6372 | ||
6373 | if (aCmd.HasOption ("kt", 3)) | |
6374 | { | |
6375 | aBSDF.Kt = aCmd.ArgVec3f ("kt"); | |
6376 | } | |
6377 | else if (aCmd.HasOption ("kt", 1, Standard_True)) | |
6378 | { | |
6379 | aBSDF.Kt = Graphic3d_Vec3 (aCmd.ArgFloat ("kt")); | |
6380 | } | |
6381 | ||
189f85a3 | 6382 | if (aCmd.HasOption ("le", 3)) |
6383 | { | |
6384 | aBSDF.Le = aCmd.ArgVec3f ("le"); | |
6385 | } | |
6386 | else if (aCmd.HasOption ("le", 1, Standard_True)) | |
6387 | { | |
6388 | aBSDF.Le = Graphic3d_Vec3 (aCmd.ArgFloat ("le")); | |
6389 | } | |
6390 | ||
6391 | const std::string aFresnelErrorMessage = | |
05aa616d | 6392 | "Error! Wrong Fresnel type. Allowed types are: Constant F, Schlick R G B, Dielectric N, Conductor N K\n"; |
189f85a3 | 6393 | |
05aa616d | 6394 | for (int aLayerID = 0; aLayerID < 2; ++aLayerID) |
189f85a3 | 6395 | { |
05aa616d | 6396 | const std::string aFresnel = aLayerID < 1 ? "baseFresnel" |
6397 | : "coatFresnel"; | |
189f85a3 | 6398 | |
05aa616d | 6399 | if (aCmd.HasOption (aFresnel, 4)) // Schlick: type R G B |
189f85a3 | 6400 | { |
05aa616d | 6401 | std::string aFresnelType = aCmd.Arg (aFresnel, 0); |
d6cda17a | 6402 | std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase); |
189f85a3 | 6403 | |
05aa616d | 6404 | if (aFresnelType == "schlick") |
6405 | { | |
6406 | Graphic3d_Vec3 aRGB (static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())), | |
6407 | static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())), | |
6408 | static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 3).c_str()))); | |
189f85a3 | 6409 | |
05aa616d | 6410 | aRGB.r() = std::min (std::max (aRGB.r(), 0.f), 1.f); |
6411 | aRGB.g() = std::min (std::max (aRGB.g(), 0.f), 1.f); | |
6412 | aRGB.b() = std::min (std::max (aRGB.b(), 0.f), 1.f); | |
6413 | ||
6414 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateSchlick (aRGB); | |
6415 | } | |
6416 | else | |
6417 | { | |
6418 | theDI << aFresnelErrorMessage.c_str() << "\n"; | |
6419 | } | |
189f85a3 | 6420 | } |
05aa616d | 6421 | else if (aCmd.HasOption (aFresnel, 3)) // Conductor: type N K |
189f85a3 | 6422 | { |
05aa616d | 6423 | std::string aFresnelType = aCmd.Arg (aFresnel, 0); |
d6cda17a | 6424 | std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase); |
05aa616d | 6425 | |
6426 | if (aFresnelType == "conductor") | |
6427 | { | |
6428 | const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())); | |
6429 | const float aK = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 2).c_str())); | |
6430 | ||
6431 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConductor (aN, aK); | |
6432 | } | |
6433 | else | |
6434 | { | |
6435 | theDI << aFresnelErrorMessage.c_str() << "\n"; | |
6436 | } | |
189f85a3 | 6437 | } |
05aa616d | 6438 | else if (aCmd.HasOption (aFresnel, 2)) // Dielectric or Constant: type N|C |
189f85a3 | 6439 | { |
05aa616d | 6440 | std::string aFresnelType = aCmd.Arg (aFresnel, 0); |
d6cda17a | 6441 | std::transform (aFresnelType.begin (), aFresnelType.end (), aFresnelType.begin (), ::LowerCase); |
05aa616d | 6442 | |
6443 | if (aFresnelType == "constant") | |
6444 | { | |
6445 | const float aR = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())); | |
6446 | ||
6447 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateConstant (aR); | |
6448 | } | |
6449 | else if (aFresnelType == "dielectric") | |
6450 | { | |
6451 | const float aN = static_cast<float> (Draw::Atof (aCmd.Arg (aFresnel, 1).c_str())); | |
6452 | ||
6453 | (aLayerID < 1 ? aBSDF.FresnelBase : aBSDF.FresnelCoat) = Graphic3d_Fresnel::CreateDielectric (aN); | |
6454 | } | |
6455 | else | |
6456 | { | |
6457 | theDI << aFresnelErrorMessage.c_str() << "\n"; | |
6458 | } | |
189f85a3 | 6459 | } |
6460 | } | |
6461 | ||
6462 | if (aCmd.HasOption ("normalize")) | |
6463 | { | |
6464 | aBSDF.Normalize(); | |
6465 | } | |
6466 | ||
6467 | aMaterial.SetBSDF (aBSDF); | |
6468 | anIObj->SetMaterial (aMaterial); | |
6469 | ||
189f85a3 | 6470 | return 0; |
6471 | } | |
6472 | ||
f751596e | 6473 | //============================================================================== |
6474 | //function : VLoadSelection | |
6475 | //purpose : Adds given objects to map of AIS and loads selection primitives for them | |
6476 | //============================================================================== | |
6477 | static Standard_Integer VLoadSelection (Draw_Interpretor& /*theDi*/, | |
6478 | Standard_Integer theArgNb, | |
6479 | const char** theArgVec) | |
6480 | { | |
6481 | if (theArgNb < 2) | |
6482 | { | |
23fe70ec | 6483 | Message::SendFail ("Syntax error: wrong number of arguments."); |
f751596e | 6484 | return 1; |
6485 | } | |
6486 | ||
6487 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
6488 | if (aCtx.IsNull()) | |
6489 | { | |
6490 | ViewerTest::ViewerInit(); | |
6491 | aCtx = ViewerTest::GetAISContext(); | |
6492 | } | |
6493 | ||
6494 | // Parse input arguments | |
f751596e | 6495 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
6496 | { | |
68dcee02 | 6497 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
5b111128 | 6498 | Handle(AIS_InteractiveObject) aShape; |
8f521168 | 6499 | if (!GetMapOfAIS().Find2 (aName, aShape)) |
6500 | { | |
1c8fc6be | 6501 | TopoDS_Shape aDrawShape = DBRep::GetExisting (aName); |
6502 | if (!aDrawShape.IsNull()) | |
f751596e | 6503 | { |
1c8fc6be | 6504 | aShape = new AIS_Shape (aDrawShape); |
f751596e | 6505 | GetMapOfAIS().Bind (aShape, aName); |
6506 | } | |
f751596e | 6507 | } |
1c8fc6be | 6508 | if (aShape.IsNull()) |
6509 | { | |
23fe70ec | 6510 | Message::SendFail() << "Syntax error: presentation '" << aName << "' not found"; |
1c8fc6be | 6511 | return 1; |
6512 | } | |
f751596e | 6513 | |
1c8fc6be | 6514 | aCtx->Load (aShape, -1); |
6515 | aCtx->Activate (aShape, aShape->GlobalSelectionMode(), Standard_True); | |
6516 | } | |
f751596e | 6517 | return 0; |
6518 | } | |
6519 | ||
7fd59977 | 6520 | //============================================================================== |
6521 | //function : ViewerTest::Commands | |
6522 | //purpose : Add all the viewer command in the Draw_Interpretor | |
6523 | //============================================================================== | |
6524 | ||
6525 | void ViewerTest::Commands(Draw_Interpretor& theCommands) | |
6526 | { | |
6527 | ViewerTest::ViewerCommands(theCommands); | |
6528 | ViewerTest::RelationCommands(theCommands); | |
6529 | ViewerTest::ObjectCommands(theCommands); | |
6530 | ViewerTest::FilletCommands(theCommands); | |
3946774d | 6531 | ViewerTest::OpenGlCommands(theCommands); |
7fd59977 | 6532 | |
6533 | const char *group = "AIS_Display"; | |
6534 | ||
6535 | // display | |
1c88cbaf | 6536 | theCommands.Add("visos", |
b6d587e3 | 6537 | "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n" |
6538 | "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n", | |
6539 | __FILE__, visos, group); | |
7fd59977 | 6540 | |
6541 | theCommands.Add("vdisplay", | |
faea8b40 | 6542 | "vdisplay [-noupdate|-update] [-local] [-mutable] [-neutral]" |
778cd667 | 6543 | "\n\t\t: [-trsfPers {zoom|rotate|zoomRotate|none}=none]" |
6544 | "\n\t\t: [-trsfPersPos X Y [Z]] [-3d]" | |
6545 | "\n\t\t: [-2d|-trihedron [{top|bottom|left|right|topLeft" | |
6546 | "\n\t\t: |topRight|bottomLeft|bottomRight}" | |
6547 | "\n\t\t: [offsetX offsetY]]]" | |
af65fb19 | 6548 | "\n\t\t: [-dispMode mode] [-highMode mode]" |
faea8b40 | 6549 | "\n\t\t: [-layer index] [-top|-topmost|-overlay|-underlay]" |
6194ee76 | 6550 | "\n\t\t: [-redisplay] [-erased]" |
e816dce3 | 6551 | "\n\t\t: [-noecho]" |
af65fb19 | 6552 | "\n\t\t: name1 [name2] ... [name n]" |
519d35d8 | 6553 | "\n\t\t: Displays named objects." |
b6d587e3 | 6554 | "\n\t\t: Option -local enables displaying of objects in local" |
6555 | "\n\t\t: selection context. Local selection context will be opened" | |
6556 | "\n\t\t: if there is not any." | |
778cd667 | 6557 | "\n\t\t: -noupdate Suppresses viewer redraw call." |
6558 | "\n\t\t: -mutable Enables optimizations for mutable objects." | |
6559 | "\n\t\t: -neutral Draws objects in main viewer." | |
6194ee76 | 6560 | "\n\t\t: -erased Loads the object into context, but does not display it." |
778cd667 | 6561 | "\n\t\t: -layer Sets z-layer for objects." |
6562 | "\n\t\t: Alternatively -overlay|-underlay|-top|-topmost" | |
6563 | "\n\t\t: options can be used for the default z-layers." | |
6564 | "\n\t\t: -top Draws object on top of main presentations" | |
6565 | "\n\t\t: but below topmost." | |
6566 | "\n\t\t: -topmost Draws in overlay for 3D presentations." | |
6567 | "\n\t\t: with independent Depth." | |
6568 | "\n\t\t: -overlay Draws objects in overlay for 2D presentations." | |
6569 | "\n\t\t: (On-Screen-Display)" | |
6570 | "\n\t\t: -underlay Draws objects in underlay for 2D presentations." | |
6571 | "\n\t\t: (On-Screen-Display)" | |
6572 | "\n\t\t: -selectable|-noselect Controls selection of objects." | |
6573 | "\n\t\t: -trsfPers Sets a transform persistence flags." | |
6574 | "\n\t\t: -trsfPersPos Sets an anchor point for transform persistence." | |
6575 | "\n\t\t: -2d Displays object in screen coordinates." | |
6576 | "\n\t\t: (DY looks up)" | |
6577 | "\n\t\t: -dispmode Sets display mode for objects." | |
6578 | "\n\t\t: -highmode Sets hilight mode for objects." | |
e816dce3 | 6579 | "\n\t\t: -redisplay Recomputes presentation of objects." |
6580 | "\n\t\t: -noecho Avoid printing of command results.", | |
b6d587e3 | 6581 | __FILE__, VDisplay2, group); |
7fd59977 | 6582 | |
bc001a40 | 6583 | theCommands.Add ("vnbdisplayed", |
6584 | "vnbdisplayed" | |
6585 | "\n\t\t: Returns number of displayed objects", | |
6586 | __FILE__, VNbDisplayed, group); | |
6587 | ||
f3889691 | 6588 | theCommands.Add ("vupdate", |
6589 | "vupdate name1 [name2] ... [name n]" | |
6590 | "\n\t\t: Updates named objects in interactive context", | |
6591 | __FILE__, VUpdate, group); | |
6592 | ||
7fd59977 | 6593 | theCommands.Add("verase", |
ab1f4580 | 6594 | "verase [-noupdate|-update] [-local] [name1] ... [name n] [-noerror]" |
ac4aaa98 | 6595 | "\n\t\t: Erases selected or named objects." |
b6d587e3 | 6596 | "\n\t\t: If there are no selected or named objects the whole viewer is erased." |
6597 | "\n\t\t: Option -local enables erasing of selected or named objects without" | |
ab1f4580 | 6598 | "\n\t\t: closing local selection context." |
6599 | "\n\t\t: Option -noerror prevents exception on non-existing objects.", | |
b6d587e3 | 6600 | __FILE__, VErase, group); |
7fd59977 | 6601 | |
eef7fc64 | 6602 | theCommands.Add("vremove", |
ab1f4580 | 6603 | "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n] [-noerror]" |
b6d587e3 | 6604 | "or vremove [-context] -all to remove all objects" |
eef7fc64 | 6605 | "\n\t\t: Removes selected or named objects." |
6606 | "\n\t\t If -context is in arguments, the objects are not deleted" | |
519d35d8 | 6607 | "\n\t\t from the map of objects and names." |
b6d587e3 | 6608 | "\n\t\t: Option -local enables removing of selected or named objects without" |
6609 | "\n\t\t: closing local selection context. Empty local selection context will be" | |
6610 | "\n\t\t: closed." | |
b7cd4ba7 | 6611 | "\n\t\t: Option -noupdate suppresses viewer redraw call." |
ab1f4580 | 6612 | "\n\t\t: Option -noinfo suppresses displaying the list of removed objects." |
6613 | "\n\t\t: Option -noerror prevents exception on non-existing objects.", | |
eef7fc64 | 6614 | __FILE__, VRemove, group); |
6615 | ||
7fd59977 | 6616 | theCommands.Add("vdonly", |
519d35d8 | 6617 | "vdonly [-noupdate|-update] [name1] ... [name n]" |
ac4aaa98 | 6618 | "\n\t\t: Displays only selected or named objects", |
7fd59977 | 6619 | __FILE__,VDonly2,group); |
6620 | ||
6621 | theCommands.Add("vdisplayall", | |
68dcee02 | 6622 | "vdisplayall" |
6623 | "\n\t\t: Displays all erased interactive objects (see vdir and vstate).", | |
b6d587e3 | 6624 | __FILE__, VDisplayAll, group); |
7fd59977 | 6625 | |
6626 | theCommands.Add("veraseall", | |
68dcee02 | 6627 | "veraseall" |
6628 | "\n\t\t: Erases all objects displayed in the viewer.", | |
b6d587e3 | 6629 | __FILE__, VErase, group); |
7fd59977 | 6630 | |
6631 | theCommands.Add("verasetype", | |
b6d587e3 | 6632 | "verasetype <Type>" |
ac4aaa98 | 6633 | "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)", |
b6d587e3 | 6634 | __FILE__, VEraseType, group); |
c2a388f8 | 6635 | theCommands.Add("vbounding", |
6636 | "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]" | |
6637 | "\n\t\t: [-print] [-hide]" | |
6638 | "\n\t\t: Temporarily display bounding box of specified Interactive" | |
6639 | "\n\t\t: Objects, or print it to console if -print is specified." | |
6640 | "\n\t\t: Already displayed box might be hidden by -hide option.", | |
6641 | __FILE__,VBounding,group); | |
6642 | ||
7fd59977 | 6643 | theCommands.Add("vdisplaytype", |
6644 | "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ", | |
6645 | __FILE__,VDisplayType,group); | |
6646 | ||
7fd59977 | 6647 | theCommands.Add("vsetdispmode", |
ac4aaa98 | 6648 | "vsetdispmode [name] mode(1,2,..)" |
6649 | "\n\t\t: Sets display mode for all, selected or named objects.", | |
7fd59977 | 6650 | __FILE__,VDispMode,group); |
6651 | ||
6652 | theCommands.Add("vunsetdispmode", | |
ac4aaa98 | 6653 | "vunsetdispmode [name]" |
6654 | "\n\t\t: Unsets custom display mode for selected or named objects.", | |
7fd59977 | 6655 | __FILE__,VDispMode,group); |
6656 | ||
6657 | theCommands.Add("vdir", | |
ab1f4580 | 6658 | "vdir [mask] [-list]" |
6659 | "\n\t\t: Lists all objects displayed in 3D viewer" | |
6660 | "\n\t\t: mask - name filter like prefix*" | |
6661 | "\n\t\t: -list - format list with new-line per name; OFF by default", | |
519d35d8 | 6662 | __FILE__,VDir,group); |
7fd59977 | 6663 | |
f978241f | 6664 | #ifdef HAVE_FREEIMAGE |
6665 | #define DUMP_FORMATS "{png|bmp|jpg|gif}" | |
6666 | #else | |
6667 | #define DUMP_FORMATS "{ppm}" | |
6668 | #endif | |
7fd59977 | 6669 | theCommands.Add("vdump", |
f978241f | 6670 | "vdump <filename>." DUMP_FORMATS " [-width Width -height Height]" |
6671 | "\n\t\t: [-buffer rgb|rgba|depth=rgb]" | |
6672 | "\n\t\t: [-stereo mono|left|right|blend|sideBySide|overUnder=mono]" | |
b40cdc2b | 6673 | "\n\t\t: [-xrPose base|head|handLeft|handRight=base]" |
3bffef55 | 6674 | "\n\t\t: [-tileSize Size=0]" |
f978241f | 6675 | "\n\t\t: Dumps content of the active view into image file", |
7fd59977 | 6676 | __FILE__,VDump,group); |
6677 | ||
6678 | theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects", | |
6679 | __FILE__,VSubInt,group); | |
6680 | ||
ad3217cd | 6681 | theCommands.Add("vaspects", |
e0b24437 | 6682 | "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults] [-subshapes subname1 [subname2 [...]]]" |
6683 | "\n\t\t: [-visibility {0|1}]" | |
6684 | "\n\t\t: [-color {ColorName | R G B}] [-unsetColor]" | |
6685 | "\n\t\t: [-backfaceColor Color]" | |
6686 | "\n\t\t: [-material MatName] [-unsetMaterial]" | |
6687 | "\n\t\t: [-transparency Transp] [-unsetTransparency]" | |
6688 | "\n\t\t: [-width LineWidth] [-unsetWidth]" | |
6689 | "\n\t\t: [-lineType {solid|dash|dot|dotDash|0xHexPattern} [-stippleFactor factor]]" | |
6690 | "\n\t\t: [-unsetLineType]" | |
6691 | "\n\t\t: [-markerType {.|+|x|O|xcircle|pointcircle|ring1|ring2|ring3|ball|ImagePath}]" | |
33cc703b | 6692 | "\n\t\t: [-unsetMarkerType]" |
e0b24437 | 6693 | "\n\t\t: [-markerSize Scale] [-unsetMarkerSize]" |
6694 | "\n\t\t: [-freeBoundary {0|1}]" | |
6695 | "\n\t\t: [-freeBoundaryWidth Width] [-unsetFreeBoundaryWidth]" | |
6696 | "\n\t\t: [-freeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]" | |
6697 | "\n\t\t: [-isoOnTriangulation 0|1]" | |
6698 | "\n\t\t: [-maxParamValue {value}]" | |
6699 | "\n\t\t: [-sensitivity {selection_mode} {value}]" | |
6700 | "\n\t\t: [-shadingModel {unlit|flat|gouraud|phong|pbr|pbr_facet}]" | |
dc89236f | 6701 | "\n\t\t: [-unsetShadingModel]" |
e0b24437 | 6702 | "\n\t\t: [-interior {solid|hatch|hidenline|point}] [-setHatch HatchStyle]" |
6703 | "\n\t\t: [-unsetInterior]" | |
9f9490e1 | 6704 | "\n\t\t: [-faceBoundaryDraw {0|1}] [-mostContinuity {c0|g1|c1|g2|c2|c3|cn}]" |
e0b24437 | 6705 | "\n\t\t: [-faceBoundaryWidth LineWidth] [-faceBoundaryColor R G B] [-faceBoundaryType LineType]" |
6706 | "\n\t\t: [-drawEdges {0|1}] [-edgeType LineType] [-edgeColor R G B] [-quadEdges {0|1}]" | |
6707 | "\n\t\t: [-drawSilhouette {0|1}]" | |
33425a46 | 6708 | "\n\t\t: [-alphaMode {opaque|mask|blend|maskblend|blendauto} [alphaCutOff=0.5]]" |
0904aa63 | 6709 | "\n\t\t: [-dumpJson]" |
6710 | "\n\t\t: [-dumpCompact {0|1}]" | |
6711 | "\n\t\t: [-dumpDepth depth]" | |
ad3217cd | 6712 | "\n\t\t: Manage presentation properties of all, selected or named objects." |
e0b24437 | 6713 | "\n\t\t: When -subshapes is specified than following properties will be assigned to specified sub-shapes." |
6262338c | 6714 | "\n\t\t: When -defaults is specified than presentation properties will be" |
6715 | "\n\t\t: assigned to all objects that have not their own specified properties" | |
6716 | "\n\t\t: and to all objects to be displayed in the future." | |
e0b24437 | 6717 | "\n\t\t: If -defaults is used there should not be any objects' names nor -subshapes specifier." |
59ee34ef | 6718 | "\n\t\t: See also vlistcolors and vlistmaterials to list named colors and materials" |
e0b24437 | 6719 | "\n\t\t: accepted by arguments -material and -color", |
ad3217cd | 6720 | __FILE__,VAspects,group); |
6721 | ||
7fd59977 | 6722 | theCommands.Add("vsetcolor", |
ad3217cd | 6723 | "vsetcolor [-noupdate|-update] [name] ColorName" |
6724 | "\n\t\t: Sets color for all, selected or named objects." | |
6725 | "\n\t\t: Alias for vaspects -setcolor [name] ColorName.", | |
6726 | __FILE__,VAspects,group); | |
7fd59977 | 6727 | |
6728 | theCommands.Add("vunsetcolor", | |
ad3217cd | 6729 | "vunsetcolor [-noupdate|-update] [name]" |
6730 | "\n\t\t: Resets color for all, selected or named objects." | |
6731 | "\n\t\t: Alias for vaspects -unsetcolor [name].", | |
6732 | __FILE__,VAspects,group); | |
7fd59977 | 6733 | |
6734 | theCommands.Add("vsettransparency", | |
ad3217cd | 6735 | "vsettransparency [-noupdate|-update] [name] Coefficient" |
ac4aaa98 | 6736 | "\n\t\t: Sets transparency for all, selected or named objects." |
ad3217cd | 6737 | "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)." |
6738 | "\n\t\t: Alias for vaspects -settransp [name] Coefficient.", | |
6739 | __FILE__,VAspects,group); | |
7fd59977 | 6740 | |
6741 | theCommands.Add("vunsettransparency", | |
ad3217cd | 6742 | "vunsettransparency [-noupdate|-update] [name]" |
6743 | "\n\t\t: Resets transparency for all, selected or named objects." | |
6744 | "\n\t\t: Alias for vaspects -unsettransp [name].", | |
6745 | __FILE__,VAspects,group); | |
7fd59977 | 6746 | |
6747 | theCommands.Add("vsetmaterial", | |
ad3217cd | 6748 | "vsetmaterial [-noupdate|-update] [name] MaterialName" |
6749 | "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.", | |
6750 | __FILE__,VAspects,group); | |
7fd59977 | 6751 | |
6752 | theCommands.Add("vunsetmaterial", | |
ad3217cd | 6753 | "vunsetmaterial [-noupdate|-update] [name]" |
6754 | "\n\t\t: Alias for vaspects -unsetmaterial [name].", | |
6755 | __FILE__,VAspects,group); | |
7fd59977 | 6756 | |
6757 | theCommands.Add("vsetwidth", | |
ad3217cd | 6758 | "vsetwidth [-noupdate|-update] [name] width(0->10)" |
6759 | "\n\t\t: Alias for vaspects -setwidth [name] width.", | |
6760 | __FILE__,VAspects,group); | |
7fd59977 | 6761 | |
6762 | theCommands.Add("vunsetwidth", | |
ad3217cd | 6763 | "vunsetwidth [-noupdate|-update] [name]" |
2a332745 | 6764 | "\n\t\t: Alias for vaspects -unsetwidth [name].", |
ad3217cd | 6765 | __FILE__,VAspects,group); |
7fd59977 | 6766 | |
99c56d44 | 6767 | theCommands.Add("vsetinteriorstyle", |
2a332745 | 6768 | "vsetinteriorstyle [-noupdate|-update] [name] Style" |
6769 | "\n\t\t: Alias for vaspects -setInterior [name] Style.", | |
6770 | __FILE__,VAspects,group); | |
6771 | ||
6772 | theCommands.Add ("vsetedgetype", | |
6773 | "vsetedgetype [name] [-type {solid, dash, dot}] [-color R G B] [-width value]" | |
6774 | "\n\t\t: Alias for vaspects [name] -setEdgeType Type.", | |
6775 | __FILE__, VAspects, group); | |
6776 | ||
6777 | theCommands.Add ("vunsetedgetype", | |
6778 | "vunsetedgetype [name]" | |
6779 | "\n\t\t: Alias for vaspects [name] -unsetEdgeType.", | |
6780 | __FILE__, VAspects, group); | |
99c56d44 | 6781 | |
0493ffd0 | 6782 | theCommands.Add ("vshowfaceboundary", |
6783 | "vshowfaceboundary [name]" | |
6784 | "\n\t\t: Alias for vaspects [name] -setFaceBoundaryDraw on", | |
6785 | __FILE__, VAspects, group); | |
6786 | ||
7fd59977 | 6787 | theCommands.Add("vsensdis", |
faea8b40 | 6788 | "vsensdis : Display active entities (sensitive entities of one of the standard types corresponding to active selection modes)." |
6789 | "\n\t\t: Standard entity types are those defined in Select3D package:" | |
6790 | "\n\t\t: - sensitive box" | |
6791 | "\n\t\t: - sensitive face" | |
6792 | "\n\t\t: - sensitive curve" | |
6793 | "\n\t\t: - sensitive segment" | |
6794 | "\n\t\t: - sensitive circle" | |
6795 | "\n\t\t: - sensitive point" | |
6796 | "\n\t\t: - sensitive triangulation" | |
6797 | "\n\t\t: - sensitive triangle" | |
6798 | "\n\t\t: Custom(application - defined) sensitive entity types are not processed by this command.", | |
6799 | __FILE__,VDispSensi,group); | |
6800 | ||
7fd59977 | 6801 | theCommands.Add("vsensera", |
faea8b40 | 6802 | "vsensera : erase active entities", |
6803 | __FILE__,VClearSensi,group); | |
7fd59977 | 6804 | |
7fd59977 | 6805 | theCommands.Add("vsetshading", |
faea8b40 | 6806 | "vsetshading : vsetshading name Quality(default=0.0008) " |
f2139a7f | 6807 | "\n\t\t: Sets deflection coefficient that defines the quality of the shape representation in the shading mode.", |
faea8b40 | 6808 | __FILE__,VShading,group); |
7fd59977 | 6809 | |
6810 | theCommands.Add("vunsetshading", | |
faea8b40 | 6811 | "vunsetshading :vunsetshading name " |
f2139a7f | 6812 | "\n\t\t: Sets default deflection coefficient (0.0008) that defines the quality of the shape representation in the shading mode.", |
faea8b40 | 6813 | __FILE__,VShading,group); |
7fd59977 | 6814 | |
d399d3c3 | 6815 | theCommands.Add ("vtexture", |
a6dee93d | 6816 | "vtexture [-noupdate|-update] name [ImageFile|IdOfTexture|off]" |
cc8cbabe | 6817 | "\n\t\t: [-tex0 Image0] [-tex1 Image1] [...]" |
a6dee93d | 6818 | "\n\t\t: [-origin {u v|off}] [-scale {u v|off}] [-repeat {u v|off}]" |
6819 | "\n\t\t: [-trsfTrans du dv] [-trsfScale su sv] [-trsfAngle Angle]" | |
6820 | "\n\t\t: [-modulate {on|off}]" | |
6821 | "\n\t\t: [-setFilter {nearest|bilinear|trilinear}]" | |
6822 | "\n\t\t: [-setAnisoFilter {off|low|middle|quality}]" | |
6823 | "\n\t\t: [-default]" | |
6824 | "\n\t\t: The texture can be specified by filepath" | |
6825 | "\n\t\t: or as ID (0<=IdOfTexture<=20) specifying one of the predefined textures." | |
6826 | "\n\t\t: The options are:" | |
6827 | "\n\t\t: -scale Setup texture scaling for generating coordinates; (1, 1) by default" | |
6828 | "\n\t\t: -origin Setup texture origin for generating coordinates; (0, 0) by default" | |
6829 | "\n\t\t: -repeat Setup texture repeat for generating coordinates; (1, 1) by default" | |
6830 | "\n\t\t: -modulate Enable or disable texture color modulation" | |
6831 | "\n\t\t: -trsfAngle Setup dynamic texture coordinates transformation - rotation angle" | |
6832 | "\n\t\t: -trsfTrans Setup dynamic texture coordinates transformation - translation vector" | |
6833 | "\n\t\t: -trsfScale Setup dynamic texture coordinates transformation - scale vector" | |
6834 | "\n\t\t: -setFilter Setup texture filter" | |
6835 | "\n\t\t: -setAnisoFilter Setup anisotropic filter for texture with mip-levels" | |
6836 | "\n\t\t: -default Sets texture mapping default parameters", | |
d399d3c3 | 6837 | __FILE__, VTexture, group); |
7fd59977 | 6838 | |
6839 | theCommands.Add("vtexscale", | |
a6dee93d | 6840 | "vtexscale name ScaleU ScaleV" |
6841 | "\n\t\t: Alias for vtexture name -setScale ScaleU ScaleV.", | |
7fd59977 | 6842 | __FILE__,VTexture,group); |
6843 | ||
6844 | theCommands.Add("vtexorigin", | |
a6dee93d | 6845 | "vtexorigin name OriginU OriginV" |
6846 | "\n\t\t: Alias for vtexture name -setOrigin OriginU OriginV.", | |
7fd59977 | 6847 | __FILE__,VTexture,group); |
6848 | ||
6849 | theCommands.Add("vtexrepeat", | |
a6dee93d | 6850 | "vtexrepeat name RepeatU RepeatV" |
6851 | "\n\t\t: Alias for vtexture name -setRepeat RepeatU RepeatV.", | |
7fd59977 | 6852 | VTexture,group); |
6853 | ||
6854 | theCommands.Add("vtexdefault", | |
a6dee93d | 6855 | "vtexdefault name" |
6856 | "\n\t\t: Alias for vtexture name -default.", | |
7fd59977 | 6857 | VTexture,group); |
6858 | ||
ac4aaa98 | 6859 | theCommands.Add("vstate", |
51023771 | 6860 | "vstate [-entities] [-hasSelected] [name1] ... [nameN]" |
8e7c8ccf | 6861 | "\n\t\t: Reports show/hidden state for selected or named objects" |
51023771 | 6862 | "\n\t\t: -entities - print low-level information about detected entities" |
6863 | "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise", | |
7fd59977 | 6864 | __FILE__,VState,group); |
6865 | ||
6866 | theCommands.Add("vpickshapes", | |
8c088c52 | 6867 | "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]" |
6868 | "\n\t\t: Hold Ctrl and pick object by clicking Left mouse button." | |
6869 | "\n\t\t: Hold also Shift for multiple selection.", | |
6870 | __FILE__, VPickShape, group); | |
7fd59977 | 6871 | |
6872 | theCommands.Add("vtypes", | |
6873 | "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters", | |
6874 | VIOTypes,group); | |
6875 | ||
faea8b40 | 6876 | theCommands.Add("vr", |
6877 | "vr filename" | |
6878 | "\n\t\t: Reads shape from BREP-format file and displays it in the viewer. ", | |
7fd59977 | 6879 | __FILE__,vr, group); |
6880 | ||
d2e60688 | 6881 | theCommands.Add("vselfilter", |
897aeb20 | 6882 | "vselfilter [-contextfilter {AND|OR}]" |
6883 | "\n [-type {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]" | |
6884 | "\n [-secondtype {VERTEX|EDGE|WIRE|FACE|SHAPE|SHELL|SOLID}]" | |
6885 | "\n [-clear]" | |
4d901cde | 6886 | "\nSets selection shape type filter in context or remove all filters." |
897aeb20 | 6887 | "\n : Option -contextfilter : To define a selection filter for two or more types of entity," |
6888 | "\n use value AND (OR by default)." | |
4551e1be | 6889 | "\n : Option -type set type of selection filter. Filters are applied with Or combination." |
4d901cde | 6890 | "\n : Option -clear remove all filters in context", |
d2e60688 | 6891 | __FILE__,VSelFilter,group); |
4d901cde | 6892 | |
d8110103 | 6893 | theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.", |
6894 | __FILE__, VPickSelected, group); | |
6895 | ||
f751596e | 6896 | theCommands.Add ("vloadselection", |
6897 | "vloadselection [-context] [name1] ... [nameN] : allows to load selection" | |
68dcee02 | 6898 | "\n\t\t: primitives for the shapes with names given without displaying them.", |
f751596e | 6899 | __FILE__, VLoadSelection, group); |
6900 | ||
189f85a3 | 6901 | theCommands.Add("vbsdf", "vbsdf [name] [options]" |
6902 | "\nAdjusts parameters of material BSDF:" | |
6903 | "\n -help : Shows this message" | |
6904 | "\n -print : Print BSDF" | |
6905 | "\n -kd : Weight of the Lambertian BRDF" | |
6906 | "\n -kr : Weight of the reflection BRDF" | |
6907 | "\n -kt : Weight of the transmission BTDF" | |
6908 | "\n -ks : Weight of the glossy Blinn BRDF" | |
6909 | "\n -le : Self-emitted radiance" | |
6910 | "\n -fresnel : Fresnel coefficients; Allowed fresnel formats are: Constant x," | |
6911 | "\n Schlick x y z, Dielectric x, Conductor x y" | |
6912 | "\n -roughness : Roughness of material (Blinn's exponent)" | |
6913 | "\n -absorpcoeff : Absorption coefficient (only for transparent material)" | |
6914 | "\n -absorpcolor : Absorption color (only for transparent material)" | |
6915 | "\n -normalize : Normalize BSDF coefficients", | |
6916 | __FILE__, VBsdf, group); | |
6917 | ||
7fd59977 | 6918 | } |
6919 | ||
6920 | //===================================================================== | |
6921 | //========================= for testing Draft and Rib ================= | |
6922 | //===================================================================== | |
6923 | #include <BRepOffsetAPI_MakeThickSolid.hxx> | |
6924 | #include <DBRep.hxx> | |
6925 | #include <TopoDS_Face.hxx> | |
6926 | #include <gp_Pln.hxx> | |
7fd59977 | 6927 | #include <BRepOffsetAPI_DraftAngle.hxx> |
6928 | #include <Precision.hxx> | |
6929 | #include <BRepAlgo.hxx> | |
6930 | #include <OSD_Environment.hxx> | |
6931 | #include <DrawTrSurf.hxx> | |
7fd59977 | 6932 | |
6933 | //======================================================================= | |
6934 | //function : IsValid | |
6935 | //purpose : | |
6936 | //======================================================================= | |
6937 | static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs, | |
6938 | const TopoDS_Shape& theResult, | |
6939 | const Standard_Boolean closedSolid, | |
6940 | const Standard_Boolean GeomCtrl) | |
6941 | { | |
6942 | OSD_Environment check ("DONT_SWITCH_IS_VALID") ; | |
6943 | TCollection_AsciiString checkValid = check.Value(); | |
6944 | Standard_Boolean ToCheck = Standard_True; | |
6945 | if (!checkValid.IsEmpty()) { | |
0797d9d3 | 6946 | #ifdef OCCT_DEBUG |
04232180 | 6947 | std::cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n"; |
7fd59977 | 6948 | #endif |
6949 | if ( checkValid=="true" || checkValid=="TRUE" ) { | |
6950 | ToCheck= Standard_False; | |
6951 | } | |
6952 | } else { | |
0797d9d3 | 6953 | #ifdef OCCT_DEBUG |
04232180 | 6954 | std::cout <<"DONT_SWITCH_IS_VALID non positionne\n"; |
7fd59977 | 6955 | #endif |
6956 | } | |
6957 | Standard_Boolean IsValid = Standard_True; | |
6958 | if (ToCheck) | |
6959 | IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ; | |
6960 | return IsValid; | |
6961 | ||
6962 | } | |
6963 | ||
6964 | //=============================================================================== | |
6965 | // TDraft : test draft, uses AIS Viewer | |
6966 | // Solid Face Plane Angle Reverse | |
6967 | //=============================================================================== | |
6968 | static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
6969 | { | |
6970 | if (argc < 5) return 1; | |
6971 | // argv[1] - TopoDS_Shape Solid | |
6972 | // argv[2] - TopoDS_Shape Face | |
6973 | // argv[3] - TopoDS_Shape Plane | |
6974 | // argv[4] - Standard_Real Angle | |
6975 | // argv[5] - Standard_Integer Reverse | |
6976 | ||
91322f44 | 6977 | // Sprintf(prefix, argv[1]); |
7fd59977 | 6978 | Standard_Real anAngle = 0; |
6979 | Standard_Boolean Rev = Standard_False; | |
6980 | Standard_Integer rev = 0; | |
1c8fc6be | 6981 | TopoDS_Shape Solid = DBRep::Get (argv[1]); |
6982 | TopoDS_Shape face = DBRep::Get (argv[2]); | |
7fd59977 | 6983 | TopoDS_Face Face = TopoDS::Face(face); |
1c8fc6be | 6984 | TopoDS_Shape Plane = DBRep::Get (argv[3]); |
7fd59977 | 6985 | if (Plane.IsNull ()) { |
586db386 | 6986 | di << "TEST : Plane is NULL\n"; |
7fd59977 | 6987 | return 1; |
6988 | } | |
91322f44 | 6989 | anAngle = Draw::Atof(argv[4]); |
c6541a0c | 6990 | anAngle = 2*M_PI * anAngle / 360.0; |
7fd59977 | 6991 | gp_Pln aPln; |
6992 | Handle( Geom_Surface )aSurf; | |
787ff240 | 6993 | PrsDim_KindOfSurface aSurfType; |
7fd59977 | 6994 | Standard_Real Offset; |
6995 | gp_Dir aDir; | |
6996 | if(argc > 4) { // == 5 | |
91322f44 | 6997 | rev = Draw::Atoi(argv[5]); |
7fd59977 | 6998 | Rev = (rev)? Standard_True : Standard_False; |
6999 | } | |
7000 | ||
7001 | TopoDS_Face face2 = TopoDS::Face(Plane); | |
787ff240 | 7002 | if(!PrsDim::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset)) |
7fd59977 | 7003 | { |
586db386 | 7004 | di << "TEST : Can't find plane\n"; |
7fd59977 | 7005 | return 1; |
7006 | } | |
7007 | ||
7008 | aDir = aPln.Axis().Direction(); | |
7009 | if (!aPln.Direct()) | |
7010 | aDir.Reverse(); | |
7011 | if (Plane.Orientation() == TopAbs_REVERSED) | |
7012 | aDir.Reverse(); | |
7013 | di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n"; | |
7014 | ||
7015 | BRepOffsetAPI_DraftAngle Draft (Solid); | |
7016 | ||
7017 | if(Abs(anAngle)< Precision::Angular()) { | |
586db386 | 7018 | di << "TEST : NULL angle\n"; |
7fd59977 | 7019 | return 1;} |
7020 | ||
7021 | if(Rev) anAngle = - anAngle; | |
7022 | Draft.Add (Face, aDir, anAngle, aPln); | |
7023 | Draft.Build (); | |
7024 | if (!Draft.IsDone()) { | |
586db386 | 7025 | di << "TEST : Draft Not DONE \n"; |
7fd59977 | 7026 | return 1; |
7027 | } | |
7028 | TopTools_ListOfShape Larg; | |
7029 | Larg.Append(Solid); | |
7030 | if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) { | |
586db386 | 7031 | di << "TEST : DesignAlgo returns Not valid\n"; |
7fd59977 | 7032 | return 1; |
7033 | } | |
7034 | ||
7035 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
7036 | Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape()); | |
7037 | ||
7038 | if ( !ais.IsNull() ) { | |
7039 | ais->SetColor(DEFAULT_COLOR); | |
7040 | ais->SetMaterial(DEFAULT_MATERIAL); | |
7041 | // Display the AIS_Shape without redraw | |
7042 | Ctx->Display(ais, Standard_False); | |
7043 | ||
7044 | const char *Name = "draft1"; | |
8f521168 | 7045 | Handle(AIS_InteractiveObject) an_object; |
7046 | if (GetMapOfAIS().Find2(Name, an_object)) | |
7047 | { | |
7048 | if (!an_object.IsNull()) | |
7049 | { | |
7050 | Ctx->Remove (an_object, Standard_True); | |
7fd59977 | 7051 | } |
8f521168 | 7052 | GetMapOfAIS().UnBind2 (Name); |
7fd59977 | 7053 | } |
7054 | GetMapOfAIS().Bind(ais, Name); | |
7055 | // DBRep::Set("draft", ais->Shape()); | |
7056 | } | |
7057 | Ctx->Display(ais, Standard_True); | |
7058 | return 0; | |
7059 | } | |
7060 | ||
1d7ca641 | 7061 | //============================================================================== |
7062 | //function : splitParameter | |
197ac94e | 7063 | //purpose : Split parameter string to parameter name and parameter value |
1d7ca641 | 7064 | //============================================================================== |
7065 | Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString, | |
7066 | TCollection_AsciiString& theName, | |
7067 | TCollection_AsciiString& theValue) | |
7068 | { | |
7069 | Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length()); | |
7070 | ||
7071 | if (aParamNameEnd == 0) | |
7072 | { | |
7073 | return Standard_False; | |
7074 | } | |
7075 | ||
7076 | TCollection_AsciiString aString (theString); | |
7077 | if (aParamNameEnd != 0) | |
7078 | { | |
7079 | theValue = aString.Split (aParamNameEnd); | |
7080 | aString.Split (aString.Length() - 1); | |
7081 | theName = aString; | |
7082 | } | |
7fd59977 | 7083 | |
1d7ca641 | 7084 | return Standard_True; |
7085 | } | |
7fd59977 | 7086 | |
7087 | //============================================================================ | |
7088 | // MyCommands | |
7089 | //============================================================================ | |
7090 | void ViewerTest::MyCommands( Draw_Interpretor& theCommands) | |
7091 | { | |
7092 | ||
7093 | DrawTrSurf::BasicCommands(theCommands); | |
7094 | const char* group = "Check Features Operations commands"; | |
7095 | ||
7096 | theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse", | |
7097 | __FILE__, | |
7098 | &TDraft,group); //Draft_Modification | |
7099 | } | |
7100 | ||
7101 | //============================================================================== | |
7102 | // ViewerTest::Factory | |
7103 | //============================================================================== | |
7104 | void ViewerTest::Factory(Draw_Interpretor& theDI) | |
7105 | { | |
7106 | // definition of Viewer Command | |
128cc8df | 7107 | ViewerTest::Commands(theDI); |
128cc8df | 7108 | |
0797d9d3 | 7109 | #ifdef OCCT_DEBUG |
586db386 | 7110 | theDI << "Draw Plugin : OCC V2d & V3d commands are loaded\n"; |
7fd59977 | 7111 | #endif |
7112 | } | |
7113 | ||
7114 | // Declare entry point PLUGINFACTORY | |
7115 | DPLUGIN(ViewerTest) |