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 <BRep_Tool.hxx>
14 #include <BRepAdaptor_Surface.hxx>
15 #include <Geom_Surface.hxx>
16 #include <Geom_CylindricalSurface.hxx>
17 #include <Geom_RectangularTrimmedSurface.hxx>
19 #include <TopoDS_Face.hxx>
21 GeomAPI_Face::GeomAPI_Face()
26 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
28 if (!theShape->isNull() && theShape->isFace()) {
29 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
33 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
38 if (!theFace->isFace())
41 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
42 const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
44 Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(TopoDS::Face(aMyShape));
45 Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(TopoDS::Face(aInShape));
47 // Check that surfaces a the same type
48 if (aMySurf->DynamicType() != aInSurf->DynamicType())
51 // Get parameters of surfaces
52 double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
53 aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
54 double aInUMin, aInUMax, aInVMin, aInVMax;
55 aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
57 // Check that parameters are the same
58 if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
59 fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
60 fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
61 fabs(aMyVMax - aInVMax) > Precision::PConfusion())
67 bool GeomAPI_Face::isCylindrical() const
69 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
70 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
71 Handle(Geom_RectangularTrimmedSurface) aTrimmed =
72 Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf);
73 if (!aTrimmed.IsNull())
74 aSurf = aTrimmed->BasisSurface();
75 return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
78 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
80 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
81 BRepAdaptor_Surface aSurfAdapt(TopoDS::Face(aShape));
83 if (aSurfAdapt.GetType() != GeomAbs_Plane)
84 return std::shared_ptr<GeomAPI_Pln>();
86 // Obtain central point
87 double aUMin, aUMax, aVMin, aVMax;
88 aUMin = aSurfAdapt.FirstUParameter();
89 aUMax = aSurfAdapt.LastUParameter();
90 aVMin = aSurfAdapt.FirstVParameter();
91 aVMax = aSurfAdapt.LastVParameter();
94 aSurfAdapt.D1((aUMin+aUMax)*0.5, (aVMin+aVMax)*0.5, aCentralPnt, aDU, aDV);
95 std::shared_ptr<GeomAPI_Pnt> aCenter(
96 new GeomAPI_Pnt(aCentralPnt.X(), aCentralPnt.Y(), aCentralPnt.Z()));
98 // Obtain plane direction
99 gp_XYZ aNormalVec = aDU.XYZ().Crossed(aDV.XYZ());
100 if (aNormalVec.SquareModulus() < Precision::Confusion() * Precision::Confusion())
101 return std::shared_ptr<GeomAPI_Pln>();
102 std::shared_ptr<GeomAPI_Dir> aNormal(
103 new GeomAPI_Dir(aNormalVec.X(), aNormalVec.Y(), aNormalVec.Z()));
105 std::shared_ptr<GeomAPI_Pln> aResult(new GeomAPI_Pln(aCenter, aNormal));