Salome HOME
Prepare version 1.2.1: quick fix for iteration 2 release
[modules/shaper.git] / src / Model / Model_Session.cpp
index 306c4d47eb451cf4e8d6200679b8e2b2ff3216af..04229f2c2257af2b46404547d8a463d4c23fe384 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModelAPI_Plugin.h>
 #include <Model_Data.h>
 #include <Model_Document.h>
+#include <Model_Objects.h>
 #include <Model_Application.h>
 #include <Model_Events.h>
 #include <Model_Validator.h>
@@ -19,6 +20,7 @@
 #include <Config_AttributeMessage.h>
 #include <Config_ValidatorMessage.h>
 #include <Config_ModuleReader.h>
+#include <Config_ValidatorReader.h>
 #include <ModelAPI_ResultPart.h>
 
 #include <TDF_CopyTool.hxx>
@@ -35,7 +37,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, ROOT_DOC);
+  return aRes;
 }
 
 bool Model_Session::save(const char* theFileName, std::list<std::string>& theResults)
@@ -45,13 +48,13 @@ bool Model_Session::save(const char* theFileName, std::list<std::string>& theRes
 
 void Model_Session::closeAll()
 {
-  ROOT_DOC->close(true);
   Model_Application::getApplication()->deleteAllDocuments();
 }
 
-void Model_Session::startOperation()
+void Model_Session::startOperation(const std::string& theId)
 {
   ROOT_DOC->startOperation();
+  ROOT_DOC->operationId(theId);
   static std::shared_ptr<Events_Message> aStartedMsg
     (new Events_Message(Events_Loop::eventByName("StartOperation")));
   Events_Loop::loop()->send(aStartedMsg);
@@ -62,12 +65,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 +103,9 @@ bool Model_Session::canUndo()
 
 void Model_Session::undo()
 {
+  setCheckTransactions(false);
   ROOT_DOC->undo();
+  setCheckTransactions(true);
 }
 
 bool Model_Session::canRedo()
@@ -106,13 +115,26 @@ bool Model_Session::canRedo()
 
 void Model_Session::redo()
 {
+  setCheckTransactions(false);
   ROOT_DOC->redo();
+  setCheckTransactions(true);
 }
 
-FeaturePtr Model_Session::createFeature(string theFeatureID)
+//! Returns stack of performed operations
+std::list<std::string> Model_Session::undoList()
+{
+  return ROOT_DOC->undoList();
+}
+//! Returns stack of rolled back operations
+std::list<std::string> Model_Session::redoList()
+{
+  return ROOT_DOC->redoList();
+}
+
+FeaturePtr Model_Session::createFeature(string theFeatureID, Model_Document* theDocOwner)
 {
   if (this != myImpl) {
-    return myImpl->createFeature(theFeatureID);
+    return myImpl->createFeature(theFeatureID, theDocOwner);
   }
 
   // load all information about plugins, features and attributes
@@ -120,7 +142,7 @@ FeaturePtr Model_Session::createFeature(string theFeatureID)
 
   if (myPlugins.find(theFeatureID) != myPlugins.end()) {
     std::pair<std::string, std::string>& aPlugin = myPlugins[theFeatureID]; // plugin and doc kind
-    if (!aPlugin.second.empty() && aPlugin.second != activeDocument()->kind()) {
+    if (!aPlugin.second.empty() && aPlugin.second != theDocOwner->kind()) {
       Events_Error::send(
           string("Feature '") + theFeatureID + "' can be created only in document '"
               + aPlugin.second + "' by the XML definition");
@@ -151,8 +173,18 @@ FeaturePtr Model_Session::createFeature(string theFeatureID)
 
 std::shared_ptr<ModelAPI_Document> Model_Session::moduleDocument()
 {
-  return std::shared_ptr<ModelAPI_Document>(
+  bool aFirstCall = !Model_Application::getApplication()->hasDocument("root");
+  if (aFirstCall) {
+    // creation of the root document is always outside of the transaction, so, avoid checking it
+    setCheckTransactions(false);
+  }
+  std::shared_ptr<ModelAPI_Document> aDoc = std::shared_ptr<ModelAPI_Document>(
       Model_Application::getApplication()->getDocument("root"));
+  if (aFirstCall) {
+    // creation of the root document is always outside of the transaction, so, avoid checking it
+    setCheckTransactions(true);
+  }
+  return aDoc;
 }
 
 std::shared_ptr<ModelAPI_Document> Model_Session::document(std::string theDocID)
@@ -178,7 +210,16 @@ void Model_Session::setActiveDocument(
 {
   if (myCurrentDoc != theDoc) {
     myCurrentDoc = theDoc;
-    if (theSendSignal) {
+    if (theDoc.get() && 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.get()) {
+        bool aWasChecked = myCheckTransactions;
+        setCheckTransactions(false);
+        aDoc->objects()->synchronizeFeatures(false, true, 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);
@@ -208,6 +249,11 @@ std::list<std::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments
   return aResult;
 }
 
+bool Model_Session::isLoadByDemand(const std::string theDocID)
+{
+  return Model_Application::getApplication()->isLoadByDemand(theDocID);
+}
+
 std::shared_ptr<ModelAPI_Document> Model_Session::copy(
     std::shared_ptr<ModelAPI_Document> theSource, std::string theID)
 {
@@ -225,7 +271,7 @@ std::shared_ptr<ModelAPI_Document> Model_Session::copy(
   aRT->SetRelocation(aSourceRoot, aTargetRoot);
   TDF_CopyTool::Copy(aDS, aRT);
 
-  aNew->synchronizeFeatures(false, true);
+  aNew->objects()->synchronizeFeatures(false, true, true);
   return aNew;
 }
 
@@ -269,7 +315,10 @@ void Model_Session::processEvent(const std::shared_ptr<Events_Message>& theMessa
         if(aMsgAttr->isConcealment()) {
           validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
         }
-        
+        if (!aMsgAttr->caseId().empty()) {
+          validators()->registerCase(aMsgAttr->featureId(), aMsgAttr->attributeId(),
+            aMsgAttr->switchId(), aMsgAttr->caseId());
+        }
       }
     }
     // plugins information was started to load, so, it will be loaded
@@ -308,8 +357,15 @@ void Model_Session::LoadPluginsInfo()
     return;
 
   // Read plugins information from XML files
-  Config_ModuleReader aXMLReader(Config_FeatureMessage::MODEL_EVENT());
-  aXMLReader.readAll();
+  Config_ModuleReader aModuleReader(Config_FeatureMessage::MODEL_EVENT());
+  aModuleReader.readAll();
+  std::set<std::string> aFiles = aModuleReader.modulePluginFiles();
+  std::set<std::string>::iterator it = aFiles.begin();
+  for ( ; it != aFiles.end(); it++ ) {
+    Config_ValidatorReader aValidatorReader (*it);
+    aValidatorReader.readAll();
+  };
+
 }
 
 void Model_Session::registerPlugin(ModelAPI_Plugin* thePlugin)