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,
22 const bool theInfinite)
24 const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
25 const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
27 if (aStart.IsEqual(anEnd, Precision::Confusion()))
28 return std::shared_ptr<GeomAPI_Edge>();
29 if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
30 return std::shared_ptr<GeomAPI_Edge>();
31 BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
32 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
33 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
35 anEdge.Infinite(Standard_True);
36 aRes->setImpl(new TopoDS_Shape(anEdge));
40 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::cylinderAxis(
41 std::shared_ptr<GeomAPI_Shape> theCylindricalFace)
43 std::shared_ptr<GeomAPI_Edge> aResult;
44 const TopoDS_Shape& aShape = theCylindricalFace->impl<TopoDS_Shape>();
47 TopoDS_Face aFace = TopoDS::Face(aShape);
51 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc);
54 Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf);
57 gp_Ax1 anAxis = aCyl->Axis();
58 gp_Pnt aStart(anAxis.Location().Transformed(aLoc.Transformation()));
59 // edge length is 100, "-" because cylinder of extrusion has negative direction with the cylinder
60 gp_Pnt anEnd(anAxis.Location().XYZ() - anAxis.Direction().XYZ() * 100.);
61 anEnd.Transform(aLoc.Transformation());
63 BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
64 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
65 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
66 // an axis is an infinite object
67 anEdge.Infinite(Standard_True);
68 aRes->setImpl(new TopoDS_Shape(anEdge));
72 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
73 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
76 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
77 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
79 gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
81 BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
82 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
83 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
84 aRes->setImpl(new TopoDS_Shape(anEdge));
88 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
89 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Pnt> theStartPoint,
90 std::shared_ptr<GeomAPI_Pnt> theEndPoint, std::shared_ptr<GeomAPI_Dir> theNormal)
92 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
93 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
95 double aRadius = theCenter->distance(theStartPoint);
96 gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
98 const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
99 const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
101 BRepBuilderAPI_MakeEdge anEdgeBuilder;
102 if (aStart.IsEqual(anEnd, Precision::Confusion())
103 || gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
104 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
106 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
108 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
109 anEdgeBuilder.Build();
111 if (anEdgeBuilder.IsDone())
112 aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
114 aRes = std::shared_ptr<GeomAPI_Edge>();