Salome HOME
Fix for activation of deleted and undo-deleted documents.
authormpv <mpv@opencascade.com>
Wed, 16 Dec 2015 09:33:00 +0000 (12:33 +0300)
committermpv <mpv@opencascade.com>
Wed, 16 Dec 2015 09:33:00 +0000 (12:33 +0300)
src/Model/Model_Objects.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_Session.cpp
src/Model/Model_Session.h

index b083c265c6667552389eaca5b68f21f797a1d786..b34d47f142bb0285dd4f6fbd46122bcb29b3f598 100644 (file)
@@ -562,6 +562,13 @@ void Model_Objects::setUniqueName(FeaturePtr theFeature)
         isSameName = (*aRIter)->data()->name() == aName;
       }
     }
+    // for new Parts create names that are not in the Postponed list
+    if (!isSameName && (theFeature->getKind() == "Part" || theFeature->getKind() == "Duplicate")) {
+      std::shared_ptr<Model_Session> aSession = 
+        std::dynamic_pointer_cast<Model_Session>(Model_Session::get());
+      isSameName = aSession->isLoadByDemand(aName) || aSession->hasDocument(aName);
+    }
+
     if (isSameName) {
       aNumObjects++;
       std::stringstream aNameStream;
index b38c0bb092d812bb38f8dbdea66a886dc8c8621e..431576afbacd1cd57096b850b45cfa445ec24f25 100644 (file)
@@ -62,8 +62,15 @@ void Model_ResultPart::activate()
 
   std::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->document(DOC_REF());
   
+  // activation may cause changes in current features in document, so it must be in transaction
+  bool isNewTransaction = false;
+  SessionPtr aMgr = ModelAPI_Session::get();
   if (!aDocRef->value().get()) {  // create (or open) a document if it is not yet created
     myIsInLoad = true;
+    if (!aMgr->isOperation()) {
+      aMgr->startOperation("Activation");
+      isNewTransaction = true;
+    }
     std::shared_ptr<ModelAPI_Document> aDoc = document()->subDocument(data()->name());
     myIsInLoad = false;
     if (aDoc) {
@@ -72,16 +79,10 @@ void Model_ResultPart::activate()
     }
   }
   if (aDocRef->value().get()) {
-    SessionPtr aMgr = ModelAPI_Session::get();
-    bool isNewTransaction = !aMgr->isOperation();
-    // activation may cause changes in current features in document, so it must be in transaction
-    if (isNewTransaction) {
-      aMgr->startOperation("Activation");
-    }
     ModelAPI_Session::get()->setActiveDocument(aDocRef->value());
-    if (isNewTransaction) {
-      aMgr->finishOperation();
-    }
+  }
+  if (isNewTransaction) {
+    aMgr->finishOperation();
   }
 }
 
index 172b7d3ff220ffd0e685853b53ffc524b62cb89f..6b3194d5a08b73e3065f9495fdc9393646cd7933 100644 (file)
@@ -61,8 +61,11 @@ void Model_Session::startOperation(const std::string& theId, const bool theAttac
     (new Events_Message(Events_Loop::eventByName("StartOperation")));
   Events_Loop::loop()->send(aStartedMsg);
   // remove all useless documents that has been closed: on start of operation undo/redo is cleared
-  std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
-  Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
+  // MPV: this code is dangerous now because it may close the document that is activated right now
+  // but not in the list of the opened documents yet (create, delete, undo, activate Part)
+  // later this must be updated by correct usage of uniques IDs of documents, not names of results
+  //std::list<std::shared_ptr<ModelAPI_Document> > aUsedDocs = allOpenedDocuments();
+  //Model_Application::getApplication()->removeUselessDocuments(aUsedDocs);
 }
 
 void Model_Session::finishOperation()
@@ -208,6 +211,11 @@ bool Model_Session::hasModuleDocument()
   return Model_Application::getApplication()->hasDocument("root");
 }
 
+bool Model_Session::hasDocument(std::string theDocID)
+{
+  return Model_Application::getApplication()->hasDocument(theDocID);
+}
+
 std::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
 {
   if (!myCurrentDoc || !Model_Application::getApplication()->hasDocument(myCurrentDoc->id()))
index 1e200f40e0bc03836bfa608b8b98b891ff529a65..04eadff1c12646b0ddff5b51e99177fbe6922808 100644 (file)
@@ -81,6 +81,8 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
 
   /// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document(std::string theDocID);
+  /// Return true if document with such ID has been already created
+  MODEL_EXPORT virtual bool hasDocument(std::string theDocID);
 
   /// Return true if root document has been already created
   MODEL_EXPORT virtual bool hasModuleDocument();