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 aRes->setImpl(new TopoDS_Shape(anEdge));
67 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
68 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
71 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
72 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
74 gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
76 BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle);
77 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
78 TopoDS_Edge anEdge = anEdgeBuilder.Edge();
79 aRes->setImpl(new TopoDS_Shape(anEdge));
83 std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
84 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Pnt> theStartPoint,
85 std::shared_ptr<GeomAPI_Pnt> theEndPoint, std::shared_ptr<GeomAPI_Dir> theNormal)
87 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
88 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
90 double aRadius = theCenter->distance(theStartPoint);
91 gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
93 const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
94 const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
96 BRepBuilderAPI_MakeEdge anEdgeBuilder;
97 if (aStart.IsEqual(anEnd, Precision::Confusion())
98 || gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
99 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
101 anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
103 std::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
104 anEdgeBuilder.Build();
106 if (anEdgeBuilder.IsDone())
107 aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
109 aRes = std::shared_ptr<GeomAPI_Edge>();