Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: ViewerTest.cxx |
2 | // Created: Wed Jul 23 14:14:01 1997 | |
3 | // Author: Henri JEANNIN | |
7fd59977 | 4 | // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display... |
5 | // | |
6 | // Modified by Robert Coublanc [nov 16-17-18 1998] | |
7 | // -split ViewerTest.cxx into 3 files : ViewerTest.cxx, | |
8 | // ViewerTest_ObjectCommands.cxx | |
9 | // ViewerTest_RelationCommands.cxx | |
10 | // -add Functions and commands for interactive selection of shapes and objects | |
11 | // in AIS Viewers. (PickShape(s), PickObject(s), | |
12 | ||
13 | #include <Standard_Stream.hxx> | |
14 | ||
15 | #include <ViewerTest.hxx> | |
16 | #include <TopLoc_Location.hxx> | |
17 | #include <TopTools_HArray1OfShape.hxx> | |
18 | #include <TColStd_HArray1OfTransient.hxx> | |
19 | #include <OSD_Directory.hxx> | |
20 | #include <OSD_File.hxx> | |
21 | #include <OSD_Path.hxx> | |
22 | #include <OSD_Timer.hxx> | |
23 | #include <Geom_Axis2Placement.hxx> | |
24 | #include <Geom_Axis1Placement.hxx> | |
25 | #include <gp_Trsf.hxx> | |
26 | #include <TopExp_Explorer.hxx> | |
27 | #include <BRepAdaptor_Curve.hxx> | |
28 | #include <StdSelect_ShapeTypeFilter.hxx> | |
29 | #include <AIS.hxx> | |
30 | #include <AIS_InteractiveObject.hxx> | |
31 | #include <AIS_Trihedron.hxx> | |
32 | #include <AIS_Axis.hxx> | |
33 | #include <AIS_Relation.hxx> | |
34 | #include <AIS_TypeFilter.hxx> | |
35 | #include <AIS_SignatureFilter.hxx> | |
36 | #include <AIS_ListOfInteractive.hxx> | |
37 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
38 | #include <Image_PixMap.hxx> | |
39 | ||
40 | #ifdef HAVE_CONFIG_H | |
41 | # include <config.h> | |
42 | #endif | |
43 | #include <stdio.h> | |
44 | #ifdef HAVE_STRINGS_H | |
45 | # include <strings.h> | |
46 | #endif | |
47 | ||
48 | #include <Draw_Interpretor.hxx> | |
49 | #include <TCollection_AsciiString.hxx> | |
50 | #include <Draw_PluginMacro.hxx> | |
51 | #include <ViewerTest.hxx> | |
52 | #include <Viewer2dTest.hxx> | |
53 | ||
54 | // avoid warnings on 'extern "C"' functions returning C++ classes | |
55 | #ifdef WNT | |
56 | #define _CRT_SECURE_NO_DEPRECATE | |
57 | #pragma warning(4:4190) | |
58 | #pragma warning (disable:4996) | |
59 | #endif | |
60 | ||
61 | #include <NIS_InteractiveContext.hxx> | |
62 | #include <NIS_Triangulated.hxx> | |
63 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); | |
64 | ||
65 | //======================================================================= | |
66 | //function : GetColorFromName | |
67 | //purpose : get the Quantity_NameOfColor from a string | |
68 | //======================================================================= | |
69 | ||
70 | #include <Quantity_NameOfColor.hxx> | |
71 | #include <Quantity_Color.hxx> | |
72 | #include <Quantity_NameOfColor.hxx> | |
73 | ||
74 | #include <Graphic3d_NameOfMaterial.hxx> | |
75 | ||
76 | #define DEFAULT_COLOR Quantity_NOC_GOLDENROD | |
77 | #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS | |
78 | ||
79 | static Quantity_NameOfColor GetColorFromName( const char *name ) | |
80 | { | |
81 | Quantity_NameOfColor ret = DEFAULT_COLOR; | |
82 | ||
83 | Standard_Boolean Found = Standard_False; | |
84 | Standard_CString colstring; | |
85 | for(Standard_Integer i=0;i<=514 && !Found;i++) | |
86 | { | |
87 | colstring = Quantity_Color::StringName(Quantity_NameOfColor(i)); | |
88 | if (!strcasecmp(name,colstring)) { | |
89 | ret = (Quantity_NameOfColor)i; | |
90 | Found = Standard_True; | |
91 | } | |
92 | } | |
93 | ||
94 | return ret; | |
95 | } | |
96 | ||
97 | //======================================================================= | |
98 | //function : GetMaterialFromName | |
99 | //purpose : get the Graphic3d_NameOfMaterial from a string | |
100 | //======================================================================= | |
101 | ||
102 | static Graphic3d_NameOfMaterial GetMaterialFromName( const char *name ) | |
103 | { | |
104 | Graphic3d_NameOfMaterial mat = DEFAULT_MATERIAL; | |
105 | ||
106 | if ( !strcasecmp(name,"BRASS" ) ) mat = Graphic3d_NOM_BRASS; | |
107 | else if ( !strcasecmp(name,"BRONZE" ) ) mat = Graphic3d_NOM_BRONZE; | |
108 | else if ( !strcasecmp(name,"COPPER" ) ) mat = Graphic3d_NOM_COPPER; | |
109 | else if ( !strcasecmp(name,"GOLD" ) ) mat = Graphic3d_NOM_GOLD; | |
110 | else if ( !strcasecmp(name,"PEWTER" ) ) mat = Graphic3d_NOM_PEWTER; | |
111 | else if ( !strcasecmp(name,"SILVER" ) ) mat = Graphic3d_NOM_SILVER; | |
112 | else if ( !strcasecmp(name,"STEEL" ) ) mat = Graphic3d_NOM_STEEL; | |
113 | else if ( !strcasecmp(name,"METALIZED" ) ) mat = Graphic3d_NOM_METALIZED; | |
114 | else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE; | |
115 | else if ( !strcasecmp(name,"CHROME" ) ) mat = Graphic3d_NOM_CHROME; | |
116 | else if ( !strcasecmp(name,"ALUMINIUM" ) ) mat = Graphic3d_NOM_ALUMINIUM; | |
117 | else if ( !strcasecmp(name,"STONE" ) ) mat = Graphic3d_NOM_STONE; | |
118 | else if ( !strcasecmp(name,"NEON_PHC" ) ) mat = Graphic3d_NOM_NEON_PHC; | |
119 | else if ( !strcasecmp(name,"NEON_GNC" ) ) mat = Graphic3d_NOM_NEON_GNC; | |
120 | else if ( !strcasecmp(name,"PLASTER" ) ) mat = Graphic3d_NOM_PLASTER; | |
121 | else if ( !strcasecmp(name,"SHINY_PLASTIC" ) ) mat = Graphic3d_NOM_SHINY_PLASTIC; | |
122 | else if ( !strcasecmp(name,"SATIN" ) ) mat = Graphic3d_NOM_SATIN; | |
123 | else if ( !strcasecmp(name,"PLASTIC" ) ) mat = Graphic3d_NOM_PLASTIC; | |
124 | else if ( !strcasecmp(name,"OBSIDIAN" ) ) mat = Graphic3d_NOM_OBSIDIAN; | |
125 | else if ( !strcasecmp(name,"JADE" ) ) mat = Graphic3d_NOM_JADE; | |
126 | ||
127 | return mat; | |
128 | } | |
129 | ||
130 | //======================================================================= | |
131 | //function : GetTypeNames | |
132 | //purpose : | |
133 | //======================================================================= | |
134 | static const char** GetTypeNames() | |
135 | { | |
136 | static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane", | |
137 | "Shape","ConnectedShape","MultiConn.Shape", | |
138 | "ConnectedInter.","MultiConn.", | |
139 | "Constraint","Dimension"}; | |
140 | static const char** ThePointer = names; | |
141 | return ThePointer; | |
142 | } | |
143 | ||
144 | //======================================================================= | |
145 | //function : GetTypeAndSignfromString | |
146 | //purpose : | |
147 | //======================================================================= | |
148 | void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign) | |
149 | { | |
150 | const char ** thefullnames = GetTypeNames(); | |
151 | Standard_Integer index(-1); | |
152 | ||
153 | for(Standard_Integer i=0;i<=13 && index==-1;i++) | |
154 | if(!strcasecmp(name,thefullnames[i])) | |
155 | index = i; | |
156 | ||
157 | if(index ==-1){ | |
158 | TheType = AIS_KOI_None; | |
159 | TheSign = -1; | |
160 | return; | |
161 | } | |
162 | ||
163 | if(index<=6){ | |
164 | TheType = AIS_KOI_Datum; | |
165 | TheSign = index+1; | |
166 | } | |
167 | else if (index <=9){ | |
168 | TheType = AIS_KOI_Shape; | |
169 | TheSign = index-7; | |
170 | } | |
171 | else if(index<=11){ | |
172 | TheType = AIS_KOI_Object; | |
173 | TheSign = index-10; | |
174 | } | |
175 | else{ | |
176 | TheType = AIS_KOI_Relation; | |
177 | TheSign = index-12; | |
178 | } | |
179 | ||
180 | } | |
181 | ||
182 | ||
183 | ||
184 | #include <string.h> | |
185 | #include <Draw_Interpretor.hxx> | |
186 | #include <Draw.hxx> | |
187 | #include <Draw_Appli.hxx> | |
188 | #include <DBRep.hxx> | |
189 | ||
190 | ||
191 | #include <TCollection_AsciiString.hxx> | |
192 | #include <V3d_Viewer.hxx> | |
193 | #include <V3d_View.hxx> | |
194 | #include <V3d.hxx> | |
195 | ||
196 | #include <AIS_InteractiveContext.hxx> | |
197 | #include <AIS_Shape.hxx> | |
198 | #include <AIS_TexturedShape.hxx> | |
199 | #include <AIS_DisplayMode.hxx> | |
200 | #include <TColStd_MapOfInteger.hxx> | |
201 | #include <AIS_MapOfInteractive.hxx> | |
202 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> | |
203 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
204 | #include <ViewerTest_EventManager.hxx> | |
205 | ||
206 | #include <TopoDS_Solid.hxx> | |
207 | #include <BRepTools.hxx> | |
208 | #include <BRep_Builder.hxx> | |
209 | #include <TopAbs_ShapeEnum.hxx> | |
210 | ||
211 | #include <TopoDS.hxx> | |
212 | #include <BRep_Tool.hxx> | |
213 | ||
214 | ||
215 | #include <Draw_Window.hxx> | |
216 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
217 | #include <AIS_ListOfInteractive.hxx> | |
218 | #include <AIS_DisplayMode.hxx> | |
219 | #include <TopTools_ListOfShape.hxx> | |
220 | #include <BRepOffsetAPI_MakeThickSolid.hxx> | |
221 | #include <BRepOffset.hxx> | |
222 | ||
223 | ||
224 | //============================================================================== | |
225 | //function : GetTypeNameFromShape | |
226 | //purpose : get the shape type as a string from a shape | |
227 | //============================================================================== | |
228 | ||
229 | static const char* GetTypeNameFromShape( const TopoDS_Shape& aShape ) | |
230 | { const char *ret = "????"; | |
231 | ||
232 | if ( aShape.IsNull() ) ret = "Null Shape"; | |
233 | ||
234 | switch ( aShape.ShapeType() ) { | |
235 | case TopAbs_COMPOUND : ret = "COMPOUND" ; break; | |
236 | case TopAbs_COMPSOLID : ret = "COMPSOLID" ; break; | |
237 | case TopAbs_SOLID : ret = "SOLID" ; break; | |
238 | case TopAbs_SHELL : ret = "SHELL" ; break; | |
239 | case TopAbs_FACE : ret = "FACE" ; break; | |
240 | case TopAbs_WIRE : ret = "WIRE" ; break; | |
241 | case TopAbs_EDGE : ret = "EDGE" ; break; | |
242 | case TopAbs_VERTEX : ret = "VERTEX" ; break; | |
243 | case TopAbs_SHAPE : ret = "SHAPE" ; break; | |
244 | } | |
245 | return ret; | |
246 | } | |
247 | //============================================================================== | |
248 | // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES | |
249 | //============================================================================== | |
250 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){ | |
251 | static ViewerTest_DoubleMapOfInteractiveAndName TheMap; | |
252 | return TheMap; | |
253 | } | |
254 | ||
9558a876 A |
255 | |
256 | //============================================================================== | |
257 | //function : VDisplayAISObject | |
258 | //purpose : register interactive object in the map of AIS objects; | |
259 | // if other object with such name already registered, it will be kept | |
260 | // or replaced depending on value of <theReplaceIfExists>, | |
261 | // if "true" - the old object will be cleared from AIS context; | |
262 | // returns Standard_True if <theAISObj> registered in map; | |
263 | //============================================================================== | |
264 | Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, | |
265 | const Handle(AIS_InteractiveObject)& theAISObj, | |
266 | Standard_Boolean theReplaceIfExists = Standard_True) | |
267 | { | |
268 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
269 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
270 | if (aContextAIS.IsNull()) | |
271 | { | |
272 | std::cout << "AIS context is not available.\n"; | |
273 | return Standard_False; | |
274 | } | |
275 | ||
276 | if (aMap.IsBound2 (theName)) | |
277 | { | |
278 | if (!theReplaceIfExists) | |
279 | { | |
280 | std::cout << "Other interactive object has been already " | |
281 | << "registered with name: " << theName << ".\n" | |
282 | << "Please use another name.\n"; | |
283 | return Standard_False; | |
284 | } | |
285 | ||
286 | // stop displaying object | |
287 | Handle(AIS_InteractiveObject) anOldObj = | |
288 | Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName)); | |
289 | ||
290 | if (!anOldObj.IsNull()) | |
291 | aContextAIS->Clear (anOldObj, Standard_True); | |
292 | ||
293 | // remove name and old object from map | |
294 | aMap.UnBind2 (theName); | |
295 | } | |
296 | ||
297 | // unbind AIS object if was bound with another name | |
298 | aMap.UnBind1 (theAISObj); | |
299 | ||
300 | // can be registered without rebinding | |
301 | aMap.Bind (theAISObj, theName); | |
302 | aContextAIS->Display (theAISObj, Standard_True); | |
303 | return Standard_True; | |
304 | } | |
305 | ||
7fd59977 | 306 | static TColStd_MapOfInteger theactivatedmodes(8); |
307 | static TColStd_ListOfTransient theEventMgrs; | |
308 | ||
309 | static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView, | |
310 | const Handle(AIS_InteractiveContext)& Ctx) | |
311 | { | |
312 | theEventMgrs.Clear(); | |
313 | theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx)); | |
314 | } | |
315 | ||
316 | static Handle(V3d_View)& a3DView(){ | |
317 | static Handle(V3d_View) Viou; | |
318 | return Viou; | |
319 | } | |
320 | ||
321 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){ | |
322 | static Handle(AIS_InteractiveContext) aContext; | |
323 | return aContext; | |
324 | } | |
325 | ||
326 | Handle(V3d_View) ViewerTest::CurrentView() | |
327 | { | |
328 | return a3DView(); | |
329 | } | |
330 | void ViewerTest::CurrentView(const Handle(V3d_View)& V) | |
331 | { | |
332 | a3DView() = V; | |
333 | } | |
334 | ||
335 | Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext() | |
336 | { | |
337 | static Handle(NIS_InteractiveContext) aContext; | |
338 | if (aContext.IsNull()) { | |
339 | aContext = new NIS_InteractiveContext; | |
340 | aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal); | |
341 | } | |
342 | return aContext; | |
343 | } | |
344 | ||
345 | Handle(AIS_InteractiveContext) ViewerTest::GetAISContext() | |
346 | { | |
347 | return TheAISContext(); | |
348 | } | |
349 | ||
350 | void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx) | |
351 | { | |
352 | TheAISContext() = aCtx; | |
353 | ViewerTest::ResetEventManager(); | |
354 | } | |
355 | ||
356 | Handle(V3d_Viewer) ViewerTest::GetViewerFromContext() | |
357 | { | |
4952a30a | 358 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
7fd59977 | 359 | } |
360 | ||
361 | Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext() | |
362 | { | |
4952a30a | 363 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
7fd59977 | 364 | } |
365 | ||
366 | ||
367 | void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){ | |
368 | theEventMgrs.Prepend(EM); | |
369 | } | |
370 | ||
371 | void ViewerTest::UnsetEventManager() | |
372 | { | |
373 | theEventMgrs.RemoveFirst(); | |
374 | } | |
375 | ||
376 | ||
377 | void ViewerTest::ResetEventManager() | |
378 | { | |
379 | const Handle(NIS_View) aView = | |
380 | Handle(NIS_View)::DownCast(ViewerTest::CurrentView()); | |
381 | VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext()); | |
382 | } | |
383 | ||
384 | Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager() | |
385 | { | |
386 | Handle(ViewerTest_EventManager) EM; | |
387 | if(theEventMgrs.IsEmpty()) return EM; | |
388 | Handle(Standard_Transient) Tr = theEventMgrs.First(); | |
389 | EM = *((Handle(ViewerTest_EventManager)*)&Tr); | |
390 | return EM; | |
391 | } | |
392 | ||
393 | ||
394 | //======================================================================= | |
395 | //function : Get Context and active viou.. | |
396 | //purpose : | |
397 | //======================================================================= | |
398 | void GetCtxAndView(Handle(AIS_InteractiveContext)& Ctx, | |
399 | Handle(V3d_View)& Viou) | |
400 | { | |
401 | Ctx = ViewerTest::GetAISContext(); | |
402 | if (!Ctx.IsNull()) | |
403 | { | |
404 | const Handle(V3d_Viewer)& Vwr = Ctx->CurrentViewer(); | |
405 | Vwr->InitActiveViews(); | |
406 | if(Vwr->MoreActiveViews()) | |
407 | Viou = Vwr->ActiveView(); | |
408 | } | |
409 | } | |
410 | ||
411 | ||
412 | //============================================================================== | |
413 | //function : GetShapeFromName | |
414 | //purpose : Compute an Shape from a draw variable or a file name | |
415 | //============================================================================== | |
416 | ||
417 | static TopoDS_Shape GetShapeFromName(const char* name) | |
418 | { | |
419 | TopoDS_Shape S = DBRep::Get(name); | |
420 | ||
421 | if ( S.IsNull() ) { | |
422 | BRep_Builder aBuilder; | |
423 | BRepTools::Read( S, name, aBuilder); | |
424 | } | |
425 | ||
426 | return S; | |
427 | } | |
428 | //============================================================================== | |
429 | //function : GetShapeFromName | |
430 | //purpose : Compute an Shape from a draw variable or a file name | |
431 | //============================================================================== | |
432 | // Unused : | |
433 | #ifdef DEB | |
434 | static TopoDS_Shape GetShapeFromAIS(const AIS_InteractiveObject & TheAisIO ) | |
435 | { | |
436 | TopoDS_Shape TheShape=((*(Handle(AIS_Shape)*)&TheAisIO))->Shape(); | |
437 | return TheShape; | |
438 | } | |
439 | #endif | |
440 | //============================================================================== | |
441 | //function : GetAISShapeFromName | |
442 | //purpose : Compute an AIS_Shape from a draw variable or a file name | |
443 | //============================================================================== | |
444 | Handle(AIS_Shape) GetAISShapeFromName(const char* name) | |
445 | { | |
446 | Handle(AIS_Shape) retsh; | |
447 | ||
448 | if(GetMapOfAIS().IsBound2(name)){ | |
449 | const Handle(AIS_InteractiveObject) IO = | |
450 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
451 | if (!IO.IsNull()) { | |
452 | if(IO->Type()==AIS_KOI_Shape) | |
453 | if(IO->Signature()==0){ | |
454 | retsh = *((Handle(AIS_Shape)*)&IO); | |
455 | } | |
456 | else | |
457 | cout << "an Object which is not an AIS_Shape " | |
458 | "already has this name!!!"<<endl; | |
459 | } | |
460 | return retsh; | |
461 | } | |
462 | ||
463 | ||
464 | TopoDS_Shape S = GetShapeFromName(name); | |
465 | if ( !S.IsNull() ) { | |
466 | retsh = new AIS_Shape(S); | |
467 | } | |
468 | return retsh; | |
469 | } | |
470 | ||
471 | ||
472 | //============================================================================== | |
473 | //function : Clear | |
474 | //purpose : Remove all the object from the viewer | |
475 | //============================================================================== | |
476 | void ViewerTest::Clear() | |
477 | { | |
478 | if ( !a3DView().IsNull() ) { | |
479 | if (TheAISContext()->HasOpenedContext()) | |
480 | TheAISContext()->CloseLocalContext(); | |
481 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS()); | |
482 | while ( it.More() ) { | |
483 | cout << "Remove " << it.Key2() << endl; | |
484 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
485 | const Handle(AIS_InteractiveObject) anObj = | |
486 | Handle(AIS_InteractiveObject)::DownCast (it.Key1()); | |
487 | TheAISContext()->Remove(anObj,Standard_False); | |
488 | } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
489 | const Handle(NIS_InteractiveObject) anObj = | |
490 | Handle(NIS_InteractiveObject)::DownCast (it.Key1()); | |
ffe2bea7 | 491 | TheNISContext()->Remove(anObj); |
7fd59977 | 492 | } |
493 | it.Next(); | |
494 | } | |
495 | TheAISContext()->UpdateCurrentViewer(); | |
ffe2bea7 | 496 | // TheNISContext()->UpdateViews(); |
7fd59977 | 497 | GetMapOfAIS().Clear(); |
498 | } | |
499 | } | |
500 | ||
501 | //============================================================================== | |
502 | //function : StandardModesActivation | |
503 | //purpose : Activate a selection mode, vertex, edge, wire ..., in a local | |
504 | // Context | |
505 | //============================================================================== | |
506 | void ViewerTest::StandardModeActivation(const Standard_Integer mode ) | |
507 | { | |
508 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
509 | if(mode==0) { | |
510 | if (TheAISContext()->HasOpenedContext()) | |
511 | aContext->CloseLocalContext(); | |
512 | } else { | |
513 | ||
514 | if(!aContext->HasOpenedContext()) { | |
515 | // To unhilight the preselected object | |
516 | aContext->UnhilightCurrents(Standard_False); | |
517 | // Open a local Context in order to be able to select subshape from | |
518 | // the selected shape if any or for all if there is no selection | |
519 | if (!aContext->FirstCurrentObject().IsNull()){ | |
520 | aContext->OpenLocalContext(Standard_False); | |
521 | ||
522 | for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){ | |
523 | aContext->Load( aContext->Current(),-1,Standard_True); | |
524 | } | |
525 | } | |
526 | else | |
527 | aContext->OpenLocalContext(); | |
528 | } | |
529 | ||
530 | const char *cmode="???"; | |
531 | ||
532 | switch (mode) { | |
533 | case 0: cmode = "Shape"; break; | |
534 | case 1: cmode = "Vertex"; break; | |
535 | case 2: cmode = "Edge"; break; | |
536 | case 3: cmode = "Wire"; break; | |
537 | case 4: cmode = "Face"; break; | |
538 | case 5: cmode = "Shell"; break; | |
539 | case 6: cmode = "Solid"; break; | |
540 | case 7: cmode = "Compound"; break; | |
541 | } | |
542 | ||
543 | if(theactivatedmodes.Contains(mode)) | |
544 | { // Desactivate | |
545 | aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode)); | |
546 | theactivatedmodes.Remove(mode); | |
547 | cout<<"Mode "<< cmode <<" OFF"<<endl; | |
548 | } | |
549 | else | |
550 | { // Activate | |
551 | aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode)); | |
552 | theactivatedmodes.Add(mode); | |
553 | cout<<"Mode "<< cmode << " ON" << endl; | |
554 | } | |
555 | } | |
556 | } | |
557 | ||
558 | //============================================================================== | |
559 | //function : SelectFromContext | |
560 | //purpose : pick / select an object from the last MoveTo() on a | |
561 | // ButtonPress event | |
562 | //============================================================================== | |
563 | ||
564 | Handle(AIS_InteractiveObject) Select(Standard_Integer argc, | |
565 | const char** argv, | |
566 | Standard_Boolean shift, | |
567 | Standard_Boolean pick ) | |
568 | { | |
569 | Handle(AIS_InteractiveObject) ret; | |
570 | Handle (ViewerTest_EventManager) EM = ViewerTest::CurrentEventManager(); | |
571 | if ( shift ) { | |
572 | EM->ShiftSelect(); | |
573 | } | |
574 | else { | |
575 | EM->Select(); | |
576 | } | |
577 | const Handle(AIS_InteractiveContext) aContext = EM->Context(); | |
578 | ||
579 | if ( !aContext->HasOpenedContext() ) { | |
580 | aContext->InitCurrent(); | |
581 | while ( aContext->MoreCurrent() ) { | |
582 | Handle(AIS_InteractiveObject) aisPickedShape = | |
583 | Handle(AIS_InteractiveObject)::DownCast(aContext->Current()); | |
584 | ||
585 | //JR/Hp | |
586 | const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))? | |
587 | // const char *name = (GetMapOfAIS().IsBound1(aisPickedShape))? | |
588 | GetMapOfAIS().Find1(aisPickedShape).ToCString() : | |
589 | "????"; | |
590 | Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aisPickedShape); | |
591 | if(!TheRealSh.IsNull()){ | |
592 | cout << "Current is " << name | |
593 | << " (" << GetTypeNameFromShape(TheRealSh->Shape()) | |
594 | << ")" << endl; | |
595 | } | |
596 | ret = aisPickedShape; | |
597 | if(!TheRealSh.IsNull()){ | |
598 | if ( pick && argc > 4 ) { | |
599 | DBRep::Set(argv[4], TheRealSh->Shape()); | |
600 | } | |
601 | } | |
602 | aContext->NextCurrent(); | |
603 | } | |
604 | } | |
605 | else { | |
606 | // A LocalContext is opened, the use xxxxSelected() | |
607 | // to select an object and its SubShape | |
608 | aContext->InitSelected(); | |
609 | while ( aContext->MoreSelected() ) { | |
610 | if ( !aContext->HasSelectedShape() ) { | |
611 | } | |
612 | else { | |
613 | TopoDS_Shape PickedShape = aContext->SelectedShape(); | |
614 | if ( pick && argc > 5 ) { | |
615 | DBRep::Set(argv[5], PickedShape); | |
616 | } | |
617 | } | |
618 | ||
619 | if ( aContext->Interactive().IsNull() ) { | |
620 | cout << "??? (No InteractiveObject selected)" << endl; | |
621 | } | |
622 | else { | |
623 | Handle(AIS_InteractiveObject) aisPicked = | |
624 | Handle(AIS_InteractiveObject)::DownCast(aContext->Interactive()); | |
625 | ret = aisPicked; | |
626 | Handle(AIS_Shape) aisPickedShape = Handle(AIS_Shape)::DownCast(aisPicked); | |
627 | ||
628 | // Get back its name | |
629 | //JR/Hp | |
630 | const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )? | |
631 | // const char *name = ( GetMapOfAIS().IsBound1(aisPicked) )? | |
632 | GetMapOfAIS().Find1(aisPicked).ToCString() : | |
633 | "????"; | |
634 | ||
635 | if(!aisPickedShape.IsNull()){ | |
636 | if ( pick && argc > 4 ) { | |
637 | // Create a draw variable to store the wohole shape | |
638 | // for vpick command | |
639 | DBRep::Set(argv[4], aisPickedShape->Shape()); | |
640 | } | |
641 | ||
642 | cout << name << " (" << GetTypeNameFromShape(aisPickedShape->Shape()) | |
643 | << ")" << endl ; | |
644 | } | |
645 | } | |
646 | // Goto the next selected object | |
647 | aContext->NextSelected(); | |
648 | } | |
649 | } | |
650 | return ret; | |
651 | } | |
652 | ||
653 | //============================================================================== | |
654 | //function : DetectedFromContext | |
655 | //purpose : hilight dynamicaly an object from the last MoveTo() on a | |
656 | // MouseMove event | |
657 | //============================================================================== | |
658 | Handle(AIS_InteractiveObject) DetectedFromContext( | |
659 | Handle(AIS_InteractiveContext) aContext ) | |
660 | { | |
661 | Handle(AIS_InteractiveObject) ret; | |
662 | if ( aContext->HasDetected() ) { | |
663 | if ( !aContext->HasDetectedShape() ) { | |
664 | //No SubShape selected | |
665 | } | |
666 | else { | |
667 | // Get the detected SubShape | |
668 | TopoDS_Shape PickedShape = aContext->DetectedShape(); | |
669 | } | |
670 | if ( !aContext->DetectedInteractive().IsNull() ) { | |
671 | Handle(AIS_InteractiveObject) aisPickedShape = | |
672 | Handle(AIS_InteractiveObject)::DownCast(aContext->DetectedInteractive()); | |
673 | ret = aisPickedShape; | |
7fd59977 | 674 | } |
675 | } | |
676 | return ret; | |
677 | } | |
678 | ||
679 | ||
680 | //============================================================================== | |
681 | //function : VDispAreas,VDispSensitive,... | |
682 | //purpose : Redraw the view | |
683 | //Draw arg : No args | |
684 | //============================================================================== | |
685 | static int VDispAreas (Draw_Interpretor& ,Standard_Integer , const char** ) | |
686 | { | |
687 | ||
688 | Handle(AIS_InteractiveContext) Ctx; | |
689 | Handle(V3d_View) Viou; | |
690 | GetCtxAndView(Ctx,Viou); | |
691 | Ctx->DisplayActiveAreas(Viou); | |
692 | return 0; | |
693 | } | |
694 | static int VClearAreas (Draw_Interpretor& ,Standard_Integer , const char** ) | |
695 | { | |
696 | Handle(AIS_InteractiveContext) Ctx; | |
697 | Handle(V3d_View) Viou; | |
698 | GetCtxAndView(Ctx,Viou); | |
699 | Ctx->ClearActiveAreas(Viou); | |
700 | return 0; | |
701 | ||
702 | } | |
703 | static int VDispSensi (Draw_Interpretor& ,Standard_Integer , const char** ) | |
704 | { | |
705 | Handle(AIS_InteractiveContext) Ctx; | |
706 | Handle(V3d_View) Viou; | |
707 | GetCtxAndView(Ctx,Viou); | |
708 | Ctx->DisplayActiveSensitive(Viou); | |
709 | return 0; | |
710 | ||
711 | } | |
712 | static int VClearSensi (Draw_Interpretor& ,Standard_Integer , const char** ) | |
713 | { | |
714 | Handle(AIS_InteractiveContext) Ctx; | |
715 | Handle(V3d_View) Viou; | |
716 | GetCtxAndView(Ctx,Viou); | |
717 | Ctx->ClearActiveSensitive(Viou); | |
718 | return 0; | |
719 | } | |
720 | ||
721 | //============================================================================== | |
722 | //function : VDebug | |
723 | //purpose : To list the displayed object with their attributes | |
724 | //Draw arg : No args | |
725 | //============================================================================== | |
726 | static int VDebug(Draw_Interpretor& di, Standard_Integer , const char** ) | |
727 | { if ( !a3DView().IsNull() ) { | |
728 | di << "List of object in the viewer :" << "\n"; | |
729 | ||
730 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS()); | |
731 | ||
732 | while ( it.More() ) { | |
733 | di << "\t" << it.Key2().ToCString() << "\n"; | |
734 | it.Next(); | |
735 | } | |
736 | } | |
737 | ||
738 | return 0; | |
739 | } | |
740 | ||
741 | //============================================================================== | |
742 | //function : VDump | |
743 | //purpose : To dump the active view snapshot to image file | |
744 | //Draw arg : Picture file name with extension corresponding to desired format | |
745 | //============================================================================== | |
746 | static Standard_Integer VDump (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
747 | { | |
748 | if (argc < 2) | |
749 | { | |
750 | di<<"Use: "<<argv[0]<<" <filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n"; | |
751 | return 1; | |
752 | } | |
753 | ||
754 | Image_TypeOfImage aBufferType = Image_TOI_RGB; | |
755 | ||
756 | if (argc > 2) | |
757 | { | |
758 | TCollection_AsciiString aBuffTypeStr (argv[2]); | |
759 | if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgb"))) | |
760 | { | |
761 | aBufferType = Image_TOI_RGB; | |
762 | } | |
763 | else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("rgba"))) | |
764 | { | |
765 | aBufferType = Image_TOI_RGBA; | |
766 | } | |
767 | else if (TCollection_AsciiString::ISSIMILAR (aBuffTypeStr, TCollection_AsciiString ("depth"))) | |
768 | { | |
769 | aBufferType = Image_TOI_FLOAT; | |
770 | } | |
771 | } | |
772 | ||
773 | Standard_Integer aWidth = (argc > 3) ? atoi (argv[3]) : 0; | |
774 | Standard_Integer aHeight = (argc > 4) ? atoi (argv[4]) : 0; | |
775 | ||
776 | Handle(AIS_InteractiveContext) IC; | |
777 | Handle(V3d_View) view; | |
778 | GetCtxAndView (IC, view); | |
779 | if (!view.IsNull()) | |
780 | { | |
781 | if (aWidth > 0 && aHeight > 0) | |
782 | { | |
783 | return view->ToPixMap (aWidth, aHeight, aBufferType)->Dump (argv[1]) ? 0 : 1; | |
784 | } | |
785 | else | |
786 | { | |
787 | return view->Dump (argv[1], aBufferType) ? 0 : 1; | |
788 | } | |
789 | } | |
790 | else | |
791 | { | |
792 | di << "Cannot find an active viewer/view" << "\n"; | |
793 | return 1; | |
794 | } | |
795 | } | |
796 | ||
797 | ||
798 | //============================================================================== | |
799 | //function : Displays,Erase... | |
800 | //purpose : | |
801 | //Draw arg : | |
802 | //============================================================================== | |
803 | static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO, | |
804 | const Standard_Integer Mode, | |
805 | const Standard_Integer TypeOfOperation, | |
806 | const Standard_Boolean Upd) | |
807 | { | |
808 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
809 | ||
810 | switch(TypeOfOperation){ | |
811 | case 1: | |
812 | Ctx->Display(IO,Mode,Upd); | |
813 | break; | |
814 | case 2:{ | |
815 | Ctx->Erase(IO,Mode,Upd); | |
816 | break; | |
817 | } | |
818 | case 3:{ | |
819 | if(IO.IsNull()) | |
820 | Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd); | |
821 | else | |
822 | Ctx->SetDisplayMode(IO,Mode,Upd); | |
823 | break; | |
824 | } | |
825 | case 4:{ | |
826 | if(IO.IsNull()) | |
827 | Ctx->SetDisplayMode(0,Upd); | |
828 | else | |
829 | Ctx->UnsetDisplayMode(IO,Upd); | |
830 | break; | |
831 | } | |
832 | } | |
833 | return 0; | |
834 | } | |
835 | ||
836 | //======================================================================= | |
837 | //function : | |
838 | //purpose : | |
839 | //======================================================================= | |
840 | static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
841 | { | |
842 | ||
843 | TCollection_AsciiString name; | |
844 | if(argc>3) | |
845 | return 1; | |
846 | // display others presentations | |
847 | Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1: | |
848 | (strcasecmp(argv[0],"verasemode")==0) ? 2 : | |
849 | (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 : | |
850 | (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1; | |
851 | ||
852 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
853 | ||
854 | //unset displaymode.. comportement particulier... | |
855 | if(TypeOfOperation==4){ | |
856 | if(argc==1){ | |
857 | if(Ctx->NbCurrents()==0 || | |
858 | Ctx->NbSelected()==0){ | |
859 | Handle(AIS_InteractiveObject) IO; | |
860 | VwrTst_DispErase(IO,-1,4,Standard_False); | |
861 | } | |
862 | else if(!Ctx->HasOpenedContext()){ | |
863 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
864 | VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False); | |
865 | } | |
866 | else{ | |
867 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
868 | VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);} | |
869 | Ctx->UpdateCurrentViewer(); | |
870 | } | |
871 | else{ | |
872 | Handle(AIS_InteractiveObject) IO; | |
873 | name = argv[1]; | |
874 | if(GetMapOfAIS().IsBound2(name)){ | |
875 | IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
876 | if (!IO.IsNull()) | |
877 | VwrTst_DispErase(IO,-1,4,Standard_True); | |
878 | } | |
879 | } | |
880 | } | |
881 | else if(argc==2){ | |
882 | Standard_Integer Dmode = atoi(argv[1]); | |
883 | if(Ctx->NbCurrents()==0 && TypeOfOperation==3){ | |
884 | Handle(AIS_InteractiveObject) IO; | |
885 | VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True); | |
886 | } | |
887 | if(!Ctx->HasOpenedContext()){ | |
888 | // set/unset display mode sur le Contexte... | |
889 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){ | |
890 | VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False); | |
891 | } | |
892 | Ctx->UpdateCurrentViewer(); | |
893 | } | |
894 | else{ | |
895 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
896 | Ctx->Display(Ctx->Interactive(),Dmode); | |
897 | } | |
898 | } | |
899 | else{ | |
900 | Handle(AIS_InteractiveObject) IO; | |
901 | name = argv[1]; | |
902 | if(GetMapOfAIS().IsBound2(name)) | |
903 | IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
904 | if (!IO.IsNull()) | |
905 | VwrTst_DispErase(IO,atoi(argv[2]),TypeOfOperation,Standard_True); | |
906 | } | |
907 | return 0; | |
908 | } | |
909 | ||
910 | ||
911 | //======================================================================= | |
912 | //function : | |
913 | //purpose : | |
914 | //======================================================================= | |
915 | static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
916 | { | |
917 | if(argc==1) return 1; | |
918 | Standard_Integer On = atoi(argv[1]); | |
919 | const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext(); | |
920 | ||
921 | if(argc==2){ | |
922 | ||
923 | if(!Ctx->HasOpenedContext()){ | |
924 | di<<"sub intensite "; | |
925 | if(On==1) di<<"On"; | |
926 | else di<<"Off"; | |
927 | di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n"; | |
928 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){ | |
929 | if(On==1){ | |
930 | Ctx->SubIntensityOn(Ctx->Current(),Standard_False);} | |
931 | else{ | |
932 | di <<"passage dans off"<<"\n"; | |
933 | Ctx->SubIntensityOff(Ctx->Current(),Standard_False); | |
934 | } | |
935 | } | |
936 | } | |
937 | else{ | |
938 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){ | |
939 | if(On==1){ | |
940 | Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);} | |
941 | else{ | |
942 | Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);} | |
943 | } | |
944 | } | |
945 | Ctx->UpdateCurrentViewer(); | |
946 | } | |
947 | else { | |
948 | Handle(AIS_InteractiveObject) IO; | |
949 | TCollection_AsciiString name = argv[2]; | |
950 | if(GetMapOfAIS().IsBound2(name)){ | |
951 | IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
952 | if (!IO.IsNull()) | |
953 | if(On==1) | |
954 | Ctx->SubIntensityOn(IO); | |
955 | else | |
956 | Ctx->SubIntensityOff(IO); | |
957 | ||
958 | } | |
959 | else return 1; | |
960 | } | |
961 | return 0; | |
962 | ||
963 | } | |
964 | //============================================================================== | |
965 | //function : VColor2 | |
966 | //Author : ege | |
967 | //purpose : change the color of a selected or named or displayed shape | |
968 | //Draw arg : vcolor2 [name] color | |
969 | //============================================================================== | |
970 | static int VColor2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
971 | { | |
972 | ||
973 | Standard_Boolean ThereIsCurrent; | |
974 | Standard_Boolean ThereIsArgument; | |
975 | Standard_Boolean IsBound = Standard_False ; | |
7fd59977 | 976 | |
5cbef0fe | 977 | const Standard_Boolean HaveToSet=(strcasecmp( argv[0],"vsetcolor") == 0); |
7fd59977 | 978 | if (HaveToSet) { |
5cbef0fe S |
979 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error: Give 2 or 3 arguments" << "\n"; return 1; } |
980 | ThereIsArgument = (argc != 2); | |
7fd59977 | 981 | } |
982 | else { | |
5cbef0fe S |
983 | if ( argc > 2 ) { di << argv[0] << " syntax error: Given too many arguments" << "\n"; return 1; } |
984 | ThereIsArgument = (argc == 2); | |
7fd59977 | 985 | } |
986 | ||
987 | if ( !a3DView().IsNull() ) { | |
988 | TCollection_AsciiString name; | |
989 | if (ThereIsArgument) { | |
990 | name = argv[1]; | |
991 | IsBound= GetMapOfAIS().IsBound2(name); | |
992 | } | |
993 | if (TheAISContext()->HasOpenedContext()) | |
994 | TheAISContext()->CloseLocalContext(); | |
995 | ||
996 | // On set le Booleen There is current | |
997 | if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; } | |
998 | else ThereIsCurrent =Standard_False; | |
999 | ||
1000 | //======================================================================= | |
1001 | // Il y a un argument | |
1002 | //======================================================================= | |
1003 | if ( ThereIsArgument && IsBound ) { | |
1004 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); | |
1005 | if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1006 | Handle(AIS_InteractiveObject) ashape = | |
1007 | Handle(AIS_InteractiveObject)::DownCast (anObj); | |
1008 | #ifdef DEB | |
7fd59977 | 1009 | if (HaveToSet) |
1010 | di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n"; | |
1011 | else | |
5cbef0fe | 1012 | di << "HaveToSet 0\n"; |
7fd59977 | 1013 | #endif |
1014 | ||
5cbef0fe | 1015 | if(HaveToSet) |
7fd59977 | 1016 | TheAISContext()->SetColor(ashape,GetColorFromName(argv[2]) ); |
7fd59977 | 1017 | else |
1018 | TheAISContext()->UnsetColor(ashape); | |
1019 | } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1020 | Handle(NIS_Triangulated) ashape = | |
1021 | Handle(NIS_Triangulated)::DownCast (anObj); | |
5cbef0fe | 1022 | if (!ashape.IsNull()) |
7fd59977 | 1023 | ashape->SetColor (GetColorFromName(argv[2])); |
1024 | } | |
1025 | } | |
1026 | ||
1027 | ||
1028 | //======================================================================= | |
1029 | // Il n'y a pas d'arguments | |
1030 | // Mais un ou plusieurs objets on des current representation | |
1031 | //======================================================================= | |
1032 | if (ThereIsCurrent && !ThereIsArgument) { | |
1033 | for (TheAISContext() -> InitCurrent() ; | |
1034 | TheAISContext() -> MoreCurrent() ; | |
1035 | TheAISContext() ->NextCurrent() ) | |
1036 | { | |
5cbef0fe | 1037 | const Handle(AIS_InteractiveObject) ashape= TheAISContext()->Current(); |
7fd59977 | 1038 | if (ashape.IsNull()) |
1039 | continue; | |
1040 | #ifdef DEB | |
5cbef0fe S |
1041 | if (HaveToSet) |
1042 | di << "HaveToSet "<< "1" <<" Color Given "<< argv[2] << " Color returned "<< GetColorFromName(argv[2]) << "\n"; | |
1043 | else | |
1044 | di << "HaveToSet 0\n"; | |
7fd59977 | 1045 | #endif |
5cbef0fe S |
1046 | if(HaveToSet) |
1047 | TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False); | |
1048 | else | |
1049 | TheAISContext()->UnsetColor(ashape,Standard_False); | |
7fd59977 | 1050 | } |
1051 | ||
1052 | TheAISContext()->UpdateCurrentViewer(); | |
1053 | } | |
1054 | ||
1055 | //======================================================================= | |
1056 | // Il n'y a pas d'arguments(nom de shape) ET aucun objet courrant | |
1057 | // on impose a tous les objets du viewer la couleur passee | |
1058 | //======================================================================= | |
1059 | else if (!ThereIsCurrent && !ThereIsArgument){ | |
1060 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS()); | |
1061 | while ( it.More() ) { | |
5cbef0fe | 1062 | const Handle(AIS_InteractiveObject) ashape = |
7fd59977 | 1063 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); |
1064 | if (!ashape.IsNull()) | |
1065 | if(HaveToSet) | |
5cbef0fe | 1066 | TheAISContext()->SetColor(ashape,GetColorFromName(argv[1]),Standard_False); |
7fd59977 | 1067 | else |
1068 | TheAISContext()->UnsetColor(ashape,Standard_False); | |
5cbef0fe | 1069 | it.Next(); |
7fd59977 | 1070 | } |
1071 | TheAISContext()->UpdateCurrentViewer(); | |
1072 | } | |
1073 | } | |
1074 | return 0; | |
1075 | } | |
1076 | ||
1077 | //============================================================================== | |
1078 | //function : VTransparency | |
1079 | //Author : ege | |
1080 | //purpose : change the transparency of a selected or named or displayed shape | |
1081 | //Draw arg : vtransparency [name] TransparencyCoeficient | |
1082 | //============================================================================== | |
1083 | ||
7fd59977 | 1084 | static int VTransparency (Draw_Interpretor& di, Standard_Integer argc, |
1085 | const char** argv) | |
1086 | { | |
1087 | Standard_Boolean ThereIsCurrent; | |
1088 | Standard_Boolean ThereIsArgument; | |
1089 | Standard_Boolean IsBound = Standard_False ; | |
7fd59977 | 1090 | |
5cbef0fe | 1091 | const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsettransparency") == 0); |
7fd59977 | 1092 | if (HaveToSet) { |
1093 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } | |
5cbef0fe | 1094 | ThereIsArgument = (argc != 2); |
7fd59977 | 1095 | } |
1096 | else{ | |
1097 | if ( argc > 2 ) { di << argv[0] << " syntax error: Passez au plus un argument" << "\n"; return 1; } | |
5cbef0fe | 1098 | ThereIsArgument = (argc == 2); |
7fd59977 | 1099 | } |
1100 | ||
1101 | if ( !a3DView().IsNull() ) { | |
1102 | TCollection_AsciiString name; | |
1103 | if (ThereIsArgument) { | |
1104 | name = argv[1]; | |
1105 | IsBound= GetMapOfAIS().IsBound2(name); | |
1106 | } | |
1107 | if (TheAISContext()->HasOpenedContext()) | |
1108 | TheAISContext()->CloseLocalContext(); | |
1109 | ||
1110 | if (TheAISContext() -> NbCurrents() > 0 ) {ThereIsCurrent =Standard_True; } | |
1111 | else ThereIsCurrent = Standard_False; | |
1112 | ||
1113 | //======================================================================= | |
1114 | // Il y a des arguments: un nom et une couleur | |
1115 | //======================================================================= | |
1116 | if ( ThereIsArgument && IsBound ) { | |
1117 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); | |
1118 | if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1119 | const Handle(AIS_InteractiveObject) ashape = | |
1120 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
1121 | if(HaveToSet) | |
1122 | TheAISContext()->SetTransparency(ashape,atof(argv[2]) ); | |
1123 | else | |
1124 | TheAISContext()->UnsetTransparency(ashape); | |
5cbef0fe | 1125 | } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { |
7fd59977 | 1126 | const Handle(NIS_InteractiveObject) ashape = |
1127 | Handle(NIS_InteractiveObject)::DownCast(anObj); | |
1128 | if(HaveToSet) | |
1129 | ashape->SetTransparency(atof(argv[2]) ); | |
1130 | else | |
1131 | ashape->UnsetTransparency(); | |
1132 | } | |
1133 | } | |
1134 | //======================================================================= | |
1135 | // Il n'y a pas d'arguments | |
1136 | // Mais un ou plusieurs objets on des current representation | |
1137 | //======================================================================= | |
1138 | if (ThereIsCurrent && !ThereIsArgument) { | |
1139 | for (TheAISContext() -> InitCurrent() ; | |
1140 | TheAISContext() -> MoreCurrent() ; | |
1141 | TheAISContext() ->NextCurrent() ) | |
1142 | { | |
5cbef0fe S |
1143 | Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current(); |
1144 | if(HaveToSet) | |
1145 | TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False); | |
1146 | else | |
1147 | TheAISContext()->UnsetTransparency(ashape,Standard_False); | |
7fd59977 | 1148 | } |
1149 | ||
1150 | TheAISContext()->UpdateCurrentViewer(); | |
1151 | } | |
1152 | //======================================================================= | |
1153 | // Il n'y a pas d'arguments ET aucun objet courrant | |
1154 | //======================================================================= | |
1155 | else if ( !ThereIsCurrent && !ThereIsArgument ) { | |
1156 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1157 | it(GetMapOfAIS()); | |
1158 | while ( it.More() ) { | |
5cbef0fe | 1159 | Handle(AIS_InteractiveObject) ashape = |
7fd59977 | 1160 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); |
1161 | if (!ashape.IsNull()) | |
1162 | if(HaveToSet) | |
5cbef0fe | 1163 | TheAISContext()->SetTransparency(ashape,atof(argv[1]),Standard_False); |
7fd59977 | 1164 | else |
1165 | TheAISContext()->UnsetTransparency(ashape,Standard_False); | |
5cbef0fe | 1166 | it.Next(); |
7fd59977 | 1167 | } |
1168 | TheAISContext()->UpdateCurrentViewer(); | |
1169 | } | |
1170 | } | |
1171 | return 0; | |
1172 | } | |
1173 | ||
1174 | ||
1175 | //============================================================================== | |
1176 | //function : VMaterial | |
1177 | //Author : ege | |
1178 | //purpose : change the Material of a selected or named or displayed shape | |
1179 | //Draw arg : vmaterial [Name] Material | |
1180 | //============================================================================== | |
1181 | static int VMaterial (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1182 | { | |
1183 | ||
1184 | Standard_Boolean ThereIsCurrent; | |
1185 | Standard_Boolean ThereIsName; | |
1186 | Standard_Boolean IsBound = Standard_False ; | |
1187 | ||
5cbef0fe | 1188 | const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetmaterial") == 0); |
7fd59977 | 1189 | if (HaveToSet) { |
1190 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } | |
5cbef0fe | 1191 | ThereIsName = (argc != 2); |
7fd59977 | 1192 | } |
1193 | else { | |
1194 | if ( argc>2 ) { di << argv[0] << " syntax error passez au plus un argument" << "\n"; return 1; } | |
5cbef0fe | 1195 | ThereIsName = (argc == 2); |
7fd59977 | 1196 | } |
1197 | ||
1198 | if ( !a3DView().IsNull() ) { | |
1199 | TCollection_AsciiString name; | |
1200 | if (ThereIsName) { | |
1201 | name = argv[1]; | |
1202 | IsBound= GetMapOfAIS().IsBound2(name); | |
1203 | } | |
1204 | if (TheAISContext()->HasOpenedContext()) | |
1205 | TheAISContext()->CloseLocalContext(); | |
1206 | if (TheAISContext() -> NbCurrents() > 0 ) | |
1207 | ThereIsCurrent =Standard_True; | |
1208 | else | |
1209 | ThereIsCurrent =Standard_False; | |
1210 | ||
1211 | //======================================================================= | |
1212 | // Ther is a name of shape and a material name | |
1213 | //======================================================================= | |
1214 | if ( ThereIsName && IsBound ) { | |
1215 | Handle(AIS_InteractiveObject) ashape = | |
1216 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(name)); | |
1217 | if (!ashape.IsNull()) | |
1218 | if (HaveToSet) | |
5cbef0fe | 1219 | TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[2])); |
7fd59977 | 1220 | else |
1221 | TheAISContext()->UnsetMaterial(ashape); | |
1222 | } | |
1223 | //======================================================================= | |
1224 | // Il n'y a pas de nom de shape | |
1225 | // Mais un ou plusieurs objets on des current representation | |
1226 | //======================================================================= | |
1227 | if (ThereIsCurrent && !ThereIsName) { | |
1228 | for (TheAISContext() -> InitCurrent() ; | |
1229 | TheAISContext() -> MoreCurrent() ; | |
1230 | TheAISContext() ->NextCurrent() ) | |
1231 | { | |
5cbef0fe S |
1232 | Handle(AIS_InteractiveObject) ashape = TheAISContext()->Current(); |
1233 | if (HaveToSet) | |
1234 | TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False); | |
1235 | else | |
1236 | TheAISContext()->UnsetMaterial(ashape,Standard_False); | |
7fd59977 | 1237 | } |
1238 | TheAISContext()->UpdateCurrentViewer(); | |
1239 | } | |
1240 | ||
1241 | //======================================================================= | |
1242 | // Il n'y a pas de noms de shape ET aucun objet courrant | |
1243 | // On impose a tous les objets du viewer le material passe en argument | |
1244 | //======================================================================= | |
1245 | else if (!ThereIsCurrent && !ThereIsName){ | |
1246 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1247 | it(GetMapOfAIS()); | |
1248 | while ( it.More() ) { | |
5cbef0fe | 1249 | Handle(AIS_InteractiveObject) ashape = |
7fd59977 | 1250 | Handle(AIS_InteractiveObject)::DownCast (it.Key1()); |
5cbef0fe | 1251 | if (!ashape.IsNull()) |
7fd59977 | 1252 | if (HaveToSet) |
5cbef0fe | 1253 | TheAISContext()->SetMaterial(ashape,GetMaterialFromName(argv[1]),Standard_False); |
7fd59977 | 1254 | else |
1255 | TheAISContext()->UnsetMaterial(ashape,Standard_False); | |
5cbef0fe | 1256 | it.Next(); |
7fd59977 | 1257 | } |
1258 | TheAISContext()->UpdateCurrentViewer(); | |
1259 | } | |
1260 | } | |
1261 | return 0; | |
1262 | } | |
1263 | ||
1264 | ||
1265 | ||
1266 | //============================================================================== | |
1267 | //function : VWidth | |
1268 | //Author : ege | |
1269 | //purpose : change the width of the edges of a selected or named or displayed shape | |
1270 | //Draw arg : vwidth [Name] WidthValue(1->10) | |
1271 | //============================================================================== | |
1272 | static int VWidth (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1273 | { | |
1274 | ||
1275 | Standard_Boolean ThereIsCurrent; | |
1276 | Standard_Boolean ThereIsArgument; | |
1277 | Standard_Boolean IsBound = Standard_False ; | |
1278 | ||
5cbef0fe | 1279 | const Standard_Boolean HaveToSet = (strcasecmp( argv[0],"vsetwidth") == 0); |
7fd59977 | 1280 | if (HaveToSet) { |
1281 | if ( argc < 2 || argc > 3 ) { di << argv[0] << " syntax error passez 1 ou 2 arguments" << "\n"; return 1; } | |
5cbef0fe | 1282 | ThereIsArgument = (argc != 2); |
7fd59977 | 1283 | } |
1284 | else { | |
1285 | if ( argc>2 ) { di << argv[0] << " syntax error passez au plus 1 argument" << "\n"; return 1; } | |
5cbef0fe | 1286 | ThereIsArgument = (argc == 2); |
7fd59977 | 1287 | } |
1288 | if ( !a3DView().IsNull() ) { | |
1289 | TCollection_AsciiString name; | |
1290 | if (ThereIsArgument) { | |
1291 | name = argv[1]; | |
1292 | IsBound= GetMapOfAIS().IsBound2(name); | |
1293 | } | |
1294 | if (TheAISContext()->HasOpenedContext()) | |
1295 | TheAISContext()->CloseLocalContext(); | |
1296 | ||
1297 | if (TheAISContext() -> NbCurrents() > 0 ) | |
1298 | ThereIsCurrent =Standard_True; | |
1299 | else | |
1300 | ThereIsCurrent =Standard_False; | |
1301 | ||
1302 | if ( ThereIsArgument && IsBound ) { | |
1303 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); | |
1304 | if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1305 | const Handle(AIS_InteractiveObject) ashape = | |
1306 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
1307 | if (HaveToSet) | |
1308 | TheAISContext()->SetWidth ( ashape,atof (argv[2]) ); | |
1309 | else | |
1310 | TheAISContext()->UnsetWidth (ashape); | |
1311 | } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1312 | const Handle(NIS_Triangulated) ashape = | |
1313 | Handle(NIS_Triangulated)::DownCast(GetMapOfAIS().Find2(name)); | |
1314 | if (HaveToSet && !ashape.IsNull()) | |
1315 | ashape->SetLineWidth ( atof (argv[2]) ); | |
1316 | } | |
1317 | } | |
1318 | ||
1319 | //======================================================================= | |
1320 | // Il n'y a pas d'arguments | |
1321 | // Mais un ou plusieurs objets on des current representation | |
1322 | //======================================================================= | |
1323 | if (ThereIsCurrent && !ThereIsArgument) { | |
1324 | for (TheAISContext() -> InitCurrent() ; | |
1325 | TheAISContext() -> MoreCurrent() ; | |
1326 | TheAISContext() ->NextCurrent() ) | |
1327 | { | |
5cbef0fe S |
1328 | Handle(AIS_InteractiveObject) ashape = TheAISContext() -> Current(); |
1329 | if (HaveToSet) | |
1330 | TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False); | |
1331 | else | |
1332 | TheAISContext()->UnsetWidth(ashape,Standard_False); | |
7fd59977 | 1333 | } |
1334 | TheAISContext()->UpdateCurrentViewer(); | |
1335 | } | |
1336 | //======================================================================= | |
1337 | // Il n'y a pas d'arguments ET aucun objet courrant | |
1338 | //======================================================================= | |
1339 | else if (!ThereIsCurrent && !ThereIsArgument){ | |
1340 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1341 | it(GetMapOfAIS()); | |
1342 | while ( it.More() ) { | |
1343 | Handle(AIS_InteractiveObject) ashape = | |
1344 | Handle(AIS_InteractiveObject)::DownCast (it.Key1()); | |
1345 | if (!ashape.IsNull()) | |
1346 | if (HaveToSet) | |
5cbef0fe | 1347 | TheAISContext()->SetWidth(ashape,atof(argv[1]),Standard_False); |
7fd59977 | 1348 | else |
5cbef0fe | 1349 | TheAISContext()->UnsetWidth(ashape,Standard_False); |
7fd59977 | 1350 | it.Next(); |
1351 | } | |
1352 | TheAISContext()->UpdateCurrentViewer(); | |
1353 | } | |
1354 | } | |
1355 | return 0; | |
1356 | } | |
1357 | //============================================================================== | |
1358 | //function : VDonly2 | |
1359 | //author : ege | |
1360 | //purpose : Display only a selected or named object | |
1361 | // if there is no selected or named object s, nothing is donne | |
1362 | //Draw arg : vdonly2 [name1] ... [name n] | |
1363 | //============================================================================== | |
1364 | static int VDonly2(Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
1365 | ||
1366 | { | |
1367 | if ( a3DView().IsNull() ) | |
1368 | return 1; | |
1369 | ||
1370 | Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0; | |
1371 | Standard_Boolean ThereIsArgument= argc>1; | |
1372 | ||
1373 | if (TheAISContext()->HasOpenedContext()) | |
1374 | TheAISContext()->CloseLocalContext(); | |
1375 | ||
1376 | //=============================================================== | |
1377 | // Il n'y a pas d'arguments mais des objets selectionnes(current) | |
1378 | // dans le viewer | |
1379 | //=============================================================== | |
1380 | if (!ThereIsArgument && ThereIsCurrent) { | |
1381 | ||
1382 | #ifdef DEB | |
1383 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1384 | it (GetMapOfAIS()); | |
1385 | #endif | |
1386 | for(TheAISContext()->InitCurrent(); | |
1387 | TheAISContext()->MoreCurrent(); | |
1388 | TheAISContext()->NextCurrent()){ | |
1389 | Handle(AIS_InteractiveObject) aShape = TheAISContext()->Current(); | |
1390 | TheAISContext()->Erase(aShape,Standard_False);} | |
1391 | } | |
1392 | TheAISContext() ->UpdateCurrentViewer(); | |
1393 | //=============================================================== | |
1394 | // Il y a des arguments | |
1395 | //=============================================================== | |
1396 | if (ThereIsArgument) { | |
1397 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1398 | it (GetMapOfAIS()); | |
1399 | while ( it.More() ) { | |
1400 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1401 | const Handle(AIS_InteractiveObject) aShape = | |
1402 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
1403 | TheAISContext()->Erase(aShape,Standard_False); | |
1404 | } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1405 | const Handle(NIS_InteractiveObject) aShape = | |
1406 | Handle(NIS_InteractiveObject)::DownCast(it.Key1()); | |
ffe2bea7 | 1407 | TheNISContext()->Erase(aShape); |
7fd59977 | 1408 | } |
1409 | it.Next(); | |
1410 | } | |
1411 | ||
1412 | // On display les objets passes par parametre | |
1413 | for (int i=1; i<argc ; i++) { | |
1414 | TCollection_AsciiString name=argv[i]; | |
1415 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name); | |
1416 | if (IsBound) { | |
1417 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); | |
1418 | if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1419 | const Handle(AIS_InteractiveObject) aShape = | |
1420 | Handle(AIS_InteractiveObject)::DownCast (anObj); | |
1421 | TheAISContext()->Display(aShape, Standard_False); | |
1422 | } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
ffe2bea7 | 1423 | Handle(NIS_InteractiveObject) aShape = |
7fd59977 | 1424 | Handle(NIS_InteractiveObject)::DownCast (anObj); |
ffe2bea7 | 1425 | TheNISContext()->Display(aShape); |
7fd59977 | 1426 | } |
1427 | } | |
1428 | } | |
1429 | TheAISContext() ->UpdateCurrentViewer(); | |
ffe2bea7 | 1430 | // TheNISContext() ->UpdateViews(); |
7fd59977 | 1431 | } |
1432 | return 0; | |
1433 | } | |
1434 | ||
1435 | //============================================================================== | |
1436 | //function : VErase2 | |
1437 | //author : ege | |
1438 | //purpose : Erase some selected or named objects | |
1439 | // if there is no selected or named objects, the whole viewer is erased | |
1440 | //Draw arg : verase2 [name1] ... [name n] | |
1441 | //============================================================================== | |
1442 | static int VErase2(Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
1443 | ||
1444 | { | |
1445 | if ( a3DView().IsNull() ) | |
1446 | return 1; | |
1447 | ||
1448 | Standard_Boolean ThereIsCurrent = TheAISContext() -> NbCurrents() > 0; | |
1449 | Standard_Boolean ThereIsArgument= argc>1; | |
1450 | if(TheAISContext()->HasOpenedContext()) | |
1451 | TheAISContext()->CloseLocalContext(); | |
1452 | ||
1453 | //=============================================================== | |
1454 | // Il n'y a pas d'arguments mais des objets selectionnes(current) | |
1455 | // dans le viewer | |
1456 | //=============================================================== | |
1457 | if (!ThereIsArgument && ThereIsCurrent) { | |
1458 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1459 | it (GetMapOfAIS()); | |
1460 | while ( it.More() ) { | |
1461 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1462 | const Handle(AIS_InteractiveObject) aShape = | |
1463 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
1464 | if (TheAISContext()->IsCurrent(aShape)) | |
1465 | TheAISContext()->Erase(aShape,Standard_False); | |
1466 | } | |
1467 | it.Next(); | |
1468 | } | |
1469 | ||
1470 | TheAISContext() ->UpdateCurrentViewer(); | |
1471 | } | |
1472 | ||
1473 | //=============================================================== | |
1474 | // Il n'y a pas d'arguments et aucuns objets selectionnes | |
1475 | // dans le viewer: | |
1476 | // On erase tout le viewer | |
1477 | //=============================================================== | |
1478 | ||
1479 | if (!ThereIsArgument && !ThereIsCurrent) { | |
1480 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS()); | |
1481 | while ( it.More() ) { | |
1482 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1483 | const Handle(AIS_InteractiveObject) aShape = | |
1484 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
1485 | TheAISContext()->Erase(aShape,Standard_False); | |
1486 | } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1487 | const Handle(NIS_InteractiveObject) aShape = | |
1488 | Handle(NIS_InteractiveObject)::DownCast(it.Key1()); | |
ffe2bea7 | 1489 | TheNISContext()->Erase(aShape); |
7fd59977 | 1490 | } |
1491 | it.Next(); | |
1492 | } | |
1493 | TheAISContext() ->UpdateCurrentViewer(); | |
ffe2bea7 | 1494 | // TheNISContext()->UpdateViews(); |
7fd59977 | 1495 | } |
1496 | ||
1497 | //=============================================================== | |
1498 | // Il y a des arguments | |
1499 | //=============================================================== | |
1500 | if (ThereIsArgument) { | |
1501 | for (int i=1; i<argc ; i++) { | |
1502 | TCollection_AsciiString name=argv[i]; | |
1503 | Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name); | |
1504 | if (IsBound) { | |
1505 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); | |
1506 | if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1507 | const Handle(AIS_InteractiveObject) aShape = | |
1508 | Handle(AIS_InteractiveObject)::DownCast (anObj); | |
1509 | TheAISContext()->Erase(aShape,Standard_False); | |
1510 | } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1511 | const Handle(NIS_InteractiveObject) aShape = | |
1512 | Handle(NIS_InteractiveObject)::DownCast (anObj); | |
ffe2bea7 | 1513 | TheNISContext()->Erase(aShape); |
7fd59977 | 1514 | } |
1515 | } | |
1516 | } | |
1517 | TheAISContext() ->UpdateCurrentViewer(); | |
ffe2bea7 | 1518 | // TheNISContext() ->UpdateViews(); |
7fd59977 | 1519 | } |
1520 | return 0; | |
1521 | } | |
1522 | ||
1523 | //============================================================================== | |
1524 | //function : VEraseAll | |
1525 | //author : ege | |
1526 | //purpose : Erase all the objects displayed in the viewer | |
1527 | //Draw arg : veraseall | |
1528 | //============================================================================== | |
1529 | static int VEraseAll(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1530 | ||
1531 | { | |
1532 | // Verification des arguments | |
1533 | if (argc>1){ di<<" Syntaxe error: "<<argv[0]<<" too much arguments."<<"\n";return 1;} | |
1534 | if (a3DView().IsNull() ) {di<<" Error: vinit hasn't been called."<<"\n";return 1;} | |
1535 | TheAISContext()->CloseAllContexts(Standard_False); | |
1536 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1537 | it(GetMapOfAIS()); | |
1538 | while ( it.More() ) { | |
1539 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1540 | const Handle(AIS_InteractiveObject) aShape = | |
1541 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
1542 | TheAISContext()->Erase(aShape,Standard_False); | |
1543 | } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1544 | const Handle(NIS_InteractiveObject) aShape = | |
1545 | Handle(NIS_InteractiveObject)::DownCast(it.Key1()); | |
ffe2bea7 | 1546 | TheNISContext()->Erase(aShape); |
7fd59977 | 1547 | } |
1548 | it.Next(); | |
1549 | } | |
1550 | TheAISContext() ->UpdateCurrentViewer(); | |
ffe2bea7 | 1551 | // TheNISContext() ->UpdateViews(); |
7fd59977 | 1552 | return 0; |
1553 | } | |
1554 | ||
1555 | ||
1556 | //============================================================================== | |
1557 | //function : VDisplayAll | |
1558 | //author : ege | |
1559 | //purpose : Display all the objects of the Map | |
1560 | //Draw arg : vdisplayall | |
1561 | //============================================================================== | |
1562 | static int VDisplayAll( Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1563 | ||
1564 | { | |
1565 | if (! a3DView().IsNull() ) { | |
1566 | if (argc > 1) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
1567 | if (TheAISContext()->HasOpenedContext()) | |
1568 | TheAISContext()->CloseLocalContext(); | |
1569 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
1570 | it (GetMapOfAIS()); | |
1571 | while ( it.More() ) { | |
1572 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1573 | const Handle(AIS_InteractiveObject) aShape = | |
1574 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
1575 | TheAISContext()->Erase(aShape,Standard_False); | |
1576 | } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1577 | const Handle(NIS_InteractiveObject) aShape = | |
1578 | Handle(NIS_InteractiveObject)::DownCast(it.Key1()); | |
ffe2bea7 | 1579 | TheNISContext()->Erase(aShape); |
7fd59977 | 1580 | } |
1581 | it.Next(); | |
1582 | } | |
1583 | it.Reset(); | |
1584 | while ( it.More() ) { | |
1585 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1586 | const Handle(AIS_InteractiveObject) aShape = | |
1587 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
1588 | TheAISContext()->Display(aShape, Standard_False); | |
1589 | } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
ffe2bea7 | 1590 | Handle(NIS_InteractiveObject) aShape = |
7fd59977 | 1591 | Handle(NIS_InteractiveObject)::DownCast(it.Key1()); |
ffe2bea7 | 1592 | TheNISContext()->Display(aShape); |
7fd59977 | 1593 | } |
1594 | it.Next(); | |
1595 | } | |
1596 | TheAISContext() ->UpdateCurrentViewer(); | |
ffe2bea7 | 1597 | // TheNISContext() ->UpdateViews(); |
7fd59977 | 1598 | } |
1599 | return 0; | |
1600 | } | |
1601 | ||
1602 | ||
1603 | //####################################################################################################### | |
1604 | ||
1605 | ||
1606 | static TCollection_AsciiString GetEnvir (Draw_Interpretor& di) { | |
1607 | ||
1608 | static Standard_Boolean IsDefined=Standard_False ; | |
1609 | static TCollection_AsciiString VarName; | |
1610 | if ( !IsDefined ) { | |
1611 | const char *envir, *casroot ; | |
1612 | envir = getenv("CSF_MDTVTexturesDirectory") ; | |
1613 | ||
1614 | Standard_Boolean HasDefinition = Standard_False ; | |
1615 | if ( !envir ) { | |
1616 | casroot = getenv("CASROOT"); | |
1617 | if ( casroot ) { | |
1618 | VarName = TCollection_AsciiString (casroot); | |
1619 | VarName += "/src/Textures" ; | |
1620 | HasDefinition = Standard_True ; | |
1621 | } | |
1622 | } else { | |
1623 | VarName = TCollection_AsciiString (envir); | |
1624 | HasDefinition = Standard_True ; | |
1625 | } | |
1626 | if ( HasDefinition ) { | |
1627 | OSD_Path aPath ( VarName ); | |
1628 | OSD_Directory aDir(aPath); | |
1629 | if ( aDir.Exists () ) { | |
1630 | TCollection_AsciiString aTexture = VarName + "/2d_MatraDatavision.rgb" ; | |
1631 | OSD_File TextureFile ( aTexture ); | |
1632 | if ( !TextureFile.Exists() ) { | |
1633 | di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n"; | |
1634 | di << " not all files are found in : "<<VarName.ToCString() << "\n"; | |
1635 | Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " ); | |
1636 | } | |
1637 | } else { | |
1638 | di << " CSF_MDTVTexturesDirectory or CASROOT not correctly setted " << "\n"; | |
1639 | di << " Directory : "<< VarName.ToCString() << " not exist " << "\n"; | |
1640 | Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory or CASROOT not correctly setted " ); | |
1641 | } | |
1642 | return VarName ; | |
1643 | } else { | |
1644 | di << " CSF_MDTVTexturesDirectory and CASROOT not setted " << "\n"; | |
1645 | di << " one of these variable are mandatory to use this fonctionnality" << "\n"; | |
1646 | Standard_Failure::Raise ( "CSF_MDTVTexturesDirectory and CASROOT not setted " ); | |
1647 | } | |
1648 | IsDefined = Standard_True ; | |
1649 | } | |
1650 | return VarName ; | |
1651 | ||
1652 | } | |
1653 | ||
1654 | //####################################################################################################### | |
1655 | ||
1656 | ||
1657 | //####################################################################################################### | |
1658 | ||
1659 | //## VTexture | |
1660 | ||
1661 | //####################################################################################################### | |
1662 | ||
1663 | Standard_Integer VTexture (Draw_Interpretor& di,Standard_Integer argc, const char** argv ) | |
1664 | { | |
1665 | Standard_Integer command = (strcasecmp(argv[0],"vtexture")==0)? 1: | |
1666 | (strcasecmp(argv[0],"vtexscale")==0) ? 2 : | |
1667 | (strcasecmp(argv[0],"vtexorigin")==0) ? 3 : | |
1668 | (strcasecmp(argv[0],"vtexrepeat")==0) ? 4 : | |
1669 | (strcasecmp(argv[0],"vtexdefault")==0) ? 5 : -1; | |
1670 | ||
1671 | Handle(AIS_InteractiveContext) myAISContext = ViewerTest::GetAISContext(); | |
1672 | if(myAISContext.IsNull()) | |
1673 | { | |
1674 | di << "use 'vinit' command before " << argv[0] << "\n"; | |
31160f80 | 1675 | return 1; |
7fd59977 | 1676 | } |
1677 | ||
1678 | Handle(AIS_InteractiveObject) TheAisIO; | |
1679 | Handle(AIS_TexturedShape) myShape; | |
1680 | Standard_Integer myPreviousMode = 0; | |
1681 | ||
31160f80 | 1682 | if (argc<2 || !argv[1]) |
7fd59977 | 1683 | { |
1684 | di << argv[0] <<" syntax error - Type 'help vtex'"<<"\n"; | |
31160f80 | 1685 | return 1; |
7fd59977 | 1686 | } |
1687 | ||
1688 | TCollection_AsciiString name = argv[1]; | |
1689 | ViewerTest::CurrentView()->SetSurfaceDetail(V3d_TEX_ALL); | |
1690 | ||
1691 | if (GetMapOfAIS().IsBound2(name)) | |
1692 | TheAisIO = Handle(AIS_InteractiveObject)::DownCast | |
1693 | (GetMapOfAIS().Find2(name)); | |
1694 | if (TheAisIO.IsNull()) | |
1695 | { | |
1696 | di <<"shape "<<name.ToCString()<<" doesn\'t exist"<<"\n"; | |
31160f80 | 1697 | return 1; |
7fd59977 | 1698 | } |
1699 | ||
1700 | if (TheAisIO->IsKind(STANDARD_TYPE(AIS_TexturedShape)) && !TheAisIO.IsNull()) | |
1701 | { | |
1702 | myShape = Handle(AIS_TexturedShape)::DownCast(TheAisIO); | |
1703 | myPreviousMode = myShape->DisplayMode() ; | |
1704 | } | |
1705 | else | |
1706 | { | |
31160f80 | 1707 | myAISContext->Clear(TheAisIO,Standard_False); |
7fd59977 | 1708 | myShape = new AIS_TexturedShape (DBRep::Get(argv[1])); |
1709 | GetMapOfAIS().UnBind1(TheAisIO); | |
1710 | GetMapOfAIS().UnBind2(name); | |
1711 | GetMapOfAIS().Bind(myShape, name); | |
1712 | } | |
1713 | switch (command) | |
1714 | { | |
1715 | case 1: // vtexture : we only map a texture on the shape | |
1716 | if(argc<=1) | |
1717 | { | |
1718 | di << argv[0] <<" syntax error - Type 'help vtex'" << "\n"; | |
31160f80 | 1719 | return 1; |
7fd59977 | 1720 | } |
31160f80 | 1721 | if (argc>2 && argv[2]) |
7fd59977 | 1722 | { |
1723 | if(strcasecmp(argv[2],"?")==0) | |
1724 | { | |
1725 | TCollection_AsciiString monPath = GetEnvir (di) ; | |
1726 | ||
1727 | di<<"\n Files in current directory : \n"<<"\n"; | |
1728 | TCollection_AsciiString Cmnd ("glob -nocomplain *"); | |
1729 | di.Eval(Cmnd.ToCString()); | |
1730 | ||
1731 | Cmnd = TCollection_AsciiString("glob -nocomplain ") ; | |
1732 | Cmnd += monPath ; | |
1733 | Cmnd += "/* " ; | |
1734 | di<<"Files in "<<monPath.ToCString()<<" : \n"<<"\n"; | |
1735 | di.Eval(Cmnd.ToCString()); | |
1736 | ||
1737 | return 0; | |
1738 | } | |
1739 | else | |
1740 | myShape->SetTextureFileName(argv[2]); | |
1741 | } | |
1742 | else | |
1743 | { | |
1744 | di <<"Texture mapping disabled \n \ | |
1745 | To enable it, use 'vtexture NameOfShape NameOfTexture' \n"<<"\n"; | |
1746 | ||
1747 | myAISContext->SetDisplayMode(myShape,1,Standard_False); | |
1748 | if (myPreviousMode == 3 ) | |
1749 | myAISContext->RecomputePrsOnly(myShape); | |
1750 | myAISContext->Display(myShape, Standard_True); | |
1751 | return 0; | |
1752 | } | |
1753 | break; | |
1754 | ||
1755 | case 2: // vtexscale : we change the scaling factor of the texture | |
1756 | ||
1757 | if(argc<2) | |
1758 | { | |
1759 | di << argv[0] <<" syntax error - Type 'help vtex'" << "\n"; | |
31160f80 | 1760 | return 1; |
7fd59977 | 1761 | } |
1762 | ||
1763 | myShape->SetTextureScale (( argv[2] ? Standard_True : Standard_False ), | |
1764 | ( argv[2] ? atof(argv[2]) : 1.0 ), | |
1765 | ( argv[2] ? atof(argv[argc-1]) : 1.0 ) ); | |
1766 | break; | |
1767 | ||
1768 | case 3: // vtexorigin : we change the origin of the texture on the shape | |
1769 | if(argc<2) | |
1770 | { | |
1771 | di << argv[0] <<" syntax error - Type 'help vtex'" << "\n"; | |
31160f80 | 1772 | return 1; |
7fd59977 | 1773 | } |
1774 | myShape->SetTextureOrigin (( argv[2] ? Standard_True : Standard_False ), | |
1775 | ( argv[2] ? atof(argv[2]) : 0.0 ), | |
1776 | ( argv[2] ? atof(argv[argc-1]) : 0.0 )); | |
1777 | break; | |
1778 | ||
1779 | case 4: // vtexrepeat : we change the number of occurences of the texture on the shape | |
1780 | if(argc<2) | |
1781 | { | |
1782 | di << argv[0] <<" syntax error - Type 'help vtex'" << "\n"; | |
31160f80 | 1783 | return 1; |
7fd59977 | 1784 | } |
31160f80 | 1785 | if (argc>2 && argv[2]) |
7fd59977 | 1786 | { |
1787 | di <<"Texture repeat enabled"<<"\n"; | |
1788 | myShape->SetTextureRepeat(Standard_True, atof(argv[2]), atof(argv[argc-1]) ); | |
1789 | } | |
1790 | else | |
1791 | { | |
1792 | di <<"Texture repeat disabled"<<"\n"; | |
1793 | myShape->SetTextureRepeat(Standard_False); | |
1794 | } | |
1795 | break; | |
1796 | ||
1797 | case 5: // vtexdefault : default texture mapping | |
1798 | // ScaleU = ScaleV = 100.0 | |
1799 | // URepeat = VRepeat = 1.0 | |
1800 | // Uorigin = VOrigin = 0.0 | |
1801 | ||
1802 | if(argc<2) | |
1803 | { | |
1804 | di << argv[0] <<" syntax error - Type 'help vtex'" << "\n"; | |
31160f80 | 1805 | return 1; |
7fd59977 | 1806 | } |
1807 | myShape->SetTextureRepeat(Standard_False); | |
1808 | myShape->SetTextureOrigin(Standard_False); | |
1809 | myShape->SetTextureScale (Standard_False); | |
1810 | break; | |
1811 | } | |
1812 | ||
1813 | if ((myShape->DisplayMode() == 3) || (myPreviousMode == 3 )) | |
1814 | myAISContext->RecomputePrsOnly(myShape); | |
1815 | else | |
1816 | { | |
1817 | myAISContext->SetDisplayMode(myShape,3,Standard_False); | |
1818 | myAISContext->Display(myShape, Standard_True); | |
1819 | myAISContext->Update(myShape,Standard_True); | |
1820 | } | |
31160f80 | 1821 | return 0; |
7fd59977 | 1822 | } |
1823 | ||
1824 | //============================================================================== | |
1825 | //function : VDisplay2 | |
1826 | //author : ege | |
1827 | //purpose : Display an object from its name | |
1828 | //Draw arg : vdisplay name1 [name2] ... [name n] | |
1829 | //============================================================================== | |
1830 | static int VDisplay2 (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1831 | ||
1832 | { | |
1833 | // Verification des arguments | |
1834 | if ( a3DView().IsNull() ) { | |
1835 | ||
1836 | ViewerTest::ViewerInit(); | |
1837 | di<<"La commande vinit n'a pas ete appele avant"<<"\n"; | |
1838 | // return 1; | |
1839 | } | |
1840 | ||
1841 | if ( argc<2) { | |
1842 | di<<argv[0]<<" Syntaxe error"<<"\n"; | |
1843 | return 1; | |
1844 | } | |
1845 | ||
1846 | ||
1847 | TCollection_AsciiString name; | |
1848 | if (TheAISContext()->HasOpenedContext()) | |
1849 | TheAISContext()->CloseLocalContext(); | |
1850 | ||
1851 | for ( int i = 1; i < argc; i++ ) { | |
1852 | name = argv[i]; | |
1853 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name); | |
1854 | Standard_Boolean IsDatum = Standard_False; | |
1855 | Handle(Standard_Transient) anObj; | |
1856 | if ( IsBound ) { | |
1857 | anObj = GetMapOfAIS().Find2(name); | |
1858 | if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
1859 | Handle(AIS_InteractiveObject) aShape = | |
1860 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
1861 | if (aShape->Type()==AIS_KOI_Datum) { | |
1862 | IsDatum = Standard_True; | |
1863 | TheAISContext()->Display(aShape, Standard_False); | |
1864 | } | |
1865 | if (!IsDatum) { | |
1866 | di << "Display " << name.ToCString() << "\n"; | |
1867 | // Get the Shape from a name | |
1868 | TopoDS_Shape NewShape = GetShapeFromName((const char *)name.ToCString()); | |
1869 | ||
1870 | // Update the Shape in the AIS_Shape | |
1871 | Handle(AIS_Shape) TheRealSh = Handle(AIS_Shape)::DownCast(aShape); | |
1872 | if(!TheRealSh.IsNull()) | |
1873 | TheRealSh->Set(NewShape); | |
1874 | TheAISContext()->Redisplay(aShape, Standard_False); | |
1875 | TheAISContext()->Display(aShape, Standard_False); | |
1876 | } | |
1877 | aShape.Nullify(); | |
1878 | } else if (anObj->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
1879 | Handle(NIS_InteractiveObject) aShape = | |
1880 | Handle(NIS_InteractiveObject)::DownCast(anObj); | |
ffe2bea7 | 1881 | TheNISContext()->Display(aShape); |
7fd59977 | 1882 | } |
1883 | } | |
1884 | else { // Create the AIS_Shape from a name | |
1885 | const Handle(AIS_InteractiveObject) aShape = | |
1886 | GetAISShapeFromName((const char *)name.ToCString()); | |
1887 | if ( !aShape.IsNull() ) { | |
1888 | GetMapOfAIS().Bind(aShape, name); | |
1889 | TheAISContext()->Display(aShape, Standard_False); | |
1890 | } | |
1891 | } | |
1892 | } | |
1893 | // Upadate the screen and redraw the view | |
1894 | TheAISContext()->UpdateCurrentViewer(); | |
ffe2bea7 | 1895 | // TheNISContext()->UpdateViews(); |
7fd59977 | 1896 | return 0; |
1897 | } | |
1898 | ||
1899 | //============================================================================== | |
1900 | //function : VMoveA | |
1901 | //purpose : Test the annimation of an object along a | |
1902 | // predifined trajectory | |
1903 | //Draw arg : vmove ShapeName | |
1904 | //============================================================================== | |
1905 | ||
1906 | #ifdef DEB | |
1907 | static int VMoveA (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { | |
1908 | ||
1909 | OSD_Timer myTimer; | |
1910 | myTimer.Start(); | |
1911 | ||
1912 | if (TheAISContext()->HasOpenedContext()) | |
1913 | TheAISContext()->CloseLocalContext(); | |
1914 | ||
c6541a0c | 1915 | Standard_Real Step=2*M_PI/180; |
7fd59977 | 1916 | Standard_Real Angle=0; |
1917 | // R est le rayon de l'hellicoide | |
1918 | Standard_Real R=50; | |
1919 | // D est la distance parcourue en translation en 1 tour | |
1920 | Standard_Real D=50; | |
1921 | ||
1922 | Handle(AIS_InteractiveObject) aIO; | |
1923 | ||
1924 | if (GetMapOfAIS().IsBound2(argv[1])) | |
1925 | aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1])); | |
1926 | ||
1927 | if (aIO.IsNull()) { | |
1928 | di<<" Syntaxe error: "<<argv[1]<<" doesn't exist"<<"\n"; | |
1929 | return 1; | |
1930 | } | |
1931 | TheAISContext()->Deactivate(aIO); | |
1932 | ||
1933 | // boucle generant le mouvement | |
1934 | if(argc==3) { | |
1935 | di<<" Transformations"<<"\n"; | |
c6541a0c | 1936 | for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) { |
7fd59977 | 1937 | |
1938 | Angle=Step*myAngle; | |
c6541a0c | 1939 | gp_Ax3 newBase(gp_Pnt(R*cos(Angle), R*sin(Angle), D*Angle/(2*M_PI) ), gp_Vec(0,0,1), gp_Vec(1,0,0) ); |
7fd59977 | 1940 | gp_Trsf myTransfo; |
1941 | myTransfo.SetTransformation(newBase.Rotated(gp_Ax1(gp_Pnt(R*cos(Angle),R*sin(Angle),0), gp_Dir(0,0,1) ),Angle ) ); | |
1942 | TheAISContext()->SetLocation(aIO,myTransfo); | |
1943 | ||
1944 | TheAISContext() ->UpdateCurrentViewer(); | |
1945 | ||
1946 | } | |
1947 | } | |
1948 | else { | |
1949 | di<<" Locations"<<"\n"; | |
1950 | gp_Trsf myAngleTrsf; | |
1951 | myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step ); | |
1952 | TopLoc_Location myDeltaAngle (myAngleTrsf); | |
1953 | gp_Trsf myDistTrsf; | |
1954 | myDistTrsf.SetTranslation(gp_Dir(0,0,1) ); | |
1955 | TopLoc_Location myDeltaDist (myDistTrsf); | |
1956 | TopLoc_Location myTrueLoc; | |
1957 | ||
c6541a0c | 1958 | for (Standard_Real myAngle=0;Angle<5*2*M_PI; myAngle++) { |
7fd59977 | 1959 | |
1960 | Angle=Step*myAngle; | |
1961 | myTrueLoc=myTrueLoc*myDeltaAngle*myDeltaDist; | |
1962 | TheAISContext()->SetLocation(aIO,myTrueLoc ); | |
1963 | TheAISContext() ->UpdateCurrentViewer(); | |
1964 | } | |
1965 | } | |
1966 | ||
1967 | ||
1968 | TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()).Located( aIO->Location() ); | |
1969 | ||
1970 | //TopLoc_Location Tempo=aIO->Location(); | |
1971 | //TopoDS_Shape ShapeBis=((*(Handle(AIS_Shape)*)&aIO)->Shape()); | |
1972 | //ShapeBis.Located(Tempo); | |
1973 | ||
1974 | ||
1975 | // On reset la location (origine) contenue dans l'AISInteractiveObject | |
1976 | TheAISContext() ->ResetLocation(aIO); | |
1977 | ||
1978 | // On force aShape a devenir l'AIS IO propre a ShapeBis | |
1979 | ||
1980 | // Pour cela on force aShape(AIS IO) a devenir une AISShape | |
1981 | // ->Set() est une methode de AIS_Shape | |
1982 | (*(Handle(AIS_Shape)*)& aIO)->Set(ShapeBis); | |
1983 | ||
1984 | // On donne a ShapeBis le nom de l'AIS IO | |
1985 | //Rep::Set(argv[1],ShapeBis); | |
1986 | ||
1987 | ||
1988 | TheAISContext()->Redisplay(aIO,Standard_False); | |
1989 | ||
1990 | // On reactive la selection des primitives sensibles | |
1991 | TheAISContext()->Activate(aIO,0); | |
1992 | ||
1993 | TheAISContext() ->UpdateCurrentViewer(); | |
1994 | a3DView() -> Redraw(); | |
1995 | ||
1996 | myTimer.Stop(); | |
1997 | di<<" Temps ecoule "<<"\n"; | |
1998 | myTimer.Show(); | |
1999 | ||
2000 | return 0; | |
2001 | } | |
2002 | #endif | |
2003 | ||
2004 | ||
2005 | //============================================================================== | |
2006 | //function : VPerf | |
2007 | //purpose : Test the annimation of an object along a | |
2008 | // predifined trajectory | |
2009 | //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF) | |
2010 | //============================================================================== | |
2011 | ||
2012 | static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) { | |
2013 | ||
2014 | OSD_Timer myTimer; | |
2015 | if (TheAISContext()->HasOpenedContext()) | |
2016 | TheAISContext()->CloseLocalContext(); | |
2017 | ||
c6541a0c | 2018 | Standard_Real Step=4*M_PI/180; |
7fd59977 | 2019 | Standard_Real Angle=0; |
2020 | ||
2021 | Handle(AIS_InteractiveObject) aIO; | |
2022 | if (GetMapOfAIS().IsBound2(argv[1])) | |
2023 | aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1])); | |
2024 | if (aIO.IsNull()) | |
2025 | return 1; | |
2026 | ||
2027 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO); | |
2028 | ||
2029 | myTimer.Start(); | |
2030 | ||
2031 | if (atoi(argv[3])==1 ) { | |
2032 | di<<" Primitives sensibles OFF"<<"\n"; | |
2033 | TheAISContext()->Deactivate(aIO); | |
2034 | } | |
2035 | else { | |
2036 | di<<" Primitives sensibles ON"<<"\n"; | |
2037 | } | |
2038 | // Movement par transformation | |
2039 | if(atoi(argv[2]) ==1) { | |
2040 | di<<" Calcul par Transformation"<<"\n"; | |
c6541a0c | 2041 | for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) { |
7fd59977 | 2042 | |
2043 | Angle=Step*myAngle; | |
2044 | gp_Trsf myTransfo; | |
2045 | myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle ); | |
2046 | TheAISContext()->SetLocation(aShape,myTransfo); | |
2047 | TheAISContext() ->UpdateCurrentViewer(); | |
2048 | ||
2049 | } | |
2050 | } | |
2051 | else { | |
2052 | di<<" Calcul par Locations"<<"\n"; | |
2053 | gp_Trsf myAngleTrsf; | |
2054 | myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step ); | |
2055 | TopLoc_Location myDeltaAngle (myAngleTrsf); | |
2056 | TopLoc_Location myTrueLoc; | |
2057 | ||
c6541a0c | 2058 | for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) { |
7fd59977 | 2059 | |
2060 | Angle=Step*myAngle; | |
2061 | myTrueLoc=myTrueLoc*myDeltaAngle; | |
2062 | TheAISContext()->SetLocation(aShape,myTrueLoc ); | |
2063 | TheAISContext() ->UpdateCurrentViewer(); | |
2064 | } | |
2065 | } | |
2066 | if (atoi(argv[3])==1 ){ | |
2067 | // On reactive la selection des primitives sensibles | |
2068 | TheAISContext()->Activate(aIO,0); | |
2069 | } | |
2070 | a3DView() -> Redraw(); | |
2071 | myTimer.Stop(); | |
2072 | di<<" Temps ecoule "<<"\n"; | |
2073 | myTimer.Show(); | |
2074 | return 0; | |
2075 | } | |
2076 | ||
2077 | ||
2078 | //================================================================================== | |
2079 | // Function : VAnimation | |
2080 | //================================================================================== | |
2081 | static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { | |
31160f80 | 2082 | if (argc != 5) { |
7fd59977 | 2083 | di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n"; |
2084 | return 1; | |
2085 | } | |
2086 | ||
2087 | Standard_Real thread = 4; | |
2088 | Standard_Real angleA=0; | |
2089 | Standard_Real angleB; | |
2090 | Standard_Real X; | |
2091 | gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1)); | |
2092 | ||
2093 | BRep_Builder B; | |
2094 | TopoDS_Shape CrankArm; | |
2095 | TopoDS_Shape CylinderHead; | |
2096 | TopoDS_Shape Propeller; | |
2097 | TopoDS_Shape EngineBlock; | |
2098 | ||
2099 | //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B); | |
2100 | //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B); | |
2101 | //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B); | |
2102 | //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B); | |
2103 | BRepTools::Read(CrankArm,argv[1],B); | |
2104 | BRepTools::Read(CylinderHead,argv[2],B); | |
2105 | BRepTools::Read(Propeller,argv[3],B); | |
2106 | BRepTools::Read(EngineBlock,argv[4],B); | |
2107 | ||
2108 | if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";} | |
2109 | ||
2110 | ||
2111 | OSD_Timer myTimer; | |
2112 | myTimer.Start(); | |
2113 | ||
2114 | Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead); | |
2115 | Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock); | |
2116 | Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm); | |
2117 | Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller); | |
2118 | ||
2119 | GetMapOfAIS().Bind(myAisCylinderHead,"a"); | |
2120 | GetMapOfAIS().Bind(myAisEngineBlock,"b"); | |
2121 | GetMapOfAIS().Bind(myAisCrankArm,"c"); | |
2122 | GetMapOfAIS().Bind(myAisPropeller,"d"); | |
2123 | ||
2124 | TheAISContext()->SetColor(myAisCylinderHead, Quantity_NOC_INDIANRED); | |
2125 | TheAISContext()->SetColor(myAisEngineBlock , Quantity_NOC_RED); | |
2126 | TheAISContext()->SetColor(myAisPropeller , Quantity_NOC_GREEN); | |
2127 | ||
2128 | TheAISContext()->Display(myAisCylinderHead,Standard_False); | |
2129 | TheAISContext()->Display(myAisEngineBlock,Standard_False ); | |
2130 | TheAISContext()->Display(myAisCrankArm,Standard_False ); | |
2131 | TheAISContext()->Display(myAisPropeller,Standard_False); | |
2132 | ||
2133 | TheAISContext()->Deactivate(myAisCylinderHead); | |
2134 | TheAISContext()->Deactivate(myAisEngineBlock ); | |
2135 | TheAISContext()->Deactivate(myAisCrankArm ); | |
2136 | TheAISContext()->Deactivate(myAisPropeller ); | |
2137 | ||
2138 | // Boucle de mouvement | |
c6541a0c | 2139 | for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) { |
7fd59977 | 2140 | |
c6541a0c | 2141 | angleA = thread*myAngle*M_PI/180; |
7fd59977 | 2142 | X = Sin(angleA)*3/8; |
2143 | angleB = atan(X / Sqrt(-X * X + 1)); | |
2144 | Standard_Real decal(25*0.6); | |
2145 | ||
2146 | ||
2147 | //Build a transformation on the display | |
2148 | gp_Trsf aPropellerTrsf; | |
2149 | aPropellerTrsf.SetRotation(Ax1,angleA); | |
2150 | TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf); | |
2151 | ||
2152 | 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)); | |
2153 | gp_Trsf aCrankArmTrsf; | |
2154 | aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB)); | |
2155 | TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf); | |
2156 | ||
2157 | TheAISContext()->UpdateCurrentViewer(); | |
2158 | } | |
2159 | ||
2160 | TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Location() ); | |
2161 | TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Location() ); | |
2162 | ||
2163 | myAisCrankArm ->ResetLocation(); | |
2164 | myAisPropeller->ResetLocation(); | |
2165 | ||
2166 | myAisCrankArm -> Set(myNewCrankArm ); | |
2167 | myAisPropeller -> Set(myNewPropeller); | |
2168 | ||
2169 | TheAISContext()->Activate(myAisCylinderHead,0); | |
2170 | TheAISContext()->Activate(myAisEngineBlock,0 ); | |
2171 | TheAISContext()->Activate(myAisCrankArm ,0 ); | |
2172 | TheAISContext()->Activate(myAisPropeller ,0 ); | |
2173 | ||
2174 | myTimer.Stop(); | |
2175 | myTimer.Show(); | |
2176 | myTimer.Start(); | |
2177 | ||
2178 | TheAISContext()->Redisplay(myAisCrankArm ,Standard_False); | |
2179 | TheAISContext()->Redisplay(myAisPropeller,Standard_False); | |
2180 | ||
2181 | TheAISContext()->UpdateCurrentViewer(); | |
2182 | a3DView()->Redraw(); | |
2183 | ||
2184 | myTimer.Stop(); | |
2185 | myTimer.Show(); | |
2186 | ||
2187 | return 0; | |
2188 | ||
2189 | } | |
2190 | ||
2191 | //============================================================================== | |
2192 | //function : VShading | |
2193 | //purpose : Sharpen or roughten the quality of the shading | |
2194 | //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg | |
2195 | //============================================================================== | |
5cbef0fe S |
2196 | static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) |
2197 | { | |
7fd59977 | 2198 | Standard_Real myDevCoef; |
2199 | Handle(AIS_InteractiveObject) TheAisIO; | |
2200 | ||
2201 | // Verifications | |
5cbef0fe S |
2202 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0); |
2203 | ||
7fd59977 | 2204 | if (TheAISContext()->HasOpenedContext()) |
2205 | TheAISContext()->CloseLocalContext(); | |
2206 | ||
2207 | if (argc < 3) { | |
2208 | myDevCoef = 0.0008; | |
2209 | } else { | |
2210 | myDevCoef =atof(argv[2]); | |
2211 | } | |
2212 | ||
7fd59977 | 2213 | TCollection_AsciiString name=argv[1]; |
2214 | if (GetMapOfAIS().IsBound2(name )) | |
5cbef0fe | 2215 | TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); |
7fd59977 | 2216 | if (TheAisIO.IsNull()) |
2217 | TheAisIO=GetAISShapeFromName((const char *)name.ToCString()); | |
2218 | ||
5cbef0fe | 2219 | if (HaveToSet) |
7fd59977 | 2220 | TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True); |
5cbef0fe | 2221 | else |
7fd59977 | 2222 | TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True); |
2223 | ||
7fd59977 | 2224 | TheAISContext()->Redisplay(TheAisIO); |
2225 | return 0; | |
2226 | } | |
2227 | //============================================================================== | |
2228 | //function : HaveMode | |
2229 | //use : VActivatedModes | |
2230 | //============================================================================== | |
2231 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
2232 | ||
2233 | Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode ) | |
2234 | { | |
2235 | TColStd_ListOfInteger List; | |
2236 | TheAISContext()->ActivatedModes (TheAisIO,List); | |
2237 | TColStd_ListIteratorOfListOfInteger it; | |
2238 | Standard_Boolean Found=Standard_False; | |
2239 | for (it.Initialize(List); it.More()&&!Found; it.Next() ){ | |
2240 | if (it.Value()==mode ) Found=Standard_True; | |
2241 | } | |
2242 | return Found; | |
2243 | } | |
2244 | ||
2245 | ||
2246 | ||
2247 | //============================================================================== | |
2248 | //function : VActivatedMode | |
2249 | //author : ege | |
2250 | //purpose : permet d'attribuer a chacune des shapes un mode d'activation | |
2251 | // (edges,vertex...)qui lui est propre et le mode de selection standard. | |
2252 | // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer) | |
2253 | // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise | |
2254 | // qu'un nom et qu'un mode. | |
2255 | //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7) | |
2256 | //============================================================================== | |
2257 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
2258 | ||
2259 | static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2260 | ||
2261 | { | |
7fd59977 | 2262 | Standard_Boolean ThereIsName = Standard_False ; |
2263 | ||
2264 | if(!a3DView().IsNull()){ | |
2265 | ||
5cbef0fe | 2266 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0); |
7fd59977 | 2267 | // verification des arguments |
2268 | if (HaveToSet) { | |
2269 | if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;} | |
5cbef0fe | 2270 | ThereIsName = (argc == 3); |
7fd59977 | 2271 | } |
2272 | else { | |
2273 | // vunsetam | |
2274 | if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;} | |
2275 | else { | |
5cbef0fe S |
2276 | di<<" R.A.Z de tous les modes de selecion"<<"\n"; |
2277 | di<<" Fermeture du Context local"<<"\n"; | |
7fd59977 | 2278 | if (TheAISContext()->HasOpenedContext()) |
2279 | TheAISContext()->CloseLocalContext(); | |
2280 | } | |
7fd59977 | 2281 | } |
2282 | ||
7fd59977 | 2283 | // IL n'y a aps de nom de shape passe en argument |
2284 | if (HaveToSet && !ThereIsName){ | |
2285 | Standard_Integer aMode=atoi(argv [1]); | |
2286 | ||
2287 | const char *cmode="???"; | |
7fd59977 | 2288 | switch (aMode) { |
2289 | case 0: cmode = "Shape"; break; | |
2290 | case 1: cmode = "Vertex"; break; | |
2291 | case 2: cmode = "Edge"; break; | |
2292 | case 3: cmode = "Wire"; break; | |
2293 | case 4: cmode = "Face"; break; | |
2294 | case 5: cmode = "Shell"; break; | |
2295 | case 6: cmode = "Solid"; break; | |
2296 | case 7: cmode = "Compound"; break; | |
2297 | } | |
2298 | ||
2299 | if( !TheAISContext()->HasOpenedContext() ) { | |
5cbef0fe S |
2300 | // il n'y a pas de Context local d'ouvert |
2301 | // on en ouvre un et on charge toutes les shapes displayees | |
2302 | // on load tous les objets displayees et on Activate les objets de la liste | |
2303 | AIS_ListOfInteractive ListOfIO; | |
2304 | // on sauve dans une AISListOfInteractive tous les objets currents | |
2305 | if (TheAISContext()->NbCurrents()>0 ){ | |
2306 | TheAISContext()->UnhilightCurrents(Standard_False); | |
2307 | ||
2308 | for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){ | |
2309 | ListOfIO.Append(TheAISContext()->Current() ); | |
7fd59977 | 2310 | } |
2311 | } | |
2312 | ||
2313 | TheAISContext()->OpenLocalContext(Standard_False); | |
2314 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
2315 | it (GetMapOfAIS()); | |
2316 | while(it.More()){ | |
2317 | Handle(AIS_InteractiveObject) aIO = | |
2318 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
2319 | if (!aIO.IsNull()) | |
2320 | TheAISContext()->Load(aIO,0,Standard_False); | |
2321 | it.Next(); | |
2322 | } | |
2323 | // traitement des objets qui etaient currents dans le Contexte global | |
2324 | if (!ListOfIO.IsEmpty() ) { | |
2325 | // il y avait des objets currents | |
2326 | AIS_ListIteratorOfListOfInteractive iter; | |
2327 | for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) { | |
2328 | Handle(AIS_InteractiveObject) aIO=iter.Value(); | |
2329 | TheAISContext()->Activate(aIO,aMode); | |
2330 | di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
2331 | } | |
2332 | } | |
2333 | else { | |
2334 | // On applique le mode a tous les objets displayes | |
2335 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
2336 | it2 (GetMapOfAIS()); | |
2337 | while(it2.More()){ | |
2338 | Handle(AIS_InteractiveObject) aIO = | |
2339 | Handle(AIS_InteractiveObject)::DownCast(it2.Key1()); | |
2340 | if (!aIO.IsNull()) { | |
2341 | di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n"; | |
2342 | TheAISContext()->Activate(aIO,aMode); | |
2343 | } | |
2344 | it2.Next(); | |
2345 | } | |
2346 | } | |
2347 | ||
2348 | } | |
2349 | ||
2350 | else { | |
2351 | // un Context local est deja ouvert | |
2352 | // Traitement des objets du Context local | |
2353 | if (TheAISContext()->NbSelected()>0 ){ | |
2354 | TheAISContext()->UnhilightSelected(Standard_False); | |
2355 | // il y a des objets selected,on les parcourt | |
2356 | for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){ | |
2357 | Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive(); | |
2358 | ||
2359 | ||
2360 | if (HaveMode(aIO,aMode) ) { | |
2361 | di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
2362 | TheAISContext()->Deactivate(aIO,aMode); | |
2363 | } | |
2364 | else{ | |
2365 | di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
2366 | TheAISContext()->Activate(aIO,aMode); | |
2367 | } | |
2368 | ||
2369 | } | |
2370 | } | |
2371 | else{ | |
2372 | // il n'y a pas d'objets selected | |
2373 | // tous les objets diplayes sont traites | |
2374 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
2375 | it (GetMapOfAIS()); | |
2376 | while(it.More()){ | |
2377 | Handle(AIS_InteractiveObject) aIO = | |
2378 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
2379 | if (!aIO.IsNull()) { | |
2380 | if (HaveMode(aIO,aMode) ) { | |
2381 | di<<" Mode: "<<cmode<<" OFF pour " | |
2382 | <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
2383 | TheAISContext()->Deactivate(aIO,aMode); | |
2384 | } | |
2385 | else{ | |
2386 | di<<" Mode: "<<cmode<<" ON pour" | |
2387 | <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
2388 | TheAISContext()->Activate(aIO,aMode); | |
2389 | } | |
2390 | } | |
2391 | it.Next(); | |
2392 | } | |
2393 | } | |
2394 | } | |
2395 | } | |
2396 | else if (HaveToSet && ThereIsName){ | |
2397 | Standard_Integer aMode=atoi(argv [2]); | |
2398 | Handle(AIS_InteractiveObject) aIO = | |
2399 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1])); | |
2400 | ||
2401 | if (!aIO.IsNull()) { | |
2402 | const char *cmode="???"; | |
2403 | ||
2404 | switch (aMode) { | |
2405 | case 0: cmode = "Shape"; break; | |
2406 | case 1: cmode = "Vertex"; break; | |
2407 | case 2: cmode = "Edge"; break; | |
2408 | case 3: cmode = "Wire"; break; | |
2409 | case 4: cmode = "Face"; break; | |
2410 | case 5: cmode = "Shell"; break; | |
2411 | case 6: cmode = "Solid"; break; | |
2412 | case 7: cmode = "Compound"; break; | |
2413 | } | |
2414 | ||
2415 | if( !TheAISContext()->HasOpenedContext() ) { | |
2416 | TheAISContext()->OpenLocalContext(Standard_False); | |
2417 | // On charge tous les objets de la map | |
2418 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS()); | |
2419 | while(it.More()){ | |
2420 | Handle(AIS_InteractiveObject) aShape= | |
2421 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
2422 | if (!aShape.IsNull()) | |
2423 | TheAISContext()->Load(aShape,0,Standard_False); | |
2424 | it.Next(); | |
2425 | } | |
2426 | TheAISContext()->Activate(aIO,aMode); | |
2427 | di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n"; | |
2428 | } | |
2429 | ||
2430 | else { | |
2431 | // un Context local est deja ouvert | |
2432 | if (HaveMode(aIO,aMode) ) { | |
2433 | di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n"; | |
2434 | TheAISContext()->Deactivate(aIO,aMode); | |
2435 | } | |
2436 | else{ | |
2437 | di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n"; | |
2438 | TheAISContext()->Activate(aIO,aMode); | |
2439 | } | |
2440 | } | |
2441 | } | |
2442 | } | |
2443 | } | |
2444 | return 0; | |
2445 | ||
2446 | } | |
2447 | ||
2448 | ||
2449 | ||
2450 | //============================================================================== | |
2451 | // function : WhoAmI | |
2452 | // user : vState | |
2453 | //============================================================================== | |
2454 | void WhoAmI (const Handle(AIS_InteractiveObject )& theShape ,Draw_Interpretor& di) { | |
2455 | ||
2456 | // AIS_Datum | |
2457 | if (theShape->Type()==AIS_KOI_Datum) { | |
2458 | if (theShape->Signature()==3 ) { di<<" AIS_Trihedron"; } | |
2459 | else if (theShape->Signature()==2 ) { di<<" AIS_Axis"; } | |
2460 | else if (theShape->Signature()==6 ) { di<<" AIS_Circle"; } | |
2461 | else if (theShape->Signature()==5 ) { di<<" AIS_Line"; } | |
2462 | else if (theShape->Signature()==7 ) { di<<" AIS_Plane"; } | |
2463 | else if (theShape->Signature()==1 ) { di<<" AIS_Point"; } | |
2464 | else if (theShape->Signature()==4 ) { di<<" AIS_PlaneTrihedron"; } | |
2465 | } | |
2466 | // AIS_Shape | |
2467 | else if (theShape->Type()==AIS_KOI_Shape && theShape->Signature()==0 ) { di<<" AIS_Shape"; } | |
2468 | // AIS_Dimentions et AIS_Relations | |
2469 | else if (theShape->Type()==AIS_KOI_Relation) { | |
2470 | Handle(AIS_Relation) TheShape= ((*(Handle(AIS_Relation)*)&theShape)); | |
2471 | ||
2472 | if (TheShape->KindOfDimension()==AIS_KOD_PLANEANGLE) {di<<" AIS_AngleDimension";} | |
2473 | else if (TheShape->KindOfDimension()==AIS_KOD_LENGTH ) {di<<" AIS_Chamf2/3dDimension/AIS_LengthDimension "; } | |
2474 | else if (TheShape->KindOfDimension()==AIS_KOD_DIAMETER ) {di<<" AIS_DiameterDimension ";} | |
2475 | else if (TheShape->KindOfDimension()==AIS_KOD_ELLIPSERADIUS ) {di<<" AIS_EllipseRadiusDimension ";} | |
2476 | //else if (TheShape->KindOfDimension()==AIS_KOD_FILLETRADIUS ) {di<<" AIS_FilletRadiusDimension "<<endl;} | |
2477 | else if (TheShape->KindOfDimension()==AIS_KOD_OFFSET ) {di<<" AIS_OffsetDimension ";} | |
2478 | else if (TheShape->KindOfDimension()==AIS_KOD_RADIUS ) {di<<" AIS_RadiusDimension ";} | |
2479 | // AIS no repertorie. | |
2480 | else {di<<" Type Unknown.";} | |
2481 | } | |
2482 | } | |
2483 | ||
2484 | ||
2485 | ||
2486 | //============================================================================== | |
2487 | //function : VState | |
2488 | //purpose : | |
2489 | //Draw arg : vstate [nameA] ... [nameN] | |
2490 | //============================================================================== | |
2491 | static int VState(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2492 | { | |
7fd59977 | 2493 | TheAISContext()->CloseAllContexts(); |
5cbef0fe S |
2494 | const Standard_Boolean ThereIsArguments=(argc>=2); |
2495 | const Standard_Boolean ThereIsCurrent=(TheAISContext()->NbCurrents()>0); | |
7fd59977 | 2496 | // Debut... |
2497 | // ================== | |
2498 | // Il y a un argument | |
2499 | // ================== | |
5cbef0fe | 2500 | if (ThereIsArguments) { |
7fd59977 | 2501 | for (int cpt=1;cpt<argc;cpt++) { |
2502 | // Verification que lq piece est bien bindee. | |
2503 | if (GetMapOfAIS().IsBound2(argv[cpt]) ) { | |
2504 | const Handle(AIS_InteractiveObject) theShape= | |
2505 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 | |
2506 | (argv[cpt])); | |
2507 | if (!theShape.IsNull()) { | |
2508 | di<<argv[cpt];WhoAmI(theShape, di); | |
2509 | if (TheAISContext()->IsDisplayed(theShape) ) { | |
2510 | di<<" Displayed"<<"\n"; | |
2511 | } | |
2512 | else { | |
2513 | di<<" Not Displayed"<<"\n"; | |
2514 | } | |
2515 | } | |
2516 | } | |
2517 | else { | |
2518 | di<<"vstate error: Shape "<<cpt<<" doesn't exist;" <<"\n";return 1; | |
2519 | } | |
2520 | } | |
2521 | } | |
2522 | else if (ThereIsCurrent ) { | |
2523 | for (TheAISContext() -> InitCurrent() ; | |
2524 | TheAISContext() -> MoreCurrent() ; | |
2525 | TheAISContext() ->NextCurrent() ) | |
2526 | { | |
2527 | Handle(AIS_InteractiveObject) theShape=TheAISContext()->Current(); | |
2528 | di<<GetMapOfAIS().Find1(theShape).ToCString(); WhoAmI(theShape, di); | |
2529 | if (TheAISContext()->IsDisplayed(theShape) ) { | |
2530 | di<<" Displayed"<<"\n"; | |
2531 | } | |
2532 | else { | |
2533 | di<<" Not Displayed"<<"\n"; | |
2534 | } | |
2535 | ||
2536 | } | |
2537 | } | |
2538 | else { | |
2539 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
2540 | it(GetMapOfAIS()); | |
2541 | while ( it.More() ) { | |
2542 | Handle(AIS_InteractiveObject) theShape = | |
2543 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
2544 | if (!theShape.IsNull()) { | |
2545 | di<<it.Key2().ToCString(); | |
2546 | WhoAmI(theShape, di); | |
2547 | if (TheAISContext()->IsDisplayed(theShape) ) { | |
2548 | di<<" Displayed"<<"\n"; | |
2549 | } | |
2550 | else { | |
2551 | di<<" Not Displayed"<<"\n"; | |
2552 | } | |
2553 | } | |
2554 | it.Next(); | |
2555 | } | |
2556 | } | |
2557 | ||
2558 | return 0; | |
2559 | } | |
2560 | ||
2561 | ||
2562 | //======================================================================= | |
2563 | //function : PickObjects | |
2564 | //purpose : | |
2565 | //======================================================================= | |
2566 | Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr, | |
2567 | const AIS_KindOfInteractive TheType, | |
2568 | const Standard_Integer TheSignature, | |
2569 | const Standard_Integer MaxPick) | |
2570 | { | |
2571 | Handle(AIS_InteractiveObject) IO; | |
2572 | Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext(); | |
2573 | ||
2574 | // step 1: prepare the data | |
4952a30a | 2575 | if(curindex !=0){ |
7fd59977 | 2576 | Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature); |
2577 | TheAISContext()->AddFilter(F1); | |
2578 | } | |
2579 | ||
2580 | // step 2 : wait for the selection... | |
2581 | // Standard_Boolean IsGood (Standard_False); | |
2582 | // Standard_Integer NbPick(0); | |
2583 | Standard_Boolean NbPickGood (0),NbToReach(arr->Length()); | |
2584 | Standard_Integer NbPickFail(0); | |
2585 | Standard_Integer argccc = 5; | |
2586 | const char *bufff[] = { "A", "B", "C","D", "E" }; | |
2587 | const char **argvvv = (const char **) bufff; | |
2588 | ||
2589 | ||
2590 | while(NbPickGood<NbToReach && NbPickFail <= MaxPick){ | |
2591 | while(ViewerMainLoop(argccc,argvvv)){} | |
2592 | Standard_Integer NbStored = TheAISContext()->NbSelected(); | |
2593 | if((unsigned int ) NbStored != NbPickGood) | |
2594 | NbPickGood= NbStored; | |
2595 | else | |
2596 | NbPickFail++; | |
2597 | cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl; | |
2598 | } | |
2599 | ||
2600 | // step3 get result. | |
2601 | ||
2602 | if((unsigned int ) NbPickFail >= NbToReach) return Standard_False; | |
2603 | ||
2604 | Standard_Integer i(0); | |
2605 | for(TheAISContext()->InitSelected(); | |
2606 | TheAISContext()->MoreSelected(); | |
2607 | TheAISContext()->NextSelected()){ | |
2608 | i++; | |
2609 | Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive(); | |
2610 | arr->SetValue(i,IO2); | |
2611 | } | |
2612 | ||
2613 | ||
2614 | if(curindex>0) | |
2615 | TheAISContext()->CloseLocalContext(curindex); | |
2616 | ||
2617 | return Standard_True; | |
2618 | } | |
2619 | ||
2620 | ||
2621 | //======================================================================= | |
2622 | //function : PickObject | |
2623 | //purpose : | |
2624 | //======================================================================= | |
2625 | Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType, | |
2626 | const Standard_Integer TheSignature, | |
2627 | const Standard_Integer MaxPick) | |
2628 | { | |
2629 | Handle(AIS_InteractiveObject) IO; | |
2630 | Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext(); | |
2631 | ||
2632 | // step 1: prepare the data | |
2633 | ||
4952a30a | 2634 | if(curindex !=0){ |
7fd59977 | 2635 | Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature); |
2636 | TheAISContext()->AddFilter(F1); | |
2637 | } | |
2638 | ||
2639 | // step 2 : wait for the selection... | |
2640 | Standard_Boolean IsGood (Standard_False); | |
2641 | Standard_Integer NbPick(0); | |
2642 | Standard_Integer argccc = 5; | |
2643 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2644 | const char **argvvv = (const char **) bufff; | |
2645 | ||
2646 | ||
2647 | while(!IsGood && NbPick<= MaxPick){ | |
2648 | while(ViewerMainLoop(argccc,argvvv)){} | |
2649 | IsGood = (TheAISContext()->NbSelected()>0) ; | |
2650 | NbPick++; | |
2651 | cout<<"Nb Pick :"<<NbPick<<endl; | |
2652 | } | |
2653 | ||
2654 | ||
2655 | // step3 get result. | |
2656 | if(IsGood){ | |
2657 | TheAISContext()->InitSelected(); | |
2658 | IO = TheAISContext()->SelectedInteractive(); | |
2659 | } | |
2660 | ||
4952a30a | 2661 | if(curindex!=0) |
7fd59977 | 2662 | TheAISContext()->CloseLocalContext(curindex); |
2663 | return IO; | |
2664 | } | |
2665 | ||
2666 | //======================================================================= | |
2667 | //function : PickShape | |
2668 | //purpose : First Activate the rightmode + Put Filters to be able to | |
2669 | // pick objets that are of type <TheType>... | |
2670 | //======================================================================= | |
2671 | ||
2672 | TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType, | |
2673 | const Standard_Integer MaxPick) | |
2674 | { | |
2675 | ||
2676 | // step 1: prepare the data | |
2677 | ||
2678 | Standard_Integer curindex = TheAISContext()->OpenLocalContext(); | |
2679 | TopoDS_Shape result; | |
2680 | ||
2681 | if(TheType==TopAbs_SHAPE){ | |
2682 | Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape); | |
2683 | TheAISContext()->AddFilter(F1); | |
2684 | } | |
2685 | else{ | |
2686 | Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType); | |
2687 | TheAISContext()->AddFilter(TF); | |
2688 | TheAISContext()->ActivateStandardMode(TheType); | |
2689 | ||
2690 | } | |
2691 | ||
2692 | ||
2693 | // step 2 : wait for the selection... | |
2694 | Standard_Boolean NoShape (Standard_True); | |
2695 | Standard_Integer NbPick(0); | |
2696 | Standard_Integer argccc = 5; | |
2697 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2698 | const char **argvvv = (const char **) bufff; | |
2699 | ||
2700 | ||
2701 | while(NoShape && NbPick<= MaxPick){ | |
2702 | while(ViewerMainLoop(argccc,argvvv)){} | |
2703 | NoShape = (TheAISContext()->NbSelected()==0) ; | |
2704 | NbPick++; | |
2705 | cout<<"Nb Pick :"<<NbPick<<endl; | |
2706 | } | |
2707 | ||
2708 | // step3 get result. | |
2709 | ||
2710 | if(!NoShape){ | |
2711 | ||
2712 | TheAISContext()->InitSelected(); | |
2713 | if(TheAISContext()->HasSelectedShape()) | |
2714 | result = TheAISContext()->SelectedShape(); | |
2715 | else{ | |
2716 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); | |
2717 | result = (*((Handle(AIS_Shape)*) &IO))->Shape(); | |
2718 | } | |
2719 | } | |
2720 | ||
2721 | if(curindex>0) | |
2722 | TheAISContext()->CloseLocalContext(curindex); | |
2723 | ||
2724 | return result; | |
2725 | } | |
2726 | ||
2727 | ||
2728 | //======================================================================= | |
2729 | //function : PickShapes | |
2730 | //purpose : | |
2731 | //======================================================================= | |
2732 | Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType, | |
2733 | Handle(TopTools_HArray1OfShape)& thearr, | |
2734 | const Standard_Integer MaxPick) | |
2735 | { | |
2736 | ||
2737 | Standard_Integer Taille = thearr->Length(); | |
2738 | if(Taille>1) | |
2739 | cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n"; | |
2740 | ||
2741 | // step 1: prepare the data | |
2742 | Standard_Integer curindex = TheAISContext()->OpenLocalContext(); | |
2743 | if(TheType==TopAbs_SHAPE){ | |
2744 | Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape); | |
2745 | TheAISContext()->AddFilter(F1); | |
2746 | } | |
2747 | else{ | |
2748 | Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType); | |
2749 | TheAISContext()->AddFilter(TF); | |
2750 | TheAISContext()->ActivateStandardMode(TheType); | |
2751 | ||
2752 | } | |
2753 | ||
2754 | // step 2 : wait for the selection... | |
2755 | ||
2756 | Standard_Boolean NbPickGood (0),NbToReach(thearr->Length()); | |
2757 | Standard_Integer NbPickFail(0); | |
2758 | Standard_Integer argccc = 5; | |
2759 | const char *bufff[] = { "A", "B", "C","D", "E" }; | |
2760 | const char **argvvv = (const char **) bufff; | |
2761 | ||
2762 | ||
2763 | while(NbPickGood<NbToReach && NbPickFail <= MaxPick){ | |
2764 | while(ViewerMainLoop(argccc,argvvv)){} | |
2765 | Standard_Integer NbStored = TheAISContext()->NbSelected(); | |
2766 | if((unsigned int ) NbStored != NbPickGood) | |
2767 | NbPickGood= NbStored; | |
2768 | else | |
2769 | NbPickFail++; | |
2770 | cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n"; | |
2771 | } | |
2772 | ||
2773 | // step3 get result. | |
2774 | ||
2775 | if((unsigned int ) NbPickFail >= NbToReach) return Standard_False; | |
2776 | ||
2777 | Standard_Integer i(0); | |
2778 | for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){ | |
2779 | i++; | |
2780 | if(TheAISContext()->HasSelectedShape()) | |
2781 | thearr->SetValue(i,TheAISContext()->SelectedShape()); | |
2782 | else{ | |
2783 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); | |
2784 | thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape()); | |
2785 | } | |
2786 | } | |
2787 | ||
2788 | TheAISContext()->CloseLocalContext(curindex); | |
2789 | return Standard_True; | |
2790 | } | |
2791 | ||
2792 | ||
2793 | //======================================================================= | |
2794 | //function : VPickShape | |
2795 | //purpose : | |
2796 | //======================================================================= | |
2797 | static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2798 | { | |
2799 | TopoDS_Shape PickSh; | |
2800 | TopAbs_ShapeEnum theType = TopAbs_COMPOUND; | |
2801 | ||
2802 | if(argc==1) | |
2803 | theType = TopAbs_SHAPE; | |
2804 | else{ | |
2805 | if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX; | |
2806 | else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE; | |
2807 | else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE; | |
2808 | else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE; | |
2809 | else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE; | |
2810 | else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL; | |
2811 | else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID; | |
2812 | } | |
2813 | ||
2814 | static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0}; | |
2815 | static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"}; | |
2816 | ||
2817 | TCollection_AsciiString name; | |
2818 | ||
2819 | ||
2820 | Standard_Integer NbToPick = argc>2 ? argc-2 : 1; | |
2821 | if(NbToPick==1){ | |
2822 | PickSh = ViewerTest::PickShape(theType); | |
2823 | ||
2824 | if(PickSh.IsNull()) | |
2825 | return 1; | |
2826 | if(argc>2){ | |
2827 | name += argv[2]; | |
2828 | } | |
2829 | else{ | |
2830 | ||
2831 | if(!PickSh.IsNull()){ | |
2832 | nbOfSub[Standard_Integer(theType)]++; | |
2833 | name += "Picked_"; | |
2834 | name += nameType[Standard_Integer(theType)]; | |
2835 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); | |
2836 | name +="_"; | |
2837 | name+=indxstring; | |
2838 | } | |
2839 | } | |
2840 | // si on avait une petite methode pour voir si la shape | |
2841 | // est deja dans la Double map, ca eviterait de creer.... | |
2842 | DBRep::Set(name.ToCString(),PickSh); | |
2843 | ||
2844 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); | |
2845 | GetMapOfAIS().Bind(newsh, name); | |
2846 | TheAISContext()->Display(newsh); | |
2847 | di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n"; | |
2848 | } | |
2849 | ||
2850 | // Plusieurs objets a picker, vite vite vite.... | |
2851 | // | |
2852 | else{ | |
2853 | Standard_Boolean autonaming = !strcasecmp(argv[2],"."); | |
2854 | Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick); | |
2855 | if(ViewerTest::PickShapes(theType,arr)){ | |
2856 | for(Standard_Integer i=1;i<=NbToPick;i++){ | |
2857 | PickSh = arr->Value(i); | |
2858 | if(!PickSh.IsNull()){ | |
2859 | if(autonaming){ | |
2860 | nbOfSub[Standard_Integer(theType)]++; | |
2861 | name.Clear(); | |
2862 | name += "Picked_"; | |
2863 | name += nameType[Standard_Integer(theType)]; | |
2864 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); | |
2865 | name +="_"; | |
2866 | name+=indxstring; | |
2867 | } | |
2868 | } | |
2869 | else | |
2870 | name = argv[1+i]; | |
2871 | ||
2872 | DBRep::Set(name.ToCString(),PickSh); | |
2873 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); | |
2874 | GetMapOfAIS().Bind(newsh, name); | |
2875 | di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n"; | |
2876 | TheAISContext()->Display(newsh); | |
2877 | ||
2878 | } | |
2879 | } | |
2880 | } | |
2881 | return 0; | |
2882 | ||
2883 | } | |
2884 | ||
2885 | ||
2886 | //======================================================================= | |
2887 | //function : VPickObject | |
2888 | //purpose : filters can be set (type of Object to pick.... | |
2889 | // | |
2890 | //======================================================================= | |
2891 | // Unused : | |
2892 | #ifdef DEB | |
2893 | static int VPickObject( Draw_Interpretor& , Standard_Integer /*argc*/, const char** /*argv*/) | |
2894 | { | |
2895 | // preparation de la nomination automatique | |
2896 | static TCollection_AsciiString ObjType[] ={"None","Datum","Shape","Object","Relation"}; | |
2897 | // static char* DatumSig [8] ={"Point","Axis","Trih","PlTri","Line","Circle","Plane","UnK"}; | |
2898 | ||
2899 | /* TCollection_AsciiString name; | |
2900 | ||
2901 | Standard_Integer NbToPick = argc>2 ? argc-2 : 1; | |
2902 | if(NbToPick==1){ | |
2903 | PickSh = ViewerTest::PickObject(theType); | |
2904 | ||
2905 | if(PickSh.IsNull()) | |
2906 | return 1; | |
2907 | if(argc>2){ | |
2908 | name += argv[2]; | |
2909 | } | |
2910 | else{ | |
2911 | ||
2912 | if(!PickSh.IsNull()){ | |
2913 | nbOfSub[Standard_Integer(theType)]++; | |
2914 | name += "Picked_"; | |
2915 | name += nameType[Standard_Integer(theType)]; | |
2916 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); | |
2917 | name +="_"; | |
2918 | name+=indxstring; | |
2919 | } | |
2920 | } | |
2921 | // si on avait une petite methode pour voir si la shape | |
2922 | // est deja dans la Double map, ca eviterait de creer.... | |
2923 | DBRep::Set(name.ToCString(),PickSh); | |
2924 | ||
2925 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); | |
2926 | GetMapOfAIS().Bind(newsh, name); | |
2927 | TheAISContext()->Display(newsh); | |
2928 | cout<<"Nom de la shape pickee : "<<name<<endl; | |
2929 | } | |
2930 | ||
2931 | // Plusieurs objets a picker, vite vite vite.... | |
2932 | // | |
2933 | else{ | |
2934 | Standard_Boolean autonaming = !strcasecmp(argv[2],"."); | |
2935 | Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick); | |
2936 | if(ViewerTest::PickShapes(theType,arr)){ | |
2937 | for(Standard_Integer i=1;i<=NbToPick;i++){ | |
2938 | PickSh = arr->Value(i); | |
2939 | if(!PickSh.IsNull()){ | |
2940 | if(autonaming){ | |
2941 | nbOfSub[Standard_Integer(theType)]++; | |
2942 | name.Clear(); | |
2943 | name += "Picked_"; | |
2944 | name += nameType[Standard_Integer(theType)]; | |
2945 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); | |
2946 | name +="_"; | |
2947 | name+=indxstring; | |
2948 | } | |
2949 | } | |
2950 | else | |
2951 | name = argv[1+i]; | |
2952 | ||
2953 | DBRep::Set(name.ToCString(),PickSh); | |
2954 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); | |
2955 | GetMapOfAIS().Bind(newsh, name); | |
2956 | cout<<"display of picke shape #"<<i<<" - nom : "<<name<<endl; | |
2957 | TheAISContext()->Display(newsh); | |
2958 | ||
2959 | } | |
2960 | } | |
2961 | } | |
2962 | */ | |
2963 | return 0; | |
2964 | } | |
2965 | #endif | |
2966 | ||
2967 | //======================================================================= | |
2968 | //function : list of known objects | |
2969 | //purpose : | |
2970 | //======================================================================= | |
2971 | static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** ) | |
2972 | { | |
2973 | // 1234567890 12345678901234567 123456789 | |
2974 | TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"}; | |
2975 | TCollection_AsciiString BlankLine(64,'_'); | |
2976 | Standard_Integer i ; | |
2977 | ||
2978 | di<<"/n"<<BlankLine.ToCString()<<"\n"; | |
2979 | ||
2980 | for( i =0;i<=2;i++) | |
2981 | Colum[i].Center(20,' '); | |
2982 | for(i=0;i<=2;i++) | |
2983 | di<<"|"<<Colum[i].ToCString(); | |
2984 | di<<"|"<<"\n"; | |
2985 | ||
2986 | di<<BlankLine.ToCString()<<"\n"; | |
2987 | ||
2988 | // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"}; | |
2989 | const char ** names = GetTypeNames(); | |
2990 | ||
2991 | TCollection_AsciiString curstring; | |
2992 | TCollection_AsciiString curcolum[3]; | |
2993 | ||
2994 | ||
2995 | // les objets de type Datum.. | |
2996 | curcolum[1]+="Datum"; | |
2997 | for(i =0;i<=6;i++){ | |
2998 | curcolum[0].Clear(); | |
2999 | curcolum[0] += names[i]; | |
3000 | ||
3001 | curcolum[2].Clear(); | |
3002 | curcolum[2]+=TCollection_AsciiString(i+1); | |
3003 | ||
3004 | for(Standard_Integer j =0;j<=2;j++){ | |
3005 | curcolum[j].Center(20,' '); | |
3006 | di<<"|"<<curcolum[j].ToCString(); | |
3007 | } | |
3008 | di<<"|"<<"\n"; | |
3009 | } | |
3010 | di<<BlankLine.ToCString()<<"\n"; | |
3011 | ||
3012 | // les objets de type shape | |
3013 | curcolum[1].Clear(); | |
3014 | curcolum[1]+="Shape"; | |
3015 | curcolum[1].Center(20,' '); | |
3016 | ||
3017 | for(i=0;i<=2;i++){ | |
3018 | curcolum[0].Clear(); | |
3019 | curcolum[0] += names[7+i]; | |
3020 | curcolum[2].Clear(); | |
3021 | curcolum[2]+=TCollection_AsciiString(i); | |
3022 | ||
3023 | for(Standard_Integer j =0;j<=2;j++){ | |
3024 | curcolum[j].Center(20,' '); | |
3025 | di<<"|"<<curcolum[j].ToCString(); | |
3026 | } | |
3027 | di<<"|"<<"\n"; | |
3028 | } | |
3029 | di<<BlankLine.ToCString()<<"\n"; | |
3030 | // les IO de type objet... | |
3031 | curcolum[1].Clear(); | |
3032 | curcolum[1]+="Object"; | |
3033 | curcolum[1].Center(20,' '); | |
3034 | for(i=0;i<=1;i++){ | |
3035 | curcolum[0].Clear(); | |
3036 | curcolum[0] += names[10+i]; | |
3037 | curcolum[2].Clear(); | |
3038 | curcolum[2]+=TCollection_AsciiString(i); | |
3039 | ||
3040 | for(Standard_Integer j =0;j<=2;j++){ | |
3041 | curcolum[j].Center(20,' '); | |
3042 | di<<"|"<<curcolum[j].ToCString(); | |
3043 | } | |
3044 | di<<"|"<<"\n"; | |
3045 | } | |
3046 | di<<BlankLine.ToCString()<<"\n"; | |
3047 | // les contraintes et dimensions. | |
3048 | // pour l'instant on separe juste contraintes et dimensions... | |
3049 | // plus tard, on detaillera toutes les sortes... | |
3050 | curcolum[1].Clear(); | |
3051 | curcolum[1]+="Relation"; | |
3052 | curcolum[1].Center(20,' '); | |
3053 | for(i=0;i<=1;i++){ | |
3054 | curcolum[0].Clear(); | |
3055 | curcolum[0] += names[12+i]; | |
3056 | curcolum[2].Clear(); | |
3057 | curcolum[2]+=TCollection_AsciiString(i); | |
3058 | ||
3059 | for(Standard_Integer j =0;j<=2;j++){ | |
3060 | curcolum[j].Center(20,' '); | |
3061 | di<<"|"<<curcolum[j].ToCString(); | |
3062 | } | |
3063 | di<<"|"<<"\n"; | |
3064 | } | |
3065 | di<<BlankLine.ToCString()<<"\n"; | |
3066 | ||
3067 | ||
3068 | return 0; | |
3069 | } | |
3070 | ||
3071 | ||
3072 | static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
3073 | { | |
4952a30a | 3074 | if(argc!=2) return 1; |
7fd59977 | 3075 | |
3076 | AIS_KindOfInteractive TheType; | |
3077 | Standard_Integer TheSign(-1); | |
3078 | GetTypeAndSignfromString(argv[1],TheType,TheSign); | |
3079 | ||
3080 | ||
3081 | AIS_ListOfInteractive LIO; | |
3082 | ||
3083 | // en attendant l'amelioration ais pour les dimensions... | |
3084 | // | |
3085 | Standard_Integer dimension_status(-1); | |
3086 | if(TheType==AIS_KOI_Relation){ | |
3087 | dimension_status = TheSign ==1 ? 1 : 0; | |
3088 | TheSign=-1; | |
3089 | } | |
3090 | ||
3091 | TheAISContext()->DisplayedObjects(TheType,TheSign,LIO); | |
3092 | Handle(AIS_InteractiveObject) curio; | |
3093 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ | |
3094 | curio = it.Value(); | |
3095 | ||
3096 | if(dimension_status == -1) | |
3097 | TheAISContext()->Erase(curio,Standard_False); | |
3098 | else { | |
3099 | AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension(); | |
3100 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| | |
3101 | (dimension_status==1 && KOD != AIS_KOD_NONE)) | |
3102 | TheAISContext()->Erase(curio,Standard_False); | |
3103 | } | |
3104 | } | |
3105 | TheAISContext()->UpdateCurrentViewer(); | |
3106 | return 0; | |
3107 | } | |
3108 | static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
3109 | { | |
3110 | if(argc!=2) return 1; | |
3111 | ||
3112 | AIS_KindOfInteractive TheType; | |
3113 | Standard_Integer TheSign(-1); | |
3114 | GetTypeAndSignfromString(argv[1],TheType,TheSign); | |
3115 | ||
3116 | // en attendant l'amelioration ais pour les dimensions... | |
3117 | // | |
3118 | Standard_Integer dimension_status(-1); | |
3119 | if(TheType==AIS_KOI_Relation){ | |
3120 | dimension_status = TheSign ==1 ? 1 : 0; | |
3121 | TheSign=-1; | |
3122 | } | |
3123 | ||
3124 | AIS_ListOfInteractive LIO; | |
3125 | TheAISContext()->ObjectsInside(LIO,TheType,TheSign); | |
3126 | Handle(AIS_InteractiveObject) curio; | |
3127 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ | |
3128 | curio = it.Value(); | |
3129 | if(dimension_status == -1) | |
3130 | TheAISContext()->Display(curio,Standard_False); | |
3131 | else { | |
3132 | AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension(); | |
3133 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| | |
3134 | (dimension_status==1 && KOD != AIS_KOD_NONE)) | |
3135 | TheAISContext()->Display(curio,Standard_False); | |
3136 | } | |
3137 | ||
3138 | } | |
3139 | ||
3140 | TheAISContext()->UpdateCurrentViewer(); | |
3141 | return 0; | |
3142 | } | |
3143 | ||
3144 | //============================================================================== | |
3145 | //function : VSetTransMode | |
3146 | //purpose : | |
3147 | //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z] | |
3148 | //============================================================================== | |
3149 | ||
3150 | static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
3151 | // Verification des arguments | |
3152 | if ( a3DView().IsNull() ) { | |
3153 | ViewerTest::ViewerInit(); | |
3154 | di << "La commande vinit n'a pas ete appele avant" << "\n"; | |
3155 | } | |
3156 | ||
3157 | if ( argc < 3 || argc > 8 ) { | |
3158 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
3159 | return 1; | |
3160 | } | |
3161 | ||
3162 | TCollection_AsciiString shapeName; | |
3163 | shapeName = argv[1]; | |
3164 | Standard_Integer persFlag1 = atoi(argv[2]); | |
3165 | Standard_Integer persFlag2 = 0; | |
3166 | Standard_Integer persFlag3 = 0; | |
3167 | gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 ); | |
3168 | if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) { | |
3169 | persFlag2 = atoi(argv[3]); | |
3170 | } | |
3171 | if ( argc == 5 || argc == 8 ) { | |
3172 | persFlag3 = atoi(argv[4]); | |
3173 | } | |
3174 | if ( argc >= 6 ) { | |
3175 | origin.SetX( atof(argv[argc - 3]) ); | |
3176 | origin.SetY( atof(argv[argc - 2]) ); | |
3177 | origin.SetZ( atof(argv[argc - 1]) ); | |
3178 | } | |
3179 | ||
3180 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName); | |
7fd59977 | 3181 | Handle(Standard_Transient) anObj; |
3182 | if ( IsBound ) { | |
3183 | anObj = GetMapOfAIS().Find2(shapeName); | |
3184 | if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) { | |
3185 | Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj); | |
3186 | aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin ); | |
3187 | if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) { | |
3188 | di << argv[0] << " All persistence modifiers were removed" << "\n"; | |
3189 | } | |
3190 | } else { | |
3191 | di << argv[0] << " Wrong object type" << "\n"; | |
3192 | return 1; | |
3193 | } | |
3194 | } else { // Create the AIS_Shape from a name | |
3195 | const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString()); | |
3196 | if ( !aShape.IsNull() ) { | |
3197 | GetMapOfAIS().Bind( aShape, shapeName ); | |
3198 | aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin ); | |
3199 | TheAISContext()->Display( aShape, Standard_False ); | |
3200 | } else { | |
3201 | di << argv[0] << " Object not found" << "\n"; | |
3202 | return 1; | |
3203 | } | |
3204 | } | |
3205 | ||
3206 | // Upadate the screen and redraw the view | |
3207 | TheAISContext()->UpdateCurrentViewer(); | |
3208 | return 0; | |
3209 | } | |
3210 | ||
3211 | static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a) | |
3212 | { | |
3213 | ifstream s(a[1]); | |
3214 | BRep_Builder builder; | |
3215 | TopoDS_Shape shape; | |
3216 | BRepTools::Read(shape, s, builder); | |
3217 | DBRep::Set(a[1], shape); | |
3218 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
3219 | Handle(AIS_Shape) ais = new AIS_Shape(shape); | |
3220 | Ctx->Display(ais); | |
3221 | return 0; | |
3222 | } | |
3223 | //============================================================================ | |
3224 | #include <AIS2D_InteractiveContext.hxx> | |
3225 | #include <HLRAlgo_Projector.hxx> | |
3226 | #include <Prs3d_Projector.hxx> | |
3227 | #include <AIS2D_ProjShape.hxx> | |
3228 | #include <gp_Ax2.hxx> | |
3229 | #include <gp.hxx> | |
3230 | Standard_Integer hlrtest(Draw_Interpretor&, Standard_Integer n, const char** a) | |
3231 | { | |
3232 | ||
3233 | Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext(); | |
3234 | ///////////////////// | |
3235 | TopoDS_Shape aShape = DBRep::Get(a[1]); | |
3236 | aContext2D->EraseAll(Standard_True); | |
6e6cd5d9 | 3237 | //Standard_Integer aPolyAlgo = 0; |
7fd59977 | 3238 | Standard_Boolean IsPoly = Standard_False; |
3239 | gp_Ax2 anAx2 = gp::XOY(); | |
3240 | ||
3241 | //if(n > 2) aPolyAlgo = atoi(a[2]); | |
3242 | ||
3243 | //IsPoly = aPolyAlgo > 0; | |
3244 | ||
3245 | TopoDS_Shape aResult = aShape; | |
3246 | ||
3247 | ||
3248 | if (n == 11) | |
3249 | { | |
3250 | Standard_Real x = atof(a[2]); | |
3251 | Standard_Real y = atof(a[3]); | |
3252 | Standard_Real z = atof(a[4]); | |
3253 | ||
3254 | Standard_Real dx = atof(a[5]); | |
3255 | Standard_Real dy = atof(a[6]); | |
3256 | Standard_Real dz = atof(a[7]); | |
3257 | ||
3258 | Standard_Real dx1 = atof(a[8]); | |
3259 | Standard_Real dy1 = atof(a[9]); | |
3260 | Standard_Real dz1 = atof(a[10]); | |
3261 | ||
3262 | gp_Pnt anOrigin (x, y, z); | |
3263 | gp_Dir aNormal (dx, dy, dz); | |
3264 | gp_Dir aDX (dx1, dy1, dz1); | |
3265 | anAx2 = gp_Ax2(anOrigin, aNormal, aDX); | |
3266 | } | |
3267 | ||
3268 | ||
3269 | HLRAlgo_Projector aProjector(anAx2); | |
3270 | ||
3271 | //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0); | |
3272 | ||
3273 | //aProjector = aProjector_t.Projector(); | |
3274 | ||
3275 | Handle(AIS2D_ProjShape) myDisplayableShape = | |
3276 | new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False); | |
3277 | ||
3278 | myDisplayableShape->ShowEdges(Standard_True, Standard_False, | |
3279 | Standard_False, Standard_True, Standard_False); | |
3280 | ||
3281 | myDisplayableShape->Add( aResult ); | |
3282 | ||
3283 | ||
3284 | aContext2D->Display( myDisplayableShape,Standard_True ); | |
3285 | aContext2D->UpdateCurrentViewer(); | |
3286 | ||
3287 | return 0; | |
3288 | } | |
3289 | ||
3290 | Standard_Integer phlrtest(Draw_Interpretor&, Standard_Integer n, const char** a) | |
3291 | { | |
3292 | ||
3293 | Handle(AIS2D_InteractiveContext) aContext2D = Viewer2dTest::GetAIS2DContext(); | |
3294 | ///////////////////// | |
3295 | TopoDS_Shape aShape = DBRep::Get(a[1]); | |
3296 | aContext2D->EraseAll(Standard_True); | |
6e6cd5d9 | 3297 | //Standard_Integer aPolyAlgo = 0; |
7fd59977 | 3298 | Standard_Boolean IsPoly = Standard_True; |
3299 | gp_Ax2 anAx2 = gp::XOY(); | |
3300 | ||
3301 | //if(n > 2) aPolyAlgo = atoi(a[2]); | |
3302 | ||
3303 | //IsPoly = aPolyAlgo > 0; | |
3304 | ||
3305 | TopoDS_Shape aResult = aShape; | |
3306 | ||
3307 | ||
3308 | if (n == 11) | |
3309 | { | |
3310 | Standard_Real x = atof(a[2]); | |
3311 | Standard_Real y = atof(a[3]); | |
3312 | Standard_Real z = atof(a[4]); | |
3313 | ||
3314 | Standard_Real dx = atof(a[5]); | |
3315 | Standard_Real dy = atof(a[6]); | |
3316 | Standard_Real dz = atof(a[7]); | |
3317 | ||
3318 | Standard_Real dx1 = atof(a[8]); | |
3319 | Standard_Real dy1 = atof(a[9]); | |
3320 | Standard_Real dz1 = atof(a[10]); | |
3321 | ||
3322 | gp_Pnt anOrigin (x, y, z); | |
3323 | gp_Dir aNormal (dx, dy, dz); | |
3324 | gp_Dir aDX (dx1, dy1, dz1); | |
3325 | anAx2 = gp_Ax2(anOrigin, aNormal, aDX); | |
3326 | } | |
3327 | ||
3328 | ||
3329 | HLRAlgo_Projector aProjector(anAx2); | |
3330 | ||
3331 | //Prs3d_Projector aProjector_t(Standard_False,1, 0,0,1,0,0,1000,0,1,0); | |
3332 | ||
3333 | //aProjector = aProjector_t.Projector(); | |
3334 | ||
3335 | Handle(AIS2D_ProjShape) myDisplayableShape = | |
3336 | new AIS2D_ProjShape(aProjector,0,IsPoly, Standard_False); | |
3337 | ||
3338 | myDisplayableShape->ShowEdges(Standard_True, Standard_False, | |
3339 | Standard_False, Standard_True, Standard_False); | |
3340 | ||
3341 | myDisplayableShape->Add( aResult ); | |
3342 | ||
3343 | ||
3344 | aContext2D->Display( myDisplayableShape,Standard_True ); | |
3345 | aContext2D->UpdateCurrentViewer(); | |
3346 | ||
3347 | return 0; | |
3348 | } | |
3349 | ||
3350 | //============================================================================== | |
3351 | //function : ViewerTest::Commands | |
3352 | //purpose : Add all the viewer command in the Draw_Interpretor | |
3353 | //============================================================================== | |
3354 | ||
3355 | void ViewerTest::Commands(Draw_Interpretor& theCommands) | |
3356 | { | |
3357 | ViewerTest::ViewerCommands(theCommands); | |
3358 | ViewerTest::RelationCommands(theCommands); | |
3359 | ViewerTest::ObjectCommands(theCommands); | |
3360 | ViewerTest::FilletCommands(theCommands); | |
3361 | ViewerTest::VoxelCommands(theCommands); | |
3362 | ||
3363 | const char *group = "AIS_Display"; | |
3364 | ||
3365 | // display | |
3366 | ||
3367 | theCommands.Add("vdisplay", | |
3368 | "vdisplay : vdisplay2 name1 [name2] ... [name n] ", | |
3369 | __FILE__,VDisplay2,group); | |
3370 | ||
3371 | theCommands.Add("verase", | |
3372 | "verase : verase2 [name1] ... [name n] ", | |
3373 | __FILE__,VErase2,group); | |
3374 | ||
3375 | theCommands.Add("vdonly", | |
3376 | "vdonly : vdonly2 [name1] ... [name n]", | |
3377 | __FILE__,VDonly2,group); | |
3378 | ||
3379 | theCommands.Add("vdisplayall", | |
3380 | "vdisplayall : vdisplayall", | |
3381 | __FILE__,VDisplayAll,group); | |
3382 | ||
3383 | theCommands.Add("veraseall", | |
3384 | "veraseall : veraseall ", | |
3385 | __FILE__,VEraseAll,group); | |
3386 | ||
3387 | theCommands.Add("verasetype", | |
3388 | "verasetype : verasetype <Type> \n\t erase all the displayed objects of one given kind (see vtypes)", | |
3389 | __FILE__,VEraseType,group); | |
3390 | ||
3391 | theCommands.Add("vdisplaytype", | |
3392 | "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ", | |
3393 | __FILE__,VDisplayType,group); | |
3394 | ||
3395 | theCommands.Add("vdisplaymode", | |
3396 | "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ", | |
3397 | __FILE__,VDispMode,group); | |
3398 | ||
3399 | theCommands.Add("verasemode", | |
3400 | "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects", | |
3401 | __FILE__,VDispMode,group); | |
3402 | ||
3403 | theCommands.Add("vsetdispmode", | |
3404 | "vsetdispmode : vsetdispmode [name] mode(1,2,..): no name -> on selected objects ", | |
3405 | __FILE__,VDispMode,group); | |
3406 | ||
3407 | theCommands.Add("vunsetdispmode", | |
3408 | "vunsetdispmode : vunsetdispmode [name] mode(1,2,..): no name -> on selected objects", | |
3409 | __FILE__,VDispMode,group); | |
3410 | ||
3411 | theCommands.Add("vdir", | |
3412 | "vdir", | |
3413 | __FILE__,VDebug,group); | |
3414 | ||
3415 | theCommands.Add("vdump", | |
3416 | "<filename>.{png|bmp|jpg|gif} [buffer={rgb|rgba|depth}] [width height]\n\t\t: Dump contents of viewer window to PNG, BMP, JPEG or GIF file", | |
3417 | __FILE__,VDump,group); | |
3418 | ||
3419 | theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects", | |
3420 | __FILE__,VSubInt,group); | |
3421 | ||
3422 | theCommands.Add("vsetcolor", | |
3423 | "vsetcolor : vsetcolor [name of shape] ColorName", | |
3424 | __FILE__,VColor2,group); | |
3425 | ||
3426 | theCommands.Add("vunsetcolor", | |
3427 | "vunsetcolor : vunsetcolor [name of shape] ", | |
3428 | __FILE__,VColor2,group); | |
3429 | ||
3430 | theCommands.Add("vsettransparency", | |
3431 | "vsettransparency : vtransparency [name of shape] TransparenctCoef (0 -> 1)", | |
3432 | __FILE__,VTransparency,group); | |
3433 | ||
3434 | theCommands.Add("vunsettransparency", | |
3435 | "vunsettransparency : vtransparency [name of shape]", | |
3436 | __FILE__,VTransparency,group); | |
3437 | ||
3438 | theCommands.Add("vsetmaterial", | |
3439 | "vmaterial : vmaterial [name of shape] MaterialName", | |
3440 | __FILE__,VMaterial,group); | |
3441 | ||
3442 | theCommands.Add("vunsetmaterial", | |
3443 | "vmaterial : vmaterial [name of shape]", | |
3444 | __FILE__,VMaterial,group); | |
3445 | ||
3446 | theCommands.Add("vsetwidth", | |
3447 | "vsetwidth : vwidth [name of shape] width(0->10)", | |
3448 | __FILE__,VWidth,group); | |
3449 | ||
3450 | theCommands.Add("vunsetwidth", | |
3451 | "vunsetwidth : vwidth [name of shape]", | |
3452 | __FILE__,VWidth,group); | |
3453 | ||
3454 | theCommands.Add("vardis", | |
3455 | "vardis : display activeareas", | |
3456 | __FILE__,VDispAreas,group); | |
3457 | ||
3458 | theCommands.Add("varera", | |
3459 | "varera : erase activeareas", | |
3460 | __FILE__,VClearAreas,group); | |
3461 | ||
3462 | theCommands.Add("vsensdis", | |
3463 | "vardisp : display active entities", | |
3464 | __FILE__,VDispSensi,group); | |
3465 | theCommands.Add("vsensera", | |
3466 | "vardisp : erase active entities", | |
3467 | __FILE__,VClearSensi,group); | |
3468 | ||
3469 | theCommands.Add("vperf", | |
3470 | "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)", | |
3471 | __FILE__,VPerf,group); | |
3472 | ||
3473 | theCommands.Add("vanimation", | |
3474 | "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile", | |
3475 | __FILE__,VAnimation,group); | |
3476 | ||
3477 | theCommands.Add("vsetshading", | |
3478 | "vsetshading : vsetshading name Quality(default=0.0008) ", | |
3479 | __FILE__,VShading,group); | |
3480 | ||
3481 | theCommands.Add("vunsetshading", | |
3482 | "vunsetshading :vunsetshading name ", | |
3483 | __FILE__,VShading,group); | |
3484 | ||
3485 | theCommands.Add("vtexture", | |
3486 | "'vtexture NameOfShape TextureFile' \n \ | |
3487 | or 'vtexture NameOfShape' if you want to disable texture mapping \n \ | |
3488 | or 'vtexture NameOfShape ?' to list available textures\n \ | |
3489 | or 'vtexture NameOfShape IdOfTexture' (0<=IdOfTexture<=20)' to use predefined textures\n ", | |
3490 | __FILE__,VTexture,group); | |
3491 | ||
3492 | theCommands.Add("vtexscale", | |
3493 | "'vtexscale NameOfShape ScaleU ScaleV' \n \ | |
3494 | or 'vtexscale NameOfShape ScaleUV' \n \ | |
3495 | or 'vtexscale NameOfShape' to disable scaling\n ", | |
3496 | __FILE__,VTexture,group); | |
3497 | ||
3498 | theCommands.Add("vtexorigin", | |
3499 | "'vtexorigin NameOfShape UOrigin VOrigin' \n \ | |
3500 | or 'vtexorigin NameOfShape UVOrigin' \n \ | |
3501 | or 'vtexorigin NameOfShape' to disable origin positioning\n ", | |
3502 | __FILE__,VTexture,group); | |
3503 | ||
3504 | theCommands.Add("vtexrepeat", | |
3505 | "'vtexrepeat NameOfShape URepeat VRepeat' \n \ | |
3506 | or 'vtexrepeat NameOfShape UVRepeat \n \ | |
3507 | or 'vtexrepeat NameOfShape' to disable texture repeat \n ", | |
3508 | VTexture,group); | |
3509 | ||
3510 | theCommands.Add("vtexdefault", | |
3511 | "'vtexdefault NameOfShape' to set texture mapping default parameters \n", | |
3512 | VTexture,group); | |
3513 | ||
3514 | theCommands.Add("vsetam", | |
3515 | "vsetActivatedModes: vsetam mode(1->7) ", | |
3516 | __FILE__,VActivatedMode,group); | |
3517 | ||
3518 | theCommands.Add("vunsetam", | |
3519 | "vunsetActivatedModes: vunsetam ", | |
3520 | __FILE__,VActivatedMode,group); | |
3521 | ||
3522 | theCommands.Add("vstate", "vstate [Name1] ... [NameN] :No arg, select currents; no currrent select all ", | |
3523 | __FILE__,VState,group); | |
3524 | ||
3525 | theCommands.Add("vpickshapes", | |
3526 | "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]", | |
3527 | __FILE__,VPickShape,group); | |
3528 | ||
3529 | theCommands.Add("vtypes", | |
3530 | "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters", | |
3531 | VIOTypes,group); | |
3532 | ||
3533 | theCommands.Add("vsettransmode", | |
3534 | "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]", | |
3535 | __FILE__,VSetTransMode,group); | |
3536 | ||
3537 | theCommands.Add("vr", "vr : reading of the shape", | |
3538 | __FILE__,vr, group); | |
3539 | ||
3540 | theCommands.Add("hlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, hlrtest, group); | |
3541 | theCommands.Add("phlrtest" , "Usage: hlrtest s1 s2 ...", __FILE__, phlrtest, group); | |
3542 | ||
3543 | } | |
3544 | ||
3545 | //===================================================================== | |
3546 | //========================= for testing Draft and Rib ================= | |
3547 | //===================================================================== | |
3548 | #include <BRepOffsetAPI_MakeThickSolid.hxx> | |
3549 | #include <DBRep.hxx> | |
3550 | #include <TopoDS_Face.hxx> | |
3551 | #include <gp_Pln.hxx> | |
3552 | #include <AIS_KindOfSurface.hxx> | |
3553 | #include <BRepOffsetAPI_DraftAngle.hxx> | |
3554 | #include <Precision.hxx> | |
3555 | #include <BRepAlgo.hxx> | |
3556 | #include <OSD_Environment.hxx> | |
3557 | #include <DrawTrSurf.hxx> | |
3558 | //#include <DbgTools.hxx> | |
3559 | //#include <FeatAlgo_MakeLinearForm.hxx> | |
3560 | ||
3561 | ||
3562 | ||
3563 | ||
3564 | //======================================================================= | |
3565 | //function : IsValid | |
3566 | //purpose : | |
3567 | //======================================================================= | |
3568 | static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs, | |
3569 | const TopoDS_Shape& theResult, | |
3570 | const Standard_Boolean closedSolid, | |
3571 | const Standard_Boolean GeomCtrl) | |
3572 | { | |
3573 | OSD_Environment check ("DONT_SWITCH_IS_VALID") ; | |
3574 | TCollection_AsciiString checkValid = check.Value(); | |
3575 | Standard_Boolean ToCheck = Standard_True; | |
3576 | if (!checkValid.IsEmpty()) { | |
3577 | #ifdef DEB | |
3578 | cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n"; | |
3579 | #endif | |
3580 | if ( checkValid=="true" || checkValid=="TRUE" ) { | |
3581 | ToCheck= Standard_False; | |
3582 | } | |
3583 | } else { | |
3584 | #ifdef DEB | |
3585 | cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n"; | |
3586 | #endif | |
3587 | } | |
3588 | Standard_Boolean IsValid = Standard_True; | |
3589 | if (ToCheck) | |
3590 | IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ; | |
3591 | return IsValid; | |
3592 | ||
3593 | } | |
3594 | ||
3595 | //=============================================================================== | |
3596 | // TDraft : test draft, uses AIS Viewer | |
3597 | // Solid Face Plane Angle Reverse | |
3598 | //=============================================================================== | |
3599 | static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3600 | { | |
3601 | if (argc < 5) return 1; | |
3602 | // argv[1] - TopoDS_Shape Solid | |
3603 | // argv[2] - TopoDS_Shape Face | |
3604 | // argv[3] - TopoDS_Shape Plane | |
3605 | // argv[4] - Standard_Real Angle | |
3606 | // argv[5] - Standard_Integer Reverse | |
3607 | ||
3608 | // sprintf(prefix, argv[1]); | |
3609 | Standard_Real anAngle = 0; | |
3610 | Standard_Boolean Rev = Standard_False; | |
3611 | Standard_Integer rev = 0; | |
3612 | TopoDS_Shape Solid = GetShapeFromName(argv[1]); | |
3613 | TopoDS_Shape face = GetShapeFromName(argv[2]); | |
3614 | TopoDS_Face Face = TopoDS::Face(face); | |
3615 | TopoDS_Shape Plane = GetShapeFromName(argv[3]); | |
3616 | if (Plane.IsNull ()) { | |
3617 | di << "TEST : Plane is NULL" << "\n"; | |
3618 | return 1; | |
3619 | } | |
3620 | anAngle = atof(argv[4]); | |
c6541a0c | 3621 | anAngle = 2*M_PI * anAngle / 360.0; |
7fd59977 | 3622 | gp_Pln aPln; |
3623 | Handle( Geom_Surface )aSurf; | |
3624 | AIS_KindOfSurface aSurfType; | |
3625 | Standard_Real Offset; | |
3626 | gp_Dir aDir; | |
3627 | if(argc > 4) { // == 5 | |
3628 | rev = atoi(argv[5]); | |
3629 | Rev = (rev)? Standard_True : Standard_False; | |
3630 | } | |
3631 | ||
3632 | TopoDS_Face face2 = TopoDS::Face(Plane); | |
3633 | if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset)) | |
3634 | { | |
3635 | di << "TEST : Can't find plane" << "\n"; | |
3636 | return 1; | |
3637 | } | |
3638 | ||
3639 | aDir = aPln.Axis().Direction(); | |
3640 | if (!aPln.Direct()) | |
3641 | aDir.Reverse(); | |
3642 | if (Plane.Orientation() == TopAbs_REVERSED) | |
3643 | aDir.Reverse(); | |
3644 | di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n"; | |
3645 | ||
3646 | BRepOffsetAPI_DraftAngle Draft (Solid); | |
3647 | ||
3648 | if(Abs(anAngle)< Precision::Angular()) { | |
3649 | di << "TEST : NULL angle" << "\n"; | |
3650 | return 1;} | |
3651 | ||
3652 | if(Rev) anAngle = - anAngle; | |
3653 | Draft.Add (Face, aDir, anAngle, aPln); | |
3654 | Draft.Build (); | |
3655 | if (!Draft.IsDone()) { | |
3656 | di << "TEST : Draft Not DONE " << "\n"; | |
3657 | return 1; | |
3658 | } | |
3659 | TopTools_ListOfShape Larg; | |
3660 | Larg.Append(Solid); | |
3661 | if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) { | |
3662 | di << "TEST : DesignAlgo returns Not valid" << "\n"; | |
3663 | return 1; | |
3664 | } | |
3665 | ||
3666 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
3667 | Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape()); | |
3668 | ||
3669 | if ( !ais.IsNull() ) { | |
3670 | ais->SetColor(DEFAULT_COLOR); | |
3671 | ais->SetMaterial(DEFAULT_MATERIAL); | |
3672 | // Display the AIS_Shape without redraw | |
3673 | Ctx->Display(ais, Standard_False); | |
3674 | ||
3675 | const char *Name = "draft1"; | |
3676 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name); | |
3677 | if (IsBound) { | |
3678 | Handle(AIS_InteractiveObject) an_object = | |
3679 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name)); | |
3680 | if (!an_object.IsNull()) { | |
3681 | Ctx->Remove(an_object, | |
3682 | Standard_True) ; | |
3683 | GetMapOfAIS().UnBind2(Name) ; | |
3684 | } | |
3685 | } | |
3686 | GetMapOfAIS().Bind(ais, Name); | |
3687 | // DBRep::Set("draft", ais->Shape()); | |
3688 | } | |
3689 | Ctx->Display(ais, Standard_True); | |
3690 | return 0; | |
3691 | } | |
3692 | ||
3693 | ||
3694 | ||
3695 | //============================================================================ | |
3696 | // MyCommands | |
3697 | //============================================================================ | |
3698 | void ViewerTest::MyCommands( Draw_Interpretor& theCommands) | |
3699 | { | |
3700 | ||
3701 | DrawTrSurf::BasicCommands(theCommands); | |
3702 | const char* group = "Check Features Operations commands"; | |
3703 | ||
3704 | theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse", | |
3705 | __FILE__, | |
3706 | &TDraft,group); //Draft_Modification | |
3707 | } | |
3708 | ||
3709 | //============================================================================== | |
3710 | // ViewerTest::Factory | |
3711 | //============================================================================== | |
3712 | void ViewerTest::Factory(Draw_Interpretor& theDI) | |
3713 | { | |
3714 | // definition of Viewer Command | |
3715 | ViewerTest::Commands(theDI); | |
3716 | ViewerTest::AviCommands(theDI); | |
3717 | Viewer2dTest::Commands(theDI); | |
3718 | #ifdef DEB | |
3719 | theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n"; | |
3720 | #endif | |
3721 | } | |
3722 | ||
3723 | // Declare entry point PLUGINFACTORY | |
3724 | DPLUGIN(ViewerTest) |