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