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