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