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