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