X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Face.cpp;h=8e8a036552229f714fd34183216f69bdfc34d72c;hb=f9426a402de748e9d13085856a7cf72a3659135d;hp=b025bca92ee2b6f3f081619f8bc071c09e1ca03b;hpb=2532fb2df83ee1ddd9ff3e8b381d3788eaa15b69;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index b025bca92..8e8a03655 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -14,7 +14,8 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com // #include "GeomAPI_Face.h" @@ -22,18 +23,34 @@ #include "GeomAPI_Dir.h" #include "GeomAPI_Pln.h" #include "GeomAPI_Pnt.h" +#include "GeomAPI_Sphere.h" +#include "GeomAPI_Cylinder.h" +#include "GeomAPI_Cone.h" +#include "GeomAPI_Torus.h" #include #include #include +#include +#include #include +#include +#include #include #include +#include #include #include +#include #include #include +#include +#include +#include +#include + + GeomAPI_Face::GeomAPI_Face() : GeomAPI_Shape() { @@ -81,9 +98,9 @@ bool GeomAPI_Face::isEqual(std::shared_ptr theFace) const return false; Handle(IntTools_Context) aContext = new IntTools_Context(); - // Double check needed bacause BOPTools_AlgoTools::CheckSameGeom not very smart. - Standard_Boolean aRes = BOPTools_AlgoTools::CheckSameGeom(aMyFace, aInFace, aContext) - && BOPTools_AlgoTools::CheckSameGeom(aInFace, aMyFace, aContext); + // Double check needed because BOPTools_AlgoTools::AreFacesSameDomain not very smart. + Standard_Boolean aRes = BOPTools_AlgoTools::AreFacesSameDomain(aMyFace, aInFace, aContext) + && BOPTools_AlgoTools::AreFacesSameDomain(aInFace, aMyFace, aContext); return aRes == Standard_True; } @@ -129,3 +146,112 @@ std::shared_ptr GeomAPI_Face::getPlane() const aResult = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); return aResult; } + +std::shared_ptr GeomAPI_Face::getSphere() const +{ + GeomSpherePtr aSphere; + + const TopoDS_Face& aFace = TopoDS::Face(impl()); + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + if (aSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) { + gp_Sphere aSph = Handle(Geom_SphericalSurface)::DownCast(aSurf)->Sphere(); + const gp_Pnt& aCenter = aSph.Location(); + double aRadius = aSph.Radius(); + + GeomPointPtr aCenterPnt(new GeomAPI_Pnt(aCenter.X(), aCenter.Y(), aCenter.Z())); + aSphere = GeomSpherePtr(new GeomAPI_Sphere(aCenterPnt, aRadius)); + } + return aSphere; +} + +std::shared_ptr GeomAPI_Face::getCylinder() const +{ + GeomCylinderPtr aCylinder; + + const TopoDS_Face& aFace = TopoDS::Face(impl()); + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + if (aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) { + gp_Cylinder aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf)->Cylinder(); + gp_Pnt aLoc = aCyl.Location(); + const gp_Dir& aDir = aCyl.Position().Direction(); + double aRadius = aCyl.Radius(); + + double aUMin, aUMax, aVMin, aVMax; + BRepTools::UVBounds(aFace, aUMin, aUMax, aVMin, aVMax); + double aHeight = aVMax - aVMin; + + aLoc.ChangeCoord() += aDir.XYZ() * aVMin; + GeomPointPtr aLocation(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); + GeomDirPtr aDirection(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); + aCylinder = GeomCylinderPtr(new GeomAPI_Cylinder(aLocation, aDirection, aRadius, aHeight)); + } + return aCylinder; +} + +std::shared_ptr GeomAPI_Face::getCone() const +{ + GeomConePtr aCone; + + const TopoDS_Face& aFace = TopoDS::Face(impl()); + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + if (aSurf->IsKind(STANDARD_TYPE(Geom_ConicalSurface))) { + gp_Cone aCon = Handle(Geom_ConicalSurface)::DownCast(aSurf)->Cone(); + gp_Pnt aLoc = aCon.Location(); + gp_Dir aDir = aCon.Position().Direction(); + + double aUMin, aUMax, aVMin, aVMax; + BRepTools::UVBounds(aFace, aUMin, aUMax, aVMin, aVMax); + + double aSemiAngle = Abs(aCon.SemiAngle()); + double aRadius1 = aCon.RefRadius() + aVMin * Sin(aCon.SemiAngle()); + double aRadius2 = aCon.RefRadius() + aVMax * Sin(aCon.SemiAngle()); + + aLoc.ChangeCoord() += aDir.XYZ() * aVMin * Cos(aCon.SemiAngle()); + + GeomPointPtr aLocation(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); + GeomDirPtr aDirection(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); + aCone = GeomConePtr(new GeomAPI_Cone(aLocation, aDirection, aSemiAngle, aRadius1, aRadius2)); + } + return aCone; +} + +std::shared_ptr GeomAPI_Face::getTorus() const +{ + GeomTorusPtr aTorus; + + const TopoDS_Face& aFace = TopoDS::Face(impl()); + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + if (aSurf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface))) { + gp_Torus aTor = Handle(Geom_ToroidalSurface)::DownCast(aSurf)->Torus(); + const gp_Pnt& aLoc = aTor.Location(); + const gp_Dir& aDir = aTor.Position().Direction(); + double aMajorRadius = aTor.MajorRadius(); + double aMinorRadius = aTor.MinorRadius(); + + GeomPointPtr aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); + GeomDirPtr aDirection(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); + aTorus = GeomTorusPtr(new GeomAPI_Torus(aCenter, aDirection, aMajorRadius, aMinorRadius)); + } + return aTorus; +} + +GeomPointPtr GeomAPI_Face::middlePoint() const +{ + GeomPointPtr anInnerPoint; + + const TopoDS_Face& aFace = impl(); + if (aFace.IsNull()) + return anInnerPoint; + + BRepGProp_Face aProp(aFace); + double aUMin, aUMax, aVMin, aVMax; + aProp.Bounds(aUMin, aUMax, aVMin, aVMax); + + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + if (aSurf.IsNull()) + return anInnerPoint; + + gp_Pnt aPnt = aSurf->Value((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5); + anInnerPoint = GeomPointPtr(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z())); + return anInnerPoint; +}