From 5168b52b0c364940f6ef78e7adb7708db4512cd7 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 4 Feb 2019 17:56:28 +0300 Subject: [PATCH 1/1] Optimization for the naming structure loading in the issue 2636 model --- src/Model/Model_ResultBody.cpp | 38 ++++++++++++++++++++++++++-------- src/Model/Model_ResultBody.h | 4 ++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index e1d3ab200..68e0c990d 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -306,14 +306,16 @@ void Model_ResultBody::updateSubs( const GeomShapePtr& theThisShape, const std::list& theOlds, const std::shared_ptr theMakeShape, const bool isGenerated) { - // to avoid changing of "isDisabled" flag in the "updateSubs" cycle - isDisabled(); myAlgo = theMakeShape; myOlds = theOlds; myIsGenerated = isGenerated; + // to avoid changing of "isDisabled" flag in the "updateSubs" cycle + isDisabled(); + updateSubs(theThisShape, true); myAlgo.reset(); myOlds.clear(); + myHistoryCash.Clear(); } @@ -387,15 +389,33 @@ void Model_ResultBody::computeOldForSub(const GeomShapePtr& theSub, // iterate one level more (for intersection of solids this is face) collectSubs(*aRootOlds, anOldSubs, true); for (TopTools_MapOfShape::Iterator anOldIter(anOldSubs); anOldIter.More(); anOldIter.Next()) { - GeomShapePtr anOldSub(new GeomAPI_Shape); - anOldSub->setImpl(new TopoDS_Shape(anOldIter.Value())); - if (anOldSub->isCompound() || anOldSub->isShell() || anOldSub->isWire()) + TopoDS_Shape anOldShape = anOldIter.Value(); + if (anOldShape.ShapeType() == TopAbs_COMPOUND || anOldShape.ShapeType() == TopAbs_SHELL || + anOldShape.ShapeType() == TopAbs_WIRE) continue; // container old-shapes are not supported by the history, may cause crash + GeomShapePtr anOldSub(new GeomAPI_Shape); + anOldSub->setImpl(new TopoDS_Shape(anOldShape)); + ListOfShape aNews; - myIsGenerated ? myAlgo->generated(anOldSub, aNews) : myAlgo->modified(anOldSub, aNews); - // MakeShape may return alone old shape if there is no history information for this input - if (aNews.size() == 1 && aNews.front()->isEqual(anOldSub)) - aNews.clear(); + if (myHistoryCash.IsBound(anOldShape)) { + const TopTools_ListOfShape& aList = myHistoryCash.Find(anOldShape); + for(TopTools_ListIteratorOfListOfShape anIter(aList); anIter.More(); anIter.Next()) { + GeomShapePtr aShape(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(anIter.Value())); + aNews.push_back(aShape); + } + } else { + myIsGenerated ? myAlgo->generated(anOldSub, aNews) : myAlgo->modified(anOldSub, aNews); + // MakeShape may return alone old shape if there is no history information for this input + if (aNews.size() == 1 && aNews.front()->isEqual(anOldSub)) + aNews.clear(); + // store result in the history + TopTools_ListOfShape aList; + for (ListOfShape::iterator aNewIter = aNews.begin(); aNewIter != aNews.end(); aNewIter++) { + aList.Append((*aNewIter)->impl()); + } + myHistoryCash.Bind(anOldShape, aList); + } for (ListOfShape::iterator aNewIter = aNews.begin(); aNewIter != aNews.end(); aNewIter++) { if (aSubSubs.Contains((*aNewIter)->impl())) { diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index a810f2ea0..629b7c808 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -26,6 +26,8 @@ #include #include +#include + /**\class Model_ResultBody * \ingroup DataModel * \brief The body (shape) result of a feature. @@ -49,6 +51,8 @@ class Model_ResultBody : public ModelAPI_ResultBody std::list myOlds; /// Information about the kind of the history information: modified or generated bool myIsGenerated; + /// Map from old shape to list of new shapes, cash for computeOldForSub method + TopTools_DataMapOfShapeListOfShape myHistoryCash; public: -- 2.39.2