X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAPI%2FGeomAPI_Face.cpp;h=c6b76d2bd62a286ac34917d5ee2497afafab7941;hb=918e097c6c3f8e02abf72c74f7a117c3b5adab61;hp=8e8a036552229f714fd34183216f69bdfc34d72c;hpb=2e9b24400c6194f045ae581a77bc2a49e6626fe0;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Face.cpp b/src/GeomAPI/GeomAPI_Face.cpp index 8e8a03655..c6b76d2bd 100644 --- a/src/GeomAPI/GeomAPI_Face.cpp +++ b/src/GeomAPI/GeomAPI_Face.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// 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" @@ -24,6 +23,7 @@ #include "GeomAPI_Pln.h" #include "GeomAPI_Pnt.h" #include "GeomAPI_Sphere.h" +#include "GeomAPI_Curve.h" #include "GeomAPI_Cylinder.h" #include "GeomAPI_Cone.h" #include "GeomAPI_Torus.h" @@ -33,13 +33,22 @@ #include #include #include +#include #include #include #include #include +#include +#include #include +#include +#include +#include #include +#include +#include #include +#include #include #include #include @@ -105,6 +114,97 @@ bool GeomAPI_Face::isEqual(std::shared_ptr theFace) const return aRes == Standard_True; } +static Handle(Geom_Surface) baseSurface(const TopoDS_Face& theFace) +{ + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(theFace); + while (aSurf->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { + Handle(Geom_RectangularTrimmedSurface) rts = + Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurf); + aSurf = rts->BasisSurface(); + } + return aSurf; +} + +bool GeomAPI_Face::isSameGeometry(const std::shared_ptr theShape) const +{ + if (!theShape->isFace()) + return false; + if (isSame(theShape)) + return true; + + GeomFacePtr anOther = theShape->face(); + if (isPlanar() && anOther->isPlanar()) { + GeomPlanePtr anOwnPlane = getPlane(); + GeomPlanePtr anOtherPlane = anOther->getPlane(); + return anOwnPlane->isCoincident(anOtherPlane); + } + + TopoDS_Face anOwnFace = TopoDS::Face(impl()); + TopoDS_Face anOtherFace = TopoDS::Face(theShape->impl()); + + Handle(Geom_Surface) anOwnSurf = baseSurface(anOwnFace); + Handle(Geom_Surface) anOtherSurf = baseSurface(anOtherFace); + + // case of two elementary surfaces + if (anOwnSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface)) && + anOtherSurf->IsKind(STANDARD_TYPE(Geom_ElementarySurface))) + { + Handle(GeomAdaptor_HSurface) aGA1 = new GeomAdaptor_HSurface(anOwnSurf); + Handle(GeomAdaptor_HSurface) aGA2 = new GeomAdaptor_HSurface(anOtherSurf); + + Handle(BRepTopAdaptor_TopolTool) aTT1 = new BRepTopAdaptor_TopolTool(); + Handle(BRepTopAdaptor_TopolTool) aTT2 = new BRepTopAdaptor_TopolTool(); + + try { + IntPatch_ImpImpIntersection anIIInt(aGA1, aTT1, aGA2, aTT2, + Precision::Confusion(), + Precision::Confusion()); + if (!anIIInt.IsDone() || anIIInt.IsEmpty()) + return false; + + return anIIInt.TangentFaces(); + } + catch (Standard_Failure const&) { + return false; + } + } + + // case of two cylindrical surfaces, at least one of which is a swept surface + // swept surfaces: SurfaceOfLinearExtrusion, SurfaceOfRevolution + if ((anOwnSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) || + anOwnSurf->IsKind(STANDARD_TYPE(Geom_SweptSurface))) && + (anOtherSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) || + anOtherSurf->IsKind(STANDARD_TYPE(Geom_SweptSurface)))) + { + GeomCylinderPtr anOwnCyl = getCylinder(); + GeomCylinderPtr anOtherCyl = anOther->getCylinder(); + if (anOwnCyl && anOtherCyl) + return anOwnCyl->isCoincident(anOtherCyl); + + // compare two swept surfaces of the same type + if ((anOwnSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion)) && + anOtherSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfLinearExtrusion))) || + (anOwnSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)) && + anOtherSurf->IsKind(STANDARD_TYPE(Geom_SurfaceOfRevolution)))) { + Handle(Geom_SweptSurface) anOwnSwept = Handle(Geom_SweptSurface)::DownCast(anOwnSurf); + Handle(Geom_SweptSurface) anOtherSwept = Handle(Geom_SweptSurface)::DownCast(anOtherSurf); + + const gp_Dir& anOwnDir = anOwnSwept->Direction(); + const gp_Dir& anOtherDir = anOtherSwept->Direction(); + + if (anOwnDir.IsParallel(anOtherDir, Precision::Angular())) { + Handle(Geom_Curve) anOwnCurve = anOwnSwept->BasisCurve(); + Handle(Geom_Curve) anOtherCurve = anOtherSwept->BasisCurve(); + GeomAPI_ExtremaCurveCurve anExtrema(anOwnCurve, anOtherCurve); + return anExtrema.Extrema().IsParallel() && + anExtrema.TotalLowerDistance() < Precision::Confusion(); + } + } + } + + return false; +} + bool GeomAPI_Face::isCylindrical() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); @@ -130,20 +230,35 @@ std::shared_ptr GeomAPI_Face::getPlane() const Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); if (aSurf.IsNull()) return aResult; // no surface - GeomLib_IsPlanarSurface isPlanar(aSurf); - if(!isPlanar.IsPlanar()) { - return aResult; + GeomLib_IsPlanarSurface isPlanarSurf(aSurf); + gp_Pln aPln; + bool isPlanar = false; + if (isPlanarSurf.IsPlanar()) { + aPln = isPlanarSurf.Plan(); + isPlanar = true; } - gp_Pln aPln = isPlanar.Plan(); - double aA, aB, aC, aD; - aPln.Coefficients(aA, aB, aC, aD); - if (aFace.Orientation() == TopAbs_REVERSED) { - aA = -aA; - aB = -aB; - aC = -aC; - aD = -aD; + else if (aSurf->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { + Handle(Geom_OffsetSurface) anOffsetSurf = Handle(Geom_OffsetSurface)::DownCast(aSurf); + Handle(Geom_Surface) aBasisSurf = anOffsetSurf->BasisSurface(); + if (aBasisSurf->IsKind(STANDARD_TYPE(Geom_Plane))) { + aPln = Handle(Geom_Plane)::DownCast(aBasisSurf)->Pln(); + gp_Vec aTranslation(aPln.Axis().Direction().XYZ() * anOffsetSurf->Offset()); + aPln.Translate(aTranslation); + isPlanar = true; + } + } + + if (isPlanar) { + double aA, aB, aC, aD; + aPln.Coefficients(aA, aB, aC, aD); + if (aFace.Orientation() == TopAbs_REVERSED) { + aA = -aA; + aB = -aB; + aC = -aC; + aD = -aD; + } + aResult = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); } - aResult = std::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); return aResult; } @@ -203,8 +318,8 @@ std::shared_ptr GeomAPI_Face::getCone() const 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()); + double aRadius1 = Abs(aCon.RefRadius() + aVMin * Sin(aCon.SemiAngle())); + double aRadius2 = Abs(aCon.RefRadius() + aVMax * Sin(aCon.SemiAngle())); aLoc.ChangeCoord() += aDir.XYZ() * aVMin * Cos(aCon.SemiAngle());