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