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