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