1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_EdgeBuilder.cpp
4 // Created: 23 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #include <GeomAlgoAPI_EdgeBuilder.h>
9 #include <BRepBuilderAPI_MakeEdge.hxx>
10 #include <TopoDS_Edge.hxx>
12 #include <BRep_Tool.hxx>
13 #include <Geom_Plane.hxx>
16 #include <gp_Circ.hxx>
18 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
19 std::shared_ptr<GeomAPI_Pnt> theStart, std::shared_ptr<GeomAPI_Pnt> theEnd)
21 const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
22 const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
24 if (aStart.IsEqual(anEnd, Precision::Confusion()))
25 return std::shared_ptr<GeomAPI_Edge>();
26 if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
27 return std::shared_ptr<GeomAPI_Edge>();
28 BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
29 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
30 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
31 aRes->setImpl(new TopoDS_Shape(anEdge));
35 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
36 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
39 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
40 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
42 gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
44 BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
45 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
46 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
47 aRes->setImpl(new TopoDS_Shape(anEdge));
51 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
52 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Pnt> theStartPoint,
53 std::shared_ptr<GeomAPI_Pnt> theEndPoint, std::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 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
72 anEdgeBuilder.Build();
74 if (anEdgeBuilder.IsDone())
75 aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
77 aRes = std::shared_ptr<GeomAPI_Edge>();