]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
Salome HOME
6b8ebd9463d5cdba2b43bbf16e3177729148ee5f
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_EdgeBuilder.cpp
1 // File:        GeomAlgoAPI_EdgeBuilder.cpp
2 // Created:     23 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include <GeomAlgoAPI_EdgeBuilder.h>
6 #include <gp_Pln.hxx>
7 #include <BRepBuilderAPI_MakeEdge.hxx>
8 #include <TopoDS_Edge.hxx>
9 #include <TopoDS.hxx>
10 #include <BRep_Tool.hxx>
11 #include <Geom_Plane.hxx>
12
13 #include <gp_Ax2.hxx>
14 #include <gp_Circ.hxx>
15
16 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_EdgeBuilder::line(
17   boost::shared_ptr<GeomAPI_Pnt> theStart, boost::shared_ptr<GeomAPI_Pnt> theEnd)
18 {
19   const gp_Pnt& aStart = theStart->impl<gp_Pnt>();
20   const gp_Pnt& anEnd = theEnd->impl<gp_Pnt>();
21
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));
30   return aRes;
31 }
32
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)
36 {
37   const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
38   const gp_Dir& aDir = theNormal->impl<gp_Dir>();
39
40   gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius);
41
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));
46   return aRes;
47 }
48
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)
54 {
55   const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
56   const gp_Dir& aDir = theNormal->impl<gp_Dir>();
57
58   double aRadius = theCenter->distance(theStartPoint);
59   gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
60
61   const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
62   const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
63
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);
68   else
69     anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
70
71   boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
72   anEdgeBuilder.Build();
73
74   if (anEdgeBuilder.IsDone())
75     aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
76   else
77     aRes = boost::shared_ptr<GeomAPI_Shape>();
78   return aRes;
79 }