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 <GeomAPI_Face.h>
10 #include <GeomAPI_Dir.h>
11 #include <GeomAPI_Pln.h>
12 #include <GeomAPI_Pnt.h>
13 #include <GeomAPI_Shape.h>
14 #include <GeomAPI_Vertex.h>
16 #include <BRep_Tool.hxx>
17 #include <BRepBuilderAPI_MakeFace.hxx>
18 #include <GC_MakePlane.hxx>
19 #include <Geom_Plane.hxx>
22 #include <TopoDS_Face.hxx>
24 //==================================================================================================
25 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
26 const std::shared_ptr<GeomAPI_Dir> theNormal,
29 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
30 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
31 gp_Pln aPlane(aCenter, aDir);
32 // half of the size in each direction from the center
33 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
35 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
36 aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
40 //==================================================================================================
41 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::squareFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
44 // half of the size in each direction from the center
45 BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
46 -theSize / 2., theSize / 2.,
47 -theSize / 2., theSize / 2.);
48 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
49 const TopoDS_Face& aFace = aFaceBuilder.Face();
50 aRes->setImpl(new TopoDS_Face(aFace));
54 //==================================================================================================
55 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr<GeomAPI_Pnt> theCenter,
56 const std::shared_ptr<GeomAPI_Dir> theNormal)
58 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
59 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
60 gp_Pln aPlane(aCenter, aDir);
61 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
62 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
63 aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
67 //==================================================================================================
68 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(const std::shared_ptr<GeomAPI_Pln> thePlane,
69 const double theX, const double theY,
70 const double theWidth, const double theHeight)
72 double aA, aB, aC, aD;
73 thePlane->coefficients(aA, aB, aC, aD);
74 gp_Pln aPlane(aA, aB, aC, aD);
76 // half of the size in each direction from the center
77 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth,
78 theY, theY + theHeight);
79 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
80 aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
84 //==================================================================================================
85 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(
86 const std::shared_ptr<GeomAPI_Vertex> theVertex1,
87 const std::shared_ptr<GeomAPI_Vertex> theVertex2,
88 const std::shared_ptr<GeomAPI_Vertex> theVertex3)
90 gp_Pnt aPnt1 = theVertex1->point()->impl<gp_Pnt>();
91 gp_Pnt aPnt2 = theVertex2->point()->impl<gp_Pnt>();
92 gp_Pnt aPnt3 = theVertex3->point()->impl<gp_Pnt>();
94 std::shared_ptr<GeomAPI_Face> aFace;
95 GC_MakePlane aMakePlane(aPnt1, aPnt2, aPnt3);
96 if(!aMakePlane.IsDone()) {
100 BRepBuilderAPI_MakeFace aMakeFace(aMakePlane.Value()->Pln());
101 aFace.reset(new GeomAPI_Face());
102 aFace->setImpl(new TopoDS_Face(aMakeFace.Face()));
106 //==================================================================================================
107 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFaceByFaceAndVertex(
108 const std::shared_ptr<GeomAPI_Face> theFace,
109 const std::shared_ptr<GeomAPI_Vertex> theVertex)
111 gp_Pln aPln = theFace->getPlane()->impl<gp_Pln>();
112 gp_Pnt aPnt = theVertex->point()->impl<gp_Pnt>();
114 std::shared_ptr<GeomAPI_Face> aFace;
115 GC_MakePlane aMakePlane(aPln, aPnt);
116 if(!aMakePlane.IsDone()) {
120 BRepBuilderAPI_MakeFace aMakeFace(aMakePlane.Value()->Pln());
121 aFace.reset(new GeomAPI_Face());
122 aFace->setImpl(new TopoDS_Face(aMakeFace.Face()));