0026586: Eliminate compile warnings obtained by building occt with vc14: declaration...
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <ViewerTest.hxx>
18
19 #include <AIS_AngleDimension.hxx>
20 #include <AIS_Circle.hxx>
21 #include <AIS_DiameterDimension.hxx>
22 #include <AIS_DisplayMode.hxx>
23 #include <AIS_InteractiveContext.hxx>
24 #include <AIS_LengthDimension.hxx>
25 #include <AIS_ListIteratorOfListOfInteractive.hxx>
26 #include <AIS_ListOfInteractive.hxx>
27 #include <AIS_MapOfInteractive.hxx>
28 #include <AIS_Point.hxx>
29 #include <AIS_RadiusDimension.hxx>
30 #include <AIS_Relation.hxx>
31 #include <AIS_Shape.hxx>
32 #include <BRepAdaptor_Curve.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRepTools.hxx>
36 #include <Draw_Interpretor.hxx>
37 #include <Draw.hxx>
38 #include <Draw_Appli.hxx>
39 #include <Draw_Window.hxx>
40 #include <DBRep.hxx>
41 #include <ElSLib.hxx>
42 #include <Font_FontMgr.hxx>
43 #include <GC_MakePlane.hxx>
44 #include <Geom_CartesianPoint.hxx>
45 #include <Geom_Circle.hxx>
46 #include <Geom_Line.hxx>
47 #include <Geom_Plane.hxx>
48 #include <GeomAPI_IntCS.hxx>
49 #include <gce_MakeLin.hxx>
50 #include <gce_MakePln.hxx>
51 #include <gp_Circ.hxx>
52 #include <gp_Pln.hxx>
53 #include <IntAna_IntConicQuad.hxx>
54 #include <IntAna_Quadric.hxx>
55 #include <Precision.hxx>
56 #include <StdSelect.hxx>
57 #include <TCollection_AsciiString.hxx>
58 #include <TCollection_ExtendedString.hxx>
59 #include <TColStd_MapOfInteger.hxx>
60 #include <TopAbs.hxx>
61 #include <TopAbs_ShapeEnum.hxx>
62 #include <TopExp.hxx>
63 #include <TopoDS.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Solid.hxx>
66 #include <TopoDS_Vertex.hxx>
67 #include <V3d_Viewer.hxx>
68 #include <V3d_View.hxx>
69 #include <V3d.hxx>
70 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
71 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
72 #include <ViewerTest_EventManager.hxx>
73
74 extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
75                                            const Handle(AIS_InteractiveObject)& theAISObj,
76                                            Standard_Boolean theReplaceIfExists = Standard_True);
77 extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
78 extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
79 extern Handle(AIS_InteractiveContext)& TheAISContext ();
80
81 #define VertexMask 0x01
82 #define EdgeMask 0x02
83 #define FaceMask 0x04
84
85 //=======================================================================
86 //function : Get3DPointAtMousePosition
87 //purpose  : Calculates the 3D points corresponding to the mouse position
88 //           in the plane of the view
89 //=======================================================================
90 static gp_Pnt Get3DPointAtMousePosition()
91 {
92   Handle(V3d_View) aView = ViewerTest::CurrentView();
93
94   Standard_Real xv,yv,zv;
95   aView->Proj (xv,yv,zv);
96   Standard_Real xat,yat,zat;
97   aView->At(xat,yat,zat);
98   gp_Pln aPlane (gp_Pnt(xat,yat,zat), gp_Dir(xv,yv,zv));
99   
100   Standard_Integer aPixX, aPixY;
101   Standard_Real aX, aY, aZ, aDX, aDY, aDZ;
102
103   ViewerTest::GetMousePosition (aPixX, aPixY);
104   aView->ConvertWithProj (aPixX, aPixY, aX, aY, aZ, aDX, aDY, aDZ);
105   gp_Lin aLine( gp_Pnt(aX, aY, aZ), gp_Dir(aDX, aDY, aDZ) );
106
107   // Compute intersection
108   Handle(Geom_Line) aGeomLine = new Geom_Line (aLine);
109   Handle(Geom_Plane) aGeomPlane = new Geom_Plane (aPlane);
110   GeomAPI_IntCS anIntersector (aGeomLine, aGeomPlane);
111   if (!anIntersector.IsDone() || anIntersector.NbPoints() == 0)
112   {
113     return gp::Origin();
114   }
115   return anIntersector.Point (1);
116 }
117
118 //=======================================================================
119 //function : Get3DPointAtMousePosition
120 //purpose  : Calculates the 3D points corresponding to the mouse position
121 //           in the plane of the view
122 //=======================================================================
123 static Standard_Boolean Get3DPointAtMousePosition (const gp_Pnt& theFirstPoint,
124                                                    const gp_Pnt& theSecondPoint,
125                                                    gp_Pnt& theOutputPoint)
126 {
127   theOutputPoint = gp::Origin();
128
129   Handle(V3d_View) aView = ViewerTest::CurrentView();
130
131   Standard_Integer aPixX, aPixY;
132   Standard_Real aX, aY, aZ, aDx, aDy, aDz, aUx, aUy, aUz;
133
134   // Get 3D point in view coordinates and projection vector from the pixel point.
135   ViewerTest::GetMousePosition (aPixX, aPixY);
136   aView->ConvertWithProj (aPixX, aPixY, aX, aY, aZ, aDx, aDy, aDz);
137   gp_Lin aProjLin (gp_Pnt(aX, aY, aZ), gp_Dir(aDx, aDy, aDz));
138
139   // Get plane
140   gp_Vec aDimVec (theFirstPoint, theSecondPoint);
141   aView->Up (aUx, aUy, aUz);
142   gp_Vec aViewUp (aUx, aUy, aUz);
143
144   if (aDimVec.IsParallel (aViewUp, Precision::Angular()))
145   {
146     theOutputPoint = Get3DPointAtMousePosition();
147     return Standard_True;
148   }
149
150   gp_Vec aDimNormal = aDimVec ^ aViewUp;
151   gp_Pln aViewPlane= gce_MakePln (theFirstPoint, aDimNormal);
152
153   // Get intersection of view plane and projection line
154   Handle(Geom_Plane) aPlane = new Geom_Plane (aViewPlane);
155   Handle(Geom_Line) aProjLine = new Geom_Line (aProjLin);
156   GeomAPI_IntCS anIntersector (aProjLine, aPlane);
157   if (!anIntersector.IsDone() || anIntersector.NbPoints() == 0)
158   {
159     return Standard_False;
160   }
161
162   theOutputPoint = anIntersector.Point (1);
163   return Standard_True;
164 }
165
166 //=======================================================================
167 //function : ParseDimensionParams
168 //purpose  : Auxilliary function: sets aspect parameters for
169 //           length, angle, radius and diameter dimension.
170 //
171 //draw args: -text [3d|2d] [wf|sh|wireframe|shading] [Size]
172 //           -label [left|right|hcenter|hfit] [top|bottom|vcenter|vfit]
173 //           -arrow [external|internal|fit] [Length(int)]
174 //           -arrowangle ArrowAngle(degrees)
175 //           -plane xoy|yoz|zox
176 //           -flyout FloatValue -extension FloatValue
177 //           -value CustomNumberValue
178 //           -dispunits DisplayUnitsString
179 //           -modelunits ModelUnitsString
180 //           -showunits
181 //           -hideunits
182 //
183 // Warning! flyout is not an aspect value, it is for dimension parameter
184 // likewise text position, but text position override other paramaters.
185 // For text position changing use 'vmovedim'.
186 //=======================================================================
187 static int ParseDimensionParams (Standard_Integer  theArgNum,
188                                  const char**      theArgVec,
189                                  Standard_Integer  theStartIndex,
190                                  const Handle(Prs3d_DimensionAspect)& theAspect,
191                                  Standard_Boolean& theIsCustomPlane, gp_Pln& thePlane,
192                                  NCollection_DataMap<TCollection_AsciiString, Standard_Real>& theRealParams,
193                                  NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>& theStringParams,
194                                  NCollection_List<Handle(AIS_InteractiveObject)>* theShapeList = NULL)
195 {
196   theRealParams.Clear();
197   theStringParams.Clear();
198
199   theIsCustomPlane  = Standard_False;
200
201   // Begin from the second parameter: the first one is dimension name
202   for (Standard_Integer anIt = theStartIndex; anIt < theArgNum; ++anIt)
203   {
204     TCollection_AsciiString aParam (theArgVec[anIt]);
205     aParam.LowerCase();
206
207     if (aParam.Search ("-") == -1)
208     {
209       continue;
210     }
211
212     // Boolean flags
213     if (aParam.IsEqual ("-showunits"))
214     {
215       theAspect->MakeUnitsDisplayed (Standard_True);
216       continue;
217     }
218     else if (aParam.IsEqual ("-hideunits"))
219     {
220       theAspect->MakeUnitsDisplayed (Standard_False);
221       continue;
222     }
223
224     // Before all non-boolean flags parsing check if a flag have at least one value.
225     if (anIt + 1 >= theArgNum)
226     {
227       std::cerr << "Error: "<< aParam <<" flag should have value.\n";
228       return 1;
229     }
230
231     // Non-boolean flags
232     if (aParam.IsEqual ("-shape")
233      || aParam.IsEqual ("-shapes"))
234     {
235       if (!theShapeList)
236       {
237         std::cerr << "Error: unknown parameter '" << aParam << "'\n";
238         return 1;
239       }
240
241       do
242       {
243         anIt++;
244         TCollection_AsciiString anArgString = theArgVec[anIt];
245         Handle(AIS_InteractiveObject) anAISObject;
246         Standard_CString aStr   = anArgString.ToCString();
247         TopoDS_Shape     aShape =  DBRep::Get (aStr);
248         if (!aShape.IsNull())
249         {
250           anAISObject = new AIS_Shape (aShape);
251         }
252         else
253         {
254           if (!GetMapOfAIS().IsBound2 (anArgString))
255           {
256             std::cerr << "Error: shape with name '" << aStr << "' is not found.\n";
257             return 1;
258           }
259
260           anAISObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString));
261           if (anAISObject.IsNull())
262           {
263             std::cerr << "Error: " << aStr <<" is not a shape.\n";
264             return 1;
265           }
266         }
267         theShapeList->Append (anAISObject);
268       }
269       while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
270     }
271     else if (aParam.IsEqual ("-text"))
272     {
273       do
274       {
275         anIt++;
276         TCollection_AsciiString aValue (theArgVec[anIt]);
277         aValue.LowerCase();
278         if (aValue.IsEqual ("3d"))
279         {
280           theAspect->MakeText3d (Standard_True);
281         }
282         else if (aValue.IsEqual ("2d"))
283         {
284           theAspect->MakeText3d (Standard_False);
285         }
286         else if (aValue.IsEqual ("wf") || aValue.IsEqual ("wireframe"))
287         {
288            theAspect->MakeTextShaded (Standard_False);
289         }
290         else if ( aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
291         {
292           theAspect->MakeTextShaded (Standard_True);
293         }
294         else if (aValue.IsIntegerValue()) // text size
295         {
296           theAspect->TextAspect()->SetHeight (Draw::Atoi (aValue.ToCString()));
297         }
298       }
299       while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
300     }
301     else if (aParam.IsEqual ("-font"))
302     {
303       if (anIt + 1 >= theArgNum)
304       {
305         std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
306         return 1;
307       }
308
309       theAspect->TextAspect()->SetFont (theArgVec[++anIt]);
310     }
311     else if (aParam.IsEqual ("-label"))
312     {
313       do
314       {
315         anIt++;
316         TCollection_AsciiString aParamValue (theArgVec[anIt]);
317         aParamValue.LowerCase();
318
319         if (aParamValue == "left")         { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Left);  }
320         else if (aParamValue == "right")   { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Right); }
321         else if (aParamValue == "hcenter") { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Center);}
322         else if (aParamValue == "hfit")    { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Fit);   }
323         else if (aParamValue == "above")   { theAspect->SetTextVerticalPosition   (Prs3d_DTVP_Above); }
324         else if (aParamValue == "below")   { theAspect->SetTextVerticalPosition   (Prs3d_DTVP_Below); }
325         else if (aParamValue == "vcenter") { theAspect->SetTextVerticalPosition   (Prs3d_DTVP_Center);}
326         else
327         {
328           std::cerr << "Error: invalid label position: '" << aParamValue << "'.\n";
329           return 1;
330         }
331       }
332       while (anIt + 1 < theArgNum && theArgVec[anIt+1][0] != '-');
333     }
334     else if (aParam.IsEqual ("-arrow"))
335     {
336       TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
337       aLocalParam.LowerCase();
338
339       if (aLocalParam == "external") { theAspect->SetArrowOrientation (Prs3d_DAO_External); }
340       if (aLocalParam == "internal") { theAspect->SetArrowOrientation (Prs3d_DAO_Internal); }
341       if (aLocalParam == "fit")      { theAspect->SetArrowOrientation (Prs3d_DAO_Fit); }
342     }
343     else if (aParam.IsEqual ("-arrowlength") || aParam.IsEqual ("-arlen"))
344     {
345       TCollection_AsciiString aValue (theArgVec[++anIt]);
346       if (!aValue.IsRealValue())
347       {
348         std::cerr << "Error: arrow lenght should be float degree value.\n";
349         return 1;
350       }
351       theAspect->ArrowAspect()->SetLength (Draw::Atof (aValue.ToCString()));
352     }
353     else if (aParam.IsEqual ("-arrowangle") || aParam.IsEqual ("-arangle"))
354     {
355       TCollection_AsciiString aValue (theArgVec[++anIt]);
356       if (!aValue.IsRealValue())
357       {
358         std::cerr << "Error: arrow angle should be float degree value.\n";
359         return 1;
360       }
361       theAspect->ArrowAspect()->SetAngle (Draw::Atof (aValue.ToCString()));
362     }
363     else if (aParam.IsEqual ("-color"))
364     {
365       theAspect->SetCommonColor (Quantity_Color (ViewerTest::GetColorFromName (theArgVec[++anIt])));
366     }
367     else if (aParam.IsEqual ("-extension"))
368     {
369       TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
370       if (!aLocalParam.IsRealValue())
371       {
372         std::cerr << "Error: extension size for dimension should be real value.\n";
373         return 1;
374       }
375       theAspect->SetExtensionSize (Draw::Atof (aLocalParam.ToCString()));
376     }
377     else if (aParam.IsEqual ("-plane"))
378     {
379       TCollection_AsciiString aValue (theArgVec[++anIt]);
380       aValue.LowerCase();
381       if (aValue == "xoy")
382       {
383         theIsCustomPlane = Standard_True;
384         thePlane = gp_Pln (gp_Ax3 (gp::XOY()));
385       }
386       else if (aValue == "zox")
387       {
388         theIsCustomPlane = Standard_True;
389         thePlane = gp_Pln (gp_Ax3 (gp::ZOX()));
390       }
391       else if (aValue == "yoz")
392       {
393         theIsCustomPlane = Standard_True;
394         thePlane = gp_Pln (gp_Ax3 (gp::YOZ()));
395       }
396       else
397       {
398         std::cerr << "Error: wrong plane '" << aValue << "'.\n";
399         return 1;
400       }
401     }
402     else if (aParam.IsEqual ("-flyout"))
403     {
404       TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
405       if (!aLocalParam.IsRealValue())
406       {
407         std::cerr << "Error: flyout for dimension should be real value.\n";
408         return 1;
409       }
410
411       theRealParams.Bind ("flyout", Draw::Atof (aLocalParam.ToCString()));
412     }
413     else if (aParam.IsEqual ("-value"))
414     {
415       TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
416       if (!aLocalParam.IsRealValue())
417       {
418         std::cerr << "Error: dimension value for dimension should be real value.\n";
419         return 1;
420       }
421
422       theRealParams.Bind ("value", Draw::Atof (aLocalParam.ToCString()));
423     }
424     else if (aParam.IsEqual ("-modelunits"))
425     {
426       TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
427
428       theStringParams.Bind ("modelunits", aLocalParam);
429     }
430     else if (aParam.IsEqual ("-dispunits"))
431     {
432       TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
433
434       theStringParams.Bind ("dispunits", aLocalParam);
435     }
436     else
437     {
438       std::cerr << "Error: unknown parameter '" << aParam << "'.\n";
439       return 1;
440     }
441   }
442
443   return 0;
444 }
445
446 //=======================================================================
447 //function : SetDimensionParams
448 //purpose  : Sets parameters for dimension
449 //=======================================================================
450 static void SetDimensionParams (const Handle(AIS_Dimension)& theDim,
451                                 const NCollection_DataMap<TCollection_AsciiString, Standard_Real>& theRealParams,
452                                 const NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString>& theStringParams)
453 {
454   if (theRealParams.IsBound ("flyout"))
455   {
456     theDim->SetFlyout (theRealParams.Find ("flyout"));
457   }
458
459   if (theRealParams.IsBound ("value"))
460   {
461     theDim->SetCustomValue (theRealParams.Find ("value"));
462   }
463
464   if (theStringParams.IsBound ("modelunits"))
465   {
466     theDim->SetModelUnits (theStringParams.Find ("modelunits"));
467   }
468
469   if (theStringParams.IsBound ("dispunits"))
470   {
471     theDim->SetDisplayUnits (theStringParams.Find ("dispunits"));
472   }
473 }
474
475 //=======================================================================
476 //function : VDimBuilder
477 //purpose  : Command for building dimension presentations: angle,
478 //           length, radius, diameter
479 //=======================================================================
480 static int VDimBuilder (Draw_Interpretor& /*theDi*/,
481                         Standard_Integer  theArgsNb,
482                         const char**      theArgs)
483 {
484   if (theArgsNb < 2)
485   {
486     std::cerr << "Error: wrong number of arguments.\n";
487     return 1;
488   }
489
490   // Parse parameters
491   TCollection_AsciiString aName (theArgs[1]);
492
493   NCollection_List<Handle(AIS_InteractiveObject)> aShapes;
494   Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect;
495   Standard_Boolean isPlaneCustom = Standard_False;
496   gp_Pln aWorkingPlane;
497
498   NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
499   NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
500
501   TCollection_AsciiString aDimType(theArgs[2]);
502   aDimType.LowerCase();
503   AIS_KindOfDimension aKindOfDimension;
504   if (aDimType == "-length")
505   {
506     aKindOfDimension = AIS_KOD_LENGTH;
507   }
508   else if (aDimType == "-angle")
509   {
510     aKindOfDimension = AIS_KOD_PLANEANGLE;
511   }
512   else if (aDimType == "-radius")
513   {
514     aKindOfDimension = AIS_KOD_RADIUS;
515   }
516   else if (aDimType == "-diameter" || aDimType == "-diam")
517   {
518     aKindOfDimension = AIS_KOD_DIAMETER;
519   }
520   else
521   {
522     std::cerr << "Error: wrong type of dimension.\n";
523     return 1;
524   }
525
526
527   if (ParseDimensionParams (theArgsNb, theArgs, 3,
528                             anAspect,isPlaneCustom,aWorkingPlane,
529                             aRealParams, aStringParams, &aShapes))
530   {
531     return 1;
532   }
533
534   // Build dimension
535   Handle(AIS_Dimension) aDim;
536   switch (aKindOfDimension)
537   {
538     case AIS_KOD_LENGTH:
539     {
540       if (!isPlaneCustom)
541       {
542         std::cerr << theArgs[0] << ": can not build dimension without working plane.\n";
543         return 1;
544       }
545       if (aShapes.Extent() == 1)
546       {
547         if (aShapes.First()->Type() == AIS_KOI_Shape
548           && (Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape().ShapeType() != TopAbs_EDGE)
549         {
550           std::cerr << theArgs[0] << ": wrong shape type.\n";
551           return 1;
552         }
553         // Adjust working plane
554         TopoDS_Edge anEdge = TopoDS::Edge ((Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape());
555         TopoDS_Vertex aFirst, aSecond;
556         TopExp::Vertices (anEdge, aFirst, aSecond);
557         aDim = new AIS_LengthDimension (anEdge, aWorkingPlane);
558
559         // Move standard plane (XOY, YOZ or ZOX) to the first point to make it working for dimension
560         aWorkingPlane.SetLocation (Handle(AIS_LengthDimension)::DownCast (aDim)->FirstPoint());
561       }
562       else if (aShapes.Extent() == 2)
563       {
564         TopoDS_Shape aShape1, aShape2;
565
566         // Getting shapes
567         if (aShapes.First()->DynamicType() == STANDARD_TYPE (AIS_Point))
568         {
569           Handle(AIS_Point) aPoint1 = Handle(AIS_Point)::DownCast (aShapes.First ());
570           aShape1 = aPoint1->Vertex();
571         }
572         else if (aShapes.First()->Type() == AIS_KOI_Shape)
573         {
574           aShape1 = (Handle(AIS_Shape)::DownCast (aShapes.First()))->Shape();
575         }
576
577         if (aShapes.Last()->DynamicType() == STANDARD_TYPE (AIS_Point))
578         {
579           Handle(AIS_Point) aPoint2 = Handle(AIS_Point)::DownCast (aShapes.Last ());
580           aShape2 = aPoint2->Vertex();
581         }
582         else if (aShapes.Last()->Type() == AIS_KOI_Shape)
583         {
584           aShape2 = (Handle(AIS_Shape)::DownCast (aShapes.Last()))->Shape();
585         }
586
587         if (aShape1.IsNull() || aShape2.IsNull())
588         {
589           std::cerr << theArgs[0] << ": wrong shape type.\n";
590           return 1;
591         }
592
593         // Adjust working plane
594         if (aShape1.ShapeType() == TopAbs_VERTEX)
595         {
596           aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape1)));
597         }
598         else if (aShape2.ShapeType() == TopAbs_VERTEX)
599         {
600           aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape2)));
601         }
602
603         aDim = new AIS_LengthDimension (aShape1, aShape2, aWorkingPlane);
604       }
605       else
606       {
607         std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
608         return 1;
609       }
610
611       break;
612     }
613     case AIS_KOD_PLANEANGLE:
614     {
615       if (aShapes.Extent() == 1 && aShapes.First()->Type()==AIS_KOI_Shape)
616       {
617         Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast(aShapes.First());
618         if (aShape->Shape().ShapeType() == TopAbs_FACE)
619           aDim = new AIS_AngleDimension (TopoDS::Face(aShape->Shape()));
620       }
621       if (aShapes.Extent() == 2)
622       {
623         Handle(AIS_Shape) aShape1 = Handle(AIS_Shape)::DownCast(aShapes.First());
624         Handle(AIS_Shape) aShape2 = Handle(AIS_Shape)::DownCast(aShapes.Last());
625         if (!aShape1.IsNull() && !aShape2.IsNull()
626           && aShape1->Shape().ShapeType() == TopAbs_EDGE
627           && aShape2->Shape().ShapeType() == TopAbs_EDGE)
628           aDim = new AIS_AngleDimension (TopoDS::Edge(aShape1->Shape()),TopoDS::Edge(aShape2->Shape()));
629         else
630         {
631           std::cerr << theArgs[0] << ": wrong shapes for angle dimension.\n";
632           return 1;
633         }
634       }
635       else if (aShapes.Extent() == 3)
636       {
637         gp_Pnt aP1, aP2, aP3;
638         Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
639         if (aPoint.IsNull())
640           return 1;
641         aP1 = aPoint->Component()->Pnt();
642         aShapes.RemoveFirst();
643         aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
644         if (aPoint.IsNull())
645           return 1;
646         aP2 = aPoint->Component()->Pnt();
647         aShapes.RemoveFirst();
648         aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
649         if (aPoint.IsNull())
650           return 1;
651         aP3 = aPoint->Component()->Pnt();
652         aDim = new AIS_AngleDimension (aP1, aP2, aP3);
653       }
654       else
655       {
656         std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
657         return 1;
658       }
659
660       break;
661     }
662     case AIS_KOD_RADIUS: // radius of the circle
663     {
664       if (aShapes.Extent() == 1)
665       {
666         if (aShapes.First()->DynamicType() == STANDARD_TYPE(AIS_Circle))
667         {
668           Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
669           gp_Circ aCircle = aShape->Circle()->Circ();
670           aDim = new AIS_RadiusDimension (aCircle);
671         }
672         else
673         {
674           Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aShapes.First());
675           if (aShape.IsNull())
676           {
677             std::cerr << "Error: shape for radius is of wrong type.\n";
678             return 1;
679           }
680           aDim = new AIS_RadiusDimension (aShape->Shape());
681         }
682       }
683       else
684       {
685         std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
686         return 1;
687       }
688
689       break;
690     }
691     case AIS_KOD_DIAMETER:
692     {
693       if (aShapes.Extent() == 1)
694       {
695         if (aShapes.First()->DynamicType() == STANDARD_TYPE(AIS_Circle))
696         {
697           Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
698           gp_Circ aCircle = aShape->Circle()->Circ();
699           aDim = new AIS_DiameterDimension (aCircle);
700         }
701         else
702         {
703           Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aShapes.First());
704           if (aShape.IsNull())
705           {
706             std::cerr << "Error: shape for radius is of wrong type.\n";
707             return 1;
708           }
709           aDim = new AIS_DiameterDimension (aShape->Shape());
710         }
711       }
712       else
713       {
714         std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
715         return 1;
716       }
717
718       break;
719     }
720     default:
721     {
722       std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n";
723       return 1;
724     }
725   }
726
727   // Check dimension geometry
728   if (!aDim->IsValid())
729   {
730     std::cerr << theArgs[0] << ":dimension geometry is invalid, " << aDimType.ToCString()
731       << " dimension can't be built on input shapes.\n";
732     return 1;
733   }
734
735   aDim->SetDimensionAspect (anAspect);
736
737   SetDimensionParams (aDim, aRealParams, aStringParams);
738
739   VDisplayAISObject (aName,aDim);
740
741   return 0;
742 }
743
744 //=======================================================================
745 //function : VAngleDimBuilder
746 //purpose  : 
747 //=======================================================================
748
749 static int VAngleDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
750 {
751   Standard_Integer aCurrentIndex;
752   if (argc!=2)
753   {
754     di << argv[0] << " error : wrong number of parameters.\n";
755     return 1;
756   }
757
758   TheAISContext()->CloseAllContexts();
759   aCurrentIndex =  TheAISContext()->OpenLocalContext();
760   // Set selection mode for edges.
761   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
762   di << "Select two edges coplanar or not.\n";
763
764   Standard_Integer anArgsNum = 5;
765   const char *aBuffer[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
766   const char **anArgsVec = (const char **) aBuffer;
767   while (ViewerMainLoop (anArgsNum, anArgsVec)) { }
768
769   TopoDS_Shape aFirstShape;
770   for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
771   {
772     aFirstShape = TheAISContext()->SelectedShape();
773   }
774
775   if (aFirstShape.IsNull())
776   {
777     di << argv[0] << " error : no picked shape.\n";
778     return 1;
779   }
780
781   if (aFirstShape.ShapeType()== TopAbs_EDGE)
782   {
783     while (ViewerMainLoop (anArgsNum, anArgsVec)) { }
784
785     TopoDS_Shape aSecondShape;
786     for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
787     {
788       aSecondShape = TheAISContext()->SelectedShape();
789     }
790
791     if (aSecondShape.IsNull())
792     {
793       di << argv[0] << " error : no picked shape.\n";
794       return 1;
795     }
796
797     if (aSecondShape.ShapeType() != TopAbs_EDGE)
798     {
799       di << argv[0] <<" error: you should have selected an edge.\n"; return 1;
800     }
801
802     // Close local context to draw dimension in the neutral point.
803     TheAISContext()->CloseLocalContext (aCurrentIndex);
804
805     // Construct the dimension.
806     Handle (AIS_AngleDimension) aDim= new AIS_AngleDimension (TopoDS::Edge(aFirstShape) ,TopoDS::Edge(aSecondShape));
807     VDisplayAISObject (argv[1], aDim);
808   }
809   else
810   {
811     di << argv[0] << " error: you must select 2 edges.\n";
812     return 1;
813   }
814
815   return 0;
816 }
817
818 //==============================================================================
819 //function : VDiameterDim
820 //purpose  : Display the diameter dimension of a face or an edge.
821 //Draw arg : vdiameterdim Name 
822 //==============================================================================
823
824 static int VDiameterDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
825 {
826   // Declarations
827   Standard_Integer aCurrentIndex;
828
829   // Verification
830   if (argc != 2)
831   {
832     di<<" vdiameterdim error"<<"\n";
833     return 1;
834   }
835
836   // Close all local contexts
837   TheAISContext()->CloseAllContexts();
838   // Open local context and get its index for recovery
839   TheAISContext()->OpenLocalContext();
840   aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
841   
842   // Activate 'edge' selection mode
843   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
844   di<<" Select an circled edge."<<"\n";
845   
846   // Loop that will handle the picking.
847   Standard_Integer argcc = 5;
848   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
849   const char **argvv = (const char **) buff;
850   while (ViewerMainLoop( argcc, argvv) ) { }
851   // end of the loop.
852   
853   TopoDS_Shape aShape;
854   for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
855   {
856     aShape = TheAISContext()->SelectedShape();
857   }
858
859   if (aShape.IsNull())
860   {
861     di << argv[0] << ": no shape is selected." << "\n";
862     return 1;
863   }
864
865   if (aShape.ShapeType() != TopAbs_EDGE)
866   {
867     di << " vdiameterdim error: the selection of a face or an edge was expected." << "\n";
868     return 1;
869   }
870
871   // Compute the radius
872   BRepAdaptor_Curve aCurve (TopoDS::Edge (aShape));
873
874   if (aCurve.GetType() != GeomAbs_Circle)
875   {
876     di << "vdiameterdim error: the edge is not a circular one." << "\n";
877     return 1;
878   }
879
880   // Construction of the diameter dimension.
881   TheAISContext()->CloseLocalContext (aCurrentIndex);
882   Handle (AIS_DiameterDimension) aDiamDim= new AIS_DiameterDimension (aShape);
883   VDisplayAISObject (argv[1], aDiamDim);
884
885   return 0;
886 }
887
888
889 //==============================================================================
890 // Fonction  vconcentric
891 // -----------------  Uniquement par selection dans le viewer.
892 //==============================================================================
893
894 //==============================================================================
895 //function : VConcentric
896 //purpose  : Display the concentric relation between two surfaces.
897 //Draw arg : vconcentric Name
898 //==============================================================================
899 #include <AIS_ConcentricRelation.hxx>
900 #include <Geom_Plane.hxx>
901 #include <gp_Pln.hxx>
902 #include <GC_MakePlane.hxx>
903 #include <BRepAdaptor_Curve.hxx>
904 #include <TopExp_Explorer.hxx>
905
906
907 static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
908 {
909   // Declarations
910   Standard_Integer myCurrentIndex;
911   
912   // Verification
913   if (argc!=2) {di<<"vconcentric  error."<<"\n";return 1;}
914   // Fermeture des contextes locaux
915   TheAISContext()->CloseAllContexts();
916   // Ouverture d'un contexte local et recuperation de son index.
917   TheAISContext()->OpenLocalContext();
918   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
919   
920   // On active les modes de selections Edges et Faces.
921   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
922   di<<" Select a circled edge."<<"\n";
923   
924   // Boucle d'attente waitpick.
925   Standard_Integer argcc = 5;
926   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
927   const char **argvv = (const char **) buff;
928   while (ViewerMainLoop( argcc, argvv) ) { }
929   // fin de la boucle
930   
931   TopoDS_Shape ShapeA;
932   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
933     ShapeA = TheAISContext()->SelectedShape();
934   }
935   // ShapeA est un edge
936   // ==================
937   if (ShapeA.ShapeType()==TopAbs_EDGE  ) {
938     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
939     di<<" Select an edge."<<"\n";
940     
941     // Boucle d'attente waitpick.
942     Standard_Integer argccc = 5;
943     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
944     const char **argvvv = (const char **) bufff;
945     while (ViewerMainLoop( argccc, argvvv) ) { }
946     // fin de la boucle
947     
948     TopoDS_Shape ShapeB;
949     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
950       ShapeB = TheAISContext()->SelectedShape();
951     }
952     if (ShapeB.ShapeType()!=TopAbs_EDGE  ) {
953       di<<" vconcentric error: select an edge."<<"\n";return 1;
954     }
955      
956     // Construction du plane.
957     // On recupere le centre du cercle A.
958     BRepAdaptor_Curve theCurveA(TopoDS::Edge(ShapeA) );
959     gp_Circ theCircleA=theCurveA.Circle();
960     gp_Pnt theCenterA=theCircleA.Location();
961     // On recupere deux points sur le cercle A
962     gp_Pnt B= theCurveA.Value(0.25);
963     gp_Pnt C= theCurveA.Value(0.75);
964     // Construction du plane.
965     GC_MakePlane MkPlane(theCenterA ,B ,C );
966     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
967     
968     // Fermeture du context local
969     TheAISContext()->CloseLocalContext(myCurrentIndex);
970     
971     Handle (AIS_ConcentricRelation) myConcentry= new AIS_ConcentricRelation(ShapeA, ShapeB, theGeomPlane );
972     TheAISContext()->Display(myConcentry );
973     GetMapOfAIS().Bind (myConcentry,argv[1]);
974   }
975   
976   
977   else {
978     di<<" vconcentric  error: the selection of a face or an edge was expected."<<"\n";return 1;
979   }
980   
981   return 0;
982   
983   
984   
985   
986 }
987
988 //==============================================================================
989 //function : VEqualDistRelation
990 //purpose  : 
991 //Draw arg : vdiameterdim Name DiameterValue
992 //==============================================================================
993 #include <AIS_EqualDistanceRelation.hxx>
994 #include <BRepExtrema_ExtCC.hxx>
995 #include <GC_MakePlane.hxx>
996
997
998 static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
999 {
1000   // Declarations
1001   Standard_Integer myCurrentIndex;
1002   
1003   // Verification
1004   if (argc!=2) {di<<" vequaldistrelation error: no arguments allowed."<<"\n";return 1;}
1005   
1006   // Fermeture des contextes locaux
1007   TheAISContext()->CloseAllContexts();
1008   
1009   // Ouverture d'un contexte local et recuperation de son index.
1010   TheAISContext()->OpenLocalContext();
1011   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1012   
1013   // On active les modes de selections Edges et Vertexes.
1014   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1015   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1016   di<<" Select an edge or a vertex"<<"\n";
1017   
1018   // Boucle d'attente waitpick.
1019   Standard_Integer argc1 = 5;
1020   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1021   const char **argv1 = (const char **) buf1;
1022   while (ViewerMainLoop( argc1, argv1) ) { }
1023   // fin de la boucle
1024   
1025   TopoDS_Shape ShapeA;
1026   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1027     ShapeA = TheAISContext()->SelectedShape();
1028   }
1029   
1030   di<<" Select an edge or a vertex"<<"\n";
1031   // Boucle d'attente waitpick.
1032   Standard_Integer argc2 = 5;
1033   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1034   const char **argv2 = (const char **) buf2;
1035   while (ViewerMainLoop( argc2, argv2) ) { }
1036   // fin de la boucle
1037   
1038   TopoDS_Shape ShapeB;
1039   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1040     ShapeB = TheAISContext()->SelectedShape();
1041   }
1042   
1043   // Verification des resultats.
1044   if (ShapeA.ShapeType()==TopAbs_EDGE && ShapeB.ShapeType()==TopAbs_EDGE  ) {
1045     // A et B sont des edges ils doivent etre paralleles
1046     BRepExtrema_ExtCC myDeltaEdge (TopoDS::Edge(ShapeA) ,TopoDS::Edge(ShapeB)  );
1047     // on verifie qu'ils sont pas paralleles.
1048     if (!myDeltaEdge.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
1049     
1050   }
1051   
1052   
1053   di<<" Select an edge or a vertex"<<"\n";
1054   // Boucle d'attente waitpick.
1055   Standard_Integer argc3 = 5;
1056   const char *buf3[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1057   const char **argv3 = (const char **) buf3;
1058   while (ViewerMainLoop( argc3, argv3) ) { }
1059   // fin de la boucle
1060   
1061   TopoDS_Shape ShapeC;
1062   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1063     ShapeC = TheAISContext()->SelectedShape();
1064   }
1065   
1066   di<<" Select an edge or a vertex"<<"\n";
1067   // Boucle d'attente waitpick.
1068   Standard_Integer argc4 = 5;
1069   const char *buf4[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1070   const char **argv4 = (const char **) buf4;
1071   while (ViewerMainLoop( argc4, argv4) ) { }
1072   // fin de la boucle
1073   
1074   TopoDS_Shape ShapeD;
1075   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1076     ShapeD = TheAISContext()->SelectedShape();
1077   }
1078   // Verification des resultats.
1079   if (ShapeC.ShapeType()==TopAbs_EDGE && ShapeD.ShapeType()==TopAbs_EDGE  ) {
1080     // C et D sont des edges ils doivent etre paralleles
1081     BRepExtrema_ExtCC myDeltaEdge2 (TopoDS::Edge(ShapeC) ,TopoDS::Edge(ShapeD)  );
1082     // on verifie qu'ils sont pas paralleles.
1083     if (!myDeltaEdge2.IsParallel() ) {di<<"vequaldist error: non parallel edges."<<"\n";return 1; }
1084     
1085   }
1086   
1087   // Creation du plan porteur de la contrainte.Methode lourde!
1088   gp_Pnt A,B,C;
1089   if (ShapeA.ShapeType()==TopAbs_EDGE) {
1090     // A est un edge
1091     TopoDS_Vertex Va,Vb;
1092     TopExp::Vertices (TopoDS::Edge(ShapeA) ,Va ,Vb );
1093     A=BRep_Tool::Pnt(Va);
1094     B=BRep_Tool::Pnt(Vb);
1095     
1096     if (ShapeB.ShapeType()==TopAbs_EDGE) {
1097       // B est un edge aussi
1098       TopoDS_Vertex Vc,Vd;
1099       TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vc ,Vd );
1100       // besoin que de 1 point.
1101       C=BRep_Tool::Pnt(Vc);
1102       
1103     }
1104     else {
1105       // B est un vertex
1106       C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1107     }
1108   }
1109   else {
1110     // A est un vertex
1111     A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1112     
1113     if (ShapeB.ShapeType()==TopAbs_EDGE ) {
1114       // B est un edge 
1115       TopoDS_Vertex Vb,Vc;
1116       TopExp::Vertices (TopoDS::Edge(ShapeB) ,Vb ,Vc );
1117       // besoin que de 2 points.
1118       B=BRep_Tool::Pnt(Vb);
1119       C=BRep_Tool::Pnt(Vc);
1120       
1121     }
1122     else {
1123       // B est un vertex
1124       B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1125       C.SetX(B.X()+5.);
1126       C.SetY(B.Y()+5.);
1127       C.SetZ(B.Z()+5.);
1128       
1129     }
1130   }
1131   
1132   // Fermeture du context local.
1133   TheAISContext()->CloseLocalContext(myCurrentIndex);
1134   
1135   // construction du plane 
1136   GC_MakePlane MkPlane(A ,B ,C );
1137   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1138   
1139   // Construction de l'AIS_EqualDistanceRelation
1140   Handle (AIS_EqualDistanceRelation ) myRelation= new AIS_EqualDistanceRelation (ShapeA, ShapeB, ShapeC ,ShapeD , theGeomPlane );
1141   TheAISContext()->Display(myRelation );
1142   GetMapOfAIS().Bind (myRelation,argv[1]);
1143   
1144
1145   
1146   return 0;
1147   
1148 }
1149
1150 //==============================================================================
1151 //function : VEqualRadiusRelation
1152 //purpose  : 
1153 //Draw arg : vdiameterdim Name DiameterValue
1154 //==============================================================================
1155 #include <AIS_EqualRadiusRelation.hxx>
1156 #include <GC_MakePlane.hxx>
1157 #include <BRepAdaptor_Curve.hxx>
1158
1159
1160 static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1161 {
1162   // Declarations
1163   Standard_Integer myCurrentIndex;
1164   
1165   // Verification
1166   if (argc!=2) {di<<" vequalrad error: no arguments allowed."<<"\n";return 1;}
1167   
1168   // Fermeture des contextes locaux
1169   TheAISContext()->CloseAllContexts();
1170   
1171   // Ouverture d'un contexte local et recuperation de son index.
1172   TheAISContext()->OpenLocalContext();
1173   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1174   
1175   // On active les modes de selections Edges.
1176   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1177   di<<" Select an circled edge "<<"\n";
1178   
1179   // Boucle d'attente waitpick.
1180   Standard_Integer argc1 = 5;
1181   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1182   const char **argv1 = (const char **) buf1;
1183   while (ViewerMainLoop( argc1, argv1) ) { }
1184   // fin de la boucle
1185   
1186   TopoDS_Shape ShapeA;
1187   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1188     ShapeA = TheAISContext()->SelectedShape();
1189   }
1190   
1191   di<<" Select the last circled edge."<<"\n";
1192   // Boucle d'attente waitpick.
1193   Standard_Integer argc2 = 5;
1194   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1195   const char **argv2 = (const char **) buf2;
1196   while (ViewerMainLoop( argc2, argv2) ) { }
1197   // fin de la boucle
1198   
1199   TopoDS_Shape ShapeB;
1200   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1201     ShapeB = TheAISContext()->SelectedShape();
1202   }
1203   // creation du plan qui contient la contrainte.
1204   TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1205   TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1206   BRepAdaptor_Curve theCurveA(EdgeA);
1207   // On recupere 3 points A,B,C de la curve.
1208   gp_Pnt A=theCurveA.Value(0.1);
1209   gp_Pnt B=theCurveA.Value(0.5);
1210   gp_Pnt C=theCurveA.Value(0.9);
1211   
1212   // fermeture du contexte local.
1213   TheAISContext()->CloseLocalContext(myCurrentIndex);
1214   
1215   // Creation du plane.
1216   GC_MakePlane MkPlane (A ,B ,C );
1217   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1218   // Construction de l'AIS_EqualRadiusRelation
1219   Handle (AIS_EqualRadiusRelation ) myRelation= new AIS_EqualRadiusRelation (EdgeA,EdgeB, theGeomPlane );
1220   TheAISContext()->Display(myRelation );
1221   GetMapOfAIS().Bind (myRelation,argv[1]);
1222   
1223   return 0;
1224   
1225 }
1226
1227
1228 //==============================================================================
1229 //function : VFixRelation
1230 //purpose  : 
1231 //Draw arg : vdiameterdim Name DiameterValue
1232 //==============================================================================
1233 #include <AIS_FixRelation.hxx>
1234 #include <GC_MakePlane.hxx>
1235 #include <BRepAdaptor_Curve.hxx>
1236
1237 static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1238 {
1239   // Declarations
1240   Standard_Integer myCurrentIndex;
1241   
1242   // Verification
1243   if (argc!=2) {di<<" vfix  error: no arguments allowed."<<"\n";return 1;}
1244   
1245   // Fermeture des contextes locaux
1246   TheAISContext()->CloseAllContexts();
1247   
1248   // Ouverture d'un contexte local et recuperation de son index.
1249   TheAISContext()->OpenLocalContext();
1250   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1251   
1252   // On active les modes de selections edge.
1253   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1254   di<<" Select an edge. "<<"\n";
1255   
1256   // Boucle d'attente waitpick.
1257   Standard_Integer argc1 = 5;
1258   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1259   const char **argv1 = (const char **) buf1;
1260   while (ViewerMainLoop( argc1, argv1) ) { }
1261   // fin de la boucle
1262   
1263   TopoDS_Shape ShapeA;
1264   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1265     ShapeA = TheAISContext()->SelectedShape();
1266   }
1267   
1268   // creation du plan qui contient la contrainte.
1269   TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1270   BRepAdaptor_Curve theCurveA(EdgeA);
1271   // On recupere 3 points A,B,C de la curve.
1272   gp_Pnt A=theCurveA.Value(0.1);
1273   gp_Pnt B=theCurveA.Value(0.5);
1274   gp_Pnt D=theCurveA.Value(0.9);
1275   gp_Pnt C(B.X()+5,B.Y()+5,B.Z()+5);
1276   
1277   // fermeture du contexte local.
1278   TheAISContext()->CloseLocalContext(myCurrentIndex);
1279   
1280   // Creation du plane.
1281   GC_MakePlane MkPlane (A ,D ,C );
1282   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1283   // Construction de l'AIS_EqualRadiusRelation
1284   Handle (AIS_FixRelation) myRelation= new AIS_FixRelation (EdgeA,theGeomPlane );
1285   TheAISContext()->Display(myRelation );
1286   GetMapOfAIS().Bind (myRelation,argv[1]);
1287   
1288   
1289   return 0;
1290   
1291 }
1292
1293 //==============================================================================
1294 //function : VIdenticRelation
1295 //purpose  : 
1296 //Draw arg : vdiameterdim Name DiameterValue
1297 //==============================================================================
1298 #include <AIS_IdenticRelation.hxx>
1299 #include <BRepAdaptor_Curve.hxx>
1300 #include <TopExp_Explorer.hxx>
1301
1302
1303 static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1304 {
1305   // Declarations
1306   Standard_Integer myCurrentIndex;
1307   
1308   // Verification
1309   if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;}
1310   
1311   // Fermeture des contextes locaux
1312   TheAISContext()->CloseAllContexts();
1313   
1314   // Ouverture d'un contexte local et recuperation de son index.
1315   TheAISContext()->OpenLocalContext();
1316   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1317   
1318   // On active les modes de selections  vertex et face.
1319   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1320   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
1321   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1322   di<<" Select an edge, a face or a vertex. "<<"\n";
1323   
1324   // Boucle d'attente waitpick.
1325   Standard_Integer argc1 = 5;
1326   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1327   const char **argv1 = (const char **) buf1;
1328   while (ViewerMainLoop( argc1, argv1) ) { }
1329   // fin de la boucle
1330   
1331   TopoDS_Shape ShapeA;
1332   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1333     ShapeA = TheAISContext()->SelectedShape();
1334   }
1335   
1336   di<<" Select an edge, a face or a vertex. "<<"\n";
1337   // Boucle d'attente waitpick.
1338   Standard_Integer argc2 = 5;
1339   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1340   const char **argv2 = (const char **) buf2;
1341   while (ViewerMainLoop( argc2, argv2) ) { }
1342   // fin de la boucle
1343   
1344   TopoDS_Shape ShapeB;
1345   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1346     ShapeB = TheAISContext()->SelectedShape();
1347   }
1348   
1349   // Recuperation de points pour construir le Geom_Plnae.
1350   gp_Pnt A,B,C;
1351   if (ShapeA.ShapeType()==TopAbs_EDGE) {
1352     // 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.
1353     // on recupere deux points sur l'edge (il peut etre rectiligne)
1354     TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
1355     BRepAdaptor_Curve theCurveA(EdgeA);
1356     // Creation des 3 points.
1357     A=theCurveA.Value(0.1);
1358     B=theCurveA.Value(0.9);
1359     C.SetX(B.X()+5.);
1360     C.SetY(B.Y()+5.);
1361     C.SetZ(B.Z()+5.);
1362   }
1363   else if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1364     // SahpeA est un Vertex
1365     // On va utiliser ShapeB
1366     if (ShapeB.ShapeType()==TopAbs_EDGE) {
1367       // B est un edge 
1368       TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
1369       BRepAdaptor_Curve theCurveB(EdgeB);
1370       // Creation des 3 points.
1371       A=theCurveB.Value(0.1);
1372       B=theCurveB.Value(0.9);
1373       C.SetX(B.X()+5.);
1374       C.SetY(B.Y()+5.);
1375       C.SetZ(B.Z()+5.);
1376       
1377     }
1378     else if (ShapeB.ShapeType()==TopAbs_FACE ) {
1379       // Shape B est une face
1380       TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1381       // On recupere 1 edge de FaceB(la face n'a pas forcement de vertex) (l'element A est forcement dans B).
1382       TopExp_Explorer FaceExp(FaceB,TopAbs_EDGE);
1383       TopoDS_Edge EdgeFromB=TopoDS::Edge(FaceExp.Current() );
1384       // On recupere les 3 points de l'edge de face B
1385       BRepAdaptor_Curve theCurveB(EdgeFromB);
1386       // On recupere 3 points A,B,C de la curve.
1387       A=theCurveB.Value(0.1);
1388       B=theCurveB.Value(0.5);
1389       C=theCurveB.Value(0.9);
1390       
1391     }
1392     else {
1393       // B ets un vetex aussi
1394       A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1395       B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1396       C.SetX(B.X()+5.);
1397       C.SetY(B.Y()+5.);
1398       C.SetZ(B.Z()+5.);
1399       
1400     }
1401     
1402   }
1403   else {
1404     // A est une face.
1405     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1406     // On recupere 1 edge de FaceA
1407     TopExp_Explorer FaceExp(FaceA,TopAbs_EDGE);
1408     TopoDS_Edge EdgeFromA=TopoDS::Edge(FaceExp.Current() );
1409     // On recupere les 3 points de l'edge
1410     BRepAdaptor_Curve theCurveA(EdgeFromA);
1411     // On recupere 3 points A,B,C de la curve.
1412     A=theCurveA.Value(0.1);
1413     B=theCurveA.Value(0.5);
1414     C=theCurveA.Value(0.9);
1415     
1416   }
1417   
1418   // Fermeture du context local.
1419   TheAISContext()->CloseLocalContext(myCurrentIndex);
1420   // On construit le plane 
1421   GC_MakePlane MkPlane (A ,B ,C );
1422   Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
1423   
1424   // Construction de l'AIS_IdenticRelation
1425   Handle ( AIS_IdenticRelation ) myRelation= new AIS_IdenticRelation  (ShapeA ,ShapeB, theGeomPlane );
1426   TheAISContext()->Display(myRelation );
1427   GetMapOfAIS().Bind (myRelation,argv[1]);
1428   
1429
1430   
1431   return 0;
1432   
1433 }
1434 //==============================================================================
1435 //function : VLengthDimension
1436 //purpose  : Display the diameter dimension of a face or an edge.
1437 //Draw arg : vdiameterdim Name DiameterValue
1438 //==============================================================================
1439 #include <AIS_LengthDimension.hxx>
1440 #include <BRepExtrema_ExtCC.hxx>
1441 #include <BRepExtrema_ExtPC.hxx>
1442 #include <BRepExtrema_ExtCF.hxx>
1443 #include <BRepExtrema_ExtPF.hxx>
1444 #include <BRepExtrema_ExtFF.hxx>
1445 #include <TCollection_ExtendedString.hxx>
1446 #include <BRepExtrema_DistShapeShape.hxx>
1447 #include <gce_MakePln.hxx>
1448 #include <TopExp_Explorer.hxx>
1449 #include <BRepBuilderAPI_MakeVertex.hxx>
1450
1451 static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1452 {
1453   // Declarations
1454   Standard_Integer aCurrentIndex;
1455   // Verification
1456   if (argc != 2)
1457   {
1458     di << argv[0] << " error: wrong number of arguments.\n";
1459     return 1;
1460   }
1461
1462   // Close all local contexts
1463   TheAISContext()->CloseAllContexts();
1464
1465   // Open local context
1466   aCurrentIndex = TheAISContext()->OpenLocalContext();
1467   // Activate 'edge', 'face' and 'vertex' selection modes.
1468   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1469   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1));
1470   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1471
1472   // First shape picking
1473   di << " Select an edge, a face or a vertex. " << "\n";
1474   // Loop that will handle the picking.
1475   Standard_Integer argc1 = 5;
1476   const char *buf1[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1477   const char **argv1 = (const char **) buf1;
1478   while (ViewerMainLoop( argc1, argv1) ) { }
1479   // end of the loop.
1480
1481   TopoDS_Shape aFirstShape;
1482   for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
1483   {
1484     aFirstShape = TheAISContext()->SelectedShape();
1485   }
1486
1487   if (aFirstShape.IsNull())
1488   {
1489     di << argv[0] << "error: no first picked shape.\n";
1490     return 1;
1491   }
1492
1493   // Second shape picking
1494   di << " Select an edge, a face or a vertex. " << "\n";
1495   // Loop that will handle the picking.
1496   Standard_Integer argc2 = 5;
1497   const char *buf2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1498   const char **argv2 = (const char **) buf2;
1499   while (ViewerMainLoop( argc2, argv2) ) { }
1500
1501   TopoDS_Shape aSecondShape;
1502   for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
1503   {
1504     aSecondShape = TheAISContext()->SelectedShape();
1505   }
1506
1507   if (aSecondShape.IsNull())
1508   {
1509     di << argv[0] << "error: no second picked shape.\n";
1510     return 1;
1511   }
1512
1513   if (aFirstShape.ShapeType() == TopAbs_EDGE)
1514   {
1515     TopoDS_Edge EdgeA = TopoDS::Edge (aFirstShape);
1516
1517     if (aSecondShape.ShapeType() == TopAbs_EDGE)
1518     {
1519       TopoDS_Edge EdgeB = TopoDS::Edge (aSecondShape);
1520       BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB);
1521
1522       if (!myDeltaEdge.IsParallel())
1523       {
1524         di << argv[0] << " error: non parallel edges." << "\n";
1525         return 1;
1526       }
1527
1528       // 3 points of edges is recovered to build a plane
1529       TopoDS_Vertex aVertex1, aVertex2, aVertex3, aVertex4;
1530       TopExp::Vertices (EdgeA, aVertex1, aVertex2);
1531       TopExp::Vertices (EdgeB, aVertex3, aVertex4);
1532       gp_Pnt A = BRep_Tool::Pnt (aVertex1);
1533       gp_Pnt B = BRep_Tool::Pnt (aVertex2);
1534       gp_Pnt C = BRep_Tool::Pnt (aVertex3);
1535
1536       gce_MakePln aMakePlane (A,B,C);
1537       gp_Pln aPlane= aMakePlane.Value();
1538
1539       // Close local context
1540       TheAISContext()->CloseLocalContext (aCurrentIndex);
1541
1542       // Construct the dimension
1543       Handle(AIS_LengthDimension ) aLenghtDim = new AIS_LengthDimension (EdgeA, EdgeB, aPlane);
1544       TheAISContext()->Display (aLenghtDim);
1545       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1546     }
1547
1548     else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1549     {
1550       TopoDS_Vertex aVertex = TopoDS::Vertex (aSecondShape);
1551       BRepExtrema_ExtPC myDeltaEdgeVertex  (aVertex ,EdgeA);
1552
1553       TopoDS_Vertex aVertex1, aVertex2;
1554       TopExp::Vertices (EdgeA, aVertex1, aVertex2);
1555       gp_Pnt A=BRep_Tool::Pnt (aVertex1);
1556       gp_Pnt B=BRep_Tool::Pnt (aVertex2);
1557       gp_Pnt C=BRep_Tool::Pnt (aVertex);
1558
1559       gce_MakePln aMakePlane (A,B,C);
1560       gp_Pln aPlane= aMakePlane.Value();
1561
1562       TheAISContext()->CloseLocalContext (aCurrentIndex);
1563       Handle(AIS_LengthDimension) aLenghtDim=new AIS_LengthDimension (EdgeA, aVertex, aPlane);
1564       TheAISContext()->Display (aLenghtDim);
1565       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1566     }
1567
1568     // Second shape is a face
1569     else
1570     {
1571       TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1572       BRepExtrema_ExtCF aDeltaEdgeFace (EdgeA,FaceB);
1573
1574       if (!aDeltaEdgeFace.IsParallel())
1575       {
1576         di << argv[0] << "error: the edge isn't parallel to the face;can't compute the distance." << "\n";
1577         return 1;
1578       }
1579
1580       Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceB, EdgeA);
1581       TheAISContext()->Display (aLenghtDim);
1582       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1583     }
1584   }
1585   else if (aFirstShape.ShapeType() == TopAbs_VERTEX)
1586   {
1587     TopoDS_Vertex  VertexA = TopoDS::Vertex (aFirstShape);
1588     if (aSecondShape.ShapeType() == TopAbs_EDGE )
1589     {
1590       TopoDS_Edge  EdgeB=TopoDS::Edge (aSecondShape);
1591       BRepExtrema_ExtPC aDeltaEdgeVertex (VertexA, EdgeB);
1592
1593       TopoDS_Vertex aVertex1, aVertex2;
1594       TopExp::Vertices(EdgeB, aVertex1, aVertex2);
1595       gp_Pnt A = BRep_Tool::Pnt (aVertex1);
1596       gp_Pnt B = BRep_Tool::Pnt (aVertex2);
1597       gp_Pnt C = BRep_Tool::Pnt (VertexA);
1598
1599       gce_MakePln aMakePlane (A,B,C);
1600       gp_Pln aPlane = aMakePlane.Value();
1601
1602       // Close local contex by its index.
1603       TheAISContext()->CloseLocalContext (aCurrentIndex);
1604
1605       // Construct the dimension.
1606       Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (EdgeB,VertexA, aPlane);
1607       TheAISContext()->Display (aLenghtDim);
1608       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1609     }
1610
1611     else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1612     {
1613       TopoDS_Vertex  VertexB = TopoDS::Vertex (aSecondShape);
1614
1615       gp_Pnt A = BRep_Tool::Pnt (VertexA);
1616       gp_Pnt B = BRep_Tool::Pnt (VertexB);
1617       gp_Pnt C(B.X() + 10.0, B.Y() + 10.0, B.Z() + 10.0);
1618
1619       gce_MakePln aMakePlane (A,B,C);
1620       gp_Pln aPlane= aMakePlane.Value();
1621
1622       TheAISContext()->CloseLocalContext (aCurrentIndex);
1623
1624       Handle(AIS_LengthDimension ) aLenghtDim = new AIS_LengthDimension (VertexA, VertexB, aPlane);
1625       TheAISContext()->Display (aLenghtDim);
1626       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1627     }
1628     // The second shape is face
1629     else
1630     {
1631       TopoDS_Face  FaceB = TopoDS::Face (aSecondShape);
1632
1633       BRepExtrema_ExtPF aDeltaVertexFace (VertexA, FaceB);
1634
1635       gp_Pnt A = BRep_Tool::Pnt (VertexA);
1636
1637       // Recover edge from face.
1638       TopExp_Explorer aFaceExp (FaceB,TopAbs_EDGE);
1639       TopoDS_Edge aSecondEdge = TopoDS::Edge (aFaceExp.Current());
1640
1641       TopoDS_Vertex aVertex1, aVertex2;
1642       TopExp::Vertices (aSecondEdge, aVertex1, aVertex2);
1643       gp_Pnt C = BRep_Tool::Pnt (aVertex2);
1644
1645       gp_Pnt aProjA = aDeltaVertexFace.Point(1);
1646       BRepBuilderAPI_MakeVertex aVertexMaker (aProjA);
1647       TopoDS_Vertex aVertexAProj = aVertexMaker.Vertex();
1648
1649       // Create working plane for the dimension.
1650       gce_MakePln aMakePlane (A, aProjA, C);
1651       gp_Pln aPlane = aMakePlane.Value();
1652
1653       TheAISContext()->CloseLocalContext (aCurrentIndex);
1654
1655       // Construct the dimension.
1656       Handle(AIS_LengthDimension ) aLenghtDim = new AIS_LengthDimension (VertexA, aVertexAProj, aPlane);
1657       TheAISContext()->Display (aLenghtDim);
1658       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1659     }
1660   }
1661
1662   // The first shape is a face.
1663   else
1664   {
1665     TopoDS_Face FaceA = TopoDS::Face (aFirstShape);
1666
1667     if (aSecondShape.ShapeType() == TopAbs_EDGE)
1668     {
1669       TopoDS_Edge EdgeB = TopoDS::Edge (aSecondShape);
1670       BRepExtrema_ExtCF aDeltaEdgeFace (EdgeB,FaceA );
1671
1672       if (!aDeltaEdgeFace.IsParallel())
1673       {
1674         di << argv[0] << " error: the edge isn't parallel to the face;can't compute the distance. " << "\n";
1675         return 1;
1676       }
1677
1678       Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceA, EdgeB);
1679       TheAISContext()->Display (aLenghtDim);
1680       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1681     }
1682
1683     else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1684     {
1685       TopoDS_Vertex  VertexB = TopoDS::Vertex (aSecondShape);
1686       BRepExtrema_ExtPF aDeltaVertexFace (VertexB, FaceA);
1687
1688       gp_Pnt B = BRep_Tool::Pnt (VertexB);
1689
1690       TopExp_Explorer aFaceExp (FaceA, TopAbs_EDGE);
1691       TopoDS_Edge anEdgeFromA = TopoDS::Edge (aFaceExp.Current());
1692       TopoDS_Vertex  aVertex1, aVertex2;
1693       TopExp::Vertices(anEdgeFromA, aVertex1, aVertex2);
1694       gp_Pnt A=BRep_Tool::Pnt(aVertex1);
1695
1696 #ifdef OCCT_DEBUG
1697       gp_Pnt C = BRep_Tool::Pnt(aVertex2);
1698 #endif
1699
1700       gp_Pnt aProjB = aDeltaVertexFace.Point(1);
1701       BRepBuilderAPI_MakeVertex aVertexMaker (aProjB);
1702       TopoDS_Vertex aVertexBProj = aVertexMaker.Vertex();
1703       gce_MakePln aMakePlane (A, B, aProjB);
1704       gp_Pln aPlane= aMakePlane.Value();
1705
1706       TheAISContext()->CloseLocalContext(aCurrentIndex);
1707
1708       Handle(AIS_LengthDimension) aLenghtDim  =new AIS_LengthDimension (VertexB, aVertexBProj, aPlane);
1709       TheAISContext()->Display (aLenghtDim);
1710       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1711     }
1712     // the second shape is face.
1713     else
1714     {
1715       TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1716       BRepExtrema_ExtFF aDeltaFaceFace (FaceA, FaceB);
1717
1718       if (!aDeltaFaceFace.IsParallel())
1719       {
1720         di << argv[0] << " error: the faces are not parallel. "<<"\n";
1721         return 1;
1722       }
1723
1724       TheAISContext()->CloseLocalContext (aCurrentIndex);
1725
1726       Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceA,FaceB);
1727       TheAISContext()->Display (aLenghtDim);
1728       GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1729     }
1730   }
1731
1732   return 0;
1733 }
1734
1735
1736 //==============================================================================
1737 //function : VRadiusDim
1738 //purpose  : Display the radius dimension of a face or an edge.
1739 //Draw arg : vradiusdim Name 
1740 //==============================================================================
1741 #include <AIS_RadiusDimension.hxx>
1742 #include <TCollection_ExtendedString.hxx>
1743 #include <BRepAdaptor_Curve.hxx>
1744 #include <gp_Circ.hxx>
1745
1746
1747 static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1748 {
1749   // Declarations
1750   Standard_Integer aCurrentIndex;
1751   TopoDS_Edge anEdge;
1752   // Verification
1753   if (argc != 2)
1754   {
1755     di << argv[0] << " error: wrong number of parameters." << "\n";
1756     return 1;
1757   }
1758
1759   // Close all local contexts
1760   TheAISContext()->CloseAllContexts();
1761
1762   // Open local context and get its index for recovery.
1763   TheAISContext()->OpenLocalContext();
1764   aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
1765
1766   // Current selection modes - faces and edges
1767   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2));
1768   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4));
1769   di << " Select a circled edge or face." << "\n";
1770
1771   // Loop that will be handle picking.
1772   Standard_Integer argcc = 5;
1773   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1774   const char **argvv = (const char **) buff;
1775   while (ViewerMainLoop (argcc, argvv)) { }
1776   // end of the loop
1777
1778   TopoDS_Shape aShape;
1779
1780   for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() )
1781   {
1782     aShape = TheAISContext()->SelectedShape();
1783   }
1784
1785   if (aShape.IsNull())
1786   {
1787     di << argv[0] << ": no shape is selected." << "\n";
1788     return 1;
1789   }
1790
1791   if (aShape.ShapeType() != TopAbs_EDGE && aShape.ShapeType() != TopAbs_FACE)
1792   {
1793     di << argv[0] << " error: the selection of a face or an edge was expected." << "\n";
1794     return 1;
1795   }
1796
1797   if (aShape.ShapeType() == TopAbs_EDGE)
1798   {
1799     anEdge = TopoDS::Edge (aShape);
1800   }
1801   else // Face
1802   {
1803     // Recover an edge of the face.
1804     TopoDS_Face aFace = TopoDS::Face (aShape);
1805
1806     TopExp_Explorer aFaceExp (aFace,TopAbs_EDGE);
1807     anEdge = TopoDS::Edge (aFaceExp.Current());
1808   }
1809
1810   // Compute the radius
1811   BRepAdaptor_Curve aCurve (anEdge);
1812   if (aCurve.GetType() != GeomAbs_Circle)
1813   {
1814     di << argv[0] << " error: the edge is not a circular one." << "\n";
1815     return 1;
1816   }
1817   // Close the context
1818   TheAISContext()->CloseLocalContext (aCurrentIndex);
1819
1820   // Construct radius dimension
1821   Handle (AIS_RadiusDimension) aRadDim= new AIS_RadiusDimension (aShape);
1822   VDisplayAISObject (argv[1], aRadDim);
1823
1824   return 0;
1825 }
1826
1827
1828
1829 //==============================================================================
1830 //function : VOffsetDim
1831 //purpose  : Display the offset dimension
1832 //Draw arg : voffsetdim Name 
1833 //==============================================================================
1834 #include <AIS_OffsetDimension.hxx>
1835 #include <TCollection_ExtendedString.hxx>
1836 #include <BRepExtrema_ExtFF.hxx>
1837
1838
1839 static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1840 {
1841   // Declarations
1842   Standard_Integer myCurrentIndex;
1843   Standard_Real    theDist;
1844   
1845   // Verification
1846   if (argc!=2) {di<<" voffsetdim error"<<"\n";return 1;}
1847   
1848   // Fermeture des contextes locaux
1849   TheAISContext()->CloseAllContexts();
1850   
1851   // Ouverture d'un contexte local et recuperation de son index.
1852   TheAISContext()->OpenLocalContext();
1853   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1854   
1855   // On active les modes de selections Faces.
1856   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1857   di<<" Select a face."<<"\n";
1858   
1859   // Boucle d'attente waitpick.
1860   Standard_Integer argcc = 5;
1861   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1862   const char **argvv = (const char **) buff;
1863   while (ViewerMainLoop( argcc, argvv) ) { }
1864   // fin de la boucle
1865   
1866   TopoDS_Shape ShapeA;
1867   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1868     ShapeA = TheAISContext()->SelectedShape();
1869   }
1870   
1871   di<<" Select a face."<<"\n";
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   TopoDS_Shape ShapeB;
1880   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1881     ShapeB = TheAISContext()->SelectedShape();
1882   }
1883   
1884   
1885   // Shape A et B est une face
1886   if (ShapeA.ShapeType()==TopAbs_FACE && ShapeB.ShapeType()==TopAbs_FACE ) {
1887     
1888     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
1889     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
1890     
1891     BRepExtrema_ExtFF myDeltaFaceFace  (FaceA ,FaceB );
1892     // On verifie que les deux faces sont bien parelles.
1893     if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
1894     
1895     // On saisit la distance et on l'arrondit!
1896     theDist=Round (sqrt (myDeltaFaceFace.SquareDistance(1))*10. )/10.;
1897     // Fermeture du contexte local.
1898     TheAISContext()->CloseLocalContext(myCurrentIndex);
1899     // Construction du texte.
1900     TCollection_ExtendedString TheMessage_Str(TCollection_ExtendedString("offset=")+TCollection_ExtendedString(theDist ) );
1901     
1902     // on construit l'AIS_OffsetDimension
1903     Handle(AIS_OffsetDimension) myOffsetDim=new AIS_OffsetDimension (FaceA,FaceB,theDist,TheMessage_Str );
1904     TheAISContext()->Display(myOffsetDim );
1905     GetMapOfAIS().Bind (myOffsetDim ,argv[1]);
1906     
1907     
1908     
1909   }
1910   
1911   else {
1912     di<<" voffsetdim error: the selection of a face was expected."<<"\n";return 1;
1913   }
1914   
1915   return 0;
1916   
1917 }
1918
1919
1920
1921
1922 //==============================================================================
1923 //function : VParallel
1924 //purpose  : Display the parallel relation 
1925 //Draw arg : vparallel Name 
1926 //==============================================================================
1927 #include <AIS_ParallelRelation.hxx>
1928 #include <TCollection_ExtendedString.hxx>
1929 #include <BRepExtrema_ExtFF.hxx>
1930 #include <BRepExtrema_ExtCC.hxx>
1931 #include <GC_MakePlane.hxx>
1932 #include <BRepAdaptor_Curve.hxx>
1933 #include <TopExp_Explorer.hxx>
1934
1935
1936 static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
1937 {
1938   // Declarations
1939   Standard_Integer myCurrentIndex;
1940  
1941   // Verification
1942   if (argc!=2) {di<<" vparallel error"<<"\n";return 1;}
1943   
1944   // Fermeture des contextes locaux
1945   TheAISContext()->CloseAllContexts();
1946   
1947   // Ouverture d'un contexte local et recuperation de son index.
1948   TheAISContext()->OpenLocalContext();
1949   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1950   
1951   // On active les modes de selections Edges.
1952   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1953   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1954   di<<" Select an edge or a face "<<"\n";
1955   
1956   // Boucle d'attente waitpick.
1957   Standard_Integer argcc = 5;
1958   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1959   const char **argvv = (const char **) buff;
1960   while (ViewerMainLoop( argcc, argvv) ) { }
1961   // fin de la boucle
1962   
1963   TopoDS_Shape ShapeA;
1964   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1965     ShapeA = TheAISContext()->SelectedShape();
1966   }
1967   
1968   // SahpeA est un edge.
1969   // ===================
1970   if (ShapeA.ShapeType()==TopAbs_EDGE ) {
1971     
1972     // desactivation du mode face
1973     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
1974     di<<" Select a second edge"<<"\n";
1975     // Boucle d'attente waitpick.
1976     Standard_Integer argccc = 5;
1977     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
1978     const char **argvvv = (const char **) bufff;
1979     while (ViewerMainLoop( argccc, argvvv) ) { }
1980     // fin de la boucle
1981     
1982     TopoDS_Shape ShapeB;
1983     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1984       ShapeB = TheAISContext()->SelectedShape();
1985     }
1986     
1987     // recuperation des edges.
1988     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
1989     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
1990     BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB );
1991     // on verifie qu'ils ne sont pas paralleles.
1992     if (!myDeltaEdge.IsParallel() ) {di<<"vparallel error: non parallel edges."<<"\n";return 1; }
1993     
1994     
1995     // On recupere les  vertexes extremites des edge A et B.
1996     BRepAdaptor_Curve theCurveA(EdgeA);
1997     BRepAdaptor_Curve theCurveB(EdgeB);
1998     // On recupere 3 points A,B,C des  curves.
1999     gp_Pnt A=theCurveA.Value(0.1);
2000     gp_Pnt B=theCurveA.Value(0.9);
2001     gp_Pnt C=theCurveB.Value(0.5);
2002     
2003     // Construction du Geom_Plane
2004     GC_MakePlane MkPlane(A,B,C);
2005     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2006     // Fermeture du contexte local.
2007     TheAISContext()->CloseLocalContext(myCurrentIndex);
2008     // Construction de l'AIS_ParallelRelation
2009     Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(EdgeA ,EdgeB ,theGeomPlane );
2010     TheAISContext()->Display(myParaRelation );
2011     GetMapOfAIS().Bind (myParaRelation ,argv[1]);
2012     
2013     
2014   }
2015   
2016   // Shape A est une face
2017   // ====================
2018   else {
2019     
2020     // desactivation du mode edge
2021     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2022     di<<" Select a second edge"<<"\n";
2023     // Boucle d'attente waitpick.
2024     Standard_Integer argccc = 5;
2025     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2026     const char **argvvv = (const char **) bufff;
2027     while (ViewerMainLoop( argccc, argvvv) ) { }
2028     // fin de la boucle
2029     
2030     TopoDS_Shape ShapeB;
2031     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2032       ShapeB = TheAISContext()->SelectedShape();
2033     }
2034     
2035     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
2036     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
2037     
2038     BRepExtrema_ExtFF myDeltaFaceFace  (FaceA ,FaceB );
2039     // On verifie que les deux faces sont bien parelles.
2040     if (!myDeltaFaceFace.IsParallel() ) {di<<"vdistdim error: the faces are not parallel. "<<"\n";return 1; }
2041     
2042     // recuperation des edges des faces.
2043     TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
2044     TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
2045     
2046     TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2047     TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
2048     
2049     // On recupere les  vertexes extremites des edge A et B.
2050     BRepAdaptor_Curve theCurveA(EdgeA);
2051     BRepAdaptor_Curve theCurveB(EdgeB);
2052     // On recupere 3 points A,B,C des  curves.
2053     gp_Pnt A=theCurveA.Value(0.1);
2054     gp_Pnt B=theCurveA.Value(0.9);
2055     gp_Pnt C=theCurveB.Value(0.5);
2056     
2057     // Construction du Geom_Plane
2058     GC_MakePlane MkPlane(A,B,C);
2059     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2060     // Fermeture du contexte local.
2061     TheAISContext()->CloseLocalContext(myCurrentIndex);
2062     // Construction de l'AIS_ParallelRelation
2063     Handle(AIS_ParallelRelation) myParaRelation= new AIS_ParallelRelation(FaceA ,FaceB ,theGeomPlane );
2064     TheAISContext()->Display(myParaRelation );
2065     GetMapOfAIS().Bind (myParaRelation ,argv[1]);
2066     
2067     
2068     
2069   }
2070   
2071   
2072   return 0;
2073   
2074 }
2075
2076
2077
2078
2079 //==============================================================================
2080 //function : VPerpendicularRelation
2081 //purpose  : Display the Perpendicular Relation
2082 //Draw arg : vperpendicular Name 
2083 //==============================================================================
2084 #include <AIS_PerpendicularRelation.hxx>
2085 #include <TCollection_ExtendedString.hxx>
2086 #include <GC_MakePlane.hxx>
2087 #include <BRepAdaptor_Curve.hxx>
2088 #include <TopExp_Explorer.hxx>
2089
2090
2091
2092 static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
2093 {
2094   // Declarations
2095   Standard_Integer myCurrentIndex;
2096  
2097   // Verification
2098   if (argc!=2) {di<<" vortho error"<<"\n";return 1;}
2099   
2100   // Fermeture des contextes locaux
2101   TheAISContext()->CloseAllContexts();
2102   
2103   // Ouverture d'un contexte local et recuperation de son index.
2104   TheAISContext()->OpenLocalContext();
2105   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
2106   
2107   // On active les modes de selections Edges.
2108   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2109   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2110   di<<" Select an edge or a face "<<"\n";
2111   
2112   // Boucle d'attente waitpick.
2113   Standard_Integer argcc = 5;
2114   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2115   const char **argvv = (const char **) buff;
2116   while (ViewerMainLoop( argcc, argvv) ) { }
2117   // fin de la boucle
2118   
2119   TopoDS_Shape ShapeA;
2120   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2121     ShapeA = TheAISContext()->SelectedShape();
2122   }
2123   
2124   // ShapeA est un edge.
2125   // ===================
2126   if (ShapeA.ShapeType()==TopAbs_EDGE ) {
2127     
2128     // desactivation du mode face
2129     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2130     di<<" Select a second edge"<<"\n";
2131     // Boucle d'attente waitpick.
2132     Standard_Integer argccc = 5;
2133     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2134     const char **argvvv = (const char **) bufff;
2135     while (ViewerMainLoop( argccc, argvvv) ) { }
2136     // fin de la boucle
2137     
2138     TopoDS_Shape ShapeB;
2139     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2140       ShapeB = TheAISContext()->SelectedShape();
2141     }
2142     
2143     // recuperation des edges.
2144     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
2145     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
2146     
2147     // On recupere les  curves
2148     BRepAdaptor_Curve theCurveA(EdgeA);
2149     BRepAdaptor_Curve theCurveB(EdgeB);
2150     // on verifie si les edges sont orthogonaux.
2151     //gp_Lin theLineA=theCurveA.Line();
2152     //gp_Lin theLineB=theCurveB.Line();
2153     //if (abs(theLineA.Angle(theLineB) ) != M_PI/2 ) {cout<<"vperpendicular error: Edges are not  othogonals."<<endl;return 1;}
2154     
2155     // On recupere 3 points A,B,C des  curves.
2156     gp_Pnt A=theCurveA.Value(0.1);
2157     gp_Pnt B=theCurveA.Value(0.9);
2158     gp_Pnt C=theCurveB.Value(0.5);
2159     // Construction du Geom_Plane
2160     GC_MakePlane MkPlane(A,B,C);
2161     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2162     // Fermeture du contexte local.
2163     TheAISContext()->CloseLocalContext(myCurrentIndex);
2164     // Construction de l'AIS_ParallelRelation
2165     Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation (EdgeA ,EdgeB ,theGeomPlane );
2166     TheAISContext()->Display(myOrthoRelation );
2167     GetMapOfAIS().Bind (myOrthoRelation ,argv[1]);
2168     
2169     
2170   }
2171   
2172   // Shape A est une face
2173   // ====================
2174   else {
2175     
2176     // desactivation du mode edge
2177     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2178     di<<" Select a second edge"<<"\n";
2179     // Boucle d'attente waitpick.
2180     Standard_Integer argccc = 5;
2181     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2182     const char **argvvv = (const char **) bufff;
2183     while (ViewerMainLoop( argccc, argvvv) ) { }
2184     // fin de la boucle
2185     
2186     TopoDS_Shape ShapeB;
2187     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2188       ShapeB = TheAISContext()->SelectedShape();
2189     }
2190     
2191     // pas de verification d'orthogonalite.
2192     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
2193     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
2194     
2195     // recuperation des edges des faces.
2196     TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
2197     TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
2198     
2199     TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2200     TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
2201     
2202     // On recupere les  vertexes extremites des edge A et B.
2203     BRepAdaptor_Curve theCurveA(EdgeA);
2204     BRepAdaptor_Curve theCurveB(EdgeB);
2205     // On recupere 3 points A,B,C des  curves.
2206     gp_Pnt A=theCurveA.Value(0.1);
2207     gp_Pnt B=theCurveA.Value(0.9);
2208     gp_Pnt C=theCurveB.Value(0.5);
2209     // Construction du Geom_Plane
2210     GC_MakePlane MkPlane(A,B,C);
2211     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2212     // Fermeture du contexte local.
2213     TheAISContext()->CloseLocalContext(myCurrentIndex);
2214     // Construction de l'AIS_PerpendicularRelation
2215     Handle(AIS_PerpendicularRelation) myOrthoRelation= new AIS_PerpendicularRelation(FaceA ,FaceB );
2216     TheAISContext()->Display(myOrthoRelation );
2217     GetMapOfAIS().Bind (myOrthoRelation  ,argv[1]);
2218     
2219     
2220     
2221   }
2222   
2223   
2224   return 0;
2225   
2226 }
2227
2228
2229 //==============================================================================
2230 //function : VTangentRelation
2231 //purpose  : Display the tangent Relation
2232 //Draw arg : vtangent Name 
2233 //==============================================================================
2234 #include <AIS_TangentRelation.hxx>
2235
2236
2237 static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
2238 {
2239   // Declarations
2240   Standard_Integer myCurrentIndex;
2241  
2242   // Verification
2243   if (argc!=2) {di<<" vtangent error"<<"\n";return 1;}
2244   
2245   // Fermeture des contextes locaux
2246   TheAISContext()->CloseAllContexts();
2247   
2248   // Ouverture d'un contexte local et recuperation de son index.
2249   TheAISContext()->OpenLocalContext();
2250   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
2251   
2252   // On active les modes de selections Edges.
2253   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2254   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
2255   di<<" Select two coplanar edges(First the circular edge then the tangent edge) or two faces "<<"\n";
2256   
2257   // Boucle d'attente waitpick.
2258   Standard_Integer argcc = 5;
2259   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2260   const char **argvv = (const char **) buff;
2261   while (ViewerMainLoop( argcc, argvv) ) { }
2262   // fin de la boucle
2263   
2264   TopoDS_Shape ShapeA;
2265   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2266     ShapeA = TheAISContext()->SelectedShape();
2267   }
2268   
2269   // ShapeA est un edge.
2270   // ===================
2271   if (ShapeA.ShapeType()==TopAbs_EDGE ) {
2272     
2273     // desactivation du mode face
2274     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(4) );
2275     di<<" Select a second edge"<<"\n";
2276     // Boucle d'attente waitpick.
2277     Standard_Integer argccc = 5;
2278     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2279     const char **argvvv = (const char **) bufff;
2280     while (ViewerMainLoop( argccc, argvvv) ) { }
2281     // fin de la boucle
2282     
2283     TopoDS_Shape ShapeB;
2284     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2285       ShapeB = TheAISContext()->SelectedShape();
2286     }
2287     
2288     // recuperation des edges.
2289     TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
2290     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
2291     
2292     // On recupere les  curves
2293     BRepAdaptor_Curve theCurveA(EdgeA);
2294     BRepAdaptor_Curve theCurveB(EdgeB);
2295     
2296     // On recupere 3 points A,B,C des  curves.
2297     gp_Pnt A=theCurveA.Value(0.1);
2298     gp_Pnt B=theCurveA.Value(0.9);
2299     gp_Pnt C=theCurveB.Value(0.5);
2300
2301     // Construction du Geom_Plane
2302     GC_MakePlane MkPlane(A,B,C);
2303     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2304     // Fermeture du contexte local.
2305     TheAISContext()->CloseLocalContext(myCurrentIndex);
2306     // Construction de l'AIS_TangentRelation
2307     Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation  (EdgeA ,EdgeB ,theGeomPlane );
2308     TheAISContext()->Display(myTanRelation );
2309     GetMapOfAIS().Bind (myTanRelation ,argv[1]);
2310     
2311     
2312   }
2313   
2314   // Shape A est une face
2315   // ====================
2316   else {
2317     
2318     // desactivation du mode edge
2319     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2320     di<<" Select a second edge"<<"\n";
2321     // Boucle d'attente waitpick.
2322     Standard_Integer argccc = 5;
2323     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2324     const char **argvvv = (const char **) bufff;
2325     while (ViewerMainLoop( argccc, argvvv) ) { }
2326     // fin de la boucle
2327     
2328     TopoDS_Shape ShapeB;
2329     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2330       ShapeB = TheAISContext()->SelectedShape();
2331     }
2332     
2333     TopoDS_Face  FaceA=TopoDS::Face(ShapeA);
2334     TopoDS_Face  FaceB=TopoDS::Face(ShapeB);
2335     
2336     // recuperation des edges des faces.
2337     TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
2338     TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
2339     
2340     TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2341     TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
2342     
2343     // On recupere les  vertexes extremites des edge A et B.
2344     BRepAdaptor_Curve theCurveA(EdgeA);
2345     BRepAdaptor_Curve theCurveB(EdgeB);
2346     // On recupere 3 points A,B,C des  curves.
2347     gp_Pnt A=theCurveA.Value(0.1);
2348     gp_Pnt B=theCurveA.Value(0.9);
2349     gp_Pnt C=theCurveB.Value(0.5);
2350
2351     // Construction du Geom_Plane
2352     GC_MakePlane MkPlane(A,B,C);
2353     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2354     // Fermeture du contexte local.
2355     TheAISContext()->CloseLocalContext(myCurrentIndex);
2356     // Construction de l'AIS_PerpendicularRelation
2357     Handle(AIS_TangentRelation) myTanRelation= new AIS_TangentRelation(FaceA ,FaceB,theGeomPlane );
2358     TheAISContext()->Display(myTanRelation );
2359     GetMapOfAIS().Bind (myTanRelation  ,argv[1]);
2360     
2361     
2362     
2363   }
2364   
2365   
2366   return 0;
2367   
2368 }
2369
2370 //==============================================================================
2371 //function : VSymetricalRelation
2372 //purpose  : Display the Symetrical Relation
2373 //Draw arg : vsymetric Name 
2374 //==============================================================================
2375 #include <AIS_SymmetricRelation.hxx>
2376 #include <AIS_InteractiveObject.hxx>
2377 #include <AIS_Dimension.hxx>
2378
2379
2380 static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
2381 {
2382   // Declarations
2383   Standard_Integer myCurrentIndex;
2384  
2385   // Verification
2386   if (argc!=2) {di<<" vSymmetric error"<<"\n";return 1;}
2387   
2388   // Fermeture des contextes locaux
2389   TheAISContext()->CloseAllContexts();
2390   
2391   // Ouverture d'un contexte local et recuperation de son index.
2392   TheAISContext()->OpenLocalContext();
2393   myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
2394   
2395   // On active les modes de selections
2396   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2397   di<<" Select an edge:the axis of symetry "<<"\n";
2398   
2399   // Boucle d'attente waitpick.
2400   Standard_Integer argcc = 5;
2401   const char *buff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2402   const char **argvv = (const char **) buff;
2403   while (ViewerMainLoop( argcc, argvv) ) { }
2404   // fin de la boucle
2405   
2406   TopoDS_Shape ShapeA;
2407   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2408     ShapeA = TheAISContext()->SelectedShape();
2409   }
2410   // recuperation des edges.
2411   TopoDS_Edge  EdgeA=TopoDS::Edge(ShapeA);
2412   
2413   // On active les modes de selections
2414   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2415   TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(1) );
2416   di<<" Select two edges or two vertices. "<<"\n";
2417   
2418   // Boucle d'attente waitpick.
2419   Standard_Integer argcc2 = 5;
2420 //  const char *buff2[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2421   const char **argvv2 = (const char **) buff;
2422   while (ViewerMainLoop( argcc2, argvv2) ) { }
2423   // fin de la boucle
2424   
2425   TopoDS_Shape ShapeB;
2426   for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2427     ShapeB = TheAISContext()->SelectedShape();
2428   }
2429   
2430   
2431   
2432   
2433   
2434   // ShapeB est un edge.
2435   // ===================
2436   if (ShapeB.ShapeType()==TopAbs_EDGE ) {
2437     
2438     // desactivation du mode vertex
2439     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(1) );
2440     di<<" Select a second edge"<<"\n";
2441     // Boucle d'attente waitpick.
2442     Standard_Integer argccc = 5;
2443     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2444     const char **argvvv = (const char **) bufff;
2445     while (ViewerMainLoop( argccc, argvvv) ) { }
2446     // fin de la boucle
2447     
2448     TopoDS_Shape ShapeC;
2449     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2450       ShapeC = TheAISContext()->SelectedShape();
2451     }
2452     
2453     // recuperation des edges.
2454     TopoDS_Edge  EdgeB=TopoDS::Edge(ShapeB);
2455     TopoDS_Edge  EdgeC=TopoDS::Edge(ShapeC);
2456     // on verifie que les edges sont paralleles
2457     BRepExtrema_ExtCC myDeltaEdgeAB (EdgeA ,EdgeB );
2458     BRepExtrema_ExtCC myDeltaEdgeAC (EdgeA ,EdgeC );
2459     // on verifie qu'ils  sont paralleles.
2460     if (!myDeltaEdgeAB.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
2461     if (!myDeltaEdgeAC.IsParallel() ) {di<<"vsymetric error: non parallel edges."<<"\n";return 1; }
2462     // on recupere les vertexs
2463     TopoDS_Vertex  Va,Vb,Vc,Vd;
2464     TopExp::Vertices(EdgeB,Va,Vb );
2465     TopExp::Vertices(EdgeC,Vc,Vd );
2466     gp_Pnt A=BRep_Tool::Pnt(Va);
2467     gp_Pnt B=BRep_Tool::Pnt(Vc);
2468     gp_Pnt C = Get3DPointAtMousePosition();
2469     
2470     //    gp_Pnt C=BRep_Tool::Pnt(Vc);
2471     // Construction du Geom_Plane
2472     GC_MakePlane MkPlane(A,B,C);
2473     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2474     // Fermeture du contexte local.
2475     TheAISContext()->CloseLocalContext(myCurrentIndex);
2476     // Construction de l'AIS_SymmetricRelation
2477     Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,EdgeB ,EdgeC, theGeomPlane );
2478     TheAISContext()->Display(mySymRelation );
2479     GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2480     
2481     
2482   }
2483   
2484   // Shape B est un vertex
2485   // =====================
2486   else {
2487     
2488     // desactivation du mode edge
2489     TheAISContext()->DeactivateStandardMode (AIS_Shape::SelectionType(2) );
2490     di<<" Select a second edge"<<"\n";
2491     // Boucle d'attente waitpick.
2492     Standard_Integer argccc = 5;
2493     const char *bufff[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2494     const char **argvvv = (const char **) bufff;
2495     while (ViewerMainLoop( argccc, argvvv) ) { }
2496     // fin de la boucle
2497     
2498     TopoDS_Shape ShapeC;
2499     for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2500       ShapeC = TheAISContext()->SelectedShape();
2501     }
2502     
2503     // recuperation des Vertex
2504     TopoDS_Vertex  VertexB=TopoDS::Vertex(ShapeB);
2505     TopoDS_Vertex  VertexC=TopoDS::Vertex(ShapeC);
2506     // transfo en gp_Pnt
2507     gp_Pnt B=BRep_Tool::Pnt(VertexB);
2508     gp_Pnt C=BRep_Tool::Pnt(VertexC);
2509     
2510     // on recupere les vertexes de l'axe de sym
2511     TopoDS_Vertex  Va,Vb;
2512     TopExp::Vertices(EdgeA,Va,Vb );
2513     gp_Pnt A=BRep_Tool::Pnt(Va);
2514     // Construction du Geom_Plane
2515     GC_MakePlane MkPlane(A,B,C);
2516     Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
2517     // Fermeture du contexte local.
2518     TheAISContext()->CloseLocalContext(myCurrentIndex);
2519     // Construction de l'AIS_SymmetricRelation
2520     Handle(AIS_SymmetricRelation) mySymRelation= new AIS_SymmetricRelation (EdgeA ,VertexB ,VertexC, theGeomPlane );
2521     TheAISContext()->Display(mySymRelation );
2522     GetMapOfAIS().Bind (mySymRelation ,argv[1]);
2523     
2524     
2525     
2526   }
2527   
2528   
2529   return 0;
2530   
2531 }
2532
2533 //=======================================================================
2534 //function : VDimParam
2535 //purpose  : Sets aspect parameters to dimension.
2536 //=======================================================================
2537 static int VDimParam (Draw_Interpretor& theDi, Standard_Integer theArgNum, const char** theArgVec)
2538 {
2539   if (theArgNum < 3)
2540   {
2541     theDi << theArgVec[0] << " error: the wrong number of input parameters.\n";
2542     return 1;
2543   }
2544
2545
2546   TCollection_AsciiString aName (theArgVec[1]);
2547   gp_Pln aWorkingPlane;
2548   Standard_Boolean isCustomPlane = Standard_False;
2549   Standard_Boolean toUpdate = Standard_True;
2550
2551   NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
2552   NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
2553
2554   if (!GetMapOfAIS().IsBound2 (aName))
2555   {
2556     theDi << theArgVec[0] << "error: no object with this name.\n";
2557     return 1;
2558   }
2559
2560   Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
2561   if (anObject->Type() != AIS_KOI_Dimension)
2562   {
2563     theDi << theArgVec[0] << "error: no dimension with this name.\n";
2564     return 1;
2565   }
2566
2567   Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (anObject);
2568   Handle(Prs3d_DimensionAspect) anAspect = aDim->DimensionAspect();
2569
2570   if (ParseDimensionParams (theArgNum, theArgVec, 2, anAspect,
2571                             isCustomPlane, aWorkingPlane,
2572                             aRealParams, aStringParams))
2573   {
2574     return 1;
2575   }
2576
2577   if (isCustomPlane)
2578   {
2579     aDim->SetCustomPlane (aWorkingPlane);
2580   }
2581
2582   SetDimensionParams (aDim, aRealParams, aStringParams);
2583
2584   if (!aDim->IsValid())
2585   {
2586     std::cerr << "Error: Dimension geometry or plane is not valid.\n";
2587     return 1;
2588   }
2589
2590   // Redisplay a dimension after parameter changing.
2591   if (ViewerTest::GetAISContext()->IsDisplayed (aDim))
2592   {
2593     ViewerTest::GetAISContext()->Redisplay (aDim, toUpdate);
2594   }
2595
2596   return 0;
2597 }
2598
2599 //=======================================================================
2600 //function : VMoveDim
2601 //purpose  : Moves dimension or relation text label to defined or picked
2602 //           position and updates the object.
2603 //draw args: vmovedim [name] [x y z]
2604 //=======================================================================
2605 static int VMoveDim (Draw_Interpretor& theDi, Standard_Integer theArgNum, const char** theArgVec) 
2606 {
2607   if (theArgNum > 5)
2608   {
2609     theDi << theArgVec[0] << " error: the wrong number of parameters.\n";
2610     return 1;
2611   }
2612
2613   // Parameters parsing
2614   Standard_Boolean isNameSet = (theArgNum ==2 || theArgNum == 5);
2615   Standard_Boolean isPointSet = (theArgNum == 4 || theArgNum == 5);
2616
2617   Handle(AIS_InteractiveObject) aPickedObj;
2618   gp_Pnt aPoint (gp::Origin());
2619   Standard_Integer aMaxPickNum = 5;
2620
2621   // Find object
2622   if (isNameSet)
2623   {
2624      TCollection_AsciiString aName (theArgVec[1]);
2625      if (!GetMapOfAIS().IsBound2 (aName))
2626      {
2627        theDi << theArgVec[0] << " error: no object with this name.\n";
2628        return 1;
2629      }
2630
2631      aPickedObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2632      
2633      if (aPickedObj.IsNull())
2634      {
2635        theDi << theArgVec[0] << " error: the object with this name is not valid.\n";
2636        return 1;
2637      }
2638
2639      if (aPickedObj->Type() != AIS_KOI_Dimension && aPickedObj->Type() != AIS_KOI_Relation)
2640      {
2641        theDi << theArgVec[0] << " error: no dimension or relation with this name.\n";
2642        return 1;
2643      }
2644   }
2645   else // Pick dimension or relation
2646   {
2647     // Close all local contexts
2648     TheAISContext()->CloseAllContexts();
2649
2650     // Open local context and get its index for recovery.
2651     TheAISContext()->OpenLocalContext();
2652
2653     // Loop that will be handle picking.
2654     Standard_Integer anArgNum = 5;
2655     const char *aBuffer[] = { "VPick", "X", "VPickY","VPickZ", "VPickShape" };
2656     const char **anArgVec = (const char **) aBuffer;
2657
2658     Standard_Boolean isPicked = Standard_False;
2659     Standard_Integer aPickNum = 0;
2660     while (!isPicked && aPickNum < aMaxPickNum)
2661     {
2662       while (ViewerMainLoop (anArgNum, anArgVec)) { }
2663
2664       for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
2665       {
2666         aPickedObj = TheAISContext()->SelectedInteractive();
2667       }
2668
2669       isPicked = (!aPickedObj.IsNull() && (aPickedObj->Type() == AIS_KOI_Dimension || aPickedObj->Type() == AIS_KOI_Relation));
2670
2671       if (isPicked)
2672       {
2673         break;
2674       }
2675       aPickNum++;
2676     }
2677     if (!isPicked)
2678     {
2679       theDi << theArgVec[0] << ": no dimension or relation is selected." << "\n";
2680       return 1;
2681     }
2682   }
2683
2684   // Find point
2685   if (isPointSet)
2686   {
2687     aPoint = theArgNum == 4 ? gp_Pnt (atoi (theArgVec[1]), atoi (theArgVec[2]), atoi (theArgVec[3]))
2688                             : gp_Pnt (atoi (theArgVec[2]), atoi (theArgVec[3]), atoi (theArgVec[4]));
2689   }
2690   else // Pick the point
2691   {
2692     Standard_Integer aPickArgNum = 5;
2693     const char *aPickBuff[] = {"VPick", "X", "VPickY", "VPickZ", "VPickShape"};
2694     const char **aPickArgVec = (const char **) aPickBuff;
2695
2696     while (ViewerMainLoop (aPickArgNum, aPickArgVec)) { }
2697
2698     // Set text position, update relation or dimension.
2699     if (aPickedObj->Type() == AIS_KOI_Relation)
2700     {
2701       Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (aPickedObj);
2702       aPoint = Get3DPointAtMousePosition();
2703       aRelation->SetPosition (aPoint);
2704       TheAISContext()->Redisplay (aRelation);
2705     }
2706     else
2707     {
2708       Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (aPickedObj);
2709       gp_Pnt aFirstPoint, aSecondPoint;
2710       if (aDim->KindOfDimension() == AIS_KOD_PLANEANGLE)
2711       {
2712         Handle(AIS_AngleDimension) anAngleDim = Handle(AIS_AngleDimension)::DownCast (aDim);
2713         aFirstPoint = anAngleDim->FirstPoint();
2714         aSecondPoint = anAngleDim->SecondPoint();
2715       }
2716       else if (aDim->KindOfDimension() == AIS_KOD_LENGTH)
2717       {
2718         Handle(AIS_LengthDimension) aLengthDim = Handle(AIS_LengthDimension)::DownCast (aDim);
2719         aFirstPoint = aLengthDim->FirstPoint();
2720         aSecondPoint = aLengthDim->SecondPoint();
2721       }
2722       else if (aDim->KindOfDimension() == AIS_KOD_RADIUS)
2723       {
2724         Handle(AIS_RadiusDimension) aRadiusDim = Handle(AIS_RadiusDimension)::DownCast (aDim);
2725         aFirstPoint = aRadiusDim->AnchorPoint();
2726         aSecondPoint = aRadiusDim->Circle().Location();
2727       }
2728       else if (aDim->KindOfDimension() == AIS_KOD_DIAMETER)
2729       {
2730         Handle(AIS_DiameterDimension) aDiameterDim = Handle(AIS_DiameterDimension)::DownCast (aDim);
2731         aFirstPoint = aDiameterDim->AnchorPoint();
2732         aSecondPoint = aDiameterDim->Circle().Location();
2733       }
2734
2735       if (!Get3DPointAtMousePosition (aFirstPoint, aSecondPoint, aPoint))
2736       {
2737         return 1;
2738       }
2739
2740       aDim->SetTextPosition (aPoint);
2741       TheAISContext()->Redisplay (aDim);
2742     }
2743
2744   }
2745
2746   // Set text position, update relation or dimension.
2747   if (aPickedObj->Type() == AIS_KOI_Relation)
2748   {
2749     Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (aPickedObj);
2750     aRelation->SetPosition (aPoint);
2751     TheAISContext()->Redisplay (aRelation);
2752   }
2753   else
2754   {
2755     Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (aPickedObj);
2756     aDim->SetTextPosition (aPoint);
2757     TheAISContext()->Redisplay (aDim);
2758   }
2759
2760   return 0;
2761 }
2762
2763 //=======================================================================
2764 //function : RelationsCommands
2765 //purpose  : 
2766 //=======================================================================
2767       
2768
2769 void ViewerTest::RelationCommands(Draw_Interpretor& theCommands)
2770 {
2771   const char *group = "AISRelations";
2772
2773   theCommands.Add("vdimension",
2774       "vdimension name {-angle|-length|-radius|-diameter} -shapes shape1 [shape2 [shape3]]\n"
2775       "[-text 3d|2d wf|sh|wireframe|shading IntegerSize]\n"
2776       "[-font FontName]\n"
2777       "[-label left|right|hcenter|hfit top|bottom|vcenter|vfit]\n"
2778       "[-arrow external|internal|fit]\n"
2779       "[{-arrowlength|-arlen} RealArrowLength]\n"
2780       "[{-arrowangle|-arangle} ArrowAngle(degrees)]\n"
2781       "[-plane xoy|yoz|zox]\n"
2782       "[-flyout FloatValue -extension FloatValue]\n"
2783       "[-value CustomNumberValue]\n"
2784       "[-dispunits DisplayUnitsString]\n"
2785       "[-modelunits ModelUnitsString]\n"
2786       "[-showunits | -hideunits]\n"
2787       " -Builds angle, length, radius and diameter dimensions.\n"
2788       " -See also: vdimparam, vmovedim.\n",
2789       __FILE__,VDimBuilder,group);
2790
2791   theCommands.Add("vdimparam",
2792     "vdimparam name"
2793     "[-text 3d|2d wf|sh|wireframe|shading IntegerSize]\n"
2794     "[-font FontName]\n"
2795     "[-label left|right|hcenter|hfit top|bottom|vcenter|vfit]\n"
2796     "[-arrow external|internal|fit]\n"
2797     "[{-arrowlength|-arlen} RealArrowLength]\n"
2798     "[{-arrowangle|-arangle} ArrowAngle(degrees)]\n"
2799     "[-plane xoy|yoz|zox]\n"
2800     "[-flyout FloatValue -extension FloatValue]\n"
2801     "[-value CustomNumberValue]\n"
2802     "[-dispunits DisplayUnitsString]\n"
2803     "[-modelunits ModelUnitsString]\n"
2804     "[-showunits | -hideunits]\n"
2805     " -Sets parameters for angle, length, radius and diameter dimensions.\n"
2806     " -See also: vmovedim, vdimension.\n",
2807     __FILE__,VDimParam,group);
2808
2809   theCommands.Add("vangledim",
2810                   "vangledim Name:Selection in the viewer only ",
2811                   __FILE__,VAngleDimBuilder,group);
2812   
2813   theCommands.Add("vdiameterdim",
2814                   "vdiameterdim Name : Selection in the viewer only ",
2815                   __FILE__,VDiameterDimBuilder,group);
2816   
2817   theCommands.Add("vconcentric",
2818                   "vconcentric Name : Selection in the viewer only ",
2819                   __FILE__,VConcentricBuilder,group);
2820
2821   theCommands.Add("vequaldist",
2822                   "vequaldist Name Selection in the viewer only ",
2823                   __FILE__,VEqualDistRelation ,group);
2824   
2825   theCommands.Add("vequalrad",
2826                   "vequalrad Name Selection in the viewer only ",
2827                   __FILE__,VEqualRadiusRelation  ,group);
2828   
2829   theCommands.Add("vfix",  
2830                   "vfix Name Selection in the viewer only ",
2831                   __FILE__,VFixRelation  ,group);
2832   
2833   theCommands.Add("videntity",
2834                   "videntity Name Selection in the viewer only ",
2835                   __FILE__,VIdenticRelation  ,group);
2836   
2837   theCommands.Add("vdistdim",
2838                   "vdistdim Name Selection in the viewer only ",
2839                   __FILE__,VLenghtDimension ,group);
2840   
2841   theCommands.Add("vradiusdim",
2842                   "vradiusdim Name Selection in the viewer only ",
2843                   __FILE__,VRadiusDimBuilder ,group);
2844   
2845   theCommands.Add("voffsetdim",
2846                   "voffsetdim Name Selection in the viewer only ",
2847                   __FILE__,VOffsetDimBuilder ,group);
2848   
2849   theCommands.Add("vparallel",
2850                   "vparallel Name Selection in the viewer only ",
2851                   __FILE__,VParallelBuilder ,group);
2852   
2853   theCommands.Add("vortho",
2854                   "vortho Name Selection in the viewer only ",
2855                   __FILE__,VPerpendicularBuilder ,group);
2856   
2857   theCommands.Add("vtangent",  
2858                   "vtangent Name Selection in the viewer only ",
2859                   __FILE__,VTangentBuilder ,group);
2860   
2861   
2862   theCommands.Add("vsymetric",
2863                   "vsymetric Name Selection in the viewer only ",
2864                   __FILE__,VSymmetricBuilder ,group);
2865
2866   theCommands.Add("vmovedim",
2867                   "vmovedim [name] [x y z]: moves picked or named (if name defined) "
2868           "dimension to picked mouse position or input point.",
2869                   __FILE__,VMoveDim,group);
2870
2871 }