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