Salome HOME
Make features history working. Optimization of features and results management and...
[modules/shaper.git] / src / Model / Model_Session.cpp
index 8b81240a2bcc185126d3b6f582bce8cdc9059396..921e964cb87be0d1a8d9abf15c2f53c9276378c6 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>
@@ -130,10 +132,10 @@ std::list<std::string> Model_Session::redoList()
   return ROOT_DOC->redoList();
 }
 
-FeaturePtr Model_Session::createFeature(string theFeatureID)
+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
@@ -141,7 +143,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");
@@ -172,8 +174,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)
@@ -205,7 +217,7 @@ void Model_Session::setActiveDocument(
       if (aDoc.get()) {
         bool aWasChecked = myCheckTransactions;
         setCheckTransactions(false);
-        aDoc->synchronizeFeatures(false, true);
+        aDoc->objects()->synchronizeFeatures(false, true, true);
         if (aWasChecked)
             setCheckTransactions(true);
       }
@@ -255,7 +267,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;
 }
 
@@ -299,7 +311,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
@@ -338,8 +353,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)