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