Commit | Line | Data |
---|---|---|
13a22457 S |
1 | // File: ViewerTest_ObjectsCommands.cxx |
2 | // Created: Thu Nov 12 15:50:42 1998 | |
3 | // Author: Robert COUBLANC | |
4 | // Copyright: OPEN CASCADE 1998 | |
7fd59977 | 5 | |
6 | ||
7 | //=============================================== | |
8 | // | |
9 | // AIS Objects Creation : Datums (axis,trihedrons,lines,planes) | |
10 | // | |
11 | //=============================================== | |
12 | ||
13 | #ifdef HAVE_CONFIG_H | |
14 | #include <config.h> | |
15 | #endif | |
16 | ||
17 | #include <ViewerTest.hxx> | |
18 | ||
19 | #include <string.h> | |
20 | ||
21 | #include <Quantity_NameOfColor.hxx> | |
22 | #include <Draw_Interpretor.hxx> | |
23 | #include <Draw.hxx> | |
24 | #include <Draw_Appli.hxx> | |
25 | #include <DBRep.hxx> | |
26 | ||
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> | |
4952a30a | 32 | #include <V3d_Plane.hxx> |
7fd59977 | 33 | #include <V3d.hxx> |
34 | ||
35 | #include <AIS_Shape.hxx> | |
36 | #include <AIS_DisplayMode.hxx> | |
37 | #include <TColStd_MapOfInteger.hxx> | |
38 | #include <AIS_MapOfInteractive.hxx> | |
39 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> | |
40 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
41 | #include <ViewerTest_EventManager.hxx> | |
42 | ||
43 | #include <TopoDS_Solid.hxx> | |
44 | #include <BRepTools.hxx> | |
45 | #include <BRep_Builder.hxx> | |
46 | #include <TopAbs_ShapeEnum.hxx> | |
47 | ||
48 | #include <TopoDS.hxx> | |
49 | #include <BRep_Tool.hxx> | |
50 | #include <TopExp_Explorer.hxx> | |
51 | ||
52 | #include <BRepAdaptor_Curve.hxx> | |
53 | #include <BRepAdaptor_Surface.hxx> | |
54 | ||
55 | #include <TopAbs.hxx> | |
56 | #include <TopExp.hxx> | |
57 | #include <TopoDS_Vertex.hxx> | |
58 | #include <TopoDS_Shape.hxx> | |
59 | #include <TopoDS_Face.hxx> | |
60 | ||
61 | #include <Draw_Window.hxx> | |
62 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
63 | #include <AIS_ListOfInteractive.hxx> | |
64 | #include <AIS_DisplayMode.hxx> | |
65 | #include <AIS_Shape.hxx> | |
66 | ||
67 | #include <AIS_InteractiveContext.hxx> | |
68 | #include <Geom_Plane.hxx> | |
69 | #include <gp_Pln.hxx> | |
70 | #include <AIS_AngleDimension.hxx> | |
71 | #include <TCollection_ExtendedString.hxx> | |
72 | #include <GC_MakePlane.hxx> | |
73 | #include <gp_Circ.hxx> | |
74 | #include <AIS_Axis.hxx> | |
75 | #include <Geom_Axis2Placement.hxx> | |
76 | #include <Geom_Axis1Placement.hxx> | |
77 | #include <AIS_Trihedron.hxx> | |
78 | #include <AIS_Axis.hxx> | |
29d43f9c A |
79 | #include <gp_Trsf.hxx> |
80 | #include <TopLoc_Location.hxx> | |
3fc57801 | 81 | |
82 | #include <HLRAlgo_Projector.hxx> | |
83 | #include <HLRBRep_PolyAlgo.hxx> | |
84 | #include <HLRBRep_PolyHLRToShape.hxx> | |
85 | #include <Aspect_Window.hxx> | |
86 | ||
9558a876 A |
87 | #include <Graphic3d_ArrayOfPoints.hxx> |
88 | #include <Graphic3d_ArrayOfSegments.hxx> | |
89 | #include <Graphic3d_ArrayOfPolylines.hxx> | |
90 | #include <Graphic3d_ArrayOfTriangles.hxx> | |
91 | #include <Graphic3d_ArrayOfTriangleFans.hxx> | |
92 | #include <Graphic3d_ArrayOfTriangleStrips.hxx> | |
93 | #include <Graphic3d_ArrayOfQuadrangles.hxx> | |
94 | #include <Graphic3d_ArrayOfQuadrangleStrips.hxx> | |
95 | #include <Graphic3d_ArrayOfPolygons.hxx> | |
96 | #include <Graphic3d_Group.hxx> | |
97 | #include <Standard_Real.hxx> | |
98 | ||
329843e2 A |
99 | #include <AIS_Circle.hxx> |
100 | #include <AIS_Drawer.hxx> | |
101 | #include <BRepBuilderAPI_MakeEdge.hxx> | |
102 | #include <BRepBuilderAPI_MakeFace.hxx> | |
103 | #include <BRepBuilderAPI_MakeWire.hxx> | |
104 | #include <Geom_Circle.hxx> | |
105 | #include <GC_MakeCircle.hxx> | |
106 | #include <Prs3d_Presentation.hxx> | |
107 | #include <Select3D_SensitiveCircle.hxx> | |
108 | #include <SelectMgr_EntityOwner.hxx> | |
109 | #include <SelectMgr_Selection.hxx> | |
110 | #include <StdFail_NotDone.hxx> | |
111 | #include <StdPrs_ShadedShape.hxx> | |
ac04d101 SA |
112 | #include <TopoDS_Wire.hxx> |
113 | ||
114 | #include <AIS_ConnectedShape.hxx> | |
115 | #include <TopLoc_Location.hxx> | |
116 | #include <TColStd_ListOfInteger.hxx> | |
117 | #include <TColStd_ListIteratorOfListOfInteger.hxx> | |
329843e2 | 118 | |
7fd59977 | 119 | #ifdef HAVE_STRINGS_H |
120 | #include <strings.h> | |
121 | #endif | |
122 | ||
123 | #ifdef WNT | |
124 | #define _CRT_SECURE_NO_DEPRECATE | |
125 | #pragma warning (disable:4996) | |
126 | #endif | |
127 | ||
128 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); | |
9558a876 A |
129 | extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName, |
130 | const Handle(AIS_InteractiveObject)& theAISObj, | |
131 | Standard_Boolean theReplaceIfExists = Standard_True); | |
7fd59977 | 132 | Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv); |
133 | extern Handle(AIS_InteractiveContext)& TheAISContext(); | |
134 | ||
135 | ||
136 | //============================================================================== | |
137 | //function : Vtrihedron 2d | |
138 | //purpose : Create a plane with a 2D trihedron from a faceselection | |
161c4476 | 139 | //Draw arg : vtri2d name |
7fd59977 | 140 | //============================================================================== |
141 | #include <AIS_PlaneTrihedron.hxx> | |
142 | ||
143 | ||
144 | ||
145 | static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
146 | ||
147 | { | |
148 | // Verification des arguments | |
149 | if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;} | |
150 | ||
151 | // Declarations | |
152 | Standard_Integer myCurrentIndex; | |
161c4476 | 153 | // Fermeture des contextes |
7fd59977 | 154 | TheAISContext()->CloseAllContexts(); |
155 | // Ouverture d'un contexte local et recuperation de son index. | |
156 | TheAISContext()->OpenLocalContext(); | |
157 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
158 | // On active les modes de selections faces. | |
159 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
160 | di<<" Select a face ."<<"\n"; | |
161 | ||
162 | // Boucle d'attente waitpick. | |
163 | Standard_Integer argccc = 5; | |
164 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
165 | const char **argvvv = (const char **) bufff; | |
166 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
167 | // fin de la boucle | |
168 | ||
169 | TopoDS_Shape ShapeB; | |
170 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
171 | ShapeB = TheAISContext()->SelectedShape(); | |
172 | } | |
173 | ||
174 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); | |
175 | ||
176 | // Construction du Plane | |
177 | // recuperation des edges des faces. | |
178 | TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE); | |
179 | ||
180 | TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() ); | |
161c4476 | 181 | // declarations |
7fd59977 | 182 | gp_Pnt A,B,C; |
183 | ||
184 | // si il y a plusieurs edges | |
185 | if (FaceExpB.More() ) { | |
186 | FaceExpB.Next(); | |
187 | TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() ); | |
188 | BRepAdaptor_Curve theCurveB(EdgeB); | |
189 | BRepAdaptor_Curve theCurveC(EdgeC); | |
190 | A=theCurveC.Value(0.1); | |
191 | B=theCurveC.Value(0.9); | |
192 | C=theCurveB.Value(0.5); | |
193 | } | |
194 | else { | |
195 | // FaceB a 1 unique edge courbe | |
196 | BRepAdaptor_Curve theCurveB(EdgeB); | |
197 | A=theCurveB.Value(0.1); | |
198 | B=theCurveB.Value(0.9); | |
199 | C=theCurveB.Value(0.5); | |
200 | } | |
201 | // Construction du Geom_Plane | |
202 | GC_MakePlane MkPlane(A,B,C); | |
203 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
204 | ||
205 | // Construction de l'AIS_PlaneTrihedron | |
206 | Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane ); | |
207 | ||
208 | // Fermeture du contexte local. | |
209 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
210 | ||
211 | // on le display & bind | |
212 | TheAISContext()->Display(theAISPlaneTri ); | |
213 | GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]); | |
214 | ||
161c4476 | 215 | return 0; |
7fd59977 | 216 | } |
217 | ||
218 | ||
219 | ||
220 | //============================================================================== | |
221 | //function : VTriherdron | |
222 | //author : ege | |
223 | //purpose : Create a trihedron. If no arguments are set, the default | |
224 | // trihedron (Oxyz) is created. | |
225 | //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] | |
226 | //============================================================================== | |
227 | ||
228 | static int VTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
229 | ||
230 | { | |
231 | // Verification des arguments | |
232 | if ( argc<2 || argc>11) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
233 | ||
234 | // Declarations et creation des objets par default | |
235 | TCollection_AsciiString name=argv[1]; | |
236 | ||
237 | if(argc > 5 && argc!=11) | |
238 | {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
239 | ||
240 | // Cas ou il y a des arguments | |
241 | Standard_Real coord[9]={0.,0.,0.,0.,0.,1.,1.,0.,0.}; | |
242 | if (argc>2){ | |
243 | Standard_Integer i ; | |
244 | for( i=0;i<=2;i++) | |
245 | coord[i]= atof(argv[2+i]); | |
246 | ||
247 | if(argc>5){ | |
248 | for(i=0;i<=2;i++){ | |
249 | coord[3+i] = atof(argv[6+i]); | |
250 | coord[6+i] = atof(argv[8+i]); | |
251 | } | |
252 | } | |
253 | } | |
254 | gp_Pnt ThePoint(coord[0],coord[1],coord[2]); | |
255 | gp_Dir TheZVector(coord[3],coord[4],coord[5]); | |
256 | gp_Dir TheXVector(coord[6],coord[7],coord[8]); | |
257 | ||
c6541a0c | 258 | if ( !TheZVector.IsNormal(TheXVector,M_PI/180)) {di<<argv[0]<<" VectorX is not normal to VectorZ"<<"\n"; return 1;} |
7fd59977 | 259 | |
260 | Handle(Geom_Axis2Placement) OrigineAndAxii=new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector); | |
261 | ||
262 | // Creation du triedre | |
263 | Handle(AIS_Trihedron) aShape= new AIS_Trihedron(OrigineAndAxii); | |
264 | GetMapOfAIS().Bind(aShape,name); | |
265 | TheAISContext()->Display(aShape); | |
266 | ||
161c4476 | 267 | return 0; |
7fd59977 | 268 | } |
269 | ||
270 | ||
271 | ||
272 | ||
273 | //============================================================================== | |
274 | //function : VSize | |
275 | //author : ege | |
276 | //purpose : Change the size of a named or selected trihedron | |
277 | // if no name : it affects the trihedrons witch are selected otherwise nothing is donne | |
278 | // if no value, the value is set at 100 by default | |
279 | //Draw arg : vsize [name] [size] | |
280 | //============================================================================== | |
281 | ||
282 | static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
283 | ||
284 | { | |
285 | // Declaration de booleens | |
286 | Standard_Boolean ThereIsName; | |
287 | Standard_Boolean ThereIsCurrent; | |
288 | Standard_Real value; | |
161c4476 | 289 | Standard_Boolean hascol; |
7fd59977 | 290 | #ifdef DEB |
291 | Quantity_NameOfColor col; | |
292 | #else | |
293 | Quantity_NameOfColor col = Quantity_NOC_BLACK ; | |
294 | #endif | |
295 | ||
296 | // Verification des arguments | |
297 | if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
298 | ||
299 | // Verification du nombre d'arguments | |
300 | if (argc==1) {ThereIsName=Standard_False;value=100;} | |
301 | else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);} | |
302 | else {ThereIsName=Standard_True;value=atof(argv[2]);} | |
303 | ||
304 | // On ferme le contexte local pour travailler dans le contexte global | |
161c4476 | 305 | if(TheAISContext()->HasOpenedContext()) |
7fd59977 | 306 | TheAISContext()->CloseLocalContext(); |
307 | ||
308 | // On set le booleen ThereIsCurrent | |
309 | if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;} | |
310 | else {ThereIsCurrent=Standard_False;} | |
311 | ||
312 | ||
313 | ||
314 | //=============================================================== | |
315 | // Il n'y a pas de nom mais des objets selectionnes | |
316 | //=============================================================== | |
161c4476 | 317 | if (!ThereIsName && ThereIsCurrent) |
7fd59977 | 318 | { |
319 | ||
320 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
321 | it (GetMapOfAIS()); | |
322 | ||
323 | while ( it.More() ) { | |
324 | ||
325 | Handle(AIS_InteractiveObject) aShape= | |
326 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
327 | ||
328 | if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) ) | |
329 | { | |
330 | ||
161c4476 | 331 | // On verifie que l'AIS InteraciveObject selectionne est bien |
7fd59977 | 332 | // un AIS_Trihedron |
333 | if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) { | |
334 | ||
335 | if (aShape->HasColor()) { | |
336 | hascol=Standard_True; | |
337 | ||
338 | // On recupere la couleur de aShape | |
339 | col=aShape->Color();} | |
340 | ||
341 | else hascol=Standard_False; | |
342 | ||
343 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
344 | // pour lui appliquer la methode SetSize() | |
345 | Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape; | |
346 | ||
347 | // C'est bien un triedre,on chage sa valeur! | |
348 | aTrihedron->SetSize(value); | |
349 | ||
350 | // On donne la couleur au Trihedron | |
351 | if(hascol) aTrihedron->SetColor(col); | |
352 | else aTrihedron->UnsetColor(); | |
353 | ||
354 | ||
355 | // The trihedron hasn't be errased from the map | |
356 | // so you just have to redisplay it | |
357 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
358 | ||
359 | } | |
360 | ||
361 | } | |
362 | ||
363 | it.Next(); | |
364 | } | |
365 | ||
366 | TheAISContext() ->UpdateCurrentViewer(); | |
367 | } | |
368 | ||
369 | //=============================================================== | |
370 | // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire! | |
371 | //=============================================================== | |
372 | ||
373 | ||
374 | ||
375 | //=============================================================== | |
376 | // Il y a un nom de triedre passe en argument | |
377 | //=============================================================== | |
378 | if (ThereIsName) { | |
379 | TCollection_AsciiString name=argv[1]; | |
380 | ||
381 | // on verifie que ce nom correspond bien a une shape | |
382 | Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name); | |
383 | ||
384 | if (IsBound) { | |
385 | ||
386 | // on recupere la shape dans la map des objets displayes | |
387 | Handle(AIS_InteractiveObject) aShape = | |
388 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
389 | ||
161c4476 | 390 | // On verifie que l'AIS InteraciveObject est bien |
7fd59977 | 391 | // un AIS_Trihedron |
392 | if (!aShape.IsNull() && | |
393 | aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) | |
394 | { | |
395 | ||
396 | if (aShape->HasColor()) { | |
397 | hascol=Standard_True; | |
398 | ||
399 | // On recupere la couleur de aShape | |
400 | col=aShape->Color();} | |
401 | ||
402 | else hascol=Standard_False; | |
403 | ||
404 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
405 | // pour lui appliquer la methode SetSize() | |
406 | Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape; | |
407 | ||
408 | // C'est bien un triedre,on chage sa valeur | |
409 | aTrihedron->SetSize(value); | |
410 | ||
411 | // On donne la couleur au Trihedron | |
412 | if(hascol) aTrihedron->SetColor(col); | |
413 | else aTrihedron->UnsetColor(); | |
414 | ||
415 | // The trihedron hasn't be errased from the map | |
416 | // so you just have to redisplay it | |
417 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
418 | ||
419 | TheAISContext() ->UpdateCurrentViewer(); | |
420 | } | |
421 | } | |
422 | } | |
161c4476 | 423 | return 0; |
7fd59977 | 424 | } |
425 | ||
426 | ||
427 | //============================================================================== | |
428 | ||
429 | //============================================================================== | |
430 | //function : VPlaneTrihedron | |
431 | //purpose : Create a plane from a trihedron selection. If no arguments are set, the default | |
161c4476 | 432 | //Draw arg : vplanetri name |
7fd59977 | 433 | //============================================================================== |
434 | #include <AIS_Plane.hxx> | |
435 | ||
436 | ||
437 | ||
438 | static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
439 | ||
440 | { | |
441 | // Verification des arguments | |
442 | if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;} | |
443 | ||
444 | // Declarations | |
445 | Standard_Integer myCurrentIndex; | |
446 | // Fermeture des contextes locaux | |
447 | TheAISContext()->CloseAllContexts(); | |
448 | ||
161c4476 | 449 | // On recupere tous les trihedrons de la GetMapOfAIS() |
7fd59977 | 450 | // et on active le mode de selection par face. |
451 | // ================================================= | |
452 | ||
453 | // Ouverture d'un contexte local et recuperation de son index. | |
454 | TheAISContext()->OpenLocalContext(Standard_False); | |
455 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
456 | ||
457 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
458 | it (GetMapOfAIS()); | |
459 | while(it.More()){ | |
460 | Handle(AIS_InteractiveObject) ShapeA = | |
461 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
462 | // On verifie que c'est bien un trihedron | |
463 | if (!ShapeA.IsNull() && | |
464 | ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) { | |
465 | // on le downcast | |
466 | Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA)); | |
467 | // on le charge dans le contexte et on active le mode Plane. | |
468 | TheAISContext()->Load(TrihedronA,0,Standard_False); | |
469 | TheAISContext()->Activate(TrihedronA,3); | |
470 | } | |
471 | it.Next(); | |
472 | } | |
473 | ||
474 | di<<" Select a plane."<<"\n"; | |
475 | // Boucle d'attente waitpick. | |
476 | Standard_Integer argccc = 5; | |
477 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
478 | const char **argvvv = (const char **) bufff; | |
479 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
480 | // fin de la boucle | |
481 | ||
482 | Handle(AIS_InteractiveObject) theIOB; | |
483 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
484 | theIOB = TheAISContext()->Interactive(); | |
485 | } | |
486 | // on le downcast | |
487 | Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB)); | |
488 | ||
489 | // Fermeture du contexte local. | |
490 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
491 | ||
492 | // on le display & bind | |
493 | TheAISContext()->Display(PlaneB ); | |
494 | GetMapOfAIS().Bind ( PlaneB ,argv[1]); | |
495 | ||
161c4476 | 496 | return 0; |
7fd59977 | 497 | } |
498 | ||
499 | ||
500 | ||
501 | //============================================================================== | |
502 | // Fonction First click 2de click | |
161c4476 | 503 | // |
7fd59977 | 504 | // vaxis vertex vertex |
505 | // edge None | |
506 | // vaxispara edge vertex | |
507 | // vaxisortho edge Vertex | |
508 | // vaxisinter Face Face | |
509 | //============================================================================== | |
510 | ||
511 | //============================================================================== | |
512 | //function : VAxisBuilder | |
161c4476 | 513 | //purpose : |
7fd59977 | 514 | //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb |
515 | //============================================================================== | |
516 | #include <TopoDS_Edge.hxx> | |
517 | #include <TopoDS_Vertex.hxx> | |
518 | #include <TopExp.hxx> | |
519 | #include <Geom_Line.hxx> | |
520 | ||
161c4476 | 521 | static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 522 | { |
523 | // Declarations | |
524 | Standard_Boolean HasArg; | |
525 | TCollection_AsciiString name; | |
526 | Standard_Integer MyCurrentIndex; | |
527 | ||
528 | // Verification | |
529 | if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
530 | if (argc==8) HasArg=Standard_True; | |
531 | else HasArg=Standard_False; | |
532 | ||
533 | name=argv[1]; | |
534 | // Fermeture des contextes | |
535 | TheAISContext()->CloseAllContexts(); | |
536 | ||
537 | // Cas ou il y a des arguments | |
538 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom) | |
539 | if (HasArg) { | |
540 | Standard_Real coord[6]; | |
541 | for(Standard_Integer i=0;i<=5;i++){ | |
542 | coord[i]=atof(argv[2+i]); | |
543 | } | |
544 | gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ; | |
545 | ||
546 | gp_Vec myVect (p1,p2); | |
547 | Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect ); | |
548 | Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine ); | |
549 | GetMapOfAIS().Bind (TheAxis,name); | |
550 | TheAISContext()->Display(TheAxis); | |
551 | } | |
552 | ||
553 | // Pas d'arguments | |
554 | else { | |
555 | // fonction vaxis | |
556 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom) | |
557 | if ( !strcasecmp(argv[0], "vaxis")) { | |
558 | TheAISContext()->OpenLocalContext(); | |
559 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
560 | ||
561 | // Active le mode edge et le mode vertex | |
562 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
563 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); | |
564 | di<<" Select an edge or a vertex."<<"\n"; | |
565 | ||
566 | // Boucle d'attente waitpick. | |
567 | Standard_Integer argcc = 5; | |
568 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
569 | const char **argvv = (const char **) buff; | |
570 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 571 | // fin de la boucle |
7fd59977 | 572 | |
573 | // recuperation de la shape. | |
574 | TopoDS_Shape ShapeA; | |
575 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
576 | ShapeA = TheAISContext()->SelectedShape(); | |
577 | } | |
578 | // recuperation de l'AIS_InteractiveObject | |
579 | //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current(); | |
580 | // down cast en AIS_Point si sig et type | |
581 | // AIS_Point -> Geom_Pnt .... | |
582 | ||
583 | if (ShapeA.ShapeType()==TopAbs_VERTEX) { | |
584 | // on desactive le mode edge | |
585 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
586 | di<<" Select a different vertex."<<"\n"; | |
587 | ||
588 | TopoDS_Shape ShapeB; | |
589 | do { | |
590 | // Boucle d'attente waitpick. | |
591 | Standard_Integer argccc = 5; | |
592 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
593 | const char **argvvv = (const char **) bufff; | |
594 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 595 | // fin de la boucle |
7fd59977 | 596 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
597 | ShapeB = TheAISContext()->SelectedShape(); | |
598 | } | |
599 | ||
600 | ||
601 | } while(ShapeB.IsSame(ShapeA) ); | |
602 | ||
603 | // Fermeture du context local | |
604 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
605 | ||
161c4476 | 606 | // Construction de l'axe |
7fd59977 | 607 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); |
608 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
609 | gp_Vec V (A,B); | |
610 | gp_Dir D (V); | |
611 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
612 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
613 | GetMapOfAIS().Bind (TheAxis,name); | |
614 | TheAISContext()->Display(TheAxis); | |
161c4476 | 615 | } |
7fd59977 | 616 | else { |
617 | // Un unique edge (ShapeA) a ete picke | |
618 | // Fermeture du context local | |
619 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
161c4476 | 620 | // Constuction de l'axe |
7fd59977 | 621 | TopoDS_Edge ed =TopoDS::Edge(ShapeA); |
622 | TopoDS_Vertex Va,Vb; | |
623 | TopExp::Vertices(ed,Va,Vb ); | |
624 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
625 | gp_Pnt B=BRep_Tool::Pnt(Vb); | |
626 | gp_Vec V (A,B); | |
627 | gp_Dir D (V); | |
628 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
629 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
630 | GetMapOfAIS().Bind (TheAxis,name); | |
631 | TheAISContext()->Display(TheAxis); | |
632 | } | |
633 | ||
634 | } | |
635 | ||
636 | // Fonction axispara | |
637 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS) | |
638 | else if ( !strcasecmp(argv[0], "vaxispara")) { | |
639 | ||
640 | TheAISContext()->OpenLocalContext(); | |
641 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
642 | ||
161c4476 | 643 | // Active le mode edge |
7fd59977 | 644 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); |
645 | di<<" Select an edge."<<"\n"; | |
646 | ||
647 | // Boucle d'attente waitpick. | |
648 | Standard_Integer argcc = 5; | |
649 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
650 | const char **argvv = (const char **) buff; | |
651 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 652 | // fin de la boucle |
7fd59977 | 653 | |
654 | TopoDS_Shape ShapeA; | |
655 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
656 | ShapeA = TheAISContext()->SelectedShape(); | |
657 | } | |
658 | // Active le mode vertex et deactive edges | |
659 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
660 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
661 | di<<" Select a vertex."<<"\n"; | |
662 | ||
663 | // Boucle d'attente waitpick. | |
664 | Standard_Integer argccc = 5; | |
665 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
666 | const char **argvvv = (const char **) bufff; | |
667 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 668 | // fin de la boucle |
7fd59977 | 669 | |
670 | // On peut choisir un pnt sur l'edge | |
671 | TopoDS_Shape ShapeB; | |
672 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
673 | ShapeB = TheAISContext()->SelectedShape(); | |
674 | } | |
675 | // Fermeture du context local | |
676 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
677 | ||
678 | // Construction de l'axe | |
679 | TopoDS_Edge ed=TopoDS::Edge(ShapeA) ; | |
680 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
681 | TopoDS_Vertex Va,Vc; | |
682 | TopExp::Vertices(ed,Va,Vc ); | |
683 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
684 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
685 | gp_Vec V (A,C); | |
686 | gp_Dir D (V); | |
687 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
688 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
689 | GetMapOfAIS().Bind (TheAxis,name); | |
690 | TheAISContext()->Display(TheAxis); | |
691 | ||
692 | } | |
693 | ||
694 | // Fonction axisortho | |
695 | else { | |
696 | TheAISContext()->OpenLocalContext(); | |
697 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
698 | ||
161c4476 | 699 | // Active le mode edge |
7fd59977 | 700 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); |
701 | di<<" Select an edge."<<"\n"; | |
702 | ||
703 | // Boucle d'attente waitpick. | |
704 | Standard_Integer argcc = 5; | |
705 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
706 | const char **argvv = (const char **) buff; | |
707 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 708 | // fin de la boucle |
7fd59977 | 709 | |
710 | TopoDS_Shape ShapeA; | |
711 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
712 | ShapeA = TheAISContext()->SelectedShape(); | |
713 | } | |
714 | // Active le mode vertex et deactive edges | |
715 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
716 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
717 | di<<" Slect a vertex."<<"\n"; | |
718 | ||
719 | // Boucle d'attente waitpick. | |
720 | Standard_Integer argccc = 5; | |
721 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
722 | const char **argvvv = (const char **) bufff; | |
723 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 724 | // fin de la boucle |
7fd59977 | 725 | |
726 | // On peut choisir un pnt sur l'edge | |
727 | TopoDS_Shape ShapeB; | |
728 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
729 | ShapeB = TheAISContext()->SelectedShape(); | |
730 | } | |
731 | // Fermeture du context local | |
732 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
733 | ||
734 | // Construction de l'axe | |
735 | TopoDS_Edge ed=TopoDS::Edge(ShapeA) ; | |
736 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
737 | TopoDS_Vertex Va,Vc; | |
738 | TopExp::Vertices(ed,Va,Vc ); | |
739 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
740 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
741 | gp_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() ); | |
742 | gp_Vec V (A,E); | |
743 | gp_Dir D (V); | |
744 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
745 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
746 | GetMapOfAIS().Bind (TheAxis,name); | |
747 | TheAISContext()->Display(TheAxis); | |
748 | ||
749 | } | |
750 | ||
751 | } | |
752 | return 0; | |
753 | } | |
754 | ||
755 | ||
756 | //============================================================================== | |
757 | // Fonction First click Result | |
161c4476 | 758 | // |
7fd59977 | 759 | // vpoint vertex AIS_Point=Vertex |
760 | // edge AIS_Point=Middle of the edge | |
761 | //============================================================================== | |
762 | ||
763 | //============================================================================== | |
764 | //function : VPointBuilder | |
765 | //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge | |
766 | //Draw arg : vpoint PoinName [Xa] [Ya] [Za] | |
767 | //============================================================================== | |
768 | #include <TopoDS_Edge.hxx> | |
769 | #include <TopoDS_Vertex.hxx> | |
770 | #include <TopExp.hxx> | |
771 | #include <AIS_Point.hxx> | |
772 | #include <Geom_CartesianPoint.hxx> | |
773 | ||
161c4476 | 774 | static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 775 | { |
776 | // Declarations | |
777 | Standard_Boolean HasArg; | |
778 | TCollection_AsciiString name; | |
779 | Standard_Integer myCurrentIndex; | |
780 | ||
781 | // Verification | |
782 | if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
783 | if (argc==5) HasArg=Standard_True; | |
784 | else HasArg=Standard_False; | |
785 | ||
786 | name=argv[1]; | |
787 | // Fermeture des contextes | |
788 | TheAISContext()->CloseAllContexts(); | |
789 | ||
790 | // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom) | |
791 | if (HasArg) { | |
792 | Standard_Real thecoord[3]; | |
793 | for(Standard_Integer i=0;i<=2;i++) | |
794 | thecoord[i]=atof(argv[2+i]); | |
795 | Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]); | |
796 | Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint ); | |
797 | GetMapOfAIS().Bind (myAISPoint,name); | |
798 | TheAISContext()->Display(myAISPoint); | |
799 | } | |
800 | ||
801 | // Il n'a pas d'arguments | |
802 | else { | |
803 | TheAISContext()->OpenLocalContext(); | |
804 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
805 | ||
806 | // Active le mode Vertex et Edges | |
807 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
808 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); | |
809 | di<<" Select a vertex or an edge(build the middle)"<<"\n"; | |
810 | ||
811 | // Boucle d'attente waitpick. | |
812 | Standard_Integer argcc = 5; | |
813 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
814 | const char **argvv = (const char **) buff; | |
815 | while (ViewerMainLoop( argcc, argvv) ) { } | |
816 | // fin de la boucle | |
817 | ||
818 | TopoDS_Shape ShapeA; | |
819 | for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
820 | ShapeA= TheAISContext()->SelectedShape(); | |
821 | } | |
822 | ||
823 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
824 | // Un vertex a ete selectionne | |
825 | // Fermeture du context local | |
826 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
827 | ||
828 | // Construction du point | |
829 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); | |
830 | Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A ); | |
831 | Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint ); | |
832 | GetMapOfAIS().Bind(myAISPoint,name); | |
833 | TheAISContext()->Display(myAISPoint); | |
834 | } | |
835 | else { | |
836 | // Un Edge a ete selectionne | |
837 | // Fermeture du context local | |
838 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
839 | ||
840 | // Construction du point milieu de l'edge | |
841 | TopoDS_Edge myEdge=TopoDS::Edge(ShapeA); | |
842 | TopoDS_Vertex myVertexA,myVertexB; | |
843 | TopExp::Vertices (myEdge ,myVertexA ,myVertexB ); | |
844 | gp_Pnt A=BRep_Tool::Pnt(myVertexA ); | |
845 | gp_Pnt B=BRep_Tool::Pnt(myVertexB ); | |
846 | // M est le milieu de [AB] | |
847 | Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 ); | |
848 | Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM ); | |
849 | GetMapOfAIS().Bind(myAISPointM,name); | |
850 | TheAISContext()->Display(myAISPointM); | |
851 | } | |
852 | ||
853 | } | |
854 | return 0; | |
855 | ||
856 | } | |
857 | ||
858 | //============================================================================== | |
161c4476 | 859 | // Fonction 1st click 2de click 3de click |
7fd59977 | 860 | // vplane Vertex Vertex Vertex |
861 | // Vertex Edge | |
862 | // Edge Vertex | |
863 | // Face | |
864 | // vplanepara Face Vertex | |
865 | // Vertex Face | |
866 | // vplaneortho Face Edge | |
867 | // Edge Face | |
868 | //============================================================================== | |
869 | ||
870 | //============================================================================== | |
871 | //function : VPlaneBuilder | |
872 | //purpose : Build an AIS_Plane from selected entities or Named AIs components | |
873 | //Draw arg : vplane PlaneName [AxisName] [PointName] | |
874 | // [PointName] [PointName] [PointName] | |
875 | // [PlaneName] [PointName] | |
876 | //============================================================================== | |
877 | ||
878 | #include <TopoDS_Edge.hxx> | |
879 | #include <TopoDS_Vertex.hxx> | |
880 | #include <TopoDS_Face.hxx> | |
881 | #include <TopExp.hxx> | |
882 | #include <AIS_Plane.hxx> | |
883 | #include <Geom_CartesianPoint.hxx> | |
884 | #include <Geom_Plane.hxx> | |
885 | #include <BRepExtrema_ExtPC.hxx> | |
886 | #include <BRepExtrema_ExtPF.hxx> | |
887 | #include <BRepAdaptor_Surface.hxx> | |
888 | #include <gp_Pln.hxx> | |
889 | #include <GC_MakePlane.hxx> | |
890 | ||
161c4476 | 891 | static int VPlaneBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 892 | { |
893 | // Declarations | |
894 | Standard_Boolean HasArg; | |
895 | TCollection_AsciiString name; | |
896 | Standard_Integer myCurrentIndex; | |
897 | ||
898 | // Verification | |
899 | if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
900 | if (argc==5 || argc==4) HasArg=Standard_True; | |
901 | else HasArg=Standard_False; | |
902 | ||
903 | name=argv[1]; | |
904 | // Fermeture des contextes | |
905 | TheAISContext()->CloseAllContexts(); | |
906 | ||
907 | ||
908 | // Il y a des arguments | |
909 | if (HasArg) { | |
910 | if (!GetMapOfAIS().IsBound2(argv[2] ) ) {di<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;} | |
911 | // on recupere la shape dans la map | |
912 | Handle(AIS_InteractiveObject) theShapeA = | |
913 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] )); | |
914 | ||
915 | // Le premier argument est un AIS_Point 1 | |
916 | if (!theShapeA.IsNull() && | |
917 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
918 | // le deuxieme argument doit etre un AIS_Point aussi | |
919 | if (argc<5 || !GetMapOfAIS().IsBound2(argv[3] ) ) {di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;} | |
920 | // on recupere la shape dans la map | |
921 | Handle(AIS_InteractiveObject) theShapeB = | |
922 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
923 | // si B n'est pas un AIS_Point | |
924 | if (theShapeB.IsNull() || | |
925 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
926 | { | |
927 | di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n"; | |
928 | return 1; | |
929 | } | |
930 | // le troisieme objet est un AIS_Point | |
931 | if (!GetMapOfAIS().IsBound2(argv[4]) ) {di<<"vplane: error 3de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1; } | |
932 | // on recupere la shape dans la map | |
933 | Handle(AIS_InteractiveObject) theShapeC = | |
934 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4])); | |
935 | // si C n'est pas un AIS_Point | |
936 | if (theShapeC.IsNull() || | |
937 | (!(theShapeC->Type()==AIS_KOI_Datum && theShapeC->Signature()==1))) | |
938 | { | |
939 | di<<"vplane: error 3de object is expected to be an AIS_Point. "<<"\n"; | |
940 | return 1; | |
941 | } | |
942 | ||
161c4476 | 943 | // Traitement des objets A,B,C |
7fd59977 | 944 | // Downcaste de AIS_IO en AIS_Point |
945 | Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA; | |
946 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
947 | Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC; | |
948 | ||
949 | Handle(Geom_Point ) myGeomPointA= theAISPointA->Component(); | |
950 | Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA); | |
951 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; | |
952 | ||
953 | Handle(Geom_Point ) myGeomPointB = theAISPointB->Component(); | |
954 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB); | |
955 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; | |
956 | ||
957 | Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component(); | |
958 | Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC); | |
959 | // Handle(Geom_CartesianPoint ) myCartPointC= *(Handle(Geom_CartesianPoint)*)& (theAISPointC->Component() ) ; | |
960 | ||
961 | // Verification que les 3 points sont bien differents. | |
962 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
963 | // B=A | |
964 | di<<"vplane error: same points"<<"\n";return 1; | |
965 | } | |
966 | if (myCartPointC->X()==myCartPointA->X() && myCartPointC->Y()==myCartPointA->Y() && myCartPointC->Z()==myCartPointA->Z() ) { | |
967 | // C=A | |
968 | di<<"vplane error: same points"<<"\n";return 1; | |
969 | } | |
970 | if (myCartPointC->X()==myCartPointB->X() && myCartPointC->Y()==myCartPointB->Y() && myCartPointC->Z()==myCartPointB->Z() ) { | |
971 | // C=B | |
972 | di<<"vplane error: same points"<<"\n";return 1; | |
973 | } | |
974 | ||
975 | gp_Pnt A= myCartPointA->Pnt(); | |
976 | gp_Pnt B= myCartPointB->Pnt(); | |
977 | gp_Pnt C= myCartPointC->Pnt(); | |
978 | ||
979 | // Construction de l'AIS_Plane | |
980 | GC_MakePlane MkPlane (A,B,C); | |
981 | Handle(Geom_Plane) myGeomPlane = MkPlane.Value(); | |
982 | Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane ); | |
983 | GetMapOfAIS().Bind (myAISPlane,name ); | |
984 | TheAISContext()->Display(myAISPlane); | |
985 | } | |
986 | ||
161c4476 | 987 | // si le premier argument est un AIS_Axis 2 |
7fd59977 | 988 | // creation d'un plan orthogonal a l'axe passant par un point |
989 | else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==2 ) { | |
990 | // le deuxieme argument doit etre un AIS_Point | |
991 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) | |
992 | { | |
993 | di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n"; | |
994 | return 1; | |
995 | } | |
996 | // on recupere la shape dans la map | |
997 | Handle(AIS_InteractiveObject) theShapeB = | |
998 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
999 | // si B n'est pas un AIS_Point | |
1000 | if (theShapeB.IsNull() || | |
1001 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
1002 | { | |
1003 | di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n"; | |
1004 | return 1; | |
1005 | } | |
1006 | ||
161c4476 | 1007 | // Traitement des objets A et B |
7fd59977 | 1008 | Handle(AIS_Axis) theAISAxisA= *(Handle(AIS_Axis)*)& theShapeA; |
1009 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1010 | ||
1011 | Handle(Geom_Line ) myGeomLineA = theAISAxisA ->Component(); | |
1012 | Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ; | |
1013 | ||
1014 | gp_Ax1 myAxis= myGeomLineA->Position(); | |
1015 | Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB; | |
1016 | ||
1017 | // Pas de moyens de verifier que le point B n'est pas sur l'axe | |
1018 | ||
1019 | gp_Dir D=myAxis.Direction(); | |
1020 | gp_Pnt B= myCartPointB->Pnt(); | |
1021 | ||
1022 | // Construction de l'AIS_Plane | |
1023 | Handle(Geom_Plane) myGeomPlane= new Geom_Plane(B,D); | |
1024 | Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane,B ); | |
1025 | GetMapOfAIS().Bind (myAISPlane,name ); | |
1026 | TheAISContext()->Display(myAISPlane); | |
1027 | ||
1028 | } | |
1029 | // Si le premier argument est un AIS_Plane 7 | |
1030 | // Creation d'un Plan parallele a ce plan passant par le point | |
1031 | else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) { | |
1032 | // le deuxieme argument doit etre un AISPoint | |
1033 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) { | |
1034 | di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n"; | |
1035 | return 1; | |
1036 | } | |
1037 | // on recupere la shape dans la map | |
1038 | Handle(AIS_InteractiveObject) theShapeB = | |
1039 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
1040 | // si B n'est pas un AIS_Point | |
1041 | if (theShapeB.IsNull() || | |
1042 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
1043 | { | |
1044 | di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n"; | |
1045 | return 1; | |
1046 | } | |
1047 | ||
161c4476 | 1048 | // Traitement des objets A et B |
7fd59977 | 1049 | Handle(AIS_Plane) theAISPlaneA= *(Handle(AIS_Plane)*)& theShapeA; |
1050 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1051 | ||
1052 | Handle (Geom_Plane) theNewGeomPlane= theAISPlaneA->Component(); | |
1053 | Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ; | |
1054 | ||
1055 | Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB; | |
1056 | gp_Pnt B= myCartPointB->Pnt(); | |
1057 | ||
1058 | // Construction de l'AIS_Plane | |
1059 | Handle(AIS_Plane) myAISPlane = new AIS_Plane(theNewGeomPlane,B ); | |
1060 | GetMapOfAIS().Bind (myAISPlane,name ); | |
1061 | TheAISContext()->Display(myAISPlane); | |
1062 | ||
1063 | } | |
1064 | // Sinon erreur | |
1065 | else {di<<"vplane: error 1st object is not an AIS. "<<"\n";return 1;} | |
1066 | ||
1067 | } | |
1068 | ||
1069 | // Il n'y a pas d'arguments | |
1070 | else { | |
1071 | ||
1072 | // Fonction vplane | |
1073 | // Teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean ) | |
1074 | if (!strcasecmp(argv[0] ,"vplane" ) ) { | |
1075 | TheAISContext()->OpenLocalContext(); | |
1076 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1077 | ||
1078 | // Active les modes Vertex, Edge et Face | |
1079 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1080 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1081 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1082 | di<<"Select a vertex, a face or an edge. "<<"\n"; | |
1083 | ||
1084 | // Boucle d'attente waitpick. | |
1085 | Standard_Integer argcc = 5; | |
1086 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1087 | const char **argvv = (const char **) buff; | |
1088 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1089 | // fin de la boucle | |
1090 | ||
1091 | TopoDS_Shape ShapeA; | |
1092 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1093 | ShapeA = TheAISContext()->SelectedShape(); | |
1094 | } | |
1095 | ||
1096 | // ShapeA est un Vertex | |
1097 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1098 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1099 | di<<" Select an edge or a different vertex."<<"\n"; | |
1100 | ||
1101 | // Boucle d'attente waitpick. | |
1102 | Standard_Integer argccc = 5; | |
1103 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1104 | const char **argvvv = (const char **) bufff; | |
1105 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1106 | // fin de la boucle | |
1107 | ||
1108 | TopoDS_Shape ShapeB; | |
1109 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1110 | ShapeB = TheAISContext()->SelectedShape(); | |
1111 | } | |
1112 | // ShapeB est un Vertex | |
1113 | if (ShapeB.ShapeType()==TopAbs_VERTEX ) { | |
1114 | // Si A et B sont le meme point | |
1115 | if (ShapeB.IsSame(ShapeA) ) {di<<" vplane: error, same points selected"<<"\n";return 1; } | |
1116 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1117 | di<<" Select a different vertex."<<"\n"; | |
1118 | ||
1119 | // Boucle d'attente waitpick. | |
1120 | Standard_Integer argcccc = 5; | |
1121 | const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1122 | const char **argvvvv = (const char **) buffff; | |
1123 | while (ViewerMainLoop( argcccc, argvvvv) ) { } | |
1124 | // fin de la boucle | |
1125 | ||
1126 | TopoDS_Shape ShapeC; | |
1127 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1128 | ShapeC = TheAISContext()->SelectedShape(); | |
1129 | } | |
1130 | // ShapeC est aussi un vertex... | |
1131 | if (ShapeC.IsSame(ShapeA)||ShapeC.IsSame(ShapeB) ) {di<<" vplane: error, same points selected"<<"\n";return 1; } | |
1132 | ||
161c4476 | 1133 | // Fermeture du contexte local |
7fd59977 | 1134 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1135 | ||
161c4476 | 1136 | // Construction du plane |
7fd59977 | 1137 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); |
1138 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) ); | |
1139 | gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC ) ); | |
1140 | GC_MakePlane MkPlane(A,B,C); | |
1141 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
1142 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1143 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1144 | TheAISContext()->Display(myAISPlane); | |
1145 | ||
1146 | } | |
1147 | // ShapeB est un edge | |
1148 | else { | |
1149 | // il s'agit de verifier que le vertex ShapeA n'est pas sur l'edge ShapeB | |
1150 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); | |
1151 | TopoDS_Vertex VertA=TopoDS::Vertex(ShapeA); | |
1152 | ||
1153 | BRepExtrema_ExtPC OrthoProj (VertA, EdgeB ); | |
1154 | if (OrthoProj.SquareDistance(1)<1e-6 ) { | |
1155 | // Le vertex est sur l'edge | |
1156 | di<<" vplane: error point is on the edge."<<"\n";return 1; | |
1157 | } | |
1158 | else { | |
1159 | // le vertex n'appartient pes a l'edge on peut construire le plane | |
161c4476 | 1160 | // Fermeture du contexte local |
7fd59977 | 1161 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
161c4476 | 1162 | // Construction du plane |
7fd59977 | 1163 | gp_Pnt A=BRep_Tool::Pnt(VertA ); |
1164 | TopoDS_Vertex VBa,VBb; | |
1165 | TopExp::Vertices(EdgeB ,VBa ,VBb ); | |
1166 | gp_Pnt Ba=BRep_Tool::Pnt(VBa); | |
1167 | gp_Pnt Bb=BRep_Tool::Pnt(VBb); | |
1168 | GC_MakePlane MkPlane (A,Ba,Bb); | |
1169 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
1170 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1171 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1172 | TheAISContext()->Display(myAISPlane); | |
1173 | ||
1174 | } | |
1175 | ||
1176 | } | |
1177 | ||
1178 | } | |
1179 | // ShapeA est un edge | |
1180 | else if (ShapeA.ShapeType()==TopAbs_EDGE ) { | |
1181 | ||
1182 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1183 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1184 | di<<" Select a vertex that don't belong to the edge."<<"\n"; | |
1185 | ||
1186 | // Boucle d'attente waitpick. | |
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) ) { } | |
1191 | // fin de la boucle | |
1192 | ||
1193 | TopoDS_Shape ShapeB; | |
1194 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1195 | ShapeB = TheAISContext()->SelectedShape(); | |
1196 | } | |
1197 | // ShapeB est forcement un Vertex | |
1198 | // On verifie que le vertex ShapeB n'est pas sur l'edge ShapeA | |
1199 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); | |
1200 | TopoDS_Vertex VertB=TopoDS::Vertex(ShapeB); | |
1201 | ||
1202 | BRepExtrema_ExtPC OrthoProj (VertB,EdgeA ); | |
1203 | if (OrthoProj.SquareDistance(1)<1e-6) { | |
1204 | // Le vertex est sur l'edge | |
1205 | di<<" vplane: error point is on the edge."<<"\n";return 1; | |
1206 | } | |
1207 | else { | |
1208 | // le vertex n'appartient pas a l'edge on peut construire le plane | |
161c4476 | 1209 | // Fermeture du contexte local |
7fd59977 | 1210 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
161c4476 | 1211 | // Construction du plane |
7fd59977 | 1212 | gp_Pnt B=BRep_Tool::Pnt(VertB ); |
1213 | TopoDS_Vertex VAa,VAb; | |
1214 | TopExp::Vertices(EdgeA ,VAa ,VAb ); | |
1215 | gp_Pnt Aa=BRep_Tool::Pnt(VAa); | |
1216 | gp_Pnt Ab=BRep_Tool::Pnt(VAb); | |
1217 | GC_MakePlane MkPlane (B,Aa,Ab); | |
1218 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
1219 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1220 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1221 | TheAISContext()->Display(myAISPlane); | |
1222 | ||
1223 | } | |
1224 | ||
1225 | ||
1226 | } | |
1227 | // ShapeA est une Face | |
1228 | else { | |
1229 | // Fermeture du contexte local: Plus rien a selectionner | |
1230 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
161c4476 | 1231 | // Construction du plane |
7fd59977 | 1232 | TopoDS_Face myFace=TopoDS::Face(ShapeA); |
1233 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1234 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1235 | gp_Pln myPlane=mySurface.Plane(); | |
1236 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1237 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1238 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1239 | TheAISContext()->Display(myAISPlane); | |
1240 | ||
1241 | } | |
1242 | else { | |
1243 | di<<" vplane: error"<<"\n";return 1; | |
1244 | } | |
1245 | ||
1246 | } | |
1247 | ||
1248 | } | |
1249 | ||
1250 | // Fonction vPlanePara | |
1251 | // =================== | |
1252 | // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt ) | |
1253 | else if (!strcasecmp(argv[0] ,"vplanepara" )) { | |
1254 | ||
1255 | TheAISContext()->OpenLocalContext(); | |
1256 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1257 | ||
161c4476 | 1258 | // Active les modes Vertex et Face |
7fd59977 | 1259 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
1260 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1261 | di<<" Select a vertex or a face."<<"\n"; | |
1262 | ||
1263 | // Boucle d'attente waitpick. | |
1264 | Standard_Integer argcc = 5; | |
1265 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1266 | const char **argvv = (const char **) buff; | |
1267 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1268 | // fin de la boucle | |
1269 | ||
1270 | TopoDS_Shape ShapeA; | |
1271 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1272 | ShapeA = TheAISContext()->SelectedShape(); | |
1273 | } | |
1274 | ||
1275 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1276 | // ShapeA est un vertex | |
1277 | // On desactive le mode Vertex | |
1278 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1279 | di<<" Select a face."<<"\n"; | |
1280 | ||
1281 | // Boucle d'attente waitpick. | |
1282 | Standard_Integer argccc = 5; | |
1283 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1284 | const char **argvvv = (const char **) bufff; | |
1285 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1286 | // fin de la boucle | |
1287 | ||
1288 | TopoDS_Shape ShapeB; | |
1289 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1290 | // Le vertex ShapeA peut etre dans la Face ShapeB | |
1291 | ShapeB = TheAISContext()->SelectedShape(); | |
1292 | } | |
1293 | ||
1294 | // Fermeture du context local | |
1295 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1296 | ||
161c4476 | 1297 | // Construction du plane |
7fd59977 | 1298 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); |
1299 | ||
1300 | TopoDS_Face myFace=TopoDS::Face(ShapeB); | |
1301 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1302 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1303 | gp_Pln myPlane=mySurface.Plane(); | |
1304 | // construit un plan parallele a theGeomPlane passant par A | |
1305 | myPlane.SetLocation(A); | |
1306 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1307 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,A ); | |
1308 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1309 | TheAISContext()->Display(myAISPlane); | |
1310 | ||
1311 | } | |
1312 | else { | |
1313 | di<<" vplane: error"<<"\n";return 1; | |
1314 | } | |
1315 | ||
1316 | } | |
1317 | else{ | |
1318 | // ShapeA est une Face | |
1319 | // On desactive le mode Face | |
1320 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1321 | di<<" Select a vertex."<<"\n"; | |
1322 | ||
1323 | // Boucle d'attente waitpick. | |
1324 | Standard_Integer argccc = 5; | |
1325 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1326 | const char **argvvv = (const char **) bufff; | |
1327 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1328 | // fin de la boucle | |
1329 | ||
1330 | TopoDS_Shape ShapeB; | |
1331 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1332 | // Le vertex ShapeB peut etre dans la Face ShapeA | |
1333 | ShapeB = TheAISContext()->SelectedShape(); | |
1334 | } | |
1335 | // Fermeture du context local | |
1336 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1337 | ||
161c4476 | 1338 | // Construction du plane |
7fd59977 | 1339 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) ); |
1340 | ||
1341 | TopoDS_Face myFace=TopoDS::Face(ShapeA); | |
1342 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1343 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1344 | gp_Pln myPlane=mySurface.Plane(); | |
1345 | myPlane.SetLocation(B); | |
1346 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1347 | // construit un plan parallele a theGeomPlane passant par B | |
1348 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,B ); | |
1349 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1350 | TheAISContext()->Display(myAISPlane); | |
1351 | ||
1352 | } | |
1353 | else { | |
1354 | di<<" vplane: error"<<"\n";return 1; | |
1355 | } | |
1356 | ||
1357 | } | |
1358 | ||
1359 | } | |
1360 | ||
1361 | // Fonction vplaneortho | |
1362 | // ==================== | |
1363 | // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt) | |
1364 | else { | |
1365 | ||
1366 | TheAISContext()->OpenLocalContext(); | |
1367 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1368 | ||
161c4476 | 1369 | // Active les modes Edge et Face |
7fd59977 | 1370 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1371 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1372 | di<<" Select a face and an edge coplanar."<<"\n"; | |
1373 | ||
1374 | // Boucle d'attente waitpick. | |
1375 | Standard_Integer argcc = 5; | |
1376 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1377 | const char **argvv = (const char **) buff; | |
1378 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1379 | // fin de la boucle | |
1380 | ||
1381 | TopoDS_Shape ShapeA; | |
1382 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1383 | ShapeA = TheAISContext()->SelectedShape(); | |
1384 | } | |
1385 | ||
1386 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { | |
1387 | // ShapeA est un edge, on desactive le mode edge... | |
1388 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1389 | di<<" Select a face."<<"\n"; | |
1390 | ||
1391 | // Boucle d'attente waitpick. | |
1392 | Standard_Integer argccc = 5; | |
1393 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1394 | const char **argvvv = (const char **) bufff; | |
1395 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1396 | // fin de la boucle | |
1397 | ||
1398 | TopoDS_Shape ShapeB; | |
1399 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1400 | // L'edge ShapeA peut etre dans la Face ShapeB | |
1401 | ShapeB = TheAISContext()->SelectedShape(); | |
1402 | } | |
1403 | ||
1404 | // Fermeture du context local | |
1405 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1406 | ||
161c4476 | 1407 | // Construction du plane |
7fd59977 | 1408 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1409 | TopoDS_Vertex VAa,VAb; | |
1410 | // vi | |
1411 | TopExp::Vertices(EdgeA ,VAa ,VAb ); | |
1412 | gp_Pnt Aa=BRep_Tool::Pnt(VAa); | |
1413 | gp_Pnt Ab=BRep_Tool::Pnt(VAb); | |
1414 | gp_Vec ab (Aa,Ab); | |
1415 | ||
1416 | gp_Dir Dab (ab); | |
161c4476 K |
1417 | // Creation de mon axe de rotation |
1418 | gp_Ax1 myRotAxis (Aa,Dab); | |
7fd59977 | 1419 | |
1420 | TopoDS_Face myFace=TopoDS::Face(ShapeB); | |
1421 | // Il faut imperativement que l'edge soit parallele a la face | |
1422 | // vi | |
1423 | BRepExtrema_ExtPF myHauteurA (VAa , myFace ); | |
1424 | BRepExtrema_ExtPF myHauteurB (VAb , myFace ); | |
1425 | // on compare les deux hauteurs a la tolerance pres | |
1426 | if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt (myHauteurB.SquareDistance(1)) )>0.1 ) { | |
161c4476 | 1427 | // l'edge n'est pas parallele a la face |
7fd59977 | 1428 | di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1; |
1429 | } | |
1430 | // l'edge est OK | |
1431 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1432 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1433 | gp_Pln myPlane=mySurface.Plane(); | |
1434 | // On effectue une rotation d'1/2 tour autour de l'axe de rotation | |
c6541a0c | 1435 | myPlane.Rotate(myRotAxis , M_PI/2 ); |
7fd59977 | 1436 | |
1437 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1438 | // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA) | |
1439 | gp_Pnt theMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 ); | |
1440 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle ); | |
1441 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1442 | TheAISContext()->Display(myAISPlane); | |
1443 | ||
1444 | } | |
1445 | else { | |
1446 | di<<" vplaneOrtho: error"<<"\n";return 1; | |
1447 | } | |
1448 | ||
1449 | } | |
1450 | ||
1451 | else { | |
1452 | // ShapeA est une Face, on desactive le mode face. | |
1453 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1454 | di<<" Select an edge."<<"\n"; | |
1455 | ||
1456 | // Boucle d'attente waitpick. | |
1457 | Standard_Integer argccc = 5; | |
1458 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1459 | const char **argvvv = (const char **) bufff; | |
1460 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1461 | // fin de la boucle | |
1462 | ||
1463 | TopoDS_Shape ShapeB; | |
1464 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1465 | // L'edge ShapeB peut etre dans la Face ShapeA | |
1466 | ShapeB = TheAISContext()->SelectedShape(); | |
1467 | } | |
1468 | ||
1469 | // Fermeture du context local | |
1470 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1471 | ||
161c4476 | 1472 | // Construction du plane |
7fd59977 | 1473 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1474 | TopoDS_Vertex VBa,VBb; | |
1475 | TopExp::Vertices(EdgeB ,VBa ,VBb ); | |
1476 | gp_Pnt Ba=BRep_Tool::Pnt(VBa); | |
1477 | gp_Pnt Bb=BRep_Tool::Pnt(VBb); | |
1478 | gp_Vec ab (Ba,Bb); | |
1479 | gp_Dir Dab (ab); | |
161c4476 K |
1480 | // Creation de mon axe de rotation |
1481 | gp_Ax1 myRotAxis (Ba,Dab); | |
7fd59977 | 1482 | |
1483 | TopoDS_Face myFace=TopoDS::Face(ShapeA); | |
1484 | // Il faut imperativement que l'edge soit parallele a la face | |
1485 | BRepExtrema_ExtPF myHauteurA (VBa , myFace ); | |
1486 | BRepExtrema_ExtPF myHauteurB (VBb , myFace ); | |
1487 | // on compare les deux hauteurs a la tolerance pres | |
1488 | if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt(myHauteurB.SquareDistance(1)) )>0.1 ) { | |
161c4476 | 1489 | // l'edge n'est pas parallele a la face |
7fd59977 | 1490 | di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1; |
1491 | } | |
1492 | // l'edge est OK | |
1493 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1494 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1495 | gp_Pln myPlane=mySurface.Plane(); | |
1496 | // On effectue une rotation d'1/2 tour autour de l'axe de rotation | |
c6541a0c | 1497 | myPlane.Rotate(myRotAxis , M_PI/2 ); |
7fd59977 | 1498 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); |
1499 | // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA) | |
1500 | gp_Pnt theMiddle ((Ba.X()+Bb.X() )/2 , (Ba.Y()+Bb.Y() )/2 , (Ba.Z()+Bb.Z() )/2 ); | |
1501 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle ); | |
1502 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1503 | TheAISContext()->Display(myAISPlane); | |
1504 | ||
1505 | } | |
1506 | else { | |
1507 | di<<" vplaneOrtho: error"<<"\n";return 1; | |
1508 | } | |
1509 | ||
1510 | } | |
1511 | ||
1512 | } | |
1513 | ||
1514 | } | |
1515 | return 0; | |
1516 | ||
1517 | } | |
1518 | ||
1519 | ||
1520 | //============================================================================== | |
1521 | // Fonction vline | |
1522 | // --------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1523 | //============================================================================== | |
1524 | ||
1525 | //============================================================================== | |
1526 | //function : VLineBuilder | |
161c4476 | 1527 | //purpose : Build an AIS_Line |
7fd59977 | 1528 | //Draw arg : vline LineName [AIS_PointName] [AIS_PointName] |
1529 | // [Xa] [Ya] [Za] [Xb] [Yb] [Zb] | |
1530 | //============================================================================== | |
1531 | #include <Geom_CartesianPoint.hxx> | |
1532 | #include <AIS_Line.hxx> | |
1533 | ||
1534 | ||
161c4476 | 1535 | static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1536 | { |
1537 | Standard_Integer myCurrentIndex; | |
1538 | // Verifications | |
1539 | if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; } | |
1540 | // Fermeture des contextes | |
1541 | TheAISContext()->CloseAllContexts(); | |
1542 | ||
1543 | // On recupere les parametres | |
1544 | Handle(AIS_InteractiveObject) theShapeA; | |
1545 | Handle(AIS_InteractiveObject) theShapeB; | |
1546 | ||
1547 | // Parametres: AIS_Point AIS_Point | |
1548 | // =============================== | |
1549 | if (argc==4) { | |
1550 | theShapeA= | |
1551 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2])); | |
1552 | // On verifie que c'est bien une AIS_Point | |
1553 | if (!theShapeA.IsNull() && | |
1554 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
1555 | // on recupere le deuxieme AIS_Point | |
1556 | theShapeB= | |
1557 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
1558 | if (theShapeA.IsNull() || | |
1559 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
1560 | { | |
1561 | di <<"vline error: wrong type of 2de argument."<<"\n"; | |
1562 | return 1; | |
1563 | } | |
1564 | } | |
161c4476 | 1565 | else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; } |
7fd59977 | 1566 | // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus |
1567 | Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA; | |
1568 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1569 | ||
1570 | Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component(); | |
1571 | Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA); | |
1572 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; | |
1573 | ||
1574 | Handle(Geom_Point ) myGeomPointB= theAISPointB->Component(); | |
1575 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB); | |
1576 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; | |
1577 | ||
1578 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
1579 | // B=A | |
1580 | di<<"vline error: same points"<<"\n";return 1; | |
1581 | } | |
1582 | // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB) | |
1583 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1584 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1585 | TheAISContext()->Display(theAISLine ); | |
1586 | ||
1587 | } | |
1588 | ||
1589 | // Parametres 6 Reals | |
1590 | // ================== | |
1591 | ||
1592 | else if (argc==8) { | |
161c4476 | 1593 | // On verifie que les deux points ne sont pas confondus |
7fd59977 | 1594 | |
1595 | Standard_Real coord[6]; | |
1596 | for(Standard_Integer i=0;i<=2;i++){ | |
1597 | coord[i]=atof(argv[2+i]); | |
1598 | coord[i+3]=atof(argv[5+i]); | |
1599 | } | |
1600 | ||
1601 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] ); | |
1602 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] ); | |
1603 | ||
1604 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1605 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1606 | TheAISContext()->Display(theAISLine ); | |
1607 | ||
1608 | } | |
1609 | ||
1610 | // Pas de parametres: Selection dans le viewer. | |
1611 | // ============================================ | |
1612 | ||
1613 | else { | |
1614 | TheAISContext()->OpenLocalContext(); | |
1615 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1616 | ||
1617 | // Active le mode Vertex. | |
1618 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1619 | di<<" Select a vertex "<<"\n"; | |
1620 | ||
1621 | // Boucle d'attente waitpick. | |
1622 | Standard_Integer argcc = 5; | |
1623 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1624 | const char **argvv = (const char **) buff; | |
1625 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1626 | // fin de la boucle | |
1627 | ||
1628 | TopoDS_Shape ShapeA; | |
1629 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1630 | ShapeA = TheAISContext()->SelectedShape(); | |
1631 | } | |
1632 | ||
1633 | // ShapeA est un Vertex | |
1634 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1635 | ||
1636 | di<<" Select a different vertex."<<"\n"; | |
1637 | ||
1638 | TopoDS_Shape ShapeB; | |
1639 | do { | |
1640 | ||
1641 | // Boucle d'attente waitpick. | |
1642 | Standard_Integer argccc = 5; | |
1643 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1644 | const char **argvvv = (const char **) bufff; | |
1645 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 1646 | // fin de la boucle |
7fd59977 | 1647 | |
1648 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1649 | ShapeB = TheAISContext()->SelectedShape(); | |
1650 | } | |
1651 | ||
1652 | ||
1653 | } while(ShapeB.IsSame(ShapeA) ); | |
1654 | ||
1655 | // Fermeture du context local | |
1656 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1657 | ||
1658 | // Construction de la line | |
1659 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); | |
1660 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
1661 | ||
1662 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A); | |
1663 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B); | |
1664 | ||
1665 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1666 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1667 | TheAISContext()->Display(theAISLine ); | |
1668 | ||
1669 | } | |
1670 | else { | |
1671 | di<<"vline error."<<"\n"; | |
1672 | } | |
1673 | ||
1674 | } | |
1675 | ||
1676 | return 0; | |
1677 | } | |
1678 | ||
329843e2 A |
1679 | //============================================================================== |
1680 | // class : FilledCircle | |
1681 | // purpose : creates filled circle based on AIS_InteractiveObject | |
1682 | // and Geom_Circle. | |
1683 | // This class is used to check method Matches() of class | |
1684 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True, | |
1685 | // because none of AIS classes provides creation of | |
1686 | // Select3D_SensitiveCircle with member myFillStatus = Standard_True | |
1687 | // (look method ComputeSelection() ) | |
1688 | //============================================================================== | |
1689 | ||
1690 | Handle(Geom_Circle) CreateCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1691 | { | |
1692 | gp_Ax2 anAxes(theCenter, gp_Dir(gp_Vec(0., 0., 1.))); | |
1693 | gp_Circ aCirc(anAxes, theRadius); | |
1694 | Handle(Geom_Circle) aCircle = new Geom_Circle(aCirc); | |
1695 | return aCircle; | |
1696 | } | |
1697 | ||
1698 | DEFINE_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject) | |
1699 | ||
1700 | class FilledCircle : public AIS_InteractiveObject | |
1701 | { | |
1702 | public: | |
1703 | // CASCADE RTTI | |
1704 | DEFINE_STANDARD_RTTI(FilledCircle); | |
1705 | ||
1706 | FilledCircle(gp_Pnt theCenter, Standard_Real theRadius); | |
1707 | FilledCircle(Handle(Geom_Circle) theCircle); | |
1708 | ||
1709 | private: | |
1710 | TopoDS_Face ComputeFace(); | |
1711 | ||
1712 | // Virtual methods implementation | |
1713 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, | |
1714 | const Handle(Prs3d_Presentation)& thePresentation, | |
1715 | const Standard_Integer theMode); | |
1716 | ||
1717 | void ComputeSelection ( const Handle(SelectMgr_Selection)& theSelection, | |
1718 | const Standard_Integer theMode); | |
1719 | ||
1720 | protected: | |
1721 | Handle(Geom_Circle) myCircle; | |
1722 | Standard_Boolean myFilledStatus; | |
1723 | ||
1724 | }; | |
1725 | ||
1726 | IMPLEMENT_STANDARD_HANDLE(FilledCircle, AIS_InteractiveObject) | |
1727 | IMPLEMENT_STANDARD_RTTIEXT(FilledCircle, AIS_InteractiveObject) | |
1728 | ||
1729 | FilledCircle::FilledCircle(gp_Pnt theCenter, Standard_Real theRadius) | |
1730 | { | |
1731 | myCircle = CreateCircle(theCenter, theRadius); | |
1732 | myFilledStatus = Standard_True; | |
1733 | } | |
1734 | ||
1735 | FilledCircle::FilledCircle(Handle(Geom_Circle) theCircle) | |
1736 | { | |
1737 | myCircle = theCircle; | |
1738 | myFilledStatus = Standard_True; | |
1739 | } | |
1740 | ||
1741 | TopoDS_Face FilledCircle::ComputeFace() | |
1742 | { | |
1743 | // Create edge from myCircle | |
1744 | BRepBuilderAPI_MakeEdge anEdgeMaker(myCircle->Circ()); | |
1745 | TopoDS_Edge anEdge = anEdgeMaker.Edge(); | |
1746 | ||
1747 | // Create wire from anEdge | |
1748 | BRepBuilderAPI_MakeWire aWireMaker(anEdge); | |
1749 | TopoDS_Wire aWire = aWireMaker.Wire(); | |
1750 | ||
1751 | // Create face from aWire | |
1752 | BRepBuilderAPI_MakeFace aFaceMaker(aWire); | |
1753 | TopoDS_Face aFace = aFaceMaker.Face(); | |
1754 | ||
1755 | return aFace; | |
1756 | } | |
1757 | ||
1758 | void FilledCircle::Compute(const Handle_PrsMgr_PresentationManager3d &thePresentationManager, | |
1759 | const Handle_Prs3d_Presentation &thePresentation, | |
1760 | const Standard_Integer theMode) | |
1761 | { | |
1762 | thePresentation->Clear(); | |
1763 | ||
1764 | TopoDS_Face aFace = ComputeFace(); | |
1765 | ||
1766 | if (aFace.IsNull()) return; | |
1767 | if (theMode != 0) return; | |
1768 | ||
1769 | StdPrs_ShadedShape::Add(thePresentation, aFace, myDrawer); | |
1770 | } | |
1771 | ||
1772 | void FilledCircle::ComputeSelection(const Handle_SelectMgr_Selection &theSelection, | |
1773 | const Standard_Integer theMode) | |
1774 | { | |
1775 | Handle(SelectMgr_EntityOwner) anEntityOwner = new SelectMgr_EntityOwner(this); | |
1776 | Handle(Select3D_SensitiveCircle) aSensitiveCircle = new Select3D_SensitiveCircle(anEntityOwner, | |
1777 | myCircle, myFilledStatus); | |
1778 | theSelection->Add(aSensitiveCircle); | |
1779 | } | |
7fd59977 | 1780 | |
1781 | //============================================================================== | |
1782 | // Fonction vcircle | |
1783 | // ----------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1784 | //============================================================================== | |
1785 | ||
1786 | //============================================================================== | |
1787 | //function : VCircleBuilder | |
161c4476 | 1788 | //purpose : Build an AIS_Circle |
329843e2 A |
1789 | //Draw arg : vcircle CircleName PlaneName PointName Radius IsFilled |
1790 | // PointName PointName PointName IsFilled | |
7fd59977 | 1791 | //============================================================================== |
329843e2 A |
1792 | |
1793 | void DisplayCircle (Handle (Geom_Circle) theGeomCircle, | |
1794 | TCollection_AsciiString theName, | |
1795 | Standard_Boolean isFilled) | |
1796 | { | |
1797 | Handle(AIS_InteractiveObject) aCircle; | |
1798 | if (isFilled) | |
1799 | { | |
1800 | aCircle = new FilledCircle(theGeomCircle); | |
1801 | } | |
1802 | else | |
1803 | { | |
1804 | aCircle = new AIS_Circle(theGeomCircle); | |
1805 | } | |
1806 | ||
1807 | // Check if there is an object with given name | |
1808 | // and remove it from context | |
1809 | if (GetMapOfAIS().IsBound2(theName)) | |
1810 | { | |
1811 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2(theName); | |
1812 | Handle(AIS_InteractiveObject) anInterObj = | |
1813 | Handle(AIS_InteractiveObject)::DownCast(anObj); | |
1814 | TheAISContext()->Remove(anInterObj, Standard_False); | |
1815 | GetMapOfAIS().UnBind2(theName); | |
1816 | } | |
1817 | ||
1818 | // Bind the circle to its name | |
1819 | GetMapOfAIS().Bind(aCircle, theName); | |
1820 | ||
1821 | // Display the circle | |
1822 | TheAISContext()->Display(aCircle); | |
1823 | ||
1824 | } | |
7fd59977 | 1825 | |
161c4476 | 1826 | static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1827 | { |
1828 | Standard_Integer myCurrentIndex; | |
329843e2 A |
1829 | // Verification of the arguments |
1830 | if (argc>6 || argc<2) | |
1831 | { | |
1832 | std::cout << "vcircle error: expect 4 arguments.\n"; | |
1833 | return 1; // TCL_ERROR | |
1834 | } | |
7fd59977 | 1835 | TheAISContext()->CloseAllContexts(); |
1836 | ||
329843e2 A |
1837 | // There are all arguments |
1838 | if (argc == 6) | |
1839 | { | |
1840 | // Get arguments | |
1841 | TCollection_AsciiString aName(argv[1]); | |
1842 | Standard_Boolean isFilled = (Standard_Boolean)atoi(argv[5]); | |
1843 | ||
7fd59977 | 1844 | Handle(AIS_InteractiveObject) theShapeA; |
1845 | Handle(AIS_InteractiveObject) theShapeB; | |
1846 | ||
329843e2 A |
1847 | theShapeA = |
1848 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[2])); | |
1849 | theShapeB = | |
1850 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[3])); | |
1851 | ||
7fd59977 | 1852 | |
1853 | // Arguments: AIS_Point AIS_Point AIS_Point | |
1854 | // ======================================== | |
329843e2 | 1855 | if (!theShapeA.IsNull() && !theShapeB.IsNull() && |
7fd59977 | 1856 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) |
1857 | { | |
329843e2 A |
1858 | if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) |
1859 | { | |
1860 | std::cout << "vcircle error: 2d argument is unexpected to be a point.\n"; | |
1861 | return 1; // TCL_ERROR | |
7fd59977 | 1862 | } |
329843e2 | 1863 | // The third object must be a point |
7fd59977 | 1864 | Handle(AIS_InteractiveObject) theShapeC = |
329843e2 | 1865 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(argv[4])); |
7fd59977 | 1866 | if (theShapeC.IsNull() || |
329843e2 A |
1867 | theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) |
1868 | { | |
1869 | std::cout << "vcircle error: 3d argument is unexpected to be a point.\n"; | |
1870 | return 1; // TCL_ERROR | |
1871 | } | |
7fd59977 | 1872 | // tag |
329843e2 A |
1873 | // Verify that the three points are different |
1874 | Handle(AIS_Point) theAISPointA = Handle(AIS_Point)::DownCast(theShapeA); | |
1875 | Handle(AIS_Point) theAISPointB = Handle(AIS_Point)::DownCast(theShapeB); | |
1876 | Handle(AIS_Point) theAISPointC = Handle(AIS_Point)::DownCast(theShapeC); | |
1877 | ||
1878 | Handle(Geom_Point) myGeomPointA = theAISPointA->Component(); | |
1879 | Handle(Geom_CartesianPoint) myCartPointA = | |
1880 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointA); | |
1881 | ||
1882 | Handle(Geom_Point) myGeomPointB = theAISPointB->Component(); | |
1883 | Handle(Geom_CartesianPoint) myCartPointB = | |
1884 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointB); | |
1885 | ||
1886 | Handle(Geom_Point) myGeomPointC = theAISPointC->Component(); | |
1887 | Handle(Geom_CartesianPoint) myCartPointC = | |
1888 | Handle(Geom_CartesianPoint)::DownCast(myGeomPointC); | |
7fd59977 | 1889 | |
1890 | // Test A=B | |
329843e2 A |
1891 | if (abs(myCartPointA->X()-myCartPointB->X()) <= Precision::Confusion() && |
1892 | abs(myCartPointA->Y()-myCartPointB->Y()) <= Precision::Confusion() && | |
1893 | abs(myCartPointA->Z()-myCartPointB->Z()) <= Precision::Confusion() ) | |
1894 | { | |
1895 | std::cout << "vcircle error: Same points.\n"; | |
1896 | return 1; // TCL_ERROR | |
7fd59977 | 1897 | } |
1898 | // Test A=C | |
329843e2 A |
1899 | if (abs(myCartPointA->X()-myCartPointC->X()) <= Precision::Confusion() && |
1900 | abs(myCartPointA->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
1901 | abs(myCartPointA->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
1902 | { | |
1903 | std::cout << "vcircle error: Same points.\n"; | |
1904 | return 1; // TCL_ERROR | |
7fd59977 | 1905 | } |
1906 | // Test B=C | |
329843e2 A |
1907 | if (abs(myCartPointB->X()-myCartPointC->X()) <= Precision::Confusion() && |
1908 | abs(myCartPointB->Y()-myCartPointC->Y()) <= Precision::Confusion() && | |
1909 | abs(myCartPointB->Z()-myCartPointC->Z()) <= Precision::Confusion() ) | |
1910 | { | |
1911 | std::cout << "vcircle error: Same points.\n"; | |
1912 | return 1;// TCL_ERROR | |
7fd59977 | 1913 | } |
329843e2 A |
1914 | // Construction of the circle |
1915 | GC_MakeCircle Cir = GC_MakeCircle (myCartPointA->Pnt(), | |
1916 | myCartPointB->Pnt(), myCartPointC->Pnt() ); | |
1917 | Handle (Geom_Circle) theGeomCircle; | |
1918 | try | |
1919 | { | |
1920 | theGeomCircle = Cir.Value(); | |
1921 | } | |
1922 | catch (StdFail_NotDone) | |
1923 | { | |
1924 | std::cout << "vcircle error: can't create circle\n"; | |
1925 | return -1; // TCL_ERROR | |
1926 | } | |
1927 | ||
1928 | DisplayCircle(theGeomCircle, aName, isFilled); | |
7fd59977 | 1929 | } |
1930 | ||
329843e2 | 1931 | // Arguments: AIS_Plane AIS_Point Real |
7fd59977 | 1932 | // =================================== |
329843e2 A |
1933 | else if (theShapeA->Type() == AIS_KOI_Datum && |
1934 | theShapeA->Signature() == 7 ) | |
1935 | { | |
1936 | if (theShapeB->Type() != AIS_KOI_Datum || | |
1937 | theShapeB->Signature() != 1 ) | |
1938 | { | |
1939 | std::cout << "vcircle error: 2d element is a unexpected to be a point.\n"; | |
1940 | return 1; // TCL_ERROR | |
1941 | } | |
1942 |