]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/Model/Model_ResultBody.cpp
Salome HOME
Initial implementation of higher level objects history for partition
[modules/shaper.git] / src / Model / Model_ResultBody.cpp
index 8b736b3390be79340d546aceab0e8125992e375c..8368220f942ce1eae62c42e4b1a70bf5d6f7a7c3 100644 (file)
@@ -95,31 +95,12 @@ void Model_ResultBody::loadModifiedShapes(const std::shared_ptr<GeomAlgoAPI_Make
                                           const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
                                           const std::string& theName)
 {
-  if (/*theSplitInSubs &&*/ mySubs.size()) { // consists of subs
+  if (mySubs.size()) { // consists of subs
     // optimization of getting of new shapes for specific sub-result
     if (!theAlgo->isNewShapesCollected(theOldShape, theShapeTypeToExplore))
       theAlgo->collectNewShapes(theOldShape, theShapeTypeToExplore);
     std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
     for(; aSubIter != mySubs.cend(); aSubIter++) {
-      // check that sub-shape was also created as modification of ShapeIn
-      /* to find when it is needed later to enable: to store modification of sub-bodies not only as primitives
-      GeomShapePtr aSubGeomShape = (*aSubIter)->shape();
-      if (!theIsStoreAsGenerated && aSubGeomShape.get() && !aSubGeomShape->isNull()) {
-        TopoDS_Shape aSubShape = aSubGeomShape->impl<TopoDS_Shape>();
-        TopoDS_Shape aWholeIn = theShapeIn->impl<TopoDS_Shape>();
-        for(TopExp_Explorer anExp(aWholeIn, aSubShape.ShapeType()); anExp.More(); anExp.Next()) {
-          ListOfShape aHistory;
-          std::shared_ptr<GeomAPI_Shape> aSubIn(new GeomAPI_Shape());
-          aSubIn->setImpl((new TopoDS_Shape(anExp.Current())));
-          theMS->modified(aSubIn, aHistory);
-          std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = aHistory.begin();
-          for (; anIt != aHistory.end(); anIt++) {
-            if ((*anIt)->isSame(aSubGeomShape)) {
-              (*aSubIter)->storeModified(aSubIn, aSubGeomShape, -2); // -2 is to avoid clearing
-            }
-          }
-        }
-      }*/
       (*aSubIter)->loadModifiedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theName);
     }
   } else { // do for this directly
@@ -271,8 +252,16 @@ void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisS
       } else { // just update shape of this result
         aSub = mySubs[aSubIndex];
       }
-      if (!aShape->isEqual(aSub->shape())) {
-        aSub->store(aShape, false);
+      GeomShapePtr anOldSubShape = aSub->shape();
+      if (!aShape->isEqual(anOldSubShape)) {
+        if (myAlgo.get()) {
+          std::list<GeomShapePtr> anOldForSub;
+          computeOldForSub(aShape, anOldForSub);
+          myIsGenerated ? aSub->storeGenerated(anOldForSub, aShape, myAlgo) :
+            aSub->storeModified(anOldForSub, aShape, myAlgo);
+        } else {
+          aSub->store(aShape, false);
+        }
         aECreator->sendUpdated(aSub, EVENT_DISP);
         aECreator->sendUpdated(aSub, EVENT_UPD);
       }
@@ -293,6 +282,7 @@ void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisS
       // redisplay this because result with and without subs are displayed differently
       aECreator->sendUpdated(data()->owner(), EVENT_DISP);
     }
+    cleanCash();
   } else if (!mySubs.empty()) { // erase all subs
     while(!mySubs.empty()) {
       ResultBodyPtr anErased = *(mySubs.rbegin());
@@ -309,20 +299,19 @@ void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisS
   }
 }
 
-bool Model_ResultBody::isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape)
+void Model_ResultBody::updateSubs(
+  const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
+  const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated)
 {
-  if (myBuilder->isLatestEqual(theShape))
-    return true;
-  // also check that it is asked for sub-elements
-  std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
-  for(; aSubIter != mySubs.cend(); aSubIter++) {
-    if (aSubIter->get() && (*aSubIter)->isLatestEqual(theShape)) {
-      return true;
-    }
-  }
-  return false;
+  myAlgo = theMakeShape;
+  myOlds = theOlds;
+  myIsGenerated = isGenerated;
+  updateSubs(theThisShape, true);
+  myAlgo.reset();
+  myOlds.clear();
 }
 
+
 bool Model_ResultBody::isConnectedTopology()
 {
   TDF_Label aDataLab = std::dynamic_pointer_cast<Model_Data>(data())->label();
@@ -340,3 +329,30 @@ bool Model_ResultBody::isConnectedTopology()
   }
   return false; // invalid case
 }
+
+void Model_ResultBody::cleanCash()
+{
+  myBuilder->cleanCash();
+  for (std::vector<ResultBodyPtr>::const_iterator aSubIter = mySubs.cbegin();
+    aSubIter != mySubs.cend(); ++aSubIter)
+  {
+    const ResultBodyPtr& aSub = *aSubIter;
+    aSub->cleanCash();
+  }
+}
+
+void Model_ResultBody::computeOldForSub(
+  const GeomShapePtr& theSubShape, std::list<GeomShapePtr>& theOldForSub)
+{
+  std::list<GeomShapePtr>::iterator aRootOlds = myOlds.begin();
+  for(; aRootOlds != myOlds.end(); aRootOlds++) {
+    ListOfShape aNews;
+    myIsGenerated ? myAlgo->generated(*aRootOlds, aNews) : myAlgo->modified(*aRootOlds, aNews);
+    for(ListOfShape::iterator aNewIter = aNews.begin(); aNewIter != aNews.end(); aNewIter++) {
+      if (theSubShape->isSame(*aNewIter)) { // found old that was used for new theSubShape creation
+        theOldForSub.push_back(*aRootOlds);
+        break;
+      }
+    }
+  }
+}