1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_FaceBuilder.cpp
4 // Created: 23 Apr 2014
5 // Author: Mikhail PONIKAROV
7 #include <GeomAlgoAPI_FaceBuilder.h>
9 #include <BRepBuilderAPI_MakeFace.hxx>
10 #include <TopoDS_Face.hxx>
12 #include <BRep_Tool.hxx>
13 #include <Geom_Plane.hxx>
15 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
16 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
19 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
20 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
21 gp_Pln aPlane(aCenter, aDir);
22 // half of the size in each direction from the center
23 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
25 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
26 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
30 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
31 std::shared_ptr<GeomAPI_Shape> theFace)
33 std::shared_ptr<GeomAPI_Pln> aResult;
35 return aResult; // bad shape
36 TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
38 return aResult; // null shape
39 if (aShape.ShapeType() != TopAbs_FACE)
40 return aResult; // not face
41 TopoDS_Face aFace = TopoDS::Face(aShape);
43 return aResult; // not face
44 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
46 return aResult; // no surface
47 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
49 return aResult; // not planar
50 double aA, aB, aC, aD;
51 aPlane->Coefficients(aA, aB, aC, aD);
52 aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
57 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::
58 planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
59 double theX, double theY,
60 double theWidth, double theHeight)
62 double aA, aB, aC, aD;
63 thePlane->coefficients(aA, aB, aC, aD);
64 gp_Pln aPlane(aA, aB, aC, aD);
66 // half of the size in each direction from the center
67 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth,
68 theY, theY + theHeight);
69 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
70 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));