]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
FIx for issue #360 : make switching on/off checking of transactions in Session -...
authormpv <mpv@opencascade.com>
Mon, 26 Jan 2015 11:56:13 +0000 (14:56 +0300)
committermpv <mpv@opencascade.com>
Mon, 26 Jan 2015 11:56:13 +0000 (14:56 +0300)
src/Model/Model_Document.cpp
src/Model/Model_Session.cpp

index f1f10b103763dca05342c19888f0d014678b9146..3efd64be7ee7be75491a628bf3790a68150f4d59 100644 (file)
@@ -156,10 +156,14 @@ bool Model_Document::load(const char* theFileName)
   if (!isError) {
     myDoc->SetUndoLimit(UNDO_LIMIT);
     // to avoid the problem that feature is created in the current, not this, document
-    Model_Session::get()->setActiveDocument(anApp->getDocument(myID), false);
+    std::shared_ptr<Model_Session> aSession = 
+      std::dynamic_pointer_cast<Model_Session>(Model_Session::get());
+    aSession->setActiveDocument(anApp->getDocument(myID), false);
+    aSession->setCheckTransactions(false);
     synchronizeFeatures(false, true);
-    Model_Session::get()->setActiveDocument(Model_Session::get()->moduleDocument(), false);
-    Model_Session::get()->setActiveDocument(anApp->getDocument(myID), true);
+    aSession->setCheckTransactions(true);
+    aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false);
+    aSession->setActiveDocument(anApp->getDocument(myID), true);
   }
   return !isError;
 }
@@ -246,7 +250,8 @@ void Model_Document::close(const bool theForever)
     subDoc(*aSubIter)->close(theForever);
 
   // close for thid document needs no transaction in this document
-  std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(false);
+  if (this == aPM->moduleDocument().get())
+    std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(false);
 
   // delete all features of this document
   std::shared_ptr<ModelAPI_Document> aThis = 
@@ -277,7 +282,8 @@ void Model_Document::close(const bool theForever)
       myDoc->Close();
   }
 
-  std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(true);
+  if (this == aPM->moduleDocument().get())
+    std::static_pointer_cast<Model_Session>(Model_Session::get())->setCheckTransactions(true);
 }
 
 void Model_Document::startOperation()
@@ -323,10 +329,6 @@ void Model_Document::finishOperation()
   bool isNestedClosed = !myDoc->HasOpenCommand() && !myNestedNum.empty();
   static std::shared_ptr<Model_Session> aSession = 
     std::static_pointer_cast<Model_Session>(Model_Session::get());
-  // just to be sure that everybody knows that changes were performed
-  if (isNestedClosed) {
-    aSession->setCheckTransactions(false);  // for nested transaction commit
-  }
   synchronizeBackRefs();
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
@@ -347,10 +349,6 @@ void Model_Document::finishOperation()
   // to avoid "updated" message appearance by updater
   //aLoop->clear(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
 
-  if (isNestedClosed) {
-    aSession->setCheckTransactions(true);  // for nested transaction commit
-  }
-
   // finish for all subs first: to avoid nested finishing and "isOperation" calls problems inside
   const std::set<std::string> aSubs = subDocuments(true);
   std::set<std::string>::iterator aSubIter = aSubs.begin();
@@ -813,8 +811,6 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t
   std::shared_ptr<ModelAPI_Document> aThis = 
     Model_Application::getApplication()->getDocument(myID);
   // after all updates, sends a message that groups of features were created or updated
-  std::static_pointer_cast<Model_Session>(Model_Session::get())
-    ->setCheckTransactions(false);
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->activateFlushes(false);
 
@@ -886,9 +882,9 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t
       ModelAPI_EventCreator::get()->sendUpdated(aFeature, EVENT_DISP);
       aFeature->erase();
       // unbind after the "erase" call: on abort sketch is removes sub-objects that corrupts aFIter
-      TDF_Label aLab = aFIter.Key();
-      aFIter.Next();
-      myObjs.UnBind(aLab);
+      myObjs.UnBind(aFIter.Key());
+      // reinitialize iterator because unbind may corrupt the previous order in the map
+      aFIter.Initialize(myObjs);
     } else
       aFIter.Next();
   }
@@ -905,8 +901,6 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool t
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
   aLoop->flush(Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
-  std::static_pointer_cast<Model_Session>(Model_Session::get())
-    ->setCheckTransactions(true);
   myExecuteFeatures = true;
 }
 
index 306c4d47eb451cf4e8d6200679b8e2b2ff3216af..9f1783fe7b0fb5cd5ea532d53830997d18453ce9 100644 (file)
@@ -35,7 +35,8 @@ static Model_Session* myImpl = new Model_Session();
 
 bool Model_Session::load(const char* theFileName)
 {
-  return ROOT_DOC->load(theFileName);
+  bool aRes = ROOT_DOC->load(theFileName);
+  return aRes;
 }
 
 bool Model_Session::save(const char* theFileName, std::list<std::string>& theResults)
@@ -62,12 +63,16 @@ void Model_Session::startOperation()
 
 void Model_Session::finishOperation()
 {
+  setCheckTransactions(false);
   ROOT_DOC->finishOperation();
+  setCheckTransactions(true);
 }
 
 void Model_Session::abortOperation()
 {
+  setCheckTransactions(false);
   ROOT_DOC->abortOperation();
+  setCheckTransactions(true);
   // here the update mechanism may work after abort, so, supress the warnings about
   // modifications outside of the transactions
   bool aWasCheck = myCheckTransactions;
@@ -96,7 +101,9 @@ bool Model_Session::canUndo()
 
 void Model_Session::undo()
 {
+  setCheckTransactions(false);
   ROOT_DOC->undo();
+  setCheckTransactions(true);
 }
 
 bool Model_Session::canRedo()
@@ -106,7 +113,9 @@ bool Model_Session::canRedo()
 
 void Model_Session::redo()
 {
+  setCheckTransactions(false);
   ROOT_DOC->redo();
+  setCheckTransactions(true);
 }
 
 FeaturePtr Model_Session::createFeature(string theFeatureID)
@@ -179,6 +188,15 @@ void Model_Session::setActiveDocument(
   if (myCurrentDoc != theDoc) {
     myCurrentDoc = theDoc;
     if (theSendSignal) {
+      // syncronize the document: it may be just opened or opened but removed before
+      std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theDoc);
+      if (aDoc) {
+        bool aWasChecked = myCheckTransactions;
+        setCheckTransactions(false);
+        aDoc->synchronizeFeatures(false, true);
+        if (aWasChecked)
+            setCheckTransactions(true);
+      }
       static std::shared_ptr<Events_Message> aMsg(
           new Events_Message(Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)));
       Events_Loop::loop()->send(aMsg);