1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAPI_Face.h"
23 #include "GeomAPI_Dir.h"
24 #include "GeomAPI_Pln.h"
25 #include "GeomAPI_Pnt.h"
27 #include <BOPTools_AlgoTools.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepAdaptor_Surface.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Geom_CylindricalSurface.hxx>
32 #include <Geom_RectangularTrimmedSurface.hxx>
33 #include <GeomLib_IsPlanarSurface.hxx>
34 #include <IntTools_Context.hxx>
36 #include <TopoDS_Face.hxx>
38 GeomAPI_Face::GeomAPI_Face()
43 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
45 if (!theShape->isNull() && theShape->isFace()) {
46 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
50 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
55 if (!theFace->isFace())
58 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
59 const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
61 TopoDS_Face aMyFace = TopoDS::Face(aMyShape);
62 TopoDS_Face aInFace = TopoDS::Face(aInShape);
64 Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(aMyFace);
65 Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(aInFace);
67 // Check that surfaces a the same type
68 if (aMySurf->DynamicType() != aInSurf->DynamicType())
71 // Get parameters of surfaces
72 double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
73 aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
74 double aInUMin, aInUMax, aInVMin, aInVMax;
75 aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
77 // Check that parameters are the same
78 if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
79 fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
80 fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
81 fabs(aMyVMax - aInVMax) > Precision::PConfusion())
84 Handle(IntTools_Context) aContext = new IntTools_Context();
85 // Double check needed bacause BOPTools_AlgoTools::CheckSameGeom not very smart.
86 Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext)
87 && BOPTools_AlgoTools::CheckSameGeom(aInFace, aMyFace, aContext);
89 return aRes == Standard_True;
92 bool GeomAPI_Face::isCylindrical() const
94 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
95 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
96 Handle(Geom_RectangularTrimmedSurface) aTrimmed =
97 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
98 if (!aTrimmed.IsNull())
99 aSurf = aTrimmed->BasisSurface();
100 return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
103 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
105 std::shared_ptr<GeomAPI_Pln> aResult;
106 TopoDS_Shape aShape = this->impl<TopoDS_Shape>();
108 return aResult; // null shape
109 if (aShape.ShapeType() != TopAbs_FACE)
110 return aResult; // not face
111 TopoDS_Face aFace = TopoDS::Face(aShape);
113 return aResult; // not face
114 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
116 return aResult; // no surface
117 GeomLib_IsPlanarSurface isPlanar(aSurf);
118 if(!isPlanar.IsPlanar()) {
121 gp_Pln aPln = isPlanar.Plan();
122 double aA, aB, aC, aD;
123 aPln.Coefficients(aA, aB, aC, aD);
124 if (aFace.Orientation() == TopAbs_REVERSED) {
130 aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));