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 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
14 std::shared_ptr<GeomAPI_Pnt> theCenter, std::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 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
24 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
28 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
29 std::shared_ptr<GeomAPI_Shape> theFace)
31 std::shared_ptr<GeomAPI_Pln> aResult;
33 return aResult; // bad shape
34 TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
36 return aResult; // null shape
37 if (aShape.ShapeType() != TopAbs_FACE)
38 return aResult; // not face
39 TopoDS_Face aFace = TopoDS::Face(aShape);
41 return aResult; // not face
42 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
44 return aResult; // no surface
45 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
47 return aResult; // not planar
48 double aA, aB, aC, aD;
49 aPlane->Coefficients(aA, aB, aC, aD);
50 aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));