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