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