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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest.hxx>
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>
38 #include <Draw_Appli.hxx>
39 #include <Draw_Window.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>
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>
61 #include <TopAbs_ShapeEnum.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>
70 #include <ViewerTest_DoubleMapOfInteractiveAndName.hxx>
71 #include <ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx>
72 #include <ViewerTest_EventManager.hxx>
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 ();
81 #define VertexMask 0x01
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()
92 Handle(V3d_View) aView = ViewerTest::CurrentView();
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));
100 Standard_Integer aPixX, aPixY;
101 Standard_Real aX, aY, aZ, aDX, aDY, aDZ;
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) );
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)
115 return anIntersector.Point (1);
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)
127 theOutputPoint = gp::Origin();
129 Handle(V3d_View) aView = ViewerTest::CurrentView();
131 Standard_Integer aPixX, aPixY;
132 Standard_Real aX, aY, aZ, aDx, aDy, aDz, aUx, aUy, aUz;
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));
140 gp_Vec aDimVec (theFirstPoint, theSecondPoint);
141 aView->Up (aUx, aUy, aUz);
142 gp_Vec aViewUp (aUx, aUy, aUz);
144 if (aDimVec.IsParallel (aViewUp, Precision::Angular()))
146 theOutputPoint = Get3DPointAtMousePosition();
147 return Standard_True;
150 gp_Vec aDimNormal = aDimVec ^ aViewUp;
151 gp_Pln aViewPlane= gce_MakePln (theFirstPoint, aDimNormal);
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)
159 return Standard_False;
162 theOutputPoint = anIntersector.Point (1);
163 return Standard_True;
166 //=======================================================================
167 //function : ParseDimensionParams
168 //purpose : Auxilliary function: sets aspect parameters for
169 // length, angle, radius and diameter dimension.
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
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)
196 theRealParams.Clear();
197 theStringParams.Clear();
199 theIsCustomPlane = Standard_False;
201 // Begin from the second parameter: the first one is dimension name
202 for (Standard_Integer anIt = theStartIndex; anIt < theArgNum; ++anIt)
204 TCollection_AsciiString aParam (theArgVec[anIt]);
207 if (aParam.Search ("-") == -1)
213 if (aParam.IsEqual ("-showunits"))
215 theAspect->MakeUnitsDisplayed (Standard_True);
218 else if (aParam.IsEqual ("-hideunits"))
220 theAspect->MakeUnitsDisplayed (Standard_False);
224 // Before all non-boolean flags parsing check if a flag have at least one value.
225 if (anIt + 1 >= theArgNum)
227 std::cerr << "Error: "<< aParam <<" flag should have value.\n";
232 if (aParam.IsEqual ("-shape")
233 || aParam.IsEqual ("-shapes"))
237 std::cerr << "Error: unknown parameter '" << aParam << "'\n";
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())
250 anAISObject = new AIS_Shape (aShape);
254 if (!GetMapOfAIS().IsBound2 (anArgString))
256 std::cerr << "Error: shape with name '" << aStr << "' is not found.\n";
260 anAISObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString));
261 if (anAISObject.IsNull())
263 std::cerr << "Error: " << aStr <<" is not a shape.\n";
267 theShapeList->Append (anAISObject);
269 while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
271 else if (aParam.IsEqual ("-text"))
276 TCollection_AsciiString aValue (theArgVec[anIt]);
278 if (aValue.IsEqual ("3d"))
280 theAspect->MakeText3d (Standard_True);
282 else if (aValue.IsEqual ("2d"))
284 theAspect->MakeText3d (Standard_False);
286 else if (aValue.IsEqual ("wf") || aValue.IsEqual ("wireframe"))
288 theAspect->MakeTextShaded (Standard_False);
290 else if ( aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
292 theAspect->MakeTextShaded (Standard_True);
294 else if (aValue.IsIntegerValue()) // text size
296 theAspect->TextAspect()->SetHeight (Draw::Atoi (aValue.ToCString()));
299 while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
301 else if (aParam.IsEqual ("-font"))
303 if (anIt + 1 >= theArgNum)
305 std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
309 theAspect->TextAspect()->SetFont (theArgVec[++anIt]);
311 else if (aParam.IsEqual ("-label"))
316 TCollection_AsciiString aParamValue (theArgVec[anIt]);
317 aParamValue.LowerCase();
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);}
328 std::cerr << "Error: invalid label position: '" << aParamValue << "'.\n";
332 while (anIt + 1 < theArgNum && theArgVec[anIt+1][0] != '-');
334 else if (aParam.IsEqual ("-arrow"))
336 TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
337 aLocalParam.LowerCase();
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); }
343 else if (aParam.IsEqual ("-arrowlength") || aParam.IsEqual ("-arlen"))
345 TCollection_AsciiString aValue (theArgVec[++anIt]);
346 if (!aValue.IsRealValue())
348 std::cerr << "Error: arrow lenght should be float degree value.\n";
351 theAspect->ArrowAspect()->SetLength (Draw::Atof (aValue.ToCString()));
353 else if (aParam.IsEqual ("-arrowangle") || aParam.IsEqual ("-arangle"))
355 TCollection_AsciiString aValue (theArgVec[++anIt]);
356 if (!aValue.IsRealValue())
358 std::cerr << "Error: arrow angle should be float degree value.\n";
361 theAspect->ArrowAspect()->SetAngle (Draw::Atof (aValue.ToCString()));
363 else if (aParam.IsEqual ("-color"))
365 theAspect->SetCommonColor (Quantity_Color (ViewerTest::GetColorFromName (theArgVec[++anIt])));
367 else if (aParam.IsEqual ("-extension"))
369 TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
370 if (!aLocalParam.IsRealValue())
372 std::cerr << "Error: extension size for dimension should be real value.\n";
375 theAspect->SetExtensionSize (Draw::Atof (aLocalParam.ToCString()));
377 else if (aParam.IsEqual ("-plane"))
379 TCollection_AsciiString aValue (theArgVec[++anIt]);
383 theIsCustomPlane = Standard_True;
384 thePlane = gp_Pln (gp_Ax3 (gp::XOY()));
386 else if (aValue == "zox")
388 theIsCustomPlane = Standard_True;
389 thePlane = gp_Pln (gp_Ax3 (gp::ZOX()));
391 else if (aValue == "yoz")
393 theIsCustomPlane = Standard_True;
394 thePlane = gp_Pln (gp_Ax3 (gp::YOZ()));
398 std::cerr << "Error: wrong plane '" << aValue << "'.\n";
402 else if (aParam.IsEqual ("-flyout"))
404 TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
405 if (!aLocalParam.IsRealValue())
407 std::cerr << "Error: flyout for dimension should be real value.\n";
411 theRealParams.Bind ("flyout", Draw::Atof (aLocalParam.ToCString()));
413 else if (aParam.IsEqual ("-value"))
415 TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
416 if (!aLocalParam.IsRealValue())
418 std::cerr << "Error: dimension value for dimension should be real value.\n";
422 theRealParams.Bind ("value", Draw::Atof (aLocalParam.ToCString()));
424 else if (aParam.IsEqual ("-modelunits"))
426 TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
428 theStringParams.Bind ("modelunits", aLocalParam);
430 else if (aParam.IsEqual ("-dispunits"))
432 TCollection_AsciiString aLocalParam(theArgVec[++anIt]);
434 theStringParams.Bind ("dispunits", aLocalParam);
438 std::cerr << "Error: unknown parameter '" << aParam << "'.\n";
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)
454 if (theRealParams.IsBound ("flyout"))
456 theDim->SetFlyout (theRealParams.Find ("flyout"));
459 if (theRealParams.IsBound ("value"))
461 theDim->SetCustomValue (theRealParams.Find ("value"));
464 if (theStringParams.IsBound ("modelunits"))
466 theDim->SetModelUnits (theStringParams.Find ("modelunits"));
469 if (theStringParams.IsBound ("dispunits"))
471 theDim->SetDisplayUnits (theStringParams.Find ("dispunits"));
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)
486 std::cerr << "Error: wrong number of arguments.\n";
491 TCollection_AsciiString aName (theArgs[1]);
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;
498 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
499 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
501 TCollection_AsciiString aDimType(theArgs[2]);
502 aDimType.LowerCase();
503 AIS_KindOfDimension aKindOfDimension;
504 if (aDimType == "-length")
506 aKindOfDimension = AIS_KOD_LENGTH;
508 else if (aDimType == "-angle")
510 aKindOfDimension = AIS_KOD_PLANEANGLE;
512 else if (aDimType == "-radius")
514 aKindOfDimension = AIS_KOD_RADIUS;
516 else if (aDimType == "-diameter" || aDimType == "-diam")
518 aKindOfDimension = AIS_KOD_DIAMETER;
522 std::cerr << "Error: wrong type of dimension.\n";
527 if (ParseDimensionParams (theArgsNb, theArgs, 3,
528 anAspect,isPlaneCustom,aWorkingPlane,
529 aRealParams, aStringParams, &aShapes))
535 Handle(AIS_Dimension) aDim;
536 switch (aKindOfDimension)
542 std::cerr << theArgs[0] << ": can not build dimension without working plane.\n";
545 if (aShapes.Extent() == 1)
547 if (aShapes.First()->Type() == AIS_KOI_Shape
548 && (Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape().ShapeType() != TopAbs_EDGE)
550 std::cerr << theArgs[0] << ": wrong shape type.\n";
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);
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());
562 else if (aShapes.Extent() == 2)
564 TopoDS_Shape aShape1, aShape2;
567 if (aShapes.First()->DynamicType() == STANDARD_TYPE (AIS_Point))
569 Handle(AIS_Point) aPoint1 = Handle(AIS_Point)::DownCast (aShapes.First ());
570 aShape1 = aPoint1->Vertex();
572 else if (aShapes.First()->Type() == AIS_KOI_Shape)
574 aShape1 = (Handle(AIS_Shape)::DownCast (aShapes.First()))->Shape();
577 if (aShapes.Last()->DynamicType() == STANDARD_TYPE (AIS_Point))
579 Handle(AIS_Point) aPoint2 = Handle(AIS_Point)::DownCast (aShapes.Last ());
580 aShape2 = aPoint2->Vertex();
582 else if (aShapes.Last()->Type() == AIS_KOI_Shape)
584 aShape2 = (Handle(AIS_Shape)::DownCast (aShapes.Last()))->Shape();
587 if (aShape1.IsNull() || aShape2.IsNull())
589 std::cerr << theArgs[0] << ": wrong shape type.\n";
593 // Adjust working plane
594 if (aShape1.ShapeType() == TopAbs_VERTEX)
596 aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape1)));
598 else if (aShape2.ShapeType() == TopAbs_VERTEX)
600 aWorkingPlane.SetLocation (BRep_Tool::Pnt (TopoDS::Vertex (aShape2)));
603 aDim = new AIS_LengthDimension (aShape1, aShape2, aWorkingPlane);
607 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
613 case AIS_KOD_PLANEANGLE:
615 if (aShapes.Extent() == 1 && aShapes.First()->Type()==AIS_KOI_Shape)
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()));
621 if (aShapes.Extent() == 2)
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()));
631 std::cerr << theArgs[0] << ": wrong shapes for angle dimension.\n";
635 else if (aShapes.Extent() == 3)
637 gp_Pnt aP1, aP2, aP3;
638 Handle(AIS_Point) aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
641 aP1 = aPoint->Component()->Pnt();
642 aShapes.RemoveFirst();
643 aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
646 aP2 = aPoint->Component()->Pnt();
647 aShapes.RemoveFirst();
648 aPoint = Handle(AIS_Point)::DownCast (aShapes.First());
651 aP3 = aPoint->Component()->Pnt();
652 aDim = new AIS_AngleDimension (aP1, aP2, aP3);
656 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
662 case AIS_KOD_RADIUS: // radius of the circle
664 if (aShapes.Extent() == 1)
666 if (aShapes.First()->DynamicType() == STANDARD_TYPE(AIS_Circle))
668 Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
669 gp_Circ aCircle = aShape->Circle()->Circ();
670 aDim = new AIS_RadiusDimension (aCircle);
674 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aShapes.First());
677 std::cerr << "Error: shape for radius is of wrong type.\n";
680 aDim = new AIS_RadiusDimension (aShape->Shape());
685 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
691 case AIS_KOD_DIAMETER:
693 if (aShapes.Extent() == 1)
695 if (aShapes.First()->DynamicType() == STANDARD_TYPE(AIS_Circle))
697 Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
698 gp_Circ aCircle = aShape->Circle()->Circ();
699 aDim = new AIS_DiameterDimension (aCircle);
703 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aShapes.First());
706 std::cerr << "Error: shape for radius is of wrong type.\n";
709 aDim = new AIS_DiameterDimension (aShape->Shape());
714 std::cerr << theArgs[0] << ": wrong number of shapes to build dimension.\n";
722 std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n";
727 // Check dimension geometry
728 if (!aDim->IsValid())
730 std::cerr << theArgs[0] << ":dimension geometry is invalid, " << aDimType.ToCString()
731 << " dimension can't be built on input shapes.\n";
735 aDim->SetDimensionAspect (anAspect);
737 SetDimensionParams (aDim, aRealParams, aStringParams);
739 VDisplayAISObject (aName,aDim);
744 //=======================================================================
745 //function : VAngleDimBuilder
747 //=======================================================================
749 static int VAngleDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
751 Standard_Integer aCurrentIndex;
754 di << argv[0] << " error : wrong number of parameters.\n";
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";
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)) { }
769 TopoDS_Shape aFirstShape;
770 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
772 aFirstShape = TheAISContext()->SelectedShape();
775 if (aFirstShape.IsNull())
777 di << argv[0] << " error : no picked shape.\n";
781 if (aFirstShape.ShapeType()== TopAbs_EDGE)
783 while (ViewerMainLoop (anArgsNum, anArgsVec)) { }
785 TopoDS_Shape aSecondShape;
786 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
788 aSecondShape = TheAISContext()->SelectedShape();
791 if (aSecondShape.IsNull())
793 di << argv[0] << " error : no picked shape.\n";
797 if (aSecondShape.ShapeType() != TopAbs_EDGE)
799 di << argv[0] <<" error: you should have selected an edge.\n"; return 1;
802 // Close local context to draw dimension in the neutral point.
803 TheAISContext()->CloseLocalContext (aCurrentIndex);
805 // Construct the dimension.
806 Handle (AIS_AngleDimension) aDim= new AIS_AngleDimension (TopoDS::Edge(aFirstShape) ,TopoDS::Edge(aSecondShape));
807 VDisplayAISObject (argv[1], aDim);
811 di << argv[0] << " error: you must select 2 edges.\n";
818 //==============================================================================
819 //function : VDiameterDim
820 //purpose : Display the diameter dimension of a face or an edge.
821 //Draw arg : vdiameterdim Name
822 //==============================================================================
824 static int VDiameterDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
827 Standard_Integer aCurrentIndex;
832 di<<" vdiameterdim error"<<"\n";
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();
842 // Activate 'edge' selection mode
843 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
844 di<<" Select an circled edge."<<"\n";
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) ) { }
854 for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
856 aShape = TheAISContext()->SelectedShape();
861 di << argv[0] << ": no shape is selected." << "\n";
865 if (aShape.ShapeType() != TopAbs_EDGE)
867 di << " vdiameterdim error: the selection of a face or an edge was expected." << "\n";
871 // Compute the radius
872 BRepAdaptor_Curve aCurve (TopoDS::Edge (aShape));
874 if (aCurve.GetType() != GeomAbs_Circle)
876 di << "vdiameterdim error: the edge is not a circular one." << "\n";
880 // Construction of the diameter dimension.
881 TheAISContext()->CloseLocalContext (aCurrentIndex);
882 Handle (AIS_DiameterDimension) aDiamDim= new AIS_DiameterDimension (aShape);
883 VDisplayAISObject (argv[1], aDiamDim);
889 //==============================================================================
890 // Fonction vconcentric
891 // ----------------- Uniquement par selection dans le viewer.
892 //==============================================================================
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>
907 static int VConcentricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
910 Standard_Integer myCurrentIndex;
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();
920 // On active les modes de selections Edges et Faces.
921 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
922 di<<" Select a circled edge."<<"\n";
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) ) { }
932 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
933 ShapeA = TheAISContext()->SelectedShape();
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";
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) ) { }
949 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
950 ShapeB = TheAISContext()->SelectedShape();
952 if (ShapeB.ShapeType()!=TopAbs_EDGE ) {
953 di<<" vconcentric error: select an edge."<<"\n";return 1;
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();
968 // Fermeture du context local
969 TheAISContext()->CloseLocalContext(myCurrentIndex);
971 Handle (AIS_ConcentricRelation) myConcentry= new AIS_ConcentricRelation(ShapeA, ShapeB, theGeomPlane );
972 TheAISContext()->Display(myConcentry );
973 GetMapOfAIS().Bind (myConcentry,argv[1]);
978 di<<" vconcentric error: the selection of a face or an edge was expected."<<"\n";return 1;
988 //==============================================================================
989 //function : VEqualDistRelation
991 //Draw arg : vdiameterdim Name DiameterValue
992 //==============================================================================
993 #include <AIS_EqualDistanceRelation.hxx>
994 #include <BRepExtrema_ExtCC.hxx>
995 #include <GC_MakePlane.hxx>
998 static int VEqualDistRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1001 Standard_Integer myCurrentIndex;
1004 if (argc!=2) {di<<" vequaldistrelation error: no arguments allowed."<<"\n";return 1;}
1006 // Fermeture des contextes locaux
1007 TheAISContext()->CloseAllContexts();
1009 // Ouverture d'un contexte local et recuperation de son index.
1010 TheAISContext()->OpenLocalContext();
1011 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
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";
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) ) { }
1025 TopoDS_Shape ShapeA;
1026 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1027 ShapeA = TheAISContext()->SelectedShape();
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) ) { }
1038 TopoDS_Shape ShapeB;
1039 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1040 ShapeB = TheAISContext()->SelectedShape();
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; }
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) ) { }
1061 TopoDS_Shape ShapeC;
1062 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1063 ShapeC = TheAISContext()->SelectedShape();
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) ) { }
1074 TopoDS_Shape ShapeD;
1075 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1076 ShapeD = TheAISContext()->SelectedShape();
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; }
1087 // Creation du plan porteur de la contrainte.Methode lourde!
1089 if (ShapeA.ShapeType()==TopAbs_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);
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);
1106 C=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1111 A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1113 if (ShapeB.ShapeType()==TopAbs_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);
1124 B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
1132 // Fermeture du context local.
1133 TheAISContext()->CloseLocalContext(myCurrentIndex);
1135 // construction du plane
1136 GC_MakePlane MkPlane(A ,B ,C );
1137 Handle(Geom_Plane) theGeomPlane=MkPlane.Value();
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]);
1150 //==============================================================================
1151 //function : VEqualRadiusRelation
1153 //Draw arg : vdiameterdim Name DiameterValue
1154 //==============================================================================
1155 #include <AIS_EqualRadiusRelation.hxx>
1156 #include <GC_MakePlane.hxx>
1157 #include <BRepAdaptor_Curve.hxx>
1160 static int VEqualRadiusRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1163 Standard_Integer myCurrentIndex;
1166 if (argc!=2) {di<<" vequalrad error: no arguments allowed."<<"\n";return 1;}
1168 // Fermeture des contextes locaux
1169 TheAISContext()->CloseAllContexts();
1171 // Ouverture d'un contexte local et recuperation de son index.
1172 TheAISContext()->OpenLocalContext();
1173 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1175 // On active les modes de selections Edges.
1176 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1177 di<<" Select an circled edge "<<"\n";
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) ) { }
1186 TopoDS_Shape ShapeA;
1187 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1188 ShapeA = TheAISContext()->SelectedShape();
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) ) { }
1199 TopoDS_Shape ShapeB;
1200 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1201 ShapeB = TheAISContext()->SelectedShape();
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);
1212 // fermeture du contexte local.
1213 TheAISContext()->CloseLocalContext(myCurrentIndex);
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]);
1228 //==============================================================================
1229 //function : VFixRelation
1231 //Draw arg : vdiameterdim Name DiameterValue
1232 //==============================================================================
1233 #include <AIS_FixRelation.hxx>
1234 #include <GC_MakePlane.hxx>
1235 #include <BRepAdaptor_Curve.hxx>
1237 static int VFixRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1240 Standard_Integer myCurrentIndex;
1243 if (argc!=2) {di<<" vfix error: no arguments allowed."<<"\n";return 1;}
1245 // Fermeture des contextes locaux
1246 TheAISContext()->CloseAllContexts();
1248 // Ouverture d'un contexte local et recuperation de son index.
1249 TheAISContext()->OpenLocalContext();
1250 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1252 // On active les modes de selections edge.
1253 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
1254 di<<" Select an edge. "<<"\n";
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) ) { }
1263 TopoDS_Shape ShapeA;
1264 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1265 ShapeA = TheAISContext()->SelectedShape();
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);
1277 // fermeture du contexte local.
1278 TheAISContext()->CloseLocalContext(myCurrentIndex);
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]);
1293 //==============================================================================
1294 //function : VIdenticRelation
1296 //Draw arg : vdiameterdim Name DiameterValue
1297 //==============================================================================
1298 #include <AIS_IdenticRelation.hxx>
1299 #include <BRepAdaptor_Curve.hxx>
1300 #include <TopExp_Explorer.hxx>
1303 static int VIdenticRelation(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1306 Standard_Integer myCurrentIndex;
1309 if (argc!=2) {di<<" videntity error: no arguments allowed."<<"\n";return 1;}
1311 // Fermeture des contextes locaux
1312 TheAISContext()->CloseAllContexts();
1314 // Ouverture d'un contexte local et recuperation de son index.
1315 TheAISContext()->OpenLocalContext();
1316 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
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";
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) ) { }
1331 TopoDS_Shape ShapeA;
1332 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1333 ShapeA = TheAISContext()->SelectedShape();
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) ) { }
1344 TopoDS_Shape ShapeB;
1345 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1346 ShapeB = TheAISContext()->SelectedShape();
1349 // Recuperation de points pour construir le Geom_Plnae.
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);
1363 else if (ShapeA.ShapeType()==TopAbs_VERTEX ) {
1364 // SahpeA est un Vertex
1365 // On va utiliser ShapeB
1366 if (ShapeB.ShapeType()==TopAbs_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);
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);
1393 // B ets un vetex aussi
1394 A=BRep_Tool::Pnt(TopoDS::Vertex(ShapeA) );
1395 B=BRep_Tool::Pnt(TopoDS::Vertex(ShapeB) );
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);
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();
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]);
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>
1451 static int VLenghtDimension(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1454 Standard_Integer aCurrentIndex;
1458 di << argv[0] << " error: wrong number of arguments.\n";
1462 // Close all local contexts
1463 TheAISContext()->CloseAllContexts();
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));
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) ) { }
1481 TopoDS_Shape aFirstShape;
1482 for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
1484 aFirstShape = TheAISContext()->SelectedShape();
1487 if (aFirstShape.IsNull())
1489 di << argv[0] << "error: no first picked shape.\n";
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) ) { }
1501 TopoDS_Shape aSecondShape;
1502 for(TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
1504 aSecondShape = TheAISContext()->SelectedShape();
1507 if (aSecondShape.IsNull())
1509 di << argv[0] << "error: no second picked shape.\n";
1513 if (aFirstShape.ShapeType() == TopAbs_EDGE)
1515 TopoDS_Edge EdgeA = TopoDS::Edge (aFirstShape);
1517 if (aSecondShape.ShapeType() == TopAbs_EDGE)
1519 TopoDS_Edge EdgeB = TopoDS::Edge (aSecondShape);
1520 BRepExtrema_ExtCC myDeltaEdge (EdgeA ,EdgeB);
1522 if (!myDeltaEdge.IsParallel())
1524 di << argv[0] << " error: non parallel edges." << "\n";
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);
1536 gce_MakePln aMakePlane (A,B,C);
1537 gp_Pln aPlane= aMakePlane.Value();
1539 // Close local context
1540 TheAISContext()->CloseLocalContext (aCurrentIndex);
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]);
1548 else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1550 TopoDS_Vertex aVertex = TopoDS::Vertex (aSecondShape);
1551 BRepExtrema_ExtPC myDeltaEdgeVertex (aVertex ,EdgeA);
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);
1559 gce_MakePln aMakePlane (A,B,C);
1560 gp_Pln aPlane= aMakePlane.Value();
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]);
1568 // Second shape is a face
1571 TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1572 BRepExtrema_ExtCF aDeltaEdgeFace (EdgeA,FaceB);
1574 if (!aDeltaEdgeFace.IsParallel())
1576 di << argv[0] << "error: the edge isn't parallel to the face;can't compute the distance." << "\n";
1580 Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceB, EdgeA);
1581 TheAISContext()->Display (aLenghtDim);
1582 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1585 else if (aFirstShape.ShapeType() == TopAbs_VERTEX)
1587 TopoDS_Vertex VertexA = TopoDS::Vertex (aFirstShape);
1588 if (aSecondShape.ShapeType() == TopAbs_EDGE )
1590 TopoDS_Edge EdgeB=TopoDS::Edge (aSecondShape);
1591 BRepExtrema_ExtPC aDeltaEdgeVertex (VertexA, EdgeB);
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);
1599 gce_MakePln aMakePlane (A,B,C);
1600 gp_Pln aPlane = aMakePlane.Value();
1602 // Close local contex by its index.
1603 TheAISContext()->CloseLocalContext (aCurrentIndex);
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]);
1611 else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1613 TopoDS_Vertex VertexB = TopoDS::Vertex (aSecondShape);
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);
1619 gce_MakePln aMakePlane (A,B,C);
1620 gp_Pln aPlane= aMakePlane.Value();
1622 TheAISContext()->CloseLocalContext (aCurrentIndex);
1624 Handle(AIS_LengthDimension ) aLenghtDim = new AIS_LengthDimension (VertexA, VertexB, aPlane);
1625 TheAISContext()->Display (aLenghtDim);
1626 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1628 // The second shape is face
1631 TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1633 BRepExtrema_ExtPF aDeltaVertexFace (VertexA, FaceB);
1635 gp_Pnt A = BRep_Tool::Pnt (VertexA);
1637 // Recover edge from face.
1638 TopExp_Explorer aFaceExp (FaceB,TopAbs_EDGE);
1639 TopoDS_Edge aSecondEdge = TopoDS::Edge (aFaceExp.Current());
1641 TopoDS_Vertex aVertex1, aVertex2;
1642 TopExp::Vertices (aSecondEdge, aVertex1, aVertex2);
1643 gp_Pnt C = BRep_Tool::Pnt (aVertex2);
1645 gp_Pnt aProjA = aDeltaVertexFace.Point(1);
1646 BRepBuilderAPI_MakeVertex aVertexMaker (aProjA);
1647 TopoDS_Vertex aVertexAProj = aVertexMaker.Vertex();
1649 // Create working plane for the dimension.
1650 gce_MakePln aMakePlane (A, aProjA, C);
1651 gp_Pln aPlane = aMakePlane.Value();
1653 TheAISContext()->CloseLocalContext (aCurrentIndex);
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]);
1662 // The first shape is a face.
1665 TopoDS_Face FaceA = TopoDS::Face (aFirstShape);
1667 if (aSecondShape.ShapeType() == TopAbs_EDGE)
1669 TopoDS_Edge EdgeB = TopoDS::Edge (aSecondShape);
1670 BRepExtrema_ExtCF aDeltaEdgeFace (EdgeB,FaceA );
1672 if (!aDeltaEdgeFace.IsParallel())
1674 di << argv[0] << " error: the edge isn't parallel to the face;can't compute the distance. " << "\n";
1678 Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceA, EdgeB);
1679 TheAISContext()->Display (aLenghtDim);
1680 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1683 else if (aSecondShape.ShapeType() == TopAbs_VERTEX)
1685 TopoDS_Vertex VertexB = TopoDS::Vertex (aSecondShape);
1686 BRepExtrema_ExtPF aDeltaVertexFace (VertexB, FaceA);
1688 gp_Pnt B = BRep_Tool::Pnt (VertexB);
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);
1697 gp_Pnt C = BRep_Tool::Pnt(aVertex2);
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();
1706 TheAISContext()->CloseLocalContext(aCurrentIndex);
1708 Handle(AIS_LengthDimension) aLenghtDim =new AIS_LengthDimension (VertexB, aVertexBProj, aPlane);
1709 TheAISContext()->Display (aLenghtDim);
1710 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
1712 // the second shape is face.
1715 TopoDS_Face FaceB = TopoDS::Face (aSecondShape);
1716 BRepExtrema_ExtFF aDeltaFaceFace (FaceA, FaceB);
1718 if (!aDeltaFaceFace.IsParallel())
1720 di << argv[0] << " error: the faces are not parallel. "<<"\n";
1724 TheAISContext()->CloseLocalContext (aCurrentIndex);
1726 Handle(AIS_LengthDimension) aLenghtDim = new AIS_LengthDimension (FaceA,FaceB);
1727 TheAISContext()->Display (aLenghtDim);
1728 GetMapOfAIS().Bind (aLenghtDim, argv[1]);
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>
1747 static int VRadiusDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1750 Standard_Integer aCurrentIndex;
1755 di << argv[0] << " error: wrong number of parameters." << "\n";
1759 // Close all local contexts
1760 TheAISContext()->CloseAllContexts();
1762 // Open local context and get its index for recovery.
1763 TheAISContext()->OpenLocalContext();
1764 aCurrentIndex = TheAISContext()->IndexOfCurrentLocal();
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";
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)) { }
1778 TopoDS_Shape aShape;
1780 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected() )
1782 aShape = TheAISContext()->SelectedShape();
1785 if (aShape.IsNull())
1787 di << argv[0] << ": no shape is selected." << "\n";
1791 if (aShape.ShapeType() != TopAbs_EDGE && aShape.ShapeType() != TopAbs_FACE)
1793 di << argv[0] << " error: the selection of a face or an edge was expected." << "\n";
1797 if (aShape.ShapeType() == TopAbs_EDGE)
1799 anEdge = TopoDS::Edge (aShape);
1803 // Recover an edge of the face.
1804 TopoDS_Face aFace = TopoDS::Face (aShape);
1806 TopExp_Explorer aFaceExp (aFace,TopAbs_EDGE);
1807 anEdge = TopoDS::Edge (aFaceExp.Current());
1810 // Compute the radius
1811 BRepAdaptor_Curve aCurve (anEdge);
1812 if (aCurve.GetType() != GeomAbs_Circle)
1814 di << argv[0] << " error: the edge is not a circular one." << "\n";
1817 // Close the context
1818 TheAISContext()->CloseLocalContext (aCurrentIndex);
1820 // Construct radius dimension
1821 Handle (AIS_RadiusDimension) aRadDim= new AIS_RadiusDimension (aShape);
1822 VDisplayAISObject (argv[1], aRadDim);
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>
1839 static int VOffsetDimBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1842 Standard_Integer myCurrentIndex;
1843 Standard_Real theDist;
1846 if (argc!=2) {di<<" voffsetdim error"<<"\n";return 1;}
1848 // Fermeture des contextes locaux
1849 TheAISContext()->CloseAllContexts();
1851 // Ouverture d'un contexte local et recuperation de son index.
1852 TheAISContext()->OpenLocalContext();
1853 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
1855 // On active les modes de selections Faces.
1856 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(4) );
1857 di<<" Select a face."<<"\n";
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) ) { }
1866 TopoDS_Shape ShapeA;
1867 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1868 ShapeA = TheAISContext()->SelectedShape();
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) ) { }
1879 TopoDS_Shape ShapeB;
1880 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1881 ShapeB = TheAISContext()->SelectedShape();
1885 // Shape A et B est une face
1886 if (ShapeA.ShapeType()==TopAbs_FACE && ShapeB.ShapeType()==TopAbs_FACE ) {
1888 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
1889 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
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; }
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 ) );
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]);
1912 di<<" voffsetdim error: the selection of a face was expected."<<"\n";return 1;
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>
1936 static int VParallelBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
1939 Standard_Integer myCurrentIndex;
1942 if (argc!=2) {di<<" vparallel error"<<"\n";return 1;}
1944 // Fermeture des contextes locaux
1945 TheAISContext()->CloseAllContexts();
1947 // Ouverture d'un contexte local et recuperation de son index.
1948 TheAISContext()->OpenLocalContext();
1949 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
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";
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) ) { }
1963 TopoDS_Shape ShapeA;
1964 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1965 ShapeA = TheAISContext()->SelectedShape();
1968 // SahpeA est un edge.
1969 // ===================
1970 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
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) ) { }
1982 TopoDS_Shape ShapeB;
1983 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
1984 ShapeB = TheAISContext()->SelectedShape();
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; }
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);
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]);
2016 // Shape A est une face
2017 // ====================
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) ) { }
2030 TopoDS_Shape ShapeB;
2031 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2032 ShapeB = TheAISContext()->SelectedShape();
2035 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
2036 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
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; }
2042 // recuperation des edges des faces.
2043 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
2044 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
2046 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2047 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
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);
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]);
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>
2092 static int VPerpendicularBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2095 Standard_Integer myCurrentIndex;
2098 if (argc!=2) {di<<" vortho error"<<"\n";return 1;}
2100 // Fermeture des contextes locaux
2101 TheAISContext()->CloseAllContexts();
2103 // Ouverture d'un contexte local et recuperation de son index.
2104 TheAISContext()->OpenLocalContext();
2105 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
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";
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) ) { }
2119 TopoDS_Shape ShapeA;
2120 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2121 ShapeA = TheAISContext()->SelectedShape();
2124 // ShapeA est un edge.
2125 // ===================
2126 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
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) ) { }
2138 TopoDS_Shape ShapeB;
2139 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2140 ShapeB = TheAISContext()->SelectedShape();
2143 // recuperation des edges.
2144 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
2145 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
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;}
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]);
2172 // Shape A est une face
2173 // ====================
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) ) { }
2186 TopoDS_Shape ShapeB;
2187 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2188 ShapeB = TheAISContext()->SelectedShape();
2191 // pas de verification d'orthogonalite.
2192 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
2193 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
2195 // recuperation des edges des faces.
2196 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
2197 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
2199 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2200 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
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]);
2229 //==============================================================================
2230 //function : VTangentRelation
2231 //purpose : Display the tangent Relation
2232 //Draw arg : vtangent Name
2233 //==============================================================================
2234 #include <AIS_TangentRelation.hxx>
2237 static int VTangentBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2240 Standard_Integer myCurrentIndex;
2243 if (argc!=2) {di<<" vtangent error"<<"\n";return 1;}
2245 // Fermeture des contextes locaux
2246 TheAISContext()->CloseAllContexts();
2248 // Ouverture d'un contexte local et recuperation de son index.
2249 TheAISContext()->OpenLocalContext();
2250 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
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";
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) ) { }
2264 TopoDS_Shape ShapeA;
2265 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2266 ShapeA = TheAISContext()->SelectedShape();
2269 // ShapeA est un edge.
2270 // ===================
2271 if (ShapeA.ShapeType()==TopAbs_EDGE ) {
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) ) { }
2283 TopoDS_Shape ShapeB;
2284 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2285 ShapeB = TheAISContext()->SelectedShape();
2288 // recuperation des edges.
2289 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
2290 TopoDS_Edge EdgeB=TopoDS::Edge(ShapeB);
2292 // On recupere les curves
2293 BRepAdaptor_Curve theCurveA(EdgeA);
2294 BRepAdaptor_Curve theCurveB(EdgeB);
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);
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]);
2314 // Shape A est une face
2315 // ====================
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) ) { }
2328 TopoDS_Shape ShapeB;
2329 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2330 ShapeB = TheAISContext()->SelectedShape();
2333 TopoDS_Face FaceA=TopoDS::Face(ShapeA);
2334 TopoDS_Face FaceB=TopoDS::Face(ShapeB);
2336 // recuperation des edges des faces.
2337 TopExp_Explorer FaceExpA(FaceA,TopAbs_EDGE);
2338 TopExp_Explorer FaceExpB(FaceB,TopAbs_EDGE);
2340 TopoDS_Edge EdgeA=TopoDS::Edge(FaceExpA.Current() );
2341 TopoDS_Edge EdgeB=TopoDS::Edge(FaceExpB.Current() );
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);
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]);
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>
2380 static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
2383 Standard_Integer myCurrentIndex;
2386 if (argc!=2) {di<<" vSymmetric error"<<"\n";return 1;}
2388 // Fermeture des contextes locaux
2389 TheAISContext()->CloseAllContexts();
2391 // Ouverture d'un contexte local et recuperation de son index.
2392 TheAISContext()->OpenLocalContext();
2393 myCurrentIndex=TheAISContext()->IndexOfCurrentLocal();
2395 // On active les modes de selections
2396 TheAISContext()->ActivateStandardMode (AIS_Shape::SelectionType(2) );
2397 di<<" Select an edge:the axis of symetry "<<"\n";
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) ) { }
2406 TopoDS_Shape ShapeA;
2407 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2408 ShapeA = TheAISContext()->SelectedShape();
2410 // recuperation des edges.
2411 TopoDS_Edge EdgeA=TopoDS::Edge(ShapeA);
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";
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) ) { }
2425 TopoDS_Shape ShapeB;
2426 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2427 ShapeB = TheAISContext()->SelectedShape();
2434 // ShapeB est un edge.
2435 // ===================
2436 if (ShapeB.ShapeType()==TopAbs_EDGE ) {
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) ) { }
2448 TopoDS_Shape ShapeC;
2449 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2450 ShapeC = TheAISContext()->SelectedShape();
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();
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]);
2484 // Shape B est un vertex
2485 // =====================
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) ) { }
2498 TopoDS_Shape ShapeC;
2499 for(TheAISContext()->InitSelected() ;TheAISContext()->MoreSelected() ;TheAISContext()->NextSelected() ) {
2500 ShapeC = TheAISContext()->SelectedShape();
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);
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]);
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)
2541 theDi << theArgVec[0] << " error: the wrong number of input parameters.\n";
2546 TCollection_AsciiString aName (theArgVec[1]);
2547 gp_Pln aWorkingPlane;
2548 Standard_Boolean isCustomPlane = Standard_False;
2549 Standard_Boolean toUpdate = Standard_True;
2551 NCollection_DataMap<TCollection_AsciiString, Standard_Real> aRealParams;
2552 NCollection_DataMap<TCollection_AsciiString, TCollection_AsciiString> aStringParams;
2554 if (!GetMapOfAIS().IsBound2 (aName))
2556 theDi << theArgVec[0] << "error: no object with this name.\n";
2560 Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2 (aName));
2561 if (anObject->Type() != AIS_KOI_Dimension)
2563 theDi << theArgVec[0] << "error: no dimension with this name.\n";
2567 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (anObject);
2568 Handle(Prs3d_DimensionAspect) anAspect = aDim->DimensionAspect();
2570 if (ParseDimensionParams (theArgNum, theArgVec, 2, anAspect,
2571 isCustomPlane, aWorkingPlane,
2572 aRealParams, aStringParams))
2579 aDim->SetCustomPlane (aWorkingPlane);
2582 SetDimensionParams (aDim, aRealParams, aStringParams);
2584 if (!aDim->IsValid())
2586 std::cerr << "Error: Dimension geometry or plane is not valid.\n";
2590 // Redisplay a dimension after parameter changing.
2591 if (ViewerTest::GetAISContext()->IsDisplayed (aDim))
2593 ViewerTest::GetAISContext()->Redisplay (aDim, toUpdate);
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)
2609 theDi << theArgVec[0] << " error: the wrong number of parameters.\n";
2613 // Parameters parsing
2614 Standard_Boolean isNameSet = (theArgNum ==2 || theArgNum == 5);
2615 Standard_Boolean isPointSet = (theArgNum == 4 || theArgNum == 5);
2617 Handle(AIS_InteractiveObject) aPickedObj;
2618 gp_Pnt aPoint (gp::Origin());
2619 Standard_Integer aMaxPickNum = 5;
2624 TCollection_AsciiString aName (theArgVec[1]);
2625 if (!GetMapOfAIS().IsBound2 (aName))
2627 theDi << theArgVec[0] << " error: no object with this name.\n";
2631 aPickedObj = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (aName));
2633 if (aPickedObj.IsNull())
2635 theDi << theArgVec[0] << " error: the object with this name is not valid.\n";
2639 if (aPickedObj->Type() != AIS_KOI_Dimension && aPickedObj->Type() != AIS_KOI_Relation)
2641 theDi << theArgVec[0] << " error: no dimension or relation with this name.\n";
2645 else // Pick dimension or relation
2647 // Close all local contexts
2648 TheAISContext()->CloseAllContexts();
2650 // Open local context and get its index for recovery.
2651 TheAISContext()->OpenLocalContext();
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;
2658 Standard_Boolean isPicked = Standard_False;
2659 Standard_Integer aPickNum = 0;
2660 while (!isPicked && aPickNum < aMaxPickNum)
2662 while (ViewerMainLoop (anArgNum, anArgVec)) { }
2664 for (TheAISContext()->InitSelected(); TheAISContext()->MoreSelected(); TheAISContext()->NextSelected())
2666 aPickedObj = TheAISContext()->SelectedInteractive();
2669 isPicked = (!aPickedObj.IsNull() && (aPickedObj->Type() == AIS_KOI_Dimension || aPickedObj->Type() == AIS_KOI_Relation));
2679 theDi << theArgVec[0] << ": no dimension or relation is selected." << "\n";
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]));
2690 else // Pick the point
2692 Standard_Integer aPickArgNum = 5;
2693 const char *aPickBuff[] = {"VPick", "X", "VPickY", "VPickZ", "VPickShape"};
2694 const char **aPickArgVec = (const char **) aPickBuff;
2696 while (ViewerMainLoop (aPickArgNum, aPickArgVec)) { }
2698 // Set text position, update relation or dimension.
2699 if (aPickedObj->Type() == AIS_KOI_Relation)
2701 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (aPickedObj);
2702 aPoint = Get3DPointAtMousePosition();
2703 aRelation->SetPosition (aPoint);
2704 TheAISContext()->Redisplay (aRelation);
2708 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (aPickedObj);
2709 gp_Pnt aFirstPoint, aSecondPoint;
2710 if (aDim->KindOfDimension() == AIS_KOD_PLANEANGLE)
2712 Handle(AIS_AngleDimension) anAngleDim = Handle(AIS_AngleDimension)::DownCast (aDim);
2713 aFirstPoint = anAngleDim->FirstPoint();
2714 aSecondPoint = anAngleDim->SecondPoint();
2716 else if (aDim->KindOfDimension() == AIS_KOD_LENGTH)
2718 Handle(AIS_LengthDimension) aLengthDim = Handle(AIS_LengthDimension)::DownCast (aDim);
2719 aFirstPoint = aLengthDim->FirstPoint();
2720 aSecondPoint = aLengthDim->SecondPoint();
2722 else if (aDim->KindOfDimension() == AIS_KOD_RADIUS)
2724 Handle(AIS_RadiusDimension) aRadiusDim = Handle(AIS_RadiusDimension)::DownCast (aDim);
2725 aFirstPoint = aRadiusDim->AnchorPoint();
2726 aSecondPoint = aRadiusDim->Circle().Location();
2728 else if (aDim->KindOfDimension() == AIS_KOD_DIAMETER)
2730 Handle(AIS_DiameterDimension) aDiameterDim = Handle(AIS_DiameterDimension)::DownCast (aDim);
2731 aFirstPoint = aDiameterDim->AnchorPoint();
2732 aSecondPoint = aDiameterDim->Circle().Location();
2735 if (!Get3DPointAtMousePosition (aFirstPoint, aSecondPoint, aPoint))
2740 aDim->SetTextPosition (aPoint);
2741 TheAISContext()->Redisplay (aDim);
2746 // Set text position, update relation or dimension.
2747 if (aPickedObj->Type() == AIS_KOI_Relation)
2749 Handle(AIS_Relation) aRelation = Handle(AIS_Relation)::DownCast (aPickedObj);
2750 aRelation->SetPosition (aPoint);
2751 TheAISContext()->Redisplay (aRelation);
2755 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (aPickedObj);
2756 aDim->SetTextPosition (aPoint);
2757 TheAISContext()->Redisplay (aDim);
2763 //=======================================================================
2764 //function : RelationsCommands
2766 //=======================================================================
2769 void ViewerTest::RelationCommands(Draw_Interpretor& theCommands)
2771 const char *group = "AISRelations";
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);
2791 theCommands.Add("vdimparam",
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);
2809 theCommands.Add("vangledim",
2810 "vangledim Name:Selection in the viewer only ",
2811 __FILE__,VAngleDimBuilder,group);
2813 theCommands.Add("vdiameterdim",
2814 "vdiameterdim Name : Selection in the viewer only ",
2815 __FILE__,VDiameterDimBuilder,group);
2817 theCommands.Add("vconcentric",
2818 "vconcentric Name : Selection in the viewer only ",
2819 __FILE__,VConcentricBuilder,group);
2821 theCommands.Add("vequaldist",
2822 "vequaldist Name Selection in the viewer only ",
2823 __FILE__,VEqualDistRelation ,group);
2825 theCommands.Add("vequalrad",
2826 "vequalrad Name Selection in the viewer only ",
2827 __FILE__,VEqualRadiusRelation ,group);
2829 theCommands.Add("vfix",
2830 "vfix Name Selection in the viewer only ",
2831 __FILE__,VFixRelation ,group);
2833 theCommands.Add("videntity",
2834 "videntity Name Selection in the viewer only ",
2835 __FILE__,VIdenticRelation ,group);
2837 theCommands.Add("vdistdim",
2838 "vdistdim Name Selection in the viewer only ",
2839 __FILE__,VLenghtDimension ,group);
2841 theCommands.Add("vradiusdim",
2842 "vradiusdim Name Selection in the viewer only ",
2843 __FILE__,VRadiusDimBuilder ,group);
2845 theCommands.Add("voffsetdim",
2846 "voffsetdim Name Selection in the viewer only ",
2847 __FILE__,VOffsetDimBuilder ,group);
2849 theCommands.Add("vparallel",
2850 "vparallel Name Selection in the viewer only ",
2851 __FILE__,VParallelBuilder ,group);
2853 theCommands.Add("vortho",
2854 "vortho Name Selection in the viewer only ",
2855 __FILE__,VPerpendicularBuilder ,group);
2857 theCommands.Add("vtangent",
2858 "vtangent Name Selection in the viewer only ",
2859 __FILE__,VTangentBuilder ,group);
2862 theCommands.Add("vsymetric",
2863 "vsymetric Name Selection in the viewer only ",
2864 __FILE__,VSymmetricBuilder ,group);
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);