]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_FaceBuilder.cpp
1 // File:        GeomAlgoAPI_FaceBuilder.cpp
2 // Created:     23 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include <GeomAlgoAPI_FaceBuilder.h>
6 #include <gp_Pln.hxx>
7 #include <BRepBuilderAPI_MakeFace.hxx>
8 #include <TopoDS_Face.hxx>
9 #include <TopoDS.hxx>
10 #include <BRep_Tool.hxx>
11 #include <Geom_Plane.hxx>
12
13 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
14     boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Dir> theNormal,
15     const double theSize)
16 {
17   const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
18   const gp_Dir& aDir = theNormal->impl<gp_Dir>();
19   gp_Pln aPlane(aCenter, aDir);
20   // half of the size in each direction from the center
21   BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
22                                        theSize / 2.);
23   boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
24   aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
25   return aRes;
26 }
27
28 boost::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
29     boost::shared_ptr<GeomAPI_Shape> theFace)
30 {
31   boost::shared_ptr<GeomAPI_Pln> aResult;
32   if (!theFace)
33     return aResult;  // bad shape
34   TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
35   if (aShape.IsNull())
36     return aResult;  // null shape
37   TopoDS_Face aFace = TopoDS::Face(aShape);
38   if (aFace.IsNull())
39     return aResult;  // not face
40   Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
41   if (aSurf.IsNull())
42     return aResult;  // no surface
43   Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
44   if (aPlane.IsNull())
45     return aResult;  // not planar
46   double aA, aB, aC, aD;
47   aPlane->Coefficients(aA, aB, aC, aD);
48   aResult = boost::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
49   return aResult;
50 }