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_Shape> 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_Shape>();
24 if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
25 return boost::shared_ptr<GeomAPI_Shape>();
26 BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
27 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
28 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
29 aRes->setImpl(new TopoDS_Shape(anEdge));
33 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::lineCircle(
34 boost::shared_ptr<GeomAPI_Pnt> theCenter,
35 boost::shared_ptr<GeomAPI_Dir> theNormal, double theRadius)
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_Shape> aRes(new GeomAPI_Shape);
44 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
45 aRes->setImpl(new TopoDS_Shape(anEdge));
49 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
50 boost::shared_ptr<GeomAPI_Pnt> theCenter,
51 boost::shared_ptr<GeomAPI_Pnt> theStartPoint,
52 boost::shared_ptr<GeomAPI_Pnt> theEndPoint,
53 boost::shared_ptr<GeomAPI_Dir> theNormal)
55 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
56 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
58 double aRadius = theCenter->distance(theStartPoint);
59 gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
61 const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
62 const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
64 BRepBuilderAPI_MakeEdge anEdgeBuilder;
65 if (aStart.IsEqual(anEnd, Precision::Confusion()) ||
66 gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
67 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
69 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
71 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
72 anEdgeBuilder.Build();
74 if (anEdgeBuilder.IsDone())
75 aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
77 aRes = boost::shared_ptr<GeomAPI_Shape>();