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>
16 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
17 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
20 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
21 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
22 gp_Pln aPlane(aCenter, aDir);
23 // half of the size in each direction from the center
24 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
26 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
27 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
31 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
32 std::shared_ptr<GeomAPI_Pln> thePlane,
35 // half of the size in each direction from the center
36 BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
37 -theSize / 2., theSize / 2.,
38 -theSize / 2., theSize / 2.);
39 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
40 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
44 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
45 std::shared_ptr<GeomAPI_Shape> theFace)
47 std::shared_ptr<GeomAPI_Pln> aResult;
49 return aResult; // bad shape
50 TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
52 return aResult; // null shape
53 if (aShape.ShapeType() != TopAbs_FACE)
54 return aResult; // not face
55 TopoDS_Face aFace = TopoDS::Face(aShape);
57 return aResult; // not face
58 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
60 return aResult; // no surface
61 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf);
63 return aResult; // not planar
64 double aA, aB, aC, aD;
65 aPlane->Coefficients(aA, aB, aC, aD);
66 aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
70 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
71 double theX, double theY,
72 double theWidth, double theHeight)
74 double aA, aB, aC, aD;
75 thePlane->coefficients(aA, aB, aC, aD);
76 gp_Pln aPlane(aA, aB, aC, aD);
78 // half of the size in each direction from the center
79 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth,
80 theY, theY + theHeight);
81 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
82 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));