1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Face.cpp
5 // Author: Artem ZHIDKOV
7 #include "GeomAPI_Face.h"
9 #include "GeomAPI_Dir.h"
10 #include "GeomAPI_Pln.h"
11 #include "GeomAPI_Pnt.h"
13 #include <BOPTools_AlgoTools.hxx>
14 #include <BRep_Tool.hxx>
15 #include <BRepAdaptor_Surface.hxx>
16 #include <Geom_Surface.hxx>
17 #include <Geom_CylindricalSurface.hxx>
18 #include <Geom_RectangularTrimmedSurface.hxx>
19 #include <GeomLib_IsPlanarSurface.hxx>
20 #include <IntTools_Context.hxx>
22 #include <TopoDS_Face.hxx>
24 GeomAPI_Face::GeomAPI_Face()
29 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
31 if (!theShape->isNull() && theShape->isFace()) {
32 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
36 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
41 if (!theFace->isFace())
44 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
45 const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
47 TopoDS_Face aMyFace = TopoDS::Face(aMyShape);
48 TopoDS_Face aInFace = TopoDS::Face(aInShape);
50 Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(aMyFace);
51 Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(aInFace);
53 // Check that surfaces a the same type
54 if (aMySurf->DynamicType() != aInSurf->DynamicType())
57 // Get parameters of surfaces
58 double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
59 aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
60 double aInUMin, aInUMax, aInVMin, aInVMax;
61 aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
63 // Check that parameters are the same
64 if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
65 fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
66 fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
67 fabs(aMyVMax - aInVMax) > Precision::PConfusion())
70 Handle(IntTools_Context) aContext = new IntTools_Context();
71 Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext);
73 return aRes == Standard_True;
76 bool GeomAPI_Face::isCylindrical() const
78 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
79 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
80 Handle(Geom_RectangularTrimmedSurface) aTrimmed =
81 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
82 if (!aTrimmed.IsNull())
83 aSurf = aTrimmed->BasisSurface();
84 return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
87 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
89 std::shared_ptr<GeomAPI_Pln> aResult;
90 TopoDS_Shape aShape = this->impl<TopoDS_Shape>();
92 return aResult; // null shape
93 if (aShape.ShapeType() != TopAbs_FACE)
94 return aResult; // not face
95 TopoDS_Face aFace = TopoDS::Face(aShape);
97 return aResult; // not face
98 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
100 return aResult; // no surface
101 GeomLib_IsPlanarSurface isPlanar(aSurf);
102 if(!isPlanar.IsPlanar()) {
105 gp_Pln aPln = isPlanar.Plan();
106 double aA, aB, aC, aD;
107 aPln.Coefficients(aA, aB, aC, aD);
108 if (aFace.Orientation() == TopAbs_REVERSED) {
114 aResult = std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(aA, aB, aC, aD));