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(
26 const std::shared_ptr<GeomAPI_Pnt> theCenter,
27 const std::shared_ptr<GeomAPI_Dir> theNormal,
30 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
31 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
32 gp_Pln aPlane(aCenter, aDir);
33 // half of the size in each direction from the center
34 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, -theSize / 2., theSize / 2., -theSize / 2.,
36 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
37 aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
41 //==================================================================================================
42 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::squareFace(
43 const std::shared_ptr<GeomAPI_Pln> thePlane,
46 // half of the size in each direction from the center
47 BRepBuilderAPI_MakeFace aFaceBuilder(thePlane->impl<gp_Pln>(),
48 -theSize / 2., theSize / 2.,
49 -theSize / 2., theSize / 2.);
50 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
51 const TopoDS_Face& aFace = aFaceBuilder.Face();
52 aRes->setImpl(new TopoDS_Face(aFace));
56 //==================================================================================================
57 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(
58 const std::shared_ptr<GeomAPI_Pnt> theCenter,
59 const std::shared_ptr<GeomAPI_Dir> theNormal)
61 const gp_Pnt& aCenter = theCenter->impl<gp_Pnt>();
62 const gp_Dir& aDir = theNormal->impl<gp_Dir>();
63 gp_Pln aPlane(aCenter, aDir);
64 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane);
65 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
66 aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
70 //==================================================================================================
71 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFace(
72 const std::shared_ptr<GeomAPI_Pln> thePlane,
73 const double theX, const double theY,
74 const double theWidth, const double theHeight)
76 double aA, aB, aC, aD;
77 thePlane->coefficients(aA, aB, aC, aD);
78 gp_Pln aPlane(aA, aB, aC, aD);
80 // half of the size in each direction from the center
81 BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, theX, theX + theWidth,
82 theY, theY + theHeight);
83 std::shared_ptr<GeomAPI_Face> aRes(new GeomAPI_Face());
84 aRes->setImpl(new TopoDS_Face(aFaceBuilder.Face()));
88 //==================================================================================================
89 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFaceByThreeVertices(
90 const std::shared_ptr<GeomAPI_Vertex> theVertex1,
91 const std::shared_ptr<GeomAPI_Vertex> theVertex2,
92 const std::shared_ptr<GeomAPI_Vertex> theVertex3)
94 gp_Pnt aPnt1 = theVertex1->point()->impl<gp_Pnt>();
95 gp_Pnt aPnt2 = theVertex2->point()->impl<gp_Pnt>();
96 gp_Pnt aPnt3 = theVertex3->point()->impl<gp_Pnt>();
98 std::shared_ptr<GeomAPI_Face> aFace;
99 GC_MakePlane aMakePlane(aPnt1, aPnt2, aPnt3);
100 if(!aMakePlane.IsDone()) {
104 BRepBuilderAPI_MakeFace aMakeFace(aMakePlane.Value()->Pln());
105 aFace.reset(new GeomAPI_Face());
106 aFace->setImpl(new TopoDS_Face(aMakeFace.Face()));
110 //==================================================================================================
111 std::shared_ptr<GeomAPI_Face> GeomAlgoAPI_FaceBuilder::planarFaceByFaceAndVertex(
112 const std::shared_ptr<GeomAPI_Face> theFace,
113 const std::shared_ptr<GeomAPI_Vertex> theVertex)
115 gp_Pln aPln = theFace->getPlane()->impl<gp_Pln>();
116 gp_Pnt aPnt = theVertex->point()->impl<gp_Pnt>();
118 std::shared_ptr<GeomAPI_Face> aFace;
119 GC_MakePlane aMakePlane(aPln, aPnt);
120 if(!aMakePlane.IsDone()) {
124 BRepBuilderAPI_MakeFace aMakeFace(aMakePlane.Value()->Pln());
125 aFace.reset(new GeomAPI_Face());
126 aFace->setImpl(new TopoDS_Face(aMakeFace.Face()));