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>
11 #include <TopoDS_Face.hxx>
13 #include <BRep_Tool.hxx>
14 #include <Geom_Plane.hxx>
15 #include <Geom_CylindricalSurface.hxx>
18 #include <gp_Circ.hxx>
20 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::line(
21 std::shared_ptr<GeomAPI_Pnt> theStart, std::shared_ptr<GeomAPI_Pnt> theEnd)
23 const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
24 const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
26 if (aStart.IsEqual(anEnd, Precision::Confusion()))
27 return std::shared_ptr<GeomAPI_Edge>();
28 if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
29 return std::shared_ptr<GeomAPI_Edge>();
30 BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
31 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
32 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
33 aRes->setImpl(new TopoDS_Shape(anEdge));
37 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::cylinderAxis(
38 std::shared_ptr<GeomAPI_Shape> theCylindricalFace)
40 std::shared_ptr<GeomAPI_Edge> aResult;
41 const TopoDS_Shape& aShape = theCylindricalFace->impl<TopoDS_Shape>();
44 TopoDS_Face aFace = TopoDS::Face(aShape);
48 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
51 Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf);
54 gp_Ax1 anAxis = aCyl->Axis();
55 gp_Pnt aStart(anAxis.Location().Transformed(aLoc.Transformation()));
56 // edge length is 100, "-" because cylinder of extrusion has negative direction with the cylinder
57 gp_Pnt anEnd(anAxis.Location().XYZ() - anAxis.Direction().XYZ() * 100.);
58 anEnd.Transform(aLoc.Transformation());
60 BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
61 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
62 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
63 // an axis is an infinite object
64 anEdge.Infinite(Standard_True);
65 aRes->setImpl(new TopoDS_Shape(anEdge));
69 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
70 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
73 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
74 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
76 gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
78 BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
79 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
80 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
81 aRes->setImpl(new TopoDS_Shape(anEdge));
85 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
86 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Pnt> theStartPoint,
87 std::shared_ptr<GeomAPI_Pnt> theEndPoint, std::shared_ptr<GeomAPI_Dir> theNormal)
89 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
90 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
92 double aRadius = theCenter->distance(theStartPoint);
93 gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
95 const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
96 const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
98 BRepBuilderAPI_MakeEdge anEdgeBuilder;
99 if (aStart.IsEqual(anEnd, Precision::Confusion())
100 || gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
101 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
103 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
105 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
106 anEdgeBuilder.Build();
108 if (anEdgeBuilder.IsDone())
109 aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
111 aRes = std::shared_ptr<GeomAPI_Edge>();