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