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>
14 #include <GeomLib_IsPlanarSurface.hxx>
17 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
18 std::shared_ptr<GeomAPI_Pnt> theCenter, std::shared_ptr<GeomAPI_Dir> theNormal,
21 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
22 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
23 gp_Pln aPlane(aCenter, aDir);
24 // half of the size in each direction from the center
25 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
27 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
28 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
32 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::square(
33 std::shared_ptr<GeomAPI_Pln> thePlane,
36 // half of the size in each direction from the center
37 BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
38 -theSize / 2., theSize / 2.,
39 -theSize / 2., theSize / 2.);
40 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
41 TopoDS_Shape aFace = aFaceBuilder.Face();
42 aRes->setImpl(new TopoDS_Shape(aFace/*aFaceBuilder.Face()*/));
46 std::shared_ptr<GeomAPI_Pln> GeomAlgoAPI_FaceBuilder::plane(
47 std::shared_ptr<GeomAPI_Shape> theFace)
49 std::shared_ptr<GeomAPI_Pln> aResult;
51 return aResult; // bad shape
52 TopoDS_Shape aShape = theFace->impl<TopoDS_Shape>();
54 return aResult; // null shape
55 if (aShape.ShapeType() != TopAbs_FACE)
56 return aResult; // not face
57 TopoDS_Face aFace = TopoDS::Face(aShape);
59 return aResult; // not face
60 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
62 return aResult; // no surface
63 GeomLib_IsPlanarSurface isPlanar(aSurf);
64 if(!isPlanar.IsPlanar()) {
67 gp_Pln aPln = isPlanar.Plan();
68 double aA, aB, aC, aD;
69 aPln.Coefficients(aA, aB, aC, aD);
70 if (aFace.Orientation() == TopAbs_REVERSED) {
76 aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));
80 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr<GeomAPI_Pnt> theCenter,
81 std::shared_ptr<GeomAPI_Dir> theNormal)
83 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
84 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
85 gp_Pln aPlane(aCenter, aDir);
86 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
87 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
88 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));
92 std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_FaceBuilder::planarFace(std::shared_ptr<GeomAPI_Pln> thePlane,
93 double theX, double theY,
94 double theWidth, double theHeight)
96 double aA, aB, aC, aD;
97 thePlane->coefficients(aA, aB, aC, aD);
98 gp_Pln aPlane(aA, aB, aC, aD);
100 // half of the size in each direction from the center
101 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth,
102 theY, theY + theHeight);
103 std::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
104 aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face()));