Salome HOME
Optimization for the naming structure loading in the issue 2636 model
authormpv <mpv@opencascade.com>
Mon, 4 Feb 2019 14:56:28 +0000 (17:56 +0300)
committermpv <mpv@opencascade.com>
Mon, 4 Feb 2019 14:56:28 +0000 (17:56 +0300)
src/Model/Model_ResultBody.cpp
src/Model/Model_ResultBody.h

index e1d3ab200d72aaf5cb6ab549c819a0ec5d90e77e..68e0c990d23fc93b4dfbfc62a44621f8091dd2ec 100644 (file)
@@ -306,14 +306,16 @@ void Model_ResultBody::updateSubs(
   const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
   const std::shared_ptr<GeomAlgoAPI_MakeShape> 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<TopoDS_Shape>(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<TopoDS_Shape>(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<TopoDS_Shape>(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<TopoDS_Shape>());
+        }
+        myHistoryCash.Bind(anOldShape, aList);
+      }
 
       for (ListOfShape::iterator aNewIter = aNews.begin(); aNewIter != aNews.end(); aNewIter++) {
         if (aSubSubs.Contains((*aNewIter)->impl<TopoDS_Shape>())) {
index a810f2ea0fd0a9bdd5a5e100bad014f1a3b91c96..629b7c808a91b5379192fa4e8a6167e4ae7d9455 100644 (file)
@@ -26,6 +26,8 @@
 #include <vector>
 #include <map>
 
+#include <TopTools_DataMapOfShapeListOfShape.hxx>
+
 /**\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<GeomShapePtr> 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: