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