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