Salome HOME
Revert "Issue #3044: Undo list contains empty string for Load python script"
[modules/shaper.git] / src / Model / Model_Document.cpp
index 082a6c60fd51f13be8e96a2cacab2d9b536eac75..be2877848b1a34b891a39b3dae19561fb94e780a 100644 (file)
@@ -892,9 +892,10 @@ void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchron
     myDoc->Undo();
   }
 
+  std::set<int> aSubs;
   if (theWithSubs) {
     // undo for all subs
-    const std::set<int> aSubs = subDocuments();
+    aSubs = subDocuments();
     std::set<int>::iterator aSubIter = aSubs.begin();
     for (; aSubIter != aSubs.end(); aSubIter++) {
       if (!subDoc(*aSubIter)->myObjs)
@@ -907,6 +908,19 @@ void Model_Document::undoInternal(const bool theWithSubs, const bool theSynchron
     myObjs->synchronizeFeatures(aDeltaLabels, true, false, false, isRoot());
     // update the current features status
     setCurrentFeature(currentFeature(false), false);
+
+    if (theWithSubs) {
+      // undo for all subs
+      const std::set<int> aNewSubs = subDocuments();
+      std::set<int>::iterator aNewSubIter = aNewSubs.begin();
+      for (; aNewSubIter != aNewSubs.end(); aNewSubIter++) {
+        // synchronize only newly appeared documents
+        if (!subDoc(*aNewSubIter)->myObjs || aSubs.find(*aNewSubIter) != aSubs.end())
+          continue;
+        TDF_LabelList anEmptyDeltas;
+        subDoc(*aNewSubIter)->myObjs->synchronizeFeatures(anEmptyDeltas, true, false, true, true);
+      }
+    }
   }
 }
 
@@ -1024,15 +1038,15 @@ FeaturePtr Model_Document::addFeature(std::string theID, const bool theMakeCurre
           aCurrent = aSub;
         }
       }
-      // #2861: if the parameter is added, add it after parameters existing in the list
-      if (aCurrent.get() &&
-          (aFeature->getKind() == "Parameter" || aFeature->getKind() == "ParametersMgr")) {
-        int anIndex = kUNDEFINED_FEATURE_INDEX;
-        for(FeaturePtr aNextFeat = myObjs->nextFeature(aCurrent, anIndex);
-            aNextFeat.get() && aNextFeat->getKind() == "Parameter";
-            aNextFeat = myObjs->nextFeature(aCurrent, anIndex))
-          aCurrent = aNextFeat;
-      }
+    }
+    // #2861,3029: if the parameter is added, add it after parameters existing in the list
+    if (aCurrent.get() &&
+      (aFeature->getKind() == "Parameter" || aFeature->getKind() == "ParametersMgr")) {
+      int anIndex = kUNDEFINED_FEATURE_INDEX;
+      for(FeaturePtr aNextFeat = myObjs->nextFeature(aCurrent, anIndex);
+        aNextFeat.get() && aNextFeat->getKind() == "Parameter";
+        aNextFeat = myObjs->nextFeature(aCurrent, anIndex))
+        aCurrent = aNextFeat;
     }
     aDocToAdd->myObjs->addFeature(aFeature, aCurrent);
     if (!aFeature->isAction()) {  // do not add action to the data model