Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1997-07-23 |
2 | // Created by: Henri JEANNIN | |
3 | // Copyright (c) 1997-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
12 | // distribution for complete text of the license and disclaimer of any warranty. | |
7fd59977 | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
17 | // Modified by Eric Gouthiere [sep-oct 98] -> add commands for display... | |
7fd59977 | 18 | // Modified by Robert Coublanc [nov 16-17-18 1998] |
19 | // -split ViewerTest.cxx into 3 files : ViewerTest.cxx, | |
20 | // ViewerTest_ObjectCommands.cxx | |
21 | // ViewerTest_RelationCommands.cxx | |
22 | // -add Functions and commands for interactive selection of shapes and objects | |
23 | // in AIS Viewers. (PickShape(s), PickObject(s), | |
24 | ||
25 | #include <Standard_Stream.hxx> | |
26 | ||
27 | #include <ViewerTest.hxx> | |
4e18052b | 28 | |
7fd59977 | 29 | #include <TopLoc_Location.hxx> |
30 | #include <TopTools_HArray1OfShape.hxx> | |
31 | #include <TColStd_HArray1OfTransient.hxx> | |
b6d587e3 | 32 | #include <TColStd_SequenceOfAsciiString.hxx> |
900f7229 | 33 | #include <TColStd_HSequenceOfAsciiString.hxx> |
b6d587e3 | 34 | #include <TColStd_MapOfTransient.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> | |
ad3217cd | 43 | #include <AIS_ColoredShape.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> | |
cb78155f | 50 | #include <AIS_LocalContext.hxx> |
7fd59977 | 51 | #include <AIS_ListOfInteractive.hxx> |
52 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
99c56d44 | 53 | #include <Aspect_InteriorStyle.hxx> |
34db9c00 | 54 | #include <Aspect_Window.hxx> |
99c56d44 | 55 | #include <Graphic3d_AspectFillArea3d.hxx> |
1c88cbaf | 56 | #include <Graphic3d_AspectLine3d.hxx> |
a1954302 | 57 | #include <Graphic3d_CStructure.hxx> |
392ac980 | 58 | #include <Graphic3d_TextureRoot.hxx> |
692613e5 | 59 | #include <Image_AlienPixMap.hxx> |
6262338c | 60 | #include <Prs3d_Drawer.hxx> |
99c56d44 | 61 | #include <Prs3d_ShadingAspect.hxx> |
1c88cbaf | 62 | #include <Prs3d_IsoAspect.hxx> |
6262338c | 63 | #include <Prs3d_PointAspect.hxx> |
8e7c8ccf | 64 | #include <Select3D_SensitiveWire.hxx> |
65 | #include <SelectMgr_EntityOwner.hxx> | |
66 | #include <StdSelect_BRepOwner.hxx> | |
67 | #include <StdSelect_ViewerSelector3d.hxx> | |
68 | #include <Select3D_Projector.hxx> | |
cb78155f | 69 | #include <TopTools_MapOfShape.hxx> |
4e18052b | 70 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 71 | |
7fd59977 | 72 | #include <stdio.h> |
7fd59977 | 73 | |
74 | #include <Draw_Interpretor.hxx> | |
75 | #include <TCollection_AsciiString.hxx> | |
76 | #include <Draw_PluginMacro.hxx> | |
7fd59977 | 77 | |
78 | // avoid warnings on 'extern "C"' functions returning C++ classes | |
79 | #ifdef WNT | |
80 | #define _CRT_SECURE_NO_DEPRECATE | |
81 | #pragma warning(4:4190) | |
82 | #pragma warning (disable:4996) | |
83 | #endif | |
84 | ||
85 | #include <NIS_InteractiveContext.hxx> | |
86 | #include <NIS_Triangulated.hxx> | |
87 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); | |
88 | ||
7fd59977 | 89 | #include <Quantity_Color.hxx> |
90 | #include <Quantity_NameOfColor.hxx> | |
91 | ||
92 | #include <Graphic3d_NameOfMaterial.hxx> | |
93 | ||
6262338c | 94 | #define DEFAULT_COLOR Quantity_NOC_GOLDENROD |
95 | #define DEFAULT_FREEBOUNDARY_COLOR Quantity_NOC_GREEN | |
96 | #define DEFAULT_MATERIAL Graphic3d_NOM_BRASS | |
7fd59977 | 97 | |
792c785c | 98 | //======================================================================= |
99 | //function : GetColorFromName | |
100 | //purpose : get the Quantity_NameOfColor from a string | |
101 | //======================================================================= | |
7fd59977 | 102 | |
792c785c | 103 | Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theName) |
104 | { | |
8316c618 | 105 | Quantity_NameOfColor aColor = DEFAULT_COLOR; |
106 | Quantity_Color::ColorFromName (theName, aColor); | |
107 | return aColor; | |
7fd59977 | 108 | } |
109 | ||
7fd59977 | 110 | //======================================================================= |
111 | //function : GetTypeNames | |
112 | //purpose : | |
113 | //======================================================================= | |
114 | static const char** GetTypeNames() | |
115 | { | |
116 | static const char* names[14] = {"Point","Axis","Trihedron","PlaneTrihedron", "Line","Circle","Plane", | |
117 | "Shape","ConnectedShape","MultiConn.Shape", | |
118 | "ConnectedInter.","MultiConn.", | |
119 | "Constraint","Dimension"}; | |
120 | static const char** ThePointer = names; | |
121 | return ThePointer; | |
122 | } | |
123 | ||
124 | //======================================================================= | |
125 | //function : GetTypeAndSignfromString | |
126 | //purpose : | |
127 | //======================================================================= | |
128 | void GetTypeAndSignfromString (const char* name,AIS_KindOfInteractive& TheType,Standard_Integer& TheSign) | |
129 | { | |
130 | const char ** thefullnames = GetTypeNames(); | |
131 | Standard_Integer index(-1); | |
132 | ||
133 | for(Standard_Integer i=0;i<=13 && index==-1;i++) | |
134 | if(!strcasecmp(name,thefullnames[i])) | |
135 | index = i; | |
136 | ||
137 | if(index ==-1){ | |
138 | TheType = AIS_KOI_None; | |
139 | TheSign = -1; | |
140 | return; | |
141 | } | |
142 | ||
143 | if(index<=6){ | |
144 | TheType = AIS_KOI_Datum; | |
145 | TheSign = index+1; | |
146 | } | |
147 | else if (index <=9){ | |
148 | TheType = AIS_KOI_Shape; | |
149 | TheSign = index-7; | |
150 | } | |
151 | else if(index<=11){ | |
152 | TheType = AIS_KOI_Object; | |
153 | TheSign = index-10; | |
154 | } | |
155 | else{ | |
156 | TheType = AIS_KOI_Relation; | |
157 | TheSign = index-12; | |
158 | } | |
159 | ||
160 | } | |
161 | ||
162 | ||
163 | ||
164 | #include <string.h> | |
165 | #include <Draw_Interpretor.hxx> | |
166 | #include <Draw.hxx> | |
167 | #include <Draw_Appli.hxx> | |
168 | #include <DBRep.hxx> | |
169 | ||
170 | ||
171 | #include <TCollection_AsciiString.hxx> | |
172 | #include <V3d_Viewer.hxx> | |
173 | #include <V3d_View.hxx> | |
174 | #include <V3d.hxx> | |
175 | ||
176 | #include <AIS_InteractiveContext.hxx> | |
177 | #include <AIS_Shape.hxx> | |
178 | #include <AIS_TexturedShape.hxx> | |
179 | #include <AIS_DisplayMode.hxx> | |
180 | #include <TColStd_MapOfInteger.hxx> | |
181 | #include <AIS_MapOfInteractive.hxx> | |
182 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> | |
183 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
184 | #include <ViewerTest_EventManager.hxx> | |
185 | ||
186 | #include <TopoDS_Solid.hxx> | |
187 | #include <BRepTools.hxx> | |
188 | #include <BRep_Builder.hxx> | |
189 | #include <TopAbs_ShapeEnum.hxx> | |
190 | ||
191 | #include <TopoDS.hxx> | |
192 | #include <BRep_Tool.hxx> | |
193 | ||
194 | ||
195 | #include <Draw_Window.hxx> | |
196 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
197 | #include <AIS_ListOfInteractive.hxx> | |
198 | #include <AIS_DisplayMode.hxx> | |
199 | #include <TopTools_ListOfShape.hxx> | |
200 | #include <BRepOffsetAPI_MakeThickSolid.hxx> | |
201 | #include <BRepOffset.hxx> | |
202 | ||
7fd59977 | 203 | //============================================================================== |
204 | // VIEWER OBJECT MANAGEMENT GLOBAL VARIABLES | |
205 | //============================================================================== | |
206 | Standard_EXPORT ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(){ | |
207 | static ViewerTest_DoubleMapOfInteractiveAndName TheMap; | |
208 | return TheMap; | |
209 | } | |
210 | ||
9558a876 A |
211 | |
212 | //============================================================================== | |
213 | //function : VDisplayAISObject | |
214 | //purpose : register interactive object in the map of AIS objects; | |
215 | // if other object with such name already registered, it will be kept | |
216 | // or replaced depending on value of <theReplaceIfExists>, | |
217 | // if "true" - the old object will be cleared from AIS context; | |
218 | // returns Standard_True if <theAISObj> registered in map; | |
219 | //============================================================================== | |
220 | Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, | |
221 | const Handle(AIS_InteractiveObject)& theAISObj, | |
222 | Standard_Boolean theReplaceIfExists = Standard_True) | |
223 | { | |
224 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
225 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
226 | if (aContextAIS.IsNull()) | |
227 | { | |
228 | std::cout << "AIS context is not available.\n"; | |
229 | return Standard_False; | |
230 | } | |
231 | ||
232 | if (aMap.IsBound2 (theName)) | |
233 | { | |
234 | if (!theReplaceIfExists) | |
235 | { | |
236 | std::cout << "Other interactive object has been already " | |
237 | << "registered with name: " << theName << ".\n" | |
238 | << "Please use another name.\n"; | |
239 | return Standard_False; | |
240 | } | |
241 | ||
242 | // stop displaying object | |
243 | Handle(AIS_InteractiveObject) anOldObj = | |
244 | Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (theName)); | |
245 | ||
246 | if (!anOldObj.IsNull()) | |
2195ab96 | 247 | aContextAIS->Remove (anOldObj, Standard_True); |
9558a876 A |
248 | |
249 | // remove name and old object from map | |
250 | aMap.UnBind2 (theName); | |
251 | } | |
252 | ||
208e6839 | 253 | if (theAISObj.IsNull()) |
254 | { | |
255 | // object with specified name already unbound | |
256 | return Standard_True; | |
257 | } | |
258 | ||
9558a876 A |
259 | // unbind AIS object if was bound with another name |
260 | aMap.UnBind1 (theAISObj); | |
261 | ||
262 | // can be registered without rebinding | |
263 | aMap.Bind (theAISObj, theName); | |
264 | aContextAIS->Display (theAISObj, Standard_True); | |
265 | return Standard_True; | |
266 | } | |
267 | ||
7fd59977 | 268 | static TColStd_MapOfInteger theactivatedmodes(8); |
269 | static TColStd_ListOfTransient theEventMgrs; | |
270 | ||
271 | static void VwrTst_InitEventMgr(const Handle(NIS_View)& aView, | |
272 | const Handle(AIS_InteractiveContext)& Ctx) | |
273 | { | |
274 | theEventMgrs.Clear(); | |
275 | theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx)); | |
276 | } | |
277 | ||
24de79c3 | 278 | static Handle(V3d_View)& a3DView() |
279 | { | |
7fd59977 | 280 | static Handle(V3d_View) Viou; |
281 | return Viou; | |
282 | } | |
283 | ||
24de79c3 | 284 | |
7fd59977 | 285 | Standard_EXPORT Handle(AIS_InteractiveContext)& TheAISContext(){ |
286 | static Handle(AIS_InteractiveContext) aContext; | |
287 | return aContext; | |
288 | } | |
289 | ||
24de79c3 | 290 | const Handle(V3d_View)& ViewerTest::CurrentView() |
7fd59977 | 291 | { |
292 | return a3DView(); | |
293 | } | |
294 | void ViewerTest::CurrentView(const Handle(V3d_View)& V) | |
295 | { | |
296 | a3DView() = V; | |
297 | } | |
298 | ||
299 | Standard_EXPORT const Handle(NIS_InteractiveContext)& TheNISContext() | |
300 | { | |
301 | static Handle(NIS_InteractiveContext) aContext; | |
302 | if (aContext.IsNull()) { | |
303 | aContext = new NIS_InteractiveContext; | |
304 | aContext->SetSelectionMode (NIS_InteractiveContext::Mode_Normal); | |
305 | } | |
306 | return aContext; | |
307 | } | |
308 | ||
24de79c3 | 309 | const Handle(AIS_InteractiveContext)& ViewerTest::GetAISContext() |
7fd59977 | 310 | { |
311 | return TheAISContext(); | |
312 | } | |
313 | ||
314 | void ViewerTest::SetAISContext (const Handle(AIS_InteractiveContext)& aCtx) | |
315 | { | |
316 | TheAISContext() = aCtx; | |
317 | ViewerTest::ResetEventManager(); | |
318 | } | |
319 | ||
320 | Handle(V3d_Viewer) ViewerTest::GetViewerFromContext() | |
321 | { | |
4952a30a | 322 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
7fd59977 | 323 | } |
324 | ||
325 | Handle(V3d_Viewer) ViewerTest::GetCollectorFromContext() | |
326 | { | |
4952a30a | 327 | return !TheAISContext().IsNull() ? TheAISContext()->CurrentViewer() : Handle(V3d_Viewer)(); |
7fd59977 | 328 | } |
329 | ||
330 | ||
331 | void ViewerTest::SetEventManager(const Handle(ViewerTest_EventManager)& EM){ | |
332 | theEventMgrs.Prepend(EM); | |
333 | } | |
334 | ||
335 | void ViewerTest::UnsetEventManager() | |
336 | { | |
337 | theEventMgrs.RemoveFirst(); | |
338 | } | |
339 | ||
340 | ||
341 | void ViewerTest::ResetEventManager() | |
342 | { | |
343 | const Handle(NIS_View) aView = | |
344 | Handle(NIS_View)::DownCast(ViewerTest::CurrentView()); | |
345 | VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext()); | |
346 | } | |
347 | ||
348 | Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager() | |
349 | { | |
350 | Handle(ViewerTest_EventManager) EM; | |
351 | if(theEventMgrs.IsEmpty()) return EM; | |
352 | Handle(Standard_Transient) Tr = theEventMgrs.First(); | |
353 | EM = *((Handle(ViewerTest_EventManager)*)&Tr); | |
354 | return EM; | |
355 | } | |
356 | ||
7fd59977 | 357 | //======================================================================= |
34db9c00 | 358 | //function : Get Context and active view |
7fd59977 | 359 | //purpose : |
360 | //======================================================================= | |
34db9c00 | 361 | static Standard_Boolean getCtxAndView (Handle(AIS_InteractiveContext)& theCtx, |
362 | Handle(V3d_View)& theView) | |
7fd59977 | 363 | { |
34db9c00 | 364 | theCtx = ViewerTest::GetAISContext(); |
365 | theView = ViewerTest::CurrentView(); | |
366 | if (theCtx.IsNull() | |
367 | || theView.IsNull()) | |
7fd59977 | 368 | { |
34db9c00 | 369 | std::cout << "Error: cannot find an active view!\n"; |
370 | return Standard_False; | |
7fd59977 | 371 | } |
34db9c00 | 372 | return Standard_True; |
7fd59977 | 373 | } |
374 | ||
7fd59977 | 375 | //============================================================================== |
376 | //function : GetShapeFromName | |
377 | //purpose : Compute an Shape from a draw variable or a file name | |
378 | //============================================================================== | |
379 | ||
380 | static TopoDS_Shape GetShapeFromName(const char* name) | |
381 | { | |
382 | TopoDS_Shape S = DBRep::Get(name); | |
383 | ||
384 | if ( S.IsNull() ) { | |
385 | BRep_Builder aBuilder; | |
386 | BRepTools::Read( S, name, aBuilder); | |
387 | } | |
388 | ||
389 | return S; | |
390 | } | |
4e18e72a | 391 | |
7fd59977 | 392 | //============================================================================== |
393 | //function : GetAISShapeFromName | |
394 | //purpose : Compute an AIS_Shape from a draw variable or a file name | |
395 | //============================================================================== | |
396 | Handle(AIS_Shape) GetAISShapeFromName(const char* name) | |
397 | { | |
398 | Handle(AIS_Shape) retsh; | |
399 | ||
400 | if(GetMapOfAIS().IsBound2(name)){ | |
401 | const Handle(AIS_InteractiveObject) IO = | |
402 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
403 | if (!IO.IsNull()) { | |
eafb234b | 404 | if(IO->Type()==AIS_KOI_Shape) { |
7fd59977 | 405 | if(IO->Signature()==0){ |
406 | retsh = *((Handle(AIS_Shape)*)&IO); | |
407 | } | |
408 | else | |
409 | cout << "an Object which is not an AIS_Shape " | |
410 | "already has this name!!!"<<endl; | |
eafb234b | 411 | } |
7fd59977 | 412 | } |
413 | return retsh; | |
414 | } | |
415 | ||
416 | ||
417 | TopoDS_Shape S = GetShapeFromName(name); | |
418 | if ( !S.IsNull() ) { | |
419 | retsh = new AIS_Shape(S); | |
420 | } | |
421 | return retsh; | |
422 | } | |
423 | ||
424 | ||
425 | //============================================================================== | |
426 | //function : Clear | |
427 | //purpose : Remove all the object from the viewer | |
428 | //============================================================================== | |
429 | void ViewerTest::Clear() | |
430 | { | |
431 | if ( !a3DView().IsNull() ) { | |
432 | if (TheAISContext()->HasOpenedContext()) | |
433 | TheAISContext()->CloseLocalContext(); | |
434 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it(GetMapOfAIS()); | |
435 | while ( it.More() ) { | |
436 | cout << "Remove " << it.Key2() << endl; | |
437 | if (it.Key1()->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
438 | const Handle(AIS_InteractiveObject) anObj = | |
439 | Handle(AIS_InteractiveObject)::DownCast (it.Key1()); | |
440 | TheAISContext()->Remove(anObj,Standard_False); | |
441 | } else if (it.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) { | |
442 | const Handle(NIS_InteractiveObject) anObj = | |
443 | Handle(NIS_InteractiveObject)::DownCast (it.Key1()); | |
ffe2bea7 | 444 | TheNISContext()->Remove(anObj); |
7fd59977 | 445 | } |
446 | it.Next(); | |
447 | } | |
448 | TheAISContext()->UpdateCurrentViewer(); | |
ffe2bea7 | 449 | // TheNISContext()->UpdateViews(); |
7fd59977 | 450 | GetMapOfAIS().Clear(); |
451 | } | |
452 | } | |
453 | ||
454 | //============================================================================== | |
455 | //function : StandardModesActivation | |
456 | //purpose : Activate a selection mode, vertex, edge, wire ..., in a local | |
457 | // Context | |
458 | //============================================================================== | |
459 | void ViewerTest::StandardModeActivation(const Standard_Integer mode ) | |
460 | { | |
461 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
462 | if(mode==0) { | |
463 | if (TheAISContext()->HasOpenedContext()) | |
464 | aContext->CloseLocalContext(); | |
465 | } else { | |
466 | ||
467 | if(!aContext->HasOpenedContext()) { | |
468 | // To unhilight the preselected object | |
469 | aContext->UnhilightCurrents(Standard_False); | |
470 | // Open a local Context in order to be able to select subshape from | |
471 | // the selected shape if any or for all if there is no selection | |
472 | if (!aContext->FirstCurrentObject().IsNull()){ | |
473 | aContext->OpenLocalContext(Standard_False); | |
474 | ||
475 | for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()){ | |
476 | aContext->Load( aContext->Current(),-1,Standard_True); | |
477 | } | |
478 | } | |
479 | else | |
480 | aContext->OpenLocalContext(); | |
481 | } | |
482 | ||
483 | const char *cmode="???"; | |
484 | ||
485 | switch (mode) { | |
486 | case 0: cmode = "Shape"; break; | |
487 | case 1: cmode = "Vertex"; break; | |
488 | case 2: cmode = "Edge"; break; | |
489 | case 3: cmode = "Wire"; break; | |
490 | case 4: cmode = "Face"; break; | |
491 | case 5: cmode = "Shell"; break; | |
492 | case 6: cmode = "Solid"; break; | |
4754e164 | 493 | case 7: cmode = "Compsolid"; break; |
494 | case 8: cmode = "Compound"; break; | |
7fd59977 | 495 | } |
496 | ||
497 | if(theactivatedmodes.Contains(mode)) | |
498 | { // Desactivate | |
499 | aContext->DeactivateStandardMode(AIS_Shape::SelectionType(mode)); | |
500 | theactivatedmodes.Remove(mode); | |
501 | cout<<"Mode "<< cmode <<" OFF"<<endl; | |
502 | } | |
503 | else | |
504 | { // Activate | |
505 | aContext->ActivateStandardMode(AIS_Shape::SelectionType(mode)); | |
506 | theactivatedmodes.Add(mode); | |
507 | cout<<"Mode "<< cmode << " ON" << endl; | |
508 | } | |
509 | } | |
510 | } | |
511 | ||
1c88cbaf | 512 | //============================================================================== |
513 | //function : CopyIsoAspect | |
514 | //purpose : Returns copy Prs3d_IsoAspect with new number of isolines. | |
515 | //============================================================================== | |
516 | static Handle(Prs3d_IsoAspect) CopyIsoAspect | |
517 | (const Handle(Prs3d_IsoAspect) &theIsoAspect, | |
518 | const Standard_Integer theNbIsos) | |
519 | { | |
520 | Quantity_Color aColor; | |
521 | Aspect_TypeOfLine aType; | |
522 | Standard_Real aWidth; | |
523 | ||
524 | theIsoAspect->Aspect()->Values(aColor, aType, aWidth); | |
525 | ||
526 | Handle(Prs3d_IsoAspect) aResult = | |
527 | new Prs3d_IsoAspect(aColor, aType, aWidth, theNbIsos); | |
528 | ||
529 | return aResult; | |
530 | } | |
531 | ||
532 | //============================================================================== | |
533 | //function : visos | |
534 | //purpose : Returns or sets the number of U- and V- isos and isIsoOnPlane flag | |
535 | //Draw arg : [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)] | |
536 | //============================================================================== | |
537 | static int visos (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
538 | { | |
539 | if (TheAISContext().IsNull()) { | |
540 | di << argv[0] << " Call 'vinit' before!\n"; | |
541 | return 1; | |
542 | } | |
543 | ||
544 | if (argc <= 1) { | |
545 | di << "Current number of isos : " << | |
546 | TheAISContext()->IsoNumber(AIS_TOI_IsoU) << " " << | |
547 | TheAISContext()->IsoNumber(AIS_TOI_IsoV) << "\n"; | |
548 | di << "IsoOnPlane mode is " << | |
549 | (TheAISContext()->IsoOnPlane() ? "ON" : "OFF") << "\n"; | |
550 | ||
551 | return 0; | |
552 | } | |
553 | ||
554 | Standard_Integer aLastInd = argc - 1; | |
555 | Standard_Boolean isChanged = Standard_False; | |
1d47d8d0 | 556 | Standard_Integer aNbUIsos = 0; |
557 | Standard_Integer aNbVIsos = 0; | |
1c88cbaf | 558 | |
559 | if (aLastInd >= 3) { | |
560 | Standard_Boolean isIsoOnPlane = Standard_False; | |
561 | ||
562 | if (strcmp(argv[aLastInd], "1") == 0) { | |
563 | isIsoOnPlane = Standard_True; | |
564 | isChanged = Standard_True; | |
565 | } else if (strcmp(argv[aLastInd], "0") == 0) { | |
566 | isIsoOnPlane = Standard_False; | |
567 | isChanged = Standard_True; | |
568 | } | |
569 | ||
570 | if (isChanged) { | |
571 | aNbVIsos = Draw::Atoi(argv[aLastInd - 1]); | |
572 | aNbUIsos = Draw::Atoi(argv[aLastInd - 2]); | |
573 | aLastInd -= 3; | |
574 | ||
575 | di << "New number of isos : " << aNbUIsos << " " << aNbVIsos << "\n"; | |
576 | di << "New IsoOnPlane mode is " << (isIsoOnPlane ? "ON" : "OFF") << "\n"; | |
577 | ||
578 | TheAISContext()->IsoOnPlane(isIsoOnPlane); | |
579 | ||
580 | if (aLastInd == 0) { | |
581 | // If there are no shapes provided set the default numbers. | |
582 | TheAISContext()->SetIsoNumber(aNbUIsos, AIS_TOI_IsoU); | |
583 | TheAISContext()->SetIsoNumber(aNbVIsos, AIS_TOI_IsoV); | |
584 | } | |
585 | } | |
586 | } | |
587 | ||
588 | Standard_Integer i; | |
589 | ||
590 | for (i = 1; i <= aLastInd; i++) { | |
591 | TCollection_AsciiString name(argv[i]); | |
592 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(name); | |
593 | ||
594 | if (IsBound) { | |
595 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(name); | |
596 | if (anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject))) { | |
597 | const Handle(AIS_InteractiveObject) aShape = | |
598 | Handle(AIS_InteractiveObject)::DownCast (anObj); | |
6262338c | 599 | Handle(Prs3d_Drawer) CurDrawer = aShape->Attributes(); |
1c88cbaf | 600 | Handle(Prs3d_IsoAspect) aUIso = CurDrawer->UIsoAspect(); |
601 | Handle(Prs3d_IsoAspect) aVIso = CurDrawer->VIsoAspect(); | |
602 | ||
603 | if (isChanged) { | |
604 | CurDrawer->SetUIsoAspect(CopyIsoAspect(aUIso, aNbUIsos)); | |
605 | CurDrawer->SetVIsoAspect(CopyIsoAspect(aVIso, aNbVIsos)); | |
606 | TheAISContext()->SetLocalAttributes | |
607 | (aShape, CurDrawer, Standard_False); | |
608 | TheAISContext()->Redisplay(aShape); | |
609 | } else { | |
610 | di << "Number of isos for " << argv[i] << " : " | |
611 | << aUIso->Number() << " " << aVIso->Number() << "\n"; | |
612 | } | |
613 | } else { | |
614 | di << argv[i] << ": Not an AIS interactive object!\n"; | |
615 | } | |
616 | } else { | |
617 | di << argv[i] << ": Use 'vdisplay' before\n"; | |
618 | } | |
619 | } | |
620 | ||
621 | if (isChanged) { | |
622 | TheAISContext()->UpdateCurrentViewer(); | |
623 | } | |
624 | ||
625 | return 0; | |
626 | } | |
627 | ||
7fd59977 | 628 | //============================================================================== |
629 | //function : VDispAreas,VDispSensitive,... | |
34db9c00 | 630 | //purpose : |
7fd59977 | 631 | //============================================================================== |
34db9c00 | 632 | static Standard_Integer VDispAreas (Draw_Interpretor& , |
633 | Standard_Integer theArgNb, | |
634 | Standard_CString* ) | |
7fd59977 | 635 | { |
34db9c00 | 636 | if (theArgNb > 1) |
637 | { | |
638 | std::cout << "Error: wrong syntax!\n"; | |
639 | return 1; | |
640 | } | |
641 | ||
642 | Handle(AIS_InteractiveContext) aCtx; | |
643 | Handle(V3d_View) aView; | |
644 | if (!getCtxAndView (aCtx, aView)) | |
645 | { | |
646 | return 1; | |
647 | } | |
7fd59977 | 648 | |
34db9c00 | 649 | aCtx->DisplayActiveAreas (aView); |
7fd59977 | 650 | return 0; |
651 | } | |
34db9c00 | 652 | static Standard_Integer VClearAreas (Draw_Interpretor& , |
653 | Standard_Integer theArgNb, | |
654 | Standard_CString* ) | |
7fd59977 | 655 | { |
34db9c00 | 656 | if (theArgNb > 1) |
657 | { | |
658 | std::cout << "Error: wrong syntax!\n"; | |
659 | return 1; | |
660 | } | |
661 | ||
662 | Handle(AIS_InteractiveContext) aCtx; | |
663 | Handle(V3d_View) aView; | |
664 | if (!getCtxAndView (aCtx, aView)) | |
665 | { | |
666 | return 1; | |
667 | } | |
668 | ||
669 | aCtx->ClearActiveAreas (aView); | |
7fd59977 | 670 | return 0; |
671 | ||
672 | } | |
34db9c00 | 673 | static Standard_Integer VDispSensi (Draw_Interpretor& , |
674 | Standard_Integer theArgNb, | |
675 | Standard_CString* ) | |
7fd59977 | 676 | { |
34db9c00 | 677 | if (theArgNb > 1) |
678 | { | |
679 | std::cout << "Error: wrong syntax!\n"; | |
680 | return 1; | |
681 | } | |
682 | ||
683 | Handle(AIS_InteractiveContext) aCtx; | |
684 | Handle(V3d_View) aView; | |
685 | if (!getCtxAndView (aCtx, aView)) | |
686 | { | |
687 | return 1; | |
688 | } | |
689 | ||
690 | aCtx->DisplayActiveSensitive (aView); | |
7fd59977 | 691 | return 0; |
692 | ||
693 | } | |
34db9c00 | 694 | |
695 | static Standard_Integer VClearSensi (Draw_Interpretor& , | |
696 | Standard_Integer theArgNb, | |
697 | Standard_CString* ) | |
7fd59977 | 698 | { |
34db9c00 | 699 | if (theArgNb > 1) |
700 | { | |
701 | std::cout << "Error: wrong syntax!\n"; | |
702 | return 1; | |
703 | } | |
704 | ||
705 | Handle(AIS_InteractiveContext) aCtx; | |
706 | Handle(V3d_View) aView; | |
707 | if (!getCtxAndView (aCtx, aView)) | |
708 | { | |
709 | return 1; | |
710 | } | |
711 | aCtx->ClearActiveSensitive (aView); | |
7fd59977 | 712 | return 0; |
713 | } | |
714 | ||
715 | //============================================================================== | |
519d35d8 | 716 | //function : VDir |
7fd59977 | 717 | //purpose : To list the displayed object with their attributes |
7fd59977 | 718 | //============================================================================== |
519d35d8 | 719 | static int VDir (Draw_Interpretor& theDI, |
720 | Standard_Integer , | |
721 | const char** ) | |
722 | { | |
723 | if (!a3DView().IsNull()) | |
724 | { | |
725 | return 0; | |
7fd59977 | 726 | } |
727 | ||
519d35d8 | 728 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
729 | anIter.More(); anIter.Next()) | |
730 | { | |
731 | theDI << "\t" << anIter.Key2().ToCString() << "\n"; | |
732 | } | |
7fd59977 | 733 | return 0; |
734 | } | |
735 | ||
3c982548 | 736 | //============================================================================== |
737 | //function : VSelPrecision | |
738 | //purpose : To set the selection precision mode and tolerance value | |
739 | //Draw arg : Selection precision mode (0 for window, 1 for view) and tolerance | |
740 | // value (integer number of pixel for window mode, double value of | |
741 | // sensitivity for view mode). Without arguments the function just | |
742 | // prints the current precision mode and the corresponding tolerance. | |
743 | //============================================================================== | |
744 | static int VSelPrecision(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
745 | { | |
746 | if( argc > 3 ) | |
747 | { | |
748 | di << "Use: " << argv[0] << " [precision_mode [tolerance_value]]\n"; | |
749 | return 1; | |
750 | } | |
751 | ||
752 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
753 | if( aContext.IsNull() ) | |
754 | return 1; | |
755 | ||
756 | if( argc == 1 ) | |
757 | { | |
758 | StdSelect_SensitivityMode aMode = aContext->SensitivityMode(); | |
759 | if( aMode == StdSelect_SM_WINDOW ) | |
760 | { | |
761 | Standard_Integer aPixelTolerance = aContext->PixelTolerance(); | |
762 | di << "Precision mode : 0 (window)\n"; | |
763 | di << "Pixel tolerance : " << aPixelTolerance << "\n"; | |
764 | } | |
765 | else if( aMode == StdSelect_SM_VIEW ) | |
766 | { | |
767 | Standard_Real aSensitivity = aContext->Sensitivity(); | |
768 | di << "Precision mode : 1 (view)\n"; | |
769 | di << "Sensitivity : " << aSensitivity << "\n"; | |
770 | } | |
771 | } | |
772 | else if( argc > 1 ) | |
773 | { | |
91322f44 | 774 | StdSelect_SensitivityMode aMode = ( StdSelect_SensitivityMode )Draw::Atoi( argv[1] ); |
3c982548 | 775 | aContext->SetSensitivityMode( aMode ); |
776 | if( argc > 2 ) | |
777 | { | |
778 | if( aMode == StdSelect_SM_WINDOW ) | |
779 | { | |
91322f44 | 780 | Standard_Integer aPixelTolerance = Draw::Atoi( argv[2] ); |
3c982548 | 781 | aContext->SetPixelTolerance( aPixelTolerance ); |
782 | } | |
783 | else if( aMode == StdSelect_SM_VIEW ) | |
784 | { | |
91322f44 | 785 | Standard_Real aSensitivity = Draw::Atof( argv[2] ); |
3c982548 | 786 | aContext->SetSensitivity( aSensitivity ); |
787 | } | |
788 | } | |
789 | } | |
790 | return 0; | |
791 | } | |
792 | ||
7fd59977 | 793 | //============================================================================== |
794 | //function : VDump | |
795 | //purpose : To dump the active view snapshot to image file | |
7fd59977 | 796 | //============================================================================== |
34db9c00 | 797 | static Standard_Integer VDump (Draw_Interpretor& theDI, |
798 | Standard_Integer theArgNb, | |
799 | Standard_CString* theArgVec) | |
7fd59977 | 800 | { |
34db9c00 | 801 | if (theArgNb < 2) |
7fd59977 | 802 | { |
34db9c00 | 803 | std::cout << "Error: wrong number of arguments! Image file name should be specified at least.\n"; |
7fd59977 | 804 | return 1; |
805 | } | |
806 | ||
34db9c00 | 807 | Standard_Integer anArgIter = 1; |
808 | Standard_CString aFilePath = theArgVec[anArgIter++]; | |
809 | Graphic3d_BufferType aBufferType = Graphic3d_BT_RGB; | |
810 | V3d_StereoDumpOptions aStereoOpts = V3d_SDO_MONO; | |
811 | Standard_Integer aWidth = 0; | |
812 | Standard_Integer aHeight = 0; | |
813 | for (; anArgIter < theArgNb; ++anArgIter) | |
7fd59977 | 814 | { |
34db9c00 | 815 | TCollection_AsciiString anArg (theArgVec[anArgIter]); |
816 | anArg.LowerCase(); | |
817 | if (anArg == "rgba") | |
7fd59977 | 818 | { |
34db9c00 | 819 | aBufferType = Graphic3d_BT_RGBA; |
7fd59977 | 820 | } |
34db9c00 | 821 | else if (anArg == "rgb") |
7fd59977 | 822 | { |
34db9c00 | 823 | aBufferType = Graphic3d_BT_RGB; |
7fd59977 | 824 | } |
34db9c00 | 825 | else if (anArg == "depth") |
7fd59977 | 826 | { |
692613e5 | 827 | aBufferType = Graphic3d_BT_Depth; |
7fd59977 | 828 | } |
34db9c00 | 829 | else if (anArg == "l" |
830 | || anArg == "left") | |
831 | { | |
832 | aStereoOpts = V3d_SDO_LEFT_EYE; | |
833 | } | |
834 | else if (anArg == "r" | |
835 | || anArg == "right") | |
836 | { | |
837 | aStereoOpts = V3d_SDO_RIGHT_EYE; | |
838 | } | |
839 | else if (anArg == "mono") | |
840 | { | |
841 | aStereoOpts = V3d_SDO_MONO; | |
842 | } | |
843 | else if (anArg == "w" | |
844 | || anArg == "width") | |
845 | { | |
846 | if (aWidth != 0) | |
847 | { | |
848 | std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n"; | |
849 | return 1; | |
850 | } | |
851 | else if (++anArgIter >= theArgNb) | |
852 | { | |
853 | std::cout << "Error: integer value is expected right after 'width'\n"; | |
854 | return 1; | |
855 | } | |
856 | aWidth = Draw::Atoi (theArgVec[anArgIter]); | |
857 | } | |
858 | else if (anArg == "h" | |
859 | || anArg == "height") | |
860 | { | |
861 | if (aHeight != 0) | |
862 | { | |
863 | std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n"; | |
864 | return 1; | |
865 | } | |
866 | if (++anArgIter >= theArgNb) | |
867 | { | |
868 | std::cout << "Error: integer value is expected right after 'height'\n"; | |
869 | return 1; | |
870 | } | |
871 | aHeight = Draw::Atoi (theArgVec[anArgIter]); | |
872 | } | |
873 | else if (anArg.IsIntegerValue()) | |
874 | { | |
875 | // compatibility with old syntax | |
876 | if (aWidth != 0 | |
877 | || aHeight != 0) | |
878 | { | |
879 | std::cout << "Error: wrong syntax at " << theArgVec[anArgIter] << "\n"; | |
880 | return 1; | |
881 | } | |
882 | else if (++anArgIter >= theArgNb) | |
883 | { | |
884 | std::cout << "Error: height value is expected right after width\n"; | |
885 | return 1; | |
886 | } | |
887 | aWidth = Draw::Atoi (theArgVec[anArgIter - 1]); | |
888 | aHeight = Draw::Atoi (theArgVec[anArgIter]); | |
889 | } | |
890 | else | |
891 | { | |
892 | std::cout << "Error: unknown argument '" << theArgVec[anArgIter] << "'\n"; | |
893 | return 1; | |
894 | } | |
7fd59977 | 895 | } |
34db9c00 | 896 | if ((aWidth <= 0 && aHeight > 0) |
897 | || (aWidth > 0 && aHeight <= 0)) | |
7fd59977 | 898 | { |
34db9c00 | 899 | std::cout << "Error: dimensions " << aWidth << "x" << aHeight << " are incorrect\n"; |
85e096c3 | 900 | return 1; |
901 | } | |
902 | ||
34db9c00 | 903 | Handle(V3d_View) aView = ViewerTest::CurrentView(); |
904 | if (aView.IsNull()) | |
85e096c3 | 905 | { |
34db9c00 | 906 | std::cout << "Error: cannot find an active view!\n"; |
907 | return 1; | |
7fd59977 | 908 | } |
85e096c3 | 909 | |
34db9c00 | 910 | if (aWidth <= 0 || aHeight <= 0) |
b5ac8292 | 911 | { |
34db9c00 | 912 | if (aStereoOpts != V3d_SDO_MONO) |
b5ac8292 | 913 | { |
34db9c00 | 914 | aView->Window()->Size (aWidth, aHeight); |
b5ac8292 | 915 | } |
34db9c00 | 916 | else |
b5ac8292 | 917 | { |
34db9c00 | 918 | if (!aView->Dump (aFilePath, aBufferType)) |
919 | { | |
920 | theDI << "Fail: view dump failed!\n"; | |
921 | } | |
922 | return 0; | |
b5ac8292 | 923 | } |
924 | } | |
925 | ||
692613e5 | 926 | Image_AlienPixMap aPixMap; |
34db9c00 | 927 | if (!aView->ToPixMap (aPixMap, aWidth, aHeight, aBufferType, Standard_True, aStereoOpts)) |
7fd59977 | 928 | { |
34db9c00 | 929 | theDI << "Fail: view dump failed!\n"; |
930 | return 0; | |
7fd59977 | 931 | } |
85e096c3 | 932 | |
692613e5 | 933 | if (aPixMap.SizeX() != Standard_Size(aWidth) |
934 | || aPixMap.SizeY() != Standard_Size(aHeight)) | |
85e096c3 | 935 | { |
34db9c00 | 936 | theDI << "Fail: dumped dimensions " << (Standard_Integer )aPixMap.SizeX() << "x" << (Standard_Integer )aPixMap.SizeY() |
937 | << " are lesser than requested " << aWidth << "x" << aHeight << "\n"; | |
85e096c3 | 938 | } |
34db9c00 | 939 | if (!aPixMap.Save (aFilePath)) |
85e096c3 | 940 | { |
34db9c00 | 941 | theDI << "Fail: image can not be saved!\n"; |
85e096c3 | 942 | } |
943 | return 0; | |
7fd59977 | 944 | } |
945 | ||
946 | ||
947 | //============================================================================== | |
948 | //function : Displays,Erase... | |
949 | //purpose : | |
950 | //Draw arg : | |
951 | //============================================================================== | |
952 | static int VwrTst_DispErase(const Handle(AIS_InteractiveObject)& IO, | |
953 | const Standard_Integer Mode, | |
954 | const Standard_Integer TypeOfOperation, | |
955 | const Standard_Boolean Upd) | |
956 | { | |
957 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
958 | ||
959 | switch(TypeOfOperation){ | |
960 | case 1: | |
961 | Ctx->Display(IO,Mode,Upd); | |
962 | break; | |
963 | case 2:{ | |
eb4320f2 | 964 | Ctx->Erase(IO,Upd); |
7fd59977 | 965 | break; |
966 | } | |
967 | case 3:{ | |
968 | if(IO.IsNull()) | |
969 | Ctx->SetDisplayMode((AIS_DisplayMode)Mode,Upd); | |
970 | else | |
971 | Ctx->SetDisplayMode(IO,Mode,Upd); | |
972 | break; | |
973 | } | |
974 | case 4:{ | |
975 | if(IO.IsNull()) | |
976 | Ctx->SetDisplayMode(0,Upd); | |
977 | else | |
978 | Ctx->UnsetDisplayMode(IO,Upd); | |
979 | break; | |
980 | } | |
981 | } | |
982 | return 0; | |
983 | } | |
984 | ||
985 | //======================================================================= | |
986 | //function : | |
987 | //purpose : | |
988 | //======================================================================= | |
989 | static int VDispMode (Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
990 | { | |
991 | ||
992 | TCollection_AsciiString name; | |
993 | if(argc>3) | |
994 | return 1; | |
995 | // display others presentations | |
996 | Standard_Integer TypeOfOperation = (strcasecmp(argv[0],"vdispmode")==0)? 1: | |
997 | (strcasecmp(argv[0],"verasemode")==0) ? 2 : | |
998 | (strcasecmp(argv[0],"vsetdispmode")==0) ? 3 : | |
999 | (strcasecmp(argv[0],"vunsetdispmode")==0) ? 4 : -1; | |
1000 | ||
1001 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
1002 | ||
1003 | //unset displaymode.. comportement particulier... | |
1004 | if(TypeOfOperation==4){ | |
1005 | if(argc==1){ | |
1006 | if(Ctx->NbCurrents()==0 || | |
1007 | Ctx->NbSelected()==0){ | |
1008 | Handle(AIS_InteractiveObject) IO; | |
1009 | VwrTst_DispErase(IO,-1,4,Standard_False); | |
1010 | } | |
1011 | else if(!Ctx->HasOpenedContext()){ | |
1012 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()) | |
1013 | VwrTst_DispErase(Ctx->Current(),-1,4,Standard_False); | |
1014 | } | |
1015 | else{ | |
1016 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1017 | VwrTst_DispErase(Ctx->Interactive(),-1,4,Standard_False);} | |
1018 | Ctx->UpdateCurrentViewer(); | |
1019 | } | |
1020 | else{ | |
1021 | Handle(AIS_InteractiveObject) IO; | |
1022 | name = argv[1]; | |
1023 | if(GetMapOfAIS().IsBound2(name)){ | |
1024 | IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
1025 | if (!IO.IsNull()) | |
1026 | VwrTst_DispErase(IO,-1,4,Standard_True); | |
1027 | } | |
1028 | } | |
1029 | } | |
1030 | else if(argc==2){ | |
91322f44 | 1031 | Standard_Integer Dmode = Draw::Atoi(argv[1]); |
7fd59977 | 1032 | if(Ctx->NbCurrents()==0 && TypeOfOperation==3){ |
1033 | Handle(AIS_InteractiveObject) IO; | |
1034 | VwrTst_DispErase(IO,Dmode,TypeOfOperation,Standard_True); | |
1035 | } | |
1036 | if(!Ctx->HasOpenedContext()){ | |
1037 | // set/unset display mode sur le Contexte... | |
1038 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){ | |
1039 | VwrTst_DispErase(Ctx->Current(),Dmode,TypeOfOperation,Standard_False); | |
1040 | } | |
1041 | Ctx->UpdateCurrentViewer(); | |
1042 | } | |
1043 | else{ | |
1044 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()) | |
1045 | Ctx->Display(Ctx->Interactive(),Dmode); | |
1046 | } | |
1047 | } | |
1048 | else{ | |
1049 | Handle(AIS_InteractiveObject) IO; | |
1050 | name = argv[1]; | |
1051 | if(GetMapOfAIS().IsBound2(name)) | |
1052 | IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
1053 | if (!IO.IsNull()) | |
91322f44 | 1054 | VwrTst_DispErase(IO,Draw::Atoi(argv[2]),TypeOfOperation,Standard_True); |
7fd59977 | 1055 | } |
1056 | return 0; | |
1057 | } | |
1058 | ||
1059 | ||
1060 | //======================================================================= | |
1061 | //function : | |
1062 | //purpose : | |
1063 | //======================================================================= | |
1064 | static int VSubInt(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
1065 | { | |
1066 | if(argc==1) return 1; | |
91322f44 | 1067 | Standard_Integer On = Draw::Atoi(argv[1]); |
7fd59977 | 1068 | const Handle(AIS_InteractiveContext)& Ctx = ViewerTest::GetAISContext(); |
1069 | ||
1070 | if(argc==2){ | |
1071 | ||
1072 | if(!Ctx->HasOpenedContext()){ | |
1073 | di<<"sub intensite "; | |
1074 | if(On==1) di<<"On"; | |
1075 | else di<<"Off"; | |
1076 | di<<" pour "<<Ctx->NbCurrents()<<" objets"<<"\n"; | |
1077 | for(Ctx->InitCurrent();Ctx->MoreCurrent();Ctx->NextCurrent()){ | |
1078 | if(On==1){ | |
1079 | Ctx->SubIntensityOn(Ctx->Current(),Standard_False);} | |
1080 | else{ | |
1081 | di <<"passage dans off"<<"\n"; | |
1082 | Ctx->SubIntensityOff(Ctx->Current(),Standard_False); | |
1083 | } | |
1084 | } | |
1085 | } | |
1086 | else{ | |
1087 | for(Ctx->InitSelected();Ctx->MoreSelected();Ctx->NextSelected()){ | |
1088 | if(On==1){ | |
1089 | Ctx->SubIntensityOn(Ctx->Interactive(),Standard_False);} | |
1090 | else{ | |
1091 | Ctx->SubIntensityOff(Ctx->Interactive(),Standard_False);} | |
1092 | } | |
1093 | } | |
1094 | Ctx->UpdateCurrentViewer(); | |
1095 | } | |
1096 | else { | |
1097 | Handle(AIS_InteractiveObject) IO; | |
1098 | TCollection_AsciiString name = argv[2]; | |
1099 | if(GetMapOfAIS().IsBound2(name)){ | |
1100 | IO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
eafb234b | 1101 | if (!IO.IsNull()) { |
7fd59977 | 1102 | if(On==1) |
1103 | Ctx->SubIntensityOn(IO); | |
1104 | else | |
1105 | Ctx->SubIntensityOff(IO); | |
eafb234b | 1106 | } |
7fd59977 | 1107 | } |
1108 | else return 1; | |
1109 | } | |
1110 | return 0; | |
7fd59977 | 1111 | } |
7fd59977 | 1112 | |
ad3217cd | 1113 | //! Auxiliary class to iterate presentations from different collections. |
1114 | class ViewTest_PrsIter | |
1115 | { | |
1116 | public: | |
7fd59977 | 1117 | |
ad3217cd | 1118 | //! Create and initialize iterator object. |
1119 | ViewTest_PrsIter (const TCollection_AsciiString& theName) | |
1120 | : mySource (IterSource_All) | |
1121 | { | |
1122 | NCollection_Sequence<TCollection_AsciiString> aNames; | |
1123 | if (!theName.IsEmpty()) | |
1124 | aNames.Append (theName); | |
1125 | Init (aNames); | |
7fd59977 | 1126 | } |
ad3217cd | 1127 | |
1128 | //! Create and initialize iterator object. | |
1129 | ViewTest_PrsIter (const NCollection_Sequence<TCollection_AsciiString>& theNames) | |
1130 | : mySource (IterSource_All) | |
1131 | { | |
1132 | Init (theNames); | |
7fd59977 | 1133 | } |
1134 | ||
ad3217cd | 1135 | //! Initialize the iterator. |
1136 | void Init (const NCollection_Sequence<TCollection_AsciiString>& theNames) | |
1137 | { | |
1138 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
1139 | mySeq = theNames; | |
1140 | mySelIter.Nullify(); | |
1141 | myCurrent.Nullify(); | |
1142 | myCurrentTrs.Nullify(); | |
1143 | if (!mySeq.IsEmpty()) | |
1144 | { | |
1145 | mySource = IterSource_List; | |
1146 | mySeqIter = NCollection_Sequence<TCollection_AsciiString>::Iterator (mySeq); | |
7fd59977 | 1147 | } |
ad3217cd | 1148 | else if (aCtx->NbCurrents() > 0) |
1149 | { | |
1150 | mySource = IterSource_Selected; | |
1151 | mySelIter = aCtx; | |
1152 | mySelIter->InitCurrent(); | |
1153 | } | |
1154 | else | |
1155 | { | |
1156 | mySource = IterSource_All; | |
1157 | myMapIter.Initialize (GetMapOfAIS()); | |
1158 | } | |
1159 | initCurrent(); | |
1160 | } | |
7fd59977 | 1161 | |
ad3217cd | 1162 | const TCollection_AsciiString& CurrentName() const |
1163 | { | |
1164 | return myCurrentName; | |
1165 | } | |
7fd59977 | 1166 | |
ad3217cd | 1167 | const Handle(AIS_InteractiveObject)& Current() const |
1168 | { | |
1169 | return myCurrent; | |
1170 | } | |
7fd59977 | 1171 | |
ad3217cd | 1172 | const Handle(Standard_Transient)& CurrentTrs() const |
1173 | { | |
1174 | return myCurrentTrs; | |
1175 | } | |
1176 | ||
1177 | //! @return true if iterator points to valid object within collection | |
1178 | Standard_Boolean More() const | |
1179 | { | |
1180 | switch (mySource) | |
1181 | { | |
1182 | case IterSource_All: return myMapIter.More(); | |
1183 | case IterSource_List: return mySeqIter.More(); | |
1184 | case IterSource_Selected: return mySelIter->MoreCurrent(); | |
1185 | } | |
1186 | return Standard_False; | |
1187 | } | |
1188 | ||
1189 | //! Go to the next item. | |
1190 | void Next() | |
1191 | { | |
1192 | myCurrentName.Clear(); | |
1193 | myCurrentTrs.Nullify(); | |
1194 | myCurrent.Nullify(); | |
1195 | switch (mySource) | |
1196 | { | |
1197 | case IterSource_All: | |
1198 | { | |
1199 | myMapIter.Next(); | |
1200 | break; | |
1201 | } | |
1202 | case IterSource_List: | |
1203 | { | |
1204 | mySeqIter.Next(); | |
1205 | break; | |
1206 | } | |
1207 | case IterSource_Selected: | |
1208 | { | |
1209 | mySelIter->NextCurrent(); | |
1210 | break; | |
7fd59977 | 1211 | } |
1212 | } | |
ad3217cd | 1213 | initCurrent(); |
1214 | } | |
7fd59977 | 1215 | |
ad3217cd | 1216 | private: |
7fd59977 | 1217 | |
ad3217cd | 1218 | void initCurrent() |
1219 | { | |
1220 | switch (mySource) | |
1221 | { | |
1222 | case IterSource_All: | |
7fd59977 | 1223 | { |
ad3217cd | 1224 | if (myMapIter.More()) |
1225 | { | |
1226 | myCurrentName = myMapIter.Key2(); | |
1227 | myCurrentTrs = myMapIter.Key1(); | |
1228 | myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); | |
eafb234b | 1229 | } |
ad3217cd | 1230 | break; |
1231 | } | |
1232 | case IterSource_List: | |
1233 | { | |
1234 | if (mySeqIter.More()) | |
1235 | { | |
1236 | if (!GetMapOfAIS().IsBound2 (mySeqIter.Value())) | |
1237 | { | |
1238 | std::cout << "Error: object " << mySeqIter.Value() << " is not displayed!\n"; | |
1239 | return; | |
1240 | } | |
1241 | myCurrentName = mySeqIter.Value(); | |
1242 | myCurrentTrs = GetMapOfAIS().Find2 (mySeqIter.Value()); | |
1243 | myCurrent = Handle(AIS_InteractiveObject)::DownCast (myCurrentTrs); | |
1244 | } | |
1245 | break; | |
1246 | } | |
1247 | case IterSource_Selected: | |
1248 | { | |
1249 | if (mySelIter->MoreCurrent()) | |
1250 | { | |
1251 | myCurrentName = GetMapOfAIS().Find1 (mySelIter->Current()); | |
1252 | myCurrent = mySelIter->Current(); | |
1253 | } | |
1254 | break; | |
7fd59977 | 1255 | } |
7fd59977 | 1256 | } |
1257 | } | |
ad3217cd | 1258 | |
1259 | private: | |
1260 | ||
1261 | enum IterSource | |
1262 | { | |
1263 | IterSource_All, | |
1264 | IterSource_List, | |
1265 | IterSource_Selected | |
1266 | }; | |
1267 | ||
1268 | private: | |
1269 | ||
1270 | Handle(AIS_InteractiveContext) mySelIter; //!< iterator for current (selected) objects (IterSource_Selected) | |
1271 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName myMapIter; //!< iterator for map of all objects (IterSource_All) | |
1272 | NCollection_Sequence<TCollection_AsciiString> mySeq; | |
1273 | NCollection_Sequence<TCollection_AsciiString>::Iterator mySeqIter; | |
1274 | ||
1275 | TCollection_AsciiString myCurrentName;//!< current item name | |
1276 | Handle(Standard_Transient) myCurrentTrs; //!< current item (as transient object) | |
1277 | Handle(AIS_InteractiveObject) myCurrent; //!< current item | |
1278 | ||
1279 | IterSource mySource; //!< iterated collection | |
1280 | ||
1281 | }; | |
7fd59977 | 1282 | |
1283 | //============================================================================== | |
ad3217cd | 1284 | //function : VInteriorStyle |
1285 | //purpose : sets interior style of the a selected or named or displayed shape | |
7fd59977 | 1286 | //============================================================================== |
ad3217cd | 1287 | static int VSetInteriorStyle (Draw_Interpretor& theDI, |
1288 | Standard_Integer theArgNb, | |
1289 | const char** theArgVec) | |
7fd59977 | 1290 | { |
ad3217cd | 1291 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
4e18052b | 1292 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
ad3217cd | 1293 | if (aCtx.IsNull()) |
1294 | { | |
1295 | std::cerr << "Error: no active view!\n"; | |
1296 | return 1; | |
1297 | } | |
7fd59977 | 1298 | |
4e18052b | 1299 | Standard_Integer anArgIter = 1; |
ad3217cd | 1300 | for (; anArgIter < theArgNb; ++anArgIter) |
1301 | { | |
4e18052b | 1302 | if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) |
ad3217cd | 1303 | { |
1304 | break; | |
1305 | } | |
7fd59977 | 1306 | } |
ad3217cd | 1307 | TCollection_AsciiString aName; |
1308 | if (theArgNb - anArgIter == 2) | |
1309 | { | |
1310 | aName = theArgVec[anArgIter++]; | |
1311 | } | |
1312 | else if (theArgNb - anArgIter != 1) | |
1313 | { | |
1314 | std::cout << "Error: wrong number of arguments! See usage:\n"; | |
1315 | theDI.PrintHelp (theArgVec[0]); | |
1316 | return 1; | |
1317 | } | |
1318 | Standard_Integer anInterStyle = Aspect_IS_SOLID; | |
1319 | TCollection_AsciiString aStyleArg (theArgVec[anArgIter++]); | |
1320 | aStyleArg.LowerCase(); | |
1321 | if (aStyleArg == "empty") | |
1322 | { | |
1323 | anInterStyle = 0; | |
1324 | } | |
1325 | else if (aStyleArg == "hollow") | |
1326 | { | |
1327 | anInterStyle = 1; | |
1328 | } | |
1329 | else if (aStyleArg == "hatch") | |
1330 | { | |
1331 | anInterStyle = 2; | |
1332 | } | |
1333 | else if (aStyleArg == "solid") | |
1334 | { | |
1335 | anInterStyle = 3; | |
1336 | } | |
1337 | else if (aStyleArg == "hiddenline") | |
1338 | { | |
1339 | anInterStyle = 4; | |
1340 | } | |
1341 | else | |
1342 | { | |
1343 | anInterStyle = aStyleArg.IntegerValue(); | |
1344 | } | |
1345 | if (anInterStyle < Aspect_IS_EMPTY | |
1346 | || anInterStyle > Aspect_IS_HIDDENLINE) | |
1347 | { | |
1348 | std::cout << "Error: style must be within a range [0 (Aspect_IS_EMPTY), " | |
1349 | << Aspect_IS_HIDDENLINE << " (Aspect_IS_HIDDENLINE)]\n"; | |
1350 | return 1; | |
7fd59977 | 1351 | } |
1352 | ||
ad3217cd | 1353 | if (!aName.IsEmpty() |
1354 | && !GetMapOfAIS().IsBound2 (aName)) | |
1355 | { | |
1356 | std::cout << "Error: object " << aName << " is not displayed!\n"; | |
1357 | return 1; | |
1358 | } | |
1359 | ||
1360 | if (aCtx->HasOpenedContext()) | |
1361 | { | |
1362 | aCtx->CloseLocalContext(); | |
1363 | } | |
1364 | for (ViewTest_PrsIter anIter (aName); anIter.More(); anIter.Next()) | |
1365 | { | |
1366 | const Handle(AIS_InteractiveObject)& anIO = anIter.Current(); | |
1367 | if (!anIO.IsNull()) | |
1368 | { | |
1369 | const Handle(Prs3d_Drawer)& aDrawer = anIO->Attributes(); | |
1370 | Handle(Prs3d_ShadingAspect) aShadingAspect = aDrawer->ShadingAspect(); | |
1371 | Handle(Graphic3d_AspectFillArea3d) aFillAspect = aShadingAspect->Aspect(); | |
1372 | aFillAspect->SetInteriorStyle ((Aspect_InteriorStyle )anInterStyle); | |
1373 | aCtx->RecomputePrsOnly (anIO, Standard_False, Standard_True); | |
7fd59977 | 1374 | } |
ad3217cd | 1375 | } |
ad3217cd | 1376 | return 0; |
1377 | } | |
7fd59977 | 1378 | |
ad3217cd | 1379 | //! Auxiliary structure for VAspects |
1380 | struct ViewerTest_AspectsChangeSet | |
1381 | { | |
5bffb882 | 1382 | Standard_Integer ToSetVisibility; |
1383 | Standard_Integer Visibility; | |
1384 | ||
ad3217cd | 1385 | Standard_Integer ToSetColor; |
1386 | Quantity_Color Color; | |
1387 | ||
1388 | Standard_Integer ToSetLineWidth; | |
1389 | Standard_Real LineWidth; | |
1390 | ||
1391 | Standard_Integer ToSetTransparency; | |
1392 | Standard_Real Transparency; | |
1393 | ||
1394 | Standard_Integer ToSetMaterial; | |
1395 | Graphic3d_NameOfMaterial Material; | |
1396 | TCollection_AsciiString MatName; | |
1397 | ||
1398 | NCollection_Sequence<TopoDS_Shape> SubShapes; | |
1399 | ||
6262338c | 1400 | Standard_Integer ToSetShowFreeBoundary; |
1401 | Standard_Integer ToSetFreeBoundaryWidth; | |
1402 | Standard_Real FreeBoundaryWidth; | |
1403 | Standard_Integer ToSetFreeBoundaryColor; | |
1404 | Quantity_Color FreeBoundaryColor; | |
1405 | ||
ad3217cd | 1406 | //! Empty constructor |
1407 | ViewerTest_AspectsChangeSet() | |
5bffb882 | 1408 | : ToSetVisibility (0), |
1409 | Visibility (1), | |
1410 | ToSetColor (0), | |
ad3217cd | 1411 | Color (DEFAULT_COLOR), |
1412 | ToSetLineWidth (0), | |
1413 | LineWidth (1.0), | |
1414 | ToSetTransparency (0), | |
1415 | Transparency (0.0), | |
1416 | ToSetMaterial (0), | |
6262338c | 1417 | Material (Graphic3d_NOM_DEFAULT), |
1418 | ToSetShowFreeBoundary (0), | |
1419 | ToSetFreeBoundaryWidth (0), | |
1420 | FreeBoundaryWidth (1.0), | |
1421 | ToSetFreeBoundaryColor (0), | |
1422 | FreeBoundaryColor (DEFAULT_FREEBOUNDARY_COLOR) {} | |
ad3217cd | 1423 | |
1424 | //! @return true if no changes have been requested | |
1425 | Standard_Boolean IsEmpty() const | |
1426 | { | |
6262338c | 1427 | return ToSetVisibility == 0 |
1428 | && ToSetLineWidth == 0 | |
1429 | && ToSetTransparency == 0 | |
1430 | && ToSetColor == 0 | |
1431 | && ToSetMaterial == 0 | |
1432 | && ToSetShowFreeBoundary == 0 | |
1433 | && ToSetFreeBoundaryColor == 0 | |
1434 | && ToSetFreeBoundaryWidth == 0; | |
ad3217cd | 1435 | } |
1436 | ||
1437 | //! @return true if properties are valid | |
1438 | Standard_Boolean Validate (const Standard_Boolean theIsSubPart) const | |
1439 | { | |
1440 | Standard_Boolean isOk = Standard_True; | |
5bffb882 | 1441 | if (Visibility != 0 && Visibility != 1) |
1442 | { | |
1443 | std::cout << "Error: the visibility should be equal to 0 or 1 (0 - invisible; 1 - visible) (specified " << Visibility << ")\n"; | |
1444 | isOk = Standard_False; | |
1445 | } | |
ad3217cd | 1446 | if (LineWidth <= 0.0 |
1447 | || LineWidth > 10.0) | |
1448 | { | |
1449 | std::cout << "Error: the width should be within [1; 10] range (specified " << LineWidth << ")\n"; | |
1450 | isOk = Standard_False; | |
7fd59977 | 1451 | } |
ad3217cd | 1452 | if (Transparency < 0.0 |
1453 | || Transparency > 1.0) | |
1454 | { | |
1455 | std::cout << "Error: the transparency should be within [0; 1] range (specified " << Transparency << ")\n"; | |
1456 | isOk = Standard_False; | |
1457 | } | |
1458 | if (theIsSubPart | |
1459 | && ToSetTransparency) | |
1460 | { | |
1461 | std::cout << "Error: the transparency can not be defined for sub-part of object!\n"; | |
1462 | isOk = Standard_False; | |
7fd59977 | 1463 | } |
ad3217cd | 1464 | if (ToSetMaterial == 1 |
1465 | && Material == Graphic3d_NOM_DEFAULT) | |
1466 | { | |
1467 | std::cout << "Error: unknown material " << MatName << ".\n"; | |
1468 | isOk = Standard_False; | |
1469 | } | |
6262338c | 1470 | if (FreeBoundaryWidth <= 0.0 |
1471 | || FreeBoundaryWidth > 10.0) | |
1472 | { | |
1473 | std::cout << "Error: the free boundary width should be within [1; 10] range (specified " << FreeBoundaryWidth << ")\n"; | |
1474 | isOk = Standard_False; | |
1475 | } | |
ad3217cd | 1476 | return isOk; |
7fd59977 | 1477 | } |
7fd59977 | 1478 | |
ad3217cd | 1479 | }; |
7fd59977 | 1480 | |
1481 | //============================================================================== | |
ad3217cd | 1482 | //function : VAspects |
1483 | //purpose : | |
7fd59977 | 1484 | //============================================================================== |
ad3217cd | 1485 | static Standard_Integer VAspects (Draw_Interpretor& /*theDI*/, |
1486 | Standard_Integer theArgNb, | |
1487 | const char** theArgVec) | |
7fd59977 | 1488 | { |
ad3217cd | 1489 | TCollection_AsciiString aCmdName (theArgVec[0]); |
1490 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); | |
4e18052b | 1491 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
ad3217cd | 1492 | if (aCtx.IsNull()) |
1493 | { | |
1494 | std::cerr << "Error: no active view!\n"; | |
1495 | return 1; | |
1496 | } | |
7fd59977 | 1497 | |
4e18052b | 1498 | Standard_Integer anArgIter = 1; |
6262338c | 1499 | Standard_Boolean isDefaults = Standard_False; |
ad3217cd | 1500 | NCollection_Sequence<TCollection_AsciiString> aNames; |
1501 | for (; anArgIter < theArgNb; ++anArgIter) | |
1502 | { | |
1503 | TCollection_AsciiString anArg = theArgVec[anArgIter]; | |
4e18052b | 1504 | if (anUpdateTool.parseRedrawMode (anArg)) |
ad3217cd | 1505 | { |
1506 | continue; | |
1507 | } | |
1508 | else if (!anArg.IsEmpty() | |
1509 | && anArg.Value (1) != '-') | |
1510 | { | |
1511 | aNames.Append (anArg); | |
1512 | } | |
1513 | else | |
1514 | { | |
6262338c | 1515 | if (anArg == "-defaults") |
1516 | { | |
1517 | isDefaults = Standard_True; | |
1518 | ++anArgIter; | |
1519 | } | |
ad3217cd | 1520 | break; |
1521 | } | |
1522 | } | |
1523 | ||
6262338c | 1524 | if (!aNames.IsEmpty() && isDefaults) |
1525 | { | |
1526 | std::cout << "Error: wrong syntax. If -defaults is used there should not be any objects' names!\n"; | |
1527 | return 1; | |
1528 | } | |
1529 | ||
ad3217cd | 1530 | NCollection_Sequence<ViewerTest_AspectsChangeSet> aChanges; |
1531 | aChanges.Append (ViewerTest_AspectsChangeSet()); | |
1532 | ViewerTest_AspectsChangeSet* aChangeSet = &aChanges.ChangeLast(); | |
7fd59977 | 1533 | |
ad3217cd | 1534 | // parse syntax of legacy commands |
1535 | if (aCmdName == "vsetwidth") | |
1536 | { | |
1537 | if (aNames.IsEmpty() | |
1538 | || !aNames.Last().IsRealValue()) | |
1539 | { | |
1540 | std::cout << "Error: not enough arguments!\n"; | |
1541 | return 1; | |
1542 | } | |
1543 | aChangeSet->ToSetLineWidth = 1; | |
1544 | aChangeSet->LineWidth = aNames.Last().RealValue(); | |
1545 | aNames.Remove (aNames.Length()); | |
7fd59977 | 1546 | } |
ad3217cd | 1547 | else if (aCmdName == "vunsetwidth") |
1548 | { | |
1549 | aChangeSet->ToSetLineWidth = -1; | |
1550 | } | |
1551 | else if (aCmdName == "vsetcolor") | |
1552 | { | |
1553 | if (aNames.IsEmpty()) | |
1554 | { | |
1555 | std::cout << "Error: not enough arguments!\n"; | |
1556 | return 1; | |
1557 | } | |
1558 | aChangeSet->ToSetColor = 1; | |
8316c618 | 1559 | |
1560 | Quantity_NameOfColor aColor = Quantity_NOC_BLACK; | |
1561 | Standard_Boolean isOk = Standard_False; | |
1562 | if (Quantity_Color::ColorFromName (aNames.Last().ToCString(), aColor)) | |
1563 | { | |
1564 | aChangeSet->Color = aColor; | |
1565 | aNames.Remove (aNames.Length()); | |
1566 | isOk = Standard_True; | |
1567 | } | |
1568 | else if (aNames.Length() >= 3) | |
1569 | { | |
1570 | const TCollection_AsciiString anRgbStr[3] = | |
1571 | { | |
1572 | aNames.Value (aNames.Upper() - 2), | |
1573 | aNames.Value (aNames.Upper() - 1), | |
1574 | aNames.Value (aNames.Upper() - 0) | |
1575 | }; | |
1576 | isOk = anRgbStr[0].IsRealValue() | |
1577 | && anRgbStr[1].IsRealValue() | |
1578 | && anRgbStr[2].IsRealValue(); | |
1579 | if (isOk) | |
1580 | { | |
1581 | Graphic3d_Vec4d anRgb; | |
1582 | anRgb.x() = anRgbStr[0].RealValue(); | |
1583 | anRgb.y() = anRgbStr[1].RealValue(); | |
1584 | anRgb.z() = anRgbStr[2].RealValue(); | |
1585 | if (anRgb.x() < 0.0 || anRgb.x() > 1.0 | |
1586 | || anRgb.y() < 0.0 || anRgb.y() > 1.0 | |
1587 | || anRgb.z() < 0.0 || anRgb.z() > 1.0) | |
1588 | { | |
1589 | std::cout << "Error: RGB color values should be within range 0..1!\n"; | |
1590 | return 1; | |
1591 | } | |
1592 | aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB); | |
1593 | aNames.Remove (aNames.Length()); | |
1594 | aNames.Remove (aNames.Length()); | |
1595 | aNames.Remove (aNames.Length()); | |
1596 | } | |
1597 | } | |
1598 | if (!isOk) | |
1599 | { | |
1600 | std::cout << "Error: not enough arguments!\n"; | |
1601 | return 1; | |
1602 | } | |
ad3217cd | 1603 | } |
1604 | else if (aCmdName == "vunsetcolor") | |
1605 | { | |
1606 | aChangeSet->ToSetColor = -1; | |
1607 | } | |
1608 | else if (aCmdName == "vsettransparency") | |
1609 | { | |
1610 | if (aNames.IsEmpty() | |
1611 | || !aNames.Last().IsRealValue()) | |
1612 | { | |
1613 | std::cout << "Error: not enough arguments!\n"; | |
1614 | return 1; | |
1615 | } | |
1616 | aChangeSet->ToSetTransparency = 1; | |
1617 | aChangeSet->Transparency = aNames.Last().RealValue(); | |
1618 | aNames.Remove (aNames.Length()); | |
1619 | } | |
1620 | else if (aCmdName == "vunsettransparency") | |
1621 | { | |
1622 | aChangeSet->ToSetTransparency = -1; | |
1623 | } | |
1624 | else if (aCmdName == "vsetmaterial") | |
1625 | { | |
1626 | if (aNames.IsEmpty()) | |
1627 | { | |
1628 | std::cout << "Error: not enough arguments!\n"; | |
1629 | return 1; | |
1630 | } | |
1631 | aChangeSet->ToSetMaterial = 1; | |
1632 | aChangeSet->MatName = aNames.Last(); | |
1633 | aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString()); | |
1634 | aNames.Remove (aNames.Length()); | |
1635 | } | |
1636 | else if (aCmdName == "vunsetmaterial") | |
1637 | { | |
1638 | aChangeSet->ToSetMaterial = -1; | |
1639 | } | |
1640 | else if (anArgIter >= theArgNb) | |
1641 | { | |
1642 | std::cout << "Error: not enough arguments!\n"; | |
1643 | return 1; | |
7fd59977 | 1644 | } |
1645 | ||
ad3217cd | 1646 | if (!aChangeSet->IsEmpty()) |
1647 | { | |
1648 | anArgIter = theArgNb; | |
1649 | } | |
1650 | for (; anArgIter < theArgNb; ++anArgIter) | |
1651 | { | |
1652 | TCollection_AsciiString anArg = theArgVec[anArgIter]; | |
1653 | anArg.LowerCase(); | |
1654 | if (anArg == "-setwidth" | |
1655 | || anArg == "-setlinewidth") | |
1656 | { | |
1657 | if (++anArgIter >= theArgNb) | |
1658 | { | |
1659 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1660 | return 1; | |
1661 | } | |
1662 | aChangeSet->ToSetLineWidth = 1; | |
1663 | aChangeSet->LineWidth = Draw::Atof (theArgVec[anArgIter]); | |
7fd59977 | 1664 | } |
ad3217cd | 1665 | else if (anArg == "-unsetwidth" |
1666 | || anArg == "-unsetlinewidth") | |
1667 | { | |
1668 | aChangeSet->ToSetLineWidth = -1; | |
1669 | aChangeSet->LineWidth = 1.0; | |
1670 | } | |
1671 | else if (anArg == "-settransp" | |
0ae61cf3 | 1672 | || anArg == "-settransparency") |
ad3217cd | 1673 | { |
1674 | if (++anArgIter >= theArgNb) | |
1675 | { | |
1676 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1677 | return 1; | |
1678 | } | |
1679 | aChangeSet->ToSetTransparency = 1; | |
1680 | aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); | |
1681 | if (aChangeSet->Transparency >= 0.0 | |
1682 | && aChangeSet->Transparency <= Precision::Confusion()) | |
1683 | { | |
1684 | aChangeSet->ToSetTransparency = -1; | |
1685 | aChangeSet->Transparency = 0.0; | |
eafb234b | 1686 | } |
7fd59977 | 1687 | } |
5bffb882 | 1688 | else if (anArg == "-setvis" |
1689 | || anArg == "-setvisibility") | |
1690 | { | |
1691 | if (++anArgIter >= theArgNb) | |
1692 | { | |
1693 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1694 | return 1; | |
1695 | } | |
1696 | ||
1697 | aChangeSet->ToSetVisibility = 1; | |
1698 | aChangeSet->Visibility = Draw::Atoi (theArgVec[anArgIter]); | |
1699 | } | |
ad3217cd | 1700 | else if (anArg == "-setalpha") |
1701 | { | |
1702 | if (++anArgIter >= theArgNb) | |
7fd59977 | 1703 | { |
ad3217cd | 1704 | std::cout << "Error: wrong syntax at " << anArg << "\n"; |
1705 | return 1; | |
1706 | } | |
1707 | aChangeSet->ToSetTransparency = 1; | |
1708 | aChangeSet->Transparency = Draw::Atof (theArgVec[anArgIter]); | |
1709 | if (aChangeSet->Transparency < 0.0 | |
1710 | || aChangeSet->Transparency > 1.0) | |
1711 | { | |
1712 | std::cout << "Error: the transparency should be within [0; 1] range (specified " << aChangeSet->Transparency << ")\n"; | |
1713 | return 1; | |
1714 | } | |
1715 | aChangeSet->Transparency = 1.0 - aChangeSet->Transparency; | |
1716 | if (aChangeSet->Transparency >= 0.0 | |
1717 | && aChangeSet->Transparency <= Precision::Confusion()) | |
1718 | { | |
1719 | aChangeSet->ToSetTransparency = -1; | |
1720 | aChangeSet->Transparency = 0.0; | |
7fd59977 | 1721 | } |
7fd59977 | 1722 | } |
ad3217cd | 1723 | else if (anArg == "-unsettransp" |
0ae61cf3 | 1724 | || anArg == "-unsettransparency" |
ad3217cd | 1725 | || anArg == "-unsetalpha" |
1726 | || anArg == "-opaque") | |
1727 | { | |
1728 | aChangeSet->ToSetTransparency = -1; | |
1729 | aChangeSet->Transparency = 0.0; | |
1730 | } | |
1731 | else if (anArg == "-setcolor") | |
1732 | { | |
8316c618 | 1733 | Standard_Integer aNbComps = 0; |
1734 | Standard_Integer aCompIter = anArgIter + 1; | |
1735 | for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps) | |
ad3217cd | 1736 | { |
8316c618 | 1737 | if (theArgVec[aCompIter][0] == '-') |
1738 | { | |
1739 | break; | |
1740 | } | |
1741 | } | |
1742 | switch (aNbComps) | |
1743 | { | |
1744 | case 1: | |
1745 | { | |
1746 | Quantity_NameOfColor aColor = Quantity_NOC_BLACK; | |
1747 | Standard_CString aName = theArgVec[anArgIter + 1]; | |
1748 | if (!Quantity_Color::ColorFromName (aName, aColor)) | |
1749 | { | |
1750 | std::cout << "Error: unknown color name '" << aName << "'\n"; | |
1751 | return 1; | |
1752 | } | |
1753 | aChangeSet->Color = aColor; | |
1754 | break; | |
1755 | } | |
1756 | case 3: | |
1757 | { | |
1758 | Graphic3d_Vec3d anRgb; | |
1759 | anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]); | |
1760 | anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]); | |
1761 | anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]); | |
1762 | if (anRgb.x() < 0.0 || anRgb.x() > 1.0 | |
1763 | || anRgb.y() < 0.0 || anRgb.y() > 1.0 | |
1764 | || anRgb.z() < 0.0 || anRgb.z() > 1.0) | |
1765 | { | |
1766 | std::cout << "Error: RGB color values should be within range 0..1!\n"; | |
1767 | return 1; | |
1768 | } | |
1769 | aChangeSet->Color.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB); | |
1770 | break; | |
1771 | } | |
1772 | default: | |
1773 | { | |
1774 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1775 | return 1; | |
1776 | } | |
7fd59977 | 1777 | } |
ad3217cd | 1778 | aChangeSet->ToSetColor = 1; |
8316c618 | 1779 | anArgIter += aNbComps; |
7fd59977 | 1780 | } |
ad3217cd | 1781 | else if (anArg == "-unsetcolor") |
1782 | { | |
1783 | aChangeSet->ToSetColor = -1; | |
1784 | aChangeSet->Color = DEFAULT_COLOR; | |
1785 | } | |
1786 | else if (anArg == "-setmat" | |
1787 | || anArg == "-setmaterial") | |
1788 | { | |
1789 | if (++anArgIter >= theArgNb) | |
1790 | { | |
1791 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1792 | return 1; | |
1793 | } | |
1794 | aChangeSet->ToSetMaterial = 1; | |
1795 | aChangeSet->MatName = theArgVec[anArgIter]; | |
1796 | aChangeSet->Material = Graphic3d_MaterialAspect::MaterialFromName (aChangeSet->MatName.ToCString()); | |
1797 | } | |
1798 | else if (anArg == "-unsetmat" | |
1799 | || anArg == "-unsetmaterial") | |
1800 | { | |
1801 | aChangeSet->ToSetMaterial = -1; | |
1802 | aChangeSet->Material = Graphic3d_NOM_DEFAULT; | |
1803 | } | |
1804 | else if (anArg == "-subshape" | |
1805 | || anArg == "-subshapes") | |
1806 | { | |
6262338c | 1807 | if (isDefaults) |
1808 | { | |
1809 | std::cout << "Error: wrong syntax. -subshapes can not be used together with -defaults call!\n"; | |
1810 | return 1; | |
1811 | } | |
1812 | ||
ad3217cd | 1813 | if (aNames.IsEmpty()) |
1814 | { | |
1815 | std::cout << "Error: main objects should specified explicitly when -subshapes is used!\n"; | |
1816 | return 1; | |
1817 | } | |
7fd59977 | 1818 | |
ad3217cd | 1819 | aChanges.Append (ViewerTest_AspectsChangeSet()); |
1820 | aChangeSet = &aChanges.ChangeLast(); | |
7fd59977 | 1821 | |
ad3217cd | 1822 | for (++anArgIter; anArgIter < theArgNb; ++anArgIter) |
1823 | { | |
1824 | Standard_CString aSubShapeName = theArgVec[anArgIter]; | |
1825 | if (*aSubShapeName == '-') | |
1826 | { | |
1827 | --anArgIter; | |
1828 | break; | |
1829 | } | |
7fd59977 | 1830 | |
ad3217cd | 1831 | TopoDS_Shape aSubShape = DBRep::Get (aSubShapeName); |
1832 | if (aSubShape.IsNull()) | |
1833 | { | |
1834 | std::cerr << "Error: shape " << aSubShapeName << " doesn't found!\n"; | |
1835 | return 1; | |
1836 | } | |
1837 | aChangeSet->SubShapes.Append (aSubShape); | |
1838 | } | |
7fd59977 | 1839 | |
ad3217cd | 1840 | if (aChangeSet->SubShapes.IsEmpty()) |
1841 | { | |
1842 | std::cerr << "Error: empty list is specified after -subshapes!\n"; | |
1843 | return 1; | |
1844 | } | |
1845 | } | |
6262338c | 1846 | else if (anArg == "-freeboundary" |
1847 | || anArg == "-fb") | |
1848 | { | |
1849 | if (++anArgIter >= theArgNb) | |
1850 | { | |
1851 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1852 | return 1; | |
1853 | } | |
1854 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
1855 | aValue.LowerCase(); | |
1856 | if (aValue == "on" | |
1857 | || aValue == "1") | |
1858 | { | |
1859 | aChangeSet->ToSetShowFreeBoundary = 1; | |
1860 | } | |
1861 | else if (aValue == "off" | |
1862 | || aValue == "0") | |
1863 | { | |
1864 | aChangeSet->ToSetShowFreeBoundary = -1; | |
1865 | } | |
1866 | else | |
1867 | { | |
1868 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1869 | return 1; | |
1870 | } | |
1871 | } | |
1872 | else if (anArg == "-setfreeboundarywidth" | |
1873 | || anArg == "-setfbwidth") | |
1874 | { | |
1875 | if (++anArgIter >= theArgNb) | |
1876 | { | |
1877 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1878 | return 1; | |
1879 | } | |
1880 | aChangeSet->ToSetFreeBoundaryWidth = 1; | |
1881 | aChangeSet->FreeBoundaryWidth = Draw::Atof (theArgVec[anArgIter]); | |
1882 | } | |
1883 | else if (anArg == "-unsetfreeboundarywidth" | |
1884 | || anArg == "-unsetfbwidth") | |
1885 | { | |
1886 | aChangeSet->ToSetFreeBoundaryWidth = -1; | |
1887 | aChangeSet->FreeBoundaryWidth = 1.0; | |
1888 | } | |
1889 | else if (anArg == "-setfreeboundarycolor" | |
1890 | || anArg == "-setfbcolor") | |
1891 | { | |
1892 | Standard_Integer aNbComps = 0; | |
1893 | Standard_Integer aCompIter = anArgIter + 1; | |
1894 | for (; aCompIter < theArgNb; ++aCompIter, ++aNbComps) | |
1895 | { | |
1896 | if (theArgVec[aCompIter][0] == '-') | |
1897 | { | |
1898 | break; | |
1899 | } | |
1900 | } | |
1901 | switch (aNbComps) | |
1902 | { | |
1903 | case 1: | |
1904 | { | |
1905 | Quantity_NameOfColor aColor = Quantity_NOC_BLACK; | |
1906 | Standard_CString aName = theArgVec[anArgIter + 1]; | |
1907 | if (!Quantity_Color::ColorFromName (aName, aColor)) | |
1908 | { | |
1909 | std::cout << "Error: unknown free boundary color name '" << aName << "'\n"; | |
1910 | return 1; | |
1911 | } | |
1912 | aChangeSet->FreeBoundaryColor = aColor; | |
1913 | break; | |
1914 | } | |
1915 | case 3: | |
1916 | { | |
1917 | Graphic3d_Vec3d anRgb; | |
1918 | anRgb.x() = Draw::Atof (theArgVec[anArgIter + 1]); | |
1919 | anRgb.y() = Draw::Atof (theArgVec[anArgIter + 2]); | |
1920 | anRgb.z() = Draw::Atof (theArgVec[anArgIter + 3]); | |
1921 | if (anRgb.x() < 0.0 || anRgb.x() > 1.0 | |
1922 | || anRgb.y() < 0.0 || anRgb.y() > 1.0 | |
1923 | || anRgb.z() < 0.0 || anRgb.z() > 1.0) | |
1924 | { | |
1925 | std::cout << "Error: free boundary RGB color values should be within range 0..1!\n"; | |
1926 | return 1; | |
1927 | } | |
1928 | aChangeSet->FreeBoundaryColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB); | |
1929 | break; | |
1930 | } | |
1931 | default: | |
1932 | { | |
1933 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1934 | return 1; | |
1935 | } | |
1936 | } | |
1937 | aChangeSet->ToSetFreeBoundaryColor = 1; | |
1938 | anArgIter += aNbComps; | |
1939 | } | |
1940 | else if (anArg == "-unsetfreeboundarycolor" | |
1941 | || anArg == "-unsetfbcolor") | |
1942 | { | |
1943 | aChangeSet->ToSetFreeBoundaryColor = -1; | |
1944 | aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR; | |
1945 | } | |
ad3217cd | 1946 | else if (anArg == "-unset") |
1947 | { | |
5bffb882 | 1948 | aChangeSet->ToSetVisibility = 1; |
1949 | aChangeSet->Visibility = 1; | |
ad3217cd | 1950 | aChangeSet->ToSetLineWidth = -1; |
1951 | aChangeSet->LineWidth = 1.0; | |
1952 | aChangeSet->ToSetTransparency = -1; | |
1953 | aChangeSet->Transparency = 0.0; | |
1954 | aChangeSet->ToSetColor = -1; | |
1955 | aChangeSet->Color = DEFAULT_COLOR; | |
1956 | aChangeSet->ToSetMaterial = -1; | |
1957 | aChangeSet->Material = Graphic3d_NOM_DEFAULT; | |
6262338c | 1958 | aChangeSet->ToSetShowFreeBoundary = -1; |
1959 | aChangeSet->ToSetFreeBoundaryColor = -1; | |
1960 | aChangeSet->FreeBoundaryColor = DEFAULT_FREEBOUNDARY_COLOR; | |
1961 | aChangeSet->ToSetFreeBoundaryWidth = -1; | |
1962 | aChangeSet->FreeBoundaryWidth = 1.0; | |
7fd59977 | 1963 | } |
7fd59977 | 1964 | else |
ad3217cd | 1965 | { |
1966 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
1967 | return 1; | |
1968 | } | |
7fd59977 | 1969 | } |
99c56d44 | 1970 | |
ad3217cd | 1971 | Standard_Boolean isFirst = Standard_True; |
1972 | for (NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges); | |
1973 | aChangesIter.More(); aChangesIter.Next()) | |
1974 | { | |
1975 | if (!aChangesIter.Value().Validate (!isFirst)) | |
1976 | { | |
1977 | return 1; | |
1978 | } | |
1979 | isFirst = Standard_False; | |
99c56d44 | 1980 | } |
99c56d44 | 1981 | |
ad3217cd | 1982 | if (aCtx->HasOpenedContext()) |
1983 | { | |
1984 | aCtx->CloseLocalContext(); | |
99c56d44 | 1985 | } |
6262338c | 1986 | |
1987 | // special case for -defaults parameter. | |
1988 | // all changed values will be set to DefaultDrawer. | |
1989 | if (isDefaults) | |
1990 | { | |
1991 | const Handle(Prs3d_Drawer)& aDrawer = aCtx->DefaultDrawer(); | |
1992 | ||
1993 | if (aChangeSet->ToSetLineWidth != 0) | |
1994 | { | |
1995 | aDrawer->LineAspect()->SetWidth (aChangeSet->LineWidth); | |
1996 | aDrawer->WireAspect()->SetWidth (aChangeSet->LineWidth); | |
1997 | aDrawer->UnFreeBoundaryAspect()->SetWidth (aChangeSet->LineWidth); | |
1998 | aDrawer->SeenLineAspect()->SetWidth (aChangeSet->LineWidth); | |
1999 | } | |
2000 | if (aChangeSet->ToSetColor != 0) | |
2001 | { | |
2002 | aDrawer->ShadingAspect()->SetColor (aChangeSet->Color); | |
2003 | aDrawer->LineAspect()->SetColor (aChangeSet->Color); | |
2004 | aDrawer->UnFreeBoundaryAspect()->SetColor (aChangeSet->Color); | |
2005 | aDrawer->SeenLineAspect()->SetColor (aChangeSet->Color); | |
2006 | aDrawer->WireAspect()->SetColor (aChangeSet->Color); | |
2007 | aDrawer->PointAspect()->SetColor (aChangeSet->Color); | |
2008 | } | |
2009 | if (aChangeSet->ToSetTransparency != 0) | |
2010 | { | |
2011 | aDrawer->ShadingAspect()->SetTransparency (aChangeSet->Transparency); | |
2012 | } | |
2013 | if (aChangeSet->ToSetMaterial != 0) | |
2014 | { | |
2015 | aDrawer->ShadingAspect()->SetMaterial (aChangeSet->Material); | |
2016 | } | |
2017 | if (aChangeSet->ToSetShowFreeBoundary == 1) | |
2018 | { | |
2019 | aDrawer->SetFreeBoundaryDraw (Standard_True); | |
2020 | } | |
2021 | else if (aChangeSet->ToSetShowFreeBoundary == -1) | |
2022 | { | |
2023 | aDrawer->SetFreeBoundaryDraw (Standard_False); | |
2024 | } | |
2025 | if (aChangeSet->ToSetFreeBoundaryWidth != 0) | |
2026 | { | |
2027 | aDrawer->FreeBoundaryAspect()->SetWidth (aChangeSet->FreeBoundaryWidth); | |
2028 | } | |
2029 | if (aChangeSet->ToSetFreeBoundaryColor != 0) | |
2030 | { | |
2031 | aDrawer->FreeBoundaryAspect()->SetColor (aChangeSet->FreeBoundaryColor); | |
2032 | } | |
2033 | ||
2034 | // redisplay all objects in context | |
2035 | for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next()) | |
2036 | { | |
2037 | Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current(); | |
2038 | if (!aPrs.IsNull()) | |
2039 | { | |
2040 | aCtx->Redisplay (aPrs, Standard_False); | |
2041 | } | |
2042 | } | |
2043 | return 0; | |
2044 | } | |
2045 | ||
ad3217cd | 2046 | for (ViewTest_PrsIter aPrsIter (aNames); aPrsIter.More(); aPrsIter.Next()) |
2047 | { | |
6262338c | 2048 | const TCollection_AsciiString& aName = aPrsIter.CurrentName(); |
2049 | Handle(AIS_InteractiveObject) aPrs = aPrsIter.Current(); | |
2050 | Handle(Prs3d_Drawer) aDrawer = aPrs->Attributes(); | |
ad3217cd | 2051 | Handle(AIS_ColoredShape) aColoredPrs; |
2052 | Standard_Boolean toDisplay = Standard_False; | |
6262338c | 2053 | Standard_Boolean toRedisplay = Standard_False; |
5bffb882 | 2054 | if (aChanges.Length() > 1 || aChangeSet->ToSetVisibility == 1) |
ad3217cd | 2055 | { |
2056 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast (aPrs); | |
2057 | if (aShapePrs.IsNull()) | |
2058 | { | |
2059 | std::cout << "Error: an object " << aName << " is not an AIS_Shape presentation!\n"; | |
2060 | return 1; | |
2061 | } | |
2062 | aColoredPrs = Handle(AIS_ColoredShape)::DownCast (aShapePrs); | |
2063 | if (aColoredPrs.IsNull()) | |
2064 | { | |
2065 | aColoredPrs = new AIS_ColoredShape (aShapePrs); | |
2066 | aCtx->Remove (aShapePrs, Standard_False); | |
2067 | GetMapOfAIS().UnBind2 (aName); | |
2068 | GetMapOfAIS().Bind (aColoredPrs, aName); | |
2069 | toDisplay = Standard_True; | |
2070 | aShapePrs = aColoredPrs; | |
2071 | aPrs = aColoredPrs; | |
2072 | } | |
2073 | } | |
99c56d44 | 2074 | |
ad3217cd | 2075 | if (!aPrs.IsNull()) |
2076 | { | |
2077 | NCollection_Sequence<ViewerTest_AspectsChangeSet>::Iterator aChangesIter (aChanges); | |
2078 | aChangeSet = &aChangesIter.ChangeValue(); | |
5bffb882 | 2079 | if (aChangeSet->ToSetVisibility == 1) |
2080 | { | |
2081 | Handle(AIS_ColoredDrawer) aColDrawer = aColoredPrs->CustomAspects (aColoredPrs->Shape()); | |
2082 | aColDrawer->SetHidden (aChangeSet->Visibility == 0); | |
2083 | } | |
2084 | else if (aChangeSet->ToSetMaterial == 1) | |
ad3217cd | 2085 | { |
2086 | aCtx->SetMaterial (aPrs, aChangeSet->Material, Standard_False); | |
2087 | } | |
2088 | else if (aChangeSet->ToSetMaterial == -1) | |
2089 | { | |
2090 | aCtx->UnsetMaterial (aPrs, Standard_False); | |
2091 | } | |
2092 | if (aChangeSet->ToSetColor == 1) | |
2093 | { | |
2094 | aCtx->SetColor (aPrs, aChangeSet->Color, Standard_False); | |
2095 | } | |
2096 | else if (aChangeSet->ToSetColor == -1) | |
2097 | { | |
2098 | aCtx->UnsetColor (aPrs, Standard_False); | |
2099 | } | |
2100 | if (aChangeSet->ToSetTransparency == 1) | |
2101 | { | |
2102 | aCtx->SetTransparency (aPrs, aChangeSet->Transparency, Standard_False); | |
2103 | } | |
2104 | else if (aChangeSet->ToSetTransparency == -1) | |
2105 | { | |
2106 | aCtx->UnsetTransparency (aPrs, Standard_False); | |
2107 | } | |
2108 | if (aChangeSet->ToSetLineWidth == 1) | |
2109 | { | |
2110 | aCtx->SetWidth (aPrs, aChangeSet->LineWidth, Standard_False); | |
2111 | } | |
2112 | else if (aChangeSet->ToSetLineWidth == -1) | |
2113 | { | |
2114 | aCtx->UnsetWidth (aPrs, Standard_False); | |
2115 | } | |
6262338c | 2116 | if (!aDrawer.IsNull()) |
2117 | { | |
2118 | if (aChangeSet->ToSetShowFreeBoundary == 1) | |
2119 | { | |
2120 | aDrawer->SetFreeBoundaryDraw (Standard_True); | |
2121 | toRedisplay = Standard_True; | |
2122 | } | |
2123 | else if (aChangeSet->ToSetShowFreeBoundary == -1) | |
2124 | { | |
2125 | aDrawer->SetFreeBoundaryDraw (Standard_False); | |
2126 | toRedisplay = Standard_True; | |
2127 | } | |
2128 | if (aChangeSet->ToSetFreeBoundaryWidth != 0) | |
2129 | { | |
2130 | Handle(Prs3d_LineAspect) aBoundaryAspect = | |
2131 | new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0); | |
2132 | *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect(); | |
2133 | aBoundaryAspect->SetWidth (aChangeSet->FreeBoundaryWidth); | |
2134 | aDrawer->SetFreeBoundaryAspect (aBoundaryAspect); | |
2135 | toRedisplay = Standard_True; | |
2136 | } | |
2137 | if (aChangeSet->ToSetFreeBoundaryColor != 0) | |
2138 | { | |
2139 | Handle(Prs3d_LineAspect) aBoundaryAspect = | |
2140 | new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0); | |
2141 | *aBoundaryAspect->Aspect() = *aDrawer->FreeBoundaryAspect()->Aspect(); | |
2142 | aBoundaryAspect->SetColor (aChangeSet->FreeBoundaryColor); | |
2143 | aDrawer->SetFreeBoundaryAspect (aBoundaryAspect); | |
2144 | toRedisplay = Standard_True; | |
2145 | } | |
2146 | } | |
99c56d44 | 2147 | |
ad3217cd | 2148 | for (aChangesIter.Next(); aChangesIter.More(); aChangesIter.Next()) |
2149 | { | |
2150 | aChangeSet = &aChangesIter.ChangeValue(); | |
2151 | for (NCollection_Sequence<TopoDS_Shape>::Iterator aSubShapeIter (aChangeSet->SubShapes); | |
2152 | aSubShapeIter.More(); aSubShapeIter.Next()) | |
2153 | { | |
2154 | const TopoDS_Shape& aSubShape = aSubShapeIter.Value(); | |
5bffb882 | 2155 | if (aChangeSet->ToSetVisibility == 1) |
2156 | { | |
2157 | Handle(AIS_ColoredDrawer) aCurColDrawer = aColoredPrs->CustomAspects (aSubShape); | |
2158 | aCurColDrawer->SetHidden (aChangeSet->Visibility == 0); | |
2159 | } | |
ad3217cd | 2160 | if (aChangeSet->ToSetColor == 1) |
2161 | { | |
2162 | aColoredPrs->SetCustomColor (aSubShape, aChangeSet->Color); | |
2163 | } | |
2164 | if (aChangeSet->ToSetLineWidth == 1) | |
2165 | { | |
2166 | aColoredPrs->SetCustomWidth (aSubShape, aChangeSet->LineWidth); | |
2167 | } | |
2168 | if (aChangeSet->ToSetColor == -1 | |
2169 | || aChangeSet->ToSetLineWidth == -1) | |
2170 | { | |
2171 | aColoredPrs->UnsetCustomAspects (aSubShape, Standard_True); | |
2172 | } | |
2173 | } | |
2174 | } | |
2175 | if (toDisplay) | |
2176 | { | |
2177 | aCtx->Display (aPrs, Standard_False); | |
2178 | } | |
6262338c | 2179 | if (toRedisplay) |
2180 | { | |
2181 | aCtx->Redisplay (aPrs, Standard_False); | |
2182 | } | |
ad3217cd | 2183 | else if (!aColoredPrs.IsNull()) |
2184 | { | |
2185 | aColoredPrs->Redisplay(); | |
2186 | } | |
99c56d44 | 2187 | } |
99c56d44 | 2188 | else |
ad3217cd | 2189 | { |
2190 | Handle(NIS_InteractiveObject) aNisObj = Handle(NIS_InteractiveObject)::DownCast (aPrsIter.CurrentTrs()); | |
2191 | Handle(NIS_Triangulated) aNisTri = Handle(NIS_Triangulated)::DownCast (aNisObj); | |
2192 | if (!aNisObj.IsNull()) | |
2193 | { | |
2194 | if (aChangeSet->ToSetTransparency != 0) | |
2195 | { | |
2196 | aNisObj->SetTransparency (aChangeSet->Transparency); | |
2197 | } | |
2198 | } | |
2199 | if (!aNisTri.IsNull()) | |
2200 | { | |
2201 | if (aChangeSet->ToSetColor != 0) | |
2202 | { | |
2203 | aNisTri->SetColor (aChangeSet->Color); | |
2204 | } | |
2205 | if (aChangeSet->ToSetLineWidth != 0) | |
2206 | { | |
2207 | aNisTri->SetLineWidth (aChangeSet->LineWidth); | |
2208 | } | |
99c56d44 | 2209 | } |
2210 | } | |
ad3217cd | 2211 | } |
99c56d44 | 2212 | return 0; |
2213 | } | |
2214 | ||
7fd59977 | 2215 | //============================================================================== |
2216 | //function : VDonly2 | |
2217 | //author : ege | |
2218 | //purpose : Display only a selected or named object | |
519d35d8 | 2219 | // if there is no selected or named object s, nothing is done |
7fd59977 | 2220 | //============================================================================== |
519d35d8 | 2221 | static int VDonly2 (Draw_Interpretor& , |
2222 | Standard_Integer theArgNb, | |
2223 | const char** theArgVec) | |
7fd59977 | 2224 | { |
519d35d8 | 2225 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
4e18052b | 2226 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
519d35d8 | 2227 | if (aCtx.IsNull()) |
2228 | { | |
2229 | std::cerr << "Error: no active view!\n"; | |
7fd59977 | 2230 | return 1; |
519d35d8 | 2231 | } |
7fd59977 | 2232 | |
519d35d8 | 2233 | if (aCtx->HasOpenedContext()) |
2234 | { | |
2235 | aCtx->CloseLocalContext(); | |
2236 | } | |
7fd59977 | 2237 | |
519d35d8 | 2238 | Standard_Integer anArgIter = 1; |
2239 | for (; anArgIter < theArgNb; ++anArgIter) | |
2240 | { | |
4e18052b | 2241 | if (!anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) |
519d35d8 | 2242 | { |
2243 | break; | |
2244 | } | |
2245 | } | |
7fd59977 | 2246 | |
519d35d8 | 2247 | NCollection_Map<Handle(Standard_Transient)> aDispSet; |
2248 | if (anArgIter >= theArgNb) | |
2249 | { | |
2250 | // display only selected objects | |
2251 | if (aCtx->NbCurrents() < 1) | |
2252 | { | |
2253 | return 0; | |
7fd59977 | 2254 | } |
2255 | ||
519d35d8 | 2256 | for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent()) |
2257 | { | |
2258 | aDispSet.Add (aCtx->Current()); | |
2259 | } | |
2260 | } | |
2261 | else | |
2262 | { | |
2263 | // display only specified objects | |
2264 | for (; anArgIter < theArgNb; ++anArgIter) | |
2265 | { | |
2266 | TCollection_AsciiString aName = theArgVec[anArgIter]; | |
2267 | if (GetMapOfAIS().IsBound2 (aName)) | |
2268 | { | |
2269 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); | |
2270 | if (anObj->IsKind (STANDARD_TYPE(AIS_InteractiveObject))) | |
2271 | { | |
2272 | const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
2273 | aCtx->Display (aShape, Standard_False); | |
2274 | } | |
2275 | else if (anObj->IsKind (STANDARD_TYPE(NIS_InteractiveObject))) | |
2276 | { | |
2277 | Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj); | |
2278 | TheNISContext()->Display (aShape); | |
7fd59977 | 2279 | } |
519d35d8 | 2280 | aDispSet.Add (anObj); |
7fd59977 | 2281 | } |
2282 | } | |
7fd59977 | 2283 | } |
519d35d8 | 2284 | |
2285 | // weed out other objects | |
2286 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); anIter.More(); anIter.Next()) | |
2287 | { | |
2288 | if (aDispSet.Contains (anIter.Key1())) | |
2289 | { | |
2290 | continue; | |
2291 | } | |
2292 | ||
2293 | if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject))) | |
2294 | { | |
2295 | const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2296 | aCtx->Erase (aShape, Standard_False); | |
2297 | } | |
2298 | else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject))) | |
2299 | { | |
2300 | const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2301 | TheNISContext()->Erase (aShape); | |
2302 | } | |
2303 | } | |
7fd59977 | 2304 | return 0; |
2305 | } | |
2306 | ||
eef7fc64 | 2307 | //============================================================================== |
2308 | //function : VRemove | |
2309 | //purpose : Removes selected or named objects. | |
2310 | // If there is no selected or named objects, | |
2311 | // all objects in the viewer can be removed with argument -all. | |
2312 | // If -context is in arguments, the object is not deleted from the map of | |
2313 | // objects (deleted only from the current context). | |
2314 | //============================================================================== | |
2315 | int VRemove (Draw_Interpretor& theDI, | |
519d35d8 | 2316 | Standard_Integer theArgNb, |
2317 | const char** theArgVec) | |
eef7fc64 | 2318 | { |
4e18052b | 2319 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
2320 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); | |
2321 | if (aCtx.IsNull()) | |
eef7fc64 | 2322 | { |
b6d587e3 | 2323 | std::cerr << "Error: no active view!\n"; |
eef7fc64 | 2324 | return 1; |
2325 | } | |
2326 | ||
4e18052b | 2327 | Standard_Boolean isContextOnly = Standard_False; |
2328 | Standard_Boolean toRemoveAll = Standard_False; | |
2329 | Standard_Boolean toPrintInfo = Standard_True; | |
b6d587e3 | 2330 | Standard_Boolean toRemoveLocal = Standard_False; |
519d35d8 | 2331 | |
2332 | Standard_Integer anArgIter = 1; | |
2333 | for (; anArgIter < theArgNb; ++anArgIter) | |
2334 | { | |
2335 | TCollection_AsciiString anArg = theArgVec[anArgIter]; | |
2336 | anArg.LowerCase(); | |
2337 | if (anArg == "-context") | |
2338 | { | |
2339 | isContextOnly = Standard_True; | |
2340 | } | |
2341 | else if (anArg == "-all") | |
2342 | { | |
2343 | toRemoveAll = Standard_True; | |
2344 | } | |
b7cd4ba7 | 2345 | else if (anArg == "-noinfo") |
2346 | { | |
2347 | toPrintInfo = Standard_False; | |
2348 | } | |
b6d587e3 | 2349 | else if (anArg == "-local") |
2350 | { | |
2351 | toRemoveLocal = Standard_True; | |
2352 | } | |
2353 | else if (anUpdateTool.parseRedrawMode (anArg)) | |
2354 | { | |
2355 | continue; | |
2356 | } | |
2357 | else | |
519d35d8 | 2358 | { |
2359 | break; | |
2360 | } | |
2361 | } | |
2362 | if (toRemoveAll | |
2363 | && anArgIter < theArgNb) | |
2364 | { | |
b6d587e3 | 2365 | std::cerr << "Error: wrong syntax!\n"; |
2366 | return 1; | |
2367 | } | |
2368 | ||
2369 | if (toRemoveLocal && !aCtx->HasOpenedContext()) | |
2370 | { | |
2371 | std::cerr << "Error: local selection context is not open.\n"; | |
519d35d8 | 2372 | return 1; |
2373 | } | |
b6d587e3 | 2374 | else if (!toRemoveLocal && aCtx->HasOpenedContext()) |
2375 | { | |
2376 | aCtx->CloseAllContexts (Standard_False); | |
2377 | } | |
519d35d8 | 2378 | |
eef7fc64 | 2379 | NCollection_List<TCollection_AsciiString> anIONameList; |
519d35d8 | 2380 | if (toRemoveAll) |
eef7fc64 | 2381 | { |
2382 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
2383 | anIter.More(); anIter.Next()) | |
2384 | { | |
2385 | anIONameList.Append (anIter.Key2()); | |
2386 | } | |
2387 | } | |
519d35d8 | 2388 | else if (anArgIter < theArgNb) // removed objects names are in argument list |
eef7fc64 | 2389 | { |
519d35d8 | 2390 | for (; anArgIter < theArgNb; ++anArgIter) |
eef7fc64 | 2391 | { |
519d35d8 | 2392 | TCollection_AsciiString aName = theArgVec[anArgIter]; |
eef7fc64 | 2393 | if (!GetMapOfAIS().IsBound2 (aName)) |
2394 | { | |
2395 | theDI << aName.ToCString() << " was not bound to some object.\n"; | |
2396 | continue; | |
2397 | } | |
2398 | ||
2399 | const Handle(Standard_Transient)& aTransientObj = GetMapOfAIS().Find2 (aName); | |
2400 | ||
2401 | const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (aTransientObj); | |
2402 | if (!anIO.IsNull()) | |
2403 | { | |
4e18052b | 2404 | if (anIO->GetContext() != aCtx) |
eef7fc64 | 2405 | { |
2406 | theDI << aName.ToCString() << " was not displayed in current context.\n"; | |
2407 | theDI << "Please activate view with this object displayed and try again.\n"; | |
2408 | continue; | |
2409 | } | |
2410 | ||
2411 | anIONameList.Append (aName); | |
2412 | continue; | |
2413 | } | |
2414 | ||
2415 | const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (aTransientObj); | |
2416 | if (!aNisIO.IsNull()) | |
2417 | { | |
2418 | anIONameList.Append (aName); | |
2419 | } | |
2420 | } | |
2421 | } | |
4e18052b | 2422 | else if (aCtx->NbCurrents() > 0 |
eef7fc64 | 2423 | || TheNISContext()->GetSelected().Extent() > 0) |
2424 | { | |
2425 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
2426 | anIter.More(); anIter.Next()) | |
2427 | { | |
2428 | const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2429 | if (!anIO.IsNull()) | |
2430 | { | |
4e18052b | 2431 | if (!aCtx->IsCurrent (anIO)) |
eef7fc64 | 2432 | { |
2433 | continue; | |
2434 | } | |
2435 | ||
2436 | anIONameList.Append (anIter.Key2()); | |
2437 | continue; | |
2438 | } | |
2439 | ||
2440 | const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2441 | if (!aNisIO.IsNull()) | |
2442 | { | |
2443 | if (!TheNISContext()->IsSelected (aNisIO)) | |
2444 | { | |
2445 | continue; | |
2446 | } | |
2447 | ||
2448 | anIONameList.Append (anIter.Key2()); | |
2449 | } | |
2450 | } | |
2451 | } | |
2452 | ||
2453 | // Unbind all removed objects from the map of displayed IO. | |
2454 | for (NCollection_List<TCollection_AsciiString>::Iterator anIter (anIONameList); | |
2455 | anIter.More(); anIter.Next()) | |
2456 | { | |
519d35d8 | 2457 | const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value())); |
519d35d8 | 2458 | if (!anIO.IsNull()) |
2459 | { | |
4e18052b | 2460 | aCtx->Remove (anIO, Standard_False); |
b7cd4ba7 | 2461 | if (toPrintInfo) |
2462 | { | |
2463 | theDI << anIter.Value().ToCString() << " was removed\n"; | |
2464 | } | |
519d35d8 | 2465 | } |
2466 | else | |
2467 | { | |
2468 | const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anIter.Value())); | |
2469 | if (!aNisIO.IsNull()) | |
eef7fc64 | 2470 | { |
519d35d8 | 2471 | TheNISContext()->Remove (aNisIO); |
b7cd4ba7 | 2472 | if (toPrintInfo) |
2473 | { | |
2474 | theDI << anIter.Value().ToCString() << " was removed\n"; | |
2475 | } | |
eef7fc64 | 2476 | } |
519d35d8 | 2477 | } |
519d35d8 | 2478 | if (!isContextOnly) |
2479 | { | |
2480 | GetMapOfAIS().UnBind2 (anIter.Value()); | |
2481 | } | |
2482 | } | |
b6d587e3 | 2483 | |
2484 | // Close local context if it is empty | |
2485 | TColStd_MapOfTransient aLocalIO; | |
2486 | if (aCtx->HasOpenedContext() | |
2487 | && !aCtx->LocalContext()->DisplayedObjects (aLocalIO)) | |
2488 | { | |
2489 | aCtx->CloseAllContexts (Standard_False); | |
2490 | } | |
2491 | ||
eef7fc64 | 2492 | return 0; |
2493 | } | |
2494 | ||
7fd59977 | 2495 | //============================================================================== |
b514beda | 2496 | //function : VErase |
2497 | //purpose : Erase some selected or named objects | |
7fd59977 | 2498 | // if there is no selected or named objects, the whole viewer is erased |
7fd59977 | 2499 | //============================================================================== |
b514beda | 2500 | int VErase (Draw_Interpretor& theDI, |
2501 | Standard_Integer theArgNb, | |
2502 | const char** theArgVec) | |
7fd59977 | 2503 | { |
a1954302 | 2504 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
2505 | const Handle(V3d_View)& aView = ViewerTest::CurrentView(); | |
2506 | ViewerTest_AutoUpdater anUpdateTool (aCtx, aView); | |
4e18052b | 2507 | if (aCtx.IsNull()) |
b514beda | 2508 | { |
b6d587e3 | 2509 | std::cerr << "Error: no active view!\n"; |
7fd59977 | 2510 | return 1; |
b514beda | 2511 | } |
519d35d8 | 2512 | |
519d35d8 | 2513 | const Standard_Boolean toEraseAll = TCollection_AsciiString (theArgNb > 0 ? theArgVec[0] : "") == "veraseall"; |
2514 | ||
2515 | Standard_Integer anArgIter = 1; | |
a272ed94 | 2516 | Standard_Boolean toEraseLocal = Standard_False; |
2517 | Standard_Boolean toEraseInView = Standard_False; | |
b6d587e3 | 2518 | TColStd_SequenceOfAsciiString aNamesOfEraseIO; |
519d35d8 | 2519 | for (; anArgIter < theArgNb; ++anArgIter) |
2520 | { | |
b6d587e3 | 2521 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
2522 | anArgCase.LowerCase(); | |
2523 | if (anUpdateTool.parseRedrawMode (anArgCase)) | |
519d35d8 | 2524 | { |
b6d587e3 | 2525 | continue; |
2526 | } | |
2527 | else if (anArgCase == "-local") | |
2528 | { | |
2529 | toEraseLocal = Standard_True; | |
2530 | } | |
a272ed94 | 2531 | else if (anArgCase == "-view" |
2532 | || anArgCase == "-inview") | |
2533 | { | |
2534 | toEraseInView = Standard_True; | |
2535 | } | |
b6d587e3 | 2536 | else |
2537 | { | |
2538 | aNamesOfEraseIO.Append (theArgVec[anArgIter]); | |
519d35d8 | 2539 | } |
2540 | } | |
2541 | ||
b6d587e3 | 2542 | if (!aNamesOfEraseIO.IsEmpty() && toEraseAll) |
b514beda | 2543 | { |
b6d587e3 | 2544 | std::cerr << "Error: wrong syntax, " << theArgVec[0] << " too much arguments.\n"; |
2545 | return 1; | |
2546 | } | |
7fd59977 | 2547 | |
b6d587e3 | 2548 | if (toEraseLocal && !aCtx->HasOpenedContext()) |
2549 | { | |
2550 | std::cerr << "Error: local selection context is not open.\n"; | |
2551 | return 1; | |
2552 | } | |
2553 | else if (!toEraseLocal && aCtx->HasOpenedContext()) | |
2554 | { | |
2555 | aCtx->CloseAllContexts (Standard_False); | |
2556 | } | |
2557 | ||
2558 | if (!aNamesOfEraseIO.IsEmpty()) | |
2559 | { | |
2560 | // Erase named objects | |
2561 | for (Standard_Integer anIter = 1; anIter <= aNamesOfEraseIO.Length(); ++anIter) | |
b514beda | 2562 | { |
b6d587e3 | 2563 | TCollection_AsciiString aName = aNamesOfEraseIO.Value (anIter); |
b514beda | 2564 | if (!GetMapOfAIS().IsBound2 (aName)) |
2565 | { | |
2566 | continue; | |
2567 | } | |
7fd59977 | 2568 | |
b514beda | 2569 | const Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); |
2570 | const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
2571 | theDI << aName.ToCString() << " "; | |
2572 | if (!anIO.IsNull()) | |
2573 | { | |
a272ed94 | 2574 | if (toEraseInView) |
2575 | { | |
2576 | aCtx->SetViewAffinity (anIO, aView, Standard_False); | |
2577 | } | |
2578 | else | |
2579 | { | |
2580 | aCtx->Erase (anIO, Standard_False); | |
2581 | } | |
b514beda | 2582 | } |
2583 | else | |
2584 | { | |
2585 | const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anObj); | |
2586 | if (!aNisIO.IsNull()) | |
2587 | { | |
2588 | TheNISContext()->Erase (aNisIO); | |
2589 | } | |
7fd59977 | 2590 | } |
7fd59977 | 2591 | } |
7fd59977 | 2592 | } |
b6d587e3 | 2593 | else if (!toEraseAll && aCtx->NbCurrents() > 0) |
b514beda | 2594 | { |
b6d587e3 | 2595 | // Erase selected objects |
b514beda | 2596 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
2597 | anIter.More(); anIter.Next()) | |
2598 | { | |
2599 | const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2600 | if (!anIO.IsNull() | |
4e18052b | 2601 | && aCtx->IsCurrent (anIO)) |
b514beda | 2602 | { |
2603 | theDI << anIter.Key2().ToCString() << " "; | |
a272ed94 | 2604 | if (toEraseInView) |
2605 | { | |
2606 | aCtx->SetViewAffinity (anIO, aView, Standard_False); | |
2607 | } | |
2608 | else | |
2609 | { | |
2610 | aCtx->Erase (anIO, Standard_False); | |
2611 | } | |
7fd59977 | 2612 | } |
2613 | } | |
b514beda | 2614 | } |
519d35d8 | 2615 | else |
b514beda | 2616 | { |
b6d587e3 | 2617 | // Erase all objects |
519d35d8 | 2618 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); |
2619 | anIter.More(); anIter.Next()) | |
b514beda | 2620 | { |
519d35d8 | 2621 | const Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); |
2622 | if (!anIO.IsNull()) | |
2623 | { | |
a272ed94 | 2624 | if (toEraseInView) |
2625 | { | |
2626 | aCtx->SetViewAffinity (anIO, aView, Standard_False); | |
2627 | } | |
2628 | else | |
2629 | { | |
2630 | aCtx->Erase (anIO, Standard_False); | |
2631 | } | |
519d35d8 | 2632 | } |
2633 | else | |
b514beda | 2634 | { |
519d35d8 | 2635 | const Handle(NIS_InteractiveObject) aNisIO = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1()); |
2636 | if (!aNisIO.IsNull()) | |
2637 | { | |
2638 | TheNISContext()->Erase (aNisIO); | |
2639 | } | |
b514beda | 2640 | } |
7fd59977 | 2641 | } |
7fd59977 | 2642 | } |
b6d587e3 | 2643 | |
7fd59977 | 2644 | return 0; |
2645 | } | |
2646 | ||
7fd59977 | 2647 | //============================================================================== |
2648 | //function : VDisplayAll | |
2649 | //author : ege | |
2650 | //purpose : Display all the objects of the Map | |
7fd59977 | 2651 | //============================================================================== |
519d35d8 | 2652 | static int VDisplayAll (Draw_Interpretor& , |
2653 | Standard_Integer theArgNb, | |
2654 | const char** theArgVec) | |
7fd59977 | 2655 | |
2656 | { | |
4e18052b | 2657 | const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); |
2658 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); | |
2659 | if (aCtx.IsNull()) | |
519d35d8 | 2660 | { |
b6d587e3 | 2661 | std::cerr << "Error: no active view!\n"; |
519d35d8 | 2662 | return 1; |
2663 | } | |
2664 | ||
519d35d8 | 2665 | Standard_Integer anArgIter = 1; |
b6d587e3 | 2666 | Standard_Boolean toDisplayLocal = Standard_False; |
519d35d8 | 2667 | for (; anArgIter < theArgNb; ++anArgIter) |
2668 | { | |
b6d587e3 | 2669 | TCollection_AsciiString anArgCase (theArgVec[anArgIter]); |
2670 | anArgCase.LowerCase(); | |
2671 | if (anArgCase == "-local") | |
2672 | { | |
2673 | toDisplayLocal = Standard_True; | |
2674 | } | |
2675 | else if (anUpdateTool.parseRedrawMode (anArgCase)) | |
2676 | { | |
2677 | continue; | |
2678 | } | |
2679 | else | |
519d35d8 | 2680 | { |
2681 | break; | |
7fd59977 | 2682 | } |
519d35d8 | 2683 | } |
2684 | if (anArgIter < theArgNb) | |
2685 | { | |
2686 | std::cout << theArgVec[0] << "Error: wrong syntax\n"; | |
2687 | return 1; | |
2688 | } | |
2689 | ||
b6d587e3 | 2690 | if (toDisplayLocal && !aCtx->HasOpenedContext()) |
519d35d8 | 2691 | { |
b6d587e3 | 2692 | std::cerr << "Error: local selection context is not open.\n"; |
2693 | return 1; | |
2694 | } | |
2695 | else if (!toDisplayLocal && aCtx->HasOpenedContext()) | |
2696 | { | |
2697 | aCtx->CloseLocalContext (Standard_False); | |
519d35d8 | 2698 | } |
2699 | ||
2700 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
2701 | anIter.More(); anIter.Next()) | |
2702 | { | |
2703 | if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject))) | |
2704 | { | |
2705 | const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); | |
4e18052b | 2706 | aCtx->Erase (aShape, Standard_False); |
519d35d8 | 2707 | } |
2708 | else if (anIter.Key1()->IsKind(STANDARD_TYPE(NIS_InteractiveObject))) | |
2709 | { | |
2710 | const Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2711 | TheNISContext()->Erase (aShape); | |
2712 | } | |
2713 | } | |
2714 | ||
2715 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
2716 | anIter.More(); anIter.Next()) | |
2717 | { | |
2718 | if (anIter.Key1()->IsKind (STANDARD_TYPE(AIS_InteractiveObject))) | |
2719 | { | |
2720 | const Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); | |
4e18052b | 2721 | aCtx->Display (aShape, Standard_False); |
519d35d8 | 2722 | } |
2723 | else if (anIter.Key1()->IsKind (STANDARD_TYPE(NIS_InteractiveObject))) | |
2724 | { | |
2725 | Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2726 | TheNISContext()->Display (aShape); | |
7fd59977 | 2727 | } |
7fd59977 | 2728 | } |
2729 | return 0; | |
2730 | } | |
2731 | ||
c2a388f8 | 2732 | //! Auxiliary method to find presentation |
2733 | inline Handle(PrsMgr_Presentation) findPresentation (const Handle(AIS_InteractiveContext)& theCtx, | |
2734 | const Handle(AIS_InteractiveObject)& theIO, | |
2735 | const Standard_Integer theMode) | |
2736 | { | |
2737 | if (theIO.IsNull()) | |
2738 | { | |
2739 | return Handle(PrsMgr_Presentation)(); | |
2740 | } | |
2741 | ||
2742 | if (theMode != -1) | |
2743 | { | |
2744 | if (theCtx->MainPrsMgr()->HasPresentation (theIO, theMode)) | |
2745 | { | |
2746 | return theCtx->MainPrsMgr()->Presentation (theIO, theMode); | |
2747 | } | |
2748 | } | |
2749 | else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theIO->DisplayMode())) | |
2750 | { | |
2751 | return theCtx->MainPrsMgr()->Presentation (theIO, theIO->DisplayMode()); | |
2752 | } | |
2753 | else if (theCtx->MainPrsMgr()->HasPresentation (theIO, theCtx->DisplayMode())) | |
2754 | { | |
2755 | return theCtx->MainPrsMgr()->Presentation (theIO, theCtx->DisplayMode()); | |
2756 | } | |
2757 | return Handle(PrsMgr_Presentation)(); | |
2758 | } | |
2759 | ||
2760 | enum ViewerTest_BndAction | |
2761 | { | |
2762 | BndAction_Hide, | |
2763 | BndAction_Show, | |
2764 | BndAction_Print | |
2765 | }; | |
2766 | ||
2767 | //! Auxiliary method to print bounding box of presentation | |
2768 | inline void bndPresentation (Draw_Interpretor& theDI, | |
2769 | const Handle(PrsMgr_Presentation)& thePrs, | |
2770 | const TCollection_AsciiString& theName, | |
2771 | const ViewerTest_BndAction theAction) | |
2772 | { | |
2773 | switch (theAction) | |
2774 | { | |
2775 | case BndAction_Hide: | |
2776 | { | |
2777 | thePrs->Presentation()->GraphicUnHighlight(); | |
2778 | break; | |
2779 | } | |
2780 | case BndAction_Show: | |
2781 | { | |
a1954302 | 2782 | Handle(Graphic3d_Structure) aPrs = thePrs->Presentation(); |
2783 | aPrs->CStructure()->HighlightColor.r = 0.988235f; | |
2784 | aPrs->CStructure()->HighlightColor.g = 0.988235f; | |
2785 | aPrs->CStructure()->HighlightColor.b = 0.988235f; | |
2786 | aPrs->CStructure()->HighlightWithBndBox (aPrs, Standard_True); | |
c2a388f8 | 2787 | break; |
2788 | } | |
2789 | case BndAction_Print: | |
2790 | { | |
ed063270 | 2791 | Bnd_Box aBox = thePrs->Presentation()->MinMaxValues(); |
2792 | gp_Pnt aMin = aBox.CornerMin(); | |
2793 | gp_Pnt aMax = aBox.CornerMax(); | |
c2a388f8 | 2794 | theDI << theName << "\n" |
ed063270 | 2795 | << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " " |
2796 | << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n"; | |
c2a388f8 | 2797 | break; |
2798 | } | |
2799 | } | |
2800 | } | |
2801 | ||
2802 | //============================================================================== | |
2803 | //function : VBounding | |
2804 | //purpose : | |
2805 | //============================================================================== | |
2806 | int VBounding (Draw_Interpretor& theDI, | |
2807 | Standard_Integer theArgNb, | |
2808 | const char** theArgVec) | |
2809 | { | |
2810 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
4e18052b | 2811 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
c2a388f8 | 2812 | if (aCtx.IsNull()) |
2813 | { | |
2814 | std::cout << "Error: no active view!\n"; | |
2815 | return 1; | |
2816 | } | |
2817 | ||
4e18052b | 2818 | ViewerTest_BndAction anAction = BndAction_Show; |
2819 | Standard_Integer aMode = -1; | |
c2a388f8 | 2820 | |
2821 | Standard_Integer anArgIter = 1; | |
2822 | for (; anArgIter < theArgNb; ++anArgIter) | |
2823 | { | |
2824 | TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
2825 | anArg.LowerCase(); | |
2826 | if (anArg == "-print") | |
2827 | { | |
2828 | anAction = BndAction_Print; | |
2829 | } | |
2830 | else if (anArg == "-show") | |
2831 | { | |
2832 | anAction = BndAction_Show; | |
2833 | } | |
2834 | else if (anArg == "-hide") | |
2835 | { | |
2836 | anAction = BndAction_Hide; | |
2837 | } | |
2838 | else if (anArg == "-mode") | |
2839 | { | |
2840 | if (++anArgIter >= theArgNb) | |
2841 | { | |
2842 | std::cout << "Error: wrong syntax at " << anArg << "\n"; | |
2843 | return 1; | |
2844 | } | |
2845 | aMode = Draw::Atoi (theArgVec[anArgIter]); | |
2846 | } | |
4e18052b | 2847 | else if (!anUpdateTool.parseRedrawMode (anArg)) |
c2a388f8 | 2848 | { |
2849 | break; | |
2850 | } | |
2851 | } | |
2852 | ||
2853 | if (anArgIter < theArgNb) | |
2854 | { | |
2855 | // has a list of names | |
2856 | for (; anArgIter < theArgNb; ++anArgIter) | |
2857 | { | |
2858 | TCollection_AsciiString aName = theArgVec[anArgIter]; | |
2859 | if (!GetMapOfAIS().IsBound2 (aName)) | |
2860 | { | |
2861 | std::cout << "Error: presentation " << aName << " does not exist\n"; | |
2862 | return 1; | |
2863 | } | |
2864 | ||
2865 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName)); | |
2866 | Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode); | |
2867 | if (aPrs.IsNull()) | |
2868 | { | |
2869 | std::cout << "Error: presentation " << aName << " does not exist\n"; | |
2870 | return 1; | |
2871 | } | |
2872 | bndPresentation (theDI, aPrs, aName, anAction); | |
2873 | } | |
2874 | } | |
4e18052b | 2875 | else if (aCtx->NbCurrents() > 0) |
c2a388f8 | 2876 | { |
2877 | // remove all currently selected objects | |
2878 | for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent()) | |
2879 | { | |
2880 | Handle(AIS_InteractiveObject) anIO = aCtx->Current(); | |
2881 | Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode); | |
2882 | if (!aPrs.IsNull()) | |
2883 | { | |
2884 | bndPresentation (theDI, aPrs, GetMapOfAIS().IsBound1 (anIO) ? GetMapOfAIS().Find1 (anIO) : "", anAction); | |
2885 | } | |
2886 | } | |
2887 | } | |
2888 | else | |
2889 | { | |
2890 | // all objects | |
2891 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anIter (GetMapOfAIS()); | |
2892 | anIter.More(); anIter.Next()) | |
2893 | { | |
2894 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anIter.Key1()); | |
2895 | Handle(PrsMgr_Presentation) aPrs = findPresentation (aCtx, anIO, aMode); | |
2896 | if (!aPrs.IsNull()) | |
2897 | { | |
2898 | bndPresentation (theDI, aPrs, anIter.Key2(), anAction); | |
2899 | } | |
2900 | } | |
2901 | } | |
c2a388f8 | 2902 | return 0; |
2903 | } | |
2904 | ||
d399d3c3 | 2905 | //============================================================================== |
2906 | //function : VTexture | |
2907 | //purpose : | |
2908 | //============================================================================== | |
2909 | Standard_Integer VTexture (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgv) | |
7fd59977 | 2910 | { |
d399d3c3 | 2911 | TCollection_AsciiString aCommandName (theArgv[0]); |
7fd59977 | 2912 | |
900f7229 | 2913 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)> aMapOfArgs; |
d399d3c3 | 2914 | if (aCommandName == "vtexture") |
2915 | { | |
2916 | if (theArgsNb < 2) | |
7fd59977 | 2917 | { |
d399d3c3 | 2918 | std::cout << theArgv[0] << ": " << " invalid arguments.\n"; |
2919 | std::cout << "Type help for more information.\n"; | |
31160f80 | 2920 | return 1; |
7fd59977 | 2921 | } |
2922 | ||
d399d3c3 | 2923 | // look for options of vtexture command |
2924 | TCollection_AsciiString aParseKey; | |
2925 | for (Standard_Integer anArgIt = 2; anArgIt < theArgsNb; ++anArgIt) | |
2926 | { | |
2927 | TCollection_AsciiString anArg (theArgv [anArgIt]); | |
7fd59977 | 2928 | |
d399d3c3 | 2929 | anArg.UpperCase(); |
2930 | if (anArg.Value (1) == '-' && !anArg.IsRealValue()) | |
2931 | { | |
2932 | aParseKey = anArg; | |
2933 | aParseKey.Remove (1); | |
2934 | aParseKey.UpperCase(); | |
900f7229 | 2935 | aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); |
d399d3c3 | 2936 | continue; |
2937 | } | |
2938 | ||
2939 | if (aParseKey.IsEmpty()) | |
2940 | { | |
2941 | continue; | |
2942 | } | |
2943 | ||
900f7229 | 2944 | aMapOfArgs(aParseKey)->Append (anArg); |
d399d3c3 | 2945 | } |
2946 | } | |
2947 | else if (aCommandName == "vtexscale" | |
2948 | || aCommandName == "vtexorigin" | |
2949 | || aCommandName == "vtexrepeat") | |
2950 | { | |
2951 | // scan for parameters of vtexscale, vtexorigin, vtexrepeat commands | |
2952 | // equal to -scale, -origin, -repeat options of vtexture command | |
2953 | if (theArgsNb < 2 || theArgsNb > 4) | |
7fd59977 | 2954 | { |
d399d3c3 | 2955 | std::cout << theArgv[0] << ": " << " invalid arguments.\n"; |
2956 | std::cout << "Type help for more information.\n"; | |
31160f80 | 2957 | return 1; |
7fd59977 | 2958 | } |
2959 | ||
900f7229 | 2960 | Handle(TColStd_HSequenceOfAsciiString) anArgs = new TColStd_HSequenceOfAsciiString; |
d399d3c3 | 2961 | if (theArgsNb == 2) |
2962 | { | |
900f7229 | 2963 | anArgs->Append ("OFF"); |
d399d3c3 | 2964 | } |
2965 | else if (theArgsNb == 4) | |
2966 | { | |
900f7229 | 2967 | anArgs->Append (TCollection_AsciiString (theArgv[2])); |
2968 | anArgs->Append (TCollection_AsciiString (theArgv[3])); | |
d399d3c3 | 2969 | } |
7fd59977 | 2970 | |
d399d3c3 | 2971 | TCollection_AsciiString anArgKey; |
2972 | if (aCommandName == "vtexscale") | |
2973 | { | |
2974 | anArgKey = "SCALE"; | |
2975 | } | |
2976 | else if (aCommandName == "vtexorigin") | |
2977 | { | |
2978 | anArgKey = "ORIGIN"; | |
2979 | } | |
2980 | else | |
2981 | { | |
2982 | anArgKey = "REPEAT"; | |
2983 | } | |
2984 | ||
2985 | aMapOfArgs.Bind (anArgKey, anArgs); | |
2986 | } | |
2987 | else if (aCommandName == "vtexdefault") | |
7fd59977 | 2988 | { |
d399d3c3 | 2989 | // scan for parameters of vtexdefault command |
2990 | // equal to -default option of vtexture command | |
900f7229 | 2991 | aMapOfArgs.Bind ("DEFAULT", new TColStd_HSequenceOfAsciiString); |
7fd59977 | 2992 | } |
2993 | ||
d399d3c3 | 2994 | // Check arguments for validity |
900f7229 | 2995 | NCollection_DataMap<TCollection_AsciiString, Handle(TColStd_HSequenceOfAsciiString)>::Iterator aMapIt (aMapOfArgs); |
d399d3c3 | 2996 | for (; aMapIt.More(); aMapIt.Next()) |
2997 | { | |
2998 | const TCollection_AsciiString& aKey = aMapIt.Key(); | |
900f7229 | 2999 | const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); |
d399d3c3 | 3000 | |
3001 | // -scale, -origin, -repeat: one argument "off", or two real values | |
3002 | if ((aKey.IsEqual ("SCALE") || aKey.IsEqual ("ORIGIN") || aKey.IsEqual ("REPEAT")) | |
900f7229 | 3003 | && ((anArgs->Length() == 1 && anArgs->Value(1) == "OFF") |
3004 | || (anArgs->Length() == 2 && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue()))) | |
7fd59977 | 3005 | { |
d399d3c3 | 3006 | continue; |
7fd59977 | 3007 | } |
d399d3c3 | 3008 | |
3009 | // -modulate: single argument "on" / "off" | |
900f7229 | 3010 | if (aKey.IsEqual ("MODULATE") && anArgs->Length() == 1 && (anArgs->Value(1) == "OFF" || anArgs->Value(1) == "ON")) |
d399d3c3 | 3011 | { |
3012 | continue; | |
3013 | } | |
3014 | ||
3015 | // -default: no arguments | |
900f7229 | 3016 | if (aKey.IsEqual ("DEFAULT") && anArgs->IsEmpty()) |
d399d3c3 | 3017 | { |
3018 | continue; | |
3019 | } | |
3020 | ||
3021 | TCollection_AsciiString aLowerKey; | |
3022 | aLowerKey = "-"; | |
3023 | aLowerKey += aKey; | |
3024 | aLowerKey.LowerCase(); | |
3025 | std::cout << theArgv[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; | |
3026 | std::cout << "Type help for more information.\n"; | |
3027 | return 1; | |
3028 | } | |
3029 | ||
3030 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
3031 | if (anAISContext.IsNull()) | |
3032 | { | |
3033 | std::cout << aCommandName << ": " << " please use 'vinit' command to initialize view.\n"; | |
3034 | return 1; | |
3035 | } | |
3036 | ||
3037 | Standard_Integer aPreviousMode = 0; | |
3038 | ||
3039 | ViewerTest::CurrentView()->SetSurfaceDetail (V3d_TEX_ALL); | |
3040 | ||
3041 | TCollection_AsciiString aShapeName (theArgv[1]); | |
3042 | Handle(AIS_InteractiveObject) anIO; | |
3043 | ||
3044 | const ViewerTest_DoubleMapOfInteractiveAndName& aMapOfIO = GetMapOfAIS(); | |
3045 | if (aMapOfIO.IsBound2 (aShapeName)) | |
3046 | { | |
3047 | anIO = Handle(AIS_InteractiveObject)::DownCast (aMapOfIO.Find2 (aShapeName)); | |
3048 | } | |
3049 | ||
3050 | if (anIO.IsNull()) | |
3051 | { | |
3052 | std::cout << aCommandName << ": shape " << aShapeName << " does not exists.\n"; | |
3053 | return 1; | |
3054 | } | |
3055 | ||
3056 | Handle(AIS_TexturedShape) aTexturedIO; | |
3057 | if (anIO->IsKind (STANDARD_TYPE (AIS_TexturedShape))) | |
3058 | { | |
3059 | aTexturedIO = Handle(AIS_TexturedShape)::DownCast (anIO); | |
3060 | aPreviousMode = aTexturedIO->DisplayMode(); | |
3061 | } | |
7fd59977 | 3062 | else |
d399d3c3 | 3063 | { |
2195ab96 | 3064 | anAISContext->Remove (anIO, Standard_False); |
d399d3c3 | 3065 | aTexturedIO = new AIS_TexturedShape (DBRep::Get (theArgv[1])); |
3066 | GetMapOfAIS().UnBind1 (anIO); | |
3067 | GetMapOfAIS().UnBind2 (aShapeName); | |
3068 | GetMapOfAIS().Bind (aTexturedIO, aShapeName); | |
3069 | } | |
3070 | ||
3071 | // ------------------------------------------- | |
3072 | // Turn texturing on/off - only for vtexture | |
3073 | // ------------------------------------------- | |
3074 | ||
3075 | if (aCommandName == "vtexture") | |
3076 | { | |
3077 | TCollection_AsciiString aTextureArg (theArgsNb > 2 ? theArgv[2] : ""); | |
3078 | ||
3079 | if (aTextureArg.IsEmpty()) | |
7fd59977 | 3080 | { |
d399d3c3 | 3081 | std::cout << aCommandName << ": " << " Texture mapping disabled.\n"; |
3082 | std::cout << "To enable it, use 'vtexture NameOfShape NameOfTexture'\n" << "\n"; | |
3083 | ||
3084 | anAISContext->SetDisplayMode (aTexturedIO, AIS_Shaded, Standard_False); | |
3085 | if (aPreviousMode == 3) | |
3086 | { | |
3087 | anAISContext->RecomputePrsOnly (aTexturedIO); | |
3088 | } | |
3089 | ||
3090 | anAISContext->Display (aTexturedIO, Standard_True); | |
3091 | return 0; | |
7fd59977 | 3092 | } |
d399d3c3 | 3093 | else if (aTextureArg.Value(1) != '-') // "-option" on place of texture argument |
7fd59977 | 3094 | { |
d399d3c3 | 3095 | if (aTextureArg == "?") |
3096 | { | |
3097 | TCollection_AsciiString aTextureFolder = Graphic3d_TextureRoot::TexturesFolder(); | |
7fd59977 | 3098 | |
d399d3c3 | 3099 | theDi << "\n Files in current directory : \n" << "\n"; |
3100 | theDi.Eval ("glob -nocomplain *"); | |
7fd59977 | 3101 | |
d399d3c3 | 3102 | TCollection_AsciiString aCmnd ("glob -nocomplain "); |
3103 | aCmnd += aTextureFolder; | |
3104 | aCmnd += "/* "; | |
7fd59977 | 3105 | |
d399d3c3 | 3106 | theDi << "Files in " << aTextureFolder.ToCString() << " : \n" << "\n"; |
3107 | theDi.Eval (aCmnd.ToCString()); | |
3108 | return 0; | |
3109 | } | |
3110 | else | |
3111 | { | |
3112 | aTexturedIO->SetTextureFileName (aTextureArg); | |
3113 | } | |
3114 | } | |
3115 | } | |
7fd59977 | 3116 | |
d399d3c3 | 3117 | // ------------------------------------ |
3118 | // Process other options and commands | |
3119 | // ------------------------------------ | |
7fd59977 | 3120 | |
900f7229 | 3121 | Handle(TColStd_HSequenceOfAsciiString) aValues; |
d399d3c3 | 3122 | if (aMapOfArgs.Find ("DEFAULT", aValues)) |
3123 | { | |
3124 | aTexturedIO->SetTextureRepeat (Standard_False); | |
3125 | aTexturedIO->SetTextureOrigin (Standard_False); | |
3126 | aTexturedIO->SetTextureScale (Standard_False); | |
3127 | aTexturedIO->EnableTextureModulate(); | |
3128 | } | |
3129 | else | |
3130 | { | |
3131 | if (aMapOfArgs.Find ("SCALE", aValues)) | |
3132 | { | |
900f7229 | 3133 | if (aValues->Value(1) != "OFF") |
d399d3c3 | 3134 | { |
900f7229 | 3135 | aTexturedIO->SetTextureScale (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue()); |
d399d3c3 | 3136 | } |
7fd59977 | 3137 | else |
d399d3c3 | 3138 | { |
3139 | aTexturedIO->SetTextureScale (Standard_False); | |
3140 | } | |
3141 | } | |
7fd59977 | 3142 | |
d399d3c3 | 3143 | if (aMapOfArgs.Find ("ORIGIN", aValues)) |
3144 | { | |
900f7229 | 3145 | if (aValues->Value(1) != "OFF") |
d399d3c3 | 3146 | { |
900f7229 | 3147 | aTexturedIO->SetTextureOrigin (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue()); |
d399d3c3 | 3148 | } |
3149 | else | |
3150 | { | |
3151 | aTexturedIO->SetTextureOrigin (Standard_False); | |
3152 | } | |
3153 | } | |
7fd59977 | 3154 | |
d399d3c3 | 3155 | if (aMapOfArgs.Find ("REPEAT", aValues)) |
3156 | { | |
900f7229 | 3157 | if (aValues->Value(1) != "OFF") |
d399d3c3 | 3158 | { |
900f7229 | 3159 | aTexturedIO->SetTextureRepeat (Standard_True, aValues->Value(1).RealValue(), aValues->Value(2).RealValue()); |
d399d3c3 | 3160 | } |
3161 | else | |
3162 | { | |
3163 | aTexturedIO->SetTextureRepeat (Standard_False); | |
3164 | } | |
7fd59977 | 3165 | } |
3166 | ||
d399d3c3 | 3167 | if (aMapOfArgs.Find ("MODULATE", aValues)) |
7fd59977 | 3168 | { |
900f7229 | 3169 | if (aValues->Value(1) == "ON") |
d399d3c3 | 3170 | { |
3171 | aTexturedIO->EnableTextureModulate(); | |
3172 | } | |
3173 | else | |
3174 | { | |
3175 | aTexturedIO->DisableTextureModulate(); | |
3176 | } | |
7fd59977 | 3177 | } |
d399d3c3 | 3178 | } |
3179 | ||
3180 | if (aTexturedIO->DisplayMode() == 3 || aPreviousMode == 3) | |
3181 | { | |
3182 | anAISContext->RecomputePrsOnly (aTexturedIO); | |
3183 | } | |
3184 | else | |
3185 | { | |
3186 | anAISContext->SetDisplayMode (aTexturedIO, 3, Standard_False); | |
3187 | anAISContext->Display (aTexturedIO, Standard_True); | |
3188 | anAISContext->Update (aTexturedIO,Standard_True); | |
3189 | } | |
3190 | ||
31160f80 | 3191 | return 0; |
7fd59977 | 3192 | } |
3193 | ||
3194 | //============================================================================== | |
3195 | //function : VDisplay2 | |
3196 | //author : ege | |
3197 | //purpose : Display an object from its name | |
7fd59977 | 3198 | //============================================================================== |
519d35d8 | 3199 | static int VDisplay2 (Draw_Interpretor& theDI, |
3200 | Standard_Integer theArgNb, | |
3201 | const char** theArgVec) | |
7fd59977 | 3202 | { |
519d35d8 | 3203 | if (theArgNb < 2) |
3204 | { | |
b6d587e3 | 3205 | std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n"; |
519d35d8 | 3206 | return 1; |
3207 | } | |
b6d587e3 | 3208 | |
3209 | Handle(AIS_InteractiveContext) aCtx = ViewerTest::GetAISContext(); | |
3210 | if (aCtx.IsNull()) | |
519d35d8 | 3211 | { |
7fd59977 | 3212 | ViewerTest::ViewerInit(); |
4e18052b | 3213 | aCtx = ViewerTest::GetAISContext(); |
7fd59977 | 3214 | } |
3215 | ||
b6d587e3 | 3216 | // Parse input arguments |
4e18052b | 3217 | ViewerTest_AutoUpdater anUpdateTool (aCtx, ViewerTest::CurrentView()); |
a1954302 | 3218 | Standard_Integer isMutable = -1; |
3219 | Graphic3d_ZLayerId aZLayer = Graphic3d_ZLayerId_UNKNOWN; | |
3220 | Standard_Boolean toDisplayLocal = Standard_False; | |
3221 | Standard_Boolean toReDisplay = Standard_False; | |
b6d587e3 | 3222 | TColStd_SequenceOfAsciiString aNamesOfDisplayIO; |
a1954302 | 3223 | AIS_DisplayStatus aDispStatus = AIS_DS_None; |
a272ed94 | 3224 | Standard_Integer toDisplayInView = Standard_False; |
519d35d8 | 3225 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) |
3226 | { | |
b7cd4ba7 | 3227 | const TCollection_AsciiString aName = theArgVec[anArgIter]; |
3228 | TCollection_AsciiString aNameCase = aName; | |
3229 | aNameCase.LowerCase(); | |
4e18052b | 3230 | if (anUpdateTool.parseRedrawMode (aName)) |
519d35d8 | 3231 | { |
3232 | continue; | |
3233 | } | |
b7cd4ba7 | 3234 | else if (aNameCase == "-mutable") |
3235 | { | |
3236 | isMutable = 1; | |
b7cd4ba7 | 3237 | } |
a1954302 | 3238 | else if (aNameCase == "-neutral") |
3239 | { | |
3240 | aDispStatus = AIS_DS_Displayed; | |
3241 | } | |
3242 | else if (aNameCase == "-immediate" | |
3243 | || aNameCase == "-top") | |
3244 | { | |
3245 | aZLayer = Graphic3d_ZLayerId_Top; | |
3246 | } | |
3247 | else if (aNameCase == "-topmost") | |
3248 | { | |
3249 | aZLayer = Graphic3d_ZLayerId_Topmost; | |
3250 | } | |
3251 | else if (aNameCase == "-osd" | |
3252 | || aNameCase == "-toposd") | |
3253 | { | |
3254 | aZLayer = Graphic3d_ZLayerId_TopOSD; | |
3255 | } | |
3256 | else if (aNameCase == "-layer") | |
3257 | { | |
3258 | if (++anArgIter >= theArgNb) | |
3259 | { | |
3260 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; | |
3261 | return 1; | |
3262 | } | |
3263 | ||
3264 | TCollection_AsciiString aValue (theArgVec[anArgIter]); | |
3265 | if (!aValue.IsIntegerValue()) | |
3266 | { | |
3267 | std::cerr << "Error: wrong syntax at " << aName << ".\n"; | |
3268 | return 1; | |
3269 | } | |
3270 | ||
3271 | aZLayer = aValue.IntegerValue(); | |
3272 | } | |
a272ed94 | 3273 | else if (aNameCase == "-view" |
3274 | || aNameCase == "-inview") | |
3275 | { | |
3276 | toDisplayInView = Standard_True; | |
3277 | } | |
b6d587e3 | 3278 | else if (aNameCase == "-local") |
3279 | { | |
a1954302 | 3280 | aDispStatus = AIS_DS_Temporary; |
b6d587e3 | 3281 | toDisplayLocal = Standard_True; |
3282 | } | |
a1954302 | 3283 | else if (aNameCase == "-redisplay") |
3284 | { | |
3285 | toReDisplay = Standard_True; | |
3286 | } | |
b6d587e3 | 3287 | else |
3288 | { | |
3289 | aNamesOfDisplayIO.Append (aName); | |
3290 | } | |
3291 | } | |
3292 | ||
3293 | if (aNamesOfDisplayIO.IsEmpty()) | |
3294 | { | |
3295 | std::cerr << theArgVec[0] << "Error: wrong number of arguments.\n"; | |
3296 | return 1; | |
3297 | } | |
3298 | ||
3299 | // Prepare context for display | |
3300 | if (toDisplayLocal && !aCtx->HasOpenedContext()) | |
3301 | { | |
3302 | aCtx->OpenLocalContext (Standard_False); | |
3303 | } | |
3304 | else if (!toDisplayLocal && aCtx->HasOpenedContext()) | |
3305 | { | |
3306 | aCtx->CloseAllContexts (Standard_False); | |
3307 | } | |
3308 | ||
3309 | // Display interactive objects | |
3310 | for (Standard_Integer anIter = 1; anIter <= aNamesOfDisplayIO.Length(); ++anIter) | |
3311 | { | |
3312 | const TCollection_AsciiString& aName = aNamesOfDisplayIO.Value(anIter); | |
3313 | ||
3314 | if (!GetMapOfAIS().IsBound2 (aName)) | |
519d35d8 | 3315 | { |
3316 | // create the AIS_Shape from a name | |
3317 | const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName (aName.ToCString()); | |
3318 | if (!aShape.IsNull()) | |
3319 | { | |
b7cd4ba7 | 3320 | if (isMutable != -1) |
3321 | { | |
3322 | aShape->SetMutable (isMutable == 1); | |
3323 | } | |
a1954302 | 3324 | if (aZLayer != Graphic3d_ZLayerId_UNKNOWN) |
3325 | { | |
3326 | aShape->SetZLayer (aZLayer); | |
3327 | } | |
519d35d8 | 3328 | GetMapOfAIS().Bind (aShape, aName); |
a1954302 | 3329 | |
3330 | Standard_Integer aDispMode = aShape->HasDisplayMode() | |
3331 | ? aShape->DisplayMode() | |
3332 | : (aShape->AcceptDisplayMode (aCtx->DisplayMode()) | |
3333 | ? aCtx->DisplayMode() | |
3334 | : 0); | |
3335 | Standard_Integer aSelMode = aShape->HasSelectionMode() && aCtx->GetAutoActivateSelection() | |
3336 | ? aShape->SelectionMode() : -1; | |
3337 | ||
3338 | aCtx->Display (aShape, aDispMode, aSelMode, | |
3339 | Standard_False, aShape->AcceptShapeDecomposition(), | |
3340 | aDispStatus); | |
a272ed94 | 3341 | if (toDisplayInView) |
3342 | { | |
3343 | for (aCtx->CurrentViewer()->InitDefinedViews(); aCtx->CurrentViewer()->MoreDefinedViews(); aCtx->CurrentViewer()->NextDefinedViews()) | |
3344 | { | |
3345 | aCtx->SetViewAffinity (aShape, aCtx->CurrentViewer()->DefinedView(), Standard_False); | |
3346 | } | |
3347 | aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True); | |
3348 | } | |
519d35d8 | 3349 | } |
3350 | continue; | |
3351 | } | |
7fd59977 | 3352 | |
519d35d8 | 3353 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); |
3354 | if (anObj->IsKind (STANDARD_TYPE (AIS_InteractiveObject))) | |
3355 | { | |
3356 | Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
b7cd4ba7 | 3357 | if (isMutable != -1) |
3358 | { | |
3359 | aShape->SetMutable (isMutable == 1); | |
3360 | } | |
a1954302 | 3361 | if (aZLayer != Graphic3d_ZLayerId_UNKNOWN) |
3362 | { | |
3363 | aShape->SetZLayer (aZLayer); | |
3364 | } | |
3365 | ||
3366 | Standard_Integer aDispMode = aShape->HasDisplayMode() | |
3367 | ? aShape->DisplayMode() | |
3368 | : (aShape->AcceptDisplayMode (aCtx->DisplayMode()) | |
3369 | ? aCtx->DisplayMode() | |
3370 | : 0); | |
3371 | Standard_Integer aSelMode = aShape->HasSelectionMode() && aCtx->GetAutoActivateSelection() | |
3372 | ? aShape->SelectionMode() : -1; | |
b7cd4ba7 | 3373 | |
519d35d8 | 3374 | if (aShape->Type() == AIS_KOI_Datum) |
3375 | { | |
3376 | aCtx->Display (aShape, Standard_False); | |
3377 | } | |
3378 | else | |
3379 | { | |
3380 | theDI << "Display " << aName.ToCString() << "\n"; | |
7fd59977 | 3381 | |
519d35d8 | 3382 | // update the Shape in the AIS_Shape |
a1954302 | 3383 | TopoDS_Shape aNewShape = GetShapeFromName (aName.ToCString()); |
519d35d8 | 3384 | Handle(AIS_Shape) aShapePrs = Handle(AIS_Shape)::DownCast(aShape); |
3385 | if (!aShapePrs.IsNull()) | |
3386 | { | |
a1954302 | 3387 | if (!aShapePrs->Shape().IsEqual (aNewShape)) |
3388 | { | |
3389 | toReDisplay = Standard_True; | |
3390 | } | |
519d35d8 | 3391 | aShapePrs->Set (aNewShape); |
7fd59977 | 3392 | } |
a1954302 | 3393 | if (toReDisplay) |
3394 | { | |
3395 | aCtx->Redisplay (aShape, Standard_False); | |
3396 | } | |
3397 | ||
3398 | aCtx->Display (aShape, aDispMode, aSelMode, | |
3399 | Standard_False, aShape->AcceptShapeDecomposition(), | |
3400 | aDispStatus); | |
a272ed94 | 3401 | if (toDisplayInView) |
3402 | { | |
3403 | aCtx->SetViewAffinity (aShape, ViewerTest::CurrentView(), Standard_True); | |
3404 | } | |
7fd59977 | 3405 | } |
3406 | } | |
519d35d8 | 3407 | else if (anObj->IsKind (STANDARD_TYPE (NIS_InteractiveObject))) |
3408 | { | |
3409 | Handle(NIS_InteractiveObject) aShape = Handle(NIS_InteractiveObject)::DownCast (anObj); | |
3410 | TheNISContext()->Display (aShape); | |
7fd59977 | 3411 | } |
3412 | } | |
b6d587e3 | 3413 | |
7fd59977 | 3414 | return 0; |
3415 | } | |
3416 | ||
f3889691 | 3417 | //=============================================================================================== |
3418 | //function : VUpdate | |
3419 | //purpose : | |
3420 | //=============================================================================================== | |
3421 | static int VUpdate (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) | |
3422 | { | |
3423 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3424 | if (aContextAIS.IsNull()) | |
3425 | { | |
3426 | std::cout << theArgVec[0] << "AIS context is not available.\n"; | |
3427 | return 1; | |
3428 | } | |
3429 | ||
3430 | if (theArgsNb < 2) | |
3431 | { | |
3432 | std::cout << theArgVec[0] << ": insufficient arguments. Type help for more information.\n"; | |
3433 | return 1; | |
3434 | } | |
3435 | ||
3436 | const ViewerTest_DoubleMapOfInteractiveAndName& anAISMap = GetMapOfAIS(); | |
3437 | ||
3438 | AIS_ListOfInteractive aListOfIO; | |
3439 | ||
3440 | for (int anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
3441 | { | |
3442 | TCollection_AsciiString aName = TCollection_AsciiString (theArgVec[anArgIt]); | |
3443 | ||
3444 | Handle(AIS_InteractiveObject) anAISObj; | |
3445 | if (anAISMap.IsBound2 (aName)) | |
3446 | { | |
3447 | anAISObj = Handle(AIS_InteractiveObject)::DownCast (anAISMap.Find2 (aName)); | |
3448 | } | |
3449 | ||
3450 | if (anAISObj.IsNull()) | |
3451 | { | |
3452 | std::cout << theArgVec[0] << ": no AIS interactive object named \"" << aName << "\".\n"; | |
3453 | return 1; | |
3454 | } | |
3455 | ||
3456 | aListOfIO.Append (anAISObj); | |
3457 | } | |
3458 | ||
3459 | AIS_ListIteratorOfListOfInteractive anIOIt (aListOfIO); | |
3460 | for (; anIOIt.More(); anIOIt.Next()) | |
3461 | { | |
3462 | aContextAIS->Update (anIOIt.Value(), Standard_False); | |
3463 | } | |
3464 | ||
3465 | aContextAIS->UpdateCurrentViewer(); | |
3466 | ||
3467 | return 0; | |
3468 | } | |
3469 | ||
7fd59977 | 3470 | //============================================================================== |
3471 | //function : VPerf | |
3472 | //purpose : Test the annimation of an object along a | |
3473 | // predifined trajectory | |
3474 | //Draw arg : vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF) | |
3475 | //============================================================================== | |
3476 | ||
3477 | static int VPerf(Draw_Interpretor& di, Standard_Integer , const char** argv) { | |
3478 | ||
3479 | OSD_Timer myTimer; | |
3480 | if (TheAISContext()->HasOpenedContext()) | |
3481 | TheAISContext()->CloseLocalContext(); | |
3482 | ||
c6541a0c | 3483 | Standard_Real Step=4*M_PI/180; |
7fd59977 | 3484 | Standard_Real Angle=0; |
3485 | ||
3486 | Handle(AIS_InteractiveObject) aIO; | |
3487 | if (GetMapOfAIS().IsBound2(argv[1])) | |
3488 | aIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1])); | |
3489 | if (aIO.IsNull()) | |
3490 | return 1; | |
3491 | ||
3492 | Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aIO); | |
3493 | ||
3494 | myTimer.Start(); | |
3495 | ||
91322f44 | 3496 | if (Draw::Atoi(argv[3])==1 ) { |
7fd59977 | 3497 | di<<" Primitives sensibles OFF"<<"\n"; |
3498 | TheAISContext()->Deactivate(aIO); | |
3499 | } | |
3500 | else { | |
3501 | di<<" Primitives sensibles ON"<<"\n"; | |
3502 | } | |
3503 | // Movement par transformation | |
91322f44 | 3504 | if(Draw::Atoi(argv[2]) ==1) { |
7fd59977 | 3505 | di<<" Calcul par Transformation"<<"\n"; |
c6541a0c | 3506 | for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) { |
7fd59977 | 3507 | |
3508 | Angle=Step*myAngle; | |
3509 | gp_Trsf myTransfo; | |
3510 | myTransfo.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ) ,Angle ); | |
3511 | TheAISContext()->SetLocation(aShape,myTransfo); | |
3512 | TheAISContext() ->UpdateCurrentViewer(); | |
3513 | ||
3514 | } | |
3515 | } | |
3516 | else { | |
3517 | di<<" Calcul par Locations"<<"\n"; | |
3518 | gp_Trsf myAngleTrsf; | |
3519 | myAngleTrsf.SetRotation(gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0,0,1) ), Step ); | |
3520 | TopLoc_Location myDeltaAngle (myAngleTrsf); | |
3521 | TopLoc_Location myTrueLoc; | |
3522 | ||
c6541a0c | 3523 | for (Standard_Real myAngle=0;Angle<10*2*M_PI; myAngle++) { |
7fd59977 | 3524 | |
3525 | Angle=Step*myAngle; | |
3526 | myTrueLoc=myTrueLoc*myDeltaAngle; | |
3527 | TheAISContext()->SetLocation(aShape,myTrueLoc ); | |
3528 | TheAISContext() ->UpdateCurrentViewer(); | |
3529 | } | |
3530 | } | |
91322f44 | 3531 | if (Draw::Atoi(argv[3])==1 ){ |
7fd59977 | 3532 | // On reactive la selection des primitives sensibles |
3533 | TheAISContext()->Activate(aIO,0); | |
3534 | } | |
3535 | a3DView() -> Redraw(); | |
3536 | myTimer.Stop(); | |
3537 | di<<" Temps ecoule "<<"\n"; | |
3538 | myTimer.Show(); | |
3539 | return 0; | |
3540 | } | |
3541 | ||
3542 | ||
3543 | //================================================================================== | |
3544 | // Function : VAnimation | |
3545 | //================================================================================== | |
3546 | static int VAnimation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { | |
31160f80 | 3547 | if (argc != 5) { |
7fd59977 | 3548 | di<<"Use: "<<argv[0]<<" CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile"<<"\n"; |
3549 | return 1; | |
3550 | } | |
3551 | ||
3552 | Standard_Real thread = 4; | |
3553 | Standard_Real angleA=0; | |
3554 | Standard_Real angleB; | |
3555 | Standard_Real X; | |
3556 | gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1)); | |
3557 | ||
3558 | BRep_Builder B; | |
3559 | TopoDS_Shape CrankArm; | |
3560 | TopoDS_Shape CylinderHead; | |
3561 | TopoDS_Shape Propeller; | |
3562 | TopoDS_Shape EngineBlock; | |
3563 | ||
3564 | //BRepTools::Read(CrankArm,"/dp_26/Indus/ege/assemblage/CrankArm.rle",B); | |
3565 | //BRepTools::Read(CylinderHead,"/dp_26/Indus/ege/assemblage/CylinderHead.rle",B); | |
3566 | //BRepTools::Read(Propeller,"/dp_26/Indus/ege/assemblage/Propeller.rle",B); | |
3567 | //BRepTools::Read(EngineBlock,"/dp_26/Indus/ege/assemblage/EngineBlock.rle",B); | |
3568 | BRepTools::Read(CrankArm,argv[1],B); | |
3569 | BRepTools::Read(CylinderHead,argv[2],B); | |
3570 | BRepTools::Read(Propeller,argv[3],B); | |
3571 | BRepTools::Read(EngineBlock,argv[4],B); | |
3572 | ||
3573 | if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() || EngineBlock.IsNull()) {di<<" Syntaxe error:loading failure."<<"\n";} | |
3574 | ||
3575 | ||
3576 | OSD_Timer myTimer; | |
3577 | myTimer.Start(); | |
3578 | ||
3579 | Handle(AIS_Shape) myAisCylinderHead = new AIS_Shape (CylinderHead); | |
3580 | Handle(AIS_Shape) myAisEngineBlock = new AIS_Shape (EngineBlock); | |
3581 | Handle(AIS_Shape) myAisCrankArm = new AIS_Shape (CrankArm); | |
3582 | Handle(AIS_Shape) myAisPropeller = new AIS_Shape (Propeller); | |
3583 | ||
3584 | GetMapOfAIS().Bind(myAisCylinderHead,"a"); | |
3585 | GetMapOfAIS().Bind(myAisEngineBlock,"b"); | |
3586 | GetMapOfAIS().Bind(myAisCrankArm,"c"); | |
3587 | GetMapOfAIS().Bind(myAisPropeller,"d"); | |
3588 | ||
b7cd4ba7 | 3589 | myAisCylinderHead->SetMutable (Standard_True); |
3590 | myAisEngineBlock ->SetMutable (Standard_True); | |
3591 | myAisCrankArm ->SetMutable (Standard_True); | |
3592 | myAisPropeller ->SetMutable (Standard_True); | |
7fd59977 | 3593 | |
b7cd4ba7 | 3594 | TheAISContext()->SetColor (myAisCylinderHead, Quantity_NOC_INDIANRED); |
3595 | TheAISContext()->SetColor (myAisEngineBlock, Quantity_NOC_RED); | |
3596 | TheAISContext()->SetColor (myAisPropeller, Quantity_NOC_GREEN); | |
3597 | ||
3598 | TheAISContext()->Display (myAisCylinderHead, Standard_False); | |
3599 | TheAISContext()->Display (myAisEngineBlock, Standard_False); | |
3600 | TheAISContext()->Display (myAisCrankArm, Standard_False); | |
3601 | TheAISContext()->Display (myAisPropeller, Standard_False); | |
7fd59977 | 3602 | |
3603 | TheAISContext()->Deactivate(myAisCylinderHead); | |
3604 | TheAISContext()->Deactivate(myAisEngineBlock ); | |
3605 | TheAISContext()->Deactivate(myAisCrankArm ); | |
3606 | TheAISContext()->Deactivate(myAisPropeller ); | |
3607 | ||
3608 | // Boucle de mouvement | |
c6541a0c | 3609 | for (Standard_Real myAngle = 0;angleA<2*M_PI*10.175 ;myAngle++) { |
7fd59977 | 3610 | |
c6541a0c | 3611 | angleA = thread*myAngle*M_PI/180; |
7fd59977 | 3612 | X = Sin(angleA)*3/8; |
3613 | angleB = atan(X / Sqrt(-X * X + 1)); | |
3614 | Standard_Real decal(25*0.6); | |
3615 | ||
3616 | ||
3617 | //Build a transformation on the display | |
3618 | gp_Trsf aPropellerTrsf; | |
3619 | aPropellerTrsf.SetRotation(Ax1,angleA); | |
3620 | TheAISContext()->SetLocation(myAisPropeller,aPropellerTrsf); | |
3621 | ||
3622 | 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)); | |
3623 | gp_Trsf aCrankArmTrsf; | |
3624 | aCrankArmTrsf.SetTransformation( base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0),gp_Dir(0,0,1)),angleB)); | |
3625 | TheAISContext()->SetLocation(myAisCrankArm,aCrankArmTrsf); | |
3626 | ||
3627 | TheAISContext()->UpdateCurrentViewer(); | |
3628 | } | |
3629 | ||
0717ddc1 | 3630 | TopoDS_Shape myNewCrankArm =myAisCrankArm ->Shape().Located( myAisCrankArm ->Transformation() ); |
3631 | TopoDS_Shape myNewPropeller =myAisPropeller->Shape().Located( myAisPropeller->Transformation() ); | |
7fd59977 | 3632 | |
0717ddc1 | 3633 | myAisCrankArm ->ResetTransformation(); |
3634 | myAisPropeller->ResetTransformation(); | |
7fd59977 | 3635 | |
3636 | myAisCrankArm -> Set(myNewCrankArm ); | |
3637 | myAisPropeller -> Set(myNewPropeller); | |
3638 | ||
3639 | TheAISContext()->Activate(myAisCylinderHead,0); | |
3640 | TheAISContext()->Activate(myAisEngineBlock,0 ); | |
3641 | TheAISContext()->Activate(myAisCrankArm ,0 ); | |
3642 | TheAISContext()->Activate(myAisPropeller ,0 ); | |
3643 | ||
3644 | myTimer.Stop(); | |
3645 | myTimer.Show(); | |
3646 | myTimer.Start(); | |
3647 | ||
3648 | TheAISContext()->Redisplay(myAisCrankArm ,Standard_False); | |
3649 | TheAISContext()->Redisplay(myAisPropeller,Standard_False); | |
3650 | ||
3651 | TheAISContext()->UpdateCurrentViewer(); | |
3652 | a3DView()->Redraw(); | |
3653 | ||
3654 | myTimer.Stop(); | |
3655 | myTimer.Show(); | |
3656 | ||
3657 | return 0; | |
3658 | ||
3659 | } | |
3660 | ||
3661 | //============================================================================== | |
3662 | //function : VShading | |
3663 | //purpose : Sharpen or roughten the quality of the shading | |
3664 | //Draw arg : vshading ShapeName 0.1->0.00001 1 deg-> 30 deg | |
3665 | //============================================================================== | |
5cbef0fe S |
3666 | static int VShading(Draw_Interpretor& ,Standard_Integer argc, const char** argv) |
3667 | { | |
7fd59977 | 3668 | Standard_Real myDevCoef; |
3669 | Handle(AIS_InteractiveObject) TheAisIO; | |
3670 | ||
3671 | // Verifications | |
5cbef0fe S |
3672 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetshading") == 0); |
3673 | ||
7fd59977 | 3674 | if (TheAISContext()->HasOpenedContext()) |
3675 | TheAISContext()->CloseLocalContext(); | |
3676 | ||
3677 | if (argc < 3) { | |
3678 | myDevCoef = 0.0008; | |
3679 | } else { | |
91322f44 | 3680 | myDevCoef =Draw::Atof(argv[2]); |
7fd59977 | 3681 | } |
3682 | ||
7fd59977 | 3683 | TCollection_AsciiString name=argv[1]; |
3684 | if (GetMapOfAIS().IsBound2(name )) | |
5cbef0fe | 3685 | TheAisIO = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); |
7fd59977 | 3686 | if (TheAisIO.IsNull()) |
3687 | TheAisIO=GetAISShapeFromName((const char *)name.ToCString()); | |
3688 | ||
5cbef0fe | 3689 | if (HaveToSet) |
7fd59977 | 3690 | TheAISContext()->SetDeviationCoefficient(TheAisIO,myDevCoef,Standard_True); |
5cbef0fe | 3691 | else |
7fd59977 | 3692 | TheAISContext()->SetDeviationCoefficient(TheAisIO,0.0008,Standard_True); |
3693 | ||
7fd59977 | 3694 | TheAISContext()->Redisplay(TheAisIO); |
3695 | return 0; | |
3696 | } | |
3697 | //============================================================================== | |
3698 | //function : HaveMode | |
3699 | //use : VActivatedModes | |
3700 | //============================================================================== | |
3701 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
3702 | ||
3703 | Standard_Boolean HaveMode(const Handle(AIS_InteractiveObject)& TheAisIO,const Standard_Integer mode ) | |
3704 | { | |
3705 | TColStd_ListOfInteger List; | |
3706 | TheAISContext()->ActivatedModes (TheAisIO,List); | |
3707 | TColStd_ListIteratorOfListOfInteger it; | |
3708 | Standard_Boolean Found=Standard_False; | |
3709 | for (it.Initialize(List); it.More()&&!Found; it.Next() ){ | |
3710 | if (it.Value()==mode ) Found=Standard_True; | |
3711 | } | |
3712 | return Found; | |
3713 | } | |
3714 | ||
3715 | ||
3716 | ||
3717 | //============================================================================== | |
3718 | //function : VActivatedMode | |
3719 | //author : ege | |
3720 | //purpose : permet d'attribuer a chacune des shapes un mode d'activation | |
3721 | // (edges,vertex...)qui lui est propre et le mode de selection standard. | |
3722 | // La fonction s'applique aux shapes selectionnees(current ou selected dans le viewer) | |
3723 | // Dans le cas ou on veut psser la shape en argument, la fonction n'autorise | |
3724 | // qu'un nom et qu'un mode. | |
3725 | //Draw arg : vsetam [ShapeName] mode(0,1,2,3,4,5,6,7) | |
3726 | //============================================================================== | |
3727 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
3728 | ||
3729 | static int VActivatedMode (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3730 | ||
3731 | { | |
7fd59977 | 3732 | Standard_Boolean ThereIsName = Standard_False ; |
3733 | ||
3734 | if(!a3DView().IsNull()){ | |
3735 | ||
5cbef0fe | 3736 | const Standard_Boolean HaveToSet = (strcasecmp(argv[0],"vsetam") == 0); |
7fd59977 | 3737 | // verification des arguments |
3738 | if (HaveToSet) { | |
3739 | if (argc<2||argc>3) { di<<" Syntaxe error"<<"\n";return 1;} | |
5cbef0fe | 3740 | ThereIsName = (argc == 3); |
7fd59977 | 3741 | } |
3742 | else { | |
3743 | // vunsetam | |
3744 | if (argc>1) {di<<" Syntaxe error"<<"\n";return 1;} | |
3745 | else { | |
5cbef0fe S |
3746 | di<<" R.A.Z de tous les modes de selecion"<<"\n"; |
3747 | di<<" Fermeture du Context local"<<"\n"; | |
7fd59977 | 3748 | if (TheAISContext()->HasOpenedContext()) |
3749 | TheAISContext()->CloseLocalContext(); | |
3750 | } | |
7fd59977 | 3751 | } |
3752 | ||
7fd59977 | 3753 | // IL n'y a aps de nom de shape passe en argument |
3754 | if (HaveToSet && !ThereIsName){ | |
91322f44 | 3755 | Standard_Integer aMode=Draw::Atoi(argv [1]); |
7fd59977 | 3756 | |
3757 | const char *cmode="???"; | |
7fd59977 | 3758 | switch (aMode) { |
3759 | case 0: cmode = "Shape"; break; | |
3760 | case 1: cmode = "Vertex"; break; | |
3761 | case 2: cmode = "Edge"; break; | |
3762 | case 3: cmode = "Wire"; break; | |
3763 | case 4: cmode = "Face"; break; | |
3764 | case 5: cmode = "Shell"; break; | |
3765 | case 6: cmode = "Solid"; break; | |
3766 | case 7: cmode = "Compound"; break; | |
3767 | } | |
3768 | ||
3769 | if( !TheAISContext()->HasOpenedContext() ) { | |
5cbef0fe S |
3770 | // il n'y a pas de Context local d'ouvert |
3771 | // on en ouvre un et on charge toutes les shapes displayees | |
3772 | // on load tous les objets displayees et on Activate les objets de la liste | |
3773 | AIS_ListOfInteractive ListOfIO; | |
3774 | // on sauve dans une AISListOfInteractive tous les objets currents | |
3775 | if (TheAISContext()->NbCurrents()>0 ){ | |
3776 | TheAISContext()->UnhilightCurrents(Standard_False); | |
3777 | ||
3778 | for (TheAISContext()->InitCurrent(); TheAISContext()->MoreCurrent(); TheAISContext()->NextCurrent() ){ | |
3779 | ListOfIO.Append(TheAISContext()->Current() ); | |
7fd59977 | 3780 | } |
3781 | } | |
3782 | ||
3783 | TheAISContext()->OpenLocalContext(Standard_False); | |
3784 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
3785 | it (GetMapOfAIS()); | |
3786 | while(it.More()){ | |
3787 | Handle(AIS_InteractiveObject) aIO = | |
3788 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
3789 | if (!aIO.IsNull()) | |
3790 | TheAISContext()->Load(aIO,0,Standard_False); | |
3791 | it.Next(); | |
3792 | } | |
3793 | // traitement des objets qui etaient currents dans le Contexte global | |
3794 | if (!ListOfIO.IsEmpty() ) { | |
3795 | // il y avait des objets currents | |
3796 | AIS_ListIteratorOfListOfInteractive iter; | |
3797 | for (iter.Initialize(ListOfIO); iter.More() ; iter.Next() ) { | |
3798 | Handle(AIS_InteractiveObject) aIO=iter.Value(); | |
3799 | TheAISContext()->Activate(aIO,aMode); | |
3800 | di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
3801 | } | |
3802 | } | |
3803 | else { | |
3804 | // On applique le mode a tous les objets displayes | |
3805 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
3806 | it2 (GetMapOfAIS()); | |
3807 | while(it2.More()){ | |
3808 | Handle(AIS_InteractiveObject) aIO = | |
3809 | Handle(AIS_InteractiveObject)::DownCast(it2.Key1()); | |
3810 | if (!aIO.IsNull()) { | |
3811 | di<<" Mode: "<<cmode<<" ON pour "<<it2.Key2().ToCString() <<"\n"; | |
3812 | TheAISContext()->Activate(aIO,aMode); | |
3813 | } | |
3814 | it2.Next(); | |
3815 | } | |
3816 | } | |
3817 | ||
3818 | } | |
3819 | ||
3820 | else { | |
3821 | // un Context local est deja ouvert | |
3822 | // Traitement des objets du Context local | |
3823 | if (TheAISContext()->NbSelected()>0 ){ | |
3824 | TheAISContext()->UnhilightSelected(Standard_False); | |
3825 | // il y a des objets selected,on les parcourt | |
3826 | for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() ){ | |
3827 | Handle(AIS_InteractiveObject) aIO=TheAISContext()->Interactive(); | |
3828 | ||
3829 | ||
3830 | if (HaveMode(aIO,aMode) ) { | |
3831 | di<<" Mode: "<<cmode<<" OFF pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
3832 | TheAISContext()->Deactivate(aIO,aMode); | |
3833 | } | |
3834 | else{ | |
3835 | di<<" Mode: "<<cmode<<" ON pour "<<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
3836 | TheAISContext()->Activate(aIO,aMode); | |
3837 | } | |
3838 | ||
3839 | } | |
3840 | } | |
3841 | else{ | |
3842 | // il n'y a pas d'objets selected | |
3843 | // tous les objets diplayes sont traites | |
3844 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
3845 | it (GetMapOfAIS()); | |
3846 | while(it.More()){ | |
3847 | Handle(AIS_InteractiveObject) aIO = | |
3848 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
3849 | if (!aIO.IsNull()) { | |
3850 | if (HaveMode(aIO,aMode) ) { | |
3851 | di<<" Mode: "<<cmode<<" OFF pour " | |
3852 | <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
3853 | TheAISContext()->Deactivate(aIO,aMode); | |
3854 | } | |
3855 | else{ | |
3856 | di<<" Mode: "<<cmode<<" ON pour" | |
3857 | <<GetMapOfAIS().Find1(aIO).ToCString() <<"\n"; | |
3858 | TheAISContext()->Activate(aIO,aMode); | |
3859 | } | |
3860 | } | |
3861 | it.Next(); | |
3862 | } | |
3863 | } | |
3864 | } | |
3865 | } | |
3866 | else if (HaveToSet && ThereIsName){ | |
91322f44 | 3867 | Standard_Integer aMode=Draw::Atoi(argv [2]); |
7fd59977 | 3868 | Handle(AIS_InteractiveObject) aIO = |
3869 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[1])); | |
3870 | ||
3871 | if (!aIO.IsNull()) { | |
3872 | const char *cmode="???"; | |
3873 | ||
3874 | switch (aMode) { | |
3875 | case 0: cmode = "Shape"; break; | |
3876 | case 1: cmode = "Vertex"; break; | |
3877 | case 2: cmode = "Edge"; break; | |
3878 | case 3: cmode = "Wire"; break; | |
3879 | case 4: cmode = "Face"; break; | |
3880 | case 5: cmode = "Shell"; break; | |
3881 | case 6: cmode = "Solid"; break; | |
3882 | case 7: cmode = "Compound"; break; | |
3883 | } | |
3884 | ||
3885 | if( !TheAISContext()->HasOpenedContext() ) { | |
3886 | TheAISContext()->OpenLocalContext(Standard_False); | |
3887 | // On charge tous les objets de la map | |
3888 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName it (GetMapOfAIS()); | |
3889 | while(it.More()){ | |
3890 | Handle(AIS_InteractiveObject) aShape= | |
3891 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
3892 | if (!aShape.IsNull()) | |
3893 | TheAISContext()->Load(aShape,0,Standard_False); | |
3894 | it.Next(); | |
3895 | } | |
3896 | TheAISContext()->Activate(aIO,aMode); | |
3897 | di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n"; | |
3898 | } | |
3899 | ||
3900 | else { | |
3901 | // un Context local est deja ouvert | |
3902 | if (HaveMode(aIO,aMode) ) { | |
3903 | di<<" Mode: "<<cmode<<" OFF pour "<<argv[1]<<"\n"; | |
3904 | TheAISContext()->Deactivate(aIO,aMode); | |
3905 | } | |
3906 | else{ | |
3907 | di<<" Mode: "<<cmode<<" ON pour "<<argv[1]<<"\n"; | |
3908 | TheAISContext()->Activate(aIO,aMode); | |
3909 | } | |
3910 | } | |
3911 | } | |
3912 | } | |
3913 | } | |
3914 | return 0; | |
7fd59977 | 3915 | } |
3916 | ||
cb78155f | 3917 | //! Auxiliary method to print Interactive Object information |
3918 | static void objInfo (const NCollection_Map<Handle(AIS_InteractiveObject)>& theDetected, | |
3919 | const Handle(Standard_Transient)& theObject, | |
3920 | Draw_Interpretor& theDI) | |
3921 | { | |
3922 | const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theObject); | |
3923 | if (anObj.IsNull()) | |
3924 | { | |
3925 | theDI << theObject->DynamicType()->Name() << " is not AIS presentation\n"; | |
3926 | return; | |
3927 | } | |
7fd59977 | 3928 | |
cb78155f | 3929 | theDI << (TheAISContext()->IsDisplayed (anObj) ? "Displayed" : "Hidden ") |
3930 | << (TheAISContext()->IsSelected (anObj) ? " Selected" : " ") | |
3931 | << (theDetected.Contains (anObj) ? " Detected" : " ") | |
3932 | << " Type: "; | |
3933 | if (anObj->Type() == AIS_KOI_Datum) | |
3934 | { | |
3935 | // AIS_Datum | |
3936 | if (anObj->Signature() == 3) { theDI << " AIS_Trihedron"; } | |
3937 | else if (anObj->Signature() == 2) { theDI << " AIS_Axis"; } | |
3938 | else if (anObj->Signature() == 6) { theDI << " AIS_Circle"; } | |
3939 | else if (anObj->Signature() == 5) { theDI << " AIS_Line"; } | |
3940 | else if (anObj->Signature() == 7) { theDI << " AIS_Plane"; } | |
3941 | else if (anObj->Signature() == 1) { theDI << " AIS_Point"; } | |
3942 | else if (anObj->Signature() == 4) { theDI << " AIS_PlaneTrihedron"; } | |
7fd59977 | 3943 | } |
3944 | // AIS_Shape | |
cb78155f | 3945 | else if (anObj->Type() == AIS_KOI_Shape |
3946 | && anObj->Signature() == 0) | |
3947 | { | |
3948 | theDI << " AIS_Shape"; | |
7fd59977 | 3949 | } |
cb78155f | 3950 | else if (anObj->Type() == AIS_KOI_Relation) |
3951 | { | |
3952 | // AIS_Dimention and AIS_Relation | |
3953 | Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (anObj); | |
3954 | switch (aRelation->KindOfDimension()) | |
3955 | { | |
3956 | case AIS_KOD_PLANEANGLE: theDI << " AIS_AngleDimension"; break; | |
3957 | case AIS_KOD_LENGTH: theDI << " AIS_Chamf2/3dDimension/AIS_LengthDimension"; break; | |
3958 | case AIS_KOD_DIAMETER: theDI << " AIS_DiameterDimension"; break; | |
3959 | case AIS_KOD_ELLIPSERADIUS: theDI << " AIS_EllipseRadiusDimension"; break; | |
3960 | //case AIS_KOD_FILLETRADIUS: theDI << " AIS_FilletRadiusDimension "; break; | |
3961 | case AIS_KOD_OFFSET: theDI << " AIS_OffsetDimension"; break; | |
3962 | case AIS_KOD_RADIUS: theDI << " AIS_RadiusDimension"; break; | |
3963 | default: theDI << " UNKNOWN dimension"; break; | |
3964 | } | |
3965 | } | |
3966 | else | |
3967 | { | |
3968 | theDI << " UserPrs"; | |
3969 | } | |
3970 | theDI << " (" << theObject->DynamicType()->Name() << ")"; | |
7fd59977 | 3971 | } |
3972 | ||
cb78155f | 3973 | //! Print information about locally selected sub-shapes |
3974 | static void localCtxInfo (Draw_Interpretor& theDI) | |
3975 | { | |
3976 | Handle(AIS_InteractiveContext) aCtx = TheAISContext(); | |
3977 | if (!aCtx->HasOpenedContext()) | |
3978 | { | |
3979 | return; | |
3980 | } | |
7fd59977 | 3981 | |
cb78155f | 3982 | TCollection_AsciiString aPrevName; |
3983 | Handle(AIS_LocalContext) aCtxLoc = aCtx->LocalContext(); | |
3984 | for (aCtxLoc->InitSelected(); aCtxLoc->MoreSelected(); aCtxLoc->NextSelected()) | |
3985 | { | |
3986 | const TopoDS_Shape aSubShape = aCtxLoc->SelectedShape(); | |
3987 | const Handle(AIS_Shape) aShapeIO = Handle(AIS_Shape)::DownCast (aCtxLoc->SelectedInteractive()); | |
3988 | if (aSubShape.IsNull() | |
3989 | || aShapeIO.IsNull() | |
3990 | || !GetMapOfAIS().IsBound1 (aShapeIO)) | |
3991 | { | |
3992 | continue; | |
3993 | } | |
3994 | ||
3995 | const TCollection_AsciiString aParentName = GetMapOfAIS().Find1 (aShapeIO); | |
3996 | TopTools_MapOfShape aFilter; | |
3997 | Standard_Integer aNumber = 0; | |
3998 | const TopoDS_Shape aShape = aShapeIO->Shape(); | |
3999 | for (TopExp_Explorer anIter (aShape, aSubShape.ShapeType()); | |
4000 | anIter.More(); anIter.Next()) | |
4001 | { | |
4002 | if (!aFilter.Add (anIter.Current())) | |
4003 | { | |
4004 | continue; // filter duplicates | |
4005 | } | |
4006 | ||
4007 | ++aNumber; | |
4008 | if (!anIter.Current().IsSame (aSubShape)) | |
4009 | { | |
4010 | continue; | |
4011 | } | |
4012 | ||
4013 | Standard_CString aShapeName = NULL; | |
4014 | switch (aSubShape.ShapeType()) | |
4015 | { | |
4016 | case TopAbs_COMPOUND: aShapeName = " Compound"; break; | |
4017 | case TopAbs_COMPSOLID: aShapeName = "CompSolid"; break; | |
4018 | case TopAbs_SOLID: aShapeName = " Solid"; break; | |
4019 | case TopAbs_SHELL: aShapeName = " Shell"; break; | |
4020 | case TopAbs_FACE: aShapeName = " Face"; break; | |
4021 | case TopAbs_WIRE: aShapeName = " Wire"; break; | |
4022 | case TopAbs_EDGE: aShapeName = " Edge"; break; | |
4023 | case TopAbs_VERTEX: aShapeName = " Vertex"; break; | |
4024 | default: | |
4025 | case TopAbs_SHAPE: aShapeName = " Shape"; break; | |
4026 | } | |
4027 | ||
4028 | if (aParentName != aPrevName) | |
4029 | { | |
4030 | theDI << "Locally selected sub-shapes within " << aParentName << ":\n"; | |
4031 | aPrevName = aParentName; | |
4032 | } | |
4033 | theDI << " " << aShapeName << " #" << aNumber << "\n"; | |
4034 | break; | |
4035 | } | |
4036 | } | |
4037 | } | |
7fd59977 | 4038 | |
4039 | //============================================================================== | |
4040 | //function : VState | |
4041 | //purpose : | |
7fd59977 | 4042 | //============================================================================== |
cb78155f | 4043 | static Standard_Integer VState (Draw_Interpretor& theDI, |
4044 | Standard_Integer theArgNb, | |
4045 | Standard_CString* theArgVec) | |
7fd59977 | 4046 | { |
cb78155f | 4047 | Handle(AIS_InteractiveContext) aCtx = TheAISContext(); |
4048 | if (aCtx.IsNull()) | |
4049 | { | |
4050 | std::cerr << "Error: No opened viewer!\n"; | |
4051 | return 1; | |
7fd59977 | 4052 | } |
cb78155f | 4053 | |
51023771 | 4054 | Standard_Boolean toPrintEntities = Standard_False; |
4055 | Standard_Boolean toCheckSelected = Standard_False; | |
4056 | ||
4057 | for (Standard_Integer anArgIdx = 1; anArgIdx < theArgNb; ++anArgIdx) | |
4058 | { | |
4059 | TCollection_AsciiString anOption (theArgVec[anArgIdx]); | |
4060 | anOption.LowerCase(); | |
4061 | if (anOption == "-detectedentities" | |
4062 | || anOption == "-entities") | |
4063 | { | |
4064 | toPrintEntities = Standard_True; | |
4065 | } | |
4066 | else if (anOption == "-hasselected") | |
4067 | { | |
4068 | toCheckSelected = Standard_True; | |
4069 | } | |
4070 | } | |
4071 | ||
4072 | if (toCheckSelected) | |
4073 | { | |
4074 | aCtx->InitSelected(); | |
4075 | TCollection_AsciiString hasSelected (static_cast<Standard_Integer> (aCtx->HasSelectedShape())); | |
4076 | theDI << "Check if context has selected shape: " << hasSelected << "\n"; | |
4077 | ||
4078 | return 0; | |
4079 | } | |
4080 | ||
4081 | if (toPrintEntities) | |
8e7c8ccf | 4082 | { |
4083 | theDI << "Detected entities:\n"; | |
4084 | Handle(StdSelect_ViewerSelector3d) aSelector = aCtx->HasOpenedContext() ? aCtx->LocalSelector() : aCtx->MainSelector(); | |
4085 | for (aSelector->Init(); aSelector->More(); aSelector->Next()) | |
4086 | { | |
4087 | Handle(SelectBasics_SensitiveEntity) anEntity = aSelector->Primitive (0); | |
4088 | Standard_Real aMatchDMin = 0.0; | |
4089 | Standard_Real aMatchDepth = Precision::Infinite(); | |
4090 | anEntity->Matches (aSelector->LastPickingArguments(), aMatchDMin, aMatchDepth); | |
4091 | ||
4092 | Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId()); | |
4093 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); | |
4094 | ||
4095 | const gp_Lin aLine = aSelector->LastPickingArguments().PickLine(); | |
4096 | const gp_Pnt aPnt = aLine.Location().Translated (gp_Vec (aLine.Direction()) * aMatchDepth); | |
4097 | ||
4098 | TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj); | |
4099 | aName.LeftJustify (20, ' '); | |
4100 | char anInfoStr[512]; | |
4101 | Sprintf (anInfoStr, " Depth: %+.3f Distance: %+.3f Point: %+.3f %+.3f %+.3f", aMatchDepth, aMatchDMin, aPnt.X(), aPnt.Y(), aPnt.Z()); | |
4102 | theDI << " " << aName | |
4103 | << anInfoStr | |
4104 | << " (" << anEntity->DynamicType()->Name() << ")" | |
4105 | << "\n"; | |
4106 | ||
4107 | Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner); | |
4108 | if (!aBRepOwner.IsNull()) | |
4109 | { | |
4110 | theDI << " Detected Shape: " | |
4111 | << aBRepOwner->Shape().TShape()->DynamicType()->Name() | |
4112 | << "\n"; | |
4113 | } | |
4114 | ||
4115 | Handle(Select3D_SensitiveWire) aWire = Handle(Select3D_SensitiveWire)::DownCast (anEntity); | |
4116 | if (!aWire.IsNull()) | |
4117 | { | |
4118 | Handle(Select3D_SensitiveEntity) aSen = aWire->GetLastDetected(); | |
4119 | theDI << " Detected Child: " | |
4120 | << aSen->DynamicType()->Name() | |
4121 | << "\n"; | |
4122 | } | |
4123 | } | |
4124 | return 0; | |
4125 | } | |
4126 | ||
cb78155f | 4127 | NCollection_Map<Handle(AIS_InteractiveObject)> aDetected; |
4128 | for (aCtx->InitDetected(); aCtx->MoreDetected(); aCtx->NextDetected()) | |
4129 | { | |
4130 | aDetected.Add (aCtx->DetectedCurrentObject()); | |
4131 | } | |
4132 | ||
4133 | const Standard_Boolean toShowAll = (theArgNb >= 2 && *theArgVec[1] == '*'); | |
4134 | if (theArgNb >= 2 | |
4135 | && !toShowAll) | |
4136 | { | |
4137 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
7fd59977 | 4138 | { |
cb78155f | 4139 | const TCollection_AsciiString anObjName = theArgVec[anArgIter]; |
4140 | if (!GetMapOfAIS().IsBound2 (anObjName)) | |
4141 | { | |
4142 | theDI << anObjName << " doesn't exist!\n"; | |
4143 | continue; | |
7fd59977 | 4144 | } |
4145 | ||
cb78155f | 4146 | const Handle(Standard_Transient) anObjTrans = GetMapOfAIS().Find2 (anObjName); |
4147 | TCollection_AsciiString aName = anObjName; | |
4148 | aName.LeftJustify (20, ' '); | |
4149 | theDI << " " << aName << " "; | |
4150 | objInfo (aDetected, anObjTrans, theDI); | |
4151 | theDI << "\n"; | |
7fd59977 | 4152 | } |
cb78155f | 4153 | return 0; |
7fd59977 | 4154 | } |
cb78155f | 4155 | |
4156 | if (aCtx->NbCurrents() > 0 | |
4157 | && !toShowAll) | |
4158 | { | |
4159 | for (aCtx->InitCurrent(); aCtx->MoreCurrent(); aCtx->NextCurrent()) | |
4160 | { | |
4161 | Handle(AIS_InteractiveObject) anObj = aCtx->Current(); | |
4162 | TCollection_AsciiString aName = GetMapOfAIS().Find1 (anObj); | |
4163 | aName.LeftJustify (20, ' '); | |
4164 | theDI << aName << " "; | |
4165 | objInfo (aDetected, anObj, theDI); | |
4166 | theDI << "\n"; | |
7fd59977 | 4167 | } |
cb78155f | 4168 | return 0; |
7fd59977 | 4169 | } |
4170 | ||
cb78155f | 4171 | theDI << "Neutral-point state:\n"; |
4172 | for (ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName anObjIter (GetMapOfAIS()); | |
4173 | anObjIter.More(); anObjIter.Next()) | |
4174 | { | |
4175 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anObjIter.Key1()); | |
4176 | if (anObj.IsNull()) | |
4177 | { | |
4178 | continue; | |
4179 | } | |
4180 | ||
4181 | TCollection_AsciiString aName = anObjIter.Key2(); | |
4182 | aName.LeftJustify (20, ' '); | |
4183 | theDI << " " << aName << " "; | |
4184 | objInfo (aDetected, anObj, theDI); | |
4185 | theDI << "\n"; | |
4186 | } | |
4187 | localCtxInfo (theDI); | |
7fd59977 | 4188 | return 0; |
4189 | } | |
4190 | ||
7fd59977 | 4191 | //======================================================================= |
4192 | //function : PickObjects | |
4193 | //purpose : | |
4194 | //======================================================================= | |
4195 | Standard_Boolean ViewerTest::PickObjects(Handle(TColStd_HArray1OfTransient)& arr, | |
4196 | const AIS_KindOfInteractive TheType, | |
4197 | const Standard_Integer TheSignature, | |
4198 | const Standard_Integer MaxPick) | |
4199 | { | |
4200 | Handle(AIS_InteractiveObject) IO; | |
4201 | Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext(); | |
4202 | ||
4203 | // step 1: prepare the data | |
4952a30a | 4204 | if(curindex !=0){ |
7fd59977 | 4205 | Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature); |
4206 | TheAISContext()->AddFilter(F1); | |
4207 | } | |
4208 | ||
4209 | // step 2 : wait for the selection... | |
4210 | // Standard_Boolean IsGood (Standard_False); | |
4211 | // Standard_Integer NbPick(0); | |
4212 | Standard_Boolean NbPickGood (0),NbToReach(arr->Length()); | |
4213 | Standard_Integer NbPickFail(0); | |
4214 | Standard_Integer argccc = 5; | |
4215 | const char *bufff[] = { "A", "B", "C","D", "E" }; | |
4216 | const char **argvvv = (const char **) bufff; | |
4217 | ||
4218 | ||
4219 | while(NbPickGood<NbToReach && NbPickFail <= MaxPick){ | |
4220 | while(ViewerMainLoop(argccc,argvvv)){} | |
4221 | Standard_Integer NbStored = TheAISContext()->NbSelected(); | |
4222 | if((unsigned int ) NbStored != NbPickGood) | |
4223 | NbPickGood= NbStored; | |
4224 | else | |
4225 | NbPickFail++; | |
4226 | cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<endl; | |
4227 | } | |
4228 | ||
4229 | // step3 get result. | |
4230 | ||
4231 | if((unsigned int ) NbPickFail >= NbToReach) return Standard_False; | |
4232 | ||
4233 | Standard_Integer i(0); | |
4234 | for(TheAISContext()->InitSelected(); | |
4235 | TheAISContext()->MoreSelected(); | |
4236 | TheAISContext()->NextSelected()){ | |
4237 | i++; | |
4238 | Handle(AIS_InteractiveObject) IO2 = TheAISContext()->SelectedInteractive(); | |
4239 | arr->SetValue(i,IO2); | |
4240 | } | |
4241 | ||
4242 | ||
4243 | if(curindex>0) | |
4244 | TheAISContext()->CloseLocalContext(curindex); | |
4245 | ||
4246 | return Standard_True; | |
4247 | } | |
4248 | ||
4249 | ||
4250 | //======================================================================= | |
4251 | //function : PickObject | |
4252 | //purpose : | |
4253 | //======================================================================= | |
4254 | Handle(AIS_InteractiveObject) ViewerTest::PickObject(const AIS_KindOfInteractive TheType, | |
4255 | const Standard_Integer TheSignature, | |
4256 | const Standard_Integer MaxPick) | |
4257 | { | |
4258 | Handle(AIS_InteractiveObject) IO; | |
4259 | Standard_Integer curindex = (TheType == AIS_KOI_None) ? 0 : TheAISContext()->OpenLocalContext(); | |
4260 | ||
4261 | // step 1: prepare the data | |
4262 | ||
4952a30a | 4263 | if(curindex !=0){ |
7fd59977 | 4264 | Handle(AIS_SignatureFilter) F1 = new AIS_SignatureFilter(TheType,TheSignature); |
4265 | TheAISContext()->AddFilter(F1); | |
4266 | } | |
4267 | ||
4268 | // step 2 : wait for the selection... | |
4269 | Standard_Boolean IsGood (Standard_False); | |
4270 | Standard_Integer NbPick(0); | |
4271 | Standard_Integer argccc = 5; | |
4272 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
4273 | const char **argvvv = (const char **) bufff; | |
4274 | ||
4275 | ||
4276 | while(!IsGood && NbPick<= MaxPick){ | |
4277 | while(ViewerMainLoop(argccc,argvvv)){} | |
4278 | IsGood = (TheAISContext()->NbSelected()>0) ; | |
4279 | NbPick++; | |
4280 | cout<<"Nb Pick :"<<NbPick<<endl; | |
4281 | } | |
4282 | ||
4283 | ||
4284 | // step3 get result. | |
4285 | if(IsGood){ | |
4286 | TheAISContext()->InitSelected(); | |
4287 | IO = TheAISContext()->SelectedInteractive(); | |
4288 | } | |
4289 | ||
4952a30a | 4290 | if(curindex!=0) |
7fd59977 | 4291 | TheAISContext()->CloseLocalContext(curindex); |
4292 | return IO; | |
4293 | } | |
4294 | ||
4295 | //======================================================================= | |
4296 | //function : PickShape | |
4297 | //purpose : First Activate the rightmode + Put Filters to be able to | |
4298 | // pick objets that are of type <TheType>... | |
4299 | //======================================================================= | |
4300 | ||
4301 | TopoDS_Shape ViewerTest::PickShape(const TopAbs_ShapeEnum TheType, | |
4302 | const Standard_Integer MaxPick) | |
4303 | { | |
4304 | ||
4305 | // step 1: prepare the data | |
4306 | ||
4307 | Standard_Integer curindex = TheAISContext()->OpenLocalContext(); | |
4308 | TopoDS_Shape result; | |
4309 | ||
4310 | if(TheType==TopAbs_SHAPE){ | |
4311 | Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape); | |
4312 | TheAISContext()->AddFilter(F1); | |
4313 | } | |
4314 | else{ | |
4315 | Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType); | |
4316 | TheAISContext()->AddFilter(TF); | |
4317 | TheAISContext()->ActivateStandardMode(TheType); | |
4318 | ||
4319 | } | |
4320 | ||
4321 | ||
4322 | // step 2 : wait for the selection... | |
4323 | Standard_Boolean NoShape (Standard_True); | |
4324 | Standard_Integer NbPick(0); | |
4325 | Standard_Integer argccc = 5; | |
4326 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
4327 | const char **argvvv = (const char **) bufff; | |
4328 | ||
4329 | ||
4330 | while(NoShape && NbPick<= MaxPick){ | |
4331 | while(ViewerMainLoop(argccc,argvvv)){} | |
4332 | NoShape = (TheAISContext()->NbSelected()==0) ; | |
4333 | NbPick++; | |
4334 | cout<<"Nb Pick :"<<NbPick<<endl; | |
4335 | } | |
4336 | ||
4337 | // step3 get result. | |
4338 | ||
4339 | if(!NoShape){ | |
4340 | ||
4341 | TheAISContext()->InitSelected(); | |
4342 | if(TheAISContext()->HasSelectedShape()) | |
4343 | result = TheAISContext()->SelectedShape(); | |
4344 | else{ | |
4345 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); | |
4346 | result = (*((Handle(AIS_Shape)*) &IO))->Shape(); | |
4347 | } | |
4348 | } | |
4349 | ||
4350 | if(curindex>0) | |
4351 | TheAISContext()->CloseLocalContext(curindex); | |
4352 | ||
4353 | return result; | |
4354 | } | |
4355 | ||
4356 | ||
4357 | //======================================================================= | |
4358 | //function : PickShapes | |
4359 | //purpose : | |
4360 | //======================================================================= | |
4361 | Standard_Boolean ViewerTest::PickShapes (const TopAbs_ShapeEnum TheType, | |
4362 | Handle(TopTools_HArray1OfShape)& thearr, | |
4363 | const Standard_Integer MaxPick) | |
4364 | { | |
4365 | ||
4366 | Standard_Integer Taille = thearr->Length(); | |
4367 | if(Taille>1) | |
4368 | cout<<" WARNING : Pick with Shift+ MB1 for Selection of more than 1 object"<<"\n"; | |
4369 | ||
4370 | // step 1: prepare the data | |
4371 | Standard_Integer curindex = TheAISContext()->OpenLocalContext(); | |
4372 | if(TheType==TopAbs_SHAPE){ | |
4373 | Handle(AIS_TypeFilter) F1 = new AIS_TypeFilter(AIS_KOI_Shape); | |
4374 | TheAISContext()->AddFilter(F1); | |
4375 | } | |
4376 | else{ | |
4377 | Handle(StdSelect_ShapeTypeFilter) TF = new StdSelect_ShapeTypeFilter(TheType); | |
4378 | TheAISContext()->AddFilter(TF); | |
4379 | TheAISContext()->ActivateStandardMode(TheType); | |
4380 | ||
4381 | } | |
4382 | ||
4383 | // step 2 : wait for the selection... | |
4384 | ||
4385 | Standard_Boolean NbPickGood (0),NbToReach(thearr->Length()); | |
4386 | Standard_Integer NbPickFail(0); | |
4387 | Standard_Integer argccc = 5; | |
4388 | const char *bufff[] = { "A", "B", "C","D", "E" }; | |
4389 | const char **argvvv = (const char **) bufff; | |
4390 | ||
4391 | ||
4392 | while(NbPickGood<NbToReach && NbPickFail <= MaxPick){ | |
4393 | while(ViewerMainLoop(argccc,argvvv)){} | |
4394 | Standard_Integer NbStored = TheAISContext()->NbSelected(); | |
4395 | if((unsigned int ) NbStored != NbPickGood) | |
4396 | NbPickGood= NbStored; | |
4397 | else | |
4398 | NbPickFail++; | |
4399 | cout<<"NbPicked = "<<NbPickGood<<" | Nb Pick Fail :"<<NbPickFail<<"\n"; | |
4400 | } | |
4401 | ||
4402 | // step3 get result. | |
4403 | ||
4404 | if((unsigned int ) NbPickFail >= NbToReach) return Standard_False; | |
4405 | ||
4406 | Standard_Integer i(0); | |
4407 | for(TheAISContext()->InitSelected();TheAISContext()->MoreSelected();TheAISContext()->NextSelected()){ | |
4408 | i++; | |
4409 | if(TheAISContext()->HasSelectedShape()) | |
4410 | thearr->SetValue(i,TheAISContext()->SelectedShape()); | |
4411 | else{ | |
4412 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); | |
4413 | thearr->SetValue(i,(*((Handle(AIS_Shape)*) &IO))->Shape()); | |
4414 | } | |
4415 | } | |
4416 | ||
4417 | TheAISContext()->CloseLocalContext(curindex); | |
4418 | return Standard_True; | |
4419 | } | |
4420 | ||
4421 | ||
4422 | //======================================================================= | |
4423 | //function : VPickShape | |
4424 | //purpose : | |
4425 | //======================================================================= | |
4426 | static int VPickShape( Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
4427 | { | |
4428 | TopoDS_Shape PickSh; | |
4429 | TopAbs_ShapeEnum theType = TopAbs_COMPOUND; | |
4430 | ||
4431 | if(argc==1) | |
4432 | theType = TopAbs_SHAPE; | |
4433 | else{ | |
4434 | if(!strcasecmp(argv[1],"V" )) theType = TopAbs_VERTEX; | |
4435 | else if (!strcasecmp(argv[1],"E" )) theType = TopAbs_EDGE; | |
4436 | else if (!strcasecmp(argv[1],"W" )) theType = TopAbs_WIRE; | |
4437 | else if (!strcasecmp(argv[1],"F" )) theType = TopAbs_FACE; | |
4438 | else if(!strcasecmp(argv[1],"SHAPE" )) theType = TopAbs_SHAPE; | |
4439 | else if (!strcasecmp(argv[1],"SHELL" )) theType = TopAbs_SHELL; | |
4440 | else if (!strcasecmp(argv[1],"SOLID" )) theType = TopAbs_SOLID; | |
4441 | } | |
4442 | ||
4443 | static Standard_Integer nbOfSub[8]={0,0,0,0,0,0,0,0}; | |
4444 | static TCollection_AsciiString nameType[8] = {"COMPS","SOL","SHE","F","W","E","V","SHAP"}; | |
4445 | ||
4446 | TCollection_AsciiString name; | |
4447 | ||
4448 | ||
4449 | Standard_Integer NbToPick = argc>2 ? argc-2 : 1; | |
4450 | if(NbToPick==1){ | |
4451 | PickSh = ViewerTest::PickShape(theType); | |
4452 | ||
4453 | if(PickSh.IsNull()) | |
4454 | return 1; | |
4455 | if(argc>2){ | |
4456 | name += argv[2]; | |
4457 | } | |
4458 | else{ | |
4459 | ||
4460 | if(!PickSh.IsNull()){ | |
4461 | nbOfSub[Standard_Integer(theType)]++; | |
4462 | name += "Picked_"; | |
4463 | name += nameType[Standard_Integer(theType)]; | |
4464 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); | |
4465 | name +="_"; | |
4466 | name+=indxstring; | |
4467 | } | |
4468 | } | |
4469 | // si on avait une petite methode pour voir si la shape | |
4470 | // est deja dans la Double map, ca eviterait de creer.... | |
4471 | DBRep::Set(name.ToCString(),PickSh); | |
4472 | ||
4473 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); | |
4474 | GetMapOfAIS().Bind(newsh, name); | |
4475 | TheAISContext()->Display(newsh); | |
4476 | di<<"Nom de la shape pickee : "<<name.ToCString()<<"\n"; | |
4477 | } | |
4478 | ||
4479 | // Plusieurs objets a picker, vite vite vite.... | |
4480 | // | |
4481 | else{ | |
4482 | Standard_Boolean autonaming = !strcasecmp(argv[2],"."); | |
4483 | Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick); | |
4484 | if(ViewerTest::PickShapes(theType,arr)){ | |
4485 | for(Standard_Integer i=1;i<=NbToPick;i++){ | |
4486 | PickSh = arr->Value(i); | |
4487 | if(!PickSh.IsNull()){ | |
4488 | if(autonaming){ | |
4489 | nbOfSub[Standard_Integer(theType)]++; | |
4490 | name.Clear(); | |
4491 | name += "Picked_"; | |
4492 | name += nameType[Standard_Integer(theType)]; | |
4493 | TCollection_AsciiString indxstring(nbOfSub[Standard_Integer(theType)]); | |
4494 | name +="_"; | |
4495 | name+=indxstring; | |
4496 | } | |
4497 | } | |
4498 | else | |
4499 | name = argv[1+i]; | |
4500 | ||
4501 | DBRep::Set(name.ToCString(),PickSh); | |
4502 | Handle(AIS_Shape) newsh = new AIS_Shape(PickSh); | |
4503 | GetMapOfAIS().Bind(newsh, name); | |
4504 | di<<"display of picke shape #"<<i<<" - nom : "<<name.ToCString()<<"\n"; | |
4505 | TheAISContext()->Display(newsh); | |
4506 | ||
4507 | } | |
4508 | } | |
4509 | } | |
4510 | return 0; | |
7fd59977 | 4511 | } |
7fd59977 | 4512 | |
d8110103 | 4513 | //======================================================================= |
4514 | //function : VPickSelected | |
4515 | //purpose : | |
4516 | //======================================================================= | |
4517 | static int VPickSelected (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgs) | |
4518 | { | |
4519 | static Standard_Integer aCount = 0; | |
4520 | TCollection_AsciiString aName = "PickedShape_"; | |
4521 | ||
4522 | if (theArgNb > 1) | |
4523 | { | |
4524 | aName = theArgs[1]; | |
4525 | } | |
4526 | else | |
4527 | { | |
4528 | aName = aName + aCount++ + "_"; | |
4529 | } | |
4530 | ||
4531 | Standard_Integer anIdx = 0; | |
4532 | for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected(), ++anIdx) | |
4533 | { | |
4534 | TopoDS_Shape aShape; | |
4535 | if (TheAISContext()->HasSelectedShape()) | |
4536 | { | |
4537 | aShape = TheAISContext()->SelectedShape(); | |
4538 | } | |
4539 | else | |
4540 | { | |
4541 | Handle(AIS_InteractiveObject) IO = TheAISContext()->SelectedInteractive(); | |
4542 | aShape = (*((Handle(AIS_Shape)*) &IO))->Shape(); | |
4543 | } | |
4544 | ||
4545 | TCollection_AsciiString aCurrentName = aName; | |
4546 | if (anIdx > 0) | |
4547 | { | |
4548 | aCurrentName += anIdx; | |
4549 | } | |
4550 | ||
4551 | DBRep::Set ((aCurrentName).ToCString(), aShape); | |
4552 | ||
4553 | Handle(AIS_Shape) aNewShape = new AIS_Shape (aShape); | |
4554 | GetMapOfAIS().Bind (aNewShape, aCurrentName); | |
4555 | TheAISContext()->Display (aNewShape); | |
4556 | } | |
4557 | ||
4558 | return 0; | |
4559 | } | |
4560 | ||
7fd59977 | 4561 | //======================================================================= |
4562 | //function : list of known objects | |
4563 | //purpose : | |
4564 | //======================================================================= | |
4565 | static int VIOTypes( Draw_Interpretor& di, Standard_Integer , const char** ) | |
4566 | { | |
4567 | // 1234567890 12345678901234567 123456789 | |
4568 | TCollection_AsciiString Colum [3]={"Standard Types","Type Of Object","Signature"}; | |
4569 | TCollection_AsciiString BlankLine(64,'_'); | |
4570 | Standard_Integer i ; | |
4571 | ||
4572 | di<<"/n"<<BlankLine.ToCString()<<"\n"; | |
4573 | ||
4574 | for( i =0;i<=2;i++) | |
4575 | Colum[i].Center(20,' '); | |
4576 | for(i=0;i<=2;i++) | |
4577 | di<<"|"<<Colum[i].ToCString(); | |
4578 | di<<"|"<<"\n"; | |
4579 | ||
4580 | di<<BlankLine.ToCString()<<"\n"; | |
4581 | ||
4582 | // TCollection_AsciiString thetypes[5]={"Datum","Shape","Object","Relation","None"}; | |
4583 | const char ** names = GetTypeNames(); | |
4584 | ||
4585 | TCollection_AsciiString curstring; | |
4586 | TCollection_AsciiString curcolum[3]; | |
4587 | ||
4588 | ||
4589 | // les objets de type Datum.. | |
4590 | curcolum[1]+="Datum"; | |
4591 | for(i =0;i<=6;i++){ | |
4592 | curcolum[0].Clear(); | |
4593 | curcolum[0] += names[i]; | |
4594 | ||
4595 | curcolum[2].Clear(); | |
4596 | curcolum[2]+=TCollection_AsciiString(i+1); | |
4597 | ||
4598 | for(Standard_Integer j =0;j<=2;j++){ | |
4599 | curcolum[j].Center(20,' '); | |
4600 | di<<"|"<<curcolum[j].ToCString(); | |
4601 | } | |
4602 | di<<"|"<<"\n"; | |
4603 | } | |
4604 | di<<BlankLine.ToCString()<<"\n"; | |
4605 | ||
4606 | // les objets de type shape | |
4607 | curcolum[1].Clear(); | |
4608 | curcolum[1]+="Shape"; | |
4609 | curcolum[1].Center(20,' '); | |
4610 | ||
4611 | for(i=0;i<=2;i++){ | |
4612 | curcolum[0].Clear(); | |
4613 | curcolum[0] += names[7+i]; | |
4614 | curcolum[2].Clear(); | |
4615 | curcolum[2]+=TCollection_AsciiString(i); | |
4616 | ||
4617 | for(Standard_Integer j =0;j<=2;j++){ | |
4618 | curcolum[j].Center(20,' '); | |
4619 | di<<"|"<<curcolum[j].ToCString(); | |
4620 | } | |
4621 | di<<"|"<<"\n"; | |
4622 | } | |
4623 | di<<BlankLine.ToCString()<<"\n"; | |
4624 | // les IO de type objet... | |
4625 | curcolum[1].Clear(); | |
4626 | curcolum[1]+="Object"; | |
4627 | curcolum[1].Center(20,' '); | |
4628 | for(i=0;i<=1;i++){ | |
4629 | curcolum[0].Clear(); | |
4630 | curcolum[0] += names[10+i]; | |
4631 | curcolum[2].Clear(); | |
4632 | curcolum[2]+=TCollection_AsciiString(i); | |
4633 | ||
4634 | for(Standard_Integer j =0;j<=2;j++){ | |
4635 | curcolum[j].Center(20,' '); | |
4636 | di<<"|"<<curcolum[j].ToCString(); | |
4637 | } | |
4638 | di<<"|"<<"\n"; | |
4639 | } | |
4640 | di<<BlankLine.ToCString()<<"\n"; | |
4641 | // les contraintes et dimensions. | |
4642 | // pour l'instant on separe juste contraintes et dimensions... | |
4643 | // plus tard, on detaillera toutes les sortes... | |
4644 | curcolum[1].Clear(); | |
4645 | curcolum[1]+="Relation"; | |
4646 | curcolum[1].Center(20,' '); | |
4647 | for(i=0;i<=1;i++){ | |
4648 | curcolum[0].Clear(); | |
4649 | curcolum[0] += names[12+i]; | |
4650 | curcolum[2].Clear(); | |
4651 | curcolum[2]+=TCollection_AsciiString(i); | |
4652 | ||
4653 | for(Standard_Integer j =0;j<=2;j++){ | |
4654 | curcolum[j].Center(20,' '); | |
4655 | di<<"|"<<curcolum[j].ToCString(); | |
4656 | } | |
4657 | di<<"|"<<"\n"; | |
4658 | } | |
4659 | di<<BlankLine.ToCString()<<"\n"; | |
4660 | ||
4661 | ||
4662 | return 0; | |
4663 | } | |
4664 | ||
4665 | ||
4666 | static int VEraseType( Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
4667 | { | |
4952a30a | 4668 | if(argc!=2) return 1; |
7fd59977 | 4669 | |
4670 | AIS_KindOfInteractive TheType; | |
4671 | Standard_Integer TheSign(-1); | |
4672 | GetTypeAndSignfromString(argv[1],TheType,TheSign); | |
4673 | ||
4674 | ||
4675 | AIS_ListOfInteractive LIO; | |
4676 | ||
4677 | // en attendant l'amelioration ais pour les dimensions... | |
4678 | // | |
4679 | Standard_Integer dimension_status(-1); | |
4680 | if(TheType==AIS_KOI_Relation){ | |
4681 | dimension_status = TheSign ==1 ? 1 : 0; | |
4682 | TheSign=-1; | |
4683 | } | |
4684 | ||
4685 | TheAISContext()->DisplayedObjects(TheType,TheSign,LIO); | |
4686 | Handle(AIS_InteractiveObject) curio; | |
4687 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ | |
4688 | curio = it.Value(); | |
4689 | ||
4690 | if(dimension_status == -1) | |
4691 | TheAISContext()->Erase(curio,Standard_False); | |
4692 | else { | |
4693 | AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension(); | |
4694 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| | |
4695 | (dimension_status==1 && KOD != AIS_KOD_NONE)) | |
4696 | TheAISContext()->Erase(curio,Standard_False); | |
4697 | } | |
4698 | } | |
4699 | TheAISContext()->UpdateCurrentViewer(); | |
4700 | return 0; | |
4701 | } | |
4702 | static int VDisplayType(Draw_Interpretor& , Standard_Integer argc, const char** argv) | |
4703 | { | |
4704 | if(argc!=2) return 1; | |
4705 | ||
4706 | AIS_KindOfInteractive TheType; | |
4707 | Standard_Integer TheSign(-1); | |
4708 | GetTypeAndSignfromString(argv[1],TheType,TheSign); | |
4709 | ||
4710 | // en attendant l'amelioration ais pour les dimensions... | |
4711 | // | |
4712 | Standard_Integer dimension_status(-1); | |
4713 | if(TheType==AIS_KOI_Relation){ | |
4714 | dimension_status = TheSign ==1 ? 1 : 0; | |
4715 | TheSign=-1; | |
4716 | } | |
4717 | ||
4718 | AIS_ListOfInteractive LIO; | |
4719 | TheAISContext()->ObjectsInside(LIO,TheType,TheSign); | |
4720 | Handle(AIS_InteractiveObject) curio; | |
4721 | for(AIS_ListIteratorOfListOfInteractive it(LIO);it.More();it.Next()){ | |
4722 | curio = it.Value(); | |
4723 | if(dimension_status == -1) | |
4724 | TheAISContext()->Display(curio,Standard_False); | |
4725 | else { | |
4726 | AIS_KindOfDimension KOD = (*((Handle(AIS_Relation)*)&curio))->KindOfDimension(); | |
4727 | if ((dimension_status==0 && KOD == AIS_KOD_NONE)|| | |
4728 | (dimension_status==1 && KOD != AIS_KOD_NONE)) | |
4729 | TheAISContext()->Display(curio,Standard_False); | |
4730 | } | |
4731 | ||
4732 | } | |
4733 | ||
4734 | TheAISContext()->UpdateCurrentViewer(); | |
4735 | return 0; | |
4736 | } | |
4737 | ||
4738 | //============================================================================== | |
4739 | //function : VSetTransMode | |
4740 | //purpose : | |
4741 | //Draw arg : vsettransmode shape flag1 [flag2] [flag3] [X Y Z] | |
4742 | //============================================================================== | |
4743 | ||
4744 | static int VSetTransMode ( Draw_Interpretor& di, Standard_Integer argc, const char** argv ) { | |
4745 | // Verification des arguments | |
4746 | if ( a3DView().IsNull() ) { | |
4747 | ViewerTest::ViewerInit(); | |
4748 | di << "La commande vinit n'a pas ete appele avant" << "\n"; | |
4749 | } | |
4750 | ||
4751 | if ( argc < 3 || argc > 8 ) { | |
4752 | di << argv[0] << " Invalid number of arguments" << "\n"; | |
4753 | return 1; | |
4754 | } | |
4755 | ||
4756 | TCollection_AsciiString shapeName; | |
4757 | shapeName = argv[1]; | |
91322f44 | 4758 | Standard_Integer persFlag1 = Draw::Atoi(argv[2]); |
7fd59977 | 4759 | Standard_Integer persFlag2 = 0; |
4760 | Standard_Integer persFlag3 = 0; | |
4761 | gp_Pnt origin = gp_Pnt( 0.0, 0.0, 0.0 ); | |
4762 | if ( argc == 4 || argc == 5 || argc == 7 || argc == 8 ) { | |
91322f44 | 4763 | persFlag2 = Draw::Atoi(argv[3]); |
7fd59977 | 4764 | } |
4765 | if ( argc == 5 || argc == 8 ) { | |
91322f44 | 4766 | persFlag3 = Draw::Atoi(argv[4]); |
7fd59977 | 4767 | } |
4768 | if ( argc >= 6 ) { | |
91322f44 | 4769 | origin.SetX( Draw::Atof(argv[argc - 3]) ); |
4770 | origin.SetY( Draw::Atof(argv[argc - 2]) ); | |
4771 | origin.SetZ( Draw::Atof(argv[argc - 1]) ); | |
7fd59977 | 4772 | } |
4773 | ||
4774 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(shapeName); | |
7fd59977 | 4775 | Handle(Standard_Transient) anObj; |
4776 | if ( IsBound ) { | |
4777 | anObj = GetMapOfAIS().Find2(shapeName); | |
4778 | if ( anObj->IsKind(STANDARD_TYPE(AIS_InteractiveObject)) ) { | |
4779 | Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast(anObj); | |
4780 | aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin ); | |
4781 | if ( persFlag1 == 0 && persFlag2 == 0 && persFlag3 == 0 ) { | |
4782 | di << argv[0] << " All persistence modifiers were removed" << "\n"; | |
4783 | } | |
4784 | } else { | |
4785 | di << argv[0] << " Wrong object type" << "\n"; | |
4786 | return 1; | |
4787 | } | |
4788 | } else { // Create the AIS_Shape from a name | |
4789 | const Handle(AIS_InteractiveObject) aShape = GetAISShapeFromName((const char* )shapeName.ToCString()); | |
4790 | if ( !aShape.IsNull() ) { | |
4791 | GetMapOfAIS().Bind( aShape, shapeName ); | |
4792 | aShape->SetTransformPersistence( (persFlag1 | persFlag2 | persFlag3), origin ); | |
4793 | TheAISContext()->Display( aShape, Standard_False ); | |
4794 | } else { | |
4795 | di << argv[0] << " Object not found" << "\n"; | |
4796 | return 1; | |
4797 | } | |
4798 | } | |
4799 | ||
4800 | // Upadate the screen and redraw the view | |
4801 | TheAISContext()->UpdateCurrentViewer(); | |
4802 | return 0; | |
4803 | } | |
4804 | ||
4805 | static Standard_Integer vr(Draw_Interpretor& , Standard_Integer , const char** a) | |
4806 | { | |
4807 | ifstream s(a[1]); | |
4808 | BRep_Builder builder; | |
4809 | TopoDS_Shape shape; | |
4810 | BRepTools::Read(shape, s, builder); | |
4811 | DBRep::Set(a[1], shape); | |
4812 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
4813 | Handle(AIS_Shape) ais = new AIS_Shape(shape); | |
4814 | Ctx->Display(ais); | |
4815 | return 0; | |
4816 | } | |
7fd59977 | 4817 | |
4818 | //============================================================================== | |
4819 | //function : ViewerTest::Commands | |
4820 | //purpose : Add all the viewer command in the Draw_Interpretor | |
4821 | //============================================================================== | |
4822 | ||
4823 | void ViewerTest::Commands(Draw_Interpretor& theCommands) | |
4824 | { | |
4825 | ViewerTest::ViewerCommands(theCommands); | |
4826 | ViewerTest::RelationCommands(theCommands); | |
4827 | ViewerTest::ObjectCommands(theCommands); | |
4828 | ViewerTest::FilletCommands(theCommands); | |
4829 | ViewerTest::VoxelCommands(theCommands); | |
3946774d | 4830 | ViewerTest::OpenGlCommands(theCommands); |
7fd59977 | 4831 | |
4832 | const char *group = "AIS_Display"; | |
4833 | ||
4834 | // display | |
1c88cbaf | 4835 | theCommands.Add("visos", |
b6d587e3 | 4836 | "visos [name1 ...] [nbUIsos nbVIsos IsoOnPlane(0|1)]\n" |
4837 | "\tIf last 3 optional parameters are not set prints numbers of U-, V- isolines and IsoOnPlane.\n", | |
4838 | __FILE__, visos, group); | |
7fd59977 | 4839 | |
4840 | theCommands.Add("vdisplay", | |
b6d587e3 | 4841 | "vdisplay [-noupdate|-update] [-local] [-mutable] name1 [name2] ... [name n]" |
519d35d8 | 4842 | "\n\t\t: Displays named objects." |
b6d587e3 | 4843 | "\n\t\t: Option -local enables displaying of objects in local" |
4844 | "\n\t\t: selection context. Local selection context will be opened" | |
4845 | "\n\t\t: if there is not any." | |
519d35d8 | 4846 | "\n\t\t: Option -noupdate suppresses viewer redraw call." |
b6d587e3 | 4847 | "\n\t\t: Option -mutable enables optimizations for mutable objects.", |
4848 | __FILE__, VDisplay2, group); | |
7fd59977 | 4849 | |
f3889691 | 4850 | theCommands.Add ("vupdate", |
4851 | "vupdate name1 [name2] ... [name n]" | |
4852 | "\n\t\t: Updates named objects in interactive context", | |
4853 | __FILE__, VUpdate, group); | |
4854 | ||
7fd59977 | 4855 | theCommands.Add("verase", |
b6d587e3 | 4856 | "verase [-noupdate|-update] [-local] [name1] ... [name n]" |
ac4aaa98 | 4857 | "\n\t\t: Erases selected or named objects." |
b6d587e3 | 4858 | "\n\t\t: If there are no selected or named objects the whole viewer is erased." |
4859 | "\n\t\t: Option -local enables erasing of selected or named objects without" | |
4860 | "\n\t\t: closing local selection context.", | |
4861 | __FILE__, VErase, group); | |
7fd59977 | 4862 | |
eef7fc64 | 4863 | theCommands.Add("vremove", |
b6d587e3 | 4864 | "vremove [-noupdate|-update] [-context] [-all] [-noinfo] [name1] ... [name n]" |
4865 | "or vremove [-context] -all to remove all objects" | |
eef7fc64 | 4866 | "\n\t\t: Removes selected or named objects." |
4867 | "\n\t\t If -context is in arguments, the objects are not deleted" | |
519d35d8 | 4868 | "\n\t\t from the map of objects and names." |
b6d587e3 | 4869 | "\n\t\t: Option -local enables removing of selected or named objects without" |
4870 | "\n\t\t: closing local selection context. Empty local selection context will be" | |
4871 | "\n\t\t: closed." | |
b7cd4ba7 | 4872 | "\n\t\t: Option -noupdate suppresses viewer redraw call." |
4873 | "\n\t\t: Option -noinfo suppresses displaying the list of removed objects.", | |
eef7fc64 | 4874 | __FILE__, VRemove, group); |
4875 | ||
7fd59977 | 4876 | theCommands.Add("vdonly", |
519d35d8 | 4877 | "vdonly [-noupdate|-update] [name1] ... [name n]" |
ac4aaa98 | 4878 | "\n\t\t: Displays only selected or named objects", |
7fd59977 | 4879 | __FILE__,VDonly2,group); |
4880 | ||
4881 | theCommands.Add("vdisplayall", | |
b6d587e3 | 4882 | "vidsplayall [-local]" |
4883 | "\n\t\t: Displays all erased interactive objects (see vdir and vstate)." | |
4884 | "\n\t\t: Option -local enables displaying of the objects in local" | |
4885 | "\n\t\t: selection context.", | |
4886 | __FILE__, VDisplayAll, group); | |
7fd59977 | 4887 | |
4888 | theCommands.Add("veraseall", | |
b6d587e3 | 4889 | "veraseall [-local]" |
4890 | "\n\t\t: Erases all objects displayed in the viewer." | |
4891 | "\n\t\t: Option -local enables erasing of the objects in local" | |
4892 | "\n\t\t: selection context.", | |
4893 | __FILE__, VErase, group); | |
7fd59977 | 4894 | |
4895 | theCommands.Add("verasetype", | |
b6d587e3 | 4896 | "verasetype <Type>" |
ac4aaa98 | 4897 | "\n\t\t: Erase all the displayed objects of one given kind (see vtypes)", |
b6d587e3 | 4898 | __FILE__, VEraseType, group); |
c2a388f8 | 4899 | theCommands.Add("vbounding", |
4900 | "vbounding [-noupdate|-update] [-mode] name1 [name2 [...]]" | |
4901 | "\n\t\t: [-print] [-hide]" | |
4902 | "\n\t\t: Temporarily display bounding box of specified Interactive" | |
4903 | "\n\t\t: Objects, or print it to console if -print is specified." | |
4904 | "\n\t\t: Already displayed box might be hidden by -hide option.", | |
4905 | __FILE__,VBounding,group); | |
4906 | ||
7fd59977 | 4907 | theCommands.Add("vdisplaytype", |
4908 | "vdisplaytype : vdisplaytype <Type> <Signature> \n\t display all the objects of one given kind (see vtypes) which are stored the AISContext ", | |
4909 | __FILE__,VDisplayType,group); | |
4910 | ||
4911 | theCommands.Add("vdisplaymode", | |
4912 | "vdispmode : vdispmode [name] mode(1,2,..) : no name -> on selected objects ", | |
4913 | __FILE__,VDispMode,group); | |
4914 | ||
4915 | theCommands.Add("verasemode", | |
4916 | "verasemode : verasemode [name] mode(1,2,..) : no name -> on selected objects", | |
4917 | __FILE__,VDispMode,group); | |
4918 | ||
4919 | theCommands.Add("vsetdispmode", | |
ac4aaa98 | 4920 | "vsetdispmode [name] mode(1,2,..)" |
4921 | "\n\t\t: Sets display mode for all, selected or named objects.", | |
7fd59977 | 4922 | __FILE__,VDispMode,group); |
4923 | ||
4924 | theCommands.Add("vunsetdispmode", | |
ac4aaa98 | 4925 | "vunsetdispmode [name]" |
4926 | "\n\t\t: Unsets custom display mode for selected or named objects.", | |
7fd59977 | 4927 | __FILE__,VDispMode,group); |
4928 | ||
4929 | theCommands.Add("vdir", | |
ac4aaa98 | 4930 | "Lists all objects displayed in 3D viewer", |
519d35d8 | 4931 | __FILE__,VDir,group); |
7fd59977 | 4932 | |
4933 | theCommands.Add("vdump", | |
ac4aaa98 | 4934 | #ifdef HAVE_FREEIMAGE |
34db9c00 | 4935 | "vdump <filename>.{png|bmp|jpg|gif} [rgb|rgba|depth=rgb] [mono|left|right=mono]" |
4936 | "\n\t\t: [width Width=0 height Height=0]" | |
4937 | "\n\t\t: Dumps content of the active view into PNG, BMP, JPEG or GIF file", | |
ac4aaa98 | 4938 | #else |
34db9c00 | 4939 | "vdump <filename>.{ppm} [rgb|rgba|depth=rgb] [mono|left|right=mono]" |
4940 | "\n\t\t: [width Width=0 height Height=0]" | |
4941 | "\n\t\t: Dumps content of the active view into PPM image file", | |
ac4aaa98 | 4942 | #endif |
7fd59977 | 4943 | __FILE__,VDump,group); |
4944 | ||
4945 | theCommands.Add("vsub", "vsub 0/1 (off/on) [obj] : Subintensity(on/off) of selected objects", | |
4946 | __FILE__,VSubInt,group); | |
4947 | ||
ad3217cd | 4948 | theCommands.Add("vaspects", |
6262338c | 4949 | "vaspects [-noupdate|-update] [name1 [name2 [...]] | -defaults]" |
5bffb882 | 4950 | "\n\t\t: [-setvisibility 0|1]" |
8316c618 | 4951 | "\n\t\t: [-setcolor ColorName] [-setcolor R G B] [-unsetcolor]" |
ad3217cd | 4952 | "\n\t\t: [-setmaterial MatName] [-unsetmaterial]" |
0ae61cf3 | 4953 | "\n\t\t: [-settransparency Transp] [-unsettransparency]" |
ad3217cd | 4954 | "\n\t\t: [-setwidth LineWidth] [-unsetwidth]" |
6262338c | 4955 | "\n\t\t: [-freeBoundary {off/on | 0/1}]" |
4956 | "\n\t\t: [-setFreeBoundaryWidth Width] [-unsetFreeBoundaryWidth]" | |
4957 | "\n\t\t: [-setFreeBoundaryColor {ColorName | R G B}] [-unsetFreeBoundaryColor]" | |
ad3217cd | 4958 | "\n\t\t: [-subshapes subname1 [subname2 [...]]]" |
4959 | "\n\t\t: Manage presentation properties of all, selected or named objects." | |
4960 | "\n\t\t: When -subshapes is specified than following properties will be" | |
6262338c | 4961 | "\n\t\t: assigned to specified sub-shapes." |
4962 | "\n\t\t: When -defaults is specified than presentation properties will be" | |
4963 | "\n\t\t: assigned to all objects that have not their own specified properties" | |
4964 | "\n\t\t: and to all objects to be displayed in the future." | |
4965 | "\n\t\t: If -defaults is used there should not be any objects' names and -subshapes specifier.", | |
ad3217cd | 4966 | __FILE__,VAspects,group); |
4967 | ||
7fd59977 | 4968 | theCommands.Add("vsetcolor", |
ad3217cd | 4969 | "vsetcolor [-noupdate|-update] [name] ColorName" |
4970 | "\n\t\t: Sets color for all, selected or named objects." | |
4971 | "\n\t\t: Alias for vaspects -setcolor [name] ColorName.", | |
4972 | __FILE__,VAspects,group); | |
7fd59977 | 4973 | |
4974 | theCommands.Add("vunsetcolor", | |
ad3217cd | 4975 | "vunsetcolor [-noupdate|-update] [name]" |
4976 | "\n\t\t: Resets color for all, selected or named objects." | |
4977 | "\n\t\t: Alias for vaspects -unsetcolor [name].", | |
4978 | __FILE__,VAspects,group); | |
7fd59977 | 4979 | |
4980 | theCommands.Add("vsettransparency", | |
ad3217cd | 4981 | "vsettransparency [-noupdate|-update] [name] Coefficient" |
ac4aaa98 | 4982 | "\n\t\t: Sets transparency for all, selected or named objects." |
ad3217cd | 4983 | "\n\t\t: The Coefficient may be between 0.0 (opaque) and 1.0 (fully transparent)." |
4984 | "\n\t\t: Alias for vaspects -settransp [name] Coefficient.", | |
4985 | __FILE__,VAspects,group); | |
7fd59977 | 4986 | |
4987 | theCommands.Add("vunsettransparency", | |
ad3217cd | 4988 | "vunsettransparency [-noupdate|-update] [name]" |
4989 | "\n\t\t: Resets transparency for all, selected or named objects." | |
4990 | "\n\t\t: Alias for vaspects -unsettransp [name].", | |
4991 | __FILE__,VAspects,group); | |
7fd59977 | 4992 | |
4993 | theCommands.Add("vsetmaterial", | |
ad3217cd | 4994 | "vsetmaterial [-noupdate|-update] [name] MaterialName" |
4995 | "\n\t\t: Alias for vaspects -setmaterial [name] MaterialName.", | |
4996 | __FILE__,VAspects,group); | |
7fd59977 | 4997 | |
4998 | theCommands.Add("vunsetmaterial", | |
ad3217cd | 4999 | "vunsetmaterial [-noupdate|-update] [name]" |
5000 | "\n\t\t: Alias for vaspects -unsetmaterial [name].", | |
5001 | __FILE__,VAspects,group); | |
7fd59977 | 5002 | |
5003 | theCommands.Add("vsetwidth", | |
ad3217cd | 5004 | "vsetwidth [-noupdate|-update] [name] width(0->10)" |
5005 | "\n\t\t: Alias for vaspects -setwidth [name] width.", | |
5006 | __FILE__,VAspects,group); | |
7fd59977 | 5007 | |
5008 | theCommands.Add("vunsetwidth", | |
ad3217cd | 5009 | "vunsetwidth [-noupdate|-update] [name]" |
5010 | "\n\t\t: Alias for vaspects -unsetwidth [name] width.", | |
5011 | __FILE__,VAspects,group); | |
7fd59977 | 5012 | |
99c56d44 | 5013 | theCommands.Add("vsetinteriorstyle", |
ad3217cd | 5014 | "vsetinteriorstyle [-noupdate|-update] [name] style" |
5015 | "\n\t\t: Where style is: 0 = EMPTY, 1 = HOLLOW, 2 = HATCH, 3 = SOLID, 4 = HIDDENLINE.", | |
5016 | __FILE__,VSetInteriorStyle,group); | |
99c56d44 | 5017 | |
7fd59977 | 5018 | theCommands.Add("vardis", |
5019 | "vardis : display activeareas", | |
5020 | __FILE__,VDispAreas,group); | |
5021 | ||
5022 | theCommands.Add("varera", | |
5023 | "varera : erase activeareas", | |
5024 | __FILE__,VClearAreas,group); | |
5025 | ||
5026 | theCommands.Add("vsensdis", | |
5027 | "vardisp : display active entities", | |
5028 | __FILE__,VDispSensi,group); | |
5029 | theCommands.Add("vsensera", | |
5030 | "vardisp : erase active entities", | |
5031 | __FILE__,VClearSensi,group); | |
5032 | ||
3c982548 | 5033 | theCommands.Add("vselprecision", |
5034 | "vselprecision : vselprecision [precision_mode [tolerance_value]]", | |
5035 | __FILE__,VSelPrecision,group); | |
5036 | ||
7fd59977 | 5037 | theCommands.Add("vperf", |
5038 | "vperf: vperf ShapeName 1/0(Transfo/Location) 1/0(Primitives sensibles ON/OFF)", | |
5039 | __FILE__,VPerf,group); | |
5040 | ||
5041 | theCommands.Add("vanimation", | |
5042 | "vanimation CrankArmFile CylinderHeadFile PropellerFile EngineBlockFile", | |
5043 | __FILE__,VAnimation,group); | |
5044 | ||
5045 | theCommands.Add("vsetshading", | |
5046 | "vsetshading : vsetshading name Quality(default=0.0008) ", | |
5047 | __FILE__,VShading,group); | |
5048 | ||
5049 | theCommands.Add("vunsetshading", | |
5050 | "vunsetshading :vunsetshading name ", | |
5051 | __FILE__,VShading,group); | |
5052 | ||
d399d3c3 | 5053 | theCommands.Add ("vtexture", |
5054 | "\n'vtexture NameOfShape [TextureFile | IdOfTexture]\n" | |
5055 | " [-scale u v] [-scale off]\n" | |
5056 | " [-origin u v] [-origin off]\n" | |
5057 | " [-repeat u v] [-repeat off]\n" | |
5058 | " [-modulate {on | off}]" | |
5059 | " [-default]'\n" | |
5060 | " The texture can be specified by filepath or as ID (0<=IdOfTexture<=20)\n" | |
5061 | " specifying one of the predefined textures.\n" | |
5062 | " The options are: \n" | |
5063 | " -scale u v : enable texture scaling and set scale factors\n" | |
5064 | " -scale off : disable texture scaling\n" | |
5065 | " -origin u v : enable texture origin positioning and set the origin\n" | |
5066 | " -origin off : disable texture origin positioning\n" | |
5067 | " -repeat u v : enable texture repeat and set texture coordinate scaling\n" | |
5068 | " -repeat off : disable texture repeat\n" | |
5069 | " -modulate {on | off} : enable or disable texture modulation\n" | |
5070 | " -default : sets texture mapping default parameters\n" | |
5071 | "or 'vtexture NameOfShape' if you want to disable texture mapping\n" | |
5072 | "or 'vtexture NameOfShape ?' to list available textures\n", | |
5073 | __FILE__, VTexture, group); | |
7fd59977 | 5074 | |
5075 | theCommands.Add("vtexscale", | |
5076 | "'vtexscale NameOfShape ScaleU ScaleV' \n \ | |
5077 | or 'vtexscale NameOfShape ScaleUV' \n \ | |
5078 | or 'vtexscale NameOfShape' to disable scaling\n ", | |
5079 | __FILE__,VTexture,group); | |
5080 | ||
5081 | theCommands.Add("vtexorigin", | |
5082 | "'vtexorigin NameOfShape UOrigin VOrigin' \n \ | |
5083 | or 'vtexorigin NameOfShape UVOrigin' \n \ | |
5084 | or 'vtexorigin NameOfShape' to disable origin positioning\n ", | |
5085 | __FILE__,VTexture,group); | |
5086 | ||
5087 | theCommands.Add("vtexrepeat", | |
5088 | "'vtexrepeat NameOfShape URepeat VRepeat' \n \ | |
5089 | or 'vtexrepeat NameOfShape UVRepeat \n \ | |
5090 | or 'vtexrepeat NameOfShape' to disable texture repeat \n ", | |
5091 | VTexture,group); | |
5092 | ||
5093 | theCommands.Add("vtexdefault", | |
5094 | "'vtexdefault NameOfShape' to set texture mapping default parameters \n", | |
5095 | VTexture,group); | |
5096 | ||
5097 | theCommands.Add("vsetam", | |
5098 | "vsetActivatedModes: vsetam mode(1->7) ", | |
5099 | __FILE__,VActivatedMode,group); | |
5100 | ||
5101 | theCommands.Add("vunsetam", | |
5102 | "vunsetActivatedModes: vunsetam ", | |
5103 | __FILE__,VActivatedMode,group); | |
5104 | ||
ac4aaa98 | 5105 | theCommands.Add("vstate", |
51023771 | 5106 | "vstate [-entities] [-hasSelected] [name1] ... [nameN]" |
8e7c8ccf | 5107 | "\n\t\t: Reports show/hidden state for selected or named objects" |
51023771 | 5108 | "\n\t\t: -entities - print low-level information about detected entities" |
5109 | "\n\t\t: -hasSelected - prints 1 if context has selected shape and 0 otherwise", | |
7fd59977 | 5110 | __FILE__,VState,group); |
5111 | ||
5112 | theCommands.Add("vpickshapes", | |
5113 | "vpickshape subtype(VERTEX,EDGE,WIRE,FACE,SHELL,SOLID) [name1 or .] [name2 or .] [name n or .]", | |
5114 | __FILE__,VPickShape,group); | |
5115 | ||
5116 | theCommands.Add("vtypes", | |
5117 | "vtypes : list of known types and signatures in AIS - To be Used in vpickobject command for selection with filters", | |
5118 | VIOTypes,group); | |
5119 | ||
5120 | theCommands.Add("vsettransmode", | |
5121 | "vsettransmode : vsettransmode shape flag1 [flag2] [flag3] [X Y Z]", | |
5122 | __FILE__,VSetTransMode,group); | |
5123 | ||
5124 | theCommands.Add("vr", "vr : reading of the shape", | |
5125 | __FILE__,vr, group); | |
5126 | ||
d8110103 | 5127 | theCommands.Add("vpickselected", "vpickselected [name]: extract selected shape.", |
5128 | __FILE__, VPickSelected, group); | |
5129 | ||
7fd59977 | 5130 | } |
5131 | ||
5132 | //===================================================================== | |
5133 | //========================= for testing Draft and Rib ================= | |
5134 | //===================================================================== | |
5135 | #include <BRepOffsetAPI_MakeThickSolid.hxx> | |
5136 | #include <DBRep.hxx> | |
5137 | #include <TopoDS_Face.hxx> | |
5138 | #include <gp_Pln.hxx> | |
5139 | #include <AIS_KindOfSurface.hxx> | |
5140 | #include <BRepOffsetAPI_DraftAngle.hxx> | |
5141 | #include <Precision.hxx> | |
5142 | #include <BRepAlgo.hxx> | |
5143 | #include <OSD_Environment.hxx> | |
5144 | #include <DrawTrSurf.hxx> | |
5145 | //#include <DbgTools.hxx> | |
5146 | //#include <FeatAlgo_MakeLinearForm.hxx> | |
5147 | ||
5148 | ||
5149 | ||
5150 | ||
5151 | //======================================================================= | |
5152 | //function : IsValid | |
5153 | //purpose : | |
5154 | //======================================================================= | |
5155 | static Standard_Boolean IsValid(const TopTools_ListOfShape& theArgs, | |
5156 | const TopoDS_Shape& theResult, | |
5157 | const Standard_Boolean closedSolid, | |
5158 | const Standard_Boolean GeomCtrl) | |
5159 | { | |
5160 | OSD_Environment check ("DONT_SWITCH_IS_VALID") ; | |
5161 | TCollection_AsciiString checkValid = check.Value(); | |
5162 | Standard_Boolean ToCheck = Standard_True; | |
5163 | if (!checkValid.IsEmpty()) { | |
0797d9d3 | 5164 | #ifdef OCCT_DEBUG |
7fd59977 | 5165 | cout <<"DONT_SWITCH_IS_VALID positionnee a :"<<checkValid.ToCString()<<"\n"; |
5166 | #endif | |
5167 | if ( checkValid=="true" || checkValid=="TRUE" ) { | |
5168 | ToCheck= Standard_False; | |
5169 | } | |
5170 | } else { | |
0797d9d3 | 5171 | #ifdef OCCT_DEBUG |
7fd59977 | 5172 | cout <<"DONT_SWITCH_IS_VALID non positionne"<<"\n"; |
5173 | #endif | |
5174 | } | |
5175 | Standard_Boolean IsValid = Standard_True; | |
5176 | if (ToCheck) | |
5177 | IsValid = BRepAlgo::IsValid(theArgs,theResult,closedSolid,GeomCtrl) ; | |
5178 | return IsValid; | |
5179 | ||
5180 | } | |
5181 | ||
5182 | //=============================================================================== | |
5183 | // TDraft : test draft, uses AIS Viewer | |
5184 | // Solid Face Plane Angle Reverse | |
5185 | //=============================================================================== | |
5186 | static Standard_Integer TDraft(Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
5187 | { | |
5188 | if (argc < 5) return 1; | |
5189 | // argv[1] - TopoDS_Shape Solid | |
5190 | // argv[2] - TopoDS_Shape Face | |
5191 | // argv[3] - TopoDS_Shape Plane | |
5192 | // argv[4] - Standard_Real Angle | |
5193 | // argv[5] - Standard_Integer Reverse | |
5194 | ||
91322f44 | 5195 | // Sprintf(prefix, argv[1]); |
7fd59977 | 5196 | Standard_Real anAngle = 0; |
5197 | Standard_Boolean Rev = Standard_False; | |
5198 | Standard_Integer rev = 0; | |
5199 | TopoDS_Shape Solid = GetShapeFromName(argv[1]); | |
5200 | TopoDS_Shape face = GetShapeFromName(argv[2]); | |
5201 | TopoDS_Face Face = TopoDS::Face(face); | |
5202 | TopoDS_Shape Plane = GetShapeFromName(argv[3]); | |
5203 | if (Plane.IsNull ()) { | |
5204 | di << "TEST : Plane is NULL" << "\n"; | |
5205 | return 1; | |
5206 | } | |
91322f44 | 5207 | anAngle = Draw::Atof(argv[4]); |
c6541a0c | 5208 | anAngle = 2*M_PI * anAngle / 360.0; |
7fd59977 | 5209 | gp_Pln aPln; |
5210 | Handle( Geom_Surface )aSurf; | |
5211 | AIS_KindOfSurface aSurfType; | |
5212 | Standard_Real Offset; | |
5213 | gp_Dir aDir; | |
5214 | if(argc > 4) { // == 5 | |
91322f44 | 5215 | rev = Draw::Atoi(argv[5]); |
7fd59977 | 5216 | Rev = (rev)? Standard_True : Standard_False; |
5217 | } | |
5218 | ||
5219 | TopoDS_Face face2 = TopoDS::Face(Plane); | |
5220 | if(!AIS::GetPlaneFromFace(face2, aPln, aSurf, aSurfType, Offset)) | |
5221 | { | |
5222 | di << "TEST : Can't find plane" << "\n"; | |
5223 | return 1; | |
5224 | } | |
5225 | ||
5226 | aDir = aPln.Axis().Direction(); | |
5227 | if (!aPln.Direct()) | |
5228 | aDir.Reverse(); | |
5229 | if (Plane.Orientation() == TopAbs_REVERSED) | |
5230 | aDir.Reverse(); | |
5231 | di << "TEST : gp::Resolution() = " << gp::Resolution() << "\n"; | |
5232 | ||
5233 | BRepOffsetAPI_DraftAngle Draft (Solid); | |
5234 | ||
5235 | if(Abs(anAngle)< Precision::Angular()) { | |
5236 | di << "TEST : NULL angle" << "\n"; | |
5237 | return 1;} | |
5238 | ||
5239 | if(Rev) anAngle = - anAngle; | |
5240 | Draft.Add (Face, aDir, anAngle, aPln); | |
5241 | Draft.Build (); | |
5242 | if (!Draft.IsDone()) { | |
5243 | di << "TEST : Draft Not DONE " << "\n"; | |
5244 | return 1; | |
5245 | } | |
5246 | TopTools_ListOfShape Larg; | |
5247 | Larg.Append(Solid); | |
5248 | if (!IsValid(Larg,Draft.Shape(),Standard_True,Standard_False)) { | |
5249 | di << "TEST : DesignAlgo returns Not valid" << "\n"; | |
5250 | return 1; | |
5251 | } | |
5252 | ||
5253 | Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext(); | |
5254 | Handle(AIS_Shape) ais = new AIS_Shape(Draft.Shape()); | |
5255 | ||
5256 | if ( !ais.IsNull() ) { | |
5257 | ais->SetColor(DEFAULT_COLOR); | |
5258 | ais->SetMaterial(DEFAULT_MATERIAL); | |
5259 | // Display the AIS_Shape without redraw | |
5260 | Ctx->Display(ais, Standard_False); | |
5261 | ||
5262 | const char *Name = "draft1"; | |
5263 | Standard_Boolean IsBound = GetMapOfAIS().IsBound2(Name); | |
5264 | if (IsBound) { | |
5265 | Handle(AIS_InteractiveObject) an_object = | |
5266 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(Name)); | |
5267 | if (!an_object.IsNull()) { | |
5268 | Ctx->Remove(an_object, | |
5269 | Standard_True) ; | |
5270 | GetMapOfAIS().UnBind2(Name) ; | |
5271 | } | |
5272 | } | |
5273 | GetMapOfAIS().Bind(ais, Name); | |
5274 | // DBRep::Set("draft", ais->Shape()); | |
5275 | } | |
5276 | Ctx->Display(ais, Standard_True); | |
5277 | return 0; | |
5278 | } | |
5279 | ||
1d7ca641 | 5280 | //============================================================================== |
5281 | //function : splitParameter | |
197ac94e | 5282 | //purpose : Split parameter string to parameter name and parameter value |
1d7ca641 | 5283 | //============================================================================== |
5284 | Standard_Boolean ViewerTest::SplitParameter (const TCollection_AsciiString& theString, | |
5285 | TCollection_AsciiString& theName, | |
5286 | TCollection_AsciiString& theValue) | |
5287 | { | |
5288 | Standard_Integer aParamNameEnd = theString.FirstLocationInSet ("=", 1, theString.Length()); | |
5289 | ||
5290 | if (aParamNameEnd == 0) | |
5291 | { | |
5292 | return Standard_False; | |
5293 | } | |
5294 | ||
5295 | TCollection_AsciiString aString (theString); | |
5296 | if (aParamNameEnd != 0) | |
5297 | { | |
5298 | theValue = aString.Split (aParamNameEnd); | |
5299 | aString.Split (aString.Length() - 1); | |
5300 | theName = aString; | |
5301 | } | |
7fd59977 | 5302 | |
1d7ca641 | 5303 | return Standard_True; |
5304 | } | |
7fd59977 | 5305 | |
5306 | //============================================================================ | |
5307 | // MyCommands | |
5308 | //============================================================================ | |
5309 | void ViewerTest::MyCommands( Draw_Interpretor& theCommands) | |
5310 | { | |
5311 | ||
5312 | DrawTrSurf::BasicCommands(theCommands); | |
5313 | const char* group = "Check Features Operations commands"; | |
5314 | ||
5315 | theCommands.Add("Draft","Draft Solid Face Plane Angle Reverse", | |
5316 | __FILE__, | |
5317 | &TDraft,group); //Draft_Modification | |
5318 | } | |
5319 | ||
5320 | //============================================================================== | |
5321 | // ViewerTest::Factory | |
5322 | //============================================================================== | |
5323 | void ViewerTest::Factory(Draw_Interpretor& theDI) | |
5324 | { | |
5325 | // definition of Viewer Command | |
128cc8df | 5326 | ViewerTest::Commands(theDI); |
5327 | ViewerTest::AviCommands(theDI); | |
5328 | ||
0797d9d3 | 5329 | #ifdef OCCT_DEBUG |
7fd59977 | 5330 | theDI << "Draw Plugin : OCC V2d & V3d commands are loaded" << "\n"; |
5331 | #endif | |
5332 | } | |
5333 | ||
5334 | // Declare entry point PLUGINFACTORY | |
5335 | DPLUGIN(ViewerTest) |