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