]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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_Edge> 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_Edge>();
24   if (Abs(aStart.SquareDistance(anEnd)) > 1.e+100)
25     return boost::shared_ptr<GeomAPI_Edge>();
26   BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd);
27   boost::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
28   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
29   aRes->setImpl(new TopoDS_Shape(anEdge));
30   return aRes;
31 }
32
33 boost::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircle(
34     boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Dir> theNormal,
35     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_Edge> aRes(new GeomAPI_Edge);
44   TopoDS_Edge anEdge = anEdgeBuilder.Edge();
45   aRes->setImpl(new TopoDS_Shape(anEdge));
46   return aRes;
47 }
48
49 boost::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
50     boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Pnt> theStartPoint,
51     boost::shared_ptr<GeomAPI_Pnt> theEndPoint, boost::shared_ptr<GeomAPI_Dir> theNormal)
52 {
53   const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
54   const gp_Dir& aDir = theNormal->impl<gp_Dir>();
55
56   double aRadius = theCenter->distance(theStartPoint);
57   gp_Circ aCircle(gp_Ax2(aCenter, aDir), aRadius);
58
59   const gp_Pnt& aStart = theStartPoint->impl<gp_Pnt>();
60   const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
61
62   BRepBuilderAPI_MakeEdge anEdgeBuilder;
63   if (aStart.IsEqual(anEnd, Precision::Confusion())
64       || gp_Pnt(0, 0, 0).IsEqual(anEnd, Precision::Confusion()))
65     anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
66   else
67     anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
68
69   boost::shared_ptr<GeomAPI_Edge> aRes(new GeomAPI_Edge);
70   anEdgeBuilder.Build();
71
72   if (anEdgeBuilder.IsDone())
73     aRes->setImpl(new TopoDS_Shape(anEdgeBuilder.Edge()));
74   else
75     aRes = boost::shared_ptr<GeomAPI_Edge>();
76   return aRes;
77 }