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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "GeomAPI_Face.h"
22 #include "GeomAPI_Dir.h"
23 #include "GeomAPI_Pln.h"
24 #include "GeomAPI_Pnt.h"
26 #include <BOPTools_AlgoTools.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepAdaptor_Surface.hxx>
29 #include <Geom_Surface.hxx>
30 #include <Geom_CylindricalSurface.hxx>
31 #include <Geom_RectangularTrimmedSurface.hxx>
32 #include <GeomLib_IsPlanarSurface.hxx>
33 #include <IntTools_Context.hxx>
35 #include <TopoDS_Face.hxx>
37 GeomAPI_Face::GeomAPI_Face()
42 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
44 if (!theShape->isNull() && theShape->isFace()) {
45 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
49 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
54 if (!theFace->isFace())
57 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
58 const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
60 TopoDS_Face aMyFace = TopoDS::Face(aMyShape);
61 TopoDS_Face aInFace = TopoDS::Face(aInShape);
63 Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(aMyFace);
64 Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(aInFace);
66 // Check that surfaces a the same type
67 if (aMySurf->DynamicType() != aInSurf->DynamicType())
70 // Get parameters of surfaces
71 double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
72 aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
73 double aInUMin, aInUMax, aInVMin, aInVMax;
74 aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
76 // Check that parameters are the same
77 if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
78 fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
79 fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
80 fabs(aMyVMax - aInVMax) > Precision::PConfusion())
83 Handle(IntTools_Context) aContext = new IntTools_Context();
84 // Double check needed bacause BOPTools_AlgoTools::CheckSameGeom not very smart.
85 Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext)
86 && BOPTools_AlgoTools::CheckSameGeom(aInFace, aMyFace, aContext);
88 return aRes == Standard_True;
91 bool GeomAPI_Face::isCylindrical() const
93 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
94 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
95 Handle(Geom_RectangularTrimmedSurface) aTrimmed =
96 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
97 if (!aTrimmed.IsNull())
98 aSurf = aTrimmed->BasisSurface();
99 return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
102 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
104 std::shared_ptr<GeomAPI_Pln> aResult;
105 TopoDS_Shape aShape = this->impl<TopoDS_Shape>();
107 return aResult; // null shape
108 if (aShape.ShapeType() != TopAbs_FACE)
109 return aResult; // not face
110 TopoDS_Face aFace = TopoDS::Face(aShape);
112 return aResult; // not face
113 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
115 return aResult; // no surface
116 GeomLib_IsPlanarSurface isPlanar(aSurf);
117 if(!isPlanar.IsPlanar()) {
120 gp_Pln aPln = isPlanar.Plan();
121 double aA, aB, aC, aD;
122 aPln.Coefficients(aA, aB, aC, aD);
123 if (aFace.Orientation() == TopAbs_REVERSED) {
129 aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));