Test for 0022778: Bug in BRepMesh
[occt.git] / src / ViewerTest / ViewerTest_RelationCommands.cxx
1 // Created on: 1998-11-12
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <ViewerTest.hxx>
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <AIS_InteractiveContext.hxx>
29 #include <string.h>
30 #include <Draw_Interpretor.hxx>
31 #include <Draw.hxx>
32 #include <Draw_Appli.hxx>
33 #include <DBRep.hxx>
34
35
36 #include <TCollection_AsciiString.hxx>
37 #include <V3d_Viewer.hxx>
38 #include <V3d_View.hxx>
39 #include <V3d.hxx>
40
41 #include <AIS_InteractiveContext.hxx>
42 #include <AIS_Shape.hxx>
43 #include <AIS_Point.hxx>
44 #include <AIS_DisplayMode.hxx>
45 #include <TColStd_MapOfInteger.hxx>
46 #include <AIS_MapOfInteractive.hxx>
47 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
48 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
49 #include <ViewerTest_EventManager.hxx>
50
51 #include <TopoDS_Solid.hxx>
52 #include <BRepTools.hxx>
53 #include <BRep_Builder.hxx>
54 #include <TopAbs_ShapeEnum.hxx>
55
56 #include <TopoDS.hxx>
57 #include <BRep_Tool.hxx>
58
59 #include <TopAbs.hxx>
60 #include <TopExp.hxx>
61 #include <TopoDS_Vertex.hxx>
62 #include <TopoDS_Face.hxx>
63
64 #include <Draw_Window.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_DisplayMode.hxx>
68 #include <ElSLib.hxx>
69 #include <Geom_CartesianPoint.hxx>
70 #include <StdSelect.hxx>
71
72
73 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
74 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
75 extern Handle(AIS_InteractiveContext)& TheAISContext ();
76
77
78 #include <Geom_Plane.hxx>
79 #include <gp_Pln.hxx>
80 #include <AIS_AngleDimension.hxx>
81 #include <TCollection_ExtendedString.hxx>
82 #include <GC_MakePlane.hxx>
83 #include <IntAna_IntConicQuad.hxx>
84 #include <Select3D_Projector.hxx>
85 #include <Precision.hxx>
86 #include <IntAna_Quadric.hxx>
87
88 #ifdef HAVE_STRINGS_H
89 # include <strings.h>
90 #endif
91
92
93
94 #define VertexMask 0x01
95 #define EdgeMask 0x02
96 #define FaceMask 0x04
97
98
99 static Standard_Boolean ComputeIntersection(const gp_Lin& L,const gp_Pln& ThePl, gp_Pnt& TheInter)
100 {
101   static IntAna_Quadric TheQuad;
102   TheQuad.SetQuadric(ThePl);
103   static IntAna_IntConicQuad QQ;
104    QQ.Perform(L,TheQuad);
105   if(QQ.IsDone()){
106     if(QQ.NbPoints()>0){
107       TheInter = QQ.Point(1);
108       return Standard_True;
109     }
110   }
111   return Standard_False;
112 }
113
114 //=======================================================================
115 //function : Get3DPointAtMousePosition
116 //purpose  : calcul du point 3D correspondant a la position souris dans le plan de 
117 // la vue...
118 //=======================================================================
119 static gp_Pnt Get3DPointAtMousePosition(){
120   Handle(V3d_View) aview = ViewerTest::CurrentView();
121   static Select3D_Projector prj;
122   prj.SetView(aview);
123   
124   // le plan de la vue...
125   Standard_Real xv,yv,zv;
126   aview->Proj(xv,yv,zv);
127   Standard_Real xat,yat,zat;
128   aview->At(xat,yat,zat);
129   gp_Pln ThePl(gp_Pnt(xat,yat,zat),gp_Dir(xv,yv,zv));
130   Standard_Integer xpix,ypix;
131   Standard_Real x,y;
132   ViewerTest::GetMousePosition(xpix,ypix);
133   aview->Convert(xpix,ypix,x,y); // espace reel 2D de la vue...
134   gp_Lin L = prj.Shoot(x,y);
135   gp_Pnt P(0.,0.,0.);
136
137   ComputeIntersection(L,ThePl,P);
138   return P;
139 }
140
141
142
143 //=======================================================================
144 //function : ComputeNewPlaneForDim
145 //purpose  : 
146 //=======================================================================
147 static void ComputeNewPlaneForDim(const Handle(AIS_Relation)& R,
148                                   gp_Pln& ,
149                                   gp_Pnt& )
150 {
151 // 0    COMPOUND,
152 // 1    COMPSOLID,
153 // 2    SOLID,
154 // 3    SHELL,
155 // 4    FACE,
156 // 5    WIRE,
157 // 6    EDGE,
158 // 7    VERTEX,
159 // 8    SHAPE
160   TopoDS_Shape S1 = R->FirstShape();
161   TopoDS_Shape S2 = R->SecondShape();
162   TopAbs_ShapeEnum Typ1 = S1.ShapeType();
163   TopAbs_ShapeEnum Typ2 = S2.ShapeType();
164   
165   gp_Pnt thepoint [3];
166   thepoint[0] = Get3DPointAtMousePosition();
167   
168   // on met l'objet le plus petit en 1...
169   if((Standard_Integer)Typ2>(Standard_Integer)Typ1){
170     
171     TopoDS_Shape tmpS = S1;
172     TopAbs_ShapeEnum tmpT = Typ1;
173     S1= S2;
174     Typ1 = Typ2;
175     S2= tmpS;
176     Typ2 = tmpT;
177   }
178 /*  
179   switch (Typ1){
180   case TopAbs_VERTEX:{
181     thepoint[0]  = BRep_Tool::Pnt(S1);
182     if(Typ2==TopAbs_VERTEX)
183       thepoint[1] = BRep_Tool::Pnt(S2);
184     else if(Typ2==TopAbs_EDGE){
185       TopoDS_Vertex  Va,Vb;
186       TopExp::Vertices(S2,Va,Vb);
187       thepoint[1] = BRep_Tool::Pnt(Va);
188     }
189     else if(Typ2==TopAbs_FACE){
190     }
191     break;
192   }
193   case TopAbs_EDGE:
194   }
195 */
196 }
197
198
199 //=======================================================================
200 //function : VAngleDimBuilder
201 //purpose  : 
202 //=======================================================================
203 static int VAngleDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
204 {
205   Standard_Integer myCurrentIndex;
206   
207   if (argc!=2) {di<<" vangledim error."<<"\n";return 1;}
208   TheAISContext()->CloseAllContexts();
209   TheAISContext()->OpenLocalContext();
210   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
211   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
212   di<<" Select two  edges coplanar or not."<<"\n";
213   Standard_Integer argcc = 5;
214   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
215   const char **argvv = (const char **) buff;
216   while (ViewerMainLoop( argcc, argvv) ) { }
217   
218   TopoDS_Shape ShapeA;
219   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
220     ShapeA = TheAISContext()->SelectedShape();
221   }
222   // Si ShapeA est un Edge.
223   if (ShapeA.ShapeType()== TopAbs_EDGE ) {
224     
225     // Boucle d'attente waitpick.
226     Standard_Integer argccc = 5;
227     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
228     const char **argvvv = (const char **) bufff;
229     while (ViewerMainLoop( argccc, argvvv) ) { }
230     // fin de la boucle
231     
232     TopoDS_Shape ShapeB;
233     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
234       ShapeB = TheAISContext()->SelectedShape();
235     }
236     // ShapeB doit etre un Edge
237     if (ShapeB.ShapeType()!= TopAbs_EDGE ) {
238       di<<" vangledim error: you shoud have selected an edge."<<"\n";return 1;
239     }
240     
241     // on recupere les vertexes de edgeA
242     TopoDS_Vertex Va,Vb;
243     TopExp::Vertices(TopoDS::Edge(ShapeA),Va ,Vb );
244     // Recuperation des points.
245     gp_Pnt A=BRep_Tool::Pnt(Va);
246     gp_Pnt B=BRep_Tool::Pnt(Vb);
247     gp_Pnt C(A.X()+5 ,A.Y()+5 ,A.Z()+5 );
248
249
250     // Construction du plane. Methode pas orthodoxe!
251     GC_MakePlane MkPlane(A ,B ,C );
252     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
253     
254     // Construction du texte.
255     TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString( 90 ) );
256     
257     // Fermeture du context local.
258     TheAISContext()->CloseLocalContext(myCurrentIndex);
259     
260     // Construction de l'AIS dimension
261     Handle (AIS_AngleDimension) myAISDim= new AIS_AngleDimension (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB) ,theGeomPlane ,M_PI/2.0 ,TheMessage_Str );
262     GetMapOfAIS().Bind (myAISDim,argv[1]);
263     TheAISContext()->Display(myAISDim );
264     
265   }
266 else {
267   di<<" vangledim error: you must select 2 edges."<<"\n";return 1;
268 }
269   
270   
271   return 0;
272 }
273
274 //==============================================================================
275 //function : VDiameterDim
276 //purpose  : Display the diameter dimension of a face or an edge.
277 //Draw arg : vdiameterdim Name 
278 //==============================================================================
279 #include <AIS_DiameterDimension.hxx>
280 #include <TCollection_ExtendedString.hxx>
281 #include <BRepAdaptor_Curve.hxx>
282 #include <gp_Circ.hxx>
283
284
285 static int VDiameterDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
286 {
287   // Declarations
288   Standard_Integer myCurrentIndex;
289   Standard_Real theRadius;
290     
291   // Verification
292   if (argc!=2) {di<<" vdiameterdim error"<<"\n";return 1;}
293   // Fermeture des contextes locaux
294   TheAISContext()->CloseAllContexts();
295   // Ouverture d'un contexte local et recuperation de son index.
296   TheAISContext()->OpenLocalContext();
297   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
298   
299   // On active les modes de selections Edges et Faces.
300   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
301   di<<" Select an circled edge."<<"\n";
302   
303   // Boucle d'attente waitpick.
304   Standard_Integer argcc = 5;
305   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
306   const char **argvv = (const char **) buff;
307   while (ViewerMainLoop( argcc, argvv) ) { }
308   // fin de la boucle
309   
310   TopoDS_Shape ShapeA;
311   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
312     ShapeA = TheAISContext()->SelectedShape();
313   }
314   if (ShapeA.ShapeType()==TopAbs_EDGE  ) {
315     
316     // Recuperation du rayon 
317     BRepAdaptor_Curve theCurve(TopoDS::Edge(ShapeA));
318     if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vdiameterdim error: the edge is not a circular one."<<"\n";return 1;}
319     else {
320       gp_Circ theGpCircle=theCurve.Circle();
321       theRadius=2.*theGpCircle.Radius();
322     }
323     
324     // Construction du texte.
325     TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theRadius  ) );
326     // Construction de L'AIS_AngleDimension.
327     TheAISContext()->CloseLocalContext(myCurrentIndex);
328     
329     Handle (AIS_DiameterDimension) myDiamDim= new AIS_DiameterDimension(ShapeA ,theRadius ,TheMessage_Str );
330     GetMapOfAIS().Bind (myDiamDim,argv[1]);
331     TheAISContext()->Display(myDiamDim );
332     
333   }
334   
335   else {
336     di<<" vdiameterdim error: the selection of a face or an edge was expected."<<"\n";return 1;
337   }
338   
339   return 0;
340   
341 }
342
343
344 //==============================================================================
345 // Fonction  vconcentric
346 // -----------------  Uniquement par selection dans le viewer.
347 //==============================================================================
348
349 //==============================================================================
350 //function : VConcentric
351 //purpose  : Display the concentric relation between two surfaces.
352 //Draw arg : vconcentric Name
353 //==============================================================================
354 #include <AIS_ConcentricRelation.hxx>
355 #include <Geom_Plane.hxx>
356 #include <gp_Pln.hxx>
357 #include <GC_MakePlane.hxx>
358 #include <BRepAdaptor_Curve.hxx>
359 #include <TopExp_Explorer.hxx>
360
361
362 static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
363 {
364   // Declarations
365   Standard_Integer myCurrentIndex;
366   
367   // Verification
368   if (argc!=2) {di<<"vconcentric  error."<<"\n";return 1;}
369   // Fermeture des contextes locaux
370   TheAISContext()->CloseAllContexts();
371   // Ouverture d'un contexte local et recuperation de son index.
372   TheAISContext()->OpenLocalContext();
373   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
374   
375   // On active les modes de selections Edges et Faces.
376   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
377   di<<" Select a circled edge."<<"\n";
378   
379   // Boucle d'attente waitpick.
380   Standard_Integer argcc = 5;
381   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
382   const char **argvv = (const char **) buff;
383   while (ViewerMainLoop( argcc, argvv) ) { }
384   // fin de la boucle
385   
386   TopoDS_Shape ShapeA;
387   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
388     ShapeA = TheAISContext()->SelectedShape();
389   }
390   // ShapeA est un edge
391   // ==================
392   if (ShapeA.ShapeType()==TopAbs_EDGE  ) {
393     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
394     di<<" Select an edge."<<"\n";
395     
396     // Boucle d'attente waitpick.
397     Standard_Integer argccc = 5;
398     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
399     const char **argvvv = (const char **) bufff;
400     while (ViewerMainLoop( argccc, argvvv) ) { }
401     // fin de la boucle
402     
403     TopoDS_Shape ShapeB;
404     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
405       ShapeB = TheAISContext()->SelectedShape();
406     }
407     if (ShapeB.ShapeType()!=TopAbs_EDGE  ) {
408       di<<" vconcentric error: select an edge."<<"\n";return 1;
409     }
410      
411     // Construction du plane.
412     // On recupere le centre du cercle A.
413     BRepAdaptor_Curve theCurveA(TopoDS::Edge(ShapeA) );
414     gp_Circ theCircleA=theCurveA.Circle();
415     gp_Pnt theCenterA=theCircleA.Location();
416     // On recupere deux points sur le cercle A
417     gp_Pnt B= theCurveA.Value(0.25);
418     gp_Pnt C= theCurveA.Value(0.75);
419     // Construction du plane.
420     GC_MakePlane MkPlane(theCenterA ,B ,C );
421     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
422     
423     // Fermeture du context local
424     TheAISContext()->CloseLocalContext(myCurrentIndex);
425     
426     Handle (AIS_ConcentricRelation) myConcentry= new AIS_ConcentricRelation(ShapeA, ShapeB, theGeomPlane );
427     TheAISContext()->Display(myConcentry );
428     GetMapOfAIS().Bind (myConcentry,argv[1]);
429   }
430   
431   
432   else {
433     di<<" vconcentric  error: the selection of a face or an edge was expected."<<"\n";return 1;
434   }
435   
436   return 0;
437   
438   
439   
440   
441 }
442
443 //==============================================================================
444 //function : VEqualDistRelation
445 //purpose  : 
446 //Draw arg : vdiameterdim Name DiameterValue
447 //==============================================================================
448 #include <AIS_EqualDistanceRelation.hxx>
449 #include <BRepExtrema_ExtCC.hxx>
450 #include <GC_MakePlane.hxx>
451
452
453 static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
454 {
455   // Declarations
456   Standard_Integer myCurrentIndex;
457   
458   // Verification
459   if (argc!=2) {di<<" vequaldistrelation error: no arguments allowed."<<"\n";return 1;}
460   
461   // Fermeture des contextes locaux
462   TheAISContext()->CloseAllContexts();
463   
464   // Ouverture d'un contexte local et recuperation de son index.
465   TheAISContext()->OpenLocalContext();
466   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
467   
468   // On active les modes de selections Edges et Vertexes.
469   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
470   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
471   di<<" Select an edge or a vertex"<<"\n";
472   
473   // Boucle d'attente waitpick.
474   Standard_Integer argc1 = 5;
475   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
476   const char **argv1 = (const char **) buf1;
477   while (ViewerMainLoop( argc1, argv1) ) { }
478   // fin de la boucle
479   
480   TopoDS_Shape ShapeA;
481   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
482     ShapeA = TheAISContext()->SelectedShape();
483   }
484   
485   di<<" Select an edge or a vertex"<<"\n";
486   // Boucle d'attente waitpick.
487   Standard_Integer argc2 = 5;
488   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
489   const char **argv2 = (const char **) buf2;
490   while (ViewerMainLoop( argc2, argv2) ) { }
491   // fin de la boucle
492   
493   TopoDS_Shape ShapeB;
494   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
495     ShapeB = TheAISContext()->SelectedShape();
496   }
497   
498   // Verification des resultats.
499   if (ShapeA.ShapeType()==TopAbs_EDGE && ShapeB.ShapeType()==TopAbs_EDGE  ) {
500     // A et B sont des edges ils doivent etre paralleles
501     BRepExtrema_ExtCC myDeltaEdge (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB)  );
502     // on verifie qu'ils sont pas paralleles.
503     if (!myDeltaEdge.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
504     
505   }
506   
507   
508   di<<" Select an edge or a vertex"<<"\n";
509   // Boucle d'attente waitpick.
510   Standard_Integer argc3 = 5;
511   const char *buf3[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
512   const char **argv3 = (const char **) buf3;
513   while (ViewerMainLoop( argc3, argv3) ) { }
514   // fin de la boucle
515   
516   TopoDS_Shape ShapeC;
517   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
518     ShapeC = TheAISContext()->SelectedShape();
519   }
520   
521   di<<" Select an edge or a vertex"<<"\n";
522   // Boucle d'attente waitpick.
523   Standard_Integer argc4 = 5;
524   const char *buf4[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
525   const char **argv4 = (const char **) buf4;
526   while (ViewerMainLoop( argc4, argv4) ) { }
527   // fin de la boucle
528   
529   TopoDS_Shape ShapeD;
530   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
531     ShapeD = TheAISContext()->SelectedShape();
532   }
533   // Verification des resultats.
534   if (ShapeC.ShapeType()==TopAbs_EDGE && ShapeD.ShapeType()==TopAbs_EDGE  ) {
535     // C et D sont des edges ils doivent etre paralleles
536     BRepExtrema_ExtCC myDeltaEdge2 (TopoDS::Edge(ShapeC) ,TopoDS::Edge(ShapeD)  );
537     // on verifie qu'ils sont pas paralleles.
538     if (!myDeltaEdge2.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
539     
540   }
541   
542   // Creation du plan porteur de la contrainte.Methode lourde!
543   gp_Pnt A,B,C;
544   if (ShapeA.ShapeType()==TopAbs_EDGE) {
545     // A est un edge
546     TopoDS_Vertex Va,Vb;
547     TopExp::Vertices (TopoDS::Edge(ShapeA) ,Va ,Vb );
548     A=BRep_Tool::Pnt(Va);
549     B=BRep_Tool::Pnt(Vb);
550     
551     if (ShapeB.ShapeType()==TopAbs_EDGE) {
552       // B est un edge aussi
553       TopoDS_Vertex Vc,Vd;
554       TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vc ,Vd );
555       // besoin que de 1 point.
556       C=BRep_Tool::Pnt(Vc);
557       
558     }
559     else {
560       // B est un vertex
561       C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
562     }
563   }
564   else {
565     // A est un vertex
566     A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
567     
568     if (ShapeB.ShapeType()==TopAbs_EDGE ) {
569       // B est un edge 
570       TopoDS_Vertex Vb,Vc;
571       TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vb ,Vc );
572       // besoin que de 2 points.
573       B=BRep_Tool::Pnt(Vb);
574       C=BRep_Tool::Pnt(Vc);
575       
576     }
577     else {
578       // B est un vertex
579       B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
580       C.SetX(B.X()+5.);
581       C.SetY(B.Y()+5.);
582       C.SetZ(B.Z()+5.);
583       
584     }
585   }
586   
587   // Fermeture du context local.
588   TheAISContext()->CloseLocalContext(myCurrentIndex);
589   
590   // construction du plane 
591   GC_MakePlane MkPlane(A ,B ,C );
592   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
593   
594   // Construction de l'AIS_EqualDistanceRelation
595   Handle (AIS_EqualDistanceRelation ) myRelation= new AIS_EqualDistanceRelation (ShapeA, ShapeB, ShapeC ,ShapeD , theGeomPlane );
596   TheAISContext()->Display(myRelation );
597   GetMapOfAIS().Bind (myRelation,argv[1]);
598   
599
600   
601   return 0;
602   
603 }
604
605 //==============================================================================
606 //function : VEqualRadiusRelation
607 //purpose  : 
608 //Draw arg : vdiameterdim Name DiameterValue
609 //==============================================================================
610 #include <AIS_EqualRadiusRelation.hxx>
611 #include <GC_MakePlane.hxx>
612 #include <BRepAdaptor_Curve.hxx>
613
614
615 static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
616 {
617   // Declarations
618   Standard_Integer myCurrentIndex;
619   
620   // Verification
621   if (argc!=2) {di<<" vequalrad error: no arguments allowed."<<"\n";return 1;}
622   
623   // Fermeture des contextes locaux
624   TheAISContext()->CloseAllContexts();
625   
626   // Ouverture d'un contexte local et recuperation de son index.
627   TheAISContext()->OpenLocalContext();
628   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
629   
630   // On active les modes de selections Edges.
631   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
632   di<<" Select an circled edge "<<"\n";
633   
634   // Boucle d'attente waitpick.
635   Standard_Integer argc1 = 5;
636   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
637   const char **argv1 = (const char **) buf1;
638   while (ViewerMainLoop( argc1, argv1) ) { }
639   // fin de la boucle
640   
641   TopoDS_Shape ShapeA;
642   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
643     ShapeA = TheAISContext()->SelectedShape();
644   }
645   
646   di<<" Select the last circled edge."<<"\n";
647   // Boucle d'attente waitpick.
648   Standard_Integer argc2 = 5;
649   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
650   const char **argv2 = (const char **) buf2;
651   while (ViewerMainLoop( argc2, argv2) ) { }
652   // fin de la boucle
653   
654   TopoDS_Shape ShapeB;
655   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
656     ShapeB = TheAISContext()->SelectedShape();
657   }
658   // creation du plan qui contient la contrainte.
659   TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
660   TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
661   BRepAdaptor_Curve theCurveA(EdgeA);
662   // On recupere 3 points A,B,C de la curve.
663   gp_Pnt A=theCurveA.Value(0.1);
664   gp_Pnt B=theCurveA.Value(0.5);
665   gp_Pnt C=theCurveA.Value(0.9);
666   
667   // fermeture du contexte local.
668   TheAISContext()->CloseLocalContext(myCurrentIndex);
669   
670   // Creation du plane.
671   GC_MakePlane MkPlane (A ,B ,C );
672   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
673   // Construction de l'AIS_EqualRadiusRelation
674   Handle (AIS_EqualRadiusRelation ) myRelation= new AIS_EqualRadiusRelation (EdgeA,EdgeB, theGeomPlane );
675   TheAISContext()->Display(myRelation );
676   GetMapOfAIS().Bind (myRelation,argv[1]);
677   
678   return 0;
679   
680 }
681
682
683 //==============================================================================
684 //function : VFixRelation
685 //purpose  : 
686 //Draw arg : vdiameterdim Name DiameterValue
687 //==============================================================================
688 #include <AIS_FixRelation.hxx>
689 #include <GC_MakePlane.hxx>
690 #include <BRepAdaptor_Curve.hxx>
691
692 static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
693 {
694   // Declarations
695   Standard_Integer myCurrentIndex;
696   
697   // Verification
698   if (argc!=2) {di<<" vfix  error: no arguments allowed."<<"\n";return 1;}
699   
700   // Fermeture des contextes locaux
701   TheAISContext()->CloseAllContexts();
702   
703   // Ouverture d'un contexte local et recuperation de son index.
704   TheAISContext()->OpenLocalContext();
705   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
706   
707   // On active les modes de selections edge.
708   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
709   di<<" Select an edge. "<<"\n";
710   
711   // Boucle d'attente waitpick.
712   Standard_Integer argc1 = 5;
713   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
714   const char **argv1 = (const char **) buf1;
715   while (ViewerMainLoop( argc1, argv1) ) { }
716   // fin de la boucle
717   
718   TopoDS_Shape ShapeA;
719   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
720     ShapeA = TheAISContext()->SelectedShape();
721   }
722   
723   // creation du plan qui contient la contrainte.
724   TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
725   BRepAdaptor_Curve theCurveA(EdgeA);
726   // On recupere 3 points A,B,C de la curve.
727   gp_Pnt A=theCurveA.Value(0.1);
728   gp_Pnt B=theCurveA.Value(0.5);
729   gp_Pnt D=theCurveA.Value(0.9);
730   gp_Pnt C(B.X()+5,B.Y()+5,B.Z()+5);
731   
732   // fermeture du contexte local.
733   TheAISContext()->CloseLocalContext(myCurrentIndex);
734   
735   // Creation du plane.
736   GC_MakePlane MkPlane (A ,D ,C );
737   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
738   // Construction de l'AIS_EqualRadiusRelation
739   Handle (AIS_FixRelation) myRelation= new AIS_FixRelation (EdgeA,theGeomPlane );
740   TheAISContext()->Display(myRelation );
741   GetMapOfAIS().Bind (myRelation,argv[1]);
742   
743   
744   return 0;
745   
746 }
747
748 //==============================================================================
749 //function : VIdenticRelation
750 //purpose  : 
751 //Draw arg : vdiameterdim Name DiameterValue
752 //==============================================================================
753 #include <AIS_IdenticRelation.hxx>
754 #include <BRepAdaptor_Curve.hxx>
755 #include <TopExp_Explorer.hxx>
756
757
758 static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
759 {
760   // Declarations
761   Standard_Integer myCurrentIndex;
762   
763   // Verification
764   if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;}
765   
766   // Fermeture des contextes locaux
767   TheAISContext()->CloseAllContexts();
768   
769   // Ouverture d'un contexte local et recuperation de son index.
770   TheAISContext()->OpenLocalContext();
771   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
772   
773   // On active les modes de selections  vertex et face.
774   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
775   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
776   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
777   di<<" Select an edge, a face or a vertex. "<<"\n";
778   
779   // Boucle d'attente waitpick.
780   Standard_Integer argc1 = 5;
781   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
782   const char **argv1 = (const char **) buf1;
783   while (ViewerMainLoop( argc1, argv1) ) { }
784   // fin de la boucle
785   
786   TopoDS_Shape ShapeA;
787   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
788     ShapeA = TheAISContext()->SelectedShape();
789   }
790   
791   di<<" Select an edge, a face or a vertex. "<<"\n";
792   // Boucle d'attente waitpick.
793   Standard_Integer argc2 = 5;
794   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
795   const char **argv2 = (const char **) buf2;
796   while (ViewerMainLoop( argc2, argv2) ) { }
797   // fin de la boucle
798   
799   TopoDS_Shape ShapeB;
800   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
801     ShapeB = TheAISContext()->SelectedShape();
802   }
803   
804   // Recuperation de points pour construir le Geom_Plnae.
805   gp_Pnt A,B,C;
806   if (ShapeA.ShapeType()==TopAbs_EDGE) {
807     // A est un edge; on peut supposer qu'il sera element d'une face ou possesseur d'un vertex ou identic a un autre edge.
808     // on recupere deux points sur l'edge (il peut etre rectiligne)
809     TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
810     BRepAdaptor_Curve theCurveA(EdgeA);
811     // Creation des 3 points.
812     A=theCurveA.Value(0.1);
813     B=theCurveA.Value(0.9);
814     C.SetX(B.X()+5.);
815     C.SetY(B.Y()+5.);
816     C.SetZ(B.Z()+5.);
817   }
818   else if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
819     // SahpeA est un Vertex
820     // On va utiliser ShapeB
821     if (ShapeB.ShapeType()==TopAbs_EDGE) {
822       // B est un edge 
823       TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
824       BRepAdaptor_Curve theCurveB(EdgeB);
825       // Creation des 3 points.
826       A=theCurveB.Value(0.1);
827       B=theCurveB.Value(0.9);
828       C.SetX(B.X()+5.);
829       C.SetY(B.Y()+5.);
830       C.SetZ(B.Z()+5.);
831       
832     }
833     else if (ShapeB.ShapeType()==TopAbs_FACE ) {
834       // Shape B est une face
835       TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
836       // On recupere 1 edge de FaceB(la face n'a pas forcement de vertex) (l'element A est forcement dans B).
837       TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE);
838       TopoDS_Edge EdgeFromB=TopoDS::Edge(FaceExp.Current() );
839       // On recupere les 3 points de l'edge de face B
840       BRepAdaptor_Curve theCurveB(EdgeFromB);
841       // On recupere 3 points A,B,C de la curve.
842       A=theCurveB.Value(0.1);
843       B=theCurveB.Value(0.5);
844       C=theCurveB.Value(0.9);
845       
846     }
847     else {
848       // B ets un vetex aussi
849       A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
850       B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
851       C.SetX(B.X()+5.);
852       C.SetY(B.Y()+5.);
853       C.SetZ(B.Z()+5.);
854       
855     }
856     
857   }
858   else {
859     // A est une face.
860     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
861     // On recupere 1 edge de FaceA
862     TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
863     TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() );
864     // On recupere les 3 points de l'edge
865     BRepAdaptor_Curve theCurveA(EdgeFromA);
866     // On recupere 3 points A,B,C de la curve.
867     A=theCurveA.Value(0.1);
868     B=theCurveA.Value(0.5);
869     C=theCurveA.Value(0.9);
870     
871   }
872   
873   // Fermeture du context local.
874   TheAISContext()->CloseLocalContext(myCurrentIndex);
875   // On construit le plane 
876   GC_MakePlane MkPlane (A ,B ,C );
877   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
878   
879   // Construction de l'AIS_IdenticRelation
880   Handle ( AIS_IdenticRelation ) myRelation= new AIS_IdenticRelation  (ShapeA ,ShapeB, theGeomPlane );
881   TheAISContext()->Display(myRelation );
882   GetMapOfAIS().Bind (myRelation,argv[1]);
883   
884
885   
886   return 0;
887   
888 }
889 //==============================================================================
890 //function : VLengthDimension
891 //purpose  : Display the diameter dimension of a face or an edge.
892 //Draw arg : vdiameterdim Name DiameterValue
893 //==============================================================================
894 #include <AIS_LengthDimension.hxx>
895 #include <BRepExtrema_ExtCC.hxx>
896 #include <BRepExtrema_ExtPC.hxx>
897 #include <BRepExtrema_ExtCF.hxx>
898 #include <BRepExtrema_ExtPF.hxx>
899 #include <BRepExtrema_ExtFF.hxx>
900 #include <TCollection_ExtendedString.hxx>
901 #include <BRepExtrema_DistShapeShape.hxx>
902 #include <GC_MakePlane.hxx>
903 #include <TopExp_Explorer.hxx>
904 #include <BRepBuilderAPI_MakeVertex.hxx>
905 static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
906 {
907   // Declarations
908   Standard_Integer myCurrentIndex;
909   Standard_Real theDist;
910   
911   // Verification
912   if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;}
913   
914   // Fermeture des contextes locaux
915   TheAISContext()->CloseAllContexts();
916   
917   // Ouverture d'un contexte local et recuperation de son index.
918   myCurrentIndex = TheAISContext()->OpenLocalContext();
919   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
920   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
921   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
922   di<<" Select an edge, a face or a vertex. "<<"\n";
923   
924   // Boucle d'attente waitpick.
925   Standard_Integer argc1 = 5;
926   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
927   const char **argv1 = (const char **) buf1;
928   while (ViewerMainLoop( argc1, argv1) ) { }
929
930   // fin de la boucle
931   TopoDS_Shape ShapeA;
932   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
933     ShapeA = TheAISContext()->SelectedShape();
934   }
935   di<<" Select an edge, a face or a vertex. "<<"\n";
936   // Boucle d'attente waitpick.
937   Standard_Integer argc2 = 5;
938   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
939   const char **argv2 = (const char **) buf2;
940   while (ViewerMainLoop( argc2, argv2) ) { }
941   // fin de la boucle
942   
943   TopoDS_Shape ShapeB;
944   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
945     ShapeB = TheAISContext()->SelectedShape();
946   }
947   // ShapeA est un edge.
948   // ===================
949   if (ShapeA.ShapeType()==TopAbs_EDGE ) {
950     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
951     
952     // Si ShapeB est un edge
953     if (ShapeB.ShapeType()==TopAbs_EDGE ) {
954       TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
955       BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB );
956       // on verifie qu'ils ne sont pas paralleles.
957       if (!myDeltaEdge.IsParallel() ) {di<<"vlenghtdim error: non parallel edges."<<"\n";return 1; }
958       
959       // On saisit la distance et on l'arrondit!
960       theDist=Round (sqrt(myDeltaEdge.SquareDistance(1))*10. )/10.;
961       
962       // On recupere 3 Points des edges pour construire un plane.
963       TopoDS_Vertex  Va,Vb,Vc,Vd;
964       TopExp::Vertices(EdgeA,Va,Vb);
965       TopExp::Vertices(EdgeB,Vc,Vd);
966       gp_Pnt A=BRep_Tool::Pnt(Va);
967       gp_Pnt B=BRep_Tool::Pnt(Vb);
968       gp_Pnt C=BRep_Tool::Pnt(Vc);
969       
970       // Creation du Plane contenant la relation.
971       GC_MakePlane MkPlane(A,B,C);
972       Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
973       
974       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
975       
976       // On ferme le contexte local.
977       TheAISContext()->CloseLocalContext(myCurrentIndex);
978       
979       // on construit l'AISLenghtDimension.
980       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeA,EdgeB,theGeomPlane,theDist,TheMessage_Str );
981       TheAISContext()->Display(myLenghtDim );
982       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
983     }
984     
985     // Si ShapeB est un vertex.
986     else if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
987       
988       TopoDS_Vertex  VertexB=TopoDS::Vertex(ShapeB);
989       BRepExtrema_ExtPC myDeltaEdgeVertex  (VertexB ,EdgeA );
990       
991       // On saisit la distance et on l'arrondit!
992       theDist=Round (sqrt (myDeltaEdgeVertex.SquareDistance(1))*10. )/10.;
993       
994       // On recupere 2 Points de EdgeA pour construire un plane.
995       TopoDS_Vertex  Va,Vb;
996       TopExp::Vertices(EdgeA,Va,Vb);
997       gp_Pnt A=BRep_Tool::Pnt(Va);
998       gp_Pnt B=BRep_Tool::Pnt(Vb);
999       gp_Pnt C=BRep_Tool::Pnt(VertexB);
1000       
1001       GC_MakePlane MkPlane(A,B,C);
1002       Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1003       
1004       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1005       TheAISContext()->CloseLocalContext(myCurrentIndex);
1006       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeA,VertexB,theGeomPlane,theDist,TheMessage_Str );
1007       TheAISContext()->Display(myLenghtDim );
1008       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1009       
1010       
1011     }
1012     
1013     // Si ShapeB est une Face
1014     else {
1015       
1016       TopoDS_Face FaceB=TopoDS::Face(ShapeB);
1017       BRepExtrema_ExtCF myDeltaEdgeFace  (EdgeA,FaceB );
1018       // On verifie que l'edge est bien parallele a la face.
1019       if (!myDeltaEdgeFace.IsParallel() ) {di<<"vdistdim error: the edge isn't parallel to the face;can't compute the distance. "<<"\n";return 1; }
1020       
1021       // On saisit la distance et on l'arrondit!
1022       theDist=Round (sqrt (myDeltaEdgeFace.SquareDistance(1))*10. )/10.;
1023       
1024       // Construction du texte.
1025       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1026       
1027       // on construit l'AISLenghtDimension.
1028       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceB,EdgeA,theDist,TheMessage_Str );
1029       TheAISContext()->Display(myLenghtDim );
1030       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1031       
1032     }
1033     
1034   }
1035   
1036   // ShapeA est un vertex
1037   // ====================
1038   if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1039     TopoDS_Vertex  VertexA=TopoDS::Vertex(ShapeA);
1040     
1041     // Si ShapeB est un edge.
1042     if (ShapeB.ShapeType()==TopAbs_EDGE ) {
1043       TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
1044       BRepExtrema_ExtPC myDeltaEdgeVertex  (VertexA ,EdgeB );
1045       // On saisit la distance et on l'arrondit!
1046       theDist=Round (sqrt (myDeltaEdgeVertex.SquareDistance(1))*10. )/10.;
1047       
1048       // On recupere 2 Points de EdgeB pour construire un plane.
1049       TopoDS_Vertex  Va,Vb;
1050       TopExp::Vertices(EdgeB,Va,Vb);
1051       gp_Pnt A=BRep_Tool::Pnt(Va);
1052       gp_Pnt B=BRep_Tool::Pnt(Vb);
1053       gp_Pnt C=BRep_Tool::Pnt(VertexA);
1054       
1055       // Creation du Plane contenant la relation.
1056       GC_MakePlane MkPlane(A,B,C);
1057       Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1058       
1059       // Fermeture du contexte local.
1060       TheAISContext()->CloseLocalContext(myCurrentIndex);
1061       // Construction du texte.
1062       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1063       
1064       // on construit l'AISLenghtDimension.
1065       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (EdgeB,VertexA,theGeomPlane,theDist,TheMessage_Str );
1066       TheAISContext()->Display(myLenghtDim );
1067       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1068       
1069     }
1070     
1071     // Si ShapeB est un vertex.
1072     else if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
1073       TopoDS_Vertex  VertexB=TopoDS::Vertex(ShapeB);
1074       BRepExtrema_DistShapeShape myDeltaVertexVertex  (VertexA ,VertexB );
1075       // On saisit la distance et on l'arrondit!
1076       theDist=Round (myDeltaVertexVertex.Value()*10. )/10.;
1077       
1078       // Les deux premiers points.
1079       gp_Pnt A=BRep_Tool::Pnt(VertexA);
1080       gp_Pnt B=BRep_Tool::Pnt(VertexB);
1081       gp_Pnt C(B.X()+10,B.Y()+10,B.Z()+10);
1082
1083       GC_MakePlane MkPlane(A,B,C);
1084       Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1085       
1086       // Fermeture du contexte local.
1087       TheAISContext()->CloseLocalContext(myCurrentIndex);
1088       // Construction du texte.
1089       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1090       
1091       // on construit l'AISLenghtDimension.
1092       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexA,VertexB,theGeomPlane,theDist,TheMessage_Str );
1093       TheAISContext()->Display(myLenghtDim );
1094       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1095       
1096       
1097       
1098       
1099     }
1100     
1101     // Si ShapeB est une Face
1102     else {
1103       
1104       TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1105       BRepExtrema_ExtPF myDeltaVertexFace  (VertexA ,FaceB );
1106       // On saisit la distance et on l'arrondit!
1107       theDist=Round (sqrt (myDeltaVertexFace.SquareDistance(1))*10. )/10.;
1108       
1109       // Premier point.
1110       gp_Pnt A=BRep_Tool::Pnt(VertexA);
1111       
1112       // On recupere 1 edge de FaceB.
1113       TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE);
1114       TopoDS_Edge EdFromB=TopoDS::Edge(FaceExp.Current() );
1115       // On recupere les deux vertexes extremites de l'edge de face B
1116       TopoDS_Vertex  Vb,Vc;
1117       TopExp::Vertices(EdFromB,Vb,Vc);
1118 #ifdef DEB
1119       gp_Pnt B=
1120 #endif
1121                BRep_Tool::Pnt(Vb);
1122       gp_Pnt C=BRep_Tool::Pnt(Vc);
1123       
1124       // On projette le point B sur la Face car il 
1125       // n'existe pas de constructeurs AIS_LD PointFace
1126       // on est donc oblige de creer un nouveau TopoDS_Vertex.
1127       gp_Pnt theProjA=myDeltaVertexFace.Point(1);
1128       BRepBuilderAPI_MakeVertex theVertexMaker(theProjA);
1129       TopoDS_Vertex VertexAproj=theVertexMaker.Vertex();
1130       // Creation du Plane contenant la relation.
1131       GC_MakePlane MkPlane(A,theProjA,C);
1132       Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1133       
1134       // Fermeture du contexte local.
1135       TheAISContext()->CloseLocalContext(myCurrentIndex);
1136       // Construction du texte.
1137       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1138       
1139       // on construit l'AISLenghtDimension.
1140       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexA,VertexAproj,theGeomPlane,theDist,TheMessage_Str );
1141       TheAISContext()->Display(myLenghtDim );
1142       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1143       
1144     }
1145     
1146     
1147     
1148   }
1149   
1150   // ShapeA est une Face
1151   // ===================
1152   else {
1153     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1154     // Si ShapeB est un edge.
1155     if (ShapeB.ShapeType()==TopAbs_EDGE ) {
1156       TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1157       BRepExtrema_ExtCF myDeltaEdgeFace  (EdgeB,FaceA );
1158       // On verifie que l'edge est bien parallele a la face.
1159       if (!myDeltaEdgeFace.IsParallel() ) {di<<"vdistdim error: the edge isn't parallel to the face;can't compute the distance. "<<"\n";return 1; }
1160       
1161       // On saisit la distance et on l'arrondit!
1162       theDist=Round (sqrt (myDeltaEdgeFace.SquareDistance(1))*10. )/10.;
1163       
1164       // Construction du texte.
1165       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1166       
1167       // on construit l'AISLenghtDimension.
1168       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceA,EdgeB,theDist,TheMessage_Str );
1169       TheAISContext()->Display(myLenghtDim );
1170       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1171       
1172     }
1173     
1174     // Si ShapeB est un vertex.
1175     else if (ShapeB.ShapeType()==TopAbs_VERTEX ) {
1176       
1177       TopoDS_Vertex  VertexB=TopoDS::Vertex(ShapeB);
1178       BRepExtrema_ExtPF myDeltaVertexFace  (VertexB ,FaceA );
1179       // On saisit la distance et on l'arrondit!
1180       theDist=Round (sqrt (myDeltaVertexFace.SquareDistance(1))*10. )/10.;
1181       
1182       // Premier point.
1183       gp_Pnt B=BRep_Tool::Pnt(VertexB);
1184       
1185       // On recupere 1 edge de FaceA.
1186       TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
1187       TopoDS_Edge EdFromA=TopoDS::Edge(FaceExp.Current() );
1188       // On recupere les deux vertexes extremites de l'edge de face A
1189       TopoDS_Vertex  Va,Vc;
1190       TopExp::Vertices(EdFromA,Va,Vc);
1191       gp_Pnt A=BRep_Tool::Pnt(Va);
1192 #ifdef DEB
1193       gp_Pnt C=
1194 #endif
1195                BRep_Tool::Pnt(Vc);
1196
1197       // On projette le point B sur la Face car il 
1198       // n'existe pas de constructeurs AIS_LD PointFace
1199       // on est donc oblige de creer un nouveau TopoDS_Vertex.
1200       gp_Pnt theProjB=myDeltaVertexFace.Point(1);
1201       BRepBuilderAPI_MakeVertex theVertexMaker(theProjB);
1202       TopoDS_Vertex VertexBproj=theVertexMaker.Vertex();
1203       // Creation du Plane contenant la relation.
1204       GC_MakePlane MkPlane(A,B,theProjB);
1205       Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1206       
1207       // Fermeture du contexte local.
1208       TheAISContext()->CloseLocalContext(myCurrentIndex);
1209       // Construction du texte.
1210       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1211       
1212       // on construit l'AISLenghtDimension mais en utilisant le constructeur Vertex Vertex.
1213       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (VertexB,VertexBproj,theGeomPlane,theDist,TheMessage_Str );
1214       TheAISContext()->Display(myLenghtDim );
1215       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1216       
1217     }
1218     
1219     // Si ShapeB est une Face
1220     else {
1221       
1222       TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1223       BRepExtrema_ExtFF myDeltaFaceFace  (FaceA ,FaceB );
1224       // On verifie que les deux faces sont bien parelles.
1225       if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1226       
1227       // On saisit la distance et on l'arrondit!
1228       theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.;
1229       // Fermeture du contexte local.
1230       TheAISContext()->CloseLocalContext(myCurrentIndex);
1231       // Construction du texte.
1232       TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("d=")+TCollection_ExtendedString(theDist ) );
1233       
1234       // on construit l'AISLenghtDimension.
1235       Handle(AIS_LengthDimension ) myLenghtDim=new AIS_LengthDimension (FaceA,FaceB,theDist,TheMessage_Str );
1236       TheAISContext()->Display(myLenghtDim );
1237       GetMapOfAIS().Bind (myLenghtDim ,argv[1]);
1238       
1239     }
1240     
1241   }
1242   
1243   
1244   
1245   return 0;
1246   
1247 }
1248
1249
1250 //==============================================================================
1251 //function : VRadiusDim
1252 //purpose  : Display the radius dimension of a face or an edge.
1253 //Draw arg : vradiusdim Name 
1254 //==============================================================================
1255 #include <AIS_RadiusDimension.hxx>
1256 #include <TCollection_ExtendedString.hxx>
1257 #include <BRepAdaptor_Curve.hxx>
1258 #include <gp_Circ.hxx>
1259
1260
1261 static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1262 {
1263   // Declarations
1264   Standard_Integer myCurrentIndex;
1265   Standard_Real theRadius;
1266     
1267   // Verification
1268   if (argc!=2) {di<<" vradiusdim error"<<"\n";return 1;}
1269   
1270   // Fermeture des contextes locaux
1271   TheAISContext()->CloseAllContexts();
1272   
1273   // Ouverture d'un contexte local et recuperation de son index.
1274   TheAISContext()->OpenLocalContext();
1275   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1276   
1277   // On active les modes de selections Edges et Faces.
1278   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1279   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1280   di<<" Select an circled edge or face."<<"\n";
1281   
1282   // Boucle d'attente waitpick.
1283   Standard_Integer argcc = 5;
1284   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1285   const char **argvv = (const char **) buff;
1286   while (ViewerMainLoop( argcc, argvv) ) { }
1287   // fin de la boucle
1288   
1289   TopoDS_Shape ShapeA;
1290   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1291     ShapeA = TheAISContext()->SelectedShape();
1292   }
1293   
1294   // Shape A est un edge.
1295   if (ShapeA.ShapeType()==TopAbs_EDGE  ) {
1296     
1297     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
1298     // Recuperation du rayon
1299     BRepAdaptor_Curve theCurve(TopoDS::Edge(ShapeA));
1300     if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vradiusdim error: the edge is not a circular one."<<"\n";return 1;}
1301     else {
1302       gp_Circ theGpCircle=theCurve.Circle();
1303       theRadius=theGpCircle.Radius();
1304       // On arrondit le rayon
1305       theRadius=Round (theRadius*10. )/10.;
1306     }
1307     
1308     // Construction du texte.
1309     TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("r=")+TCollection_ExtendedString(theRadius  ) );
1310     
1311     // Fermeture du contexte.
1312     TheAISContext()->CloseLocalContext(myCurrentIndex);
1313     
1314     // Construction de L'AIS_RadiusDimension.
1315     Handle (AIS_RadiusDimension) myRadDim= new AIS_RadiusDimension(ShapeA ,theRadius ,TheMessage_Str );
1316     GetMapOfAIS().Bind (myRadDim,argv[1]);
1317     TheAISContext()->Display(myRadDim );
1318     
1319     
1320   }
1321   
1322   // Shape A est une face
1323   else if (ShapeA.ShapeType()==TopAbs_FACE ) {
1324     
1325     // on recupere un edge de la face.
1326     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1327     // on explore.
1328     TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
1329     TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() );
1330     
1331     // Recuperation du rayon
1332     BRepAdaptor_Curve theCurve(EdgeFromA );
1333     if (theCurve.GetType()!=GeomAbs_Circle ) {di<<"vradiusdim error: the face is not a circular one."<<"\n";return 1;}
1334     else {
1335       gp_Circ theGpCircle=theCurve.Circle();
1336       theRadius=theGpCircle.Radius();
1337       // On arrondit le rayon
1338       theRadius=Round (theRadius*10. )/10.;
1339     }
1340     
1341     // Construction du texte.
1342     TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("r=")+TCollection_ExtendedString(theRadius  ) );
1343     
1344     // Fermeture du contexte.
1345     TheAISContext()->CloseLocalContext(myCurrentIndex);
1346     
1347     // Construction de L'AIS_RadiusDimension.
1348     Handle (AIS_RadiusDimension) myRadDim= new AIS_RadiusDimension(ShapeA ,theRadius ,TheMessage_Str );
1349     //Handle (AIS_MinRadiusDimension) myRadDim= new AIS_MinRadiusDimension(EdgeFromA ,theRadius ,TheMessage_Str );
1350     GetMapOfAIS().Bind (myRadDim,argv[1]);
1351     TheAISContext()->Display(myRadDim );
1352     
1353     
1354   }
1355   
1356   else {
1357     di<<" vradiusdim error: the selection of a face or an edge was expected."<<"\n";return 1;
1358   }
1359   
1360   return 0;
1361   
1362 }
1363
1364
1365
1366 //==============================================================================
1367 //function : VOffsetDim
1368 //purpose  : Display the offset dimension
1369 //Draw arg : voffsetdim Name 
1370 //==============================================================================
1371 #include <AIS_OffsetDimension.hxx>
1372 #include <TCollection_ExtendedString.hxx>
1373 #include <BRepExtrema_ExtFF.hxx>
1374
1375
1376 static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1377 {
1378   // Declarations
1379   Standard_Integer myCurrentIndex;
1380   Standard_Real    theDist;
1381   
1382   // Verification
1383   if (argc!=2) {di<<" voffsetdim error"<<"\n";return 1;}
1384   
1385   // Fermeture des contextes locaux
1386   TheAISContext()->CloseAllContexts();
1387   
1388   // Ouverture d'un contexte local et recuperation de son index.
1389   TheAISContext()->OpenLocalContext();
1390   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1391   
1392   // On active les modes de selections Faces.
1393   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1394   di<<" Select a face."<<"\n";
1395   
1396   // Boucle d'attente waitpick.
1397   Standard_Integer argcc = 5;
1398   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1399   const char **argvv = (const char **) buff;
1400   while (ViewerMainLoop( argcc, argvv) ) { }
1401   // fin de la boucle
1402   
1403   TopoDS_Shape ShapeA;
1404   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1405     ShapeA = TheAISContext()->SelectedShape();
1406   }
1407   
1408   di<<" Select a face."<<"\n";
1409   // Boucle d'attente waitpick.
1410   Standard_Integer argccc = 5;
1411   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1412   const char **argvvv = (const char **) bufff;
1413   while (ViewerMainLoop( argccc, argvvv) ) { }
1414   // fin de la boucle
1415   
1416   TopoDS_Shape ShapeB;
1417   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1418     ShapeB = TheAISContext()->SelectedShape();
1419   }
1420   
1421   
1422   // Shape A et B est une face
1423   if (ShapeA.ShapeType()==TopAbs_FACE && ShapeB.ShapeType()==TopAbs_FACE ) {
1424     
1425     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1426     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1427     
1428     BRepExtrema_ExtFF myDeltaFaceFace  (FaceA ,FaceB );
1429     // On verifie que les deux faces sont bien parelles.
1430     if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1431     
1432     // On saisit la distance et on l'arrondit!
1433     theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.;
1434     // Fermeture du contexte local.
1435     TheAISContext()->CloseLocalContext(myCurrentIndex);
1436     // Construction du texte.
1437     TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("offset=")+TCollection_ExtendedString(theDist ) );
1438     
1439     // on construit l'AIS_OffsetDimension
1440     Handle(AIS_OffsetDimension) myOffsetDim=new AIS_OffsetDimension (FaceA,FaceB,theDist,TheMessage_Str );
1441     TheAISContext()->Display(myOffsetDim );
1442     GetMapOfAIS().Bind (myOffsetDim ,argv[1]);
1443     
1444     
1445     
1446   }
1447   
1448   else {
1449     di<<" voffsetdim error: the selection of a face was expected."<<"\n";return 1;
1450   }
1451   
1452   return 0;
1453   
1454 }
1455
1456
1457
1458
1459 //==============================================================================
1460 //function : VParallel
1461 //purpose  : Display the parallel relation 
1462 //Draw arg : vparallel Name 
1463 //==============================================================================
1464 #include <AIS_ParallelRelation.hxx>
1465 #include <TCollection_ExtendedString.hxx>
1466 #include <BRepExtrema_ExtFF.hxx>
1467 #include <BRepExtrema_ExtCC.hxx>
1468 #include <GC_MakePlane.hxx>
1469 #include <BRepAdaptor_Curve.hxx>
1470 #include <TopExp_Explorer.hxx>
1471
1472
1473 static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1474 {
1475   // Declarations
1476   Standard_Integer myCurrentIndex;
1477  
1478   // Verification
1479   if (argc!=2) {di<<" vparallel error"<<"\n";return 1;}
1480   
1481   // Fermeture des contextes locaux
1482   TheAISContext()->CloseAllContexts();
1483   
1484   // Ouverture d'un contexte local et recuperation de son index.
1485   TheAISContext()->OpenLocalContext();
1486   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1487   
1488   // On active les modes de selections Edges.
1489   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1490   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1491   di<<" Select an edge or a face "<<"\n";
1492   
1493   // Boucle d'attente waitpick.
1494   Standard_Integer argcc = 5;
1495   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1496   const char **argvv = (const char **) buff;
1497   while (ViewerMainLoop( argcc, argvv) ) { }
1498   // fin de la boucle
1499   
1500   TopoDS_Shape ShapeA;
1501   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1502     ShapeA = TheAISContext()->SelectedShape();
1503   }
1504   
1505   // SahpeA est un edge.
1506   // ===================
1507   if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1508     
1509     // desactivation du mode face
1510     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1511     di<<" Select a second edge"<<"\n";
1512     // Boucle d'attente waitpick.
1513     Standard_Integer argccc = 5;
1514     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1515     const char **argvvv = (const char **) bufff;
1516     while (ViewerMainLoop( argccc, argvvv) ) { }
1517     // fin de la boucle
1518     
1519     TopoDS_Shape ShapeB;
1520     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1521       ShapeB = TheAISContext()->SelectedShape();
1522     }
1523     
1524     // recuperation des edges.
1525     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
1526     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
1527     BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB );
1528     // on verifie qu'ils ne sont pas paralleles.
1529     if (!myDeltaEdge.IsParallel() ) {di<<"vparallel error: non parallel edges."<<"\n";return 1; }
1530     
1531     
1532     // On recupere les  vertexes extremites des edge A et B.
1533     BRepAdaptor_Curve theCurveA(EdgeA);
1534     BRepAdaptor_Curve theCurveB(EdgeB);
1535     // On recupere 3 points A,B,C des  curves.
1536     gp_Pnt A=theCurveA.Value(0.1);
1537     gp_Pnt B=theCurveA.Value(0.9);
1538     gp_Pnt C=theCurveB.Value(0.5);
1539     
1540     // Construction du Geom_Plane
1541     GC_MakePlane MkPlane(A,B,C);
1542     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1543     // Fermeture du contexte local.
1544     TheAISContext()->CloseLocalContext(myCurrentIndex);
1545     // Construction de l'AIS_ParallelRelation
1546     Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(EdgeA ,EdgeB ,theGeomPlane );
1547     TheAISContext()->Display(myParaRelation );
1548     GetMapOfAIS().Bind (myParaRelation ,argv[1]);
1549     
1550     
1551   }
1552   
1553   // Shape A est une face
1554   // ====================
1555   else {
1556     
1557     // desactivation du mode edge
1558     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1559     di<<" Select a second edge"<<"\n";
1560     // Boucle d'attente waitpick.
1561     Standard_Integer argccc = 5;
1562     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1563     const char **argvvv = (const char **) bufff;
1564     while (ViewerMainLoop( argccc, argvvv) ) { }
1565     // fin de la boucle
1566     
1567     TopoDS_Shape ShapeB;
1568     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1569       ShapeB = TheAISContext()->SelectedShape();
1570     }
1571     
1572     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1573     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1574     
1575     BRepExtrema_ExtFF myDeltaFaceFace  (FaceA ,FaceB );
1576     // On verifie que les deux faces sont bien parelles.
1577     if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1578     
1579     // recuperation des edges des faces.
1580     TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1581     TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1582     
1583     TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
1584     TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
1585     
1586     // On recupere les  vertexes extremites des edge A et B.
1587     BRepAdaptor_Curve theCurveA(EdgeA);
1588     BRepAdaptor_Curve theCurveB(EdgeB);
1589     // On recupere 3 points A,B,C des  curves.
1590     gp_Pnt A=theCurveA.Value(0.1);
1591     gp_Pnt B=theCurveA.Value(0.9);
1592     gp_Pnt C=theCurveB.Value(0.5);
1593     
1594     // Construction du Geom_Plane
1595     GC_MakePlane MkPlane(A,B,C);
1596     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1597     // Fermeture du contexte local.
1598     TheAISContext()->CloseLocalContext(myCurrentIndex);
1599     // Construction de l'AIS_ParallelRelation
1600     Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(FaceA ,FaceB ,theGeomPlane );
1601     TheAISContext()->Display(myParaRelation );
1602     GetMapOfAIS().Bind (myParaRelation ,argv[1]);
1603     
1604     
1605     
1606   }
1607   
1608   
1609   return 0;
1610   
1611 }
1612
1613
1614
1615
1616 //==============================================================================
1617 //function : VPerpendicularRelation
1618 //purpose  : Display the Perpendicular Relation
1619 //Draw arg : vperpendicular Name 
1620 //==============================================================================
1621 #include <AIS_PerpendicularRelation.hxx>
1622 #include <TCollection_ExtendedString.hxx>
1623 #include <GC_MakePlane.hxx>
1624 #include <BRepAdaptor_Curve.hxx>
1625 #include <TopExp_Explorer.hxx>
1626
1627
1628
1629 static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1630 {
1631   // Declarations
1632   Standard_Integer myCurrentIndex;
1633  
1634   // Verification
1635   if (argc!=2) {di<<" vortho error"<<"\n";return 1;}
1636   
1637   // Fermeture des contextes locaux
1638   TheAISContext()->CloseAllContexts();
1639   
1640   // Ouverture d'un contexte local et recuperation de son index.
1641   TheAISContext()->OpenLocalContext();
1642   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1643   
1644   // On active les modes de selections Edges.
1645   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1646   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1647   di<<" Select an edge or a face "<<"\n";
1648   
1649   // Boucle d'attente waitpick.
1650   Standard_Integer argcc = 5;
1651   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1652   const char **argvv = (const char **) buff;
1653   while (ViewerMainLoop( argcc, argvv) ) { }
1654   // fin de la boucle
1655   
1656   TopoDS_Shape ShapeA;
1657   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1658     ShapeA = TheAISContext()->SelectedShape();
1659   }
1660   
1661   // ShapeA est un edge.
1662   // ===================
1663   if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1664     
1665     // desactivation du mode face
1666     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1667     di<<" Select a second edge"<<"\n";
1668     // Boucle d'attente waitpick.
1669     Standard_Integer argccc = 5;
1670     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1671     const char **argvvv = (const char **) bufff;
1672     while (ViewerMainLoop( argccc, argvvv) ) { }
1673     // fin de la boucle
1674     
1675     TopoDS_Shape ShapeB;
1676     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1677       ShapeB = TheAISContext()->SelectedShape();
1678     }
1679     
1680     // recuperation des edges.
1681     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
1682     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
1683     
1684     // On recupere les  curves
1685     BRepAdaptor_Curve theCurveA(EdgeA);
1686     BRepAdaptor_Curve theCurveB(EdgeB);
1687     // on verifie si les edges sont orthogonaux.
1688     //gp_Lin theLineA=theCurveA.Line();
1689     //gp_Lin theLineB=theCurveB.Line();
1690     //if (abs(theLineA.Angle(theLineB) ) != M_PI/2 ) {cout<<"vperpendicular error: Edges are not  othogonals."<<endl;return 1;}
1691     
1692     // On recupere 3 points A,B,C des  curves.
1693     gp_Pnt A=theCurveA.Value(0.1);
1694     gp_Pnt B=theCurveA.Value(0.9);
1695     gp_Pnt C=theCurveB.Value(0.5);
1696     // Construction du Geom_Plane
1697     GC_MakePlane MkPlane(A,B,C);
1698     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1699     // Fermeture du contexte local.
1700     TheAISContext()->CloseLocalContext(myCurrentIndex);
1701     // Construction de l'AIS_ParallelRelation
1702     Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation (EdgeA ,EdgeB ,theGeomPlane );
1703     TheAISContext()->Display(myOrthoRelation );
1704     GetMapOfAIS().Bind (myOrthoRelation ,argv[1]);
1705     
1706     
1707   }
1708   
1709   // Shape A est une face
1710   // ====================
1711   else {
1712     
1713     // desactivation du mode edge
1714     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1715     di<<" Select a second edge"<<"\n";
1716     // Boucle d'attente waitpick.
1717     Standard_Integer argccc = 5;
1718     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1719     const char **argvvv = (const char **) bufff;
1720     while (ViewerMainLoop( argccc, argvvv) ) { }
1721     // fin de la boucle
1722     
1723     TopoDS_Shape ShapeB;
1724     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1725       ShapeB = TheAISContext()->SelectedShape();
1726     }
1727     
1728     // pas de verification d'orthogonalite.
1729     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1730     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1731     
1732     // recuperation des edges des faces.
1733     TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1734     TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1735     
1736     TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
1737     TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
1738     
1739     // On recupere les  vertexes extremites des edge A et B.
1740     BRepAdaptor_Curve theCurveA(EdgeA);
1741     BRepAdaptor_Curve theCurveB(EdgeB);
1742     // On recupere 3 points A,B,C des  curves.
1743     gp_Pnt A=theCurveA.Value(0.1);
1744     gp_Pnt B=theCurveA.Value(0.9);
1745     gp_Pnt C=theCurveB.Value(0.5);
1746     // Construction du Geom_Plane
1747     GC_MakePlane MkPlane(A,B,C);
1748     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1749     // Fermeture du contexte local.
1750     TheAISContext()->CloseLocalContext(myCurrentIndex);
1751     // Construction de l'AIS_PerpendicularRelation
1752     Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation(FaceA ,FaceB );
1753     TheAISContext()->Display(myOrthoRelation );
1754     GetMapOfAIS().Bind (myOrthoRelation  ,argv[1]);
1755     
1756     
1757     
1758   }
1759   
1760   
1761   return 0;
1762   
1763 }
1764
1765
1766 //==============================================================================
1767 //function : VTangentRelation
1768 //purpose  : Display the tangent Relation
1769 //Draw arg : vtangent Name 
1770 //==============================================================================
1771 #include <AIS_TangentRelation.hxx>
1772
1773
1774 static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1775 {
1776   // Declarations
1777   Standard_Integer myCurrentIndex;
1778  
1779   // Verification
1780   if (argc!=2) {di<<" vtangent error"<<"\n";return 1;}
1781   
1782   // Fermeture des contextes locaux
1783   TheAISContext()->CloseAllContexts();
1784   
1785   // Ouverture d'un contexte local et recuperation de son index.
1786   TheAISContext()->OpenLocalContext();
1787   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1788   
1789   // On active les modes de selections Edges.
1790   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1791   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1792   di<<" Select two coplanar edges(First the circular edge then the tangent edge) or two faces "<<"\n";
1793   
1794   // Boucle d'attente waitpick.
1795   Standard_Integer argcc = 5;
1796   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1797   const char **argvv = (const char **) buff;
1798   while (ViewerMainLoop( argcc, argvv) ) { }
1799   // fin de la boucle
1800   
1801   TopoDS_Shape ShapeA;
1802   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1803     ShapeA = TheAISContext()->SelectedShape();
1804   }
1805   
1806   // ShapeA est un edge.
1807   // ===================
1808   if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1809     
1810     // desactivation du mode face
1811     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1812     di<<" Select a second edge"<<"\n";
1813     // Boucle d'attente waitpick.
1814     Standard_Integer argccc = 5;
1815     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1816     const char **argvvv = (const char **) bufff;
1817     while (ViewerMainLoop( argccc, argvvv) ) { }
1818     // fin de la boucle
1819     
1820     TopoDS_Shape ShapeB;
1821     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1822       ShapeB = TheAISContext()->SelectedShape();
1823     }
1824     
1825     // recuperation des edges.
1826     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
1827     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
1828     
1829     // On recupere les  curves
1830     BRepAdaptor_Curve theCurveA(EdgeA);
1831     BRepAdaptor_Curve theCurveB(EdgeB);
1832     
1833     // On recupere 3 points A,B,C des  curves.
1834     gp_Pnt A=theCurveA.Value(0.1);
1835     gp_Pnt B=theCurveA.Value(0.9);
1836     gp_Pnt C=theCurveB.Value(0.5);
1837
1838     // Construction du Geom_Plane
1839     GC_MakePlane MkPlane(A,B,C);
1840     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1841     // Fermeture du contexte local.
1842     TheAISContext()->CloseLocalContext(myCurrentIndex);
1843     // Construction de l'AIS_TangentRelation
1844     Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation  (EdgeA ,EdgeB ,theGeomPlane );
1845     TheAISContext()->Display(myTanRelation );
1846     GetMapOfAIS().Bind (myTanRelation ,argv[1]);
1847     
1848     
1849   }
1850   
1851   // Shape A est une face
1852   // ====================
1853   else {
1854     
1855     // desactivation du mode edge
1856     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
1857     di<<" Select a second edge"<<"\n";
1858     // Boucle d'attente waitpick.
1859     Standard_Integer argccc = 5;
1860     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1861     const char **argvvv = (const char **) bufff;
1862     while (ViewerMainLoop( argccc, argvvv) ) { }
1863     // fin de la boucle
1864     
1865     TopoDS_Shape ShapeB;
1866     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1867       ShapeB = TheAISContext()->SelectedShape();
1868     }
1869     
1870     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1871     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1872     
1873     // recuperation des edges des faces.
1874     TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
1875     TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
1876     
1877     TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
1878     TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
1879     
1880     // On recupere les  vertexes extremites des edge A et B.
1881     BRepAdaptor_Curve theCurveA(EdgeA);
1882     BRepAdaptor_Curve theCurveB(EdgeB);
1883     // On recupere 3 points A,B,C des  curves.
1884     gp_Pnt A=theCurveA.Value(0.1);
1885     gp_Pnt B=theCurveA.Value(0.9);
1886     gp_Pnt C=theCurveB.Value(0.5);
1887
1888     // Construction du Geom_Plane
1889     GC_MakePlane MkPlane(A,B,C);
1890     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1891     // Fermeture du contexte local.
1892     TheAISContext()->CloseLocalContext(myCurrentIndex);
1893     // Construction de l'AIS_PerpendicularRelation
1894     Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation(FaceA ,FaceB,theGeomPlane );
1895     TheAISContext()->Display(myTanRelation );
1896     GetMapOfAIS().Bind (myTanRelation  ,argv[1]);
1897     
1898     
1899     
1900   }
1901   
1902   
1903   return 0;
1904   
1905 }
1906
1907 //==============================================================================
1908 //function : VSymetricalRelation
1909 //purpose  : Display the Symetrical Relation
1910 //Draw arg : vsymetric Name 
1911 //==============================================================================
1912 #include <AIS_SymmetricRelation.hxx>
1913
1914
1915 static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1916 {
1917   // Declarations
1918   Standard_Integer myCurrentIndex;
1919  
1920   // Verification
1921   if (argc!=2) {di<<" vSymmetric error"<<"\n";return 1;}
1922   
1923   // Fermeture des contextes locaux
1924   TheAISContext()->CloseAllContexts();
1925   
1926   // Ouverture d'un contexte local et recuperation de son index.
1927   TheAISContext()->OpenLocalContext();
1928   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1929   
1930   // On active les modes de selections
1931   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1932   di<<" Select an edge:the axis of symetry "<<"\n";
1933   
1934   // Boucle d'attente waitpick.
1935   Standard_Integer argcc = 5;
1936   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1937   const char **argvv = (const char **) buff;
1938   while (ViewerMainLoop( argcc, argvv) ) { }
1939   // fin de la boucle
1940   
1941   TopoDS_Shape ShapeA;
1942   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1943     ShapeA = TheAISContext()->SelectedShape();
1944   }
1945   // recuperation des edges.
1946   TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
1947   
1948   // On active les modes de selections
1949   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1950   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1951   di<<" Select two edges or two vertices. "<<"\n";
1952   
1953   // Boucle d'attente waitpick.
1954   Standard_Integer argcc2 = 5;
1955 //  const char *buff2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1956   const char **argvv2 = (const char **) buff;
1957   while (ViewerMainLoop( argcc2, argvv2) ) { }
1958   // fin de la boucle
1959   
1960   TopoDS_Shape ShapeB;
1961   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1962     ShapeB = TheAISContext()->SelectedShape();
1963   }
1964   
1965   
1966   
1967   
1968   
1969   // ShapeB est un edge.
1970   // ===================
1971   if (ShapeB.ShapeType()==TopAbs_EDGE ) {
1972     
1973     // desactivation du mode vertex
1974     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
1975     di<<" Select a second edge"<<"\n";
1976     // Boucle d'attente waitpick.
1977     Standard_Integer argccc = 5;
1978     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1979     const char **argvvv = (const char **) bufff;
1980     while (ViewerMainLoop( argccc, argvvv) ) { }
1981     // fin de la boucle
1982     
1983     TopoDS_Shape ShapeC;
1984     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1985       ShapeC = TheAISContext()->SelectedShape();
1986     }
1987     
1988     // recuperation des edges.
1989     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
1990     TopoDS_Edge  EdgeC=TopoDS::Edge(ShapeC);
1991     // on verifie que les edges sont paralleles
1992     BRepExtrema_ExtCC myDeltaEdgeAB (EdgeA ,EdgeB );
1993     BRepExtrema_ExtCC myDeltaEdgeAC (EdgeA ,EdgeC );
1994     // on verifie qu'ils  sont paralleles.
1995     if (!myDeltaEdgeAB.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
1996     if (!myDeltaEdgeAC.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
1997     // on recupere les vertexs
1998     TopoDS_Vertex  Va,Vb,Vc,Vd;
1999     TopExp::Vertices(EdgeB,Va,Vb );
2000     TopExp::Vertices(EdgeC,Vc,Vd );
2001     gp_Pnt A=BRep_Tool::Pnt(Va);
2002     gp_Pnt B=BRep_Tool::Pnt(Vc);
2003     gp_Pnt C = Get3DPointAtMousePosition();
2004     
2005     //    gp_Pnt C=BRep_Tool::Pnt(Vc);
2006     // Construction du Geom_Plane
2007     GC_MakePlane MkPlane(A,B,C);
2008     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2009     // Fermeture du contexte local.
2010     TheAISContext()->CloseLocalContext(myCurrentIndex);
2011     // Construction de l'AIS_SymmetricRelation
2012     Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,EdgeB ,EdgeC, theGeomPlane );
2013     TheAISContext()->Display(mySymRelation );
2014     GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2015     
2016     
2017   }
2018   
2019   // Shape B est un vertex
2020   // =====================
2021   else {
2022     
2023     // desactivation du mode edge
2024     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2025     di<<" Select a second edge"<<"\n";
2026     // Boucle d'attente waitpick.
2027     Standard_Integer argccc = 5;
2028     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2029     const char **argvvv = (const char **) bufff;
2030     while (ViewerMainLoop( argccc, argvvv) ) { }
2031     // fin de la boucle
2032     
2033     TopoDS_Shape ShapeC;
2034     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2035       ShapeC = TheAISContext()->SelectedShape();
2036     }
2037     
2038     // recuperation des Vertex
2039     TopoDS_Vertex  VertexB=TopoDS::Vertex(ShapeB);
2040     TopoDS_Vertex  VertexC=TopoDS::Vertex(ShapeC);
2041     // transfo en gp_Pnt
2042     gp_Pnt B=BRep_Tool::Pnt(VertexB);
2043     gp_Pnt C=BRep_Tool::Pnt(VertexC);
2044     
2045     // on recupere les vertexes de l'axe de sym
2046     TopoDS_Vertex  Va,Vb;
2047     TopExp::Vertices(EdgeA,Va,Vb );
2048     gp_Pnt A=BRep_Tool::Pnt(Va);
2049     // Construction du Geom_Plane
2050     GC_MakePlane MkPlane(A,B,C);
2051     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2052     // Fermeture du contexte local.
2053     TheAISContext()->CloseLocalContext(myCurrentIndex);
2054     // Construction de l'AIS_SymmetricRelation
2055     Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,VertexB ,VertexC, theGeomPlane );
2056     TheAISContext()->Display(mySymRelation );
2057     GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2058     
2059     
2060     
2061   }
2062   
2063   
2064   return 0;
2065   
2066 }
2067 //=======================================================================
2068 //function : VMoveDim
2069 //purpose  : 
2070 //=======================================================================
2071 static int VMoveDim(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
2072 {
2073   if(argc>2) return 1;
2074   
2075   const Handle(V3d_View) aview = ViewerTest::CurrentView();
2076   Handle(AIS_InteractiveObject) pickedobj;
2077   if(argc==1){
2078     pickedobj = TheAISContext()->FirstCurrentObject();
2079     if(pickedobj.IsNull() || pickedobj->Type()!=AIS_KOI_Relation)
2080       pickedobj = ViewerTest::PickObject(AIS_KOI_Relation);
2081   }
2082   else{
2083     // reperage dans le viewer...
2084     if(!strcasecmp(argv[1],".")){
2085       pickedobj = ViewerTest::PickObject(AIS_KOI_Relation);
2086       
2087     }
2088     else if(GetMapOfAIS().IsBound2(argv[1]))
2089       pickedobj = Handle(AIS_InteractiveObject)::DownCast
2090         (GetMapOfAIS().Find2(argv[1]));
2091   }
2092   
2093   if(pickedobj.IsNull()){
2094     di<<"Bad Type Object"<<"\n";
2095     return 1 ;}
2096   
2097   if(pickedobj->Type() != AIS_KOI_Relation)
2098     return 1;
2099   Standard_Integer argccc = 5;
2100   
2101   const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2102   const char **argvvv = (const char **) bufff;
2103
2104   Handle(AIS_Relation) R = *((Handle(AIS_Relation)*)&pickedobj);
2105   Handle(Geom_Plane) ThePl;
2106 //  Standard_Real x,y,z,xv,yv,zv;
2107   Standard_Real x,y,xv,yv,zv;
2108   static Standard_Real last_xv(0),last_yv(0),last_zv(0);
2109   Standard_Integer xpix,ypix;
2110 //  Standard_Boolean SameAsLast(Standard_False);
2111   Select3D_Projector prj(aview);
2112   
2113   
2114   while (ViewerMainLoop( argccc, argvvv) ) {
2115     //....... la ligne de tir
2116     ViewerTest::GetMousePosition(xpix,ypix);
2117     aview->Convert(xpix,ypix,x,y); // espace reel 2D de la vue...
2118     gp_Lin L = prj.Shoot(x,y);
2119
2120     
2121     
2122     // ....... le plan de la vue...
2123     aview->Proj(xv,yv,zv);
2124     static Standard_Boolean haschanged(Standard_False);
2125     if(Abs(last_xv-xv)>Precision::Confusion() ||
2126        Abs(last_yv-yv)>Precision::Confusion() ||
2127        Abs(last_zv-zv)>Precision::Confusion() ){
2128       last_xv = xv;
2129       last_yv = yv;
2130       last_zv = zv;
2131       Standard_Real xat,yat,zat;
2132       aview->At(xat,yat,zat);
2133       ThePl = new Geom_Plane(gp_Pnt(xat,yat,zat),gp_Dir(xv,yv,zv));
2134       haschanged = Standard_True;
2135       di <<"changement de plan"<<"\n";
2136     }
2137     
2138     //  
2139 //    Standard_Integer xpix,ypix;
2140 //    Standard_Real x,y;
2141     gp_Pnt GoodPoint;
2142     if(haschanged){
2143       gp_Pln NewPlane;;
2144       ComputeNewPlaneForDim(R,NewPlane,GoodPoint);
2145       haschanged = Standard_False;
2146     }
2147     else{
2148       if(ComputeIntersection(L,ThePl->Pln(),GoodPoint)){
2149         R->SetPosition(GoodPoint);
2150       }
2151       TheAISContext()->Redisplay(R);
2152     }
2153   }
2154   
2155   return 0;
2156 }
2157 //=======================================================================
2158 //function : RelationsCommands
2159 //purpose  : 
2160 //=======================================================================
2161       
2162
2163 void ViewerTest::RelationCommands(Draw_Interpretor& theCommands)
2164 {
2165   const char *group = "AISRelations";
2166
2167   
2168   theCommands.Add("vangledim",
2169                   "vangledim Name:Selection in the viewer only ",
2170                   __FILE__,VAngleDimBuilder,group);
2171   
2172   theCommands.Add("vdiameterdim",
2173                   "vdiameterdim Name : Selection in the viewer only ",
2174                   __FILE__,VDiameterDimBuilder,group);
2175   
2176   theCommands.Add("vconcentric",
2177                   "vconcentric Name : Selection in the viewer only ",
2178                   __FILE__,VConcentricBuilder,group);
2179
2180   theCommands.Add("vequaldist",
2181                   "vequaldist Name Selection in the viewer only ",
2182                   __FILE__,VEqualDistRelation ,group);
2183   
2184   theCommands.Add("vequalrad",
2185                   "vequalrad Name Selection in the viewer only ",
2186                   __FILE__,VEqualRadiusRelation  ,group);
2187   
2188   theCommands.Add("vfix",  
2189                   "vfix Name Selection in the viewer only ",
2190                   __FILE__,VFixRelation  ,group);
2191   
2192   theCommands.Add("videntity",
2193                   "videntity Name Selection in the viewer only ",
2194                   __FILE__,VIdenticRelation  ,group);
2195   
2196   theCommands.Add("vdistdim",
2197                   "vdistdim Name Selection in the viewer only ",
2198                   __FILE__,VLenghtDimension ,group);
2199   
2200   theCommands.Add("vradiusdim",
2201                   "vradiusdim Name Selection in the viewer only ",
2202                   __FILE__,VRadiusDimBuilder ,group);
2203   
2204   theCommands.Add("voffsetdim",
2205                   "voffsetdim Name Selection in the viewer only ",
2206                   __FILE__,VOffsetDimBuilder ,group);
2207   
2208   theCommands.Add("vparallel",
2209                   "vparallel Name Selection in the viewer only ",
2210                   __FILE__,VParallelBuilder ,group);
2211   
2212   theCommands.Add("vortho",
2213                   "vortho Name Selection in the viewer only ",
2214                   __FILE__,VPerpendicularBuilder ,group);
2215   
2216   theCommands.Add("vtangent",  
2217                   "vtangent Name Selection in the viewer only ",
2218                   __FILE__,VTangentBuilder ,group);
2219   
2220   
2221   theCommands.Add("vsymetric",
2222                   "vsymetric Name Selection in the viewer only ",
2223                   __FILE__,VSymmetricBuilder ,group);
2224
2225   theCommands.Add("vmovedim",
2226                   "vmovedim [name] : move Mouse in the viewer; click MB1 to stop motion...",
2227                   __FILE__,VMoveDim,group);
2228
2229 }