Salome HOME
Issue #517: make sketch sub-elements are numbered (for naming) independently on featu...
[modules/shaper.git] / src / Model / Model_Session.cpp
index 042ebe6f3964ec88c3a1d6a44b544fe6f2f43651..ff74e5bf3ad2b095e274c7cbdbfb9ff7c9739a91 100644 (file)
@@ -52,8 +52,9 @@ void Model_Session::closeAll()
   Model_Application::getApplication()->deleteAllDocuments();
 }
 
-void Model_Session::startOperation(const std::string& theId)
+void Model_Session::startOperation(const std::string& theId, const bool theAttachedToNested)
 {
+  myOperationAttachedToNext = theAttachedToNested;
   ROOT_DOC->startOperation();
   ROOT_DOC->operationId(theId);
   static std::shared_ptr<Events_Message> aStartedMsg
@@ -68,6 +69,10 @@ void Model_Session::finishOperation()
 {
   setCheckTransactions(false);
   ROOT_DOC->finishOperation();
+  if (myOperationAttachedToNext) { // twice, with nested
+    ROOT_DOC->finishOperation();
+    myOperationAttachedToNext = false;
+  }
   setCheckTransactions(true);
 }
 
@@ -75,6 +80,10 @@ void Model_Session::abortOperation()
 {
   setCheckTransactions(false);
   ROOT_DOC->abortOperation();
+  if (myOperationAttachedToNext) { // twice, with nested
+    ROOT_DOC->abortOperation();
+    myOperationAttachedToNext = false;
+  }
   setCheckTransactions(true);
   // here the update mechanism may work after abort, so, supress the warnings about
   // modifications outside of the transactions
@@ -209,9 +218,8 @@ std::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
 /// makes the last feature in the document as the current
 static void makeCurrentLast(std::shared_ptr<ModelAPI_Document> theDoc) {
   if (theDoc.get()) {
-    FeaturePtr aLastFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theDoc->object(
-      ModelAPI_Feature::group(), theDoc->size(ModelAPI_Feature::group()) - 1));
-    theDoc->setCurrentFeature(aLastFeature, false);
+    FeaturePtr aLast = std::dynamic_pointer_cast<Model_Document>(theDoc)->lastFeature();
+    theDoc->setCurrentFeature(aLast, false);
   }
 }
 
@@ -219,6 +227,11 @@ void Model_Session::setActiveDocument(
   std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal)
 {
   if (myCurrentDoc != theDoc) {
+    if (myCurrentDoc.get())
+      myCurrentDoc->setActive(false);
+    if (theDoc.get())
+      theDoc->setActive(true);
+
     std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
     myCurrentDoc = theDoc;
     if (theDoc.get() && theSendSignal) {
@@ -309,6 +322,7 @@ Model_Session::Model_Session()
 {
   myPluginsInfoLoaded = false;
   myCheckTransactions = true;
+  myOperationAttachedToNext = false;
   ModelAPI_Session::setSession(std::shared_ptr<ModelAPI_Session>(this));
   // register the configuration reading listener
   Events_Loop* aLoop = Events_Loop::loop();
@@ -420,3 +434,8 @@ ModelAPI_ValidatorsFactory* Model_Session::validators()
   static Model_ValidatorsFactory* aFactory = new Model_ValidatorsFactory;
   return aFactory;
 }
+
+int Model_Session::transactionID()
+{
+  return ROOT_DOC->transactionID();
+}