1 // File: GeomAlgoAPI_EdgeBuilder.cpp
2 // Created: 23 Apr 2014
3 // Author: Mikhail PONIKAROV
5 #include <GeomAlgoAPI_EdgeBuilder.h>
7 #include <BRepBuilderAPI_MakeEdge.hxx>
8 #include <TopoDS_Edge.hxx>
10 #include <BRep_Tool.hxx>
11 #include <Geom_Plane.hxx>
14 #include <gp_Circ.hxx>
16 boost::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
17 boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
19 const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
20 const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
22 if (aStart.IsEqual(anEnd, Precision::Confusion()))
23 return boost::shared_ptr<GeomAPI_Edge>();
24 if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
25 return boost::shared_ptr<GeomAPI_Edge>();
26 BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
27 boost::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
28 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
29 aRes->setImpl(new TopoDS_Shape(anEdge));
33 boost::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
34 boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Dir> theNormal,
37 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
38 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
40 gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
42 BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
43 boost::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
44 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
45 aRes->setImpl(new TopoDS_Shape(anEdge));
49 boost::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
50 boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Pnt> theStartPoint,
51 boost::shared_ptr<GeomAPI_Pnt> theEndPoint, boost::shared_ptr<GeomAPI_Dir> theNormal)
53 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
54 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
56 double aRadius = theCenter->distance(theStartPoint);
57 gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
59 const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
60 const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
62 BRepBuilderAPI_MakeEdge anEdgeBuilder;
63 if (aStart.IsEqual(anEnd, Precision::Confusion())
64 || gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
65 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
67 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
69 boost::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
70 anEdgeBuilder.Build();
72 if (anEdgeBuilder.IsDone())
73 aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
75 aRes = boost::shared_ptr<GeomAPI_Edge>();