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