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