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