Salome HOME
Merge from 'master'
[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 }