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