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