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