Commit | Line | Data |
---|---|---|
7fd59977 | 1 | // File: ViewerTest_ObjectsCommands.cxx |
2 | // Created: Thu Nov 12 15:50:42 1998 | |
3 | // Author: Robert COUBLANC | |
4 | // <rob@robox.paris1.matra-dtv.fr> | |
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> |
29 | #include <V3d_Viewer.hxx> | |
30 | #include <V3d_View.hxx> | |
31 | #include <V3d.hxx> | |
32 | ||
33 | #include <AIS_Shape.hxx> | |
34 | #include <AIS_DisplayMode.hxx> | |
35 | #include <TColStd_MapOfInteger.hxx> | |
36 | #include <AIS_MapOfInteractive.hxx> | |
37 | #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx> | |
38 | #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx> | |
39 | #include <ViewerTest_EventManager.hxx> | |
40 | ||
41 | #include <TopoDS_Solid.hxx> | |
42 | #include <BRepTools.hxx> | |
43 | #include <BRep_Builder.hxx> | |
44 | #include <TopAbs_ShapeEnum.hxx> | |
45 | ||
46 | #include <TopoDS.hxx> | |
47 | #include <BRep_Tool.hxx> | |
48 | #include <TopExp_Explorer.hxx> | |
49 | ||
50 | #include <BRepAdaptor_Curve.hxx> | |
51 | #include <BRepAdaptor_Surface.hxx> | |
52 | ||
53 | #include <TopAbs.hxx> | |
54 | #include <TopExp.hxx> | |
55 | #include <TopoDS_Vertex.hxx> | |
56 | #include <TopoDS_Shape.hxx> | |
57 | #include <TopoDS_Face.hxx> | |
58 | ||
59 | #include <Draw_Window.hxx> | |
60 | #include <AIS_ListIteratorOfListOfInteractive.hxx> | |
61 | #include <AIS_ListOfInteractive.hxx> | |
62 | #include <AIS_DisplayMode.hxx> | |
63 | #include <AIS_Shape.hxx> | |
64 | ||
65 | #include <AIS_InteractiveContext.hxx> | |
66 | #include <Geom_Plane.hxx> | |
67 | #include <gp_Pln.hxx> | |
68 | #include <AIS_AngleDimension.hxx> | |
69 | #include <TCollection_ExtendedString.hxx> | |
70 | #include <GC_MakePlane.hxx> | |
71 | #include <gp_Circ.hxx> | |
72 | #include <AIS_Axis.hxx> | |
73 | #include <Geom_Axis2Placement.hxx> | |
74 | #include <Geom_Axis1Placement.hxx> | |
75 | #include <AIS_Trihedron.hxx> | |
76 | #include <AIS_Axis.hxx> | |
77 | #ifdef HAVE_STRINGS_H | |
78 | #include <strings.h> | |
79 | #endif | |
80 | ||
81 | #ifdef WNT | |
82 | #define _CRT_SECURE_NO_DEPRECATE | |
83 | #pragma warning (disable:4996) | |
84 | #endif | |
85 | ||
86 | extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS(); | |
87 | Standard_IMPORT int ViewerMainLoop(Standard_Integer argc, const char** argv); | |
88 | extern Handle(AIS_InteractiveContext)& TheAISContext(); | |
89 | ||
90 | ||
91 | //============================================================================== | |
92 | //function : Vtrihedron 2d | |
93 | //purpose : Create a plane with a 2D trihedron from a faceselection | |
161c4476 | 94 | //Draw arg : vtri2d name |
7fd59977 | 95 | //============================================================================== |
96 | #include <AIS_PlaneTrihedron.hxx> | |
97 | ||
98 | ||
99 | ||
100 | static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
101 | ||
102 | { | |
103 | // Verification des arguments | |
104 | if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;} | |
105 | ||
106 | // Declarations | |
107 | Standard_Integer myCurrentIndex; | |
161c4476 | 108 | // Fermeture des contextes |
7fd59977 | 109 | TheAISContext()->CloseAllContexts(); |
110 | // Ouverture d'un contexte local et recuperation de son index. | |
111 | TheAISContext()->OpenLocalContext(); | |
112 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
113 | // On active les modes de selections faces. | |
114 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
115 | di<<" Select a face ."<<"\n"; | |
116 | ||
117 | // Boucle d'attente waitpick. | |
118 | Standard_Integer argccc = 5; | |
119 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
120 | const char **argvvv = (const char **) bufff; | |
121 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
122 | // fin de la boucle | |
123 | ||
124 | TopoDS_Shape ShapeB; | |
125 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
126 | ShapeB = TheAISContext()->SelectedShape(); | |
127 | } | |
128 | ||
129 | TopoDS_Face FaceB=TopoDS::Face(ShapeB); | |
130 | ||
131 | // Construction du Plane | |
132 | // recuperation des edges des faces. | |
133 | TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE); | |
134 | ||
135 | TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() ); | |
161c4476 | 136 | // declarations |
7fd59977 | 137 | gp_Pnt A,B,C; |
138 | ||
139 | // si il y a plusieurs edges | |
140 | if (FaceExpB.More() ) { | |
141 | FaceExpB.Next(); | |
142 | TopoDS_Edge EdgeC=TopoDS::Edge(FaceExpB.Current() ); | |
143 | BRepAdaptor_Curve theCurveB(EdgeB); | |
144 | BRepAdaptor_Curve theCurveC(EdgeC); | |
145 | A=theCurveC.Value(0.1); | |
146 | B=theCurveC.Value(0.9); | |
147 | C=theCurveB.Value(0.5); | |
148 | } | |
149 | else { | |
150 | // FaceB a 1 unique edge courbe | |
151 | BRepAdaptor_Curve theCurveB(EdgeB); | |
152 | A=theCurveB.Value(0.1); | |
153 | B=theCurveB.Value(0.9); | |
154 | C=theCurveB.Value(0.5); | |
155 | } | |
156 | // Construction du Geom_Plane | |
157 | GC_MakePlane MkPlane(A,B,C); | |
158 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
159 | ||
160 | // Construction de l'AIS_PlaneTrihedron | |
161 | Handle(AIS_PlaneTrihedron) theAISPlaneTri= new AIS_PlaneTrihedron(theGeomPlane ); | |
162 | ||
163 | // Fermeture du contexte local. | |
164 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
165 | ||
166 | // on le display & bind | |
167 | TheAISContext()->Display(theAISPlaneTri ); | |
168 | GetMapOfAIS().Bind ( theAISPlaneTri ,argv[1]); | |
169 | ||
161c4476 | 170 | return 0; |
7fd59977 | 171 | } |
172 | ||
173 | ||
174 | ||
175 | //============================================================================== | |
176 | //function : VTriherdron | |
177 | //author : ege | |
178 | //purpose : Create a trihedron. If no arguments are set, the default | |
179 | // trihedron (Oxyz) is created. | |
180 | //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] | |
181 | //============================================================================== | |
182 | ||
183 | static int VTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
184 | ||
185 | { | |
186 | // Verification des arguments | |
187 | if ( argc<2 || argc>11) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
188 | ||
189 | // Declarations et creation des objets par default | |
190 | TCollection_AsciiString name=argv[1]; | |
191 | ||
192 | if(argc > 5 && argc!=11) | |
193 | {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
194 | ||
195 | // Cas ou il y a des arguments | |
196 | Standard_Real coord[9]={0.,0.,0.,0.,0.,1.,1.,0.,0.}; | |
197 | if (argc>2){ | |
198 | Standard_Integer i ; | |
199 | for( i=0;i<=2;i++) | |
200 | coord[i]= atof(argv[2+i]); | |
201 | ||
202 | if(argc>5){ | |
203 | for(i=0;i<=2;i++){ | |
204 | coord[3+i] = atof(argv[6+i]); | |
205 | coord[6+i] = atof(argv[8+i]); | |
206 | } | |
207 | } | |
208 | } | |
209 | gp_Pnt ThePoint(coord[0],coord[1],coord[2]); | |
210 | gp_Dir TheZVector(coord[3],coord[4],coord[5]); | |
211 | gp_Dir TheXVector(coord[6],coord[7],coord[8]); | |
212 | ||
213 | if ( !TheZVector.IsNormal(TheXVector,PI/180)) {di<<argv[0]<<" VectorX is not normal to VectorZ"<<"\n"; return 1;} | |
214 | ||
215 | Handle(Geom_Axis2Placement) OrigineAndAxii=new Geom_Axis2Placement(ThePoint,TheZVector,TheXVector); | |
216 | ||
217 | // Creation du triedre | |
218 | Handle(AIS_Trihedron) aShape= new AIS_Trihedron(OrigineAndAxii); | |
219 | GetMapOfAIS().Bind(aShape,name); | |
220 | TheAISContext()->Display(aShape); | |
221 | ||
161c4476 | 222 | return 0; |
7fd59977 | 223 | } |
224 | ||
225 | ||
226 | ||
227 | ||
228 | //============================================================================== | |
229 | //function : VSize | |
230 | //author : ege | |
231 | //purpose : Change the size of a named or selected trihedron | |
232 | // if no name : it affects the trihedrons witch are selected otherwise nothing is donne | |
233 | // if no value, the value is set at 100 by default | |
234 | //Draw arg : vsize [name] [size] | |
235 | //============================================================================== | |
236 | ||
237 | static int VSize (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
238 | ||
239 | { | |
240 | // Declaration de booleens | |
241 | Standard_Boolean ThereIsName; | |
242 | Standard_Boolean ThereIsCurrent; | |
243 | Standard_Real value; | |
161c4476 | 244 | Standard_Boolean hascol; |
7fd59977 | 245 | #ifdef DEB |
246 | Quantity_NameOfColor col; | |
247 | #else | |
248 | Quantity_NameOfColor col = Quantity_NOC_BLACK ; | |
249 | #endif | |
250 | ||
251 | // Verification des arguments | |
252 | if ( argc>3 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
253 | ||
254 | // Verification du nombre d'arguments | |
255 | if (argc==1) {ThereIsName=Standard_False;value=100;} | |
256 | else if (argc==2) {ThereIsName=Standard_False;value=atof(argv[1]);} | |
257 | else {ThereIsName=Standard_True;value=atof(argv[2]);} | |
258 | ||
259 | // On ferme le contexte local pour travailler dans le contexte global | |
161c4476 | 260 | if(TheAISContext()->HasOpenedContext()) |
7fd59977 | 261 | TheAISContext()->CloseLocalContext(); |
262 | ||
263 | // On set le booleen ThereIsCurrent | |
264 | if (TheAISContext() -> NbCurrents() > 0) {ThereIsCurrent=Standard_True;} | |
265 | else {ThereIsCurrent=Standard_False;} | |
266 | ||
267 | ||
268 | ||
269 | //=============================================================== | |
270 | // Il n'y a pas de nom mais des objets selectionnes | |
271 | //=============================================================== | |
161c4476 | 272 | if (!ThereIsName && ThereIsCurrent) |
7fd59977 | 273 | { |
274 | ||
275 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
276 | it (GetMapOfAIS()); | |
277 | ||
278 | while ( it.More() ) { | |
279 | ||
280 | Handle(AIS_InteractiveObject) aShape= | |
281 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
282 | ||
283 | if (!aShape.IsNull() && TheAISContext()->IsCurrent(aShape) ) | |
284 | { | |
285 | ||
161c4476 | 286 | // On verifie que l'AIS InteraciveObject selectionne est bien |
7fd59977 | 287 | // un AIS_Trihedron |
288 | if (aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) { | |
289 | ||
290 | if (aShape->HasColor()) { | |
291 | hascol=Standard_True; | |
292 | ||
293 | // On recupere la couleur de aShape | |
294 | col=aShape->Color();} | |
295 | ||
296 | else hascol=Standard_False; | |
297 | ||
298 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
299 | // pour lui appliquer la methode SetSize() | |
300 | Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape; | |
301 | ||
302 | // C'est bien un triedre,on chage sa valeur! | |
303 | aTrihedron->SetSize(value); | |
304 | ||
305 | // On donne la couleur au Trihedron | |
306 | if(hascol) aTrihedron->SetColor(col); | |
307 | else aTrihedron->UnsetColor(); | |
308 | ||
309 | ||
310 | // The trihedron hasn't be errased from the map | |
311 | // so you just have to redisplay it | |
312 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
313 | ||
314 | } | |
315 | ||
316 | } | |
317 | ||
318 | it.Next(); | |
319 | } | |
320 | ||
321 | TheAISContext() ->UpdateCurrentViewer(); | |
322 | } | |
323 | ||
324 | //=============================================================== | |
325 | // Il n'y a pas d'arguments et aucuns objets selectionne Rien A Faire! | |
326 | //=============================================================== | |
327 | ||
328 | ||
329 | ||
330 | //=============================================================== | |
331 | // Il y a un nom de triedre passe en argument | |
332 | //=============================================================== | |
333 | if (ThereIsName) { | |
334 | TCollection_AsciiString name=argv[1]; | |
335 | ||
336 | // on verifie que ce nom correspond bien a une shape | |
337 | Standard_Boolean IsBound= GetMapOfAIS().IsBound2(name); | |
338 | ||
339 | if (IsBound) { | |
340 | ||
341 | // on recupere la shape dans la map des objets displayes | |
342 | Handle(AIS_InteractiveObject) aShape = | |
343 | Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(name)); | |
344 | ||
161c4476 | 345 | // On verifie que l'AIS InteraciveObject est bien |
7fd59977 | 346 | // un AIS_Trihedron |
347 | if (!aShape.IsNull() && | |
348 | aShape->Type()==AIS_KOI_Datum && aShape->Signature()==3) | |
349 | { | |
350 | ||
351 | if (aShape->HasColor()) { | |
352 | hascol=Standard_True; | |
353 | ||
354 | // On recupere la couleur de aShape | |
355 | col=aShape->Color();} | |
356 | ||
357 | else hascol=Standard_False; | |
358 | ||
359 | // On downcast aShape de AIS_InteractiveObject a AIS_Trihedron | |
360 | // pour lui appliquer la methode SetSize() | |
361 | Handle(AIS_Trihedron) aTrihedron = *(Handle(AIS_Trihedron)*) &aShape; | |
362 | ||
363 | // C'est bien un triedre,on chage sa valeur | |
364 | aTrihedron->SetSize(value); | |
365 | ||
366 | // On donne la couleur au Trihedron | |
367 | if(hascol) aTrihedron->SetColor(col); | |
368 | else aTrihedron->UnsetColor(); | |
369 | ||
370 | // The trihedron hasn't be errased from the map | |
371 | // so you just have to redisplay it | |
372 | TheAISContext() ->Redisplay(aTrihedron,Standard_False); | |
373 | ||
374 | TheAISContext() ->UpdateCurrentViewer(); | |
375 | } | |
376 | } | |
377 | } | |
161c4476 | 378 | return 0; |
7fd59977 | 379 | } |
380 | ||
381 | ||
382 | //============================================================================== | |
383 | ||
384 | //============================================================================== | |
385 | //function : VPlaneTrihedron | |
386 | //purpose : Create a plane from a trihedron selection. If no arguments are set, the default | |
161c4476 | 387 | //Draw arg : vplanetri name |
7fd59977 | 388 | //============================================================================== |
389 | #include <AIS_Plane.hxx> | |
390 | ||
391 | ||
392 | ||
393 | static int VPlaneTrihedron (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
394 | ||
395 | { | |
396 | // Verification des arguments | |
397 | if ( argc!=2) {di<<argv[0]<<" error"<<"\n"; return 1;} | |
398 | ||
399 | // Declarations | |
400 | Standard_Integer myCurrentIndex; | |
401 | // Fermeture des contextes locaux | |
402 | TheAISContext()->CloseAllContexts(); | |
403 | ||
161c4476 | 404 | // On recupere tous les trihedrons de la GetMapOfAIS() |
7fd59977 | 405 | // et on active le mode de selection par face. |
406 | // ================================================= | |
407 | ||
408 | // Ouverture d'un contexte local et recuperation de son index. | |
409 | TheAISContext()->OpenLocalContext(Standard_False); | |
410 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
411 | ||
412 | ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName | |
413 | it (GetMapOfAIS()); | |
414 | while(it.More()){ | |
415 | Handle(AIS_InteractiveObject) ShapeA = | |
416 | Handle(AIS_InteractiveObject)::DownCast(it.Key1()); | |
417 | // On verifie que c'est bien un trihedron | |
418 | if (!ShapeA.IsNull() && | |
419 | ShapeA->Type()==AIS_KOI_Datum && ShapeA->Signature()==3 ) { | |
420 | // on le downcast | |
421 | Handle(AIS_Trihedron) TrihedronA =((*(Handle(AIS_Trihedron)*)&ShapeA)); | |
422 | // on le charge dans le contexte et on active le mode Plane. | |
423 | TheAISContext()->Load(TrihedronA,0,Standard_False); | |
424 | TheAISContext()->Activate(TrihedronA,3); | |
425 | } | |
426 | it.Next(); | |
427 | } | |
428 | ||
429 | di<<" Select a plane."<<"\n"; | |
430 | // Boucle d'attente waitpick. | |
431 | Standard_Integer argccc = 5; | |
432 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
433 | const char **argvvv = (const char **) bufff; | |
434 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
435 | // fin de la boucle | |
436 | ||
437 | Handle(AIS_InteractiveObject) theIOB; | |
438 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
439 | theIOB = TheAISContext()->Interactive(); | |
440 | } | |
441 | // on le downcast | |
442 | Handle(AIS_Plane) PlaneB =((*(Handle(AIS_Plane)*)&theIOB)); | |
443 | ||
444 | // Fermeture du contexte local. | |
445 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
446 | ||
447 | // on le display & bind | |
448 | TheAISContext()->Display(PlaneB ); | |
449 | GetMapOfAIS().Bind ( PlaneB ,argv[1]); | |
450 | ||
161c4476 | 451 | return 0; |
7fd59977 | 452 | } |
453 | ||
454 | ||
455 | ||
456 | //============================================================================== | |
457 | // Fonction First click 2de click | |
161c4476 | 458 | // |
7fd59977 | 459 | // vaxis vertex vertex |
460 | // edge None | |
461 | // vaxispara edge vertex | |
462 | // vaxisortho edge Vertex | |
463 | // vaxisinter Face Face | |
464 | //============================================================================== | |
465 | ||
466 | //============================================================================== | |
467 | //function : VAxisBuilder | |
161c4476 | 468 | //purpose : |
7fd59977 | 469 | //Draw arg : vaxis AxisName Xa Ya Za Xb Yb Zb |
470 | //============================================================================== | |
471 | #include <TopoDS_Edge.hxx> | |
472 | #include <TopoDS_Vertex.hxx> | |
473 | #include <TopExp.hxx> | |
474 | #include <Geom_Line.hxx> | |
475 | ||
161c4476 | 476 | static int VAxisBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 477 | { |
478 | // Declarations | |
479 | Standard_Boolean HasArg; | |
480 | TCollection_AsciiString name; | |
481 | Standard_Integer MyCurrentIndex; | |
482 | ||
483 | // Verification | |
484 | if (argc<2 || argc>8 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
485 | if (argc==8) HasArg=Standard_True; | |
486 | else HasArg=Standard_False; | |
487 | ||
488 | name=argv[1]; | |
489 | // Fermeture des contextes | |
490 | TheAISContext()->CloseAllContexts(); | |
491 | ||
492 | // Cas ou il y a des arguments | |
493 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Line from Geom) | |
494 | if (HasArg) { | |
495 | Standard_Real coord[6]; | |
496 | for(Standard_Integer i=0;i<=5;i++){ | |
497 | coord[i]=atof(argv[2+i]); | |
498 | } | |
499 | gp_Pnt p1(coord[0],coord[1],coord[2]), p2(coord[3],coord[4],coord[5]) ; | |
500 | ||
501 | gp_Vec myVect (p1,p2); | |
502 | Handle(Geom_Line) myLine=new Geom_Line (p1 ,myVect ); | |
503 | Handle(AIS_Axis) TheAxis=new AIS_Axis (myLine ); | |
504 | GetMapOfAIS().Bind (TheAxis,name); | |
505 | TheAISContext()->Display(TheAxis); | |
506 | } | |
507 | ||
508 | // Pas d'arguments | |
509 | else { | |
510 | // fonction vaxis | |
511 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis (x:Axis1Placement from Geom) | |
512 | if ( !strcasecmp(argv[0], "vaxis")) { | |
513 | TheAISContext()->OpenLocalContext(); | |
514 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
515 | ||
516 | // Active le mode edge et le mode vertex | |
517 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
518 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); | |
519 | di<<" Select an edge or a vertex."<<"\n"; | |
520 | ||
521 | // Boucle d'attente waitpick. | |
522 | Standard_Integer argcc = 5; | |
523 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
524 | const char **argvv = (const char **) buff; | |
525 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 526 | // fin de la boucle |
7fd59977 | 527 | |
528 | // recuperation de la shape. | |
529 | TopoDS_Shape ShapeA; | |
530 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
531 | ShapeA = TheAISContext()->SelectedShape(); | |
532 | } | |
533 | // recuperation de l'AIS_InteractiveObject | |
534 | //Handle(AIS_InteractiveObject) myAISio=TheAISContext()->Current(); | |
535 | // down cast en AIS_Point si sig et type | |
536 | // AIS_Point -> Geom_Pnt .... | |
537 | ||
538 | if (ShapeA.ShapeType()==TopAbs_VERTEX) { | |
539 | // on desactive le mode edge | |
540 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
541 | di<<" Select a different vertex."<<"\n"; | |
542 | ||
543 | TopoDS_Shape ShapeB; | |
544 | do { | |
545 | // Boucle d'attente waitpick. | |
546 | Standard_Integer argccc = 5; | |
547 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
548 | const char **argvvv = (const char **) bufff; | |
549 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 550 | // fin de la boucle |
7fd59977 | 551 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { |
552 | ShapeB = TheAISContext()->SelectedShape(); | |
553 | } | |
554 | ||
555 | ||
556 | } while(ShapeB.IsSame(ShapeA) ); | |
557 | ||
558 | // Fermeture du context local | |
559 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
560 | ||
161c4476 | 561 | // Construction de l'axe |
7fd59977 | 562 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); |
563 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
564 | gp_Vec V (A,B); | |
565 | gp_Dir D (V); | |
566 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
567 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
568 | GetMapOfAIS().Bind (TheAxis,name); | |
569 | TheAISContext()->Display(TheAxis); | |
161c4476 | 570 | } |
7fd59977 | 571 | else { |
572 | // Un unique edge (ShapeA) a ete picke | |
573 | // Fermeture du context local | |
574 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
161c4476 | 575 | // Constuction de l'axe |
7fd59977 | 576 | TopoDS_Edge ed =TopoDS::Edge(ShapeA); |
577 | TopoDS_Vertex Va,Vb; | |
578 | TopExp::Vertices(ed,Va,Vb ); | |
579 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
580 | gp_Pnt B=BRep_Tool::Pnt(Vb); | |
581 | gp_Vec V (A,B); | |
582 | gp_Dir D (V); | |
583 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (A,D); | |
584 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
585 | GetMapOfAIS().Bind (TheAxis,name); | |
586 | TheAISContext()->Display(TheAxis); | |
587 | } | |
588 | ||
589 | } | |
590 | ||
591 | // Fonction axispara | |
592 | // Purpose: Teste le constructeur AIS_Axis::AIS_Axis(x: Axis2Placement from Geom, y: TypeOfAxis from AIS) | |
593 | else if ( !strcasecmp(argv[0], "vaxispara")) { | |
594 | ||
595 | TheAISContext()->OpenLocalContext(); | |
596 | MyCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
597 | ||
161c4476 | 598 | // Active le mode edge |
7fd59977 | 599 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(2) ); |
600 | di<<" Select an edge."<<"\n"; | |
601 | ||
602 | // Boucle d'attente waitpick. | |
603 | Standard_Integer argcc = 5; | |
604 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
605 | const char **argvv = (const char **) buff; | |
606 | while (ViewerMainLoop( argcc, argvv) ) { } | |
161c4476 | 607 | // fin de la boucle |
7fd59977 | 608 | |
609 | TopoDS_Shape ShapeA; | |
610 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
611 | ShapeA = TheAISContext()->SelectedShape(); | |
612 | } | |
613 | // Active le mode vertex et deactive edges | |
614 | TheAISContext()->DeactivateStandardMode(AIS_Shape::SelectionType(2) ); | |
615 | TheAISContext()->ActivateStandardMode(AIS_Shape::SelectionType(1) ); | |
616 | di<<" Select a vertex."<<"\n"; | |
617 | ||
618 | // Boucle d'attente waitpick. | |
619 | Standard_Integer argccc = 5; | |
620 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
621 | const char **argvvv = (const char **) bufff; | |
622 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 623 | // fin de la boucle |
7fd59977 | 624 | |
625 | // On peut choisir un pnt sur l'edge | |
626 | TopoDS_Shape ShapeB; | |
627 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
628 | ShapeB = TheAISContext()->SelectedShape(); | |
629 | } | |
630 | // Fermeture du context local | |
631 | TheAISContext()->CloseLocalContext(MyCurrentIndex); | |
632 | ||
633 | // Construction de l'axe | |
634 | TopoDS_Edge ed=TopoDS::Edge(ShapeA) ; | |
635 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
636 | TopoDS_Vertex Va,Vc; | |
637 | TopExp::Vertices(ed,Va,Vc ); | |
638 | gp_Pnt A=BRep_Tool::Pnt(Va); | |
639 | gp_Pnt C=BRep_Tool::Pnt(Vc); | |
640 | gp_Vec V (A,C); | |
641 | gp_Dir D (V); | |
642 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
643 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
644 | GetMapOfAIS().Bind (TheAxis,name); | |
645 | TheAISContext()->Display(TheAxis); | |
646 | ||
647 | } | |
648 | ||
649 | // Fonction axisortho | |
650 | else { | |
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<<" Slect 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_Pnt E(A.Y()+A.Z()-C.Y()-C.Z() ,C.X()-A.X() ,C.X()-A.X() ); | |
697 | gp_Vec V (A,E); | |
698 | gp_Dir D (V); | |
699 | Handle(Geom_Axis1Placement) OrigineAndVect=new Geom_Axis1Placement (B,D); | |
700 | Handle(AIS_Axis) TheAxis=new AIS_Axis (OrigineAndVect); | |
701 | GetMapOfAIS().Bind (TheAxis,name); | |
702 | TheAISContext()->Display(TheAxis); | |
703 | ||
704 | } | |
705 | ||
706 | } | |
707 | return 0; | |
708 | } | |
709 | ||
710 | ||
711 | //============================================================================== | |
712 | // Fonction First click Result | |
161c4476 | 713 | // |
7fd59977 | 714 | // vpoint vertex AIS_Point=Vertex |
715 | // edge AIS_Point=Middle of the edge | |
716 | //============================================================================== | |
717 | ||
718 | //============================================================================== | |
719 | //function : VPointBuilder | |
720 | //purpose : Build an AIS_Point from coordinates or with a selected vertex or edge | |
721 | //Draw arg : vpoint PoinName [Xa] [Ya] [Za] | |
722 | //============================================================================== | |
723 | #include <TopoDS_Edge.hxx> | |
724 | #include <TopoDS_Vertex.hxx> | |
725 | #include <TopExp.hxx> | |
726 | #include <AIS_Point.hxx> | |
727 | #include <Geom_CartesianPoint.hxx> | |
728 | ||
161c4476 | 729 | static int VPointBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 730 | { |
731 | // Declarations | |
732 | Standard_Boolean HasArg; | |
733 | TCollection_AsciiString name; | |
734 | Standard_Integer myCurrentIndex; | |
735 | ||
736 | // Verification | |
737 | if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
738 | if (argc==5) HasArg=Standard_True; | |
739 | else HasArg=Standard_False; | |
740 | ||
741 | name=argv[1]; | |
742 | // Fermeture des contextes | |
743 | TheAISContext()->CloseAllContexts(); | |
744 | ||
745 | // Il y a des arguments: teste l'unique constructeur AIS_Pnt::AIS_Pnt(Point from Geom) | |
746 | if (HasArg) { | |
747 | Standard_Real thecoord[3]; | |
748 | for(Standard_Integer i=0;i<=2;i++) | |
749 | thecoord[i]=atof(argv[2+i]); | |
750 | Handle(Geom_CartesianPoint ) myGeomPoint= new Geom_CartesianPoint (thecoord[0],thecoord[1],thecoord[2]); | |
751 | Handle(AIS_Point) myAISPoint=new AIS_Point(myGeomPoint ); | |
752 | GetMapOfAIS().Bind (myAISPoint,name); | |
753 | TheAISContext()->Display(myAISPoint); | |
754 | } | |
755 | ||
756 | // Il n'a pas d'arguments | |
757 | else { | |
758 | TheAISContext()->OpenLocalContext(); | |
759 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
760 | ||
761 | // Active le mode Vertex et Edges | |
762 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
763 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); | |
764 | di<<" Select a vertex or an edge(build the middle)"<<"\n"; | |
765 | ||
766 | // Boucle d'attente waitpick. | |
767 | Standard_Integer argcc = 5; | |
768 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
769 | const char **argvv = (const char **) buff; | |
770 | while (ViewerMainLoop( argcc, argvv) ) { } | |
771 | // fin de la boucle | |
772 | ||
773 | TopoDS_Shape ShapeA; | |
774 | for (TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
775 | ShapeA= TheAISContext()->SelectedShape(); | |
776 | } | |
777 | ||
778 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
779 | // Un vertex a ete selectionne | |
780 | // Fermeture du context local | |
781 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
782 | ||
783 | // Construction du point | |
784 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); | |
785 | Handle(Geom_CartesianPoint) myGeomPoint= new Geom_CartesianPoint (A ); | |
786 | Handle(AIS_Point) myAISPoint = new AIS_Point (myGeomPoint ); | |
787 | GetMapOfAIS().Bind(myAISPoint,name); | |
788 | TheAISContext()->Display(myAISPoint); | |
789 | } | |
790 | else { | |
791 | // Un Edge a ete selectionne | |
792 | // Fermeture du context local | |
793 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
794 | ||
795 | // Construction du point milieu de l'edge | |
796 | TopoDS_Edge myEdge=TopoDS::Edge(ShapeA); | |
797 | TopoDS_Vertex myVertexA,myVertexB; | |
798 | TopExp::Vertices (myEdge ,myVertexA ,myVertexB ); | |
799 | gp_Pnt A=BRep_Tool::Pnt(myVertexA ); | |
800 | gp_Pnt B=BRep_Tool::Pnt(myVertexB ); | |
801 | // M est le milieu de [AB] | |
802 | Handle(Geom_CartesianPoint) myGeomPointM= new Geom_CartesianPoint ( (A.X()+B.X())/2 , (A.Y()+B.Y())/2 , (A.Z()+B.Z())/2 ); | |
803 | Handle(AIS_Point) myAISPointM = new AIS_Point (myGeomPointM ); | |
804 | GetMapOfAIS().Bind(myAISPointM,name); | |
805 | TheAISContext()->Display(myAISPointM); | |
806 | } | |
807 | ||
808 | } | |
809 | return 0; | |
810 | ||
811 | } | |
812 | ||
813 | //============================================================================== | |
161c4476 | 814 | // Fonction 1st click 2de click 3de click |
7fd59977 | 815 | // vplane Vertex Vertex Vertex |
816 | // Vertex Edge | |
817 | // Edge Vertex | |
818 | // Face | |
819 | // vplanepara Face Vertex | |
820 | // Vertex Face | |
821 | // vplaneortho Face Edge | |
822 | // Edge Face | |
823 | //============================================================================== | |
824 | ||
825 | //============================================================================== | |
826 | //function : VPlaneBuilder | |
827 | //purpose : Build an AIS_Plane from selected entities or Named AIs components | |
828 | //Draw arg : vplane PlaneName [AxisName] [PointName] | |
829 | // [PointName] [PointName] [PointName] | |
830 | // [PlaneName] [PointName] | |
831 | //============================================================================== | |
832 | ||
833 | #include <TopoDS_Edge.hxx> | |
834 | #include <TopoDS_Vertex.hxx> | |
835 | #include <TopoDS_Face.hxx> | |
836 | #include <TopExp.hxx> | |
837 | #include <AIS_Plane.hxx> | |
838 | #include <Geom_CartesianPoint.hxx> | |
839 | #include <Geom_Plane.hxx> | |
840 | #include <BRepExtrema_ExtPC.hxx> | |
841 | #include <BRepExtrema_ExtPF.hxx> | |
842 | #include <BRepAdaptor_Surface.hxx> | |
843 | #include <gp_Pln.hxx> | |
844 | #include <GC_MakePlane.hxx> | |
845 | ||
161c4476 | 846 | static int VPlaneBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 847 | { |
848 | // Declarations | |
849 | Standard_Boolean HasArg; | |
850 | TCollection_AsciiString name; | |
851 | Standard_Integer myCurrentIndex; | |
852 | ||
853 | // Verification | |
854 | if (argc<2 || argc>5 ) {di<<" Syntaxe error"<<"\n";return 1;} | |
855 | if (argc==5 || argc==4) HasArg=Standard_True; | |
856 | else HasArg=Standard_False; | |
857 | ||
858 | name=argv[1]; | |
859 | // Fermeture des contextes | |
860 | TheAISContext()->CloseAllContexts(); | |
861 | ||
862 | ||
863 | // Il y a des arguments | |
864 | if (HasArg) { | |
865 | if (!GetMapOfAIS().IsBound2(argv[2] ) ) {di<<"vplane: error 1st name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;} | |
866 | // on recupere la shape dans la map | |
867 | Handle(AIS_InteractiveObject) theShapeA = | |
868 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2] )); | |
869 | ||
870 | // Le premier argument est un AIS_Point 1 | |
871 | if (!theShapeA.IsNull() && | |
872 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
873 | // le deuxieme argument doit etre un AIS_Point aussi | |
874 | if (argc<5 || !GetMapOfAIS().IsBound2(argv[3] ) ) {di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1;} | |
875 | // on recupere la shape dans la map | |
876 | Handle(AIS_InteractiveObject) theShapeB = | |
877 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
878 | // si B n'est pas un AIS_Point | |
879 | if (theShapeB.IsNull() || | |
880 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
881 | { | |
882 | di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n"; | |
883 | return 1; | |
884 | } | |
885 | // le troisieme objet est un AIS_Point | |
886 | if (!GetMapOfAIS().IsBound2(argv[4]) ) {di<<"vplane: error 3de name doesn't exist in the GetMapOfAIS()."<<"\n";return 1; } | |
887 | // on recupere la shape dans la map | |
888 | Handle(AIS_InteractiveObject) theShapeC = | |
889 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4])); | |
890 | // si C n'est pas un AIS_Point | |
891 | if (theShapeC.IsNull() || | |
892 | (!(theShapeC->Type()==AIS_KOI_Datum && theShapeC->Signature()==1))) | |
893 | { | |
894 | di<<"vplane: error 3de object is expected to be an AIS_Point. "<<"\n"; | |
895 | return 1; | |
896 | } | |
897 | ||
161c4476 | 898 | // Traitement des objets A,B,C |
7fd59977 | 899 | // Downcaste de AIS_IO en AIS_Point |
900 | Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA; | |
901 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
902 | Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC; | |
903 | ||
904 | Handle(Geom_Point ) myGeomPointA= theAISPointA->Component(); | |
905 | Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA); | |
906 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; | |
907 | ||
908 | Handle(Geom_Point ) myGeomPointB = theAISPointB->Component(); | |
909 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB); | |
910 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; | |
911 | ||
912 | Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component(); | |
913 | Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC); | |
914 | // Handle(Geom_CartesianPoint ) myCartPointC= *(Handle(Geom_CartesianPoint)*)& (theAISPointC->Component() ) ; | |
915 | ||
916 | // Verification que les 3 points sont bien differents. | |
917 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
918 | // B=A | |
919 | di<<"vplane error: same points"<<"\n";return 1; | |
920 | } | |
921 | if (myCartPointC->X()==myCartPointA->X() && myCartPointC->Y()==myCartPointA->Y() && myCartPointC->Z()==myCartPointA->Z() ) { | |
922 | // C=A | |
923 | di<<"vplane error: same points"<<"\n";return 1; | |
924 | } | |
925 | if (myCartPointC->X()==myCartPointB->X() && myCartPointC->Y()==myCartPointB->Y() && myCartPointC->Z()==myCartPointB->Z() ) { | |
926 | // C=B | |
927 | di<<"vplane error: same points"<<"\n";return 1; | |
928 | } | |
929 | ||
930 | gp_Pnt A= myCartPointA->Pnt(); | |
931 | gp_Pnt B= myCartPointB->Pnt(); | |
932 | gp_Pnt C= myCartPointC->Pnt(); | |
933 | ||
934 | // Construction de l'AIS_Plane | |
935 | GC_MakePlane MkPlane (A,B,C); | |
936 | Handle(Geom_Plane) myGeomPlane = MkPlane.Value(); | |
937 | Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane ); | |
938 | GetMapOfAIS().Bind (myAISPlane,name ); | |
939 | TheAISContext()->Display(myAISPlane); | |
940 | } | |
941 | ||
161c4476 | 942 | // si le premier argument est un AIS_Axis 2 |
7fd59977 | 943 | // creation d'un plan orthogonal a l'axe passant par un point |
944 | else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==2 ) { | |
945 | // le deuxieme argument doit etre un AIS_Point | |
946 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) | |
947 | { | |
948 | di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n"; | |
949 | return 1; | |
950 | } | |
951 | // on recupere la shape dans la map | |
952 | Handle(AIS_InteractiveObject) theShapeB = | |
953 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
954 | // si B n'est pas un AIS_Point | |
955 | if (theShapeB.IsNull() || | |
956 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
957 | { | |
958 | di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n"; | |
959 | return 1; | |
960 | } | |
961 | ||
161c4476 | 962 | // Traitement des objets A et B |
7fd59977 | 963 | Handle(AIS_Axis) theAISAxisA= *(Handle(AIS_Axis)*)& theShapeA; |
964 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
965 | ||
966 | Handle(Geom_Line ) myGeomLineA = theAISAxisA ->Component(); | |
967 | Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ; | |
968 | ||
969 | gp_Ax1 myAxis= myGeomLineA->Position(); | |
970 | Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB; | |
971 | ||
972 | // Pas de moyens de verifier que le point B n'est pas sur l'axe | |
973 | ||
974 | gp_Dir D=myAxis.Direction(); | |
975 | gp_Pnt B= myCartPointB->Pnt(); | |
976 | ||
977 | // Construction de l'AIS_Plane | |
978 | Handle(Geom_Plane) myGeomPlane= new Geom_Plane(B,D); | |
979 | Handle(AIS_Plane) myAISPlane = new AIS_Plane(myGeomPlane,B ); | |
980 | GetMapOfAIS().Bind (myAISPlane,name ); | |
981 | TheAISContext()->Display(myAISPlane); | |
982 | ||
983 | } | |
984 | // Si le premier argument est un AIS_Plane 7 | |
985 | // Creation d'un Plan parallele a ce plan passant par le point | |
986 | else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) { | |
987 | // le deuxieme argument doit etre un AISPoint | |
988 | if (argc!=4 || !GetMapOfAIS().IsBound2(argv[3] ) ) { | |
989 | di<<"vplane: error 2de name doesn't exist in the GetMapOfAIS()."<<"\n"; | |
990 | return 1; | |
991 | } | |
992 | // on recupere la shape dans la map | |
993 | Handle(AIS_InteractiveObject) theShapeB = | |
994 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
995 | // si B n'est pas un AIS_Point | |
996 | if (theShapeB.IsNull() || | |
997 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
998 | { | |
999 | di<<"vplane: error 2de object is expected to be an AIS_Point. "<<"\n"; | |
1000 | return 1; | |
1001 | } | |
1002 | ||
161c4476 | 1003 | // Traitement des objets A et B |
7fd59977 | 1004 | Handle(AIS_Plane) theAISPlaneA= *(Handle(AIS_Plane)*)& theShapeA; |
1005 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1006 | ||
1007 | Handle (Geom_Plane) theNewGeomPlane= theAISPlaneA->Component(); | |
1008 | Handle(Geom_Point) myGeomPointB= theAISPointB->Component() ; | |
1009 | ||
1010 | Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint )*)& myGeomPointB; | |
1011 | gp_Pnt B= myCartPointB->Pnt(); | |
1012 | ||
1013 | // Construction de l'AIS_Plane | |
1014 | Handle(AIS_Plane) myAISPlane = new AIS_Plane(theNewGeomPlane,B ); | |
1015 | GetMapOfAIS().Bind (myAISPlane,name ); | |
1016 | TheAISContext()->Display(myAISPlane); | |
1017 | ||
1018 | } | |
1019 | // Sinon erreur | |
1020 | else {di<<"vplane: error 1st object is not an AIS. "<<"\n";return 1;} | |
1021 | ||
1022 | } | |
1023 | ||
1024 | // Il n'y a pas d'arguments | |
1025 | else { | |
1026 | ||
1027 | // Fonction vplane | |
1028 | // Teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane, Standard_Boolean ) | |
1029 | if (!strcasecmp(argv[0] ,"vplane" ) ) { | |
1030 | TheAISContext()->OpenLocalContext(); | |
1031 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1032 | ||
1033 | // Active les modes Vertex, Edge et Face | |
1034 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1035 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1036 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1037 | di<<"Select a vertex, a face or an edge. "<<"\n"; | |
1038 | ||
1039 | // Boucle d'attente waitpick. | |
1040 | Standard_Integer argcc = 5; | |
1041 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1042 | const char **argvv = (const char **) buff; | |
1043 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1044 | // fin de la boucle | |
1045 | ||
1046 | TopoDS_Shape ShapeA; | |
1047 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1048 | ShapeA = TheAISContext()->SelectedShape(); | |
1049 | } | |
1050 | ||
1051 | // ShapeA est un Vertex | |
1052 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1053 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1054 | di<<" Select an edge or a different vertex."<<"\n"; | |
1055 | ||
1056 | // Boucle d'attente waitpick. | |
1057 | Standard_Integer argccc = 5; | |
1058 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1059 | const char **argvvv = (const char **) bufff; | |
1060 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1061 | // fin de la boucle | |
1062 | ||
1063 | TopoDS_Shape ShapeB; | |
1064 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1065 | ShapeB = TheAISContext()->SelectedShape(); | |
1066 | } | |
1067 | // ShapeB est un Vertex | |
1068 | if (ShapeB.ShapeType()==TopAbs_VERTEX ) { | |
1069 | // Si A et B sont le meme point | |
1070 | if (ShapeB.IsSame(ShapeA) ) {di<<" vplane: error, same points selected"<<"\n";return 1; } | |
1071 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1072 | di<<" Select a different vertex."<<"\n"; | |
1073 | ||
1074 | // Boucle d'attente waitpick. | |
1075 | Standard_Integer argcccc = 5; | |
1076 | const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1077 | const char **argvvvv = (const char **) buffff; | |
1078 | while (ViewerMainLoop( argcccc, argvvvv) ) { } | |
1079 | // fin de la boucle | |
1080 | ||
1081 | TopoDS_Shape ShapeC; | |
1082 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1083 | ShapeC = TheAISContext()->SelectedShape(); | |
1084 | } | |
1085 | // ShapeC est aussi un vertex... | |
1086 | if (ShapeC.IsSame(ShapeA)||ShapeC.IsSame(ShapeB) ) {di<<" vplane: error, same points selected"<<"\n";return 1; } | |
1087 | ||
161c4476 | 1088 | // Fermeture du contexte local |
7fd59977 | 1089 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
1090 | ||
161c4476 | 1091 | // Construction du plane |
7fd59977 | 1092 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); |
1093 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) ); | |
1094 | gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC ) ); | |
1095 | GC_MakePlane MkPlane(A,B,C); | |
1096 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
1097 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1098 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1099 | TheAISContext()->Display(myAISPlane); | |
1100 | ||
1101 | } | |
1102 | // ShapeB est un edge | |
1103 | else { | |
1104 | // il s'agit de verifier que le vertex ShapeA n'est pas sur l'edge ShapeB | |
1105 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); | |
1106 | TopoDS_Vertex VertA=TopoDS::Vertex(ShapeA); | |
1107 | ||
1108 | BRepExtrema_ExtPC OrthoProj (VertA, EdgeB ); | |
1109 | if (OrthoProj.SquareDistance(1)<1e-6 ) { | |
1110 | // Le vertex est sur l'edge | |
1111 | di<<" vplane: error point is on the edge."<<"\n";return 1; | |
1112 | } | |
1113 | else { | |
1114 | // le vertex n'appartient pes a l'edge on peut construire le plane | |
161c4476 | 1115 | // Fermeture du contexte local |
7fd59977 | 1116 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
161c4476 | 1117 | // Construction du plane |
7fd59977 | 1118 | gp_Pnt A=BRep_Tool::Pnt(VertA ); |
1119 | TopoDS_Vertex VBa,VBb; | |
1120 | TopExp::Vertices(EdgeB ,VBa ,VBb ); | |
1121 | gp_Pnt Ba=BRep_Tool::Pnt(VBa); | |
1122 | gp_Pnt Bb=BRep_Tool::Pnt(VBb); | |
1123 | GC_MakePlane MkPlane (A,Ba,Bb); | |
1124 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
1125 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1126 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1127 | TheAISContext()->Display(myAISPlane); | |
1128 | ||
1129 | } | |
1130 | ||
1131 | } | |
1132 | ||
1133 | } | |
1134 | // ShapeA est un edge | |
1135 | else if (ShapeA.ShapeType()==TopAbs_EDGE ) { | |
1136 | ||
1137 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1138 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1139 | di<<" Select a vertex that don't belong to the edge."<<"\n"; | |
1140 | ||
1141 | // Boucle d'attente waitpick. | |
1142 | Standard_Integer argccc = 5; | |
1143 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1144 | const char **argvvv = (const char **) bufff; | |
1145 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1146 | // fin de la boucle | |
1147 | ||
1148 | TopoDS_Shape ShapeB; | |
1149 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1150 | ShapeB = TheAISContext()->SelectedShape(); | |
1151 | } | |
1152 | // ShapeB est forcement un Vertex | |
1153 | // On verifie que le vertex ShapeB n'est pas sur l'edge ShapeA | |
1154 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); | |
1155 | TopoDS_Vertex VertB=TopoDS::Vertex(ShapeB); | |
1156 | ||
1157 | BRepExtrema_ExtPC OrthoProj (VertB,EdgeA ); | |
1158 | if (OrthoProj.SquareDistance(1)<1e-6) { | |
1159 | // Le vertex est sur l'edge | |
1160 | di<<" vplane: error point is on the edge."<<"\n";return 1; | |
1161 | } | |
1162 | else { | |
1163 | // le vertex n'appartient pas a l'edge on peut construire le plane | |
161c4476 | 1164 | // Fermeture du contexte local |
7fd59977 | 1165 | TheAISContext()->CloseLocalContext(myCurrentIndex); |
161c4476 | 1166 | // Construction du plane |
7fd59977 | 1167 | gp_Pnt B=BRep_Tool::Pnt(VertB ); |
1168 | TopoDS_Vertex VAa,VAb; | |
1169 | TopExp::Vertices(EdgeA ,VAa ,VAb ); | |
1170 | gp_Pnt Aa=BRep_Tool::Pnt(VAa); | |
1171 | gp_Pnt Ab=BRep_Tool::Pnt(VAb); | |
1172 | GC_MakePlane MkPlane (B,Aa,Ab); | |
1173 | Handle(Geom_Plane) theGeomPlane=MkPlane.Value(); | |
1174 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1175 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1176 | TheAISContext()->Display(myAISPlane); | |
1177 | ||
1178 | } | |
1179 | ||
1180 | ||
1181 | } | |
1182 | // ShapeA est une Face | |
1183 | else { | |
1184 | // Fermeture du contexte local: Plus rien a selectionner | |
1185 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
161c4476 | 1186 | // Construction du plane |
7fd59977 | 1187 | TopoDS_Face myFace=TopoDS::Face(ShapeA); |
1188 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1189 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1190 | gp_Pln myPlane=mySurface.Plane(); | |
1191 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1192 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ); | |
1193 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1194 | TheAISContext()->Display(myAISPlane); | |
1195 | ||
1196 | } | |
1197 | else { | |
1198 | di<<" vplane: error"<<"\n";return 1; | |
1199 | } | |
1200 | ||
1201 | } | |
1202 | ||
1203 | } | |
1204 | ||
1205 | // Fonction vPlanePara | |
1206 | // =================== | |
1207 | // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt ) | |
1208 | else if (!strcasecmp(argv[0] ,"vplanepara" )) { | |
1209 | ||
1210 | TheAISContext()->OpenLocalContext(); | |
1211 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1212 | ||
161c4476 | 1213 | // Active les modes Vertex et Face |
7fd59977 | 1214 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); |
1215 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1216 | di<<" Select a vertex or a face."<<"\n"; | |
1217 | ||
1218 | // Boucle d'attente waitpick. | |
1219 | Standard_Integer argcc = 5; | |
1220 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1221 | const char **argvv = (const char **) buff; | |
1222 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1223 | // fin de la boucle | |
1224 | ||
1225 | TopoDS_Shape ShapeA; | |
1226 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1227 | ShapeA = TheAISContext()->SelectedShape(); | |
1228 | } | |
1229 | ||
1230 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1231 | // ShapeA est un vertex | |
1232 | // On desactive le mode Vertex | |
1233 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1234 | di<<" Select a face."<<"\n"; | |
1235 | ||
1236 | // Boucle d'attente waitpick. | |
1237 | Standard_Integer argccc = 5; | |
1238 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1239 | const char **argvvv = (const char **) bufff; | |
1240 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1241 | // fin de la boucle | |
1242 | ||
1243 | TopoDS_Shape ShapeB; | |
1244 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1245 | // Le vertex ShapeA peut etre dans la Face ShapeB | |
1246 | ShapeB = TheAISContext()->SelectedShape(); | |
1247 | } | |
1248 | ||
1249 | // Fermeture du context local | |
1250 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1251 | ||
161c4476 | 1252 | // Construction du plane |
7fd59977 | 1253 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA ) ); |
1254 | ||
1255 | TopoDS_Face myFace=TopoDS::Face(ShapeB); | |
1256 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1257 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1258 | gp_Pln myPlane=mySurface.Plane(); | |
1259 | // construit un plan parallele a theGeomPlane passant par A | |
1260 | myPlane.SetLocation(A); | |
1261 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1262 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,A ); | |
1263 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1264 | TheAISContext()->Display(myAISPlane); | |
1265 | ||
1266 | } | |
1267 | else { | |
1268 | di<<" vplane: error"<<"\n";return 1; | |
1269 | } | |
1270 | ||
1271 | } | |
1272 | else{ | |
1273 | // ShapeA est une Face | |
1274 | // On desactive le mode Face | |
1275 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1276 | di<<" Select a vertex."<<"\n"; | |
1277 | ||
1278 | // Boucle d'attente waitpick. | |
1279 | Standard_Integer argccc = 5; | |
1280 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1281 | const char **argvvv = (const char **) bufff; | |
1282 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1283 | // fin de la boucle | |
1284 | ||
1285 | TopoDS_Shape ShapeB; | |
1286 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1287 | // Le vertex ShapeB peut etre dans la Face ShapeA | |
1288 | ShapeB = TheAISContext()->SelectedShape(); | |
1289 | } | |
1290 | // Fermeture du context local | |
1291 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1292 | ||
161c4476 | 1293 | // Construction du plane |
7fd59977 | 1294 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB ) ); |
1295 | ||
1296 | TopoDS_Face myFace=TopoDS::Face(ShapeA); | |
1297 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1298 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1299 | gp_Pln myPlane=mySurface.Plane(); | |
1300 | myPlane.SetLocation(B); | |
1301 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1302 | // construit un plan parallele a theGeomPlane passant par B | |
1303 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,B ); | |
1304 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1305 | TheAISContext()->Display(myAISPlane); | |
1306 | ||
1307 | } | |
1308 | else { | |
1309 | di<<" vplane: error"<<"\n";return 1; | |
1310 | } | |
1311 | ||
1312 | } | |
1313 | ||
1314 | } | |
1315 | ||
1316 | // Fonction vplaneortho | |
1317 | // ==================== | |
1318 | // teste le constructeur AIS_Plane::AIS_Plane(Geom_Plane,gp_Pnt,gp_Pnt,gp_Pnt) | |
1319 | else { | |
1320 | ||
1321 | TheAISContext()->OpenLocalContext(); | |
1322 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1323 | ||
161c4476 | 1324 | // Active les modes Edge et Face |
7fd59977 | 1325 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) ); |
1326 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1327 | di<<" Select a face and an edge coplanar."<<"\n"; | |
1328 | ||
1329 | // Boucle d'attente waitpick. | |
1330 | Standard_Integer argcc = 5; | |
1331 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1332 | const char **argvv = (const char **) buff; | |
1333 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1334 | // fin de la boucle | |
1335 | ||
1336 | TopoDS_Shape ShapeA; | |
1337 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1338 | ShapeA = TheAISContext()->SelectedShape(); | |
1339 | } | |
1340 | ||
1341 | if (ShapeA.ShapeType()==TopAbs_EDGE ) { | |
1342 | // ShapeA est un edge, on desactive le mode edge... | |
1343 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) ); | |
1344 | di<<" Select a face."<<"\n"; | |
1345 | ||
1346 | // Boucle d'attente waitpick. | |
1347 | Standard_Integer argccc = 5; | |
1348 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1349 | const char **argvvv = (const char **) bufff; | |
1350 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1351 | // fin de la boucle | |
1352 | ||
1353 | TopoDS_Shape ShapeB; | |
1354 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1355 | // L'edge ShapeA peut etre dans la Face ShapeB | |
1356 | ShapeB = TheAISContext()->SelectedShape(); | |
1357 | } | |
1358 | ||
1359 | // Fermeture du context local | |
1360 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1361 | ||
161c4476 | 1362 | // Construction du plane |
7fd59977 | 1363 | TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA); |
1364 | TopoDS_Vertex VAa,VAb; | |
1365 | // vi | |
1366 | TopExp::Vertices(EdgeA ,VAa ,VAb ); | |
1367 | gp_Pnt Aa=BRep_Tool::Pnt(VAa); | |
1368 | gp_Pnt Ab=BRep_Tool::Pnt(VAb); | |
1369 | gp_Vec ab (Aa,Ab); | |
1370 | ||
1371 | gp_Dir Dab (ab); | |
161c4476 K |
1372 | // Creation de mon axe de rotation |
1373 | gp_Ax1 myRotAxis (Aa,Dab); | |
7fd59977 | 1374 | |
1375 | TopoDS_Face myFace=TopoDS::Face(ShapeB); | |
1376 | // Il faut imperativement que l'edge soit parallele a la face | |
1377 | // vi | |
1378 | BRepExtrema_ExtPF myHauteurA (VAa , myFace ); | |
1379 | BRepExtrema_ExtPF myHauteurB (VAb , myFace ); | |
1380 | // on compare les deux hauteurs a la tolerance pres | |
1381 | if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt (myHauteurB.SquareDistance(1)) )>0.1 ) { | |
161c4476 | 1382 | // l'edge n'est pas parallele a la face |
7fd59977 | 1383 | di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1; |
1384 | } | |
1385 | // l'edge est OK | |
1386 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1387 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1388 | gp_Pln myPlane=mySurface.Plane(); | |
1389 | // On effectue une rotation d'1/2 tour autour de l'axe de rotation | |
1390 | myPlane.Rotate(myRotAxis , PI/2 ); | |
1391 | ||
1392 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1393 | // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA) | |
1394 | gp_Pnt theMiddle ((Aa.X()+Ab.X() )/2 ,(Aa.Y()+Ab.Y() )/2 ,(Aa.Z()+Ab.Z() )/2 ); | |
1395 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle ); | |
1396 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1397 | TheAISContext()->Display(myAISPlane); | |
1398 | ||
1399 | } | |
1400 | else { | |
1401 | di<<" vplaneOrtho: error"<<"\n";return 1; | |
1402 | } | |
1403 | ||
1404 | } | |
1405 | ||
1406 | else { | |
1407 | // ShapeA est une Face, on desactive le mode face. | |
1408 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1409 | di<<" Select an edge."<<"\n"; | |
1410 | ||
1411 | // Boucle d'attente waitpick. | |
1412 | Standard_Integer argccc = 5; | |
1413 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1414 | const char **argvvv = (const char **) bufff; | |
1415 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
1416 | // fin de la boucle | |
1417 | ||
1418 | TopoDS_Shape ShapeB; | |
1419 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1420 | // L'edge ShapeB peut etre dans la Face ShapeA | |
1421 | ShapeB = TheAISContext()->SelectedShape(); | |
1422 | } | |
1423 | ||
1424 | // Fermeture du context local | |
1425 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1426 | ||
161c4476 | 1427 | // Construction du plane |
7fd59977 | 1428 | TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB); |
1429 | TopoDS_Vertex VBa,VBb; | |
1430 | TopExp::Vertices(EdgeB ,VBa ,VBb ); | |
1431 | gp_Pnt Ba=BRep_Tool::Pnt(VBa); | |
1432 | gp_Pnt Bb=BRep_Tool::Pnt(VBb); | |
1433 | gp_Vec ab (Ba,Bb); | |
1434 | gp_Dir Dab (ab); | |
161c4476 K |
1435 | // Creation de mon axe de rotation |
1436 | gp_Ax1 myRotAxis (Ba,Dab); | |
7fd59977 | 1437 | |
1438 | TopoDS_Face myFace=TopoDS::Face(ShapeA); | |
1439 | // Il faut imperativement que l'edge soit parallele a la face | |
1440 | BRepExtrema_ExtPF myHauteurA (VBa , myFace ); | |
1441 | BRepExtrema_ExtPF myHauteurB (VBb , myFace ); | |
1442 | // on compare les deux hauteurs a la tolerance pres | |
1443 | if ( fabs(sqrt(myHauteurA.SquareDistance(1)) - sqrt(myHauteurB.SquareDistance(1)) )>0.1 ) { | |
161c4476 | 1444 | // l'edge n'est pas parallele a la face |
7fd59977 | 1445 | di<<" vplaneOrtho error: l'edge n'est pas parallele a la face."<<"\n";return 1; |
1446 | } | |
1447 | // l'edge est OK | |
1448 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1449 | if (mySurface.GetType()==GeomAbs_Plane ) { | |
1450 | gp_Pln myPlane=mySurface.Plane(); | |
1451 | // On effectue une rotation d'1/2 tour autour de l'axe de rotation | |
1452 | myPlane.Rotate(myRotAxis , PI/2 ); | |
1453 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1454 | // construit un plan parallele a theGeomPlane contenant l'edgeA (De centre le milieu de l'edgeA) | |
1455 | gp_Pnt theMiddle ((Ba.X()+Bb.X() )/2 , (Ba.Y()+Bb.Y() )/2 , (Ba.Z()+Bb.Z() )/2 ); | |
1456 | Handle(AIS_Plane) myAISPlane=new AIS_Plane (theGeomPlane ,theMiddle ); | |
1457 | GetMapOfAIS().Bind (myAISPlane ,name ); | |
1458 | TheAISContext()->Display(myAISPlane); | |
1459 | ||
1460 | } | |
1461 | else { | |
1462 | di<<" vplaneOrtho: error"<<"\n";return 1; | |
1463 | } | |
1464 | ||
1465 | } | |
1466 | ||
1467 | } | |
1468 | ||
1469 | } | |
1470 | return 0; | |
1471 | ||
1472 | } | |
1473 | ||
1474 | ||
1475 | //============================================================================== | |
1476 | // Fonction vline | |
1477 | // --------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1478 | //============================================================================== | |
1479 | ||
1480 | //============================================================================== | |
1481 | //function : VLineBuilder | |
161c4476 | 1482 | //purpose : Build an AIS_Line |
7fd59977 | 1483 | //Draw arg : vline LineName [AIS_PointName] [AIS_PointName] |
1484 | // [Xa] [Ya] [Za] [Xb] [Yb] [Zb] | |
1485 | //============================================================================== | |
1486 | #include <Geom_CartesianPoint.hxx> | |
1487 | #include <AIS_Line.hxx> | |
1488 | ||
1489 | ||
161c4476 | 1490 | static int VLineBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1491 | { |
1492 | Standard_Integer myCurrentIndex; | |
1493 | // Verifications | |
1494 | if (argc!=4 && argc!=8 && argc!=2 ) {di<<"vline error: number of arguments not correct "<<"\n";return 1; } | |
1495 | // Fermeture des contextes | |
1496 | TheAISContext()->CloseAllContexts(); | |
1497 | ||
1498 | // On recupere les parametres | |
1499 | Handle(AIS_InteractiveObject) theShapeA; | |
1500 | Handle(AIS_InteractiveObject) theShapeB; | |
1501 | ||
1502 | // Parametres: AIS_Point AIS_Point | |
1503 | // =============================== | |
1504 | if (argc==4) { | |
1505 | theShapeA= | |
1506 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2])); | |
1507 | // On verifie que c'est bien une AIS_Point | |
1508 | if (!theShapeA.IsNull() && | |
1509 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) { | |
1510 | // on recupere le deuxieme AIS_Point | |
1511 | theShapeB= | |
1512 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
1513 | if (theShapeA.IsNull() || | |
1514 | (!(theShapeB->Type()==AIS_KOI_Datum && theShapeB->Signature()==1))) | |
1515 | { | |
1516 | di <<"vline error: wrong type of 2de argument."<<"\n"; | |
1517 | return 1; | |
1518 | } | |
1519 | } | |
161c4476 | 1520 | else {di <<"vline error: wrong type of 1st argument."<<"\n";return 1; } |
7fd59977 | 1521 | // Les deux parametres sont du bon type. On verifie que les points ne sont pas confondus |
1522 | Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA; | |
1523 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1524 | ||
1525 | Handle(Geom_Point ) myGeomPointBA= theAISPointA->Component(); | |
1526 | Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointBA); | |
1527 | // Handle(Geom_CartesianPoint ) myCartPointA= *(Handle(Geom_CartesianPoint)*)& (theAISPointA->Component() ) ; | |
1528 | ||
1529 | Handle(Geom_Point ) myGeomPointB= theAISPointB->Component(); | |
1530 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& myGeomPointB); | |
1531 | // Handle(Geom_CartesianPoint ) myCartPointB= *(Handle(Geom_CartesianPoint)*)& (theAISPointB->Component() ) ; | |
1532 | ||
1533 | if (myCartPointB->X()==myCartPointA->X() && myCartPointB->Y()==myCartPointA->Y() && myCartPointB->Z()==myCartPointA->Z() ) { | |
1534 | // B=A | |
1535 | di<<"vline error: same points"<<"\n";return 1; | |
1536 | } | |
1537 | // Les deux points sont OK...Construction de l'AIS_Line (en faite, le segment AB) | |
1538 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1539 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1540 | TheAISContext()->Display(theAISLine ); | |
1541 | ||
1542 | } | |
1543 | ||
1544 | // Parametres 6 Reals | |
1545 | // ================== | |
1546 | ||
1547 | else if (argc==8) { | |
161c4476 | 1548 | // On verifie que les deux points ne sont pas confondus |
7fd59977 | 1549 | |
1550 | Standard_Real coord[6]; | |
1551 | for(Standard_Integer i=0;i<=2;i++){ | |
1552 | coord[i]=atof(argv[2+i]); | |
1553 | coord[i+3]=atof(argv[5+i]); | |
1554 | } | |
1555 | ||
1556 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint (coord[0],coord[1],coord[2] ); | |
1557 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint (coord[3],coord[4],coord[5] ); | |
1558 | ||
1559 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1560 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1561 | TheAISContext()->Display(theAISLine ); | |
1562 | ||
1563 | } | |
1564 | ||
1565 | // Pas de parametres: Selection dans le viewer. | |
1566 | // ============================================ | |
1567 | ||
1568 | else { | |
1569 | TheAISContext()->OpenLocalContext(); | |
1570 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1571 | ||
1572 | // Active le mode Vertex. | |
1573 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1574 | di<<" Select a vertex "<<"\n"; | |
1575 | ||
1576 | // Boucle d'attente waitpick. | |
1577 | Standard_Integer argcc = 5; | |
1578 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1579 | const char **argvv = (const char **) buff; | |
1580 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1581 | // fin de la boucle | |
1582 | ||
1583 | TopoDS_Shape ShapeA; | |
1584 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1585 | ShapeA = TheAISContext()->SelectedShape(); | |
1586 | } | |
1587 | ||
1588 | // ShapeA est un Vertex | |
1589 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1590 | ||
1591 | di<<" Select a different vertex."<<"\n"; | |
1592 | ||
1593 | TopoDS_Shape ShapeB; | |
1594 | do { | |
1595 | ||
1596 | // Boucle d'attente waitpick. | |
1597 | Standard_Integer argccc = 5; | |
1598 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1599 | const char **argvvv = (const char **) bufff; | |
1600 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 1601 | // fin de la boucle |
7fd59977 | 1602 | |
1603 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1604 | ShapeB = TheAISContext()->SelectedShape(); | |
1605 | } | |
1606 | ||
1607 | ||
1608 | } while(ShapeB.IsSame(ShapeA) ); | |
1609 | ||
1610 | // Fermeture du context local | |
1611 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1612 | ||
1613 | // Construction de la line | |
1614 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); | |
1615 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
1616 | ||
1617 | Handle(Geom_CartesianPoint ) myCartPointA=new Geom_CartesianPoint(A); | |
1618 | Handle(Geom_CartesianPoint ) myCartPointB=new Geom_CartesianPoint(B); | |
1619 | ||
1620 | Handle(AIS_Line) theAISLine= new AIS_Line(myCartPointA,myCartPointB ); | |
1621 | GetMapOfAIS().Bind(theAISLine,argv[1] ); | |
1622 | TheAISContext()->Display(theAISLine ); | |
1623 | ||
1624 | } | |
1625 | else { | |
1626 | di<<"vline error."<<"\n"; | |
1627 | } | |
1628 | ||
1629 | } | |
1630 | ||
1631 | return 0; | |
1632 | } | |
1633 | ||
1634 | ||
1635 | //============================================================================== | |
1636 | // Fonction vcircle | |
1637 | // ----------------- Uniquement par parametre. Pas de selection dans le viewer. | |
1638 | //============================================================================== | |
1639 | ||
1640 | //============================================================================== | |
1641 | //function : VCircleBuilder | |
161c4476 | 1642 | //purpose : Build an AIS_Circle |
7fd59977 | 1643 | //Draw arg : vcircle CircleName PlaneName PointName Radius |
1644 | // PointName PointName PointName | |
1645 | //============================================================================== | |
1646 | #include <Geom_CartesianPoint.hxx> | |
1647 | #include <Geom_Circle.hxx> | |
1648 | #include <AIS_Circle.hxx> | |
1649 | #include <GC_MakeCircle.hxx> | |
1650 | #include <Geom_Plane.hxx> | |
1651 | #include <gp_Pln.hxx> | |
1652 | ||
161c4476 | 1653 | static int VCircleBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
7fd59977 | 1654 | { |
1655 | Standard_Integer myCurrentIndex; | |
1656 | // verification of the arguments | |
1657 | if (argc>5 || argc<2 ) {di<<"vcircle error: expect 3 arguments."<<"\n";return 1; } | |
1658 | TheAISContext()->CloseAllContexts(); | |
1659 | ||
1660 | // Il y a des arguments | |
1661 | if (argc==5 ) { | |
1662 | Handle(AIS_InteractiveObject) theShapeA; | |
1663 | Handle(AIS_InteractiveObject) theShapeB; | |
1664 | ||
1665 | theShapeA= | |
1666 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[2])); | |
1667 | theShapeB= | |
1668 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[3])); | |
1669 | ||
1670 | // Arguments: AIS_Point AIS_Point AIS_Point | |
1671 | // ======================================== | |
1672 | if (!theShapeA.IsNull() && theShapeB.IsNull() && | |
1673 | theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==1) | |
1674 | { | |
1675 | if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) { | |
1676 | di<<"vcircle error: 2de argument is unexpected to be a point."<<"\n"; | |
161c4476 | 1677 | return 1; |
7fd59977 | 1678 | } |
1679 | // Le troisieme objet doit etre un point | |
1680 | Handle(AIS_InteractiveObject) theShapeC = | |
1681 | Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2(argv[4])); | |
1682 | if (theShapeC.IsNull() || | |
1683 | theShapeC->Type()!=AIS_KOI_Datum || theShapeC->Signature()!=1 ) { | |
1684 | di<<"vcircle error: 3de argument is unexpected to be a point."<<"\n"; | |
161c4476 | 1685 | return 1; |
7fd59977 | 1686 | } |
1687 | // tag | |
1688 | // On verifie que les 3 points sont differents. | |
1689 | Handle(AIS_Point) theAISPointA= *(Handle(AIS_Point)*)& theShapeA; | |
1690 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1691 | Handle(AIS_Point) theAISPointC= *(Handle(AIS_Point)*)& theShapeC; | |
1692 | ||
1693 | Handle(Geom_Point ) myGeomPointA= theAISPointA->Component(); | |
1694 | Handle(Geom_CartesianPoint ) myCartPointA= *((Handle(Geom_CartesianPoint)*)& myGeomPointA); | |
1695 | ||
1696 | Handle(Geom_Point ) myGeomPointB = theAISPointB->Component(); | |
1697 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB); | |
1698 | ||
1699 | Handle(Geom_Point ) myGeomPointBC= theAISPointC->Component(); | |
1700 | Handle(Geom_CartesianPoint ) myCartPointC= *((Handle(Geom_CartesianPoint)*)& theAISPointC); | |
1701 | ||
1702 | // Test A=B | |
1703 | if (myCartPointA->X()==myCartPointB->X() && myCartPointA->Y()==myCartPointB->Y() && myCartPointA->Z()==myCartPointB->Z() ) { | |
161c4476 | 1704 | di<<"vcircle error: Same points."<<"\n";return 1; |
7fd59977 | 1705 | } |
1706 | // Test A=C | |
1707 | if (myCartPointA->X()==myCartPointC->X() && myCartPointA->Y()==myCartPointC->Y() && myCartPointA->Z()==myCartPointC->Z() ) { | |
161c4476 | 1708 | di<<"vcircle error: Same points."<<"\n";return 1; |
7fd59977 | 1709 | } |
1710 | // Test B=C | |
1711 | if (myCartPointB->X()==myCartPointC->X() && myCartPointB->Y()==myCartPointC->Y() && myCartPointB->Z()==myCartPointC->Z() ) { | |
161c4476 | 1712 | di<<"vcircle error: Same points."<<"\n";return 1; |
7fd59977 | 1713 | } |
1714 | // Construction du cercle | |
1715 | GC_MakeCircle Cir=GC_MakeCircle (myCartPointA->Pnt(),myCartPointB->Pnt(),myCartPointC->Pnt() ); | |
1716 | Handle (Geom_Circle) theGeomCircle=Cir.Value(); | |
1717 | Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle ); | |
1718 | GetMapOfAIS().Bind(theAISCircle,argv[1] ); | |
1719 | TheAISContext()->Display(theAISCircle ); | |
1720 | ||
1721 | } | |
1722 | ||
1723 | // Arguments: ASI_Plane AIS_Point Real | |
1724 | // =================================== | |
1725 | else if (theShapeA->Type()==AIS_KOI_Datum && theShapeA->Signature()==7 ) { | |
1726 | if (theShapeB->Type()!=AIS_KOI_Datum || theShapeB->Signature()!=1 ) { | |
161c4476 | 1727 | di<<"vcircle error: 2de element is a unexpected to be a point."<<"\n";return 1; |
7fd59977 | 1728 | } |
1729 | // On verifie que le rayon est bien >=0 | |
1730 | if (atof(argv[4])<=0 ) {di<<"vcircle error: the radius must be >=0."<<"\n";return 1; } | |
1731 | ||
1732 | // On recupere la normale au Plane. | |
1733 | Handle(AIS_Plane) theAISPlane= *(Handle(AIS_Plane)*)& theShapeA; | |
1734 | Handle(AIS_Point) theAISPointB= *(Handle(AIS_Point)*)& theShapeB; | |
1735 | ||
1736 | ||
1737 | // Handle(Geom_Plane ) myGeomPlane= *(Handle(Geom_Plane)*)& (theAISPlane->Component() ); | |
1738 | Handle(Geom_Plane ) myGeomPlane= theAISPlane->Component(); | |
1739 | Handle(Geom_Point ) myGeomPointB = theAISPointB->Component(); | |
1740 | Handle(Geom_CartesianPoint ) myCartPointB= *((Handle(Geom_CartesianPoint)*)& theAISPointB); | |
1741 | ||
1742 | gp_Pln mygpPlane = myGeomPlane->Pln(); | |
1743 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
1744 | gp_Dir theDir = thegpAxe.Direction(); | |
1745 | gp_Pnt theCenter=myCartPointB->Pnt(); | |
1746 | Standard_Real TheR = atof(argv[4]); | |
1747 | GC_MakeCircle Cir=GC_MakeCircle (theCenter, theDir ,TheR); | |
1748 | Handle (Geom_Circle) theGeomCircle=Cir.Value(); | |
1749 | Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle ); | |
1750 | GetMapOfAIS().Bind(theAISCircle,argv[1] ); | |
1751 | TheAISContext()->Display(theAISCircle ); | |
1752 | ||
1753 | } | |
1754 | ||
1755 | // Error | |
1756 | else{ | |
1757 | di<<"vcircle error: !st argument is a unexpected type."<<"\n";return 1; | |
1758 | } | |
1759 | ||
1760 | } | |
1761 | // Pas d'arguments: selection dans le viewer | |
1762 | // ========================================= | |
1763 | else { | |
1764 | ||
1765 | TheAISContext()->OpenLocalContext(); | |
1766 | myCurrentIndex=TheAISContext()->IndexOfCurrentLocal(); | |
1767 | ||
1768 | // Active le mode Vertex et face. | |
1769 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) ); | |
1770 | TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1771 | di<<" Select a vertex or a face."<<"\n"; | |
1772 | ||
1773 | // Boucle d'attente waitpick. | |
1774 | Standard_Integer argcc = 5; | |
1775 | const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1776 | const char **argvv = (const char **) buff; | |
1777 | while (ViewerMainLoop( argcc, argvv) ) { } | |
1778 | // fin de la boucle | |
1779 | ||
1780 | TopoDS_Shape ShapeA; | |
1781 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1782 | ShapeA = TheAISContext()->SelectedShape(); | |
1783 | } | |
1784 | ||
1785 | // ShapeA est un Vertex | |
1786 | if (ShapeA.ShapeType()==TopAbs_VERTEX ) { | |
1787 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1788 | di<<" Select a different vertex."<<"\n"; | |
1789 | ||
1790 | TopoDS_Shape ShapeB; | |
1791 | do { | |
1792 | ||
1793 | // Boucle d'attente waitpick. | |
1794 | Standard_Integer argccc = 5; | |
1795 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1796 | const char **argvvv = (const char **) bufff; | |
1797 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 1798 | // fin de la boucle |
7fd59977 | 1799 | |
1800 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1801 | ShapeB = TheAISContext()->SelectedShape(); | |
1802 | } | |
1803 | ||
1804 | ||
1805 | } while(ShapeB.IsSame(ShapeA) ); | |
1806 | ||
1807 | // Selection de ShapeC | |
1808 | di<<" Select the last vertex."<<"\n"; | |
1809 | TopoDS_Shape ShapeC; | |
1810 | do { | |
1811 | ||
1812 | // Boucle d'attente waitpick. | |
1813 | Standard_Integer argcccc = 5; | |
1814 | const char *buffff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1815 | const char **argvvvv = (const char **) buffff; | |
1816 | while (ViewerMainLoop( argcccc, argvvvv) ) { } | |
161c4476 | 1817 | // fin de la boucle |
7fd59977 | 1818 | |
1819 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1820 | ShapeC = TheAISContext()->SelectedShape(); | |
1821 | } | |
1822 | ||
1823 | ||
1824 | } while(ShapeC.IsSame(ShapeA) || ShapeC.IsSame(ShapeB) ); | |
1825 | ||
1826 | // Fermeture du context local | |
1827 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1828 | ||
161c4476 | 1829 | // Construction du cercle |
7fd59977 | 1830 | gp_Pnt A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) ); |
1831 | gp_Pnt B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
1832 | gp_Pnt C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeC) ); | |
1833 | ||
1834 | GC_MakeCircle Cir=GC_MakeCircle (A,B,C ); | |
1835 | Handle (Geom_Circle) theGeomCircle=Cir.Value(); | |
1836 | Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle ); | |
1837 | GetMapOfAIS().Bind(theAISCircle,argv[1] ); | |
1838 | TheAISContext()->Display(theAISCircle ); | |
1839 | ||
1840 | } | |
1841 | // ShapeA est une face. | |
1842 | else { | |
1843 | di<<" Select a vertex (in your face)."<<"\n"; | |
1844 | TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) ); | |
1845 | ||
1846 | TopoDS_Shape ShapeB; | |
1847 | // Boucle d'attente waitpick. | |
1848 | Standard_Integer argccc = 5; | |
1849 | const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" }; | |
1850 | const char **argvvv = (const char **) bufff; | |
1851 | while (ViewerMainLoop( argccc, argvvv) ) { } | |
161c4476 | 1852 | // fin de la boucle |
7fd59977 | 1853 | |
1854 | for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) { | |
1855 | ShapeB = TheAISContext()->SelectedShape(); | |
1856 | } | |
1857 | ||
1858 | // Recuperation du rayon. | |
1859 | Standard_Integer theRad; | |
1860 | do { | |
1861 | di<<" Enter the value of the radius:"<<"\n"; | |
1862 | cin>>theRad; | |
1863 | } while (theRad<=0); | |
1864 | ||
1865 | // Fermeture du context local | |
1866 | TheAISContext()->CloseLocalContext(myCurrentIndex); | |
1867 | // Construction du cercle. | |
1868 | ||
1869 | // On recupere la normale au Plane. tag | |
1870 | TopoDS_Face myFace=TopoDS::Face(ShapeA); | |
1871 | BRepAdaptor_Surface mySurface (myFace, Standard_False ); | |
1872 | gp_Pln myPlane=mySurface.Plane(); | |
1873 | Handle(Geom_Plane) theGeomPlane=new Geom_Plane (myPlane ); | |
1874 | gp_Pln mygpPlane = theGeomPlane->Pln(); | |
1875 | gp_Ax1 thegpAxe = mygpPlane.Axis(); | |
1876 | gp_Dir theDir = thegpAxe.Direction(); | |
1877 | ||
1878 | // On recupere le centre. | |
1879 | gp_Pnt theCenter=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) ); | |
1880 | ||
1881 | // On construit l'AIS_Circle | |
1882 | GC_MakeCircle Cir=GC_MakeCircle (theCenter, theDir ,theRad ); | |
1883 | Handle (Geom_Circle) theGeomCircle=Cir.Value(); | |
1884 | Handle(AIS_Circle) theAISCircle=new AIS_Circle(theGeomCircle ); | |
1885 | GetMapOfAIS().Bind(theAISCircle,argv[1] ); | |
1886 | TheAISContext()->Display(theAISCircle ); | |
1887 | ||
1888 | } | |
1889 | ||
1890 | ||
1891 | } | |
1892 | ||
1893 | return 0; | |
1894 | } | |
1895 | ||
1896 | ||
1897 | //=============================================================================================== | |
1898 | //function : VDrawText | |
1899 | //author : psn | |
1900 | //purpose : Create a text. | |
1901 | //Draw arg : vdrawtext name [X] [Y] [Z] [R] [G] [B] [hor_align] [ver_align] [angle] [zoomable] | |
1902 | //=============================================================================================== | |
1903 | #include <Graphic3d_Group.hxx> | |
1904 | #include <Graphic3d_Structure.hxx> | |
1905 | #include <Graphic3d_NameOfFont.hxx> | |
1906 | #include <Graphic3d_AspectText3d.hxx> | |
1907 | #include <Graphic2d_GraphicObject.hxx> | |
1908 | #include <Graphic3d_Array1OfVertex.hxx> | |
161c4476 | 1909 | #include <Graphic3d_AspectFillArea3d.hxx> |
7fd59977 | 1910 | #include <Graphic3d_StructureManager.hxx> |
1911 | #include <Graphic3d_VerticalTextAlignment.hxx> | |
1912 | #include <Graphic3d_HorizontalTextAlignment.hxx> | |
1913 | ||
1914 | #include <Visual3d_ViewManager.hxx> | |
1915 | #include <ViewerTest_Tool.ixx> | |
1916 | ||
1917 | #include <Standard_DefineHandle.hxx> | |
1918 | ||
1919 | #include <AIS_Drawer.hxx> | |
1920 | ||
1921 | #include <Prs3d_Root.hxx> | |
1922 | #include <Prs3d_Text.hxx> | |
1923 | #include <Prs3d_TextAspect.hxx> | |
1924 | #include <Prs3d_Presentation.hxx> | |
1925 | #include <Prs3d_ShadingAspect.hxx> | |
1926 | #include <PrsMgr_PresentationManager3d.hxx> | |
1927 | ||
1928 | #include <TCollection_ExtendedString.hxx> | |
1929 | #include <TCollection_AsciiString.hxx> | |
1930 | ||
1931 | #include <gp_Pnt.hxx> | |
1932 | #include <Quantity_NameOfColor.hxx> | |
161c4476 | 1933 | #include <Quantity_Color.hxx> |
7fd59977 | 1934 | |
1935 | ||
1936 | DEFINE_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject) | |
1937 | ||
1938 | class MyTextClass:public AIS_InteractiveObject{ | |
1939 | ||
1940 | public: | |
1941 | // CASCADE RTTI | |
1942 | DEFINE_STANDARD_RTTI(MyTextClass ); | |
1943 | ||
1944 | MyTextClass(){}; | |
1945 | ||
161c4476 | 1946 | MyTextClass |
7fd59977 | 1947 | ( |
1948 | const TCollection_ExtendedString& , const gp_Pnt& , | |
161c4476 K |
1949 | Quantity_Color color, |
1950 | Standard_Integer aHJust, | |
7fd59977 | 1951 | Standard_Integer aVJust , |
161c4476 K |
1952 | Standard_Real Angle , |
1953 | Standard_Boolean Zoom , | |
1954 | Standard_Real Height, | |
7fd59977 | 1955 | OSD_FontAspect FontAspect, |
1956 | Standard_CString Font | |
1957 | ); | |
1958 | ||
1959 | private: | |
1960 | ||
1961 | void Compute ( const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
1962 | const Handle(Prs3d_Presentation)& aPresentation, | |
1963 | const Standard_Integer aMode); | |
1964 | ||
1965 | void ComputeSelection ( const Handle(SelectMgr_Selection)& aSelection, | |
161c4476 | 1966 | const Standard_Integer aMode){} ; |
7fd59977 | 1967 | |
1968 | protected: | |
1969 | TCollection_ExtendedString aText; | |
1970 | gp_Pnt aPosition; | |
1971 | Standard_Real Red; | |
1972 | Standard_Real Green; | |
1973 | Standard_Real Blue; | |
1974 | Standard_Real aAngle; | |
161c4476 | 1975 | Standard_Real aHeight; |
7fd59977 | 1976 | Standard_Boolean aZoomable; |
1977 | Quantity_Color aColor; | |
161c4476 | 1978 | Standard_CString aFont; |
7fd59977 | 1979 | OSD_FontAspect aFontAspect; |
1980 | Graphic3d_HorizontalTextAlignment aHJustification; | |
1981 | Graphic3d_VerticalTextAlignment aVJustification; | |
1982 | }; | |
1983 | ||
1984 | ||
1985 | ||
1986 | IMPLEMENT_STANDARD_HANDLE(MyTextClass, AIS_InteractiveObject) | |
161c4476 | 1987 | IMPLEMENT_STANDARD_RTTIEXT(MyTextClass, AIS_InteractiveObject) |
7fd59977 | 1988 | |
1989 | ||
1990 | ||
161c4476 K |
1991 | MyTextClass::MyTextClass( const TCollection_ExtendedString& text, const gp_Pnt& position, |
1992 | Quantity_Color color = Quantity_NOC_YELLOW, | |
1993 | Standard_Integer aHJust = Graphic3d_HTA_LEFT, | |
7fd59977 | 1994 | Standard_Integer aVJust = Graphic3d_VTA_BOTTOM, |
1995 | Standard_Real angle = 0.0 , | |
1996 | Standard_Boolean zoomable = Standard_True, | |
1997 | Standard_Real height = 12., | |
1998 | OSD_FontAspect fontAspect = OSD_FA_Regular, | |
1999 | Standard_CString font = "Courier") | |
2000 | { | |
2001 | aText = text; | |
161c4476 | 2002 | aPosition = position; |
7fd59977 | 2003 | aHJustification = Graphic3d_HorizontalTextAlignment(aHJust); |
2004 | aVJustification = Graphic3d_VerticalTextAlignment(aVJust); | |
2005 | aAngle = angle; | |
161c4476 K |
2006 | aZoomable = zoomable; |
2007 | aHeight = height; | |
7fd59977 | 2008 | aColor = color; |
2009 | aFontAspect = fontAspect; | |
2010 | aFont = font; | |
2011 | }; | |
2012 | ||
2013 | ||
2014 | ||
2015 | ////////////////////////////////////////////////////////////////////////////// | |
2016 | void MyTextClass::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager, | |
2017 | const Handle(Prs3d_Presentation)& aPresentation, | |
2018 | const Standard_Integer aMode) | |
2019 | { | |
2020 | ||
2021 | aPresentation->Clear(); | |
2022 | ||
2023 | Handle_Prs3d_TextAspect asp = myDrawer->TextAspect(); | |
2024 | ||
2025 | asp->SetFont(aFont); | |
2026 | asp->SetColor(aColor); | |
2027 | asp->SetHeight(aHeight); // I am changing the myHeight value | |
2028 | ||
2029 | asp->SetHorizontalJustification(aHJustification); | |
161c4476 | 2030 | asp->SetVerticalJustification(aVJustification); |
7fd59977 | 2031 | asp->Aspect()->SetTextZoomable(aZoomable); |
2032 | asp->Aspect()->SetTextAngle(aAngle); | |
2033 | asp->Aspect()->SetTextFontAspect(aFontAspect); | |
2034 | Prs3d_Text::Draw(aPresentation, asp, aText, aPosition); | |
161c4476 | 2035 | |
7fd59977 | 2036 | /* This comment code is worked |
2037 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation); | |
2038 | Handle(Graphic3d_AspectFillArea3d) aspect = myDrawer->ShadingAspect()->Aspect(); | |
2039 | Graphic3d_Vertex vertices_text; | |
2040 | vertices_text.SetCoord(aPosition.X(),aPosition.Y(),aPosition.Y()); | |
2041 | TheGroup->SetPrimitivesAspect(aspect); | |
2042 | TheGroup->BeginPrimitives(); | |
2043 | TheGroup->Text(aText,vertices_text,aHeight,Standard_True); | |
2044 | TheGroup->EndPrimitives(); | |
2045 | */ | |
2046 | }; | |
2047 | ||
2048 | static int VDrawText (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
2049 | { | |
2050 | // Verification des arguments | |
2051 | if ( argc > 17 ) {di<<argv[0]<<" Syntaxe error"<<"\n"; return 1;} | |
2052 | Quantity_Parameter R, G, B; | |
2053 | Quantity_Color aColor; | |
2054 | Standard_Real angle; | |
2055 | Standard_Real height; | |
2056 | Standard_Boolean zoom; | |
2057 | OSD_FontAspect aspect; | |
2058 | TCollection_AsciiString font; | |
2059 | gp_Pnt pnt; | |
2060 | int hor_align; | |
2061 | int ver_align; | |
2062 | TCollection_AsciiString aFont; | |
2063 | TCollection_AsciiString name = argv[1]; | |
2064 | ||
2065 | //Declarations et creation des objets par default | |
2066 | Standard_Real X,Y,Z; | |
2067 | X = atof(argv[2]); | |
2068 | Y = atof(argv[3]); | |
2069 | Z = atof(argv[4]); | |
2070 | pnt.SetCoord(X,Y,Z); | |
2071 | ||
2072 | R = atof(argv[5])/255.; | |
2073 | G = atof(argv[6])/255.; | |
2074 | B = atof(argv[7])/255.; | |
2075 | ||
161c4476 | 2076 | hor_align = atoi(argv[8]); |
7fd59977 | 2077 | ver_align = atoi(argv[9]); |
2078 | ||
2079 | angle = atof(argv[10]); | |
2080 | ||
2081 | zoom = atoi(argv[11]); | |
2082 | ||
2083 | height = atof(argv[12]); | |
2084 | ||
2085 | aspect = OSD_FontAspect(atoi(argv[13])); | |
2086 | ||
2087 | if(argc == 14) | |
2088 | font.AssignCat("Courier"); | |
2089 | if(argc == 15) | |
2090 | font.AssignCat(argv[14]); | |
2091 | if(argc == 16) | |
2092 | { | |
2093 | font.AssignCat(argv[14]); | |
161c4476 K |
2094 | font.AssignCat(" "); |
2095 | font.AssignCat(argv[15]); | |
7fd59977 | 2096 | } |
161c4476 K |
2097 | if(argc == 17) |
2098 | { | |
7fd59977 | 2099 | font.AssignCat(argv[14]); |
161c4476 | 2100 | font.AssignCat(" "); |
7fd59977 | 2101 | font.AssignCat(argv[15]); |
161c4476 K |
2102 | font.AssignCat(" "); |
2103 | font.AssignCat(argv[16]); | |
7fd59977 | 2104 | } |
2105 | ||
2106 | aColor.SetValues( R, G, B, Quantity_TOC_RGB ); | |
2107 | ||
2108 | Handle(AIS_InteractiveContext) aContext= ViewerTest::GetAISContext(); | |
2109 | ||
2110 | Handle(MyTextClass) my=new MyTextClass(argv[1],pnt,aColor,hor_align,ver_align,angle,zoom,height,aspect,font.ToCString()); | |
2111 | ||
2112 | aContext->Display(my,Standard_True); | |
2113 | ||
161c4476 K |
2114 | if(aContext.IsNull()) |
2115 | { | |
7fd59977 | 2116 | di << "use 'vinit' command before " << argv[0] << "\n"; |
2117 | return -1; | |
2118 | } | |
161c4476 | 2119 | return 0; |
7fd59977 | 2120 | } |
2121 | ||
2122 | #include <math.h> | |
2123 | #include <gp_Pnt.hxx> | |
2124 | #include <Graphic3d_ArrayOfPoints.hxx> | |
2125 | #include <Graphic3d_ArrayOfPrimitives.hxx> | |
2126 | #include <Graphic3d_Array1OfVertex.hxx> | |
2127 | #include <Graphic3d_ArrayOfTriangles.hxx> | |
2128 | #include <Poly_Array1OfTriangle.hxx> | |
2129 | #include <Poly_Triangle.hxx> | |
2130 | #include <Poly_Triangulation.hxx> | |
2131 | #include <TColgp_Array1OfPnt.hxx> | |
2132 | #include <TShort_Array1OfShortReal.hxx> | |
2133 | #include <TShort_HArray1OfShortReal.hxx> | |
2134 | ||
2135 | #include <AIS_Triangulation.hxx> | |
2136 | #include <Aspect_GraphicDevice.hxx> | |
2137 | #include <StdPrs_ToolShadedShape.hxx> | |
2138 | #include <Poly_Connect.hxx> | |
2139 | #include <TColgp_Array1OfDir.hxx> | |
2140 | #include <Graphic3d_GraphicDriver.hxx> | |
2141 | ||
2142 | #include <AIS_Drawer.hxx> | |
2143 | #include <TColStd_Array1OfInteger.hxx> | |
2144 | #include <TColStd_HArray1OfInteger.hxx> | |
2145 | #include <Prs3d_ShadingAspect.hxx> | |
2146 | #include <Graphic3d_MaterialAspect.hxx> | |
2147 | #include <Graphic3d_AspectFillArea3d.hxx> | |
2148 | ||
2149 | #include <BRepPrimAPI_MakeCylinder.hxx> | |
2150 | #include <TopoDS_Shape.hxx> | |
2151 | #include <TopExp_Explorer.hxx> | |
2152 | #include <TopAbs.hxx> | |
2153 | #include <StdSelect_ShapeTypeFilter.hxx> | |
2154 | ||
2155 | ||
2156 | //=============================================================================================== | |
2157 | //function : CalculationOfSphere | |
2158 | //author : psn | |
2159 | //purpose : Create a Sphere | |
2160 | //=============================================================================================== | |
2161 | ||
161c4476 | 2162 | Handle( Poly_Triangulation ) CalculationOfSphere( double X , double Y , double Z , |
7fd59977 | 2163 | int res , |
2164 | double Radius ){ | |
2165 | double mRadius = Radius; | |
2166 | double mCenter[3] = {X,Y,Z}; | |
2167 | int mThetaResolution; | |
2168 | int mPhiResolution; | |
2169 | double mStartTheta = 0;//StartTheta; | |
2170 | double mEndTheta = 360;//EndTheta; | |
2171 | double mStartPhi = 0;//StartPhi; | |
2172 | double mEndPhi = 180;//EndPhi; | |
2173 | res = res < 4 ? 4 : res; | |
2174 | ||
2175 | mThetaResolution = res; | |
2176 | mPhiResolution = res; | |
2177 | ||
2178 | int i, j; | |
2179 | int jStart, jEnd, numOffset; | |
2180 | int numPts, numPolys; | |
2181 | double x[3], n[3], deltaPhi, deltaTheta, phi, theta, radius; | |
2182 | double startTheta, endTheta, startPhi, endPhi; | |
2183 | int base, numPoles=0, thetaResolution, phiResolution; | |
2184 | ||
2185 | int pts[3]; | |
2186 | int piece = -1; | |
2187 | int numPieces = 1; | |
2188 | if ( numPieces > mThetaResolution ) { | |
2189 | numPieces = mThetaResolution; | |
2190 | } | |
2191 | ||
2192 | int localThetaResolution = mThetaResolution; | |
2193 | double localStartTheta = mStartTheta; | |
2194 | double localEndTheta = mEndTheta; | |
2195 | ||
2196 | while ( localEndTheta < localStartTheta ) { | |
2197 | localEndTheta += 360.0; | |
2198 | } | |
2199 | ||
2200 | deltaTheta = (localEndTheta - localStartTheta) / localThetaResolution; | |
2201 | ||
2202 | // Change the ivars based on pieces. | |
2203 | int start, end; | |
2204 | start = piece * localThetaResolution / numPieces; | |
2205 | end = (piece+1) * localThetaResolution / numPieces; | |
2206 | localEndTheta = localStartTheta + (double)(end) * deltaTheta; | |
2207 | localStartTheta = localStartTheta + (double)(start) * deltaTheta; | |
2208 | localThetaResolution = end - start; | |
2209 | ||
2210 | numPts = mPhiResolution * localThetaResolution + 2; | |
2211 | numPolys = mPhiResolution * 2 * localThetaResolution; | |
2212 | ||
2213 | // Create north pole if needed | |
2214 | int number_point = 0; | |
2215 | int number_pointArray = 0; | |
2216 | ||
2217 | if ( mStartPhi <= 0.0 ) { | |
2218 | number_pointArray++; | |
2219 | numPoles++; | |
2220 | } | |
2221 | if ( mEndPhi >= 180.0 ) { | |
2222 | number_pointArray++; | |
2223 | numPoles++; | |
2224 | } | |
161c4476 | 2225 | |
7fd59977 | 2226 | // Check data, determine increments, and convert to radians |
2227 | startTheta = (localStartTheta < localEndTheta ? localStartTheta : localEndTheta); | |
2228 | startTheta *= Standard_PI / 180.0; | |
2229 | endTheta = (localEndTheta > localStartTheta ? localEndTheta : localStartTheta); | |
2230 | endTheta *= Standard_PI / 180.0; | |
2231 | ||
2232 | ||
2233 | startPhi = ( mStartPhi < mEndPhi ? mStartPhi : mEndPhi); | |
2234 | startPhi *= Standard_PI / 180.0; | |
2235 | endPhi = ( mEndPhi > mStartPhi ? mEndPhi : mStartPhi); | |
2236 | endPhi *= Standard_PI / 180.0; | |
2237 | ||
2238 | phiResolution = mPhiResolution - numPoles; | |
2239 | deltaPhi = (endPhi - startPhi) / ( mPhiResolution - 1); | |
2240 | thetaResolution = localThetaResolution; | |
2241 | if ( fabs(localStartTheta - localEndTheta) < 360.0 ) { | |
2242 | ++localThetaResolution; | |
2243 | } | |
2244 | deltaTheta = (endTheta - startTheta) / thetaResolution; | |
2245 | ||
2246 | jStart = ( mStartPhi <= 0.0 ? 1 : 0); | |
2247 | jEnd = ( mEndPhi >= 180.0 ? mPhiResolution - 1 : mPhiResolution); | |
2248 | ||
2249 | // Create intermediate points | |
2250 | for ( i = 0; i < localThetaResolution; i++ ) { | |
2251 | for ( j = jStart; j < jEnd; j++ ) { | |
2252 | number_pointArray++; | |
2253 | } | |
2254 | } | |
2255 | ||
2256 | //Generate mesh connectivity | |
2257 | base = phiResolution * localThetaResolution; | |
2258 | ||
2259 | int number_triangle = 0 ; | |
2260 | if ( mStartPhi <= 0.0 ) { // around north pole | |
2261 | number_triangle += localThetaResolution; | |
2262 | } | |
161c4476 | 2263 | |
7fd59977 | 2264 | if ( mEndPhi >= 180.0 ) { // around south pole |
2265 | number_triangle += localThetaResolution; | |
2266 | } | |
2267 | ||
2268 | // bands in-between poles | |
2269 | for ( i=0; i < localThetaResolution; i++){ | |
2270 | for ( j=0; j < (phiResolution-1); j++){ | |
2271 | number_triangle +=2; | |
2272 | } | |
2273 | } | |
2274 | ||
2275 | Handle( Poly_Triangulation ) polyTriangulation = new Poly_Triangulation(number_pointArray, number_triangle, false); | |
2276 | TColgp_Array1OfPnt& PointsOfArray = polyTriangulation->ChangeNodes(); | |
2277 | Poly_Array1OfTriangle& pArrayTriangle = polyTriangulation->ChangeTriangles(); | |
2278 | ||
2279 | if ( mStartPhi <= 0.0 ){ | |
2280 | x[0] = mCenter[0]; | |
2281 | x[1] = mCenter[1]; | |
2282 | x[2] = mCenter[2] + mRadius; | |
2283 | PointsOfArray.SetValue(1,gp_Pnt(x[0],x[1],x[2])); | |
2284 | } | |
2285 | ||
2286 | // Create south pole if needed | |
2287 | if ( mEndPhi >= 180.0 ){ | |
2288 | x[0] = mCenter[0]; | |
2289 | x[1] = mCenter[1]; | |
2290 | x[2] = mCenter[2] - mRadius; | |
2291 | PointsOfArray.SetValue(2,gp_Pnt(x[0],x[1],x[2])); | |
2292 | } | |
2293 | ||
2294 | number_point = 3; | |
2295 | for ( i=0; i < localThetaResolution; i++){ | |
2296 | theta = localStartTheta * Standard_PI / 180.0 + i*deltaTheta; | |
2297 | for ( j = jStart; j < jEnd; j++){ | |
2298 | phi = startPhi + j*deltaPhi; | |
2299 | radius = mRadius * sin((double)phi); | |
2300 | n[0] = radius * cos((double)theta); | |
2301 | n[1] = radius * sin((double)theta); | |
2302 | n[2] = mRadius * cos((double)phi); | |
2303 | x[0] = n[0] + mCenter[0]; | |
2304 | x[1] = n[1] + mCenter[1]; | |
2305 | x[2] = n[2] + mCenter[2]; | |
2306 | PointsOfArray.SetValue(number_point,gp_Pnt(x[0],x[1],x[2])); | |
2307 | number_point++; | |
2308 | } | |
2309 | } | |
2310 | ||
2311 | numPoles = 3; | |
2312 | number_triangle = 1; | |
2313 | if ( mStartPhi <= 0.0 ){// around north pole | |
2314 | for (i=0; i < localThetaResolution; i++){ | |
2315 | pts[0] = phiResolution*i + numPoles; | |
2316 | pts[1] = (phiResolution*(i+1) % base) + numPoles; | |
2317 | pts[2] = 1; | |
2318 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2319 | number_triangle++; | |
2320 | } | |
2321 | } | |
161c4476 | 2322 | |
7fd59977 | 2323 | if ( mEndPhi >= 180.0 ){ // around south pole |
2324 | numOffset = phiResolution - 1 + numPoles; | |
2325 | for (i=0; i < localThetaResolution; i++){ | |
2326 | pts[0] = phiResolution*i + numOffset; | |
2327 | pts[2] = ((phiResolution*(i+1)) % base) + numOffset; | |
2328 | pts[1] = numPoles - 1; | |
2329 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2330 | number_triangle++; | |
2331 | } | |
2332 | } | |
2333 | ||
2334 | // bands in-between poles | |
161c4476 | 2335 | |
7fd59977 | 2336 | for (i=0; i < localThetaResolution; i++){ |
2337 | for (j=0; j < (phiResolution-1); j++){ | |
2338 | pts[0] = phiResolution*i + j + numPoles; | |
2339 | pts[1] = pts[0] + 1; | |
2340 | pts[2] = ((phiResolution*(i+1)+j) % base) + numPoles + 1; | |
2341 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2342 | number_triangle++; | |
2343 | pts[1] = pts[2]; | |
2344 | pts[2] = pts[1] - 1; | |
2345 | pArrayTriangle.SetValue(number_triangle,Poly_Triangle(pts[0],pts[1],pts[2])); | |
2346 | number_triangle++; | |
2347 | } | |
2348 | } | |
2349 | ||
2350 | Poly_Connect* pc = new Poly_Connect(polyTriangulation); | |
2351 | ||
2352 | Handle(TShort_HArray1OfShortReal) Normals = new TShort_HArray1OfShortReal(1, polyTriangulation->NbNodes() * 3); | |
2353 | ||
2354 | Standard_Integer index[3]; | |
2355 | Standard_Real Tol = Precision::Confusion(); | |
2356 | ||
2357 | gp_Dir Nor; | |
2358 | for (i = PointsOfArray.Lower(); i <= PointsOfArray.Upper(); i++) { | |
2359 | gp_XYZ eqPlan(0, 0, 0); | |
2360 | for ( pc->Initialize(i); pc->More(); pc->Next()) { | |
2361 | pArrayTriangle(pc->Value()).Get(index[0], index[1], index[2]); | |
2362 | gp_XYZ v1(PointsOfArray(index[1]).Coord()-PointsOfArray(index[0]).Coord()); | |
2363 | gp_XYZ v2(PointsOfArray(index[2]).Coord()-PointsOfArray(index[1]).Coord()); | |
2364 | gp_XYZ vv = v1^v2; | |
2365 | Standard_Real mod = vv.Modulus(); | |
2366 | if(mod < Tol) continue; | |
2367 | eqPlan += vv/mod; | |
2368 | } | |
2369 | ||
2370 | Standard_Real modmax = eqPlan.Modulus(); | |
2371 | ||
161c4476 | 2372 | if(modmax > Tol) |
7fd59977 | 2373 | Nor = gp_Dir(eqPlan); |
161c4476 | 2374 | else |
7fd59977 | 2375 | Nor = gp_Dir(0., 0., 1.); |
2376 | ||
2377 | Standard_Integer j = (i - PointsOfArray.Lower()) * 3; | |
2378 | Normals->SetValue(j + 1, (Standard_ShortReal)Nor.X()); | |
2379 | Normals->SetValue(j + 2, (Standard_ShortReal)Nor.Y()); | |
2380 | Normals->SetValue(j + 3, (Standard_ShortReal)Nor.Z()); | |
2381 | } | |
2382 | ||
2383 | delete pc; | |
2384 | polyTriangulation->SetNormals(Normals); | |
2385 | ||
2386 | return polyTriangulation; | |
2387 | } | |
2388 | ||
2389 | //=============================================================================================== | |
2390 | //function : VDrawSphere | |
2391 | //author : psn | |
2392 | //purpose : Create an AIS shape. | |
7fd59977 | 2393 | //=============================================================================================== |
161c4476 K |
2394 | static int VDrawSphere (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
2395 | { | |
2396 | // check for errors | |
2397 | Handle(AIS_InteractiveContext) aContextAIS = ViewerTest::GetAISContext(); | |
2398 | if (aContextAIS.IsNull()) | |
2399 | { | |
2400 | std::cout << "Call vinit before!\n"; | |
2401 | return 1; | |
2402 | } | |
2403 | else if (argc < 3) | |
2404 | { | |
2405 | std::cout << "Use: " << argv[0] | |
2406 | << " shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n"; | |
2407 | return 1; | |
2408 | } | |
7fd59977 | 2409 | |
161c4476 K |
2410 | // read the arguments |
2411 | TCollection_AsciiString aShapeName (argv[1]); | |
2412 | Standard_Integer aResolution = atoi (argv[2]); | |
2413 | Standard_Real aCenterX = (argc > 5) ? atof (argv[3]) : 0.0; | |
2414 | Standard_Real aCenterY = (argc > 5) ? atof (argv[4]) : 0.0; | |
2415 | Standard_Real aCenterZ = (argc > 5) ? atof (argv[5]) : 0.0; | |
2416 | Standard_Real aRadius = (argc > 6) ? atof (argv[6]) : 100.0; | |
2417 | Standard_Boolean isVBOEnabled = (argc > 7) ? atoi (argv[7]) : Standard_True; | |
2418 | Standard_Integer aRedrawsNb = (argc > 8) ? atoi (argv[8]) : 1; | |
2419 | Standard_Boolean toShowEdges = (argc > 9) ? atoi (argv[9]) : Standard_False; | |
2420 | ||
2421 | if (aRedrawsNb <= 0) | |
2422 | { | |
2423 | aRedrawsNb = 1; | |
2424 | } | |
7fd59977 | 2425 | |
161c4476 K |
2426 | // remove AIS object with given name from map |
2427 | if (GetMapOfAIS().IsBound2 (aShapeName)) | |
2428 | { | |
2429 | Handle(Standard_Transient) anObj = GetMapOfAIS().Find2 (aShapeName); | |
2430 | Handle(AIS_InteractiveObject) anInterObj = Handle(AIS_InteractiveObject)::DownCast (anObj); | |
2431 | if (anInterObj.IsNull()) | |
2432 | { | |
2433 | std::cout << "Shape name was used for non AIS viewer\n!"; | |
2434 | return 1; | |
2435 | } | |
2436 | aContextAIS->Remove (anInterObj, Standard_False); | |
2437 | GetMapOfAIS().UnBind2 (aShapeName); | |
2438 | } | |
2439 | ||
2440 | // enable/disable VBO | |
2441 | Handle(Graphic3d_GraphicDriver) aDriver = | |
2442 | Handle(Graphic3d_GraphicDriver)::DownCast (aContextAIS->CurrentViewer()->Device()->GraphicDriver()); | |
2443 | if (!aDriver.IsNull()) | |
2444 | { | |
2445 | aDriver->EnableVBO (isVBOEnabled); | |
2446 | } | |
2447 | ||
2448 | std::cout << "Compute Triangulation...\n"; | |
2449 | Handle(AIS_Triangulation) aShape | |
2450 | = new AIS_Triangulation (CalculationOfSphere (aCenterX, aCenterY, aCenterZ, | |
2451 | aResolution, | |
2452 | aRadius)); | |
2453 | Standard_Integer aNumberPoints = aShape->GetTriangulation()->Nodes().Length(); | |
2454 | Standard_Integer aNumberTriangles = aShape->GetTriangulation()->Triangles().Length(); | |
2455 | ||
2456 | // register the object in map | |
2457 | GetMapOfAIS().Bind (aShape, aShapeName); | |
2458 | ||
2459 | // stupid initialization of Green color in RGBA space as integer | |
2460 | // probably wrong for big-endian CPUs | |
2461 | Standard_Integer aRed = 0; | |
2462 | Standard_Integer aGreen = 255; | |
2463 | Standard_Integer aBlue = 0; | |
2464 | Standard_Integer anAlpha = 0; // not used | |
2465 | Standard_Integer aColorInt = aRed; | |
2466 | aColorInt += aGreen << 8; | |
2467 | aColorInt += aBlue << 16; | |
2468 | aColorInt += anAlpha << 24; | |
2469 | ||
2470 | // setup colors array per vertex | |
2471 | Handle(TColStd_HArray1OfInteger) aColorArray = new TColStd_HArray1OfInteger (1, aNumberPoints); | |
2472 | for (Standard_Integer aNodeId = 1; aNodeId <= aNumberPoints; ++aNodeId) | |
2473 | { | |
2474 | aColorArray->SetValue (aNodeId, aColorInt); | |
7fd59977 | 2475 | } |
161c4476 K |
2476 | aShape->SetColors (aColorArray); |
2477 | ||
2478 | // show statistics | |
2479 | Standard_Integer aPointsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
2480 | Standard_Integer aNormalsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat | |
2481 | Standard_Integer aColorsSize = aNumberPoints * 3 * sizeof(float); // 3x GLfloat without alpha | |
2482 | Standard_Integer aTrianglesSize = aNumberTriangles * 3 * sizeof(int); // 3x GLint | |
2483 | Standard_Integer aPolyConnectSize = aNumberPoints * 4 + aNumberTriangles * 6 * 4; | |
2484 | Standard_Integer aTotalSize = aPointsSize + aNormalsSize + aColorsSize + aTrianglesSize; | |
2485 | aTotalSize >>= 20; //MB | |
2486 | aNormalsSize >>= 20; | |
2487 | aColorsSize >>= 20; | |
2488 | aTrianglesSize >>= 20; | |
2489 | aPolyConnectSize >>= 20; | |
2490 | std::cout << "NumberOfPoints: " << aNumberPoints << "\n" | |
2491 | << "NumberOfTriangles: " << aNumberTriangles << "\n" | |
2492 | << "Amount of memory required for PolyTriangulation without Normals: " << (aTotalSize - aNormalsSize) << " Mb\n" | |
2493 | << "Amount of memory for colors: " << aColorsSize << " Mb\n" | |
2494 | << "Amount of memory for PolyConnect: " << aPolyConnectSize << " Mb\n" | |
2495 | << "Amount of graphic card memory required: " << aTotalSize << " Mb\n"; | |
7fd59977 | 2496 | |
2497 | // Setting material properties, very important for desirable visual result! | |
161c4476 K |
2498 | Graphic3d_MaterialAspect aMat (Graphic3d_NOM_PLASTIC); |
2499 | aMat.SetAmbient (0.2); | |
2500 | aMat.SetSpecular (0.5); | |
2501 | Handle(Graphic3d_AspectFillArea3d) anAspect | |
2502 | = new Graphic3d_AspectFillArea3d (Aspect_IS_SOLID, | |
2503 | Quantity_NOC_RED, | |
2504 | Quantity_NOC_YELLOW, | |
2505 | Aspect_TOL_SOLID, | |
2506 | 1.0, | |
2507 | aMat, | |
2508 | aMat); | |
7fd59977 | 2509 | Handle(Prs3d_ShadingAspect) aShAsp = new Prs3d_ShadingAspect(); |
161c4476 K |
2510 | if (toShowEdges) |
2511 | { | |
2512 | anAspect->SetEdgeOn(); | |
2513 | } | |
7fd59977 | 2514 | else |
161c4476 K |
2515 | { |
2516 | anAspect->SetEdgeOff(); | |
2517 | } | |
2518 | aShAsp->SetAspect (anAspect); | |
2519 | aShape->Attributes()->SetShadingAspect (aShAsp); | |
7fd59977 | 2520 | |
161c4476 | 2521 | aContextAIS->Display (aShape, Standard_False); |
7fd59977 | 2522 | |
2523 | // Two viewer updates are needed in order to measure time spent on | |
161c4476 | 2524 | // loading triangulation to graphic card memory + redrawing (1st update) and |
7fd59977 | 2525 | // time spent on redrawing itself (2nd and all further updates) |
161c4476 K |
2526 | OSD_Chronometer aTimer; |
2527 | Standard_Real aUserSeconds, aSystemSeconds; | |
2528 | aTimer.Start(); | |
2529 | const Handle(V3d_Viewer)& aViewer = aContextAIS->CurrentViewer(); | |
2530 | for (Standard_Integer anInteration = 0; anInteration < aRedrawsNb; ++anInteration) | |
2531 | { | |
2532 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) | |
7fd59977 | 2533 | { |
161c4476 K |
2534 | if (anInteration == 0) |
2535 | { | |
2536 | aViewer->ActiveView()->Update(); | |
2537 | } | |
7fd59977 | 2538 | else |
161c4476 K |
2539 | { |
2540 | aViewer->ActiveView()->Redraw(); | |
2541 | } | |
7fd59977 | 2542 | } |
2543 | } | |
161c4476 K |
2544 | aTimer.Show (aUserSeconds, aSystemSeconds); |
2545 | aTimer.Stop(); | |
2546 | std::cout << "Number of scene redrawings: " << aRedrawsNb << "\n" | |
2547 | << "CPU user time: " | |
2548 | << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aUserSeconds | |
2549 | << " msec\n" | |
2550 | << "CPU system time: " | |
2551 | << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * aSystemSeconds | |
2552 | << " msec\n" | |
2553 | << "CPU average time of scene redrawing: " | |
2554 | << std::setiosflags(std::ios::fixed) << std::setprecision(16) << 1000.0 * (aUserSeconds / (Standard_Real )aRedrawsNb) | |
2555 | << " msec\n"; | |
7fd59977 | 2556 | return 0; |
2557 | } | |
2558 | ||
2559 | ||
2560 | //======================================================================= | |
2561 | //function : ObjectsCommands | |
161c4476 | 2562 | //purpose : |
7fd59977 | 2563 | //======================================================================= |
2564 | ||
2565 | void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) | |
2566 | { | |
2567 | const char *group ="AISObjects"; | |
2568 | theCommands.Add("vtrihedron", | |
2569 | "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] ", | |
2570 | __FILE__,VTrihedron,group); | |
2571 | ||
161c4476 | 2572 | theCommands.Add("vtri2d", |
7fd59977 | 2573 | "vtri2d Name Selection in the viewer only ", |
2574 | __FILE__,VTrihedron2D ,group); | |
2575 | ||
161c4476 | 2576 | theCommands.Add("vplanetri", |
7fd59977 | 2577 | "vplanetri Name Selection in the viewer only ", |
2578 | __FILE__,VPlaneTrihedron ,group); | |
2579 | ||
2580 | theCommands.Add("vsize", | |
2581 | "vsize : vsize [name(Default=Current)] [size(Default=100)] ", | |
2582 | __FILE__,VSize,group); | |
2583 | ||
2584 | theCommands.Add("vaxis", | |
2585 | "vaxis nom [Xa] [Ya] [Za] [Xb] [Yb] [Zb]", | |
2586 | __FILE__,VAxisBuilder,group); | |
2587 | ||
161c4476 | 2588 | theCommands.Add("vaxispara", |
7fd59977 | 2589 | "vaxispara nom ", |
2590 | __FILE__,VAxisBuilder,group); | |
2591 | ||
2592 | theCommands.Add("vaxisortho", | |
2593 | "vaxisotho nom ", | |
2594 | __FILE__,VAxisBuilder,group); | |
2595 | ||
2596 | theCommands.Add("vpoint", | |
2597 | "vpoint PointName [Xa] [Ya] [Za] ", | |
2598 | __FILE__,VPointBuilder,group); | |
2599 | ||
2600 | theCommands.Add("vplane", | |
2601 | "vplane PlaneName [AxisName/PlaneName/PointName] [PointName/PointName/PointName] [Nothing/Nothing/PointName] ", | |
2602 | __FILE__,VPlaneBuilder,group); | |
2603 | ||
2604 | theCommands.Add("vplanepara", | |
2605 | "vplanepara PlaneName ", | |
2606 | __FILE__,VPlaneBuilder,group); | |
2607 | ||
2608 | theCommands.Add("vplaneortho", | |
2609 | "vplaneortho PlaneName ", | |
2610 | __FILE__,VPlaneBuilder,group); | |
2611 | ||
161c4476 | 2612 | theCommands.Add("vline", |
7fd59977 | 2613 | "vline: vline LineName [Xa/PointName] [Ya/PointName] [Za] [Xb] [Yb] [Zb] ", |
2614 | __FILE__,VLineBuilder,group); | |
2615 | ||
2616 | theCommands.Add("vcircle", | |
2617 | "vcircle CircleName [PointName/PlaneName] [PointName] [Radius] ", | |
2618 | __FILE__,VCircleBuilder,group); | |
2619 | ||
2620 | theCommands.Add("vdrawtext", | |
2621 | "vdrawtext : vdrawtext name X Y Z R G B hor_align ver_align angle zoomable height Aspect FONT ", | |
2622 | __FILE__,VDrawText,group); | |
2623 | ||
2624 | theCommands.Add("vdrawsphere", | |
161c4476 | 2625 | "vdrawsphere: vdrawsphere shapeName Fineness [X=0.0 Y=0.0 Z=0.0] [Radius=100.0] [ToEnableVBO=1] [NumberOfViewerUpdate=1] [ToShowEdges=0]\n", |
7fd59977 | 2626 | __FILE__,VDrawSphere,group); |
2627 | ||
2628 | } |