diff --git a/src/FoundationClasses/TKMath/TopLoc/TopLoc_Location.cxx b/src/FoundationClasses/TKMath/TopLoc/TopLoc_Location.cxx index d7d970f0e3..96c0d99399 100644 --- a/src/FoundationClasses/TKMath/TopLoc/TopLoc_Location.cxx +++ b/src/FoundationClasses/TKMath/TopLoc/TopLoc_Location.cxx @@ -125,6 +125,18 @@ TopLoc_Location TopLoc_Location::Divided(const TopLoc_Location& Other) const TopLoc_Location TopLoc_Location::Predivided(const TopLoc_Location& Other) const { + if (Other.IsIdentity()) + { + return *this; + } + if (IsIdentity()) + { + return Other.Inverted(); + } + if (*this == Other) + { + return TopLoc_Location(); + } return Other.Inverted().Multiplied(*this); } diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx index b47ead18fd..bbeb73362d 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.cxx @@ -159,8 +159,12 @@ void BRepGProp_Face::Bounds(double& U1, double& U2, double& V1, double& V2) cons bool BRepGProp_Face::Load(const TopoDS_Edge& E) { - double a, b; - occ::handle C = BRep_Tool::CurveOnSurface(E, mySurface.Face(), a, b); + double a, b; + if (!myIsFaceContextReady) + { + return false; + } + occ::handle C = BRep_Tool::CurveOnSurface(E, myFaceSurface, myFaceLocation, a, b); if (C.IsNull()) { return false; @@ -182,6 +186,8 @@ void BRepGProp_Face::Load(const TopoDS_Face& F) { TopoDS_Shape aLocalShape = F.Oriented(TopAbs_FORWARD); mySurface.Initialize(TopoDS::Face(aLocalShape)); + myFaceSurface = BRep_Tool::Surface(mySurface.Face(), myFaceLocation); + myIsFaceContextReady = !myFaceSurface.IsNull(); // mySurface.Initialize(TopoDS::Face(F.Oriented(TopAbs_FORWARD))); mySReverse = (F.Orientation() == TopAbs_REVERSED); } diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.hxx b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.hxx index 0dd9dfeeef..63df4bd921 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.hxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.hxx @@ -28,12 +28,15 @@ #include #include #include +#include + class TopoDS_Face; class gp_Pnt; class gp_Vec; class TopoDS_Edge; class gp_Pnt2d; class gp_Vec2d; +class Geom_Surface; class BRepGProp_Face { @@ -149,10 +152,13 @@ public: occ::handle>& theTKnots) const; private: - BRepAdaptor_Surface mySurface; - Geom2dAdaptor_Curve myCurve; - bool mySReverse; - bool myIsUseSpan; + BRepAdaptor_Surface mySurface; + Geom2dAdaptor_Curve myCurve; + occ::handle myFaceSurface; + TopLoc_Location myFaceLocation; + bool myIsFaceContextReady; + bool mySReverse; + bool myIsUseSpan; }; #include diff --git a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.lxx b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.lxx index e796b7ecf1..f2554bd4e9 100644 --- a/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.lxx +++ b/src/ModelingAlgorithms/TKTopAlgo/BRepGProp/BRepGProp_Face.lxx @@ -21,7 +21,8 @@ //======================================================================= inline BRepGProp_Face::BRepGProp_Face(const bool IsUseSpan) - : mySReverse(false), + : myIsFaceContextReady(false), + mySReverse(false), myIsUseSpan(IsUseSpan) { } @@ -33,7 +34,9 @@ inline BRepGProp_Face::BRepGProp_Face(const bool IsUseSpan) //======================================================================= inline BRepGProp_Face::BRepGProp_Face(const TopoDS_Face& F, const bool IsUseSpan) - : myIsUseSpan(IsUseSpan) + : myIsFaceContextReady(false), + mySReverse(false), + myIsUseSpan(IsUseSpan) { Load(F); } diff --git a/src/ModelingData/TKBRep/BRep/BRep_Tool.cxx b/src/ModelingData/TKBRep/BRep/BRep_Tool.cxx index 25b51676fc..19a7bd756c 100644 --- a/src/ModelingData/TKBRep/BRep/BRep_Tool.cxx +++ b/src/ModelingData/TKBRep/BRep/BRep_Tool.cxx @@ -321,28 +321,31 @@ occ::handle BRep_Tool::CurveOnSurface(const TopoDS_Edge& double& Last, bool* theIsStored) { - TopLoc_Location loc = L.Predivided(E.Location()); - bool Eisreversed = (E.Orientation() == TopAbs_REVERSED); + bool Eisreversed = (E.Orientation() == TopAbs_REVERSED); if (theIsStored) *theIsStored = true; // find the representation const BRep_TEdge* TE = static_cast(E.TShape().get()); NCollection_List>::Iterator itcr(TE->Curves()); - - while (itcr.More()) + if (itcr.More()) { - const occ::handle& cr = itcr.Value(); - if (cr->IsCurveOnSurface(S, loc)) + const TopLoc_Location loc = L.Predivided(E.Location()); + + while (itcr.More()) { - const BRep_GCurve* GC = static_cast(cr.get()); - GC->Range(First, Last); - if (GC->IsCurveOnClosedSurface() && Eisreversed) - return GC->PCurve2(); - else - return GC->PCurve(); + const occ::handle& cr = itcr.Value(); + if (cr->IsCurveOnSurface(S, loc)) + { + const BRep_GCurve* GC = static_cast(cr.get()); + GC->Range(First, Last); + if (GC->IsCurveOnClosedSurface() && Eisreversed) + return GC->PCurve2(); + else + return GC->PCurve(); + } + itcr.Next(); } - itcr.Next(); } // Curve is not found. Try projection on plane