Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1998-11-12 |
2 | // Created by: Robert COUBLANC | |
3 | // Copyright (c) 1998-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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
b311480e | 16 | |
7fd59977 | 17 | #include <ViewerTest.hxx> |
18 | ||
7fd59977 | 19 | #include <Quantity_NameOfColor.hxx> |
20 | #include <Draw_Interpretor.hxx> | |
21 | #include <Draw.hxx> | |
22 | #include <Draw_Appli.hxx> | |
23 | #include <DBRep.hxx> | |
24 | ||
b514beda | 25 | #include <Font_BRepFont.hxx> |
725ef85e | 26 | #include <Font_FontMgr.hxx> |
161c4476 | 27 | #include <OSD_Chronometer.hxx> |
7fd59977 | 28 | #include <TCollection_AsciiString.hxx> |
4952a30a | 29 | #include <Visual3d_View.hxx> |
7fd59977 | 30 | #include <V3d_Viewer.hxx> |
31 | #include <V3d_View.hxx> | |
32 | #include <V3d.hxx> | |
33 | ||
34 | #include <AIS_Shape.hxx> | |
35 | #include <AIS_DisplayMode.hxx> | |
d33222c1 | 36 | #include <AIS_PointCloud.hxx> |
7fd59977 | 37 | #include <TColStd_MapOfInteger.hxx> |
38 | #include <AIS_MapOfInteractive.hxx> | |
4e18052b | 39 | #include <ViewerTest_AutoUpdater.hxx> |
7fd59977 | 40 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> |
41 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
42 | #include <ViewerTest_EventManager.hxx> | |
43 | ||
44 | #include <TopoDS_Solid.hxx> | |
45 | #include <BRepTools.hxx> | |
46 | #include <BRep_Builder.hxx> | |
47 | #include <TopAbs_ShapeEnum.hxx> | |
48 | ||
49 | #include <TopoDS.hxx> | |
50 | #include <BRep_Tool.hxx> | |
51 | #include <TopExp_Explorer.hxx> | |
52 | ||
53 | #include <BRepAdaptor_Curve.hxx> | |
54 | #include <BRepAdaptor_Surface.hxx> | |
55 | ||
56 | #include <TopAbs.hxx> | |
57 | #include <TopExp.hxx> | |
58 | #include <TopoDS_Vertex.hxx> | |
59 | #include <TopoDS_Shape.hxx> | |
60 | #include <TopoDS_Face.hxx> | |
61 | ||
62 | #include <Draw_Window.hxx> | |
63 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
64 | #include <AIS_ListOfInteractive.hxx> | |
65 | #include <AIS_DisplayMode.hxx> | |
66 | #include <AIS_Shape.hxx> | |
67 | ||
68 | #include <AIS_InteractiveContext.hxx> | |
69 | #include <Geom_Plane.hxx> | |
70 | #include <gp_Pln.hxx> | |
7fd59977 | 71 | #include <TCollection_ExtendedString.hxx> |
725ef85e | 72 | #include <TCollection_HAsciiString.hxx> |
7fd59977 | 73 | #include <GC_MakePlane.hxx> |
74 | #include <gp_Circ.hxx> | |
75 | #include <AIS_Axis.hxx> | |
76 | #include <Geom_Axis2Placement.hxx> | |
77 | #include <Geom_Axis1Placement.hxx> | |
78 | #include <AIS_Trihedron.hxx> | |
79 | #include <AIS_Axis.hxx> | |
29d43f9c A |
80 | #include <gp_Trsf.hxx> |
81 | #include <TopLoc_Location.hxx> | |
3fc57801 | 82 | |
83 | #include <HLRAlgo_Projector.hxx> | |
84 | #include <HLRBRep_PolyAlgo.hxx> | |
85 | #include <HLRBRep_PolyHLRToShape.hxx> | |
86 | #include <Aspect_Window.hxx> | |
87 | ||
9558a876 A |
88 | #include <Graphic3d_ArrayOfPoints.hxx> |
89 | #include <Graphic3d_ArrayOfSegments.hxx> | |
90 | #include <Graphic3d_ArrayOfPolylines.hxx> | |
91 | #include <Graphic3d_ArrayOfTriangles.hxx> | |
92 | #include <Graphic3d_ArrayOfTriangleFans.hxx> | |
93 | #include <Graphic3d_ArrayOfTriangleStrips.hxx> | |
94 | #include <Graphic3d_ArrayOfQuadrangles.hxx> | |
95 | #include <Graphic3d_ArrayOfQuadrangleStrips.hxx> | |
96 | #include <Graphic3d_ArrayOfPolygons.hxx> | |
a577aaab | 97 | #include <Graphic3d_AspectMarker3d.hxx> |
9558a876 A |
98 | #include <Graphic3d_Group.hxx> |
99 | #include <Standard_Real.hxx> | |
100 | ||
329843e2 A |
101 | #include <AIS_Circle.hxx> |
102 | #include <AIS_Drawer.hxx> | |
103 | #include <BRepBuilderAPI_MakeEdge.hxx> | |
104 | #include <BRepBuilderAPI_MakeFace.hxx> | |
105 | #include <BRepBuilderAPI_MakeWire.hxx> | |
106 | #include <Geom_Circle.hxx> | |
107 | #include <GC_MakeCircle.hxx> | |
108 | #include <Prs3d_Presentation.hxx> | |
109 | #include <Select3D_SensitiveCircle.hxx> | |
110 | #include <SelectMgr_EntityOwner.hxx> | |
111 | #include <SelectMgr_Selection.hxx> | |
112 | #include <StdFail_NotDone.hxx> | |
113 | #include <StdPrs_ShadedShape.hxx> | |
a2d5ab2e | 114 | #include <TopoDS_Wire.hxx> |
ac04d101 | 115 | |
792c785c | 116 | #include <AIS_MultipleConnectedInteractive.hxx> |
0717ddc1 | 117 | #include <AIS_ConnectedInteractive.hxx> |
ac04d101 SA |
118 | #include <TopLoc_Location.hxx> |
119 | #include <TColStd_ListOfInteger.hxx> | |
120 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
329843e2 | 121 | |
ceae62f0 A |
122 | #include <Select3D_SensitiveTriangle.hxx> |
123 | #include <Select3D_SensitiveCurve.hxx> | |
a577aaab | 124 | #include <Select3D_SensitivePoint.hxx> |
ceae62f0 A |
125 | #include <BRepAdaptor_Curve.hxx> |
126 | #include <StdPrs_Curve.hxx> | |
127 | ||
128 | #include <BRepExtrema_ExtPC.hxx> | |
129 | #include <BRepExtrema_ExtPF.hxx> | |
130 | ||
53b15292 | 131 | #include <Prs3d_VertexDrawMode.hxx> |
a2d5ab2e | 132 | #include <Prs3d_LineAspect.hxx> |
a577aaab | 133 | #include <Prs3d_PointAspect.hxx> |
134 | ||
135 | #include <Image_AlienPixMap.hxx> | |
eb4320f2 | 136 | #include <TColStd_HArray1OfAsciiString.hxx> |
a2d5ab2e | 137 | |
03155c18 | 138 | #ifdef _WIN32 |
139 | # define _CRT_SECURE_NO_DEPRECATE | |
140 | # pragma warning (disable:4996) | |
7fd59977 | 141 | #endif |
142 | ||
143 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); | |
9558a876 A |
144 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
145 | const Handle(AIS_InteractiveObject)& theAISObj, | |
146 | Standard_Boolean theReplaceIfExists = Standard_True); | |
1d0a9d4d | 147 | extern int ViewerMainLoop(Standard_Integer argc, const char** argv); |
7fd59977 | 148 | extern Handle(AIS_InteractiveContext)& TheAISContext(); |
149 | ||
150 | ||
151 | //============================================================================== | |
152 | //function : Vtrihedron 2d | |
153 | //purpose : Create a plane with a 2D trihedron from a faceselection | |
161c4476 | 154 | //Draw arg : vtri2d name |
7fd59977 | 155 | //============================================================================== |
156 | #include <AIS_PlaneTrihedron.hxx> | |
157 | ||
158 | ||
159 | ||
160 | static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
161 | ||
162 | { | |
163 | // Verification des arguments | |
164 | if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;} | |
165 | ||
166 | // Declarations | |
167 | Standard_Integer myCurrentIndex; | |
161c4476 | 168 | // Fermeture des contextes |
7fd59977 | 169 | TheAISContext()->CloseAllContexts(); |
170 | // Ouverture d'un contexte local et recuperation de son index. | |
171 | TheAISContext()->OpenLocalContext(); | |
172 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
173 | // On active les modes de selections faces. | |
174 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
175 | di<<" Select a face ."<<"\n"; | |
176 | ||
177 | // Boucle d'attente waitpick. | |
178 | Standard_Integer argccc = 5; | |
179 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
180 | const char **argvvv = (const char **) bufff; | |
181 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
182 | // fin de la boucle | |
183 | ||
184 | TopoDS_Shape ShapeB; | |
185 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
186 | ShapeB = TheAISContext()->SelectedShape(); | |
187 | } | |
188 | ||
189 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); | |
190 | ||
191 | // Construction du Plane | |
192 | // recuperation des edges des faces. | |
193 | TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE); | |
194 | ||
195 | TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() ); | |
161c4476 | 196 | // declarations |
7fd59977 | 197 | gp_Pnt A,B,C; |
198 | ||
199 | // si il y a plusieurs edges | |
200 | if (FaceExpB.More() ) { | |
201 | FaceExpB.Next(); | |
202 | TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() ); | |
203 | BRepAdaptor_Curve theCurveB(EdgeB); | |
204 | BRepAdaptor_Curve theCurveC(EdgeC); | |
205 | A=theCurveC.Value(0.1); | |
206 | B=theCurveC.Value(0.9); | |
207 | C=theCurveB.Value(0.5); | |
208 | } | |
209 | else { | |
210 | // FaceB a 1 unique edge courbe | |
211 | BRepAdaptor_Curve theCurveB(EdgeB); | |
212 | A=theCurveB.Value(0.1); | |
213 | B=theCurveB.Value(0.9); | |
214 | C=theCurveB.Value(0.5); | |
215 | } | |
216 | // Construction du Geom_Plane | |
217 | GC_MakePlane MkPlane(A,B,C); | |
218 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
219 | ||
220 | // Construction de l'AIS_PlaneTrihedron | |
221 | Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane ); | |
222 | ||
223 | // Fermeture du contexte local. | |
224 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
225 | ||
226 | // on le display & bind | |
227 | TheAISContext()->Display(theAISPlaneTri ); | |
228 | GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]); | |
229 | ||
161c4476 | 230 | return 0; |
7fd59977 | 231 | } |
232 | ||
233 | ||
234 | ||
235 | //============================================================================== | |
236 | //function : VTriherdron | |
7fd59977 | 237 | //purpose : Create a trihedron. If no arguments are set, the default |
238 | // trihedron (Oxyz) is created. | |
239 | //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] | |
240 | //============================================================================== | |
241 | ||
dc9b6d23 | 242 | static int VTrihedron (Draw_Interpretor& theDi, |
243 | Standard_Integer theArgsNb, | |
244 | const char** theArgVec) | |
7fd59977 | 245 | { |
dc9b6d23 | 246 | if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11) |
247 | { | |
248 | theDi << theArgVec[0] << " Syntax error\n"; | |
249 | return 1; | |
7fd59977 | 250 | } |
7fd59977 | 251 | |
dc9b6d23 | 252 | gp_Pnt anOrigin (0.0, 0.0, 0.0); |
253 | gp_Dir aDirZ = gp::DZ(); | |
254 | gp_Dir aDirX = gp::DX(); | |
255 | Standard_Integer anArgIter = 2; // 1st is an IO name | |
256 | if (anArgIter < theArgsNb) | |
257 | { | |
91322f44 | 258 | anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++])); |
259 | anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++])); | |
260 | anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++])); | |
dc9b6d23 | 261 | if (anArgIter < theArgsNb) |
262 | { | |
91322f44 | 263 | Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]); |
264 | Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]); | |
265 | Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]); | |
dc9b6d23 | 266 | aDirZ.SetCoord (aX, aY, aZ); |
267 | ||
91322f44 | 268 | aX = Draw::Atof (theArgVec[anArgIter++]); |
269 | aY = Draw::Atof (theArgVec[anArgIter++]); | |
270 | aZ = Draw::Atof (theArgVec[anArgIter++]); | |
dc9b6d23 | 271 | aDirX.SetCoord (aX, aY, aZ); |
272 | } | |
273 | } | |
7fd59977 | 274 | |
dc9b6d23 | 275 | if (!aDirZ.IsNormal (aDirX, M_PI / 180.0)) |
276 | { | |
277 | theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n"; | |
278 | return 1; | |
279 | } | |
7fd59977 | 280 | |
dc9b6d23 | 281 | Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX); |
282 | Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement); | |
283 | VDisplayAISObject (theArgVec[1], aShape); | |
161c4476 | 284 | return 0; |
7fd59977 | 285 | } |
286 | ||
7fd59977 | 287 | //============================================================================== |
288 | //function : VSize | |
289 | //author : ege | |
290 | //purpose : Change the size of a named or selected trihedron | |
291 | // if no name : it affects the trihedrons witch are selected otherwise nothing is donne | |
292 | // if no value, the value is set at 100 by default | |
293 | //Draw arg : vsize [name] [size] | |
294 | //============================================================================== | |
295 | ||
296 | static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
297 | ||
298 | { | |
299 | // Declaration de booleens | |
300 | Standard_Boolean ThereIsName; | |
301 | Standard_Boolean ThereIsCurrent; | |
302 | Standard_Real value; | |
161c4476 | 303 | Standard_Boolean hascol; |
1d47d8d0 | 304 | |
7fd59977 | 305 | Quantity_NameOfColor col = Quantity_NOC_BLACK ; |
7fd59977 | 306 | |
307 | // Verification des arguments | |
308 | if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
309 | ||
310 | // Verification du nombre d'arguments | |
311 | if (argc==1) {ThereIsName=Standard_False;value=100;} | |
91322f44 | 312 | else if (argc==2) {ThereIsName=Standard_False;value=Draw::Atof(argv[1]);} |
313 | else {ThereIsName=Standard_True;value=Draw::Atof(argv[2]);} | |
7fd59977 | 314 | |
315 | // On ferme le contexte local pour travailler dans le contexte global | |
161c4476 | 316 | if(TheAISContext()->HasOpenedContext()) |
7fd59977 | 317 | TheAISContext()->CloseLocalContext(); |
318 | ||
319 | // On set le booleen ThereIsCurrent | |
320 | if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;} | |
321 | else {ThereIsCurrent=Standard_False;} | |
322 | ||
323 | ||
324 | ||
325 | //=============================================================== | |
326 | // Il n'y a pas de nom mais des objets selectionnes | |
327 | //=============================================================== | |
161c4476 | 328 | if (!ThereIsName && ThereIsCurrent) |
7fd59977 | 329 | { |
330 | ||
331 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
332 | it (GetMapOfAIS()); | |
333 | ||
334 | while ( it.More() ) { | |
335 | ||
336 | Handle(AIS_InteractiveObject) aShape= | |
337 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
338 | ||
339 | if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) ) | |
340 | { | |
341 | ||
161c4476 | 342 | // On verifie que l'AIS InteraciveObject selectionne est bien |
7fd59977 | 343 | // un AIS_Trihedron |
344 | if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) { | |
345 | ||
346 | if (aShape->HasColor()) { | |
347 | hascol=Standard_True; | |
348 | ||
349 | // On recupere la couleur de aShape | |
350 | col=aShape->Color();} | |
351 | ||
352 | else hascol=Standard_False; | |
353 | ||
354 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
355 | // pour lui appliquer la methode SetSize() | |
356 | Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape; | |
357 | ||
358 | // C'est bien un triedre,on chage sa valeur! | |
359 | aTrihedron->SetSize(value); | |
360 | ||
361 | // On donne la couleur au Trihedron | |
362 | if(hascol) aTrihedron->SetColor(col); | |
363 | else aTrihedron->UnsetColor(); | |
364 | ||
365 | ||
366 | // The trihedron hasn't be errased from the map | |
367 | // so you just have to redisplay it | |
368 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
369 | ||
370 | } | |
371 | ||
372 | } | |
373 | ||
374 | it.Next(); | |
375 | } | |
376 | ||
377 | TheAISContext() ->UpdateCurrentViewer(); | |
378 | } | |
379 | ||
380 | //=============================================================== | |
381 | // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire! | |
382 | //=============================================================== | |
383 | ||
384 | ||
385 | ||
386 | //=============================================================== | |
387 | // Il y a un nom de triedre passe en argument | |
388 | //=============================================================== | |
389 | if (ThereIsName) { | |
390 | TCollection_AsciiString name=argv[1]; | |
391 | ||
392 | // on verifie que ce nom correspond bien a une shape | |
393 | Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name); | |
394 | ||
395 | if (IsBound) { | |
396 | ||
397 | // on recupere la shape dans la map des objets displayes | |
398 | Handle(AIS_InteractiveObject) aShape = | |
399 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
400 | ||
161c4476 | 401 | // On verifie que l'AIS InteraciveObject est bien |
7fd59977 | 402 | // un AIS_Trihedron |
403 | if (!aShape.IsNull() && | |
404 | aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) | |
405 | { | |
406 | ||
407 | if (aShape->HasColor()) { | |
408 | hascol=Standard_True; | |
409 | ||
410 | // On recupere la couleur de aShape | |
411 | col=aShape->Color();} | |
412 | ||
413 | else hascol=Standard_False; | |
414 | ||
415 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
416 | // pour lui appliquer la methode SetSize() | |
417 | Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape; | |
418 | ||
419 | // C'est bien un triedre,on chage sa valeur | |
420 | aTrihedron->SetSize(value); | |
421 | ||
422 | // On donne la couleur au Trihedron | |
423 | if(hascol) aTrihedron->SetColor(col); | |
424 | else aTrihedron->UnsetColor(); | |
425 | ||
426 | // The trihedron hasn't be errased from the map | |
427 | // so you just have to redisplay it | |
428 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
429 | ||
430 | TheAISContext() ->UpdateCurrentViewer(); | |
431 | } | |
432 | } | |
433 | } | |
161c4476 | 434 | return 0; |
7fd59977 | 435 | } |
436 | ||
437 | ||
438 | //============================================================================== | |
439 | ||
440 | //============================================================================== | |
441 | //function : VPlaneTrihedron | |
442 | //purpose : Create a plane from a trihedron selection. If no arguments are set, the default | |
161c4476 | 443 | //Draw arg : vplanetri name |
7fd59977 | 444 | //============================================================================== |
445 | #include <AIS_Plane.hxx> | |
446 | ||
447 | ||
448 | ||
449 | static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
450 | ||
451 | { | |
452 | // Verification des arguments | |
453 | if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;} | |
454 | ||
455 | // Declarations | |
456 | Standard_Integer myCurrentIndex; | |
457 | // Fermeture des contextes locaux | |
458 | TheAISContext()->CloseAllContexts(); | |
459 | ||
161c4476 | 460 | // On recupere tous les trihedrons de la GetMapOfAIS() |
7fd59977 | 461 | // et on active le mode de selection par face. |
462 | // ================================================= | |
463 | ||
464 | // Ouverture d'un contexte local et recuperation de son index. | |
465 | TheAISContext()->OpenLocalContext(Standard_False); | |
466 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
467 | ||
468 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
469 | it (GetMapOfAIS()); | |
470 | while(it.More()){ | |
471 | Handle(AIS_InteractiveObject) ShapeA = | |
472 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
473 | // On verifie que c'est bien un trihedron | |
474 | if (!ShapeA.IsNull() && | |
475 | ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) { | |
476 | // on le downcast | |
477 | Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA)); | |
478 | // on le charge dans le contexte et on active le mode Plane. | |
479 | TheAISContext()->Load(TrihedronA,0,Standard_False); | |
480 | TheAISContext()->Activate(TrihedronA,3); | |
481 | } | |
482 | it.Next(); | |
483 | } | |
484 | ||
485 | di<<" Select a plane."<<"\n"; | |
486 | // Boucle d'attente waitpick. | |
487 | Standard_Integer argccc = 5; | |
488 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
489 | const char **argvvv = (const char **) bufff; | |
490 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
491 | // fin de la boucle | |
492 | ||
493 | Handle(AIS_InteractiveObject) theIOB; | |
494 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
495 | theIOB = TheAISContext()->Interactive(); | |
496 | } | |
497 | // on le downcast | |
498 | Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB)); | |
499 | ||
500 | // Fermeture du contexte local. | |
501 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
502 | ||
503 | // on le display & bind | |
504 | TheAISContext()->Display(PlaneB ); | |
505 | GetMapOfAIS().Bind ( PlaneB ,argv[1]); | |
506 | ||
161c4476 | 507 | return 0; |
7fd59977 | 508 | } |
509 | ||
510 | ||
511 | ||
512 | //============================================================================== | |
513 | // Fonction First click 2de click | |
161c4476 | 514 | // |
7fd59977 | 515 | // vaxis vertex vertex |
516 | // edge None | |
517 | // vaxispara edge vertex | |
518 | // vaxisortho edge Vertex | |
519 | // vaxisinter Face Face | |
520 | //============================================================================== | |
521 | ||
522 | //============================================================================== | |
523 | //function : VAxisBuilder | |
161c4476 | 524 | //purpose : |
7fd59977 | 525 | //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb |
526 | //============================================================================== | |
527 | #include <TopoDS_Edge.hxx> | |
528 | #include <TopoDS_Vertex.hxx> | |
529 | #include <TopExp.hxx> | |
530 | #include <Geom_Line.hxx> | |
531 | ||
161c4476 | 532 | static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 533 | { |
534 | // Declarations | |
535 | Standard_Boolean HasArg; | |
536 | TCollection_AsciiString name; | |
537 | Standard_Integer MyCurrentIndex; | |
538 | ||
539 | // Verification | |
540 | if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
541 | if (argc==8) HasArg=Standard_True; | |
542 | else HasArg=Standard_False; | |
543 | ||
544 | name=argv[1]; | |
545 | // Fermeture des contextes | |
546 | TheAISContext()->CloseAllContexts(); | |
547 | ||
548 | // Cas ou il y a des arguments | |
549 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom) | |
550 | if (HasArg) { | |
551 | Standard_Real coord[6]; | |
552 | for(Standard_Integer i=0;i<=5;i++){ | |
91322f44 | 553 | coord[i]=Draw::Atof(argv[2+i]); |
7fd59977 | 554 | } |
555 | gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ; | |
556 | ||
557 | gp_Vec myVect (p1,p2); | |
558 | Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect ); | |
559 | Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine ); | |
560 | GetMapOfAIS().Bind (TheAxis,name); | |
561 | TheAISContext()->Display(TheAxis); | |
562 | } | |
563 | ||
564 | // Pas d'arguments | |
565 | else { | |
566 | // fonction vaxis | |
567 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom) | |
568 | if ( !strcasecmp(argv[0], "vaxis")) { | |
569 | TheAISContext()->OpenLocalContext(); | |
570 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
571 | ||
572 | // Active le mode edge et le mode vertex | |
573 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
574 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); | |
575 | di<<" Select an edge or a vertex."<<"\n"; | |
576 | ||
577 | // Boucle d'attente waitpick. | |
578 | Standard_Integer argcc = 5; | |
579 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
580 | const char **argvv = (const char **) buff; | |
581 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 582 | // fin de la boucle |
7fd59977 | 583 | |
584 | // recuperation de la shape. | |
585 | TopoDS_Shape ShapeA; | |
586 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
587 | ShapeA = TheAISContext()->SelectedShape(); | |
588 | } | |
589 | // recuperation de l'AIS_InteractiveObject | |
590 | //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current(); | |
591 | // down cast en AIS_Point si sig et type | |
592 | // AIS_Point -> Geom_Pnt .... | |
593 | ||
594 | if (ShapeA.ShapeType()==TopAbs_VERTEX) { | |
595 | // on desactive le mode edge | |
596 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
597 | di<<" Select a different vertex."<<"\n"; | |
598 | ||
599 | TopoDS_Shape ShapeB; | |
600 | do { | |
601 | // Boucle d'attente waitpick. | |
602 | Standard_Integer argccc = 5; | |
603 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
604 | const char **argvvv = (const char **) bufff; | |
605 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 606 | // fin de la boucle |
7fd59977 | 607 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
608 | ShapeB = TheAISContext()->SelectedShape(); | |
609 | } | |
610 | ||
611 | ||
612 | } while(ShapeB.IsSame(ShapeA) ); | |
613 | ||
614 | // Fermeture du context local | |
615 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
616 | ||
161c4476 | 617 | // Construction de l'axe |
7fd59977 | 618 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); |
619 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
620 | gp_Vec V (A,B); | |
621 | gp_Dir D (V); | |
622 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
623 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
624 | GetMapOfAIS().Bind (TheAxis,name); | |
625 | TheAISContext()->Display(TheAxis); | |
161c4476 | 626 | } |
7fd59977 | 627 | else { |
628 | // Un unique edge (ShapeA) a ete picke | |
629 | // Fermeture du context local | |
630 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
161c4476 | 631 | // Constuction de l'axe |
7fd59977 | 632 | TopoDS_Edge ed =TopoDS::Edge(ShapeA); |
633 | TopoDS_Vertex Va,Vb; | |
634 | TopExp::Vertices(ed,Va,Vb ); | |
635 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
636 | gp_Pnt B=BRep_Tool::Pnt(Vb); | |
637 | gp_Vec V (A,B); | |
638 | gp_Dir D (V); | |
639 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
640 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
641 | GetMapOfAIS().Bind (TheAxis,name); | |
642 | TheAISContext()->Display(TheAxis); | |
643 | } | |
644 | ||
645 | } | |
646 | ||
647 | // Fonction axispara | |
648 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS) | |
649 | else if ( !strcasecmp(argv[0], "vaxispara")) { | |
650 | ||
651 | TheAISContext()->OpenLocalContext(); | |
652 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
653 | ||
161c4476 | 654 | // Active le mode edge |
7fd59977 | 655 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); |
656 | di<<" Select an edge."<<"\n"; | |
657 | ||
658 | // Boucle d'attente waitpick. | |
659 | Standard_Integer argcc = 5; | |
660 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
661 | const char **argvv = (const char **) buff; | |
662 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 663 | // fin de la boucle |
7fd59977 | 664 | |
665 | TopoDS_Shape ShapeA; | |
666 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
667 | ShapeA = TheAISContext()->SelectedShape(); | |
668 | } | |
669 | // Active le mode vertex et deactive edges | |
670 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
671 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
672 | di<<" Select a vertex."<<"\n"; | |
673 | ||
674 | // Boucle d'attente waitpick. | |
675 | Standard_Integer argccc = 5; | |
676 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
677 | const char **argvvv = (const char **) bufff; | |
678 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 679 | // fin de la boucle |
7fd59977 | 680 | |
681 | // On peut choisir un pnt sur l'edge | |
682 | TopoDS_Shape ShapeB; | |
683 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
684 | ShapeB = TheAISContext()->SelectedShape(); | |
685 | } | |
686 | // Fermeture du context local | |
687 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
688 | ||
689 | // Construction de l'axe | |
690 | TopoDS_Edge ed=TopoDS::Edge(ShapeA) ; | |
691 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
692 | TopoDS_Vertex Va,Vc; | |
693 | TopExp::Vertices(ed,Va,Vc ); | |
694 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
695 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
696 | gp_Vec V (A,C); | |
697 | gp_Dir D (V); | |
698 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
699 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
700 | GetMapOfAIS().Bind (TheAxis,name); | |
701 | TheAISContext()->Display(TheAxis); | |
702 | ||
703 | } | |
704 | ||
705 | // Fonction axisortho | |
706 | else { | |
707 | TheAISContext()->OpenLocalContext(); | |
708 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
709 | ||
161c4476 | 710 | // Active le mode edge |
7fd59977 | 711 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); |
712 | di<<" Select an edge."<<"\n"; | |
713 | ||
714 | // Boucle d'attente waitpick. | |
715 | Standard_Integer argcc = 5; | |
716 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
717 | const char **argvv = (const char **) buff; | |
718 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 719 | // fin de la boucle |
7fd59977 | 720 | |
721 | TopoDS_Shape ShapeA; | |
722 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
723 | ShapeA = TheAISContext()->SelectedShape(); | |
724 | } | |
725 | // Active le mode vertex et deactive edges | |
726 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
727 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
728 | di<<" Slect a vertex."<<"\n"; | |
729 | ||
730 | // Boucle d'attente waitpick. | |
731 | Standard_Integer argccc = 5; | |
732 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
733 | const char **argvvv = (const char **) bufff; | |
734 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 735 | // fin de la boucle |
7fd59977 | 736 | |
737 | // On peut choisir un pnt sur l'edge | |
738 | TopoDS_Shape ShapeB; | |
739 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
740 | ShapeB = TheAISContext()->SelectedShape(); | |
741 | } | |
742 | // Fermeture du context local | |
743 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
744 | ||
745 | // Construction de l'axe | |
746 | TopoDS_Edge ed=TopoDS::Edge(ShapeA) ; | |
747 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
748 | TopoDS_Vertex Va,Vc; | |
749 | TopExp::Vertices(ed,Va,Vc ); | |
750 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
751 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
752 | gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() ); | |
753 | gp_Vec V (A,E); | |
754 | gp_Dir D (V); | |
755 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
756 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
757 | GetMapOfAIS().Bind (TheAxis,name); | |
758 | TheAISContext()->Display(TheAxis); | |
759 | ||
760 | } | |
761 | ||
762 | } | |
763 | return 0; | |
764 | } | |
765 | ||
766 | ||
767 | //============================================================================== | |
768 | // Fonction First click Result | |
161c4476 | 769 | // |
7fd59977 | 770 | // vpoint vertex AIS_Point=Vertex |
771 | // edge AIS_Point=Middle of the edge | |
772 | //============================================================================== | |
773 | ||
774 | //============================================================================== | |
775 | //function : VPointBuilder | |
776 | //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge | |
777 | //Draw arg : vpoint PoinName [Xa] [Ya] [Za] | |
778 | //============================================================================== | |
779 | #include <TopoDS_Edge.hxx> | |
780 | #include <TopoDS_Vertex.hxx> | |
781 | #include <TopExp.hxx> | |
782 | #include <AIS_Point.hxx> | |
783 | #include <Geom_CartesianPoint.hxx> | |
784 | ||
161c4476 | 785 | static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 786 | { |
787 | // Declarations | |
788 | Standard_Boolean HasArg; | |
789 | TCollection_AsciiString name; | |
790 | Standard_Integer myCurrentIndex; | |
791 | ||
792 | // Verification | |
793 | if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
794 | if (argc==5) HasArg=Standard_True; | |
795 | else HasArg=Standard_False; | |
796 | ||
797 | name=argv[1]; | |
798 | // Fermeture des contextes | |
799 | TheAISContext()->CloseAllContexts(); | |
800 | ||
801 | // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom) | |
802 | if (HasArg) { | |
803 | Standard_Real thecoord[3]; | |
804 | for(Standard_Integer i=0;i<=2;i++) | |
91322f44 | 805 | thecoord[i]=Draw::Atof(argv[2+i]); |
7fd59977 | 806 | Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]); |
807 | Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint ); | |
808 | GetMapOfAIS().Bind (myAISPoint,name); | |
809 | TheAISContext()->Display(myAISPoint); | |
810 | } | |
811 | ||
812 | // Il n'a pas d'arguments | |
813 | else { | |
814 | TheAISContext()->OpenLocalContext(); | |
815 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
816 | ||
817 | // Active le mode Vertex et Edges | |
818 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
819 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); | |
820 | di<<" Select a vertex or an edge(build the middle)"<<"\n"; | |
821 | ||
822 | // Boucle d'attente waitpick. | |
823 | Standard_Integer argcc = 5; | |
824 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
825 | const char **argvv = (const char **) buff; | |
826 | while (ViewerMainLoop( argcc, argvv) ) { } | |
827 | // fin de la boucle | |
828 | ||
829 | TopoDS_Shape ShapeA; | |
830 | for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
831 | ShapeA= TheAISContext()->SelectedShape(); | |
832 | } | |
833 | ||
834 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
835 | // Un vertex a ete selectionne | |
836 | // Fermeture du context local | |
837 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
838 | ||
839 | // Construction du point | |
840 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); | |
841 | Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A ); | |
842 | Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint ); | |
843 | GetMapOfAIS().Bind(myAISPoint,name); | |
844 | TheAISContext()->Display(myAISPoint); | |
845 | } | |
846 | else { | |
847 | // Un Edge a ete selectionne | |
848 | // Fermeture du context local | |
849 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
850 | ||
851 | // Construction du point milieu de l'edge | |
852 | TopoDS_Edge myEdge=TopoDS::Edge(ShapeA); | |
853 | TopoDS_Vertex myVertexA,myVertexB; | |
854 | TopExp::Vertices (myEdge ,myVertexA ,myVertexB ); | |
855 | gp_Pnt A=BRep_Tool::Pnt(myVertexA ); | |
856 | gp_Pnt B=BRep_Tool::Pnt(myVertexB ); | |
857 | // M est le milieu de [AB] | |
858 | Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 ); | |
859 | Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM ); | |
860 | GetMapOfAIS().Bind(myAISPointM,name); | |
861 | TheAISContext()->Display(myAISPointM); | |
862 | } | |
863 | ||
864 | } | |
865 | return 0; | |
866 | ||
867 | } | |
868 | ||
869 | //============================================================================== | |
ceae62f0 | 870 | // Function 1st click 2de click 3de click |
7fd59977 | 871 | // vplane Vertex Vertex Vertex |
872 | // Vertex Edge | |
873 | // Edge Vertex | |
874 | // Face | |
875 | // vplanepara Face Vertex | |
876 | // Vertex Face | |
877 | // vplaneortho Face Edge | |
878 | // Edge Face | |
879 | //============================================================================== | |
880 | ||
881 | //============================================================================== | |
882 | //function : VPlaneBuilder | |
ceae62f0 | 883 | //purpose : Build an AIS_Plane from selected entities or Named AIS components |
9e8804b6 | 884 | //Draw arg : vplane PlaneName [AxisName] [PointName] [TypeOfSensitivity] |
885 | // [PointName] [PointName] [PointName] [TypeOfSensitivity] | |
886 | // [PlaneName] [PointName] [TypeOfSensitivity] | |
7fd59977 | 887 | //============================================================================== |
888 | ||
35e08fe8 | 889 | static Standard_Integer VPlaneBuilder (Draw_Interpretor& /*di*/, |
ceae62f0 A |
890 | Standard_Integer argc, |
891 | const char** argv) | |
7fd59977 | 892 | { |
893 | // Declarations | |
ceae62f0 A |
894 | Standard_Boolean hasArg; |
895 | TCollection_AsciiString aName; | |
896 | Standard_Integer aCurrentIndex; | |
7fd59977 | 897 | |
898 | // Verification | |
9e8804b6 | 899 | if (argc<2 || argc>6 ) |
ceae62f0 A |
900 | { |
901 | std::cout<<" Syntax error\n"; | |
902 | return 1; | |
903 | } | |
9e8804b6 | 904 | if (argc == 6 || argc==5 || argc==4) |
ceae62f0 A |
905 | hasArg=Standard_True; |
906 | else | |
907 | hasArg=Standard_False; | |
7fd59977 | 908 | |
ceae62f0 A |
909 | aName=argv[1]; |
910 | // Close all contexts | |
7fd59977 | 911 | TheAISContext()->CloseAllContexts(); |
912 | ||
ceae62f0 A |
913 | // There are some arguments |
914 | if (hasArg) | |
915 | { | |
916 | if (!GetMapOfAIS().IsBound2(argv[2] )) | |
917 | { | |
918 | std::cout<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()\n"; | |
919 | return 1; | |
920 | } | |
921 | // Get shape from map | |
922 | Handle(AIS_InteractiveObject) aShapeA = | |
7fd59977 | 923 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] )); |
924 | ||
ceae62f0 A |
925 | // The first argument is an AIS_Point |
926 | if (!aShapeA.IsNull() && | |
927 | aShapeA->Type()==AIS_KOI_Datum && | |
928 | aShapeA->Signature()==1) | |
929 | { | |
930 | // The second argument must also be an AIS_Point | |
931 | if (argc<5 || !GetMapOfAIS().IsBound2(argv[3])) | |
932 | { | |
933 | std::cout<<"vplane: error 2nd name doesn't exist in the GetMapOfAIS()\n"; | |
934 | return 1; | |
935 | } | |
936 | // Get shape from map | |
937 | Handle(AIS_InteractiveObject) aShapeB = | |
7fd59977 | 938 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); |
ceae62f0 A |
939 | // If B is not an AIS_Point |
940 | if (aShapeB.IsNull() || | |
941 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 942 | { |
ceae62f0 | 943 | std::cout<<"vplane: error 2nd object is expected to be an AIS_Point.\n"; |
7fd59977 | 944 | return 1; |
945 | } | |
ceae62f0 A |
946 | // The third object is an AIS_Point |
947 | if (!GetMapOfAIS().IsBound2(argv[4]) ) | |
948 | { | |
949 | std::cout<<"vplane: error 3d name doesn't exist in the GetMapOfAIS().\n"; | |
950 | return 1; | |
951 | } | |
952 | // Get shape from map | |
953 | Handle(AIS_InteractiveObject) aShapeC = | |
7fd59977 | 954 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4])); |
ceae62f0 A |
955 | // If C is not an AIS_Point |
956 | if (aShapeC.IsNull() || | |
957 | (!(aShapeC->Type()==AIS_KOI_Datum && aShapeC->Signature()==1))) | |
7fd59977 | 958 | { |
ceae62f0 | 959 | std::cout<<"vplane: error 3d object is expected to be an AIS_Point.\n"; |
7fd59977 | 960 | return 1; |
961 | } | |
962 | ||
ceae62f0 A |
963 | // Treatment of objects A, B, C |
964 | // Downcast an AIS_IO to AIS_Point | |
965 | Handle(AIS_Point) anAISPointA = Handle(AIS_Point)::DownCast( aShapeA); | |
966 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast( aShapeB); | |
967 | Handle(AIS_Point) anAISPointC = Handle(AIS_Point)::DownCast( aShapeC); | |
7fd59977 | 968 | |
ceae62f0 A |
969 | Handle(Geom_CartesianPoint ) aCartPointA = |
970 | Handle(Geom_CartesianPoint)::DownCast( anAISPointA->Component()); | |
7fd59977 | 971 | |
ceae62f0 A |
972 | Handle(Geom_CartesianPoint ) aCartPointB = |
973 | Handle(Geom_CartesianPoint)::DownCast( anAISPointB->Component()); | |
7fd59977 | 974 | |
ceae62f0 A |
975 | Handle(Geom_CartesianPoint ) aCartPointC = |
976 | Handle(Geom_CartesianPoint)::DownCast( anAISPointC->Component()); | |
7fd59977 | 977 | |
ceae62f0 | 978 | // Verification that the three points are different |
91322f44 | 979 | if(Abs(aCartPointB->X()-aCartPointA->X())<=Precision::Confusion() && |
980 | Abs(aCartPointB->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
981 | Abs(aCartPointB->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 982 | { |
7fd59977 | 983 | // B=A |
ceae62f0 | 984 | std::cout<<"vplane error: same points"<<"\n";return 1; |
7fd59977 | 985 | } |
91322f44 | 986 | if(Abs(aCartPointC->X()-aCartPointA->X())<=Precision::Confusion() && |
987 | Abs(aCartPointC->Y()-aCartPointA->Y())<=Precision::Confusion() && | |
988 | Abs(aCartPointC->Z()-aCartPointA->Z())<=Precision::Confusion()) | |
ceae62f0 | 989 | { |
7fd59977 | 990 | // C=A |
ceae62f0 | 991 | std::cout<<"vplane error: same points"<<"\n";return 1; |
7fd59977 | 992 | } |
91322f44 | 993 | if(Abs(aCartPointC->X()-aCartPointB->X())<=Precision::Confusion() && |
994 | Abs(aCartPointC->Y()-aCartPointB->Y())<=Precision::Confusion() && | |
995 | Abs(aCartPointC->Z()-aCartPointB->Z())<=Precision::Confusion()) | |
ceae62f0 | 996 | { |
7fd59977 | 997 | // C=B |
ceae62f0 | 998 | std::cout<<"vplane error: same points"<<"\n";return 1; |
7fd59977 | 999 | } |
1000 | ||
ceae62f0 A |
1001 | gp_Pnt A = aCartPointA->Pnt(); |
1002 | gp_Pnt B = aCartPointB->Pnt(); | |
1003 | gp_Pnt C = aCartPointC->Pnt(); | |
7fd59977 | 1004 | |
ceae62f0 | 1005 | // Construction of AIS_Plane |
7fd59977 | 1006 | GC_MakePlane MkPlane (A,B,C); |
ceae62f0 A |
1007 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); |
1008 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane ); | |
1009 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1010 | if (argc == 6) |
1011 | { | |
1012 | Standard_Integer aType = Draw::Atoi (argv[5]); | |
1013 | if (aType != 0 && aType != 1) | |
1014 | { | |
1015 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1016 | << "Should be one of the following values:\n" | |
1017 | << "0 - Interior\n" | |
1018 | << "1 - Boundary" | |
1019 | << std::endl; | |
1020 | return 1; | |
1021 | } | |
1022 | else | |
1023 | { | |
1024 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1025 | } | |
1026 | } | |
ceae62f0 | 1027 | TheAISContext()->Display(anAISPlane); |
7fd59977 | 1028 | } |
1029 | ||
ceae62f0 A |
1030 | // The first argument is an AIS_Axis |
1031 | // Creation of a plane orthogonal to the axis through a point | |
1032 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==2 ) { | |
1033 | // The second argument should be an AIS_Point | |
7fd59977 | 1034 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) |
1035 | { | |
ceae62f0 | 1036 | std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n"; |
7fd59977 | 1037 | return 1; |
1038 | } | |
ceae62f0 A |
1039 | // Get shape from map |
1040 | Handle(AIS_InteractiveObject) aShapeB = | |
7fd59977 | 1041 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); |
ceae62f0 A |
1042 | // If B is not an AIS_Point |
1043 | if (aShapeB.IsNull() || | |
1044 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1045 | { |
ceae62f0 | 1046 | std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n"; |
7fd59977 | 1047 | return 1; |
1048 | } | |
1049 | ||
ceae62f0 A |
1050 | // Treatment of objects A and B |
1051 | Handle(AIS_Axis) anAISAxisA = Handle(AIS_Axis)::DownCast(aShapeA); | |
1052 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1053 | |
ceae62f0 A |
1054 | Handle(Geom_Line ) aGeomLineA = anAISAxisA ->Component(); |
1055 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component() ; | |
7fd59977 | 1056 | |
ceae62f0 A |
1057 | gp_Ax1 anAxis = aGeomLineA->Position(); |
1058 | Handle(Geom_CartesianPoint) aCartPointB = | |
1059 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
7fd59977 | 1060 | |
ceae62f0 A |
1061 | gp_Dir D =anAxis.Direction(); |
1062 | gp_Pnt B = aCartPointB->Pnt(); | |
7fd59977 | 1063 | |
ceae62f0 A |
1064 | // Construction of AIS_Plane |
1065 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(B,D); | |
1066 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane,B ); | |
1067 | GetMapOfAIS().Bind (anAISPlane,aName ); | |
9e8804b6 | 1068 | if (argc == 5) |
1069 | { | |
1070 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1071 | if (aType != 0 && aType != 1) | |
1072 | { | |
1073 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1074 | << "Should be one of the following values:\n" | |
1075 | << "0 - Interior\n" | |
1076 | << "1 - Boundary" | |
1077 | << std::endl; | |
1078 | return 1; | |
1079 | } | |
1080 | else | |
1081 | { | |
1082 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1083 | } | |
1084 | } | |
ceae62f0 | 1085 | TheAISContext()->Display(anAISPlane); |
7fd59977 | 1086 | |
1087 | } | |
ceae62f0 A |
1088 | // The first argumnet is an AIS_Plane |
1089 | // Creation of a plane parallel to the plane passing through the point | |
1090 | else if (aShapeA->Type()==AIS_KOI_Datum && aShapeA->Signature()==7) | |
1091 | { | |
1092 | // The second argument should be an AIS_Point | |
1093 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3])) | |
1094 | { | |
1095 | std::cout<<"vplane: error 2d name doesn't exist in the GetMapOfAIS()\n"; | |
7fd59977 | 1096 | return 1; |
1097 | } | |
ceae62f0 A |
1098 | // Get shape from map |
1099 | Handle(AIS_InteractiveObject) aShapeB = | |
7fd59977 | 1100 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); |
ceae62f0 A |
1101 | // B should be an AIS_Point |
1102 | if (aShapeB.IsNull() || | |
1103 | (!(aShapeB->Type()==AIS_KOI_Datum && aShapeB->Signature()==1))) | |
7fd59977 | 1104 | { |
ceae62f0 | 1105 | std::cout<<"vplane: error 2d object is expected to be an AIS_Point\n"; |
7fd59977 | 1106 | return 1; |
1107 | } | |
1108 | ||
ceae62f0 A |
1109 | // Treatment of objects A and B |
1110 | Handle(AIS_Plane) anAISPlaneA = Handle(AIS_Plane)::DownCast(aShapeA); | |
1111 | Handle(AIS_Point) anAISPointB = Handle(AIS_Point)::DownCast(aShapeB); | |
7fd59977 | 1112 | |
ceae62f0 A |
1113 | Handle(Geom_Plane) aNewGeomPlane= anAISPlaneA->Component(); |
1114 | Handle(Geom_Point) aGeomPointB = anAISPointB->Component(); | |
7fd59977 | 1115 | |
ceae62f0 A |
1116 | Handle(Geom_CartesianPoint) aCartPointB = |
1117 | Handle(Geom_CartesianPoint)::DownCast(aGeomPointB); | |
1118 | gp_Pnt B= aCartPointB->Pnt(); | |
7fd59977 | 1119 | |
ceae62f0 A |
1120 | // Construction of an AIS_Plane |
1121 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aNewGeomPlane, B); | |
1122 | GetMapOfAIS().Bind (anAISPlane, aName); | |
9e8804b6 | 1123 | if (argc == 5) |
1124 | { | |
1125 | Standard_Integer aType = Draw::Atoi (argv[4]); | |
1126 | if (aType != 0 && aType != 1) | |
1127 | { | |
1128 | std::cout << "vplane error: wrong type of sensitivity!\n" | |
1129 | << "Should be one of the following values:\n" | |
1130 | << "0 - Interior\n" | |
1131 | << "1 - Boundary" | |
1132 | << std::endl; | |
1133 | return 1; | |
1134 | } | |
1135 | else | |
1136 | { | |
1137 | anAISPlane->SetTypeOfSensitivity (Select3D_TypeOfSensitivity (aType)); | |
1138 | } | |
1139 | } | |
ceae62f0 A |
1140 | TheAISContext()->Display(anAISPlane); |
1141 | } | |
1142 | // Error | |
1143 | else | |
1144 | { | |
1145 | std::cout<<"vplane: error 1st object is not an AIS\n"; | |
1146 | return 1; | |
7fd59977 | 1147 | } |
7fd59977 | 1148 | } |
ceae62f0 A |
1149 | // There are no arguments |
1150 | else | |
1151 | { | |
1152 | // Function vplane | |
1153 | // Test the constructor AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean ) | |
1154 | if (!strcasecmp(argv[0], "vplane")) | |
1155 | { | |
7fd59977 | 1156 | TheAISContext()->OpenLocalContext(); |
ceae62f0 | 1157 | aCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 1158 | |
ceae62f0 A |
1159 | // Active modes Vertex, Edge and Face |
1160 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1)); | |
1161 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2)); | |
1162 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4)); | |
1163 | std::cout<<"Select a vertex, a face or an edge\n"; | |
7fd59977 | 1164 | |
ceae62f0 | 1165 | // Wait for picking |
7fd59977 | 1166 | Standard_Integer argcc = 5; |
1167 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1168 | const char **argvv = (const char **) buff; | |
1169 | while (ViewerMainLoop( argcc, argvv) ) { } | |
ceae62f0 | 1170 | // end of the loop |
7fd59977 | 1171 | |
ceae62f0 A |
1172 | TopoDS_Shape aShapeA; |
1173 | for (TheAISContext()->InitSelected(); | |
1174 | TheAISContext()->MoreSelected(); | |
1175 | TheAISContext()->NextSelected()) | |
1176 | { | |
1177 | aShapeA = TheAISContext()->SelectedShape(); | |
7fd59977 | 1178 | } |
1179 | ||
ceae62f0 A |
1180 | // aShapeA is a Vertex |
1181 | if (aShapeA.ShapeType()==TopAbs_VERTEX ) | |
1182 | { | |
1183 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1184 | std::cout<<" Select an edge or a different vertex\n"; | |
7fd59977 | 1185 | |
ceae62f0 | 1186 | // Wait for picking |
7fd59977 | 1187 | Standard_Integer argccc = 5; |
1188 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1189 | const char **argvvv = (const char **) bufff; | |
1190 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1191 | // end of the loop |
7fd59977 | 1192 | |
ceae62f0 A |
1193 | TopoDS_Shape aShapeB; |
1194 | for (TheAISContext()->InitSelected(); | |
1195 | TheAISContext()->MoreSelected(); | |
1196 | TheAISContext()->NextSelected()) | |
1197 | { | |
1198 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1199 | } |
ceae62f0 A |
1200 | // aShapeB is a Vertex |
1201 | if (aShapeB.ShapeType()==TopAbs_VERTEX) | |
1202 | { | |
1203 | // A and B are the same | |
1204 | if (aShapeB.IsSame(aShapeA)) | |
1205 | { | |
1206 | std::cout<<" vplane: error, same points selected\n"; | |
1207 | return 1; | |
1208 | } | |
1209 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2)); | |
1210 | std::cout<<" Select a different vertex\n"; | |
7fd59977 | 1211 | |
ceae62f0 | 1212 | // Wait for picking |
7fd59977 | 1213 | Standard_Integer argcccc = 5; |
1214 | const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1215 | const char **argvvvv = (const char **) buffff; | |
1216 | while (ViewerMainLoop( argcccc, argvvvv) ) { } | |
ceae62f0 | 1217 | // end of the loop |
7fd59977 | 1218 | |
ceae62f0 A |
1219 | TopoDS_Shape aShapeC; |
1220 | for (TheAISContext()->InitSelected(); | |
1221 | TheAISContext()->MoreSelected(); | |
1222 | TheAISContext()->NextSelected()) | |
1223 | { | |
1224 | aShapeC = TheAISContext()->SelectedShape(); | |
1225 | } | |
1226 | // aShapeC is the same as A or B | |
1227 | if (aShapeC.IsSame(aShapeA)||aShapeC.IsSame(aShapeB)) | |
1228 | { | |
1229 | std::cout<<" vplane: error, same points selected\n"; | |
1230 | return 1; | |
7fd59977 | 1231 | } |
7fd59977 | 1232 | |
ceae62f0 A |
1233 | // Close the local context |
1234 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1235 | ||
1236 | // Construction of plane | |
1237 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA)); | |
1238 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB)); | |
1239 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(aShapeC)); | |
1240 | GC_MakePlane MkPlane(A, B, C); | |
1241 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1242 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1243 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1244 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1245 | } |
ceae62f0 A |
1246 | // ShapeB is an edge |
1247 | else | |
1248 | { | |
1249 | // Verify that the vertex is not on the edge ShapeB | |
1250 | TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB); | |
1251 | TopoDS_Vertex aVertA = TopoDS::Vertex(aShapeA); | |
7fd59977 | 1252 | |
ceae62f0 A |
1253 | BRepExtrema_ExtPC OrthoProj(aVertA, anEdgeB); |
1254 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1255 | { | |
1256 | // The vertex is on the edge | |
1257 | std::cout<<" vplane: error point is on the edge\n"; | |
1258 | return 1; | |
1259 | } | |
1260 | else | |
1261 | { | |
1262 | // Close the local context | |
1263 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1264 | // Construction of plane | |
1265 | gp_Pnt A = BRep_Tool::Pnt(aVertA); | |
1266 | TopoDS_Vertex aVBa, aVBb; | |
1267 | TopExp::Vertices(anEdgeB ,aVBa ,aVBb); | |
1268 | gp_Pnt aBa = BRep_Tool::Pnt(aVBa); | |
1269 | gp_Pnt aBb = BRep_Tool::Pnt(aVBb); | |
1270 | GC_MakePlane MkPlane (A, aBa, aBb); | |
1271 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); | |
1272 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1273 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1274 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1275 | } |
7fd59977 | 1276 | } |
7fd59977 | 1277 | } |
ceae62f0 A |
1278 | // aShapeA is an edge |
1279 | else if (aShapeA.ShapeType()==TopAbs_EDGE) | |
1280 | { | |
1281 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1282 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2)); | |
1283 | std::cout<<" Select a vertex that don't belong to the edge\n"; | |
7fd59977 | 1284 | |
ceae62f0 | 1285 | // Wait for picking |
7fd59977 | 1286 | Standard_Integer argccc = 5; |
1287 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1288 | const char **argvvv = (const char **) bufff; | |
1289 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1290 | // end of the loop |
7fd59977 | 1291 | |
ceae62f0 A |
1292 | TopoDS_Shape aShapeB; |
1293 | for (TheAISContext()->InitSelected(); | |
1294 | TheAISContext()->MoreSelected(); | |
1295 | TheAISContext()->NextSelected()) | |
1296 | { | |
1297 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1298 | } |
ceae62f0 A |
1299 | // aShapeB should be a Vertex |
1300 | // Check that the vertex aShapeB is not on the edge | |
1301 | TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA); | |
1302 | TopoDS_Vertex aVertB = TopoDS::Vertex(aShapeB); | |
1303 | ||
1304 | BRepExtrema_ExtPC OrthoProj (aVertB, anEdgeA); | |
1305 | if (OrthoProj.SquareDistance(1)<Precision::Approximation()) | |
1306 | { | |
1307 | // The vertex is on the edge | |
1308 | std::cout<<" vplane: error point is on the edge\n"; | |
1309 | return 1; | |
7fd59977 | 1310 | } |
ceae62f0 A |
1311 | else |
1312 | { | |
1313 | // Close the local context | |
1314 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1315 | // Construction of plane | |
1316 | gp_Pnt B = BRep_Tool::Pnt(aVertB); | |
1317 | TopoDS_Vertex aVAa, aVAb; | |
1318 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1319 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1320 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
7fd59977 | 1321 | GC_MakePlane MkPlane (B,Aa,Ab); |
ceae62f0 A |
1322 | Handle(Geom_Plane) aGeomPlane = MkPlane.Value(); |
1323 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane); | |
1324 | GetMapOfAIS().Bind (anAISPlane ,aName); | |
1325 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1326 | } |
7fd59977 | 1327 | } |
ceae62f0 A |
1328 | // aShapeA is a Face |
1329 | else | |
1330 | { | |
1331 | // Close the local context: nothing to select | |
1332 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1333 | // Construction of plane | |
1334 | TopoDS_Face aFace = TopoDS::Face(aShapeA); | |
1335 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1336 | if (aSurface.GetType()==GeomAbs_Plane) | |
1337 | { | |
1338 | gp_Pln aPlane = aSurface.Plane(); | |
1339 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane(aPlane); | |
1340 | Handle(AIS_Plane) anAISPlane = new AIS_Plane(aGeomPlane); | |
1341 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1342 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1343 | } |
ceae62f0 A |
1344 | else |
1345 | { | |
1346 | std::cout<<" vplane: error\n"; | |
1347 | return 1; | |
7fd59977 | 1348 | } |
7fd59977 | 1349 | } |
7fd59977 | 1350 | } |
1351 | ||
ceae62f0 | 1352 | // Function vPlanePara |
7fd59977 | 1353 | // =================== |
ceae62f0 A |
1354 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt) |
1355 | else if (!strcasecmp(argv[0], "vplanepara")) | |
1356 | { | |
7fd59977 | 1357 | TheAISContext()->OpenLocalContext(); |
ceae62f0 | 1358 | aCurrentIndex = TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 1359 | |
ceae62f0 A |
1360 | // Activate modes Vertex and Face |
1361 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1)); | |
1362 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4)); | |
1363 | std::cout<<" Select a vertex or a face\n"; | |
7fd59977 | 1364 | |
ceae62f0 | 1365 | // Wait for picking |
7fd59977 | 1366 | Standard_Integer argcc = 5; |
1367 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1368 | const char **argvv = (const char **) buff; | |
1369 | while (ViewerMainLoop( argcc, argvv) ) { } | |
ceae62f0 | 1370 | // end of the loop |
7fd59977 | 1371 | |
ceae62f0 A |
1372 | TopoDS_Shape aShapeA; |
1373 | for (TheAISContext()->InitSelected(); | |
1374 | TheAISContext()->MoreSelected(); | |
1375 | TheAISContext()->NextSelected()) | |
1376 | { | |
1377 | aShapeA = TheAISContext()->SelectedShape(); | |
7fd59977 | 1378 | } |
1379 | ||
ceae62f0 A |
1380 | if (aShapeA.ShapeType()==TopAbs_VERTEX ) |
1381 | { | |
1382 | // aShapeA is a vertex | |
1383 | // Deactivate the mode Vertex | |
1384 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1)); | |
1385 | std::cout<<" Select a face\n"; | |
7fd59977 | 1386 | |
ceae62f0 | 1387 | // Wait for picking |
7fd59977 | 1388 | Standard_Integer argccc = 5; |
1389 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1390 | const char **argvvv = (const char **) bufff; | |
1391 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1392 | // end of the loop |
7fd59977 | 1393 | |
ceae62f0 A |
1394 | TopoDS_Shape aShapeB; |
1395 | for (TheAISContext()->InitSelected(); | |
1396 | TheAISContext()->MoreSelected(); | |
1397 | TheAISContext()->NextSelected()) | |
1398 | { | |
1399 | // A vertex ShapeA can be on Face ShapeB | |
1400 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1401 | } |
1402 | ||
ceae62f0 A |
1403 | // Close the local context |
1404 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
7fd59977 | 1405 | |
ceae62f0 A |
1406 | // Construction of plane |
1407 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(aShapeA)); | |
1408 | ||
1409 | TopoDS_Face aFace = TopoDS::Face(aShapeB); | |
1410 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1411 | if (aSurface.GetType()==GeomAbs_Plane ) | |
1412 | { | |
1413 | gp_Pln aPlane = aSurface.Plane(); | |
1414 | // Construct a plane parallel to aGeomPlane through A | |
1415 | aPlane.SetLocation(A); | |
1416 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1417 | Handle(AIS_Plane) aAISPlane = new AIS_Plane (aGeomPlane, A); | |
1418 | GetMapOfAIS().Bind (aAISPlane ,aName); | |
1419 | TheAISContext()->Display(aAISPlane); | |
7fd59977 | 1420 | } |
ceae62f0 A |
1421 | else |
1422 | { | |
1423 | std::cout<<" vplanepara: error\n"; | |
1424 | return 1; | |
7fd59977 | 1425 | } |
7fd59977 | 1426 | } |
ceae62f0 A |
1427 | else |
1428 | { | |
1429 | // ShapeA is a Face | |
1430 | // Deactive the mode Face | |
1431 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1432 | std::cout<<" Select a vertex\n"; | |
7fd59977 | 1433 | |
ceae62f0 | 1434 | // Wait for picking |
7fd59977 | 1435 | Standard_Integer argccc = 5; |
1436 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1437 | const char **argvvv = (const char **) bufff; | |
1438 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1439 | // end of the loop |
7fd59977 | 1440 | |
ceae62f0 A |
1441 | TopoDS_Shape aShapeB; |
1442 | for (TheAISContext()->InitSelected(); | |
1443 | TheAISContext()->MoreSelected(); | |
1444 | TheAISContext()->NextSelected()) | |
1445 | { | |
1446 | // A vertex ShapeB can be on Face ShapeA | |
1447 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1448 | } |
ceae62f0 A |
1449 | // Close the local context |
1450 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
7fd59977 | 1451 | |
ceae62f0 A |
1452 | // Construction of plane |
1453 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(aShapeB)); | |
1454 | ||
1455 | TopoDS_Face aFace=TopoDS::Face(aShapeA); | |
1456 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1457 | if (aSurface.GetType()==GeomAbs_Plane ) | |
1458 | { | |
1459 | gp_Pln aPlane = aSurface.Plane(); | |
1460 | aPlane.SetLocation(B); | |
1461 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1462 | // Construct a plane parallel to aGeomPlane through B | |
1463 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, B); | |
1464 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1465 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1466 | } |
ceae62f0 A |
1467 | else |
1468 | { | |
1469 | std::cout<<" vplanepara: error"<<"\n";return 1; | |
7fd59977 | 1470 | } |
7fd59977 | 1471 | } |
7fd59977 | 1472 | } |
1473 | ||
ceae62f0 | 1474 | // Function vplaneortho |
7fd59977 | 1475 | // ==================== |
ceae62f0 A |
1476 | // test the constructor AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt) |
1477 | else | |
1478 | { | |
7fd59977 | 1479 | TheAISContext()->OpenLocalContext(); |
ceae62f0 | 1480 | aCurrentIndex = TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 1481 | |
ceae62f0 A |
1482 | // Activate the modes Edge and Face |
1483 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2)); | |
1484 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4)); | |
1485 | std::cout<<" Select a face and an edge coplanar\n"; | |
7fd59977 | 1486 | |
ceae62f0 | 1487 | // Wait for picking |
7fd59977 | 1488 | Standard_Integer argcc = 5; |
1489 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1490 | const char **argvv = (const char **) buff; | |
1491 | while (ViewerMainLoop( argcc, argvv) ) { } | |
ceae62f0 | 1492 | // end of the loop |
7fd59977 | 1493 | |
ceae62f0 A |
1494 | TopoDS_Shape aShapeA; |
1495 | for (TheAISContext()->InitSelected(); | |
1496 | TheAISContext()->MoreSelected(); | |
1497 | TheAISContext()->NextSelected()) | |
1498 | { | |
1499 | aShapeA = TheAISContext()->SelectedShape(); | |
7fd59977 | 1500 | } |
1501 | ||
ceae62f0 A |
1502 | if (aShapeA.ShapeType()==TopAbs_EDGE ) |
1503 | { | |
1504 | // ShapeA is an edge, deactivate the mode Edge... | |
1505 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2)); | |
1506 | std::cout<<" Select a face\n"; | |
7fd59977 | 1507 | |
ceae62f0 | 1508 | // Wait for picking |
7fd59977 | 1509 | Standard_Integer argccc = 5; |
1510 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1511 | const char **argvvv = (const char **) bufff; | |
1512 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1513 | // end of the loop |
7fd59977 | 1514 | |
ceae62f0 A |
1515 | TopoDS_Shape aShapeB; |
1516 | for (TheAISContext()->InitSelected(); | |
1517 | TheAISContext()->MoreSelected(); | |
1518 | TheAISContext()->NextSelected()) | |
1519 | { | |
1520 | // Edge ShapeA can be on Face ShapeB | |
1521 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1522 | } |
1523 | ||
ceae62f0 A |
1524 | // Close the local context |
1525 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
7fd59977 | 1526 | |
ceae62f0 A |
1527 | // Construction of plane |
1528 | TopoDS_Edge anEdgeA = TopoDS::Edge(aShapeA); | |
1529 | TopoDS_Vertex aVAa, aVAb; | |
1530 | TopExp::Vertices(anEdgeA, aVAa, aVAb); | |
1531 | gp_Pnt Aa = BRep_Tool::Pnt(aVAa); | |
1532 | gp_Pnt Ab = BRep_Tool::Pnt(aVAb); | |
1533 | gp_Vec ab (Aa,Ab); | |
7fd59977 | 1534 | |
1535 | gp_Dir Dab (ab); | |
ceae62f0 A |
1536 | // Creation of rotation axis |
1537 | gp_Ax1 aRotAxis (Aa,Dab); | |
1538 | ||
1539 | TopoDS_Face aFace = TopoDS::Face(aShapeB); | |
1540 | // The edge must be parallel to the face | |
1541 | BRepExtrema_ExtPF aHeightA (aVAa, aFace); | |
1542 | BRepExtrema_ExtPF aHeightB (aVAb, aFace); | |
1543 | // Compare to heights | |
1544 | if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1))) | |
1545 | >Precision::Confusion()) | |
1546 | { | |
1547 | // the edge is not parallel to the face | |
1548 | std::cout<<" vplaneortho error: the edge is not parallel to the face\n"; | |
1549 | return 1; | |
7fd59977 | 1550 | } |
ceae62f0 A |
1551 | // the edge is OK |
1552 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1553 | if (aSurface.GetType()==GeomAbs_Plane) | |
1554 | { | |
1555 | gp_Pln aPlane = aSurface.Plane(); | |
1556 | // It rotates a half turn round the axis of rotation | |
1557 | aPlane.Rotate(aRotAxis , M_PI/2); | |
1558 | ||
1559 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1560 | // constructed aGeomPlane parallel to a plane containing the edge (center mid-edge) | |
1561 | gp_Pnt aMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 ); | |
1562 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle); | |
1563 | GetMapOfAIS().Bind (anAISPlane, aName); | |
1564 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1565 | } |
ceae62f0 A |
1566 | else |
1567 | { | |
1568 | std::cout<<" vplaneortho: error\n"; | |
1569 | return 1; | |
7fd59977 | 1570 | } |
7fd59977 | 1571 | } |
ceae62f0 A |
1572 | else |
1573 | { | |
1574 | // ShapeA is a Face, deactive the mode Face. | |
1575 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4)); | |
1576 | std::cout<<" Select an edge\n"; | |
7fd59977 | 1577 | |
ceae62f0 | 1578 | // Wait for picking |
7fd59977 | 1579 | Standard_Integer argccc = 5; |
1580 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1581 | const char **argvvv = (const char **) bufff; | |
1582 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
ceae62f0 | 1583 | // end of the loop |
7fd59977 | 1584 | |
ceae62f0 A |
1585 | TopoDS_Shape aShapeB; |
1586 | for (TheAISContext()->InitSelected(); | |
1587 | TheAISContext()->MoreSelected(); | |
1588 | TheAISContext()->NextSelected()) | |
1589 | { | |
1590 | // Edge ShapeB can be on Face ShapeA | |
1591 | aShapeB = TheAISContext()->SelectedShape(); | |
7fd59977 | 1592 | } |
ceae62f0 A |
1593 | // Close the local context |
1594 | TheAISContext()->CloseLocalContext(aCurrentIndex); | |
1595 | ||
1596 | // Construction of plane | |
1597 | TopoDS_Edge anEdgeB = TopoDS::Edge(aShapeB); | |
1598 | TopoDS_Vertex aVBa, aVBb; | |
1599 | TopExp::Vertices(anEdgeB, aVBa, aVBb); | |
1600 | gp_Pnt aBa = BRep_Tool::Pnt(aVBa); | |
1601 | gp_Pnt aBb = BRep_Tool::Pnt(aVBb); | |
1602 | gp_Vec ab (aBa,aBb); | |
7fd59977 | 1603 | gp_Dir Dab (ab); |
ceae62f0 A |
1604 | // Creation of rotation axe |
1605 | gp_Ax1 aRotAxis (aBa,Dab); | |
1606 | ||
1607 | TopoDS_Face aFace = TopoDS::Face(aShapeA); | |
1608 | // The edge must be parallel to the face | |
1609 | BRepExtrema_ExtPF aHeightA (aVBa, aFace); | |
1610 | BRepExtrema_ExtPF aHeightB (aVBb, aFace); | |
1611 | // Comparing the two heights | |
1612 | if (fabs(sqrt(aHeightA.SquareDistance(1)) - sqrt(aHeightB.SquareDistance(1))) | |
1613 | >Precision::Confusion()) | |
1614 | { | |
1615 | // the edge is not parallel to the face | |
1616 | std::cout<<" vplaneortho error: the edge is not parallel to the face\n"; | |
1617 | return 1; | |
7fd59977 | 1618 | } |
ceae62f0 A |
1619 | // The edge is OK |
1620 | BRepAdaptor_Surface aSurface (aFace, Standard_False); | |
1621 | if (aSurface.GetType()==GeomAbs_Plane) | |
1622 | { | |
1623 | gp_Pln aPlane = aSurface.Plane(); | |
1624 | // It rotates a half turn round the axis of rotation | |
1625 | aPlane.Rotate(aRotAxis , M_PI/2); | |
1626 | Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane); | |
1627 | // constructed aGeomPlane parallel to a plane containing the edge theGeomPlane (center mid-edge) | |
1628 | gp_Pnt aMiddle ((aBa.X()+aBb.X() )/2 , (aBa.Y()+aBb.Y() )/2 , (aBa.Z()+aBb.Z() )/2 ); | |
1629 | Handle(AIS_Plane) anAISPlane = new AIS_Plane (aGeomPlane, aMiddle); | |
1630 | GetMapOfAIS().Bind (anAISPlane ,aName); | |
1631 | TheAISContext()->Display(anAISPlane); | |
7fd59977 | 1632 | } |
ceae62f0 A |
1633 | else |
1634 | { | |
1635 | std::cout<<" vplaneortho: error\n"; | |
1636 | return 1; | |
7fd59977 | 1637 | } |
7fd59977 | 1638 | } |
7fd59977 | 1639 | } |
7fd59977 | 1640 | } |
1641 | return 0; | |
7fd59977 | 1642 | } |
1643 | ||
f3889691 | 1644 | //=============================================================================================== |
1645 | //function : VChangePlane | |
1646 | //purpose : | |
1647 | //=============================================================================================== | |
1648 | static int VChangePlane (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) | |
1649 | { | |
1650 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
1651 | if (aContextAIS.IsNull()) | |
1652 | { | |
1653 | std::cout << theArgVec[0] << "AIS context is not available.\n"; | |
1654 | return 1; | |
1655 | } | |
1656 | ||
1657 | if (theArgsNb < 3 || theArgsNb > 11) | |
1658 | { | |
1659 | std::cerr << theArgVec[0] | |
1660 | << ": incorrect number of command arguments.\n" | |
1661 | << "Type help for more information.\n"; | |
1662 | return 1; | |
1663 | } | |
1664 | ||
1665 | TCollection_AsciiString aName (theArgVec[1]); | |
1666 | ||
1667 | Handle(AIS_Plane) aPlane = GetMapOfAIS().IsBound2(aName) | |
1668 | ? Handle(AIS_Plane)::DownCast (GetMapOfAIS().Find2 (aName)) | |
1669 | : NULL; | |
1670 | ||
1671 | if ( aPlane.IsNull() ) | |
1672 | { | |
1673 | std::cout << theArgVec[0] | |
1674 | << ": there is no interactive plane with the given name." | |
1675 | << "Type help for more information.\n"; | |
1676 | return 1; | |
1677 | } | |
1678 | ||
1679 | Standard_Real aCenterX = aPlane->Center().X(); | |
1680 | Standard_Real aCenterY = aPlane->Center().Y(); | |
1681 | Standard_Real aCenterZ = aPlane->Center().Z(); | |
1682 | ||
1683 | Standard_Real aDirX = aPlane->Component()->Axis().Direction().X(); | |
1684 | Standard_Real aDirY = aPlane->Component()->Axis().Direction().Y(); | |
1685 | Standard_Real aDirZ = aPlane->Component()->Axis().Direction().Z(); | |
1686 | ||
1687 | Standard_Real aSizeX = 0.0; | |
1688 | Standard_Real aSizeY = 0.0; | |
1689 | aPlane->Size (aSizeX, aSizeY); | |
1690 | Standard_Boolean isUpdate = Standard_True; | |
1691 | ||
1692 | TCollection_AsciiString aPName, aPValue; | |
1693 | for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) | |
1694 | { | |
1695 | const TCollection_AsciiString anArg = theArgVec[anArgIt]; | |
1696 | TCollection_AsciiString anArgCase = anArg; | |
1697 | anArgCase.UpperCase(); | |
1698 | if (ViewerTest::SplitParameter (anArg, aPName, aPValue)) | |
1699 | { | |
1700 | aPName.UpperCase(); | |
1701 | if (aPName.IsEqual ("X")) | |
1702 | { | |
1703 | aCenterX = aPValue.RealValue(); | |
1704 | } | |
1705 | else if (aPName.IsEqual ("Y")) | |
1706 | { | |
1707 | aCenterY = aPValue.RealValue(); | |
1708 | } | |
1709 | else if (aPName.IsEqual ("Z")) | |
1710 | { | |
1711 | aCenterZ = aPValue.RealValue(); | |
1712 | } | |
1713 | else if (aPName.IsEqual ("DX")) | |
1714 | { | |
1715 | aDirX = aPValue.RealValue(); | |
1716 | } | |
1717 | else if (aPName.IsEqual ("DY")) | |
1718 | { | |
1719 | aDirY = aPValue.RealValue(); | |
1720 | } | |
1721 | else if (aPName.IsEqual ("DZ")) | |
1722 | { | |
1723 | aDirZ = aPValue.RealValue(); | |
1724 | } | |
1725 | else if (aPName.IsEqual ("SX")) | |
1726 | { | |
1727 | aSizeX = aPValue.RealValue(); | |
1728 | } | |
1729 | else if (aPName.IsEqual ("SY")) | |
1730 | { | |
1731 | aSizeY = aPValue.RealValue(); | |
1732 | } | |
1733 | } | |
1734 | else if (anArg.IsEqual ("NOUPDATE")) | |
1735 | { | |
1736 | isUpdate = Standard_False; | |
1737 | } | |
1738 | } | |
1739 | ||
1740 | gp_Dir aDirection (aDirX, aDirY, aDirZ); | |
1741 | gp_Pnt aCenterPnt (aCenterX, aCenterY, aCenterZ); | |
1742 | aPlane->SetCenter (aCenterPnt); | |
1743 | aPlane->SetComponent (new Geom_Plane (aCenterPnt, aDirection)); | |
1744 | aPlane->SetSize (aSizeX, aSizeY); | |
1745 | ||
1746 | if (isUpdate) | |
1747 | { | |
1748 | aContextAIS->Update (aPlane, Standard_True); | |
1749 | } | |
1750 | ||
1751 | return 0; | |
1752 | } | |
7fd59977 | 1753 | |
1754 | //============================================================================== | |
1755 | // Fonction vline | |
1756 | // --------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1757 | //============================================================================== | |
1758 | ||
1759 | //============================================================================== | |
1760 | //function : VLineBuilder | |
161c4476 | 1761 | //purpose : Build an AIS_Line |
7fd59977 | 1762 | //Draw arg : vline LineName [AIS_PointName] [AIS_PointName] |
1763 | // [Xa] [Ya] [Za] [Xb] [Yb] [Zb] | |
1764 | //============================================================================== | |
1765 | #include <Geom_CartesianPoint.hxx> | |
1766 | #include <AIS_Line.hxx> | |
1767 | ||
1768 | ||
161c4476 | 1769 | static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1770 | { |
1771 | Standard_Integer myCurrentIndex; | |
1772 | // Verifications | |
1773 | if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; } | |
1774 | // Fermeture des contextes | |
1775 | TheAISContext()->CloseAllContexts(); | |
1776 | ||
1777 | // On recupere les parametres | |
1778 | Handle(AIS_InteractiveObject) theShapeA; | |
1779 | Handle(AIS_InteractiveObject) theShapeB; | |
1780 | ||
1781 | // Parametres: AIS_Point AIS_Point | |
1782 | // =============================== | |
1783 | if (argc==4) { | |
1784 | theShapeA= | |
1785 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2])); | |
1786 | // On verifie que c'est bien une AIS_Point | |
1787 | if (!theShapeA.IsNull() && | |
1788 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
1789 | // on recupere le deuxieme AIS_Point | |
1790 | theShapeB= | |
1791 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
1792 | if (theShapeA.IsNull() || | |
1793 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
1794 | { | |
1795 | di <<"vline error: wrong type of 2de argument."<<"\n"; | |
1796 | return 1; | |
1797 | } | |
1798 | } | |
161c4476 | 1799 | else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; } |
7fd59977 | 1800 | // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus |
1801 | Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA; | |
1802 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1803 | ||
1804 | Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component(); | |
1805 | Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA); | |
1806 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; | |
1807 | ||
1808 | Handle(Geom_Point ) myGeomPointB= theAISPointB->Component(); | |
1809 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB); | |
1810 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; | |
1811 | ||
1812 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
1813 | // B=A | |
1814 | di<<"vline error: same points"<<"\n";return 1; | |
1815 | } | |
1816 | // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB) | |
1817 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1818 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1819 | TheAISContext()->Display(theAISLine ); | |
1820 | ||
1821 | } | |
1822 | ||
1823 | // Parametres 6 Reals | |
1824 | // ================== | |
1825 | ||
1826 | else if (argc==8) { | |
161c4476 | 1827 | // On verifie que les deux points ne sont pas confondus |
7fd59977 | 1828 | |
1829 | Standard_Real coord[6]; | |
1830 | for(Standard_Integer i=0;i<=2;i++){ | |
91322f44 | 1831 | coord[i]=Draw::Atof(argv[2+i]); |
1832 | coord[i+3]=Draw::Atof(argv[5+i]); | |
7fd59977 | 1833 | } |
1834 | ||
1835 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] ); | |
1836 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] ); | |
1837 | ||
1838 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1839 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1840 | TheAISContext()->Display(theAISLine ); | |
1841 | ||
1842 | } | |
1843 | ||
1844 | // Pas de parametres: Selection dans le viewer. | |
1845 | // ============================================ | |
1846 | ||
1847 | else { | |
1848 | TheAISContext()->OpenLocalContext(); | |
1849 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1850 | ||
1851 | // Active le mode Vertex. | |
1852 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1853 | di<<" Select a vertex "<<"\n"; | |
1854 | ||
1855 | // Boucle d'attente waitpick. | |
1856 | Standard_Integer argcc = 5; | |
1857 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1858 | const char **argvv = (const char **) buff; | |
1859 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1860 | // fin de la boucle | |
1861 | ||
1862 | TopoDS_Shape ShapeA; | |
1863 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1864 | ShapeA = TheAISContext()->SelectedShape(); | |
1865 | } | |
1866 | ||
1867 | // ShapeA est un Vertex | |
1868 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1869 | ||
1870 | di<<" Select a different vertex."<<"\n"; | |
1871 | ||
1872 | TopoDS_Shape ShapeB; | |
1873 | do { | |
1874 | ||
1875 | // Boucle d'attente waitpick. | |
1876 | Standard_Integer argccc = 5; | |
1877 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1878 | const char **argvvv = (const char **) bufff; | |
1879 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 1880 | // fin de la boucle |
7fd59977 | 1881 | |
1882 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1883 | ShapeB = TheAISContext()->SelectedShape(); | |
1884 | } | |
1885 | ||
1886 | ||
1887 | } while(ShapeB.IsSame(ShapeA) ); | |
1888 | ||
1889 | // Fermeture du context local | |
1890 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1891 | ||
1892 | // Construction de la line | |
1893 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); | |
1894 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
1895 | ||
1896 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A); | |
1897 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B); | |
1898 | ||
1899 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1900 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1901 | TheAISContext()->Display(theAISLine ); | |
1902 | ||
1903 | } | |
1904 | else { | |
1905 | di<<"vline error."<<"\n"; | |
1906 | } | |
1907 | ||
1908 | } | |
1909 | ||
1910 | return 0; | |
1911 | } | |
1912 | ||
329843e2 A |
1913 | //============================================================================== |
1914 | // class : FilledCircle | |
1915 | // purpose : creates filled circle based on AIS_InteractiveObject | |
1916 | // and Geom_Circle. | |
1917 | // This class is used to check method Matches() of class | |
1918 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True, | |
1919 | // because none of AIS classes provides creation of | |
1920 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True | |
1921 | // (look method ComputeSelection() ) | |
1922 | //============================================================================== | |
1923 | ||
1924 | Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1925 | { | |
1926 | gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.))); | |
1927 | gp_Circ aCirc(anAxes, theRadius); | |
1928 | Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc); | |
1929 | return aCircle; | |
1930 | } | |
1931 | ||
1932 | DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject) | |
1933 | ||
1934 | class FilledCircle : public AIS_InteractiveObject | |
1935 | { | |
1936 | public: | |
1937 | // CASCADE RTTI | |
1938 | DEFINE_STANDARD_RTTI(FilledCircle); | |
1939 | ||
1940 | FilledCircle(gp_Pnt theCenter, Standard_Real theRadius); | |
1941 | FilledCircle(Handle(Geom_Circle) theCircle); | |
1942 | ||
1943 | private: | |
1944 | TopoDS_Face ComputeFace(); | |
1945 | ||
1946 | // Virtual methods implementation | |
1947 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
1948 | const Handle(Prs3d_Presentation)& thePresentation, | |
1949 | const Standard_Integer theMode); | |
1950 | ||
1951 | void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, | |
1952 | const Standard_Integer theMode); | |
1953 | ||
1954 | protected: | |
1955 | Handle(Geom_Circle) myCircle; | |
1956 | Standard_Boolean myFilledStatus; | |
1957 | ||
1958 | }; | |
1959 | ||
1960 | IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject) | |
1961 | IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject) | |
1962 | ||
1963 | FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1964 | { | |
1965 | myCircle = CreateCircle(theCenter, theRadius); | |
1966 | myFilledStatus = Standard_True; | |
1967 | } | |
1968 | ||
1969 | FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle) | |
1970 | { | |
1971 | myCircle = theCircle; | |
1972 | myFilledStatus = Standard_True; | |
1973 | } | |
1974 | ||
1975 | TopoDS_Face FilledCircle::ComputeFace() | |
1976 | { | |
1977 | // Create edge from myCircle | |
1978 | BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ()); | |
1979 | TopoDS_Edge anEdge = anEdgeMaker.Edge(); | |
1980 | ||
1981 | // Create wire from anEdge | |
1982 | BRepBuilderAPI_MakeWire aWireMaker(anEdge); | |
1983 | TopoDS_Wire aWire = aWireMaker.Wire(); | |
1984 | ||
1985 | // Create face from aWire | |
1986 | BRepBuilderAPI_MakeFace aFaceMaker(aWire); | |
1987 | TopoDS_Face aFace = aFaceMaker.Face(); | |
1988 | ||
1989 | return aFace; | |
1990 | } | |
1991 | ||
857ffd5e | 1992 | void FilledCircle::Compute(const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/, |
1993 | const Handle(Prs3d_Presentation) &thePresentation, | |
329843e2 A |
1994 | const Standard_Integer theMode) |
1995 | { | |
1996 | thePresentation->Clear(); | |
1997 | ||
1998 | TopoDS_Face aFace = ComputeFace(); | |
1999 | ||
2000 | if (aFace.IsNull()) return; | |
2001 | if (theMode != 0) return; | |
2002 | ||
2003 | StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer); | |
2004 | } | |
2005 | ||
857ffd5e | 2006 | void FilledCircle::ComputeSelection(const Handle(SelectMgr_Selection) &theSelection, |
35e08fe8 | 2007 | const Standard_Integer /*theMode*/) |
329843e2 A |
2008 | { |
2009 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); | |
2010 | Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner, | |
2011 | myCircle, myFilledStatus); | |
2012 | theSelection->Add(aSensitiveCircle); | |
2013 | } | |
7fd59977 | 2014 | |
2015 | //============================================================================== | |
2016 | // Fonction vcircle | |
2017 | // ----------------- Uniquement par parametre. Pas de selection dans le viewer. | |
2018 | //============================================================================== | |
2019 | ||
2020 | //============================================================================== | |
2021 | //function : VCircleBuilder | |
161c4476 | 2022 | //purpose : Build an AIS_Circle |
329843e2 A |
2023 | //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled |
2024 | // PointName PointName PointName IsFilled | |
7fd59977 | 2025 | //============================================================================== |
329843e2 A |
2026 | |
2027 | void DisplayCircle (Handle (Geom_Circle) theGeomCircle, | |
2028 | TCollection_AsciiString theName, | |
2029 | Standard_Boolean isFilled) | |
2030 | { | |
2031 | Handle(AIS_InteractiveObject) aCircle; | |
2032 | if (isFilled) | |
2033 | { | |
2034 | aCircle = new FilledCircle(theGeomCircle); | |
2035 | } | |
2036 | else | |
2037 | { | |
2038 | aCircle = new AIS_Circle(theGeomCircle); | |
9e8804b6 | 2039 | Handle(AIS_Circle)::DownCast (aCircle)->SetFilledCircleSens (Standard_False); |
329843e2 A |
2040 | } |
2041 | ||
2042 | // Check if there is an object with given name | |
2043 | // and remove it from context | |
2044 | if (GetMapOfAIS().IsBound2(theName)) | |
2045 | { | |
2046 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName); | |
2047 | Handle(AIS_InteractiveObject) anInterObj = | |
2048 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
2049 | TheAISContext()->Remove(anInterObj, Standard_False); | |
2050 | GetMapOfAIS().UnBind2(theName); | |
2051 | } | |
2052 | ||
2053 | // Bind the circle to its name | |
2054 | GetMapOfAIS().Bind(aCircle, theName); | |
2055 | ||
2056 | // Display the circle | |
2057 | TheAISContext()->Display(aCircle); | |
2058 | ||
2059 | } | |
7fd59977 | 2060 | |
35e08fe8 | 2061 | static int VCircleBuilder(Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
7fd59977 | 2062 | { |
2063 | Standard_Integer myCurrentIndex; | |
329843e2 A |
2064 | // Verification of the arguments |
2065 | if (argc>6 || argc<2) | |
2066 | { | |
2067 | std::cout << "vcircle error: expect 4 arguments.\n"; | |
2068 | return 1; // TCL_ERROR | |
2069 | } | |
7fd59977 | 2070 | TheAISContext()->CloseAllContexts(); |
2071 | ||
329843e2 A |
2072 | // There are all arguments |
2073 | if (argc == 6) | |
2074 | { | |
2075 | // Get arguments | |
2076 | TCollection_AsciiString aName(argv[1]); | |
91322f44 | 2077 | Standard_Boolean isFilled = (Standard_Boolean)Draw::Atoi(argv[5]); |
329843e2 | 2078 | |
7fd59977 | 2079 | Handle(AIS_InteractiveObject) theShapeA; |
2080 | Handle(AIS_InteractiveObject) theShapeB; | |
2081 | ||
329843e2 A |
2082 | theShapeA = |
2083 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2])); | |
2084 | theShapeB = | |
2085 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3])); | |
2086 | ||
7fd59977 | 2087 | |
2088 | // Arguments: AIS_Point AIS_Point AIS_Point | |
2089 | // ======================================== | |
329843e2 | 2090 | if (!theShapeA.IsNull() && !theShapeB.IsNull() && |
7fd59977 | 2091 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) |
2092 | { | |
329843e2 A |
2093 | if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) |
2094 | { | |
2095 | std::cout << "vcircle error: 2d argument is unexpected to be a point.\n"; | |
2096 | return 1; // TCL_ERROR | |
7fd59977 | 2097 | } |
329843e2 | 2098 | // The third object must be a point |
7fd59977 | 2099 | Handle(AIS_InteractiveObject) theShapeC = |
329843e2 | 2100 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4])); |
7fd59977 | 2101 | if (theShapeC.IsNull() || |
329843e2 A |
2102 | theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) |
2103 | { | |
2104 | std::cout << "vcircle error: 3d argument is unexpected to be a point.\n"; | |
2105 | return 1; // TCL_ERROR | |
2106 | } | |
7fd59977 | 2107 | // tag |
329843e2 A |
2108 | // Verify that the three points are different |
2109 | Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA); | |
2110 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
2111 | Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC); | |
2112 | ||
2113 | Handle(Geom_Point) myGeomPointA = theAISPointA->Component(); | |
2114 | Handle(Geom_CartesianPoint) myCartPointA = | |
2115 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointA); | |
2116 | ||
2117 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2118 | Handle(Geom_CartesianPoint) myCartPointB = | |
2119 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
2120 | ||
2121 | Handle(Geom_Point) myGeomPointC = theAISPointC->Component(); | |
2122 | Handle(Geom_CartesianPoint) myCartPointC = | |
2123 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointC); | |
7fd59977 | 2124 | |
2125 | // Test A=B | |
91322f44 | 2126 | if (Abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() && |
2127 | Abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() && | |
2128 | Abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2129 | { |
2130 | std::cout << "vcircle error: Same points.\n"; | |
2131 | return 1; // TCL_ERROR | |
7fd59977 | 2132 | } |
2133 | // Test A=C | |
91322f44 | 2134 | if (Abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() && |
2135 | Abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2136 | Abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2137 | { |
2138 | std::cout << "vcircle error: Same points.\n"; | |
2139 | return 1; // TCL_ERROR | |
7fd59977 | 2140 | } |
2141 | // Test B=C | |
91322f44 | 2142 | if (Abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() && |
2143 | Abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
2144 | Abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
329843e2 A |
2145 | { |
2146 | std::cout << "vcircle error: Same points.\n"; | |
2147 | return 1;// TCL_ERROR | |
7fd59977 | 2148 | } |
329843e2 A |
2149 | // Construction of the circle |
2150 | GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(), | |
2151 | myCartPointB->Pnt(), myCartPointC->Pnt() ); | |
2152 | Handle (Geom_Circle) theGeomCircle; | |
2153 | try | |
2154 | { | |
2155 | theGeomCircle = Cir.Value(); | |
2156 | } | |
2157 | catch (StdFail_NotDone) | |
2158 | { | |
2159 | std::cout << "vcircle error: can't create circle\n"; | |
2160 | return -1; // TCL_ERROR | |
2161 | } | |
2162 | ||
2163 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 2164 | } |
2165 | ||
329843e2 | 2166 | // Arguments: AIS_Plane AIS_Point Real |
7fd59977 | 2167 | // =================================== |
329843e2 A |
2168 | else if (theShapeA->Type() == AIS_KOI_Datum && |
2169 | theShapeA->Signature() == 7 ) | |
2170 | { | |
2171 | if (theShapeB->Type() != AIS_KOI_Datum || | |
2172 | theShapeB->Signature() != 1 ) | |
2173 | { | |
2174 | std::cout << "vcircle error: 2d element is a unexpected to be a point.\n"; | |
2175 | return 1; // TCL_ERROR | |
2176 | } | |
623c29a5 | 2177 | // Check that the radius is >= 0 |
91322f44 | 2178 | if (Draw::Atof(argv[4]) <= 0 ) |
329843e2 A |
2179 | { |
2180 | std::cout << "vcircle error: the radius must be >=0.\n"; | |
2181 | return 1; // TCL_ERROR | |
7fd59977 | 2182 | } |
7fd59977 | 2183 | |
329843e2 A |
2184 | // Recover the normal to the plane |
2185 | Handle(AIS_Plane) theAISPlane = Handle(AIS_Plane)::DownCast(theShapeA); | |
2186 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
7fd59977 | 2187 | |
329843e2 A |
2188 | Handle(Geom_Plane) myGeomPlane = theAISPlane->Component(); |
2189 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
2190 | Handle(Geom_CartesianPoint) myCartPointB = | |
2191 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
7fd59977 | 2192 | |
2193 | gp_Pln mygpPlane = myGeomPlane->Pln(); | |
2194 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2195 | gp_Dir theDir = thegpAxe.Direction(); | |
329843e2 | 2196 | gp_Pnt theCenter = myCartPointB->Pnt(); |
91322f44 | 2197 | Standard_Real TheR = Draw::Atof(argv[4]); |
329843e2 A |
2198 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,TheR); |
2199 | Handle (Geom_Circle) theGeomCircle; | |
2200 | try | |
2201 | { | |
2202 | theGeomCircle = Cir.Value(); | |
2203 | } | |
2204 | catch (StdFail_NotDone) | |
2205 | { | |
2206 | std::cout << "vcircle error: can't create circle\n"; | |
2207 | return -1; // TCL_ERROR | |
2208 | } | |
2209 | ||
2210 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 2211 | |
2212 | } | |
2213 | ||
2214 | // Error | |
329843e2 A |
2215 | else |
2216 | { | |
2217 | std::cout << "vcircle error: 1st argument is a unexpected type.\n"; | |
2218 | return 1; // TCL_ERROR | |
7fd59977 | 2219 | } |
2220 | ||
2221 | } | |
329843e2 | 2222 | // No arguments: selection in the viewer |
7fd59977 | 2223 | // ========================================= |
329843e2 A |
2224 | else |
2225 | { | |
2226 | // Get the name of the circle | |
2227 | TCollection_AsciiString aName(argv[1]); | |
7fd59977 | 2228 | |
2229 | TheAISContext()->OpenLocalContext(); | |
329843e2 | 2230 | myCurrentIndex = TheAISContext()->IndexOfCurrentLocal(); |
7fd59977 | 2231 | |
329843e2 | 2232 | // Activate selection mode for vertices and faces |
7fd59977 | 2233 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
2234 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
ceae62f0 | 2235 | std::cout << " Select a vertex or a face\n"; |
7fd59977 | 2236 | |
329843e2 | 2237 | // Wait for picking |
7fd59977 | 2238 | Standard_Integer argcc = 5; |
2239 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2240 | const char **argvv = (const char **) buff; | |
2241 | while (ViewerMainLoop( argcc, argvv) ) { } | |
329843e2 | 2242 | // end of the loop |
7fd59977 | 2243 | |
2244 | TopoDS_Shape ShapeA; | |
329843e2 A |
2245 | for(TheAISContext()->InitSelected(); |
2246 | TheAISContext()->MoreSelected(); | |
2247 | TheAISContext()->NextSelected() ) | |
2248 | { | |
7fd59977 | 2249 | ShapeA = TheAISContext()->SelectedShape(); |
2250 | } | |
2251 | ||
329843e2 A |
2252 | // ShapeA is a Vertex |
2253 | if (ShapeA.ShapeType() == TopAbs_VERTEX ) | |
2254 | { | |
7fd59977 | 2255 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
ceae62f0 | 2256 | std::cout << " Select a different vertex\n"; |
7fd59977 | 2257 | |
2258 | TopoDS_Shape ShapeB; | |
329843e2 A |
2259 | do |
2260 | { | |
2261 | // Wait for picking | |
7fd59977 | 2262 | Standard_Integer argccc = 5; |
2263 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2264 | const char **argvvv = (const char **) bufff; | |
2265 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
329843e2 | 2266 | // end of the loop |
7fd59977 | 2267 | |
329843e2 A |
2268 | for(TheAISContext()->InitSelected(); |
2269 | TheAISContext()->MoreSelected(); | |
2270 | TheAISContext()->NextSelected() ) | |
2271 | { | |
7fd59977 | 2272 | ShapeB = TheAISContext()->SelectedShape(); |
2273 | } | |
7fd59977 | 2274 | } while(ShapeB.IsSame(ShapeA) ); |
2275 | ||
329843e2 | 2276 | // Selection of ShapeC |
ceae62f0 | 2277 | std::cout << " Select the last vertex\n"; |
7fd59977 | 2278 | TopoDS_Shape ShapeC; |
329843e2 A |
2279 | do |
2280 | { | |
2281 | // Wait for picking | |
7fd59977 | 2282 | Standard_Integer argcccc = 5; |
2283 | const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2284 | const char **argvvvv = (const char **) buffff; | |
2285 | while (ViewerMainLoop( argcccc, argvvvv) ) { } | |
329843e2 | 2286 | // end of the loop |
7fd59977 | 2287 | |
329843e2 A |
2288 | for(TheAISContext()->InitSelected(); |
2289 | TheAISContext()->MoreSelected(); | |
2290 | TheAISContext()->NextSelected() ) | |
2291 | { | |
7fd59977 | 2292 | ShapeC = TheAISContext()->SelectedShape(); |
2293 | } | |
7fd59977 | 2294 | } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) ); |
329843e2 A |
2295 | |
2296 | // Get isFilled | |
2297 | Standard_Boolean isFilled; | |
2298 | std::cout << "Enter filled status (0 or 1)\n"; | |
2299 | cin >> isFilled; | |
7fd59977 | 2300 | |
329843e2 | 2301 | // Close the local context |
7fd59977 | 2302 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
2303 | ||
329843e2 A |
2304 | // Construction of the circle |
2305 | gp_Pnt A = BRep_Tool::Pnt(TopoDS::Vertex(ShapeA)); | |
2306 | gp_Pnt B = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); | |
2307 | gp_Pnt C = BRep_Tool::Pnt(TopoDS::Vertex(ShapeC)); | |
2308 | ||
2309 | GC_MakeCircle Cir = GC_MakeCircle (A, B, C); | |
2310 | Handle (Geom_Circle) theGeomCircle; | |
2311 | try | |
2312 | { | |
2313 | theGeomCircle = Cir.Value(); | |
2314 | } | |
2315 | catch (StdFail_NotDone) | |
2316 | { | |
2317 | std::cout << "vcircle error: can't create circle\n"; | |
2318 | return -1; // TCL_ERROR | |
2319 | } | |
7fd59977 | 2320 | |
329843e2 | 2321 | DisplayCircle(theGeomCircle, aName, isFilled); |
7fd59977 | 2322 | |
2323 | } | |
329843e2 | 2324 | // Shape is a face |
ceae62f0 | 2325 | else |
329843e2 | 2326 | { |
ceae62f0 | 2327 | std::cout << " Select a vertex (in your face)\n"; |
7fd59977 | 2328 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); |
2329 | ||
2330 | TopoDS_Shape ShapeB; | |
329843e2 | 2331 | // Wait for picking |
7fd59977 | 2332 | Standard_Integer argccc = 5; |
2333 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
2334 | const char **argvvv = (const char **) bufff; | |
2335 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
329843e2 | 2336 | // end of the loop |
7fd59977 | 2337 | |
329843e2 A |
2338 | for(TheAISContext()->InitSelected(); |
2339 | TheAISContext()->MoreSelected(); | |
2340 | TheAISContext()->NextSelected() ) | |
2341 | { | |
7fd59977 | 2342 | ShapeB = TheAISContext()->SelectedShape(); |
2343 | } | |
2344 | ||
329843e2 A |
2345 | // Recover the radius |
2346 | Standard_Real theRad; | |
2347 | do | |
2348 | { | |
2349 | std::cout << " Enter the value of the radius:\n"; | |
2350 | cin >> theRad; | |
2351 | } while (theRad <= 0); | |
2352 | ||
2353 | // Get filled status | |
2354 | Standard_Boolean isFilled; | |
2355 | std::cout << "Enter filled status (0 or 1)\n"; | |
2356 | cin >> isFilled; | |
7fd59977 | 2357 | |
329843e2 | 2358 | // Close the local context |
7fd59977 | 2359 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
329843e2 | 2360 | // Construction of the circle |
7fd59977 | 2361 | |
329843e2 A |
2362 | // Recover the normal to the plane. tag |
2363 | TopoDS_Face myFace = TopoDS::Face(ShapeA); | |
2364 | BRepAdaptor_Surface mySurface (myFace, Standard_False); | |
2365 | gp_Pln myPlane = mySurface.Plane(); | |
2366 | Handle(Geom_Plane) theGeomPlane = new Geom_Plane (myPlane); | |
7fd59977 | 2367 | gp_Pln mygpPlane = theGeomPlane->Pln(); |
2368 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
2369 | gp_Dir theDir = thegpAxe.Direction(); | |
2370 | ||
329843e2 A |
2371 | // Recover the center |
2372 | gp_Pnt theCenter = BRep_Tool::Pnt(TopoDS::Vertex(ShapeB)); | |
7fd59977 | 2373 | |
623c29a5 | 2374 | // Construct the circle |
329843e2 A |
2375 | GC_MakeCircle Cir = GC_MakeCircle (theCenter, theDir ,theRad); |
2376 | Handle (Geom_Circle) theGeomCircle; | |
2377 | try | |
2378 | { | |
2379 | theGeomCircle = Cir.Value(); | |
2380 | } | |
2381 | catch (StdFail_NotDone) | |
2382 | { | |
2383 | std::cout << "vcircle error: can't create circle\n"; | |
2384 | return -1; // TCL_ERROR | |
2385 | } | |
7fd59977 | 2386 | |
329843e2 A |
2387 | DisplayCircle(theGeomCircle, aName, isFilled); |
2388 | ||
7fd59977 | 2389 | } |
2390 | ||
7fd59977 | 2391 | } |
2392 | ||
2393 | return 0; | |
2394 | } | |
2395 | ||
ceae62f0 | 2396 | |
7fd59977 | 2397 | //=============================================================================================== |
2398 | //function : VDrawText | |
2399 | //author : psn | |
2400 | //purpose : Create a text. | |
2401 | //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable] | |
2402 | //=============================================================================================== | |
2403 | #include <Graphic3d_Group.hxx> | |
2404 | #include <Graphic3d_Structure.hxx> | |
7fd59977 | 2405 | #include <Graphic3d_AspectText3d.hxx> |
161c4476 | 2406 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 2407 | #include <Graphic3d_StructureManager.hxx> |
2408 | #include <Graphic3d_VerticalTextAlignment.hxx> | |
2409 | #include <Graphic3d_HorizontalTextAlignment.hxx> | |
2410 | ||
aff395a3 | 2411 | #include <Font_NameOfFont.hxx> |
2412 | ||
7fd59977 | 2413 | #include <Visual3d_ViewManager.hxx> |
7fd59977 | 2414 | |
2415 | #include <Standard_DefineHandle.hxx> | |
2416 | ||
7fd59977 | 2417 | #include <Prs3d_Root.hxx> |
2418 | #include <Prs3d_Text.hxx> | |
2419 | #include <Prs3d_TextAspect.hxx> | |
7fd59977 | 2420 | #include <Prs3d_ShadingAspect.hxx> |
2421 | #include <PrsMgr_PresentationManager3d.hxx> | |
2422 | ||
2423 | #include <TCollection_ExtendedString.hxx> | |
2424 | #include <TCollection_AsciiString.hxx> | |
2425 | ||
2426 | #include <gp_Pnt.hxx> | |
2427 | #include <Quantity_NameOfColor.hxx> | |
161c4476 | 2428 | #include <Quantity_Color.hxx> |
7fd59977 | 2429 | |
2430 | ||
2431 | DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject) | |
2432 | ||
13a22457 S |
2433 | class MyTextClass:public AIS_InteractiveObject |
2434 | { | |
7fd59977 | 2435 | public: |
2436 | // CASCADE RTTI | |
2437 | DEFINE_STANDARD_RTTI(MyTextClass ); | |
2438 | ||
2439 | MyTextClass(){}; | |
2440 | ||
161c4476 | 2441 | MyTextClass |
7fd59977 | 2442 | ( |
2443 | const TCollection_ExtendedString& , const gp_Pnt& , | |
161c4476 K |
2444 | Quantity_Color color, |
2445 | Standard_Integer aHJust, | |
7fd59977 | 2446 | Standard_Integer aVJust , |
161c4476 K |
2447 | Standard_Real Angle , |
2448 | Standard_Boolean Zoom , | |
2449 | Standard_Real Height, | |
eeaaaefb | 2450 | Font_FontAspect FontAspect, |
7fd59977 | 2451 | Standard_CString Font |
2452 | ); | |
2453 | ||
2454 | private: | |
2455 | ||
2456 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
2457 | const Handle(Prs3d_Presentation)& aPresentation, | |
2458 | const Standard_Integer aMode); | |
2459 | ||
35e08fe8 | 2460 | void ComputeSelection ( const Handle(SelectMgr_Selection)& /*aSelection*/, |
2461 | const Standard_Integer /*aMode*/){} ; | |
7fd59977 | 2462 | |
2463 | protected: | |
2464 | TCollection_ExtendedString aText; | |
2465 | gp_Pnt aPosition; | |
2466 | Standard_Real Red; | |
2467 | Standard_Real Green; | |
2468 | Standard_Real Blue; | |
2469 | Standard_Real aAngle; | |
161c4476 | 2470 | Standard_Real aHeight; |
7fd59977 | 2471 | Standard_Boolean aZoomable; |
2472 | Quantity_Color aColor; | |
eb4320f2 | 2473 | TCollection_AsciiString aFont; |
eeaaaefb | 2474 | Font_FontAspect aFontAspect; |
7fd59977 | 2475 | Graphic3d_HorizontalTextAlignment aHJustification; |
2476 | Graphic3d_VerticalTextAlignment aVJustification; | |
2477 | }; | |
2478 | ||
2479 | ||
2480 | ||
2481 | IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject) | |
161c4476 | 2482 | IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject) |
7fd59977 | 2483 | |
2484 | ||
161c4476 K |
2485 | MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position, |
2486 | Quantity_Color color = Quantity_NOC_YELLOW, | |
2487 | Standard_Integer aHJust = Graphic3d_HTA_LEFT, | |
7fd59977 | 2488 | Standard_Integer aVJust = Graphic3d_VTA_BOTTOM, |
2489 | Standard_Real angle = 0.0 , | |
2490 | Standard_Boolean zoomable = Standard_True, | |
2491 | Standard_Real height = 12., | |
eeaaaefb | 2492 | Font_FontAspect fontAspect = Font_FA_Regular, |
7fd59977 | 2493 | Standard_CString font = "Courier") |
2494 | { | |
2495 | aText = text; | |
161c4476 | 2496 | aPosition = position; |
7fd59977 | 2497 | aHJustification = Graphic3d_HorizontalTextAlignment(aHJust); |
2498 | aVJustification = Graphic3d_VerticalTextAlignment(aVJust); | |
2499 | aAngle = angle; | |
161c4476 K |
2500 | aZoomable = zoomable; |
2501 | aHeight = height; | |
7fd59977 | 2502 | aColor = color; |
2503 | aFontAspect = fontAspect; | |
2504 | aFont = font; | |
2505 | }; | |
2506 | ||
2507 | ||
2508 | ||
2509 | ////////////////////////////////////////////////////////////////////////////// | |
35e08fe8 | 2510 | void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
7fd59977 | 2511 | const Handle(Prs3d_Presentation)& aPresentation, |
35e08fe8 | 2512 | const Standard_Integer /*aMode*/) |
7fd59977 | 2513 | { |
2514 | ||
2515 | aPresentation->Clear(); | |
2516 | ||
857ffd5e | 2517 | Handle(Prs3d_TextAspect) asp = myDrawer->TextAspect(); |
7fd59977 | 2518 | |
eb4320f2 | 2519 | asp->SetFont(aFont.ToCString()); |
7fd59977 | 2520 | asp->SetColor(aColor); |
2521 | asp->SetHeight(aHeight); // I am changing the myHeight value | |
2522 | ||
2523 | asp->SetHorizontalJustification(aHJustification); | |
161c4476 | 2524 | asp->SetVerticalJustification(aVJustification); |
7fd59977 | 2525 | asp->Aspect()->SetTextZoomable(aZoomable); |
2526 | asp->Aspect()->SetTextAngle(aAngle); | |
2527 | asp->Aspect()->SetTextFontAspect(aFontAspect); | |
2528 | Prs3d_Text::Draw(aPresentation, asp, aText, aPosition); | |
161c4476 | 2529 | |
7fd59977 | 2530 | /* This comment code is worked |
2531 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation); | |
2532 | Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect(); | |
2533 | Graphic3d_Vertex vertices_text; | |
2534 | vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y()); | |
2535 | TheGroup->SetPrimitivesAspect(aspect); | |
7fd59977 | 2536 | TheGroup->Text(aText,vertices_text,aHeight,Standard_True); |
7fd59977 | 2537 | */ |
2538 | }; | |
2539 | ||
2540 | static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2541 | { | |
13a22457 S |
2542 | // Check arguments |
2543 | if (argc < 14) | |
7fd59977 | 2544 | { |
13a22457 S |
2545 | di<<"Error: "<<argv[0]<<" - invalid number of arguments\n"; |
2546 | di<<"Usage: type help "<<argv[0]<<"\n"; | |
2547 | return 1; //TCL_ERROR | |
7fd59977 | 2548 | } |
13a22457 S |
2549 | |
2550 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
2551 | ||
2552 | // Create 3D view if it doesn't exist | |
2553 | if ( aContext.IsNull() ) | |
161c4476 | 2554 | { |
13a22457 S |
2555 | ViewerTest::ViewerInit(); |
2556 | aContext = ViewerTest::GetAISContext(); | |
2557 | if( aContext.IsNull() ) | |
2558 | { | |
2559 | di << "Error: Cannot create a 3D view\n"; | |
2560 | return 1; //TCL_ERROR | |
2561 | } | |
7fd59977 | 2562 | } |
2563 | ||
13a22457 | 2564 | // Text position |
91322f44 | 2565 | const Standard_Real X = Draw::Atof(argv[2]); |
2566 | const Standard_Real Y = Draw::Atof(argv[3]); | |
2567 | const Standard_Real Z = Draw::Atof(argv[4]); | |
13a22457 | 2568 | const gp_Pnt pnt(X,Y,Z); |
7fd59977 | 2569 | |
13a22457 | 2570 | // Text color |
91322f44 | 2571 | const Quantity_Parameter R = Draw::Atof(argv[5])/255.; |
2572 | const Quantity_Parameter G = Draw::Atof(argv[6])/255.; | |
2573 | const Quantity_Parameter B = Draw::Atof(argv[7])/255.; | |
13a22457 | 2574 | const Quantity_Color aColor( R, G, B, Quantity_TOC_RGB ); |
7fd59977 | 2575 | |
13a22457 | 2576 | // Text alignment |
91322f44 | 2577 | const int hor_align = Draw::Atoi(argv[8]); |
2578 | const int ver_align = Draw::Atoi(argv[9]); | |
7fd59977 | 2579 | |
13a22457 | 2580 | // Text angle |
91322f44 | 2581 | const Standard_Real angle = Draw::Atof(argv[10]); |
7fd59977 | 2582 | |
13a22457 | 2583 | // Text zooming |
91322f44 | 2584 | const Standard_Boolean zoom = Draw::Atoi(argv[11]); |
13a22457 S |
2585 | |
2586 | // Text height | |
91322f44 | 2587 | const Standard_Real height = Draw::Atof(argv[12]); |
13a22457 S |
2588 | |
2589 | // Text aspect | |
91322f44 | 2590 | const Font_FontAspect aspect = Font_FontAspect(Draw::Atoi(argv[13])); |
13a22457 S |
2591 | |
2592 | // Text font | |
2593 | TCollection_AsciiString font; | |
2594 | if(argc < 15) | |
2595 | font.AssignCat("Courier"); | |
2596 | else | |
2597 | font.AssignCat(argv[14]); | |
2598 | ||
2599 | // Text is multibyte | |
91322f44 | 2600 | const Standard_Boolean isMultibyte = (argc < 16)? Standard_False : (Draw::Atoi(argv[15]) != 0); |
13a22457 S |
2601 | |
2602 | // Read text string | |
2603 | TCollection_ExtendedString name; | |
2604 | if (isMultibyte) | |
161c4476 | 2605 | { |
13a22457 | 2606 | const char *str = argv[1]; |
f3f08423 | 2607 | while ( *str || *(str+1)=='\x0A' || *(str+1)=='\x0B' || *(str+1)=='\x0C' || *(str+1)=='\x0D' |
2608 | || *(str+1)=='\x07' || *(str+1)=='\x08' || *(str+1)=='\x09' ) | |
13a22457 S |
2609 | { |
2610 | unsigned short c1 = *str++; | |
2611 | unsigned short c2 = *str++; | |
f3f08423 | 2612 | if (!c2) break; |
13a22457 S |
2613 | name += (Standard_ExtCharacter)((c1 << 8) | c2); |
2614 | } | |
7fd59977 | 2615 | } |
13a22457 S |
2616 | else |
2617 | { | |
2618 | name += argv[1]; | |
2619 | } | |
2620 | ||
2621 | if (name.Length()) | |
2622 | { | |
2623 | Handle(MyTextClass) myT = new MyTextClass(name,pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString()); | |
2624 | aContext->Display(myT,Standard_True); | |
2625 | } | |
2626 | ||
161c4476 | 2627 | return 0; |
7fd59977 | 2628 | } |
2629 | ||
2630 | #include <math.h> | |
2631 | #include <gp_Pnt.hxx> | |
2632 | #include <Graphic3d_ArrayOfPoints.hxx> | |
2633 | #include <Graphic3d_ArrayOfPrimitives.hxx> | |
7fd59977 | 2634 | #include <Graphic3d_ArrayOfTriangles.hxx> |
2635 | #include <Poly_Array1OfTriangle.hxx> | |
2636 | #include <Poly_Triangle.hxx> | |
2637 | #include <Poly_Triangulation.hxx> | |
2638 | #include <TColgp_Array1OfPnt.hxx> | |
2639 | #include <TShort_Array1OfShortReal.hxx> | |
2640 | #include <TShort_HArray1OfShortReal.hxx> | |
2641 | ||
2642 | #include <AIS_Triangulation.hxx> | |
7fd59977 | 2643 | #include <StdPrs_ToolShadedShape.hxx> |
2644 | #include <Poly_Connect.hxx> | |
2645 | #include <TColgp_Array1OfDir.hxx> | |
2646 | #include <Graphic3d_GraphicDriver.hxx> | |
2647 | ||
7fd59977 | 2648 | #include <TColStd_Array1OfInteger.hxx> |
2649 | #include <TColStd_HArray1OfInteger.hxx> | |
2650 | #include <Prs3d_ShadingAspect.hxx> | |
2651 | #include <Graphic3d_MaterialAspect.hxx> | |
2652 | #include <Graphic3d_AspectFillArea3d.hxx> | |
2653 | ||
2654 | #include <BRepPrimAPI_MakeCylinder.hxx> | |
2655 | #include <TopoDS_Shape.hxx> | |
2656 | #include <TopExp_Explorer.hxx> | |
2657 | #include <TopAbs.hxx> | |
2658 | #include <StdSelect_ShapeTypeFilter.hxx> | |
2659 | ||
2660 | ||
2661 | //=============================================================================================== | |
2662 | //function : CalculationOfSphere | |
2663 | //author : psn | |
2664 | //purpose : Create a Sphere | |
2665 | //=============================================================================================== | |
2666 | ||
161c4476 | 2667 | Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z , |
7fd59977 | 2668 | int res , |
2669 | double Radius ){ | |
2670 | double mRadius = Radius; | |
2671 | double mCenter[3] = {X,Y,Z}; | |
2672 | int mThetaResolution; | |
2673 | int mPhiResolution; | |
2674 | double mStartTheta = 0;//StartTheta; | |
2675 | double mEndTheta = 360;//EndTheta; | |
2676 | double mStartPhi = 0;//StartPhi; | |
2677 | double mEndPhi = 180;//EndPhi; | |
2678 | res = res < 4 ? 4 : res; | |
2679 | ||
2680 | mThetaResolution = res; | |
2681 | mPhiResolution = res; | |
2682 | ||
2683 | int i, j; | |
2684 | int jStart, jEnd, numOffset; | |
7fd59977 | 2685 | double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius; |
2686 | double startTheta, endTheta, startPhi, endPhi; | |
2687 | int base, numPoles=0, thetaResolution, phiResolution; | |
2688 | ||
2689 | int pts[3]; | |
2690 | int piece = -1; | |
2691 | int numPieces = 1; | |
2692 | if ( numPieces > mThetaResolution ) { | |
2693 | numPieces = mThetaResolution; | |
2694 | } | |
2695 | ||
2696 | int localThetaResolution = mThetaResolution; | |
2697 | double localStartTheta = mStartTheta; | |
2698 | double localEndTheta = mEndTheta; | |
2699 | ||
2700 | while ( localEndTheta < localStartTheta ) { | |
2701 | localEndTheta += 360.0; | |
2702 | } | |
2703 | ||
2704 | deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution; | |
2705 | ||
2706 | // Change the ivars based on pieces. | |
2707 | int start, end; | |
2708 | start = piece * localThetaResolution / numPieces; | |
2709 | end = (piece+1) * localThetaResolution / numPieces; | |
2710 | localEndTheta = localStartTheta + (double)(end) * deltaTheta; | |
2711 | localStartTheta = localStartTheta + (double)(start) * deltaTheta; | |
2712 | localThetaResolution = end - start; | |
2713 | ||
7fd59977 | 2714 | // Create north pole if needed |
2715 | int number_point = 0; | |
2716 | int number_pointArray = 0; | |
2717 | ||
2718 | if ( mStartPhi <= 0.0 ) { | |
2719 | number_pointArray++; | |
2720 | numPoles++; | |
2721 | } | |
2722 | if ( mEndPhi >= 180.0 ) { | |
2723 | number_pointArray++; | |
2724 | numPoles++; | |
2725 | } | |
161c4476 | 2726 | |
7fd59977 | 2727 | // Check data, determine increments, and convert to radians |
2728 | startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta); | |
c6541a0c | 2729 | startTheta *= M_PI / 180.0; |
7fd59977 | 2730 | endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta); |
c6541a0c | 2731 | endTheta *= M_PI / 180.0; |
7fd59977 | 2732 | |
2733 | ||
2734 | startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi); | |
c6541a0c | 2735 | startPhi *= M_PI / 180.0; |
7fd59977 | 2736 | endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi); |
c6541a0c | 2737 | endPhi *= M_PI / 180.0; |
7fd59977 | 2738 | |
2739 | phiResolution = mPhiResolution - numPoles; | |
2740 | deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1); | |
2741 | thetaResolution = localThetaResolution; | |
2742 | if ( fabs(localStartTheta - localEndTheta) < 360.0 ) { | |
2743 | ++localThetaResolution; | |
2744 | } | |
2745 | deltaTheta = (endTheta - startTheta) / thetaResolution; | |
2746 | ||
2747 | jStart = ( mStartPhi <= 0.0 ? 1 : 0); | |
2748 | jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution); | |
2749 | ||
2750 | // Create intermediate points | |
2751 | for ( i = 0; i < localThetaResolution; i++ ) { | |
2752 | for ( j = jStart; j < jEnd; j++ ) { | |
2753 | number_pointArray++; | |
2754 | } | |
2755 | } | |
2756 | ||
2757 | //Generate mesh connectivity | |
2758 | base = phiResolution * localThetaResolution; | |
2759 | ||
2760 | int number_triangle = 0 ; | |
2761 | if ( mStartPhi <= 0.0 ) { // around north pole | |
2762 | number_triangle += localThetaResolution; | |
2763 | } | |
161c4476 | 2764 | |
7fd59977 | 2765 | if ( mEndPhi >= 180.0 ) { // around south pole |
2766 | number_triangle += localThetaResolution; | |
2767 | } | |
2768 | ||
2769 | // bands in-between poles | |
2770 | for ( i=0; i < localThetaResolution; i++){ | |
2771 | for ( j=0; j < (phiResolution-1); j++){ | |
2772 | number_triangle +=2; | |
2773 | } | |
2774 | } | |
2775 | ||
2776 | Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false); | |
2777 | TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes(); | |
2778 | Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles(); | |
2779 | ||
2780 | if ( mStartPhi <= 0.0 ){ | |
2781 | x[0] = mCenter[0]; | |
2782 | x[1] = mCenter[1]; | |
2783 | x[2] = mCenter[2] + mRadius; | |
2784 | PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2])); | |
2785 | } | |
2786 | ||
2787 | // Create south pole if needed | |
2788 | if ( mEndPhi >= 180.0 ){ | |
2789 | x[0] = mCenter[0]; | |
2790 | x[1] = mCenter[1]; | |
2791 | x[2] = mCenter[2] - mRadius; | |
2792 | PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2])); | |
2793 | } | |
2794 | ||
2795 | number_point = 3; | |
2796 | for ( i=0; i < localThetaResolution; i++){ | |
c6541a0c | 2797 | theta = localStartTheta * M_PI / 180.0 + i*deltaTheta; |
7fd59977 | 2798 | for ( j = jStart; j < jEnd; j++){ |
2799 | phi = startPhi + j*deltaPhi; | |
2800 | radius = mRadius * sin((double)phi); | |
2801 | n[0] = radius * cos((double)theta); | |
2802 | n[1] = radius * sin((double)theta); | |
2803 | n[2] = mRadius * cos((double)phi); | |
2804 | x[0] = n[0] + mCenter[0]; | |
2805 | x[1] = n[1] + mCenter[1]; | |
2806 | x[2] = n[2] + mCenter[2]; | |
2807 | PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2])); | |
2808 | number_point++; | |
2809 | } | |
2810 | } | |
2811 | ||
2812 | numPoles = 3; | |
2813 | number_triangle = 1; | |
2814 | if ( mStartPhi <= 0.0 ){// around north pole | |
2815 | for (i=0; i < localThetaResolution; i++){ | |
2816 | pts[0] = phiResolution*i + numPoles; | |
2817 | pts[1] = (phiResolution*(i+1) % base) + numPoles; | |
2818 | pts[2] = 1; | |
2819 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2820 | number_triangle++; | |
2821 | } | |
2822 | } | |
161c4476 | 2823 | |
7fd59977 | 2824 | if ( mEndPhi >= 180.0 ){ // around south pole |
2825 | numOffset = phiResolution - 1 + numPoles; | |
2826 | for (i=0; i < localThetaResolution; i++){ | |
2827 | pts[0] = phiResolution*i + numOffset; | |
2828 | pts[2] = ((phiResolution*(i+1)) % base) + numOffset; | |
2829 | pts[1] = numPoles - 1; | |
2830 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2831 | number_triangle++; | |
2832 | } | |
2833 | } | |
2834 | ||
2835 | // bands in-between poles | |
161c4476 | 2836 | |
7fd59977 | 2837 | for (i=0; i < localThetaResolution; i++){ |
2838 | for (j=0; j < (phiResolution-1); j++){ | |
2839 | pts[0] = phiResolution*i + j + numPoles; | |
2840 | pts[1] = pts[0] + 1; | |
2841 | pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1; | |
2842 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2843 | number_triangle++; | |
2844 | pts[1] = pts[2]; | |
2845 | pts[2] = pts[1] - 1; | |
2846 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2847 | number_triangle++; | |
2848 | } | |
2849 | } | |
2850 | ||
2851 | Poly_Connect* pc = new Poly_Connect(polyTriangulation); | |
2852 | ||
2853 | Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3); | |
2854 | ||
2855 | Standard_Integer index[3]; | |
2856 | Standard_Real Tol = Precision::Confusion(); | |
2857 | ||
2858 | gp_Dir Nor; | |
2859 | for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) { | |
2860 | gp_XYZ eqPlan(0, 0, 0); | |
2861 | for ( pc->Initialize(i); pc->More(); pc->Next()) { | |
2862 | pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]); | |
2863 | gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord()); | |
2864 | gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord()); | |
2865 | gp_XYZ vv = v1^v2; | |
2866 | Standard_Real mod = vv.Modulus(); | |
2867 | if(mod < Tol) continue; | |
2868 | eqPlan += vv/mod; | |
2869 | } | |
2870 | ||
2871 | Standard_Real modmax = eqPlan.Modulus(); | |
2872 | ||
161c4476 | 2873 | if(modmax > Tol) |
7fd59977 | 2874 | Nor = gp_Dir(eqPlan); |
161c4476 | 2875 | else |
7fd59977 | 2876 | Nor = gp_Dir(0., 0., 1.); |
2877 | ||
2878 | Standard_Integer j = (i - PointsOfArray.Lower()) * 3; | |
2879 | Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X()); | |
2880 | Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y()); | |
2881 | Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z()); | |
2882 | } | |
2883 | ||
2884 | delete pc; | |
2885 | polyTriangulation->SetNormals(Normals); | |
2886 | ||
2887 | return polyTriangulation; | |
2888 | } | |
2889 | ||
2890 | //=============================================================================================== | |
2891 | //function : VDrawSphere | |
2892 | //author : psn | |
2893 | //purpose : Create an AIS shape. | |
7fd59977 | 2894 | //=============================================================================================== |
35e08fe8 | 2895 | static int VDrawSphere (Draw_Interpretor& /*di*/, Standard_Integer argc, const char** argv) |
161c4476 K |
2896 | { |
2897 | // check for errors | |
2898 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
2899 | if (aContextAIS.IsNull()) | |
2900 | { | |
2901 | std::cout << "Call vinit before!\n"; | |
2902 | return 1; | |
2903 | } | |
2904 | else if (argc < 3) | |
2905 | { | |
2906 | std::cout << "Use: " << argv[0] | |
58655684 | 2907 | << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0]\n"; |
161c4476 K |
2908 | return 1; |
2909 | } | |
7fd59977 | 2910 | |
161c4476 K |
2911 | // read the arguments |
2912 | TCollection_AsciiString aShapeName (argv[1]); | |
91322f44 | 2913 | Standard_Integer aResolution = Draw::Atoi (argv[2]); |
2914 | Standard_Real aCenterX = (argc > 5) ? Draw::Atof (argv[3]) : 0.0; | |
2915 | Standard_Real aCenterY = (argc > 5) ? Draw::Atof (argv[4]) : 0.0; | |
2916 | Standard_Real aCenterZ = (argc > 5) ? Draw::Atof (argv[5]) : 0.0; | |
2917 | Standard_Real aRadius = (argc > 6) ? Draw::Atof (argv[6]) : 100.0; | |
b7cd4ba7 | 2918 | Standard_Boolean toShowEdges = (argc > 7) ? Draw::Atoi (argv[7]) == 1 : Standard_False; |
2919 | Standard_Boolean toPrintInfo = (argc > 8) ? Draw::Atoi (argv[8]) == 1 : Standard_True; | |
7fd59977 | 2920 | |
161c4476 | 2921 | // remove AIS object with given name from map |
208e6839 | 2922 | VDisplayAISObject (aShapeName, Handle(AIS_InteractiveObject)()); |
161c4476 | 2923 | |
b7cd4ba7 | 2924 | if (toPrintInfo) |
2925 | std::cout << "Compute Triangulation...\n"; | |
161c4476 K |
2926 | Handle(AIS_Triangulation) aShape |
2927 | = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ, | |
2928 | aResolution, | |
2929 | aRadius)); | |
2930 | Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); | |
2931 | Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); | |
2932 | ||
161c4476 K |
2933 | // stupid initialization of Green color in RGBA space as integer |
2934 | // probably wrong for big-endian CPUs | |
2935 | Standard_Integer aRed = 0; | |
2936 | Standard_Integer aGreen = 255; | |
2937 | Standard_Integer aBlue = 0; | |
2938 | Standard_Integer anAlpha = 0; // not used | |
2939 | Standard_Integer aColorInt = aRed; | |
2940 | aColorInt += aGreen << 8; | |
2941 | aColorInt += aBlue << 16; | |
2942 | aColorInt += anAlpha << 24; | |
2943 | ||
2944 | // setup colors array per vertex | |
2945 | Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints); | |
2946 | for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId) | |
2947 | { | |
2948 | aColorArray->SetValue (aNodeId, aColorInt); | |
7fd59977 | 2949 | } |
161c4476 K |
2950 | aShape->SetColors (aColorArray); |
2951 | ||
2952 | // show statistics | |
2953 | Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
2954 | Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
2955 | Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha | |
2956 | Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint | |
2957 | Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4; | |
2958 | Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize; | |
2959 | aTotalSize >>= 20; //MB | |
2960 | aNormalsSize >>= 20; | |
2961 | aColorsSize >>= 20; | |
2962 | aTrianglesSize >>= 20; | |
2963 | aPolyConnectSize >>= 20; | |
b7cd4ba7 | 2964 | if (toPrintInfo) |
2965 | { | |
2966 | std::cout << "NumberOfPoints: " << aNumberPoints << "\n" | |
2967 | << "NumberOfTriangles: " << aNumberTriangles << "\n" | |
2968 | << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n" | |
2969 | << "Amount of memory for colors: " << aColorsSize << " Mb\n" | |
2970 | << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n" | |
2971 | << "Amount of graphic card memory required: " << aTotalSize << " Mb\n"; | |
2972 | } | |
7fd59977 | 2973 | |
2974 | // Setting material properties, very important for desirable visual result! | |
161c4476 K |
2975 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC); |
2976 | aMat.SetAmbient (0.2); | |
2977 | aMat.SetSpecular (0.5); | |
2978 | Handle(Graphic3d_AspectFillArea3d) anAspect | |
2979 | = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, | |
2980 | Quantity_NOC_RED, | |
2981 | Quantity_NOC_YELLOW, | |
2982 | Aspect_TOL_SOLID, | |
2983 | 1.0, | |
2984 | aMat, | |
2985 | aMat); | |
7fd59977 | 2986 | Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect(); |
161c4476 K |
2987 | if (toShowEdges) |
2988 | { | |
2989 | anAspect->SetEdgeOn(); | |
2990 | } | |
7fd59977 | 2991 | else |
161c4476 K |
2992 | { |
2993 | anAspect->SetEdgeOff(); | |
2994 | } | |
2995 | aShAsp->SetAspect (anAspect); | |
2996 | aShape->Attributes()->SetShadingAspect (aShAsp); | |
7fd59977 | 2997 | |
208e6839 | 2998 | VDisplayAISObject (aShapeName, aShape); |
7fd59977 | 2999 | return 0; |
3000 | } | |
3001 | ||
3fc57801 | 3002 | //============================================================================= |
3003 | //function : VComputeHLR | |
3004 | //purpose : | |
3005 | //============================================================================= | |
3006 | ||
3007 | static int VComputeHLR (Draw_Interpretor& di, | |
3008 | Standard_Integer argc, | |
3009 | const char** argv) | |
3010 | { | |
3011 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext (); | |
3012 | ||
3013 | if (aContextAIS.IsNull ()) | |
3014 | { | |
3015 | di << "Please call vinit before\n"; | |
3016 | return 1; | |
3017 | } | |
3018 | ||
3019 | if ( argc != 3 && argc != 12 ) | |
3020 | { | |
3021 | di << "Usage: " << argv[0] << " ShapeName HlrName " | |
3022 | << "[ eye_x eye_y eye_z dir_x dir_y dir_z upx upy upz ]" << "\n" | |
3023 | << " ShapeName - name of the initial shape\n" | |
3024 | << " HlrName - result hlr object from initial shape\n" | |
3025 | << " eye, dir are eye position and look direction\n" | |
3026 | << " up is the look up direction vector\n" | |
3027 | << " Use vtop to see projected hlr shape\n"; | |
3028 | return 1; | |
3029 | } | |
3030 | ||
3031 | // shape and new object name | |
3032 | TCollection_AsciiString aShapeName (argv[1]); | |
3033 | TCollection_AsciiString aHlrName (argv[2]); | |
3034 | ||
3035 | TopoDS_Shape aSh = DBRep::Get (argv[1]); | |
3036 | if (aSh.IsNull()) | |
3037 | { | |
3038 | BRep_Builder aBrepBuilder; | |
3039 | BRepTools::Read (aSh, argv[1], aBrepBuilder); | |
3040 | if (aSh.IsNull ()) | |
3041 | { | |
3042 | di << "No shape with name " << argv[1] << " found\n"; | |
3043 | return 1; | |
3044 | } | |
3045 | } | |
3046 | ||
3047 | if (GetMapOfAIS ().IsBound2 (aHlrName)) | |
3048 | { | |
3049 | di << "Presentable object with name " << argv[2] << " already exists\n"; | |
3050 | return 1; | |
3051 | } | |
3052 | ||
3053 | // close local context | |
3054 | if (aContextAIS->HasOpenedContext ()) | |
3055 | aContextAIS->CloseLocalContext (); | |
3056 | ||
3057 | Handle(HLRBRep_PolyAlgo) aPolyAlgo = new HLRBRep_PolyAlgo(); | |
3058 | HLRBRep_PolyHLRToShape aHLRToShape; | |
3059 | ||
3060 | gp_Pnt anEye; | |
3061 | gp_Dir aDir; | |
3062 | gp_Ax2 aProjAx; | |
3063 | if (argc == 9) | |
3064 | { | |
3065 | gp_Dir anUp; | |
3066 | ||
91322f44 | 3067 | anEye.SetCoord (Draw::Atof (argv[3]), Draw::Atof (argv[4]), Draw::Atof (argv[5])); |
3068 | aDir.SetCoord (Draw::Atof (argv[6]), Draw::Atof (argv[7]), Draw::Atof (argv[8])); | |
3069 | anUp.SetCoord (Draw::Atof (argv[9]), Draw::Atof (argv[10]), Draw::Atof (argv[11])); | |
3fc57801 | 3070 | aProjAx.SetLocation (anEye); |
3071 | aProjAx.SetDirection (aDir); | |
3072 | aProjAx.SetYDirection (anUp); | |
3073 | } | |
3074 | else | |
3075 | { | |
3076 | gp_Dir aRight; | |
3077 | ||
3078 | Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext(); | |
3079 | Handle(V3d_View) aView = ViewerTest::CurrentView(); | |
3080 | Standard_Integer aWidth, aHeight; | |
3081 | Standard_Real aCentX, aCentY, aCentZ, aDirX, aDirY, aDirZ; | |
3082 | Standard_Real aRightX, aRightY, aRightZ; | |
3083 | aView->Window()->Size (aWidth, aHeight); | |
3084 | ||
3085 | aView->ConvertWithProj (aWidth, aHeight/2, | |
3086 | aRightX, aRightY, aRightZ, | |
3087 | aDirX, aDirY, aDirZ); | |
3088 | ||
3089 | aView->ConvertWithProj (aWidth/2, aHeight/2, | |
3090 | aCentX, aCentY, aCentZ, | |
3091 | aDirX, aDirY, aDirZ); | |
3092 | ||
3093 | anEye.SetCoord (-aCentX, -aCentY, -aCentZ); | |
3094 | aDir.SetCoord (-aDirX, -aDirY, -aDirZ); | |
3095 | aRight.SetCoord (aRightX - aCentX, aRightY - aCentY, aRightZ - aCentZ); | |
3096 | aProjAx.SetLocation (anEye); | |
3097 | aProjAx.SetDirection (aDir); | |
3098 | aProjAx.SetXDirection (aRight); | |
3099 | } | |
3100 | ||
3101 | HLRAlgo_Projector aProjector (aProjAx); | |
3102 | aPolyAlgo->Projector (aProjector); | |
3103 | aPolyAlgo->Load (aSh); | |
3104 | aPolyAlgo->Update (); | |
3105 | ||
3106 | aHLRToShape.Update (aPolyAlgo); | |
3107 | ||
3108 | // make hlr shape from input shape | |
3109 | TopoDS_Compound aHlrShape; | |
3110 | BRep_Builder aBuilder; | |
3111 | aBuilder.MakeCompound (aHlrShape); | |
3112 | ||
3113 | TopoDS_Shape aCompound = aHLRToShape.VCompound(); | |
3114 | if (!aCompound.IsNull ()) | |
3115 | { | |
3116 | aBuilder.Add (aHlrShape, aCompound); | |
3117 | } | |
3118 | ||
3119 | // extract visible outlines | |
3120 | aCompound = aHLRToShape.OutLineVCompound(); | |
3121 | if (!aCompound.IsNull ()) | |
3122 | { | |
3123 | aBuilder.Add (aHlrShape, aCompound); | |
3124 | } | |
3125 | ||
3126 | // create an AIS shape and display it | |
3127 | Handle(AIS_Shape) anObject = new AIS_Shape (aHlrShape); | |
3128 | GetMapOfAIS().Bind (anObject, aHlrName); | |
3129 | aContextAIS->Display (anObject); | |
3130 | ||
3131 | aContextAIS->UpdateCurrentViewer (); | |
3132 | ||
3133 | return 0; | |
3134 | } | |
3135 | ||
9558a876 A |
3136 | // This class is a wrap for Graphic3d_ArrayOfPrimitives; it is used for |
3137 | // manipulating and displaying such an array with AIS context | |
3138 | DEFINE_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject) | |
3139 | class MyPArrayObject : public AIS_InteractiveObject | |
3140 | { | |
3141 | ||
3142 | public: | |
3143 | ||
eb4320f2 | 3144 | MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDescription, |
a577aaab | 3145 | Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL) |
9558a876 | 3146 | { |
eb4320f2 | 3147 | myArrayDescription = theArrayDescription; |
a577aaab | 3148 | myMarkerAspect = theMarkerAspect; |
9558a876 A |
3149 | } |
3150 | ||
3151 | DEFINE_STANDARD_RTTI(MyPArrayObject); | |
3152 | ||
3153 | private: | |
3154 | ||
3155 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
3156 | const Handle(Prs3d_Presentation)& aPresentation, | |
3157 | const Standard_Integer aMode); | |
3158 | ||
a577aaab | 3159 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, |
3160 | const Standard_Integer /*theMode*/); | |
9558a876 | 3161 | |
eb4320f2 | 3162 | bool CheckInputCommand (const TCollection_AsciiString theCommand, |
3163 | const Handle(TColStd_HArray1OfAsciiString) theArgsArray, | |
3164 | Standard_Integer &theArgIndex, | |
3165 | Standard_Integer theArgCount, | |
3166 | Standard_Integer theMaxArgs); | |
3167 | ||
9558a876 A |
3168 | protected: |
3169 | ||
eb4320f2 | 3170 | Handle(TColStd_HArray1OfAsciiString) myArrayDescription; |
a577aaab | 3171 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; |
9558a876 A |
3172 | |
3173 | }; | |
3174 | ||
3175 | IMPLEMENT_STANDARD_HANDLE(MyPArrayObject, AIS_InteractiveObject) | |
3176 | IMPLEMENT_STANDARD_RTTIEXT(MyPArrayObject, AIS_InteractiveObject) | |
3177 | ||
35e08fe8 | 3178 | void MyPArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, |
9558a876 | 3179 | const Handle(Prs3d_Presentation)& aPresentation, |
35e08fe8 | 3180 | const Standard_Integer /*aMode*/) |
9558a876 | 3181 | { |
9558a876 | 3182 | |
eb4320f2 | 3183 | // Parsing array description |
9558a876 | 3184 | Standard_Integer aVertexNum = 0, aBoundNum = 0, aEdgeNum = 0; |
871fa103 | 3185 | Standard_Boolean hasVColors, hasBColors, hasNormals, hasTexels; |
3186 | hasVColors = hasNormals = hasBColors = hasTexels = Standard_False; | |
9558a876 | 3187 | |
eb4320f2 | 3188 | Standard_Integer anArgIndex = 0; |
3189 | Standard_Integer anArgsCount = myArrayDescription->Length(); | |
3190 | TCollection_AsciiString anArrayType = myArrayDescription->Value (anArgIndex++); | |
3191 | ||
9558a876 | 3192 | TCollection_AsciiString aCommand; |
eb4320f2 | 3193 | while (anArgIndex < anArgsCount) |
9558a876 | 3194 | { |
eb4320f2 | 3195 | aCommand = myArrayDescription->Value (anArgIndex); |
9558a876 | 3196 | aCommand.LowerCase(); |
9558a876 A |
3197 | |
3198 | // vertex command | |
eb4320f2 | 3199 | if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3200 | { |
3201 | // vertex has a normal or normal with color or texel | |
eb4320f2 | 3202 | if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3203 | hasNormals = Standard_True; |
3204 | ||
3205 | // vertex has a color | |
eb4320f2 | 3206 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3207 | hasVColors = Standard_True; |
3208 | ||
3209 | // vertex has a texel | |
eb4320f2 | 3210 | if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount)) |
9558a876 A |
3211 | hasTexels = Standard_True; |
3212 | ||
3213 | aVertexNum++; | |
3214 | } | |
3215 | // bound command | |
eb4320f2 | 3216 | else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 A |
3217 | { |
3218 | // bound has color | |
eb4320f2 | 3219 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 A |
3220 | hasBColors = Standard_True; |
3221 | ||
3222 | aBoundNum++; | |
3223 | } | |
3224 | // edge command | |
eb4320f2 | 3225 | else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 | 3226 | { |
9558a876 A |
3227 | aEdgeNum++; |
3228 | } | |
3229 | // unknown command | |
3230 | else | |
eb4320f2 | 3231 | anArgIndex++; |
9558a876 A |
3232 | } |
3233 | ||
9558a876 A |
3234 | Handle(Graphic3d_ArrayOfPrimitives) anArray; |
3235 | if (anArrayType == "points") | |
a577aaab | 3236 | { |
9558a876 | 3237 | anArray = new Graphic3d_ArrayOfPoints (aVertexNum); |
a577aaab | 3238 | } |
9558a876 A |
3239 | else if (anArrayType == "segments") |
3240 | anArray = new Graphic3d_ArrayOfSegments (aVertexNum, aEdgeNum, hasVColors); | |
3241 | else if (anArrayType == "polylines") | |
3242 | anArray = new Graphic3d_ArrayOfPolylines (aVertexNum, aBoundNum, aEdgeNum, | |
871fa103 | 3243 | hasVColors, hasBColors); |
9558a876 A |
3244 | else if (anArrayType == "triangles") |
3245 | anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals, | |
871fa103 | 3246 | hasVColors, hasTexels); |
9558a876 A |
3247 | else if (anArrayType == "trianglefans") |
3248 | anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum, | |
3249 | hasNormals, hasVColors, | |
3250 | hasBColors, hasTexels); | |
3251 | else if (anArrayType == "trianglestrips") | |
3252 | anArray = new Graphic3d_ArrayOfTriangleStrips (aVertexNum, aBoundNum, | |
3253 | hasNormals, hasVColors, | |
3254 | hasBColors, hasTexels); | |
3255 | else if (anArrayType == "quads") | |
3256 | anArray = new Graphic3d_ArrayOfQuadrangles (aVertexNum, aEdgeNum, | |
3257 | hasNormals, hasVColors, | |
871fa103 | 3258 | hasTexels); |
9558a876 A |
3259 | else if (anArrayType == "quadstrips") |
3260 | anArray = new Graphic3d_ArrayOfQuadrangleStrips (aVertexNum, aBoundNum, | |
3261 | hasNormals, hasVColors, | |
3262 | hasBColors, hasTexels); | |
3263 | else if (anArrayType == "polygons") | |
3264 | anArray = new Graphic3d_ArrayOfPolygons (aVertexNum, aBoundNum, aEdgeNum, | |
3265 | hasNormals, hasVColors, hasBColors, | |
871fa103 | 3266 | hasTexels); |
9558a876 | 3267 | |
eb4320f2 | 3268 | anArgIndex = 1; |
3269 | while (anArgIndex < anArgsCount) | |
9558a876 | 3270 | { |
eb4320f2 | 3271 | aCommand = myArrayDescription->Value (anArgIndex); |
9558a876 A |
3272 | aCommand.LowerCase(); |
3273 | if (!aCommand.IsAscii()) | |
3274 | break; | |
3275 | ||
3276 | // vertex command | |
eb4320f2 | 3277 | if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 | 3278 | { |
eb4320f2 | 3279 | anArray->AddVertex (myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3280 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3281 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
871fa103 | 3282 | const Standard_Integer aVertIndex = anArray->VertexNumber(); |
9558a876 A |
3283 | |
3284 | // vertex has a normal or normal with color or texel | |
eb4320f2 | 3285 | if (CheckInputCommand ("n", myArrayDescription, anArgIndex, 3, anArgsCount)) |
871fa103 | 3286 | anArray->SetVertexNormal (aVertIndex, |
eb4320f2 | 3287 | myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3288 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3289 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 | 3290 | |
eb4320f2 | 3291 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
871fa103 | 3292 | anArray->SetVertexColor (aVertIndex, |
eb4320f2 | 3293 | myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3294 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3295 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 | 3296 | |
eb4320f2 | 3297 | if (CheckInputCommand ("t", myArrayDescription, anArgIndex, 2, anArgsCount)) |
871fa103 | 3298 | anArray->SetVertexTexel (aVertIndex, |
eb4320f2 | 3299 | myArrayDescription->Value (anArgIndex - 2).RealValue(), |
3300 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 A |
3301 | } |
3302 | // bounds command | |
eb4320f2 | 3303 | else if (CheckInputCommand ("b", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 | 3304 | { |
eb4320f2 | 3305 | Standard_Integer aVertCount = myArrayDescription->Value (anArgIndex - 1).IntegerValue(); |
9558a876 | 3306 | |
eb4320f2 | 3307 | if (CheckInputCommand ("c", myArrayDescription, anArgIndex, 3, anArgsCount)) |
9558a876 | 3308 | anArray->AddBound (aVertCount, |
eb4320f2 | 3309 | myArrayDescription->Value (anArgIndex - 3).RealValue(), |
3310 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3311 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
9558a876 A |
3312 | |
3313 | else | |
3314 | anArray->AddBound (aVertCount); | |
3315 | } | |
3316 | // edge command | |
eb4320f2 | 3317 | else if (CheckInputCommand ("e", myArrayDescription, anArgIndex, 1, anArgsCount)) |
9558a876 | 3318 | { |
871fa103 | 3319 | const Standard_Integer aVertIndex = myArrayDescription->Value (anArgIndex - 1).IntegerValue(); |
3320 | anArray->AddEdge (aVertIndex); | |
9558a876 A |
3321 | } |
3322 | // unknown command | |
3323 | else | |
eb4320f2 | 3324 | anArgIndex++; |
3325 | } | |
3326 | ||
3327 | aPresentation->Clear(); | |
3328 | if (!myMarkerAspect.IsNull()) | |
3329 | { | |
3330 | Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect); | |
3331 | } | |
3332 | Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray); | |
3333 | } | |
3334 | ||
3335 | void MyPArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
3336 | const Standard_Integer /*theMode*/) | |
3337 | { | |
3338 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this); | |
3339 | ||
3340 | Standard_Integer anArgIndex = 1; | |
3341 | while (anArgIndex < myArrayDescription->Length()) | |
3342 | { | |
3343 | if (CheckInputCommand ("v", myArrayDescription, anArgIndex, 3, myArrayDescription->Length())) | |
3344 | { | |
3345 | gp_Pnt aPoint (myArrayDescription->Value (anArgIndex - 3).RealValue(), | |
3346 | myArrayDescription->Value (anArgIndex - 2).RealValue(), | |
3347 | myArrayDescription->Value (anArgIndex - 1).RealValue()); | |
3348 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
3349 | theSelection->Add (aSensetivePoint); | |
3350 | } | |
3351 | else | |
3352 | { | |
3353 | anArgIndex++; | |
3354 | } | |
3355 | } | |
3356 | } | |
3357 | ||
3358 | bool MyPArrayObject::CheckInputCommand (const TCollection_AsciiString theCommand, | |
3359 | const Handle(TColStd_HArray1OfAsciiString) theArgsArray, | |
3360 | Standard_Integer &theArgIndex, | |
3361 | Standard_Integer theArgCount, | |
3362 | Standard_Integer theMaxArgs) | |
3363 | { | |
3364 | // check if there is more elements than expected | |
3365 | if (theArgIndex >= theMaxArgs) | |
3366 | return false; | |
3367 | ||
3368 | TCollection_AsciiString aStrCommand = theArgsArray->Value (theArgIndex); | |
3369 | aStrCommand.LowerCase(); | |
3370 | if (aStrCommand.Search(theCommand) != 1 || | |
3371 | theArgIndex + (theArgCount - 1) >= theMaxArgs) | |
3372 | return false; | |
3373 | ||
3374 | // go to the first data element | |
3375 | theArgIndex++; | |
3376 | ||
3377 | // check data if it can be converted to numeric | |
3378 | for (int aElement = 0; aElement < theArgCount; aElement++, theArgIndex++) | |
3379 | { | |
3380 | aStrCommand = theArgsArray->Value (theArgIndex); | |
3381 | if (!aStrCommand.IsRealValue()) | |
3382 | return false; | |
3383 | } | |
3384 | ||
3385 | return true; | |
3386 | } | |
3387 | ||
3388 | //============================================================================= | |
3389 | //function : VDrawPArray | |
3390 | //purpose : Draws primitives array from list of vertexes, bounds, edges | |
3391 | //============================================================================= | |
3392 | ||
3393 | static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
3394 | { | |
3395 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
3396 | if (aContextAIS.IsNull()) | |
3397 | { | |
3398 | di << "Call vinit before!\n"; | |
3399 | return 1; | |
3400 | } | |
3401 | else if (argc < 3) | |
3402 | { | |
3403 | di << "Use: " << argv[0] << " Name TypeOfArray" | |
3404 | << " [vertex] ... [bounds] ... [edges]\n" | |
3405 | << " TypeOfArray={ points | segments | polylines | triangles |\n" | |
3406 | << " trianglefans | trianglestrips | quads |\n" | |
3407 | << " quadstrips | polygons }\n" | |
3408 | << " vertex={ 'v' x y z [normal={ 'n' nx ny nz }] [color={ 'c' r g b }]" | |
3409 | << " [texel={ 't' tx ty }] } \n" | |
3410 | << " bounds={ 'b' verticies_count [color={ 'c' r g b }] }\n" | |
871fa103 | 3411 | << " edges={ 'e' vertex_id }\n"; |
eb4320f2 | 3412 | return 1; |
3413 | } | |
3414 | ||
3415 | // read the arguments | |
3416 | Standard_Integer aArgIndex = 1; | |
3417 | TCollection_AsciiString aName (argv[aArgIndex++]); | |
3418 | TCollection_AsciiString anArrayType (argv[aArgIndex++]); | |
3419 | ||
3420 | Standard_Boolean hasVertex = Standard_False; | |
3421 | ||
3422 | Handle(TColStd_HArray1OfAsciiString) anArgsArray = new TColStd_HArray1OfAsciiString (0, argc - 2); | |
3423 | anArgsArray->SetValue (0, anArrayType); | |
3424 | ||
3425 | if (anArrayType != "points" && | |
3426 | anArrayType != "segments" && | |
3427 | anArrayType != "polylines" && | |
3428 | anArrayType != "triangles" && | |
3429 | anArrayType != "trianglefans" && | |
3430 | anArrayType != "trianglestrips" && | |
3431 | anArrayType != "quads" && | |
3432 | anArrayType != "quadstrips" && | |
3433 | anArrayType != "polygons") | |
3434 | { | |
3435 | di << "Unexpected type of primitives array\n"; | |
3436 | return 1; | |
3437 | } | |
3438 | ||
3439 | TCollection_AsciiString aCommand; | |
3440 | for (Standard_Integer anArgIndex = 3; anArgIndex < argc; anArgIndex++) | |
3441 | { | |
3442 | aCommand = argv[anArgIndex]; | |
3443 | aCommand.LowerCase(); | |
3444 | if (!aCommand.IsAscii()) | |
3445 | { | |
3446 | di << "Unexpected argument: #" << aArgIndex - 1 << " , " | |
3447 | << "should be an array element: 'v', 'b', 'e' \n"; | |
3448 | break; | |
3449 | } | |
3450 | ||
3451 | if (aCommand == "v") | |
3452 | { | |
3453 | hasVertex = Standard_True; | |
3454 | } | |
3455 | ||
3456 | anArgsArray->SetValue (anArgIndex - 2, aCommand); | |
3457 | } | |
3458 | ||
3459 | if (!hasVertex) | |
3460 | { | |
3461 | di << "You should pass any verticies in the list of array elements\n"; | |
3462 | return 1; | |
3463 | } | |
3464 | ||
3465 | Handle(Graphic3d_AspectMarker3d) anAspPoints; | |
3466 | if (anArrayType == "points") | |
3467 | { | |
3468 | anAspPoints = new Graphic3d_AspectMarker3d (Aspect_TOM_POINT, Quantity_NOC_YELLOW, 1.0f); | |
9558a876 A |
3469 | } |
3470 | ||
9558a876 | 3471 | // create primitives array object |
eb4320f2 | 3472 | Handle(MyPArrayObject) aPObject = new MyPArrayObject (anArgsArray, anAspPoints); |
9558a876 A |
3473 | |
3474 | // register the object in map | |
3475 | VDisplayAISObject (aName, aPObject); | |
3476 | ||
3477 | return 0; | |
3478 | } | |
3479 | ||
29d43f9c A |
3480 | //======================================================================= |
3481 | //function : VSetLocation | |
3482 | //purpose : Change location of AIS interactive object | |
3483 | //======================================================================= | |
3484 | ||
0bd2a43f | 3485 | static Standard_Integer VSetLocation (Draw_Interpretor& /*di*/, |
4e18052b | 3486 | Standard_Integer theArgNb, |
3487 | const char** theArgVec) | |
29d43f9c A |
3488 | { |
3489 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4e18052b | 3490 | ViewerTest_AutoUpdater anUpdateTool (aContext, ViewerTest::CurrentView()); |
29d43f9c A |
3491 | if (aContext.IsNull()) |
3492 | { | |
4e18052b | 3493 | std::cout << "Error: no active view!\n"; |
29d43f9c A |
3494 | return 1; |
3495 | } | |
3496 | ||
4e18052b | 3497 | TCollection_AsciiString aName; |
3498 | gp_Vec aLocVec; | |
3499 | Standard_Boolean isSetLoc = Standard_False; | |
3500 | ||
3501 | Standard_Integer anArgIter = 1; | |
3502 | for (; anArgIter < theArgNb; ++anArgIter) | |
29d43f9c | 3503 | { |
4e18052b | 3504 | Standard_CString anArg = theArgVec[anArgIter]; |
3505 | if (anUpdateTool.parseRedrawMode (theArgVec[anArgIter])) | |
3506 | { | |
3507 | continue; | |
3508 | } | |
3509 | else if (aName.IsEmpty()) | |
3510 | { | |
3511 | aName = anArg; | |
3512 | } | |
3513 | else if (!isSetLoc) | |
3514 | { | |
3515 | isSetLoc = Standard_True; | |
3516 | if (anArgIter + 1 >= theArgNb) | |
3517 | { | |
3518 | std::cout << "Error: syntax error at '" << anArg << "'\n"; | |
3519 | return 1; | |
3520 | } | |
3521 | aLocVec.SetX (Draw::Atof (theArgVec[anArgIter++])); | |
3522 | aLocVec.SetY (Draw::Atof (theArgVec[anArgIter])); | |
3523 | if (anArgIter + 1 < theArgNb) | |
3524 | { | |
3525 | aLocVec.SetZ (Draw::Atof (theArgVec[++anArgIter])); | |
3526 | } | |
3527 | } | |
3528 | else | |
3529 | { | |
3530 | std::cout << "Error: unknown argument '" << anArg << "'\n"; | |
3531 | return 1; | |
3532 | } | |
29d43f9c A |
3533 | } |
3534 | ||
29d43f9c | 3535 | // find object |
4e18052b | 3536 | const ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); |
29d43f9c | 3537 | Handle(AIS_InteractiveObject) anIObj; |
4e18052b | 3538 | if (aMap.IsBound2 (aName)) |
29d43f9c | 3539 | { |
4e18052b | 3540 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (aName)); |
29d43f9c | 3541 | } |
4e18052b | 3542 | if (anIObj.IsNull()) |
29d43f9c | 3543 | { |
4e18052b | 3544 | std::cout << "Error: object '" << aName << "' is not displayed!\n"; |
3545 | return 1; | |
29d43f9c A |
3546 | } |
3547 | ||
4e18052b | 3548 | gp_Trsf aTrsf; |
3549 | aTrsf.SetTranslation (aLocVec); | |
3550 | TopLoc_Location aLocation (aTrsf); | |
3551 | aContext->SetLocation (anIObj, aLocation); | |
29d43f9c A |
3552 | return 0; |
3553 | } | |
3554 | ||
ac04d101 SA |
3555 | //=============================================================================================== |
3556 | //function : VConnect | |
3557 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location | |
0717ddc1 | 3558 | //Draw arg : vconnect name Xo Yo Zo object1 object2 ... [color=NAME] |
ac04d101 SA |
3559 | //=============================================================================================== |
3560 | ||
0717ddc1 | 3561 | static Standard_Integer VConnect (Draw_Interpretor& /*di*/, |
3562 | Standard_Integer argc, | |
3563 | const char ** argv) | |
ac04d101 | 3564 | { |
792c785c | 3565 | // Check the viewer |
3566 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
3567 | if (aContext.IsNull()) | |
ac04d101 | 3568 | { |
792c785c | 3569 | std::cout << "vconnect error : call vinit before\n"; |
ac04d101 SA |
3570 | return 1; // TCL_ERROR |
3571 | } | |
792c785c | 3572 | // Check argumnets |
0717ddc1 | 3573 | if (argc < 6) |
ac04d101 | 3574 | { |
0717ddc1 | 3575 | std::cout << "vconnect error: expect at least 5 arguments\n"; |
ac04d101 SA |
3576 | return 1; // TCL_ERROR |
3577 | } | |
792c785c | 3578 | |
3579 | // Get values | |
3580 | Standard_Integer anArgIter = 1; | |
3581 | TCollection_AsciiString aName (argv[anArgIter++]); | |
0717ddc1 | 3582 | Handle(AIS_MultipleConnectedInteractive) anOriginObject; |
792c785c | 3583 | TCollection_AsciiString aColorString (argv[argc-1]); |
1d47d8d0 | 3584 | Standard_CString aColorName = ""; |
792c785c | 3585 | Standard_Boolean hasColor = Standard_False; |
3586 | if (aColorString.Search ("color=") != -1) | |
ac04d101 | 3587 | { |
792c785c | 3588 | hasColor = Standard_True; |
3589 | aColorString.Remove (1, 6); | |
3590 | aColorName = aColorString.ToCString(); | |
3591 | } | |
3592 | Handle(AIS_InteractiveObject) anObject; | |
3593 | ||
0717ddc1 | 3594 | // AIS_MultipleConnectedInteractive |
3595 | const Standard_Integer aNbShapes = hasColor ? (argc - 1) : argc; | |
3596 | for (Standard_Integer i = 5; i < aNbShapes; ++i) | |
792c785c | 3597 | { |
0717ddc1 | 3598 | TCollection_AsciiString anOriginObjectName (argv[i]); |
792c785c | 3599 | if (aName.IsEqual (anOriginObjectName)) |
ac04d101 | 3600 | { |
0717ddc1 | 3601 | std::cout << "vconnect error: equal names for connected objects\n"; |
3602 | continue; | |
ac04d101 | 3603 | } |
792c785c | 3604 | if (GetMapOfAIS().IsBound2 (anOriginObjectName)) |
3605 | { | |
3606 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName); | |
0717ddc1 | 3607 | anObject = Handle(AIS_InteractiveObject)::DownCast(anObj); |
3608 | if (anObject.IsNull()) | |
792c785c | 3609 | { |
3610 | std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n"; | |
0717ddc1 | 3611 | continue; |
792c785c | 3612 | } |
3613 | } | |
3614 | else | |
3615 | { | |
3616 | Standard_CString aName = anOriginObjectName.ToCString(); | |
3617 | TopoDS_Shape aTDShape = DBRep::Get (aName); | |
3618 | if (aTDShape.IsNull()) | |
3619 | { | |
3620 | std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n"; | |
792c785c | 3621 | continue; |
3622 | } | |
0717ddc1 | 3623 | anObject = new AIS_Shape (aTDShape); |
3624 | anObject->SetColor (ViewerTest::GetColorFromName (aColorName)); | |
792c785c | 3625 | } |
0717ddc1 | 3626 | |
792c785c | 3627 | if (anOriginObject.IsNull()) |
3628 | { | |
0717ddc1 | 3629 | anOriginObject = new AIS_MultipleConnectedInteractive(); |
792c785c | 3630 | } |
0717ddc1 | 3631 | |
3632 | anOriginObject->Connect (anObject); | |
3633 | } | |
3634 | if (anOriginObject.IsNull()) | |
3635 | { | |
3636 | std::cout << "vconect error : can't connect input objects\n"; | |
3637 | return 1; // TCL_ERROR | |
792c785c | 3638 | } |
3639 | ||
ac04d101 | 3640 | // Get location data |
91322f44 | 3641 | Standard_Real aXo = Draw::Atof (argv[anArgIter++]); |
3642 | Standard_Real aYo = Draw::Atof (argv[anArgIter++]); | |
3643 | Standard_Real aZo = Draw::Atof (argv[anArgIter++]); | |
ac04d101 SA |
3644 | |
3645 | // Create transformation | |
0717ddc1 | 3646 | gp_Vec aTranslation (aXo, aYo, aZo); |
3647 | ||
ac04d101 | 3648 | gp_Trsf aTrsf; |
0717ddc1 | 3649 | aTrsf.SetTranslationPart (aTranslation); |
3650 | TopLoc_Location aLocation (aTrsf); | |
ac04d101 | 3651 | |
0717ddc1 | 3652 | anOriginObject->SetLocalTransformation (aTrsf); |
ac04d101 SA |
3653 | |
3654 | // Check if there is another object with given name | |
3655 | // and remove it from context | |
3656 | if(GetMapOfAIS().IsBound2(aName)) | |
3657 | { | |
3658 | Handle(AIS_InteractiveObject) anObj = | |
3659 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName)); | |
3660 | TheAISContext()->Remove(anObj, Standard_False); | |
3661 | GetMapOfAIS().UnBind2(aName); | |
3662 | } | |
3663 | ||
792c785c | 3664 | // Bind connected object to its name |
0717ddc1 | 3665 | GetMapOfAIS().Bind (anOriginObject, aName); |
ac04d101 SA |
3666 | |
3667 | // Display connected object | |
0717ddc1 | 3668 | TheAISContext()->Display (anOriginObject); |
ac04d101 SA |
3669 | |
3670 | return 0; | |
3671 | } | |
3672 | ||
3673 | //=============================================================================================== | |
0717ddc1 | 3674 | //function : VConnectTo |
3675 | //purpose : Creates and displays AIS_ConnectedInteractive object from input object and location | |
3676 | //Draw arg : vconnectto name Xo Yo Zo object | |
ac04d101 SA |
3677 | //=============================================================================================== |
3678 | ||
0717ddc1 | 3679 | static Standard_Integer VConnectTo (Draw_Interpretor& /*di*/, |
3680 | Standard_Integer argc, | |
3681 | const char ** argv) | |
ac04d101 | 3682 | { |
792c785c | 3683 | // Check the viewer |
3684 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
3685 | if (aContext.IsNull()) | |
ac04d101 | 3686 | { |
0717ddc1 | 3687 | std::cout << "vconnect error : call vinit before\n"; |
ac04d101 SA |
3688 | return 1; // TCL_ERROR |
3689 | } | |
0717ddc1 | 3690 | // Check argumnets |
3691 | if (argc != 6) | |
ac04d101 | 3692 | { |
0717ddc1 | 3693 | std::cout << "vconnect error: expect at least 5 arguments\n"; |
ac04d101 SA |
3694 | return 1; // TCL_ERROR |
3695 | } | |
792c785c | 3696 | |
3697 | // Get values | |
3698 | Standard_Integer anArgIter = 1; | |
3699 | TCollection_AsciiString aName (argv[anArgIter++]); | |
0717ddc1 | 3700 | Handle(AIS_InteractiveObject) anOriginObject; |
3701 | ||
3702 | TCollection_AsciiString anOriginObjectName(argv[5]); | |
3703 | if (aName.IsEqual (anOriginObjectName)) | |
792c785c | 3704 | { |
0717ddc1 | 3705 | std::cout << "vconnect error: equal names for connected objects\n"; |
3706 | return 1; // TCL_ERROR | |
792c785c | 3707 | } |
0717ddc1 | 3708 | if (GetMapOfAIS().IsBound2 (anOriginObjectName)) |
ac04d101 | 3709 | { |
0717ddc1 | 3710 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (anOriginObjectName); |
3711 | anOriginObject = Handle(AIS_InteractiveObject)::DownCast(anObj); | |
3712 | if (anOriginObject.IsNull()) | |
ac04d101 | 3713 | { |
0717ddc1 | 3714 | std::cout << "Object " << anOriginObjectName << " is used for non AIS viewer\n"; |
792c785c | 3715 | return 1; // TCL_ERROR |
3716 | } | |
792c785c | 3717 | } |
792c785c | 3718 | else |
3719 | { | |
0717ddc1 | 3720 | Standard_CString aName = anOriginObjectName.ToCString(); |
3721 | TopoDS_Shape aTDShape = DBRep::Get (aName); | |
3722 | if (aTDShape.IsNull()) | |
792c785c | 3723 | { |
0717ddc1 | 3724 | std::cout << "vconnect error: object " << anOriginObjectName << " doesn't exist\n"; |
ac04d101 SA |
3725 | return 1; // TCL_ERROR |
3726 | } | |
0717ddc1 | 3727 | anOriginObject = new AIS_Shape (aTDShape); |
ac04d101 | 3728 | } |
0717ddc1 | 3729 | |
3730 | // Get location data | |
91322f44 | 3731 | Standard_Real aXo = Draw::Atof (argv[anArgIter++]); |
3732 | Standard_Real aYo = Draw::Atof (argv[anArgIter++]); | |
3733 | Standard_Real aZo = Draw::Atof (argv[anArgIter++]); | |
ac04d101 SA |
3734 | |
3735 | // Create transformation | |
0717ddc1 | 3736 | gp_Vec aTranslation (aXo, aYo, aZo); |
ac04d101 | 3737 | |
0717ddc1 | 3738 | gp_Trsf aTrsf; |
3739 | aTrsf.SetTranslationPart (aTranslation); | |
3740 | ||
792c785c | 3741 | Handle(AIS_ConnectedInteractive) aConnected; |
0717ddc1 | 3742 | |
3743 | aConnected = new AIS_ConnectedInteractive(); | |
3744 | ||
3745 | aConnected->Connect (anOriginObject, aTrsf); | |
ac04d101 SA |
3746 | |
3747 | // Check if there is another object with given name | |
3748 | // and remove it from context | |
3749 | if(GetMapOfAIS().IsBound2(aName)) | |
3750 | { | |
3751 | Handle(AIS_InteractiveObject) anObj = | |
3752 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName)); | |
3753 | TheAISContext()->Remove(anObj, Standard_False); | |
3754 | GetMapOfAIS().UnBind2(aName); | |
3755 | } | |
3756 | ||
0717ddc1 | 3757 | // Bind connected object to its name |
792c785c | 3758 | GetMapOfAIS().Bind (aConnected, aName); |
ac04d101 | 3759 | |
0717ddc1 | 3760 | // Display connected object |
792c785c | 3761 | TheAISContext()->Display (aConnected); |
ac04d101 SA |
3762 | |
3763 | return 0; | |
3764 | } | |
3765 | ||
0717ddc1 | 3766 | //======================================================================= |
3767 | //function : VDisconnect | |
3768 | //purpose : | |
3769 | //======================================================================= | |
3770 | static Standard_Integer VDisconnect (Draw_Interpretor& di, | |
3771 | Standard_Integer argc, | |
3772 | const char ** argv) | |
3773 | { | |
3774 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
3775 | if (aContext.IsNull()) | |
3776 | { | |
3777 | std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n"; | |
3778 | return 1; | |
3779 | } | |
3780 | ||
3781 | if (argc != 3) | |
3782 | { | |
3783 | std::cout << "ERROR : Usage : " << argv[0] << " name object" << "\n"; | |
3784 | return 1; | |
3785 | } | |
3786 | ||
3787 | TCollection_AsciiString aName (argv[1]); | |
3788 | TCollection_AsciiString anObject (argv[2]); | |
3789 | Standard_Integer anObjectNumber = Draw::Atoi (argv[2]); | |
3790 | ||
3791 | // find objects | |
3792 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
3793 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
3794 | if (!aMap.IsBound2 (aName) ) | |
3795 | { | |
3796 | std::cout << "Use 'vdisplay' before" << "\n"; | |
3797 | return 1; | |
3798 | } | |
3799 | ||
3800 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
3801 | if (anAssembly.IsNull()) | |
3802 | { | |
3803 | di << "Not an assembly" << "\n"; | |
3804 | return 1; | |
3805 | } | |
3806 | ||
3807 | Handle(AIS_InteractiveObject) anIObj; | |
3808 | if (!aMap.IsBound2 (anObject)) | |
3809 | { | |
3810 | // try to interpret second argument as child number | |
3811 | if (anObjectNumber > 0 && anObjectNumber <= anAssembly->Children().Size()) | |
3812 | { | |
3813 | Standard_Integer aCounter = 1; | |
3814 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
3815 | { | |
3816 | if (aCounter == anObjectNumber) | |
3817 | { | |
3818 | anIObj = Handle(AIS_InteractiveObject)::DownCast (anIter.Value()); | |
3819 | break; | |
3820 | } | |
3821 | ++aCounter; | |
3822 | } | |
3823 | } | |
3824 | else | |
3825 | { | |
3826 | std::cout << "Use 'vdisplay' before" << "\n"; | |
3827 | return 1; | |
3828 | } | |
3829 | } | |
3830 | ||
3831 | // if object was found by name | |
3832 | if (anIObj.IsNull()) | |
3833 | { | |
3834 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject)); | |
3835 | } | |
3836 | ||
3837 | anAssembly->Disconnect (anIObj); | |
3838 | aContext->UpdateCurrentViewer(); | |
3839 | ||
3840 | return 0; | |
3841 | } | |
3842 | ||
3843 | //======================================================================= | |
3844 | //function : VAddConnected | |
3845 | //purpose : | |
3846 | //======================================================================= | |
3847 | static Standard_Integer VAddConnected (Draw_Interpretor& di, | |
3848 | Standard_Integer argc, | |
3849 | const char ** argv) | |
3850 | { | |
3851 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
3852 | if (aContext.IsNull()) | |
3853 | { | |
3854 | std::cout << argv[0] << "error : use 'vinit' command before " << "\n"; | |
3855 | return 1; | |
3856 | } | |
3857 | ||
3858 | if (argc != 6) | |
3859 | { | |
3860 | std::cout << argv[0] << " error: expect 5 arguments\n"; | |
3861 | return 1; | |
3862 | } | |
3863 | ||
3864 | TCollection_AsciiString aName (argv[1]); | |
3865 | TCollection_AsciiString anObject (argv[5]); | |
3866 | Standard_Real aX = Draw::Atof (argv[2]); | |
3867 | Standard_Real aY = Draw::Atof (argv[3]); | |
3868 | Standard_Real aZ = Draw::Atof (argv[4]); | |
3869 | ||
3870 | // find object | |
3871 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
3872 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
3873 | if (!aMap.IsBound2 (aName) ) | |
3874 | { | |
3875 | std::cout << "Use 'vdisplay' before" << "\n"; | |
3876 | return 1; | |
3877 | } | |
3878 | ||
3879 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
3880 | if (anAssembly.IsNull()) | |
3881 | { | |
3882 | di << "Not an assembly" << "\n"; | |
3883 | return 1; | |
3884 | } | |
3885 | ||
3886 | Handle(AIS_InteractiveObject) anIObj; | |
3887 | if (!aMap.IsBound2 (anObject)) | |
3888 | { | |
3889 | std::cout << "Use 'vdisplay' before" << "\n"; | |
3890 | return 1; | |
3891 | } | |
3892 | ||
3893 | anIObj = Handle(AIS_InteractiveObject)::DownCast (aMap.Find2 (anObject)); | |
3894 | ||
3895 | gp_Trsf aTrsf; | |
3896 | aTrsf.SetTranslation (gp_Vec (aX, aY, aZ)); | |
3897 | ||
3898 | anAssembly->Connect (anIObj, aTrsf); | |
3899 | TheAISContext()->Display (anAssembly); | |
3900 | TheAISContext()->RecomputeSelectionOnly (anAssembly); | |
3901 | aContext->UpdateCurrentViewer(); | |
3902 | ||
3903 | return 0; | |
3904 | } | |
3905 | ||
3906 | //======================================================================= | |
3907 | //function : VListConnected | |
3908 | //purpose : | |
3909 | //======================================================================= | |
0bd2a43f | 3910 | static Standard_Integer VListConnected (Draw_Interpretor& /*di*/, |
0717ddc1 | 3911 | Standard_Integer argc, |
3912 | const char ** argv) | |
3913 | { | |
3914 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
3915 | if (aContext.IsNull()) | |
3916 | { | |
3917 | std::cout << argv[0] << "ERROR : use 'vinit' command before " << "\n"; | |
3918 | return 1; | |
3919 | } | |
3920 | ||
3921 | if (argc != 2) | |
3922 | { | |
3923 | std::cout << "ERROR : Usage : " << argv[0] << " name" << "\n"; | |
3924 | return 1; | |
3925 | } | |
3926 | ||
3927 | TCollection_AsciiString aName (argv[1]); | |
3928 | ||
3929 | // find object | |
3930 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
3931 | Handle(AIS_MultipleConnectedInteractive) anAssembly; | |
3932 | if (!aMap.IsBound2 (aName) ) | |
3933 | { | |
3934 | std::cout << "Use 'vdisplay' before" << "\n"; | |
3935 | return 1; | |
3936 | } | |
3937 | ||
3938 | anAssembly = Handle(AIS_MultipleConnectedInteractive)::DownCast (aMap.Find2 (aName)); | |
3939 | if (anAssembly.IsNull()) | |
3940 | { | |
3941 | std::cout << "Not an assembly" << "\n"; | |
3942 | return 1; | |
3943 | } | |
3944 | ||
3945 | std::cout << "Children of " << aName << ":\n"; | |
3946 | ||
3947 | Standard_Integer aCounter = 1; | |
3948 | for (PrsMgr_ListOfPresentableObjectsIter anIter (anAssembly->Children()); anIter.More(); anIter.Next()) | |
3949 | { | |
3950 | if (GetMapOfAIS().IsBound1 (anIter.Value())) | |
3951 | { | |
3952 | TCollection_AsciiString aName = GetMapOfAIS().Find1 (anIter.Value()); | |
3953 | std::cout << aCounter << ") " << aName << " (" << anIter.Value()->DynamicType()->Name() << ")"; | |
3954 | } | |
3955 | ||
3956 | std::cout << aCounter << ") " << anIter.Value()->DynamicType()->Name(); | |
3957 | ||
3958 | Handle(AIS_ConnectedInteractive) aConnected = Handle(AIS_ConnectedInteractive)::DownCast (anIter.Value()); | |
3959 | if (!aConnected.IsNull() && !aConnected->ConnectedTo().IsNull() && aMap.IsBound1 (aConnected->ConnectedTo())) | |
3960 | { | |
3961 | std::cout << " connected to " << aMap.Find1 (aConnected->ConnectedTo()); | |
3962 | } | |
3963 | std::cout << std::endl; | |
3964 | ||
3965 | ++aCounter; | |
3966 | } | |
3967 | ||
3968 | return 0; | |
3969 | } | |
3970 | ||
9f37b47d | 3971 | namespace |
3972 | { | |
3973 | //! Checks if theMode is already turned on for theObj. | |
3974 | static Standard_Boolean InList (const Handle(AIS_InteractiveContext)& theAISContext, | |
3975 | const Handle(AIS_InteractiveObject)& theObj, | |
3976 | const Standard_Integer theMode) | |
3977 | { | |
3978 | TColStd_ListOfInteger anActiveModes; | |
3979 | theAISContext->ActivatedModes (theObj, anActiveModes); | |
3980 | for (TColStd_ListIteratorOfListOfInteger aModeIt (anActiveModes); aModeIt.More(); aModeIt.Next()) | |
3981 | { | |
3982 | if (aModeIt.Value() == theMode) | |
3983 | { | |
3984 | return Standard_True; | |
3985 | } | |
3986 | } | |
3987 | return Standard_False; | |
3988 | } | |
3989 | }; | |
3990 | ||
ac04d101 SA |
3991 | //=============================================================================================== |
3992 | //function : VSetSelectionMode | |
3993 | //purpose : Sets input selection mode for input object or for all displayed objects | |
3994 | //Draw arg : vselmode [object] mode On/Off (1/0) | |
3995 | //=============================================================================================== | |
9f37b47d | 3996 | static Standard_Integer VSetSelectionMode (Draw_Interpretor& /*di*/, |
3997 | Standard_Integer theArgc, | |
3998 | const char** theArgv) | |
ac04d101 SA |
3999 | { |
4000 | // Check errors | |
4001 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
9f37b47d | 4002 | if (anAISContext.IsNull()) |
ac04d101 | 4003 | { |
709e97a0 | 4004 | std::cerr << "Call vinit before!" << std::endl; |
9f37b47d | 4005 | return 1; |
ac04d101 SA |
4006 | } |
4007 | ||
9f37b47d | 4008 | // Check the arguments |
4009 | if (theArgc != 3 && theArgc != 4) | |
ac04d101 | 4010 | { |
9f37b47d | 4011 | std::cerr << "vselmode error : expects at least 2 arguments.\n" |
709e97a0 | 4012 | << "Type help "<< theArgv[0] <<" for more information." << std::endl; |
9f37b47d | 4013 | return 1; |
ac04d101 SA |
4014 | } |
4015 | ||
9f37b47d | 4016 | // get objects to change selection mode |
4017 | AIS_ListOfInteractive aTargetIOs; | |
4018 | if (theArgc == 3) | |
ac04d101 | 4019 | { |
9f37b47d | 4020 | anAISContext->DisplayedObjects (aTargetIOs); |
4021 | } | |
4022 | else | |
4023 | { | |
4024 | // Check if there is an object with given name in context | |
4025 | const TCollection_AsciiString aNameIO (theArgv[1]); | |
4026 | if (GetMapOfAIS().IsBound2 (aNameIO)) | |
ac04d101 | 4027 | { |
9f37b47d | 4028 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aNameIO)); |
4029 | if (anIO.IsNull()) | |
ac04d101 | 4030 | { |
709e97a0 | 4031 | std::cerr << "vselmode error : object name is used for non AIS viewer" << std::endl; |
9f37b47d | 4032 | return 1; |
ac04d101 | 4033 | } |
9f37b47d | 4034 | aTargetIOs.Append (anIO); |
ac04d101 | 4035 | } |
9f37b47d | 4036 | } |
ac04d101 | 4037 | |
9f37b47d | 4038 | const Standard_Integer aSelectionMode = Draw::Atoi (theArgc == 3 ? theArgv[1] : theArgv[2]); |
4039 | const Standard_Boolean toTurnOn = Draw::Atoi (theArgc == 3 ? theArgv[2] : theArgv[3]); | |
4040 | if (aSelectionMode == 0 && anAISContext->HasOpenedContext()) | |
4041 | { | |
4042 | anAISContext->CloseLocalContext(); | |
ac04d101 SA |
4043 | } |
4044 | ||
709e97a0 | 4045 | if (aSelectionMode == 0) |
4046 | { | |
4047 | if (toTurnOn) | |
4048 | { | |
4049 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) | |
4050 | { | |
4051 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); | |
4052 | if (!InList (anAISContext, anIO, aSelectionMode)) | |
4053 | { | |
4054 | anAISContext->Activate (anIO); | |
4055 | } | |
4056 | } | |
4057 | } | |
4058 | else | |
4059 | { | |
4060 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) | |
4061 | { | |
4062 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); | |
4063 | if (InList (anAISContext, anIO, aSelectionMode)) | |
4064 | { | |
4065 | anAISContext->Deactivate (anIO); | |
4066 | } | |
4067 | } | |
4068 | } | |
4069 | } | |
4070 | ||
9f37b47d | 4071 | if (aSelectionMode != 0 && toTurnOn) // Turn on specified mode |
ac04d101 | 4072 | { |
9f37b47d | 4073 | if (!anAISContext->HasOpenedContext()) |
4074 | { | |
4075 | anAISContext->OpenLocalContext (Standard_False); | |
4076 | } | |
ac04d101 | 4077 | |
9f37b47d | 4078 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) |
ac04d101 | 4079 | { |
9f37b47d | 4080 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); |
4081 | if (!InList (anAISContext, anIO, aSelectionMode)) | |
ac04d101 | 4082 | { |
9f37b47d | 4083 | anAISContext->Load (anIO, -1, Standard_True); |
4084 | anAISContext->Activate (anIO, aSelectionMode); | |
ac04d101 SA |
4085 | } |
4086 | } | |
9f37b47d | 4087 | } |
ac04d101 | 4088 | |
9f37b47d | 4089 | if (aSelectionMode != 0 && !toTurnOn) // Turn off specified mode |
4090 | { | |
4091 | if (!anAISContext->HasOpenedContext()) | |
ac04d101 | 4092 | { |
9f37b47d | 4093 | return 0; |
ac04d101 SA |
4094 | } |
4095 | ||
9f37b47d | 4096 | for (AIS_ListIteratorOfListOfInteractive aTargetIt (aTargetIOs); aTargetIt.More(); aTargetIt.Next()) |
ac04d101 | 4097 | { |
9f37b47d | 4098 | const Handle(AIS_InteractiveObject)& anIO = aTargetIt.Value(); |
4099 | if (InList (anAISContext, anIO, aSelectionMode)) | |
ac04d101 | 4100 | { |
9f37b47d | 4101 | anAISContext->Deactivate (anIO, aSelectionMode); |
ac04d101 SA |
4102 | } |
4103 | } | |
4104 | } | |
9f37b47d | 4105 | |
ac04d101 SA |
4106 | return 0; |
4107 | } | |
4108 | ||
ceae62f0 A |
4109 | //========================================================================== |
4110 | //class : Triangle | |
4111 | //purpose : creates Triangle based on AIS_InteractiveObject. | |
4112 | // This class was implemented for testing Select3D_SensitiveTriangle | |
4113 | //=========================================================================== | |
4114 | DEFINE_STANDARD_HANDLE(Triangle, AIS_InteractiveObject) | |
4115 | class Triangle: public AIS_InteractiveObject | |
4116 | { | |
4117 | public: | |
4118 | // CASCADE RTTI | |
4119 | DEFINE_STANDARD_RTTI(FilledCircle); | |
4120 | Triangle (const gp_Pnt& theP1, | |
4121 | const gp_Pnt& theP2, | |
4122 | const gp_Pnt& theP3); | |
4123 | protected: | |
4124 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
4125 | const Handle(Prs3d_Presentation)& thePresentation, | |
4126 | const Standard_Integer theMode); | |
4127 | ||
4128 | void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, | |
4129 | const Standard_Integer theMode); | |
4130 | private: | |
4131 | gp_Pnt myPoint1; | |
4132 | gp_Pnt myPoint2; | |
4133 | gp_Pnt myPoint3; | |
4134 | }; | |
4135 | IMPLEMENT_STANDARD_HANDLE(Triangle, AIS_InteractiveObject) | |
4136 | IMPLEMENT_STANDARD_RTTIEXT(Triangle, AIS_InteractiveObject) | |
4137 | ||
4138 | Triangle::Triangle (const gp_Pnt& theP1, | |
4139 | const gp_Pnt& theP2, | |
4140 | const gp_Pnt& theP3) | |
4141 | { | |
4142 | myPoint1 = theP1; | |
4143 | myPoint2 = theP2; | |
4144 | myPoint3 = theP3; | |
4145 | } | |
4146 | ||
35e08fe8 | 4147 | void Triangle::Compute(const Handle(PrsMgr_PresentationManager3d)& /*thePresentationManager*/, |
ceae62f0 | 4148 | const Handle(Prs3d_Presentation)& thePresentation, |
35e08fe8 | 4149 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4150 | { |
4151 | thePresentation->Clear(); | |
4152 | ||
4153 | BRepBuilderAPI_MakeEdge anEdgeMaker1(myPoint1, myPoint2), | |
4154 | anEdgeMaker2(myPoint2, myPoint3), | |
4155 | anEdgeMaker3(myPoint3, myPoint1); | |
4156 | ||
4157 | TopoDS_Edge anEdge1 = anEdgeMaker1.Edge(), | |
4158 | anEdge2 = anEdgeMaker2.Edge(), | |
4159 | anEdge3 = anEdgeMaker3.Edge(); | |
4160 | if(anEdge1.IsNull() || anEdge2.IsNull() || anEdge3.IsNull()) | |
4161 | return; | |
4162 | ||
4163 | BRepBuilderAPI_MakeWire aWireMaker(anEdge1, anEdge2, anEdge3); | |
4164 | TopoDS_Wire aWire = aWireMaker.Wire(); | |
4165 | if(aWire.IsNull()) return; | |
4166 | ||
4167 | BRepBuilderAPI_MakeFace aFaceMaker(aWire); | |
4168 | TopoDS_Face aFace = aFaceMaker.Face(); | |
4169 | if(aFace.IsNull()) return; | |
4170 | ||
4171 | StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer); | |
4172 | } | |
4173 | ||
4174 | void Triangle::ComputeSelection(const Handle(SelectMgr_Selection)& theSelection, | |
35e08fe8 | 4175 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4176 | { |
4177 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); | |
4178 | Handle(Select3D_SensitiveTriangle) aSensTriangle = | |
4179 | new Select3D_SensitiveTriangle(anEntityOwner, myPoint1, myPoint2, myPoint3); | |
4180 | theSelection->Add(aSensTriangle); | |
4181 | } | |
4182 | ||
4183 | //=========================================================================== | |
4184 | //function : VTriangle | |
4185 | //Draw arg : vtriangle Name PointName PointName PointName | |
4186 | //purpose : creates and displays Triangle | |
4187 | //=========================================================================== | |
4188 | ||
4189 | //function: IsPoint | |
4190 | //purpose : checks if the object with theName is AIS_Point, | |
4191 | // if yes initialize thePoint from MapOfAIS | |
4192 | Standard_Boolean IsPoint (const TCollection_AsciiString& theName, | |
4193 | Handle(AIS_Point)& thePoint) | |
4194 | { | |
4195 | Handle(AIS_InteractiveObject) anObject = | |
4196 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(theName)); | |
4197 | if(anObject.IsNull() || | |
4198 | anObject->Type() != AIS_KOI_Datum || | |
4199 | anObject->Signature() != 1) | |
4200 | { | |
4201 | return Standard_False; | |
4202 | } | |
4203 | thePoint = Handle(AIS_Point)::DownCast(anObject); | |
4204 | if(thePoint.IsNull()) | |
4205 | return Standard_False; | |
4206 | return Standard_True; | |
4207 | } | |
4208 | ||
4209 | //function: IsMatch | |
4210 | //purpose: checks if thePoint1 is equal to thePoint2 | |
4211 | Standard_Boolean IsMatch (const Handle(Geom_CartesianPoint)& thePoint1, | |
4212 | const Handle(Geom_CartesianPoint)& thePoint2) | |
4213 | { | |
91322f44 | 4214 | if(Abs(thePoint1->X()-thePoint2->X()) <= Precision::Confusion() && |
4215 | Abs(thePoint1->Y()-thePoint2->Y()) <= Precision::Confusion() && | |
4216 | Abs(thePoint1->Z()-thePoint2->Z()) <= Precision::Confusion()) | |
ceae62f0 A |
4217 | { |
4218 | return Standard_True; | |
4219 | } | |
4220 | return Standard_False; | |
4221 | } | |
4222 | ||
35e08fe8 | 4223 | static Standard_Integer VTriangle (Draw_Interpretor& /*di*/, |
ceae62f0 A |
4224 | Standard_Integer argc, |
4225 | const char ** argv) | |
4226 | { | |
4227 | // Check arguments | |
4228 | if (argc != 5) | |
4229 | { | |
4230 | std::cout<<"vtriangle error: expects 4 argumnets\n"; | |
4231 | return 1; // TCL_ERROR | |
4232 | } | |
4233 | ||
4234 | TheAISContext()->CloseAllContexts(); | |
4235 | ||
4236 | // Get and check values | |
4237 | TCollection_AsciiString aName(argv[1]); | |
4238 | ||
4239 | Handle(AIS_Point) aPoint1, aPoint2, aPoint3; | |
4240 | if (!IsPoint(argv[2], aPoint1)) | |
4241 | { | |
4242 | std::cout<<"vtriangle error: the 2nd argument must be a point\n"; | |
4243 | return 1; // TCL_ERROR | |
4244 | } | |
4245 | if (!IsPoint(argv[3], aPoint2)) | |
4246 | { | |
4247 | std::cout<<"vtriangle error: the 3d argument must be a point\n"; | |
4248 | return 1; // TCL_ERROR | |
4249 | } | |
4250 | if (!IsPoint(argv[4], aPoint3)) | |
4251 | { | |
4252 | std::cout<<"vtriangle error: the 4th argument must be a point\n"; | |
4253 | return 1; // TCL_ERROR | |
4254 | } | |
4255 | ||
4256 | // Check that points are different | |
4257 | Handle(Geom_CartesianPoint) aCartPoint1 = | |
4258 | Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component()); | |
4259 | Handle(Geom_CartesianPoint) aCartPoint2 = | |
4260 | Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component()); | |
4261 | // Test aPoint1 = aPoint2 | |
4262 | if (IsMatch(aCartPoint1, aCartPoint2)) | |
4263 | { | |
4264 | std::cout<<"vtriangle error: the 1st and the 2nd points are equal\n"; | |
4265 | return 1; // TCL_ERROR | |
4266 | } | |
4267 | // Test aPoint2 = aPoint3 | |
4268 | Handle(Geom_CartesianPoint) aCartPoint3 = | |
4269 | Handle(Geom_CartesianPoint)::DownCast(aPoint3->Component()); | |
4270 | if (IsMatch(aCartPoint2, aCartPoint3)) | |
4271 | { | |
4272 | std::cout<<"vtriangle error: the 2nd and the 3d points are equal\n"; | |
4273 | return 1; // TCL_ERROR | |
4274 | } | |
4275 | // Test aPoint3 = aPoint1 | |
4276 | if (IsMatch(aCartPoint1, aCartPoint3)) | |
4277 | { | |
4278 | std::cout<<"vtriangle error: the 1st and the 3d points are equal\n"; | |
4279 | return 1; // TCL_ERROR | |
4280 | } | |
4281 | ||
4282 | // Create triangle | |
4283 | Handle(Triangle) aTriangle = new Triangle(aCartPoint1->Pnt(), | |
4284 | aCartPoint2->Pnt(), | |
4285 | aCartPoint3->Pnt()); | |
4286 | ||
4287 | // Check if there is an object with given name | |
4288 | // and remove it from context | |
4289 | if (GetMapOfAIS().IsBound2(aName)) | |
4290 | { | |
4291 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName); | |
4292 | Handle(AIS_InteractiveObject) anInterObj = | |
4293 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
4294 | TheAISContext()->Remove(anInterObj, Standard_False); | |
4295 | GetMapOfAIS().UnBind2(aName); | |
4296 | } | |
4297 | ||
4298 | // Bind triangle to its name | |
4299 | GetMapOfAIS().Bind(aTriangle, aName); | |
4300 | ||
4301 | // Display triangle | |
4302 | TheAISContext()->Display(aTriangle); | |
4303 | return 0; | |
4304 | } | |
4305 | ||
4306 | //class : SegmentObject | |
4307 | //purpose: creates segment based on AIS_InteractiveObject. | |
4308 | // This class was implemented for testing Select3D_SensitiveCurve | |
4309 | DEFINE_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject) | |
4310 | class SegmentObject: public AIS_InteractiveObject | |
4311 | { | |
4312 | public: | |
4313 | // CASCADE RTTI | |
4314 | DEFINE_STANDARD_RTTI(SegmentObject); | |
4315 | SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2); | |
4316 | protected: | |
4317 | void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
4318 | const Handle(Prs3d_Presentation)& thePresentation, | |
4319 | const Standard_Integer theMode); | |
4320 | ||
4321 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
4322 | const Standard_Integer theMode); | |
4323 | private: | |
4324 | gp_Pnt myPoint1; | |
4325 | gp_Pnt myPoint2; | |
4326 | }; | |
4327 | IMPLEMENT_STANDARD_HANDLE(SegmentObject, AIS_InteractiveObject) | |
4328 | IMPLEMENT_STANDARD_RTTIEXT(SegmentObject, AIS_InteractiveObject) | |
4329 | ||
4330 | SegmentObject::SegmentObject (const gp_Pnt& thePnt1, const gp_Pnt& thePnt2) | |
4331 | { | |
4332 | myPoint1 = thePnt1; | |
4333 | myPoint2 = thePnt2; | |
4334 | } | |
4335 | ||
857ffd5e | 4336 | void SegmentObject::Compute (const Handle(PrsMgr_PresentationManager3d) &/*thePresentationManager*/, |
4337 | const Handle(Prs3d_Presentation) &thePresentation, | |
35e08fe8 | 4338 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4339 | { |
4340 | thePresentation->Clear(); | |
4341 | BRepBuilderAPI_MakeEdge anEdgeMaker(myPoint1, myPoint2); | |
4342 | TopoDS_Edge anEdge = anEdgeMaker.Edge(); | |
4343 | if (anEdge.IsNull()) | |
4344 | return; | |
4345 | BRepAdaptor_Curve aCurveAdaptor(anEdge); | |
4346 | StdPrs_Curve::Add(thePresentation, aCurveAdaptor, myDrawer); | |
4347 | } | |
4348 | ||
857ffd5e | 4349 | void SegmentObject::ComputeSelection (const Handle(SelectMgr_Selection) &theSelection, |
35e08fe8 | 4350 | const Standard_Integer /*theMode*/) |
ceae62f0 A |
4351 | { |
4352 | Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner(this); | |
4353 | Handle(TColgp_HArray1OfPnt) anArray = new TColgp_HArray1OfPnt(1, 2); | |
4354 | anArray->SetValue(1, myPoint1); | |
4355 | anArray->SetValue(2, myPoint2); | |
4356 | Handle(Select3D_SensitiveCurve) aSensCurve = | |
4357 | new Select3D_SensitiveCurve(anOwner, anArray); | |
4358 | theSelection->Add(aSensCurve); | |
4359 | } | |
4360 | ||
4361 | //======================================================================= | |
4362 | //function : VSegment | |
4363 | //Draw args : vsegment Name PointName PointName | |
4364 | //purpose : creates and displays Segment | |
4365 | //======================================================================= | |
35e08fe8 | 4366 | static Standard_Integer VSegment (Draw_Interpretor& /*di*/, |
ceae62f0 A |
4367 | Standard_Integer argc, |
4368 | const char ** argv) | |
4369 | { | |
4370 | // Check arguments | |
4371 | if(argc!=4) | |
4372 | { | |
4373 | std::cout<<"vsegment error: expects 3 arguments\n"; | |
4374 | return 1; // TCL_ERROR | |
4375 | } | |
4376 | ||
4377 | TheAISContext()->CloseAllContexts(); | |
4378 | ||
4379 | // Get and check arguments | |
4380 | TCollection_AsciiString aName(argv[1]); | |
4381 | Handle(AIS_Point) aPoint1, aPoint2; | |
4382 | if (!IsPoint(argv[2], aPoint1)) | |
4383 | { | |
4384 | std::cout<<"vsegment error: the 2nd argument should be a point\n"; | |
4385 | return 1; // TCL_ERROR | |
4386 | } | |
4387 | if (!IsPoint(argv[3], aPoint2)) | |
4388 | { | |
4389 | std::cout<<"vsegment error: the 3d argument should be a point\n"; | |
4390 | return 1; // TCL_ERROR | |
4391 | } | |
4392 | //Check that points are different | |
4393 | Handle(Geom_CartesianPoint) aCartPoint1 = | |
4394 | Handle(Geom_CartesianPoint)::DownCast(aPoint1->Component()); | |
4395 | Handle(Geom_CartesianPoint) aCartPoint2 = | |
4396 | Handle(Geom_CartesianPoint)::DownCast(aPoint2->Component()); | |
4397 | if(IsMatch(aCartPoint1, aCartPoint2)) | |
4398 | { | |
4399 | std::cout<<"vsegment error: equal points\n"; | |
4400 | return 1; // TCL_ERROR | |
4401 | } | |
4402 | ||
4403 | // Create segment | |
4404 | Handle(SegmentObject) aSegment = new SegmentObject(aCartPoint1->Pnt(), aCartPoint2->Pnt()); | |
4405 | // Check if there is an object with given name | |
4406 | // and remove it from context | |
4407 | if (GetMapOfAIS().IsBound2(aName)) | |
4408 | { | |
4409 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(aName); | |
4410 | Handle(AIS_InteractiveObject) anInterObj = | |
4411 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
4412 | TheAISContext()->Remove(anInterObj, Standard_False); | |
4413 | GetMapOfAIS().UnBind2(aName); | |
4414 | } | |
4415 | ||
4416 | // Bind segment to its name | |
4417 | GetMapOfAIS().Bind(aSegment, aName); | |
4418 | ||
4419 | // Display segment | |
4420 | TheAISContext()->Display(aSegment); | |
4421 | return 0; | |
4422 | } | |
4423 | ||
59f45b7c | 4424 | //======================================================================= |
4425 | //function : VObjZLayer | |
4426 | //purpose : Set or get z layer id for presentable object | |
4427 | //======================================================================= | |
4428 | ||
4429 | static Standard_Integer VObjZLayer (Draw_Interpretor& di, | |
4430 | Standard_Integer argc, | |
4431 | const char ** argv) | |
4432 | { | |
4433 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4434 | if (aContext.IsNull()) | |
4435 | { | |
4436 | di << argv[0] << "Call 'vinit' before!\n"; | |
4437 | return 1; | |
4438 | } | |
4439 | ||
4440 | // get operation | |
4441 | TCollection_AsciiString aOperation; | |
4442 | if (argc >= 2) | |
4443 | aOperation = TCollection_AsciiString (argv [1]); | |
4444 | ||
4445 | // check for correct arguments | |
4446 | if (!(argc == 4 && aOperation.IsEqual ("set")) && | |
4447 | !(argc == 3 && aOperation.IsEqual ("get"))) | |
4448 | { | |
4449 | di << "Usage : " << argv[0] << " set/get object [layerid]\n"; | |
4450 | di << " set - set layer id for interactive object, layerid - z layer id\n"; | |
4451 | di << " get - get layer id of interactive object\n"; | |
4452 | di << " argument layerid should be passed for set operation only\n"; | |
4453 | return 1; | |
4454 | } | |
4455 | ||
4456 | // find object | |
4457 | TCollection_AsciiString aName (argv[2]); | |
4458 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4459 | if (!aMap.IsBound2 (aName)) | |
4460 | { | |
4461 | di << "Use 'vdisplay' before" << "\n"; | |
4462 | return 1; | |
4463 | } | |
4464 | ||
4465 | // find interactive object | |
4466 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); | |
4467 | Handle(AIS_InteractiveObject) anInterObj = | |
4468 | Handle(AIS_InteractiveObject)::DownCast (anObj); | |
4469 | if (anInterObj.IsNull()) | |
4470 | { | |
4471 | di << "Not an AIS interactive object!\n"; | |
4472 | return 1; | |
4473 | } | |
4474 | ||
4475 | // process operation | |
4476 | if (aOperation.IsEqual ("set")) | |
4477 | { | |
91322f44 | 4478 | Standard_Integer aLayerId = Draw::Atoi (argv [3]); |
59f45b7c | 4479 | aContext->SetZLayer (anInterObj, aLayerId); |
4480 | } | |
4481 | else if (aOperation.IsEqual ("get")) | |
4482 | { | |
4483 | di << "Z layer id: " << aContext->GetZLayer (anInterObj); | |
4484 | } | |
4485 | ||
4486 | return 0; | |
4487 | } | |
4488 | ||
3ddebf91 | 4489 | //======================================================================= |
4490 | //function : VPolygonOffset | |
4491 | //purpose : Set or get polygon offset parameters | |
4492 | //======================================================================= | |
35e08fe8 | 4493 | static Standard_Integer VPolygonOffset(Draw_Interpretor& /*di*/, |
3ddebf91 | 4494 | Standard_Integer argc, |
4495 | const char ** argv) | |
4496 | { | |
4497 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4498 | if (aContext.IsNull()) | |
4499 | { | |
4500 | std::cout << argv[0] << " Call 'vinit' before!\n"; | |
4501 | return 1; | |
4502 | } | |
4503 | ||
4504 | if (argc > 2 && argc != 5) | |
4505 | { | |
4506 | std::cout << "Usage : " << argv[0] << " [object [mode factor units]] - sets/gets polygon offset parameters for an object," | |
4507 | "without arguments prints the default values" << std::endl; | |
4508 | return 1; | |
4509 | } | |
4510 | ||
4511 | // find object | |
4512 | Handle(AIS_InteractiveObject) anInterObj; | |
4513 | if (argc >= 2) | |
4514 | { | |
4515 | TCollection_AsciiString aName (argv[1]); | |
4516 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS(); | |
4517 | if (!aMap.IsBound2 (aName)) | |
4518 | { | |
4519 | std::cout << "Use 'vdisplay' before" << std::endl; | |
4520 | return 1; | |
4521 | } | |
4522 | ||
4523 | // find interactive object | |
4524 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aName); | |
4525 | anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
4526 | if (anInterObj.IsNull()) | |
4527 | { | |
4528 | std::cout << "Not an AIS interactive object!" << std::endl; | |
4529 | return 1; | |
4530 | } | |
4531 | } | |
4532 | ||
4533 | Standard_Integer aMode; | |
60be1f9b | 4534 | Standard_ShortReal aFactor, aUnits; |
3ddebf91 | 4535 | if (argc == 5) |
4536 | { | |
91322f44 | 4537 | aMode = Draw::Atoi(argv[2]); |
4538 | aFactor = (Standard_ShortReal) Draw::Atof(argv[3]); | |
4539 | aUnits = (Standard_ShortReal) Draw::Atof(argv[4]); | |
3ddebf91 | 4540 | |
4541 | anInterObj->SetPolygonOffsets(aMode, aFactor, aUnits); | |
4542 | aContext->UpdateCurrentViewer(); | |
4543 | return 0; | |
4544 | } | |
4545 | else if (argc == 2) | |
4546 | { | |
4547 | if (anInterObj->HasPolygonOffsets()) | |
4548 | { | |
4549 | anInterObj->PolygonOffsets(aMode, aFactor, aUnits); | |
4550 | std::cout << "Current polygon offset parameters for " << argv[1] << ":" << std::endl; | |
4551 | std::cout << "\tMode: " << aMode << std::endl; | |
4552 | std::cout << "\tFactor: " << aFactor << std::endl; | |
4553 | std::cout << "\tUnits: " << aUnits << std::endl; | |
4554 | return 0; | |
4555 | } | |
4556 | else | |
4557 | { | |
4558 | std::cout << "Specific polygon offset parameters are not set for " << argv[1] << std::endl; | |
4559 | } | |
4560 | } | |
4561 | ||
4562 | std::cout << "Default polygon offset parameters:" << std::endl; | |
4563 | aContext->DefaultDrawer()->ShadingAspect()->Aspect()->PolygonOffsets(aMode, aFactor, aUnits); | |
4564 | std::cout << "\tMode: " << aMode << std::endl; | |
4565 | std::cout << "\tFactor: " << aFactor << std::endl; | |
4566 | std::cout << "\tUnits: " << aUnits << std::endl; | |
4567 | ||
4568 | return 0; | |
4569 | } | |
4570 | ||
a2d5ab2e | 4571 | //======================================================================= |
4572 | //function : VShowFaceBoundaries | |
4573 | //purpose : Set face boundaries drawing on/off for ais object | |
4574 | //======================================================================= | |
35e08fe8 | 4575 | static Standard_Integer VShowFaceBoundary (Draw_Interpretor& /*di*/, |
a2d5ab2e | 4576 | Standard_Integer argc, |
4577 | const char ** argv) | |
4578 | { | |
4579 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext (); | |
4580 | if (aContext.IsNull ()) | |
4581 | { | |
4582 | std::cout << argv[0] << " Call 'vinit' before!\n"; | |
4583 | return 1; | |
4584 | } | |
4585 | ||
4586 | if ((argc != 3 && argc < 6) || argc > 8) | |
4587 | { | |
4588 | std::cout << "Usage :\n " << argv[0] | |
4589 | << " ObjectName isOn [R G B [LineWidth [LineStyle]]]\n" | |
4590 | << " ObjectName - name of AIS interactive object. \n" | |
4591 | << " if ObjectName = \"\", then set as default\n" | |
4592 | << " settings for all newly displayed objects\n" | |
4593 | << " isOn - flag indicating whether the boundaries\n" | |
4594 | << " should be turned on or off (can be set\n" | |
4595 | << " to 0 (off) or 1 (on)).\n" | |
4596 | << " R, G, B - red, green and blue components of boundary\n" | |
4597 | << " color in range (0 - 255).\n" | |
4598 | << " (default is (0, 0, 0)\n" | |
4599 | << " LineWidth - line width\n" | |
4600 | << " (default is 1)\n" | |
4601 | << " LineStyle - line fill style :\n" | |
4602 | << " 0 - solid \n" | |
4603 | << " 1 - dashed \n" | |
4604 | << " 2 - dot \n" | |
4605 | << " 3 - dashdot\n" | |
4606 | << " (default is solid)"; | |
4607 | return 1; | |
4608 | } | |
4609 | ||
4610 | TCollection_AsciiString aName (argv[1]); | |
4611 | ||
4612 | Quantity_Parameter aRed = 0.0; | |
4613 | Quantity_Parameter aGreen = 0.0; | |
4614 | Quantity_Parameter aBlue = 0.0; | |
4615 | Standard_Real aWidth = 1.0; | |
4616 | Aspect_TypeOfLine aLineType = Aspect_TOL_SOLID; | |
4617 | ||
4618 | // find object | |
4619 | Handle(AIS_InteractiveObject) anInterObj; | |
4620 | ||
4621 | // if name is empty - apply attributes for default aspect | |
4622 | if (!aName.IsEmpty ()) | |
4623 | { | |
4624 | ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS (); | |
4625 | if (!aMap.IsBound2 (aName)) | |
4626 | { | |
4627 | std::cout << "Use 'vdisplay' on " << aName << " before" << std::endl; | |
4628 | return 1; | |
4629 | } | |
4630 | ||
4631 | // find interactive object | |
4632 | Handle(Standard_Transient) anObj = GetMapOfAIS ().Find2 (aName); | |
4633 | anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
4634 | if (anInterObj.IsNull ()) | |
4635 | { | |
4636 | std::cout << "Not an AIS interactive object!" << std::endl; | |
4637 | return 1; | |
4638 | } | |
4639 | } | |
4640 | ||
4641 | const Handle(Prs3d_Drawer)& aDrawer = (aName.IsEmpty ()) ? | |
4642 | TheAISContext ()->DefaultDrawer () : anInterObj->Attributes (); | |
4643 | ||
4644 | // turn boundaries on/off | |
91322f44 | 4645 | Standard_Boolean isBoundaryDraw = (Draw::Atoi (argv[2]) == 1); |
a2d5ab2e | 4646 | aDrawer->SetFaceBoundaryDraw (isBoundaryDraw); |
4647 | ||
4648 | // set boundary line color | |
4649 | if (argc >= 6) | |
4650 | { | |
4651 | // Text color | |
91322f44 | 4652 | aRed = Draw::Atof (argv[3])/255.; |
4653 | aGreen = Draw::Atof (argv[4])/255.; | |
4654 | aBlue = Draw::Atof (argv[5])/255.; | |
a2d5ab2e | 4655 | } |
4656 | ||
4657 | // set line width | |
4658 | if (argc >= 7) | |
4659 | { | |
91322f44 | 4660 | aWidth = (Standard_Real)Draw::Atof (argv[6]); |
a2d5ab2e | 4661 | } |
4662 | ||
4663 | // select appropriate line type | |
4664 | if (argc == 8) | |
4665 | { | |
91322f44 | 4666 | switch (Draw::Atoi (argv[7])) |
a2d5ab2e | 4667 | { |
4668 | case 1: aLineType = Aspect_TOL_DASH; break; | |
4669 | case 2: aLineType = Aspect_TOL_DOT; break; | |
4670 | case 3: aLineType = Aspect_TOL_DOTDASH; break; | |
4671 | default: | |
4672 | aLineType = Aspect_TOL_SOLID; | |
4673 | } | |
4674 | } | |
4675 | ||
4676 | Quantity_Color aColor (aRed, aGreen, aBlue, Quantity_TOC_RGB); | |
4677 | ||
4678 | Handle(Prs3d_LineAspect) aBoundaryAspect = | |
4679 | new Prs3d_LineAspect (aColor, aLineType, aWidth); | |
4680 | ||
4681 | aDrawer->SetFaceBoundaryAspect (aBoundaryAspect); | |
4682 | ||
4683 | TheAISContext()->Redisplay (anInterObj); | |
4684 | ||
4685 | return 0; | |
4686 | } | |
4687 | ||
eb4320f2 | 4688 | // This class is used for testing markers. |
4689 | DEFINE_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject) | |
4690 | class ViewerTest_MarkersArrayObject : public AIS_InteractiveObject | |
4691 | { | |
4692 | ||
4693 | public: | |
4694 | ||
4695 | ViewerTest_MarkersArrayObject (const gp_XYZ& theStartPoint, | |
4696 | const Standard_Integer& thePointsOnSide, | |
4697 | Handle(Graphic3d_AspectMarker3d) theMarkerAspect = NULL) | |
4698 | { | |
4699 | myStartPoint = theStartPoint; | |
4700 | myPointsOnSide = thePointsOnSide; | |
4701 | myMarkerAspect = theMarkerAspect; | |
4702 | } | |
4703 | ||
4704 | DEFINE_STANDARD_RTTI(MyPArrayObject); | |
4705 | ||
4706 | private: | |
4707 | ||
4708 | void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
4709 | const Handle(Prs3d_Presentation)& aPresentation, | |
4710 | const Standard_Integer aMode); | |
4711 | ||
4712 | void ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
4713 | const Standard_Integer /*theMode*/); | |
4714 | ||
4715 | protected: | |
4716 | ||
4717 | gp_XYZ myStartPoint; | |
4718 | Standard_Integer myPointsOnSide; | |
4719 | Handle(Graphic3d_AspectMarker3d) myMarkerAspect; | |
4720 | }; | |
4721 | ||
4722 | IMPLEMENT_STANDARD_HANDLE(ViewerTest_MarkersArrayObject, AIS_InteractiveObject) | |
4723 | IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_MarkersArrayObject, AIS_InteractiveObject) | |
4724 | ||
4725 | void ViewerTest_MarkersArrayObject::Compute (const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/, | |
4726 | const Handle(Prs3d_Presentation)& aPresentation, | |
4727 | const Standard_Integer /*aMode*/) | |
4728 | { | |
4729 | Handle(Graphic3d_ArrayOfPrimitives) anArray = new Graphic3d_ArrayOfPoints ((Standard_Integer )Pow (myPointsOnSide, 3), myPointsOnSide != 1); | |
4730 | if (myPointsOnSide == 1) | |
4731 | { | |
4732 | anArray->AddVertex (myStartPoint); | |
4733 | } | |
4734 | else | |
4735 | { | |
4736 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
4737 | { | |
4738 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
4739 | { | |
4740 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
4741 | { | |
4742 | anArray->AddVertex (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
4743 | anArray->SetVertexColor (anArray->VertexNumber(), | |
4744 | i / myPointsOnSide, | |
4745 | j / myPointsOnSide, | |
4746 | k / myPointsOnSide); | |
4747 | } | |
4748 | } | |
4749 | } | |
4750 | } | |
4751 | ||
4752 | aPresentation->Clear(); | |
4753 | if (!myMarkerAspect.IsNull()) | |
4754 | { | |
4755 | Prs3d_Root::CurrentGroup (aPresentation)->SetGroupPrimitivesAspect (myMarkerAspect); | |
4756 | } | |
4757 | Prs3d_Root::CurrentGroup (aPresentation)->AddPrimitiveArray (anArray); | |
4758 | } | |
4759 | ||
4760 | void ViewerTest_MarkersArrayObject::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection, | |
4761 | const Standard_Integer /*theMode*/) | |
4762 | { | |
4763 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner (this); | |
4764 | ||
4765 | if (myPointsOnSide == 1) | |
4766 | { | |
4767 | gp_Pnt aPoint (myStartPoint); | |
4768 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
4769 | theSelection->Add (aSensetivePoint); | |
4770 | } | |
4771 | else | |
4772 | { | |
4773 | for (Standard_Real i = 1; i <= myPointsOnSide; i++) | |
4774 | { | |
4775 | for (Standard_Real j = 1; j <= myPointsOnSide; j++) | |
4776 | { | |
4777 | for (Standard_Real k = 1; k <= myPointsOnSide; k++) | |
4778 | { | |
4779 | gp_Pnt aPoint (myStartPoint.X() + i, myStartPoint.Y() + j, myStartPoint.Z() + k); | |
4780 | Handle(Select3D_SensitivePoint) aSensetivePoint = new Select3D_SensitivePoint (anEntityOwner, aPoint); | |
4781 | theSelection->Add (aSensetivePoint); | |
4782 | } | |
4783 | } | |
4784 | } | |
4785 | } | |
4786 | } | |
a577aaab | 4787 | //======================================================================= |
4788 | //function : VMarkersTest | |
4789 | //purpose : Draws an array of markers for testing purposes. | |
4790 | //======================================================================= | |
498ce76b | 4791 | static Standard_Integer VMarkersTest (Draw_Interpretor&, |
a577aaab | 4792 | Standard_Integer theArgNb, |
4793 | const char** theArgVec) | |
4794 | { | |
4795 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
4796 | if (aContext.IsNull()) | |
4797 | { | |
4798 | std::cerr << "Call 'vinit' before!\n"; | |
4799 | return 1; | |
4800 | } | |
4801 | ||
4802 | if (theArgNb < 5) | |
4803 | { | |
4804 | std::cerr << "Usage :\n " << theArgVec[0] | |
4805 | << "name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n"; | |
4806 | return 1; | |
4807 | } | |
4808 | ||
4809 | Standard_Integer anArgIter = 1; | |
4810 | ||
4811 | TCollection_AsciiString aName (theArgVec[anArgIter++]); | |
4812 | TCollection_AsciiString aFileName; | |
4813 | gp_XYZ aPnt (Atof (theArgVec[anArgIter]), | |
4814 | Atof (theArgVec[anArgIter + 1]), | |
4815 | Atof (theArgVec[anArgIter + 2])); | |
4816 | anArgIter += 3; | |
4817 | ||
4818 | Standard_Integer aPointsOnSide = 10; | |
4819 | Standard_Integer aMarkerType = -1; | |
4820 | Standard_Real aScale = 1.0; | |
4821 | for (; anArgIter < theArgNb; ++anArgIter) | |
4822 | { | |
4823 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
4824 | if (anArg.Search ("PointsOnSide=") > -1) | |
4825 | { | |
4826 | aPointsOnSide = anArg.Token ("=", 2).IntegerValue(); | |
4827 | } | |
4828 | else if (anArg.Search ("MarkerType=") > -1) | |
4829 | { | |
4830 | aMarkerType = anArg.Token ("=", 2).IntegerValue(); | |
4831 | } | |
4832 | else if (anArg.Search ("Scale=") > -1) | |
4833 | { | |
4834 | aScale = anArg.Token ("=", 2).RealValue(); | |
4835 | } | |
4836 | else if (anArg.Search ("FileName=") > -1) | |
4837 | { | |
4838 | aFileName = anArg.Token ("=", 2); | |
4839 | } | |
4840 | else | |
4841 | { | |
4842 | std::cerr << "Wrong argument: " << anArg << "\n"; | |
4843 | return 1; | |
4844 | } | |
4845 | } | |
4846 | ||
4847 | Handle(Graphic3d_AspectMarker3d) anAspect; | |
4848 | Handle(Image_AlienPixMap) anImage; | |
4849 | Quantity_Color aColor (Quantity_NOC_GREEN1); | |
4850 | if ((aMarkerType == Aspect_TOM_USERDEFINED || aMarkerType < 0) | |
4851 | && !aFileName.IsEmpty()) | |
4852 | { | |
4853 | anImage = new Image_AlienPixMap(); | |
4854 | if (!anImage->Load (aFileName)) | |
4855 | { | |
4856 | std::cerr << "Could not load image from file '" << aFileName << "'!\n"; | |
4857 | return 1; | |
4858 | } | |
4859 | anAspect = new Graphic3d_AspectMarker3d (anImage); | |
4860 | } | |
4861 | else | |
4862 | { | |
4863 | anAspect = new Graphic3d_AspectMarker3d (aMarkerType >= 0 ? (Aspect_TypeOfMarker )aMarkerType : Aspect_TOM_POINT, aColor, aScale); | |
4864 | } | |
4865 | ||
eb4320f2 | 4866 | Handle(ViewerTest_MarkersArrayObject) aMarkersArray = new ViewerTest_MarkersArrayObject (aPnt, aPointsOnSide, anAspect); |
4867 | VDisplayAISObject (aName, aMarkersArray); | |
a577aaab | 4868 | |
4869 | return 0; | |
4870 | } | |
4871 | ||
725ef85e | 4872 | //! Auxiliary function to parse font aspect style argument |
4873 | static Standard_Boolean parseFontStyle (const TCollection_AsciiString& theArg, | |
4874 | Font_FontAspect& theAspect) | |
4875 | { | |
4876 | if (theArg == "regular" | |
4877 | || *theArg.ToCString() == 'r') | |
4878 | { | |
4879 | theAspect = Font_FA_Regular; | |
4880 | return Standard_True; | |
4881 | } | |
4882 | else if (theArg == "bolditalic") | |
4883 | { | |
4884 | theAspect = Font_FA_BoldItalic; | |
4885 | return Standard_True; | |
4886 | } | |
4887 | else if (theArg == "bold" | |
4888 | || *theArg.ToCString() == 'b') | |
4889 | { | |
4890 | theAspect = Font_FA_Bold; | |
4891 | return Standard_True; | |
4892 | } | |
4893 | else if (theArg == "italic" | |
4894 | || *theArg.ToCString() == 'i') | |
4895 | { | |
4896 | theAspect = Font_FA_Italic; | |
4897 | return Standard_True; | |
4898 | } | |
4899 | return Standard_False; | |
4900 | } | |
4901 | ||
4902 | //! Auxiliary function | |
4903 | static TCollection_AsciiString fontStyleString (const Font_FontAspect theAspect) | |
4904 | { | |
4905 | switch (theAspect) | |
4906 | { | |
4907 | case Font_FA_Regular: return "regular"; | |
4908 | case Font_FA_BoldItalic: return "bolditalic"; | |
4909 | case Font_FA_Bold: return "bold"; | |
4910 | case Font_FA_Italic: return "italic"; | |
4911 | default: return "undefined"; | |
4912 | } | |
4913 | } | |
4914 | ||
b514beda | 4915 | //======================================================================= |
4916 | //function : TextToBrep | |
4917 | //purpose : Tool for conversion text to occt-shapes | |
4918 | //======================================================================= | |
4919 | ||
4920 | static int TextToBRep (Draw_Interpretor& /*theDI*/, | |
4921 | Standard_Integer theArgNb, | |
4922 | const char** theArgVec) | |
4923 | { | |
4924 | // Check arguments | |
4925 | if (theArgNb < 5) | |
4926 | { | |
4927 | std::cerr << "Error: " << theArgVec[0] << " - invalid syntax\n"; | |
4928 | return 1; | |
4929 | } | |
4930 | ||
4931 | Standard_Integer anArgIter = 1; | |
4932 | Standard_CString aResName = theArgVec[anArgIter++]; | |
4933 | Standard_CString aText = theArgVec[anArgIter++]; | |
4934 | Standard_CString aFontName = theArgVec[anArgIter++]; | |
4935 | const Standard_Real aSize = Atof (theArgVec[anArgIter++]); | |
4936 | ||
4937 | Font_BRepFont aFont; | |
4938 | Font_FontAspect aFontAspect = Font_FA_Regular; | |
4939 | Standard_Boolean isCompositeCurve = Standard_False; | |
4940 | gp_Ax3 aPenAx3 (gp::XOY()); | |
4941 | gp_Pnt aPenLoc; | |
4942 | while (anArgIter < theArgNb) | |
4943 | { | |
4944 | const TCollection_AsciiString anArg (theArgVec[anArgIter++]); | |
725ef85e | 4945 | TCollection_AsciiString anArgCase (anArg); |
4946 | anArgCase.LowerCase(); | |
4947 | if (anArgCase.Search ("x=") > -1) | |
b514beda | 4948 | { |
4949 | aPenLoc.SetX (anArg.Token ("=", 2).RealValue()); | |
4950 | } | |
725ef85e | 4951 | else if (anArgCase.Search ("y=") > -1) |
b514beda | 4952 | { |
4953 | aPenLoc.SetY (anArg.Token ("=", 2).RealValue()); | |
4954 | } | |
725ef85e | 4955 | else if (anArgCase.Search ("z=") > -1) |
b514beda | 4956 | { |
4957 | aPenLoc.SetZ (anArg.Token ("=", 2).RealValue()); | |
4958 | } | |
725ef85e | 4959 | else if (anArgCase.Search ("composite=") > -1) |
b514beda | 4960 | { |
4961 | isCompositeCurve = (anArg.Token ("=", 2).IntegerValue() == 1); | |
4962 | } | |
725ef85e | 4963 | else if (parseFontStyle (anArgCase, aFontAspect)) |
b514beda | 4964 | { |
725ef85e | 4965 | // |
b514beda | 4966 | } |
4967 | else | |
4968 | { | |
4969 | std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n"; | |
4970 | } | |
4971 | } | |
4972 | ||
4973 | aFont.SetCompositeCurveMode (isCompositeCurve); | |
4974 | if (!aFont.Init (aFontName, aFontAspect, aSize)) | |
4975 | { | |
4976 | std::cerr << "Font initialization error\n"; | |
4977 | return 1; | |
4978 | } | |
4979 | ||
4980 | aPenAx3.SetLocation (aPenLoc); | |
4981 | DBRep::Set (aResName, aFont.RenderText (aText, aPenAx3)); | |
4982 | return 0; | |
4983 | } | |
4984 | ||
725ef85e | 4985 | //======================================================================= |
4986 | //function : VFont | |
4987 | //purpose : Font management | |
4988 | //======================================================================= | |
4989 | ||
4990 | static int VFont (Draw_Interpretor& theDI, | |
4991 | Standard_Integer theArgNb, | |
4992 | const char** theArgVec) | |
4993 | { | |
4994 | Handle(Font_FontMgr) aMgr = Font_FontMgr::GetInstance(); | |
4995 | if (theArgNb < 2) | |
4996 | { | |
4997 | // just print the list of available fonts | |
4998 | Standard_Boolean isFirst = Standard_True; | |
4999 | for (Font_NListOfSystemFont::Iterator anIter (aMgr->GetAvailableFonts()); | |
5000 | anIter.More(); anIter.Next()) | |
5001 | { | |
5002 | const Handle(Font_SystemFont)& aFont = anIter.Value(); | |
5003 | if (!isFirst) | |
5004 | { | |
5005 | theDI << "\n"; | |
5006 | } | |
5007 | ||
5008 | theDI << aFont->FontName()->String() | |
5009 | << " " << fontStyleString (aFont->FontAspect()) | |
5010 | << " " << aFont->FontPath()->String(); | |
5011 | isFirst = Standard_False; | |
5012 | } | |
5013 | return 0; | |
5014 | } | |
5015 | ||
5016 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) | |
5017 | { | |
5018 | const TCollection_AsciiString anArg (theArgVec[anArgIter]); | |
5019 | TCollection_AsciiString anArgCase (anArg); | |
5020 | anArgCase.LowerCase(); | |
5021 | if (anArgCase == "find") | |
5022 | { | |
5023 | if (++anArgIter >= theArgNb) | |
5024 | { | |
5025 | std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n"; | |
5026 | return 1; | |
5027 | } | |
5028 | ||
5029 | Standard_CString aFontName = theArgVec[anArgIter]; | |
5030 | Font_FontAspect aFontAspect = Font_FA_Undefined; | |
5031 | if (++anArgIter < theArgNb) | |
5032 | { | |
5033 | anArgCase = theArgVec[anArgIter]; | |
5034 | anArgCase.LowerCase(); | |
5035 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5036 | { | |
5037 | --anArgIter; | |
5038 | } | |
5039 | } | |
5040 | Handle(Font_SystemFont) aFont = aMgr->FindFont (new TCollection_HAsciiString (aFontName), aFontAspect, -1); | |
5041 | if (aFont.IsNull()) | |
5042 | { | |
5043 | std::cerr << "Error: font '" << aFontName << "' is not found!\n"; | |
5044 | continue; | |
5045 | } | |
5046 | ||
5047 | theDI << aFont->FontName()->String() | |
5048 | << " " << fontStyleString (aFont->FontAspect()) | |
5049 | << " " << aFont->FontPath()->String(); | |
5050 | } | |
5051 | else if (anArgCase == "add" | |
5052 | || anArgCase == "register") | |
5053 | { | |
5054 | if (++anArgIter >= theArgNb) | |
5055 | { | |
5056 | std::cerr << "Wrong syntax at argument '" << anArg.ToCString() << "'!\n"; | |
5057 | return 1; | |
5058 | } | |
5059 | Standard_CString aFontPath = theArgVec[anArgIter]; | |
5060 | Standard_CString aFontName = NULL; | |
5061 | Font_FontAspect aFontAspect = Font_FA_Undefined; | |
5062 | if (++anArgIter < theArgNb) | |
5063 | { | |
5064 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5065 | { | |
5066 | aFontName = theArgVec[anArgIter]; | |
5067 | } | |
5068 | if (++anArgIter < theArgNb) | |
5069 | { | |
5070 | anArgCase = theArgVec[anArgIter]; | |
5071 | anArgCase.LowerCase(); | |
5072 | if (!parseFontStyle (anArgCase, aFontAspect)) | |
5073 | { | |
5074 | --anArgIter; | |
5075 | } | |
5076 | } | |
5077 | } | |
5078 | ||
5079 | Handle(Font_SystemFont) aFont = aMgr->CheckFont (aFontPath); | |
5080 | if (aFont.IsNull()) | |
5081 | { | |
5082 | std::cerr << "Error: font '" << aFontPath << "' is not found!\n"; | |
5083 | continue; | |
5084 | } | |
5085 | ||
5086 | if (aFontAspect != Font_FA_Undefined | |
5087 | || aFontName != NULL) | |
5088 | { | |
5089 | if (aFontAspect == Font_FA_Undefined) | |
5090 | { | |
5091 | aFontAspect = aFont->FontAspect(); | |
5092 | } | |
5093 | Handle(TCollection_HAsciiString) aName = aFont->FontName(); | |
5094 | if (aFontName != NULL) | |
5095 | { | |
5096 | aName = new TCollection_HAsciiString (aFontName); | |
5097 | } | |
5098 | aFont = new Font_SystemFont (aName, aFontAspect, new TCollection_HAsciiString (aFontPath)); | |
5099 | } | |
5100 | ||
5101 | aMgr->RegisterFont (aFont, Standard_True); | |
5102 | theDI << aFont->FontName()->String() | |
5103 | << " " << fontStyleString (aFont->FontAspect()) | |
5104 | << " " << aFont->FontPath()->String(); | |
5105 | } | |
5106 | else | |
5107 | { | |
5108 | std::cerr << "Warning! Unknown argument '" << anArg.ToCString() << "'\n"; | |
5109 | } | |
5110 | } | |
5111 | ||
5112 | return 0; | |
5113 | } | |
5114 | ||
5ad539d2 | 5115 | //======================================================================= |
5116 | //function : VSetEdgeType | |
5117 | //purpose : Edges type management | |
5118 | //======================================================================= | |
5119 | ||
5120 | static int VSetEdgeType (Draw_Interpretor& theDI, | |
5121 | Standard_Integer theArgNum, | |
5122 | const char** theArgs) | |
5123 | { | |
5124 | if (theArgNum < 4 || theArgNum > 9) | |
5125 | { | |
5126 | theDI << theArgs[0] << " error: wrong number of parameters. Type 'help " | |
5127 | << theArgs[0] << "' for more information.\n"; | |
5128 | return 1; | |
5129 | } | |
5130 | ||
5131 | Standard_Boolean isForceRedisplay = Standard_False; | |
5132 | ||
5133 | // Get shape name | |
5134 | TCollection_AsciiString aName(theArgs[1]); | |
5135 | if (!GetMapOfAIS().IsBound2 (aName)) | |
5136 | { | |
5137 | theDI << theArgs[0] << " error: wrong object name.\n"; | |
5138 | return 1; | |
5139 | } | |
5140 | ||
5141 | Handle(AIS_InteractiveObject) anObject = | |
5142 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName)); | |
5143 | ||
5144 | // Enable trianle edge mode | |
5145 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOn(); | |
5146 | ||
5147 | // Parse parameters | |
5148 | for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt) | |
5149 | { | |
5150 | TCollection_AsciiString aParam ((theArgs[anIt])); | |
5151 | if (aParam.Value (1) == '-' && !aParam.IsRealValue()) | |
5152 | { | |
5153 | if (aParam.IsEqual ("-type")) | |
5154 | { | |
5155 | if (theArgNum <= anIt + 1) | |
5156 | { | |
5157 | theDI << theArgs[0] << " error: wrong number of values for parameter '" | |
5158 | << aParam.ToCString() << "'.\n"; | |
5159 | return 1; | |
5160 | } | |
5161 | ||
5162 | TCollection_AsciiString aType = theArgs[++anIt]; | |
5163 | aType.UpperCase(); | |
5164 | ||
5165 | if (aType.IsEqual ("SOLID")) | |
5166 | { | |
5167 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_SOLID); | |
5168 | } | |
5169 | else if (aType.IsEqual ("DASH")) | |
5170 | { | |
5171 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DASH); | |
5172 | } | |
5173 | else if (aType.IsEqual ("DOT")) | |
5174 | { | |
5175 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOT); | |
5176 | } | |
5177 | else if (aType.IsEqual ("DOTDASH")) | |
5178 | { | |
5179 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeLineType(Aspect_TOL_DOTDASH); | |
5180 | } | |
5181 | else | |
5182 | { | |
5183 | theDI << theArgs[0] << " error: wrong line type: '" << aType.ToCString() << "'.\n"; | |
5184 | return 1; | |
5185 | } | |
5186 | ||
5187 | } | |
5188 | else if (aParam.IsEqual ("-color")) | |
5189 | { | |
5190 | if (theArgNum <= anIt + 3) | |
5191 | { | |
5192 | theDI << theArgs[0] << " error: wrong number of values for parameter '" | |
5193 | << aParam.ToCString() << "'.\n"; | |
5194 | return 1; | |
5195 | } | |
5196 | ||
5197 | Quantity_Parameter aR = Draw::Atof(theArgs[++anIt]); | |
5198 | Quantity_Parameter aG = Draw::Atof(theArgs[++anIt]); | |
5199 | Quantity_Parameter aB = Draw::Atof(theArgs[++anIt]); | |
5200 | Quantity_Color aColor = Quantity_Color (aR > 1 ? aR / 255.0 : aR, | |
5201 | aG > 1 ? aG / 255.0 : aG, | |
5202 | aB > 1 ? aB / 255.0 : aB, | |
5203 | Quantity_TOC_RGB); | |
5204 | ||
5205 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeColor (aColor); | |
5206 | } | |
5207 | else if (aParam.IsEqual ("-force")) | |
5208 | { | |
5209 | isForceRedisplay = Standard_True; | |
5210 | } | |
5211 | else | |
5212 | { | |
5213 | theDI << theArgs[0] << " error: unknown parameter '" | |
5214 | << aParam.ToCString() << "'.\n"; | |
5215 | return 1; | |
5216 | } | |
5217 | } | |
5218 | } | |
5219 | ||
5220 | // Update shape presentation as aspect parameters were changed | |
5221 | if (isForceRedisplay) | |
5222 | { | |
5223 | ViewerTest::GetAISContext()->Redisplay (anObject); | |
5224 | } | |
5225 | else | |
5226 | { | |
5227 | anObject->SetAspect (anObject->Attributes()->ShadingAspect()); | |
5228 | } | |
5229 | ||
5230 | //Update view | |
5231 | ViewerTest::CurrentView()->Redraw(); | |
5232 | ||
5233 | return 0; | |
5234 | } | |
5235 | ||
5236 | //======================================================================= | |
5237 | //function : VUnsetEdgeType | |
5238 | //purpose : Unsets edges visibility in shading mode | |
5239 | //======================================================================= | |
5240 | ||
5241 | static int VUnsetEdgeType (Draw_Interpretor& theDI, | |
5242 | Standard_Integer theArgNum, | |
5243 | const char** theArgs) | |
5244 | { | |
5245 | if (theArgNum != 2 && theArgNum != 3) | |
5246 | { | |
5247 | theDI << theArgs[0] << " error: wrong number of parameters. Type 'help " | |
5248 | << theArgs[0] << "' for more information.\n"; | |
5249 | return 1; | |
5250 | } | |
5251 | ||
5252 | Standard_Boolean isForceRedisplay = Standard_False; | |
5253 | ||
5254 | // Get shape name | |
5255 | TCollection_AsciiString aName (theArgs[1]); | |
5256 | if (!GetMapOfAIS().IsBound2 (aName)) | |
5257 | { | |
5258 | theDI << theArgs[0] << " error: wrong object name.\n"; | |
5259 | return 1; | |
5260 | } | |
5261 | ||
5262 | Handle(AIS_InteractiveObject) anObject = | |
5263 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName)); | |
5264 | ||
5265 | // Enable trianle edge mode | |
5266 | anObject->Attributes()->ShadingAspect()->Aspect()->SetEdgeOff(); | |
5267 | ||
5268 | // Parse parameters | |
5269 | if (theArgNum == 3) | |
5270 | { | |
5271 | TCollection_AsciiString aParam ((theArgs[2])); | |
5272 | if (aParam.IsEqual ("-force")) | |
5273 | { | |
5274 | isForceRedisplay = Standard_True; | |
5275 | } | |
5276 | else | |
5277 | { | |
5278 | theDI << theArgs[0] << " error: unknown parameter '" | |
5279 | << aParam.ToCString() << "'.\n"; | |
5280 | return 1; | |
5281 | } | |
5282 | } | |
5283 | ||
5284 | // Update shape presentation as aspect parameters were changed | |
5285 | if (isForceRedisplay) | |
5286 | { | |
5287 | ViewerTest::GetAISContext()->Redisplay (anObject); | |
5288 | } | |
5289 | else | |
5290 | { | |
5291 | anObject->SetAspect (anObject->Attributes()->ShadingAspect()); | |
5292 | } | |
5293 | ||
5294 | //Update view | |
5295 | ViewerTest::CurrentView()->Redraw(); | |
5296 | ||
5297 | return 0; | |
5298 | } | |
5299 | ||
53b15292 | 5300 | |
5301 | //======================================================================= | |
5302 | //function : VVertexMode | |
5303 | //purpose : Switches vertex display mode for AIS_Shape or displays the current value | |
5304 | //======================================================================= | |
5305 | ||
5306 | static int VVertexMode (Draw_Interpretor& theDI, | |
5307 | Standard_Integer theArgNum, | |
5308 | const char** theArgs) | |
5309 | { | |
5310 | Handle(AIS_InteractiveContext) aContext = ViewerTest::GetAISContext(); | |
5311 | if (aContext.IsNull()) | |
5312 | { | |
5313 | std::cout << "Error: no view available, call 'vinit' before!" << std::endl; | |
5314 | return 1; | |
5315 | } | |
5316 | ||
5317 | // No arguments --> print the current default vertex draw mode | |
5318 | if (theArgNum == 1) | |
5319 | { | |
5320 | Prs3d_VertexDrawMode aCurrMode = aContext->DefaultDrawer()->VertexDrawMode(); | |
5321 | theDI << "Default vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
5322 | return 0; | |
5323 | } | |
5324 | ||
5325 | // -set argument --> change the default vertex draw mode and the mode for all displayed or given object(s) | |
5326 | TCollection_AsciiString aParam (theArgs[1]); | |
5327 | if (aParam == "-set") | |
5328 | { | |
5329 | if (theArgNum == 2) | |
5330 | { | |
5331 | std::cout << "Error: '-set' option not followed by the mode and optional object name(s)" << std::endl; | |
5332 | std::cout << "Type 'help vvertexmode' for usage hints" << std::endl; | |
5333 | return 1; | |
5334 | } | |
5335 | ||
5336 | TCollection_AsciiString aModeStr (theArgs[2]); | |
5337 | Prs3d_VertexDrawMode aNewMode = | |
5338 | aModeStr == "isolated" ? Prs3d_VDM_Isolated : | |
5339 | (aModeStr == "all" ? Prs3d_VDM_All : | |
5340 | Prs3d_VDM_Inherited); | |
5341 | ||
5342 | Standard_Boolean aRedrawNeeded = Standard_False; | |
5343 | AIS_ListOfInteractive anObjs; | |
5344 | ||
5345 | // No object(s) specified -> use all displayed | |
5346 | if (theArgNum == 3) | |
5347 | { | |
5348 | theDI << "Setting the default vertex draw mode and updating all displayed objects...\n"; | |
5349 | aContext->DisplayedObjects (anObjs); | |
5350 | aContext->DefaultDrawer()->SetVertexDrawMode (aNewMode); | |
5351 | aRedrawNeeded = Standard_True; | |
5352 | } | |
5353 | ||
5354 | Handle(AIS_InteractiveObject) anObject; | |
5355 | for (Standard_Integer aCount = 3; aCount < theArgNum; aCount++) | |
5356 | { | |
5357 | TCollection_AsciiString aName (theArgs[aCount]); | |
5358 | if (!GetMapOfAIS().IsBound2 (aName)) | |
5359 | { | |
5360 | theDI << "Warning: wrong object name ignored - " << theArgs[0] << "\n"; | |
5361 | continue; | |
5362 | } | |
5363 | anObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(aName)); | |
5364 | anObjs.Append (anObject); | |
5365 | } | |
5366 | ||
5367 | for (AIS_ListIteratorOfListOfInteractive anIt (anObjs); anIt.More(); anIt.Next()) | |
5368 | { | |
5369 | anObject = anIt.Value(); | |
5370 | anObject->Attributes()->SetVertexDrawMode (aNewMode); | |
5371 | aContext->Redisplay (anObject, Standard_False); | |
5372 | aRedrawNeeded = Standard_True; | |
5373 | } | |
5374 | ||
5375 | if (aRedrawNeeded) | |
5376 | ViewerTest::CurrentView()->Redraw(); | |
5377 | ||
5378 | return 0; | |
5379 | } | |
5380 | ||
5381 | if (theArgNum > 2) | |
5382 | { | |
5383 | std::cout << "Error: invalid number of arguments" << std::endl; | |
5384 | std::cout << "Type 'help vvertexmode' for usage hints" << std::endl; | |
5385 | return 1; | |
5386 | } | |
5387 | ||
5388 | // One argument (object name) --> print the current vertex draw mode for the object | |
5389 | Handle(AIS_InteractiveObject) anObject = | |
5390 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aParam)); | |
5391 | Prs3d_VertexDrawMode aCurrMode = anObject->Attributes()->VertexDrawMode(); | |
5392 | theDI << "Object's vertex draw mode: " << (aCurrMode == Prs3d_VDM_Isolated ? "'isolated'" : "'all'") << "\n"; | |
5393 | return 0; | |
5394 | } | |
5395 | ||
d33222c1 | 5396 | //======================================================================= |
5397 | //function : VPointCloud | |
5398 | //purpose : Create interactive object for arbitary set of points. | |
5399 | //======================================================================= | |
5400 | static Standard_Integer VPointCloud (Draw_Interpretor& theDI, | |
5401 | Standard_Integer theArgNum, | |
5402 | const char** theArgs) | |
5403 | { | |
5404 | Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); | |
5405 | if (anAISContext.IsNull()) | |
5406 | { | |
5407 | std::cerr << "Error: no active view!\n"; | |
5408 | return 1; | |
5409 | } | |
5410 | ||
5411 | // command to execute | |
5412 | enum Command | |
5413 | { | |
5414 | CloudForShape, // generate point cloud for shape | |
5415 | CloudSphere, // generate point cloud for generic sphere | |
5416 | Unknow | |
5417 | }; | |
5418 | ||
5419 | // count number of non-optional command arguments | |
5420 | Command aCmd = Unknow; | |
5421 | Standard_Integer aCmdArgs = 0; | |
5422 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) | |
5423 | { | |
5424 | Standard_CString anArg = theArgs[anArgIter]; | |
5425 | TCollection_AsciiString aFlag (anArg); | |
5426 | aFlag.LowerCase(); | |
5427 | if (aFlag.IsRealValue() || aFlag.Search ("-") != 1) | |
5428 | { | |
5429 | aCmdArgs++; | |
5430 | } | |
5431 | } | |
5432 | switch (aCmdArgs) | |
5433 | { | |
5434 | case 2 : aCmd = CloudForShape; break; | |
5435 | case 7 : aCmd = CloudSphere; break; | |
5436 | default : | |
5437 | std::cout << "Error: wrong number of arguments! See usage:\n"; | |
5438 | theDI.PrintHelp (theArgs[0]); | |
5439 | return 1; | |
5440 | } | |
5441 | ||
5442 | // parse options | |
5443 | Standard_Boolean toRandColors = Standard_False; | |
5444 | Standard_Boolean hasNormals = Standard_True; | |
5445 | Standard_Boolean isSetArgNorm = Standard_False; | |
5446 | for (Standard_Integer anArgIter = 1; anArgIter < theArgNum; ++anArgIter) | |
5447 | { | |
5448 | Standard_CString anArg = theArgs[anArgIter]; | |
5449 | TCollection_AsciiString aFlag (anArg); | |
5450 | aFlag.LowerCase(); | |
5451 | if (aFlag == "-randcolors" | |
5452 | || aFlag == "-randcolor") | |
5453 | { | |
5454 | if (isSetArgNorm && hasNormals) | |
5455 | { | |
5456 | std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n"; | |
5457 | return 1; | |
5458 | } | |
5459 | toRandColors = Standard_True; | |
5460 | hasNormals = Standard_False; | |
5461 | } | |
5462 | else if (aFlag == "-normals" | |
5463 | || aFlag == "-normal") | |
5464 | { | |
5465 | if (toRandColors) | |
5466 | { | |
5467 | std::cout << "Error: wrong syntax - normals can not be enabled with colors at the same time\n"; | |
5468 | return 1; | |
5469 | } | |
5470 | isSetArgNorm = Standard_True; | |
5471 | hasNormals = Standard_True; | |
5472 | } | |
5473 | else if (aFlag == "-nonormals" | |
5474 | || aFlag == "-nonormal") | |
5475 | { | |
5476 | isSetArgNorm = Standard_True; | |
5477 | hasNormals = Standard_False; | |
5478 | } | |
5479 | } | |
5480 | ||
5481 | Standard_CString aName = theArgs[1]; | |
5482 | ||
5483 | // generate arbitrary set of points | |
5484 | Handle(Graphic3d_ArrayOfPoints) anArrayPoints; | |
5485 | if (aCmd == CloudForShape) | |
5486 | { | |
5487 | Standard_CString aShapeName = theArgs[2]; | |
5488 | TopoDS_Shape aShape = DBRep::Get (aShapeName); | |
5489 | ||
5490 | if (aShape.IsNull()) | |
5491 | { | |
5492 | std::cout << "Error: no shape with name '" << aShapeName << "' found\n"; | |
5493 | return 1; | |
5494 | } | |
5495 | ||
5496 | // calculate number of points | |
5497 | TopLoc_Location aLocation; | |
5498 | Standard_Integer aNbPoints = 0; | |
5499 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) | |
5500 | { | |
5501 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5502 | Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation); | |
5503 | if (!aTriangulation.IsNull()) | |
5504 | { | |
5505 | aNbPoints += aTriangulation->NbNodes(); | |
5506 | } | |
5507 | } | |
5508 | if (aNbPoints < 3) | |
5509 | { | |
5510 | std::cout << "Error: shape should be triangulated!\n"; | |
5511 | return 1; | |
5512 | } | |
5513 | ||
5514 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals); | |
5515 | for (TopExp_Explorer aFaceIt (aShape, TopAbs_FACE); aFaceIt.More(); aFaceIt.Next()) | |
5516 | { | |
5517 | const TopoDS_Face& aFace = TopoDS::Face (aFaceIt.Current()); | |
5518 | Handle(Poly_Triangulation) aTriangulation = StdPrs_ToolShadedShape::Triangulation (aFace, aLocation); | |
5519 | if (aTriangulation.IsNull()) | |
5520 | { | |
5521 | continue; | |
5522 | } | |
5523 | ||
5524 | const TColgp_Array1OfPnt& aNodes = aTriangulation->Nodes(); | |
5525 | const gp_Trsf& aTrsf = aLocation.Transformation(); | |
5526 | ||
5527 | // extract normals from nodes | |
5528 | TColgp_Array1OfDir aNormals (aNodes.Lower(), hasNormals ? aNodes.Upper() : aNodes.Lower()); | |
5529 | if (hasNormals) | |
5530 | { | |
5531 | Poly_Connect aPolyConnect (aTriangulation); | |
5532 | StdPrs_ToolShadedShape::Normal (aFace, aPolyConnect, aNormals); | |
5533 | } | |
5534 | ||
5535 | for (Standard_Integer aNodeIter = aNodes.Lower(); aNodeIter <= aNodes.Upper(); ++aNodeIter) | |
5536 | { | |
5537 | gp_Pnt aPoint = aNodes (aNodeIter); | |
5538 | if (!aLocation.IsIdentity()) | |
5539 | { | |
5540 | aPoint.Transform (aTrsf); | |
5541 | if (hasNormals) | |
5542 | { | |
5543 | aNormals (aNodeIter).Transform (aTrsf); | |
5544 | } | |
5545 | } | |
5546 | ||
5547 | // add vertex into array of points | |
5548 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
5549 | if (toRandColors) | |
5550 | { | |
5551 | Quantity_Color aColor (360.0 * Standard_Real(anIndexOfPoint) / Standard_Real(aNbPoints), | |
5552 | 1.0, 0.5, Quantity_TOC_HLS); | |
5553 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
5554 | } | |
5555 | ||
5556 | if (hasNormals) | |
5557 | { | |
5558 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aNormals (aNodeIter)); | |
5559 | } | |
5560 | } | |
5561 | } | |
5562 | } | |
5563 | else if (aCmd == CloudSphere) | |
5564 | { | |
5565 | Standard_Real aCenterX = Draw::Atof (theArgs[2]); | |
5566 | Standard_Real aCenterY = Draw::Atof (theArgs[3]); | |
5567 | Standard_Real aCenterZ = Draw::Atof (theArgs[4]); | |
5568 | Standard_Real aRadius = Draw::Atof (theArgs[5]); | |
5569 | Standard_Integer aNbPoints = Draw::Atoi (theArgs[6]); | |
5570 | ||
5571 | TCollection_AsciiString aDistribution = TCollection_AsciiString(theArgs[7]); | |
5572 | aDistribution.LowerCase(); | |
5573 | if ( aDistribution != "surface" && aDistribution != "volume" ) | |
5574 | { | |
5575 | std::cout << "Error: wrong arguments! See usage:\n"; | |
5576 | theDI.PrintHelp (theArgs[0]); | |
5577 | return 1; | |
5578 | } | |
5579 | Standard_Boolean isSurface = aDistribution == "surface"; | |
5580 | ||
5581 | gp_Pnt aCenter(aCenterX, aCenterY, aCenterZ); | |
5582 | ||
5583 | anArrayPoints = new Graphic3d_ArrayOfPoints (aNbPoints, toRandColors, hasNormals); | |
5584 | for (Standard_Integer aPntIt = 0; aPntIt < aNbPoints; ++aPntIt) | |
5585 | { | |
5586 | Standard_Real anAlpha = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
5587 | Standard_Real aBeta = (Standard_Real (rand() % 2000) / 1000.0) * M_PI; | |
5588 | Standard_Real aDistance = isSurface ? | |
5589 | aRadius : (Standard_Real (rand() % aNbPoints) / aNbPoints) * aRadius; | |
5590 | ||
5591 | gp_Dir aDir (Cos (anAlpha) * Sin (aBeta), | |
5592 | Sin (anAlpha), | |
5593 | Cos (anAlpha) * Cos (aBeta)); | |
5594 | gp_Pnt aPoint = aCenter.Translated (aDir.XYZ() * aDistance); | |
5595 | ||
5596 | const Standard_Integer anIndexOfPoint = anArrayPoints->AddVertex (aPoint); | |
5597 | if (toRandColors) | |
5598 | { | |
5599 | Quantity_Color aColor (360.0 * Standard_Real (anIndexOfPoint) / Standard_Real (aNbPoints), | |
5600 | 1.0, 0.5, Quantity_TOC_HLS); | |
5601 | anArrayPoints->SetVertexColor (anIndexOfPoint, aColor); | |
5602 | } | |
5603 | ||
5604 | if (hasNormals) | |
5605 | { | |
5606 | anArrayPoints->SetVertexNormal (anIndexOfPoint, aDir); | |
5607 | } | |
5608 | } | |
5609 | } | |
5610 | ||
5611 | // set array of points in point cloud object | |
5612 | Handle(AIS_PointCloud) aPointCloud = new AIS_PointCloud(); | |
5613 | aPointCloud->SetPoints (anArrayPoints); | |
5614 | VDisplayAISObject (aName, aPointCloud); | |
5615 | return 0; | |
5616 | } | |
5617 | ||
7fd59977 | 5618 | //======================================================================= |
5619 | //function : ObjectsCommands | |
161c4476 | 5620 | //purpose : |
7fd59977 | 5621 | //======================================================================= |
5622 | ||
5623 | void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) | |
5624 | { | |
5625 | const char *group ="AISObjects"; | |
5626 | theCommands.Add("vtrihedron", | |
5627 | "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ", | |
5628 | __FILE__,VTrihedron,group); | |
5629 | ||
161c4476 | 5630 | theCommands.Add("vtri2d", |
7fd59977 | 5631 | "vtri2d Name Selection in the viewer only ", |
5632 | __FILE__,VTrihedron2D ,group); | |
5633 | ||
161c4476 | 5634 | theCommands.Add("vplanetri", |
7fd59977 | 5635 | "vplanetri Name Selection in the viewer only ", |
5636 | __FILE__,VPlaneTrihedron ,group); | |
5637 | ||
5638 | theCommands.Add("vsize", | |
5639 | "vsize : vsize [name(Default=Current)] [size(Default=100)] ", | |
5640 | __FILE__,VSize,group); | |
5641 | ||
5642 | theCommands.Add("vaxis", | |
5643 | "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]", | |
5644 | __FILE__,VAxisBuilder,group); | |
5645 | ||
161c4476 | 5646 | theCommands.Add("vaxispara", |
7fd59977 | 5647 | "vaxispara nom ", |
5648 | __FILE__,VAxisBuilder,group); | |
5649 | ||
5650 | theCommands.Add("vaxisortho", | |
5651 | "vaxisotho nom ", | |
5652 | __FILE__,VAxisBuilder,group); | |
5653 | ||
5654 | theCommands.Add("vpoint", | |
5655 | "vpoint PointName [Xa] [Ya] [Za] ", | |
5656 | __FILE__,VPointBuilder,group); | |
5657 | ||
5658 | theCommands.Add("vplane", | |
9e8804b6 | 5659 | "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] [TypeOfSensitivity]", |
7fd59977 | 5660 | __FILE__,VPlaneBuilder,group); |
5661 | ||
f3889691 | 5662 | theCommands.Add ("vchangeplane", "vchangeplane usage: \n" |
5663 | " vchangeplane <plane_name>" | |
5664 | " [x=center_x y=center_y z=center_z]" | |
5665 | " [dx=dir_x dy=dir_y dz=dir_z]" | |
5666 | " [sx=size_x sy=size_y]" | |
5667 | " [noupdate]\n" | |
5668 | " - changes parameters of the plane:\n" | |
5669 | " - x y z - center\n" | |
5670 | " - dx dy dz - normal\n" | |
5671 | " - sx sy - plane sizes\n" | |
5672 | " - noupdate - do not update/redisplay the plane in context\n" | |
5673 | " Please enter coordinates in format \"param=value\" in arbitrary order.", | |
5674 | __FILE__, VChangePlane, group); | |
5675 | ||
7fd59977 | 5676 | theCommands.Add("vplanepara", |
5677 | "vplanepara PlaneName ", | |
5678 | __FILE__,VPlaneBuilder,group); | |
5679 | ||
5680 | theCommands.Add("vplaneortho", | |
5681 | "vplaneortho PlaneName ", | |
5682 | __FILE__,VPlaneBuilder,group); | |
5683 | ||
161c4476 | 5684 | theCommands.Add("vline", |
7fd59977 | 5685 | "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ", |
5686 | __FILE__,VLineBuilder,group); | |
5687 | ||
5688 | theCommands.Add("vcircle", | |
329843e2 | 5689 | "vcircle CircleName [PointName PointName PointName IsFilled]\n\t\t\t\t\t[PlaneName PointName Radius IsFilled]", |
7fd59977 | 5690 | __FILE__,VCircleBuilder,group); |
5691 | ||
5692 | theCommands.Add("vdrawtext", | |
13a22457 | 5693 | "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect [Font [isMultiByte]]", |
7fd59977 | 5694 | __FILE__,VDrawText,group); |
5695 | ||
5696 | theCommands.Add("vdrawsphere", | |
b7cd4ba7 | 5697 | "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToShowEdges=0] [ToPrintInfo=1]\n", |
7fd59977 | 5698 | __FILE__,VDrawSphere,group); |
5699 | ||
29d43f9c | 5700 | theCommands.Add ("vsetlocation", |
4e18052b | 5701 | "vsetlocation [-noupdate|-update] name x y z" |
5702 | "\n\t\t: Set new location for an interactive object.", | |
29d43f9c A |
5703 | __FILE__, VSetLocation, group); |
5704 | ||
3fc57801 | 5705 | theCommands.Add ( |
5706 | "vcomputehlr", | |
5707 | "vcomputehlr: shape hlrname [ eyex eyey eyez lookx looky lookz ]", | |
5708 | __FILE__, VComputeHLR, group); | |
5709 | ||
9558a876 | 5710 | theCommands.Add("vdrawparray", |
871fa103 | 5711 | "vdrawparray : vdrawparray Name TypeOfArray [vertex = { 'v' x y z [vertex_normal = { 'n' x y z }] [vertex_color = { 'c' r g b }] ] ... [bound = { 'b' vertex_count [bound_color = { 'c' r g b }] ] ... [edge = { 'e' vertex_id ]", |
9558a876 | 5712 | __FILE__,VDrawPArray,group); |
ac04d101 SA |
5713 | |
5714 | theCommands.Add("vconnect", | |
0717ddc1 | 5715 | "vconnect : assembly_name Xo Yo Zo object1 object2 ..." |
5716 | " Makes an assembly of object instances located in point (Xo Yo Zo).", | |
ac04d101 SA |
5717 | __FILE__, VConnect, group); |
5718 | ||
0717ddc1 | 5719 | theCommands.Add("vconnectto", |
5720 | "vconnectto : instance_name Xo Yo Zo object" | |
5721 | " Makes an instance 'instance_name' of 'object' with position (Xo Yo Zo).", | |
5722 | __FILE__, VConnectTo,group); | |
5723 | ||
5724 | theCommands.Add("vdisconnect", | |
5725 | "vdisconnect assembly_name (object_name | object_number | 'all')" | |
5726 | " Disconnects all objects from assembly or disconnects object by name or number (use vlistconnected to enumerate assembly children).", | |
5727 | __FILE__,VDisconnect,group); | |
5728 | ||
5729 | theCommands.Add("vaddconnected", | |
5730 | "vaddconnected assembly_name object_name" | |
5731 | "Adds object to assembly.", | |
5732 | __FILE__,VAddConnected,group); | |
5733 | ||
5734 | theCommands.Add("vlistconnected", | |
5735 | "vlistconnected assembly_name" | |
5736 | "Lists objects in assembly.", | |
5737 | __FILE__,VListConnected,group); | |
5738 | ||
ac04d101 SA |
5739 | |
5740 | theCommands.Add("vselmode", | |
446e9c14 | 5741 | "vselmode : [object] mode_number is_turned_on=(1|0)\n" |
5742 | " switches selection mode for the determined object or\n" | |
5743 | " for all objects in context.\n" | |
5744 | " mode_number is non-negative integer that has different\n" | |
5745 | " meaning for different interactive object classes.\n" | |
5746 | " For shapes the following mode_number values are allowed:\n" | |
5747 | " 0 - shape\n" | |
5748 | " 1 - vertex\n" | |
5749 | " 2 - edge\n" | |
5750 | " 3 - wire\n" | |
5751 | " 4 - face\n" | |
5752 | " 5 - shell\n" | |
5753 | " 6 - solid\n" | |
5754 | " 7 - compsolid\n" | |
5755 | " 8 - compound\n" | |
5756 | " is_turned_on is:\n" | |
5757 | " 1 if mode is to be switched on\n" | |
5758 | " 0 if mode is to be switched off\n", | |
ac04d101 | 5759 | __FILE__, VSetSelectionMode, group); |
ceae62f0 A |
5760 | |
5761 | theCommands.Add("vtriangle", | |
5762 | "vtriangle Name PointName PointName PointName", | |
5763 | __FILE__, VTriangle,group); | |
5764 | ||
5765 | theCommands.Add("vsegment", | |
5766 | "vsegment Name PointName PointName", | |
5767 | __FILE__, VSegment,group); | |
59f45b7c | 5768 | |
5769 | theCommands.Add("vobjzlayer", | |
5770 | "vobjzlayer : set/get object [layerid] - set or get z layer id for the interactive object", | |
5771 | __FILE__, VObjZLayer, group); | |
3ddebf91 | 5772 | |
5773 | theCommands.Add("vpolygonoffset", | |
5774 | "vpolygonoffset : [object [mode factor units]] - sets/gets polygon offset parameters for an object, without arguments prints the default values", | |
5775 | __FILE__, VPolygonOffset, group); | |
a2d5ab2e | 5776 | |
5777 | theCommands.Add ("vshowfaceboundary", | |
5778 | "vshowfaceboundary : ObjectName isOn (1/0) [R G B [LineWidth [LineStyle]]]" | |
5779 | "- turns on/off drawing of face boundaries for ais object " | |
5780 | "and defines boundary line style.", | |
5781 | __FILE__, VShowFaceBoundary, group); | |
a577aaab | 5782 | |
5783 | theCommands.Add ("vmarkerstest", | |
5784 | "vmarkerstest: name X Y Z [PointsOnSide=10] [MarkerType=0] [Scale=1.0] [FileName=ImageFile]\n", | |
5785 | __FILE__, VMarkersTest, group); | |
b514beda | 5786 | |
5787 | theCommands.Add ("text2brep", | |
5788 | "text2brep: res text fontName fontSize [x=0.0 y=0.0 z=0.0 composite=1 {regular,bold,italic,bolditalic=regular}]\n", | |
5789 | __FILE__, TextToBRep, group); | |
725ef85e | 5790 | theCommands.Add ("vfont", |
5791 | "vfont [add pathToFont [fontName] [regular,bold,italic,bolditalic=undefined]]" | |
5792 | "\n\t\t: [find fontName [regular,bold,italic,bolditalic=undefined]]", | |
5793 | __FILE__, VFont, group); | |
5ad539d2 | 5794 | |
5795 | theCommands.Add ("vsetedgetype", | |
5796 | "vsetedgetype usage:\n" | |
5797 | "vsetedgetype ShapeName [-force] [-type {solid, dash, dot}] [-color R G B] " | |
5798 | "\n\t\t: Sets edges type and color for input shape", | |
5799 | __FILE__, VSetEdgeType, group); | |
5800 | ||
5801 | theCommands.Add ("vunsetedgetype", | |
5802 | "vunsetedgetype usage:\n" | |
5803 | "vunsetedgetype ShapeName [-force]" | |
5804 | "\n\t\t: Unsets edges type and color for input shape", | |
5805 | __FILE__, VUnsetEdgeType, group); | |
53b15292 | 5806 | |
5807 | theCommands.Add ("vvertexmode", | |
5808 | "vvertexmode [name | -set {isolated | all | inherited} [name1 name2 ...]]\n" | |
5809 | "vvertexmode - prints the default vertex draw mode\n" | |
5810 | "vvertexmode name - prints the vertex draw mode of the given object\n" | |
5811 | "vvertexmode -set {isolated | all | inherited} - sets the default vertex draw mode and updates the mode for all displayed objects\n" | |
5812 | "vvertexmode -set {isolated | all | inherited} name1 name2 ... - sets the vertex draw mode for the specified object(s)\n", | |
5813 | __FILE__, VVertexMode, group); | |
d33222c1 | 5814 | |
5815 | theCommands.Add ("vpointcloud", | |
5816 | "vpointcloud name shape [-randColor] [-normals] [-noNormals]" | |
5817 | "\n\t\t: Create an interactive object for arbitary set of points" | |
5818 | "\n\t\t: from triangulated shape." | |
5819 | "\n" | |
5820 | "vpointcloud name x y z r npts {surface|volume}\n" | |
5821 | " ... [-randColor] [-normals] [-noNormals]" | |
5822 | "\n\t\t: Create arbitrary set of points (npts) randomly distributed" | |
5823 | "\n\t\t: on spheric surface or within spheric volume (x y z r)." | |
5824 | "\n\t\t:" | |
5825 | "\n\t\t: Additional options:" | |
5826 | "\n\t\t: -randColor - generate random color per point" | |
5827 | "\n\t\t: -normals - generate normal per point (default)" | |
5828 | "\n\t\t: -noNormals - do not generate normal per point" | |
5829 | "\n", | |
5830 | __FILE__, VPointCloud, group); | |
7fd59977 | 5831 | } |