1 // File: GeomAlgoAPI_FaceBuilder.cpp
2 // Created: 23 Apr 2014
3 // Author: Mikhail PONIKAROV
5 #include <GeomAlgoAPI_FaceBuilder.h>
7 #include <BRepBuilderAPI_MakeFace.hxx>
8 #include <TopoDS_Face.hxx>
10 #include <BRep_Tool.hxx>
11 #include <Geom_Plane.hxx>
13 boost::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
14 boost::shared_ptr<GeomAPI_Pnt> theCenter, boost::shared_ptr<GeomAPI_Dir> theNormal,
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.,
23 boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
24 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
28 boost::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
29 boost::shared_ptr<GeomAPI_Shape> theFace)
31 boost::shared_ptr<GeomAPI_Pln> aResult;
33 return aResult; // bad shape
34 TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
36 return aResult; // null shape
37 TopoDS_Face aFace = TopoDS::Face(aShape);
39 return aResult; // not face
40 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
42 return aResult; // no surface
43 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
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));