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 <IntTools_Context.hxx>
21 #include <TopoDS_Face.hxx>
23 GeomAPI_Face::GeomAPI_Face()
28 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
30 if (!theShape->isNull() && theShape->isFace()) {
31 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
35 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
40 if (!theFace->isFace())
43 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
44 const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
46 TopoDS_Face aMyFace = TopoDS::Face(aMyShape);
47 TopoDS_Face aInFace = TopoDS::Face(aInShape);
49 Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(aMyFace);
50 Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(aInFace);
52 // Check that surfaces a the same type
53 if (aMySurf->DynamicType() != aInSurf->DynamicType())
56 // Get parameters of surfaces
57 double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
58 aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
59 double aInUMin, aInUMax, aInVMin, aInVMax;
60 aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
62 // Check that parameters are the same
63 if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
64 fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
65 fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
66 fabs(aMyVMax - aInVMax) > Precision::PConfusion())
69 Handle(IntTools_Context) aContext = new IntTools_Context();
70 Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext);
72 return aRes == Standard_True;
75 bool GeomAPI_Face::isCylindrical() const
77 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
78 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
79 Handle(Geom_RectangularTrimmedSurface) aTrimmed =
80 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
81 if (!aTrimmed.IsNull())
82 aSurf = aTrimmed->BasisSurface();
83 return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
86 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
88 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
89 BRepAdaptor_Surface aSurfAdapt(TopoDS::Face(aShape));
91 if (aSurfAdapt.GetType() != GeomAbs_Plane)
92 return std::shared_ptr<GeomAPI_Pln>();
94 // Obtain central point
95 double aUMin, aUMax, aVMin, aVMax;
96 aUMin = aSurfAdapt.FirstUParameter();
97 aUMax = aSurfAdapt.LastUParameter();
98 aVMin = aSurfAdapt.FirstVParameter();
99 aVMax = aSurfAdapt.LastVParameter();
102 aSurfAdapt.D1((aUMin+aUMax)*0.5, (aVMin+aVMax)*0.5, aCentralPnt, aDU, aDV);
103 std::shared_ptr<GeomAPI_Pnt> aCenter(
104 new GeomAPI_Pnt(aCentralPnt.X(), aCentralPnt.Y(), aCentralPnt.Z()));
106 // Obtain plane direction
107 gp_XYZ aNormalVec = aDU.XYZ().Crossed(aDV.XYZ());
108 if (aNormalVec.SquareModulus() < Precision::Confusion() * Precision::Confusion())
109 return std::shared_ptr<GeomAPI_Pln>();
110 std::shared_ptr<GeomAPI_Dir> aNormal(
111 new GeomAPI_Dir(aNormalVec.X(), aNormalVec.Y(), aNormalVec.Z()));
113 std::shared_ptr<GeomAPI_Pln> aResult(new GeomAPI_Pln(aCenter, aNormal));