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