diff --git a/src/GEOMAlgo/BlockFix_UnionFaces.cxx b/src/GEOMAlgo/BlockFix_UnionFaces.cxx index 577943930..e513cbe59 100644 --- a/src/GEOMAlgo/BlockFix_UnionFaces.cxx +++ b/src/GEOMAlgo/BlockFix_UnionFaces.cxx @@ -23,55 +23,62 @@ // Created: Tue Dec 7 17:15:42 2004 // Author: Pavel DURANDIN // + #include -#include -#include -#include + +#include +#include + +#include #include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + #include #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include #include #include +#include + +#include +#include #include #include +#include +#include +#include +#include + +#include +#include //======================================================================= //function : BlockFix_UnionFaces @@ -292,7 +299,7 @@ TopoDS_Shape BlockFix_UnionFaces::Perform(const TopoDS_Shape& Shape) } } while (isNewFound); - // sorting eny type of edges + // sorting any type of edges aWire = TopoDS::Wire(aContext->Apply(aWire)); TopoDS_Face tmpF = TopoDS::Face(aContext->Apply(faces(1).Oriented(TopAbs_FORWARD))); @@ -489,7 +496,91 @@ Standard_Boolean BlockFix_UnionFaces::IsSameDomain(const TopoDS_Face& aFace, S1 = BRep_Tool::Surface(aFace,L1); S2 = BRep_Tool::Surface(aCheckedFace,L2); - return (S1 == S2 && L1 == L2); + if (S1 == S2 && L1 == L2) + return true; + + // begin: planar case (improvement 20052) + S1 = BRep_Tool::Surface(aFace); + S2 = BRep_Tool::Surface(aCheckedFace); + + Handle(Geom_Plane) aGP1, aGP2; + Handle(Geom_RectangularTrimmedSurface) aGRTS1, aGRTS2; + Handle(Geom_OffsetSurface) aGOFS1, aGOFS2; + + aGRTS1 = Handle(Geom_RectangularTrimmedSurface)::DownCast(S1); + aGRTS2 = Handle(Geom_RectangularTrimmedSurface)::DownCast(S2); + + aGOFS1 = Handle(Geom_OffsetSurface)::DownCast(S1); + aGOFS2 = Handle(Geom_OffsetSurface)::DownCast(S2); + + if (!aGOFS1.IsNull()) { + aGP1 = Handle(Geom_Plane)::DownCast(aGOFS1->BasisSurface()); + } + else if (!aGRTS1.IsNull()) { + aGP1 = Handle(Geom_Plane)::DownCast(aGRTS1->BasisSurface()); + } + else { + aGP1 = Handle(Geom_Plane)::DownCast(S1); + } + + if (!aGOFS2.IsNull()) { + aGP2 = Handle(Geom_Plane)::DownCast(aGOFS2->BasisSurface()); + } + else if (!aGRTS2.IsNull()) { + aGP2 = Handle(Geom_Plane)::DownCast(aGRTS2->BasisSurface()); + } + else { + aGP2 = Handle(Geom_Plane)::DownCast(S2); + } + + if (!aGP1.IsNull() && !aGP2.IsNull()) { + // both surfaces are planar, check equality + Standard_Real A1, B1, C1, D1; + Standard_Real A2, B2, C2, D2; + aGP1->Coefficients(A1, B1, C1, D1); + aGP2->Coefficients(A2, B2, C2, D2); + + if (fabs(A1) > Precision::Confusion()) { + A1 = 1.0; + B1 /= A1; + C1 /= A1; + D1 /= A1; + } + else if (fabs(B1) > Precision::Confusion()) { + B1 = 1.0; + C1 /= B1; + D1 /= B1; + } + else { + C1 = 1.0; + D1 /= C1; + } + + if (fabs(A2) > Precision::Confusion()) { + A2 = 1.0; + B2 /= A2; + C2 /= A2; + D2 /= A2; + } + else if (fabs(B2) > Precision::Confusion()) { + B2 = 1.0; + C2 /= B2; + D2 /= B2; + } + else { + C2 = 1.0; + D2 /= C2; + } + + if (fabs(A1 - A2) < Precision::Confusion() && + fabs(B1 - B2) < Precision::Confusion() && + fabs(C1 - C2) < Precision::Confusion() && + fabs(D1 - D2) < Precision::Confusion()) + return true; + } + // end: planar case (improvement 20052) + + return false; } @@ -529,4 +620,3 @@ void BlockFix_UnionFaces::MovePCurves(TopoDS_Face& aTarget, B.Add(aTarget,ResWire); } } -