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