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