Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / Model / Model_Session.cpp
index 51f97e0f717c628408167d9eb638e4798cd07433..16a4d07f0bc2d242ffd2b63de10d32fdc5e8978a 100644 (file)
@@ -13,6 +13,7 @@
 #include <Events_Loop.h>
 #include <Events_Error.h>
 #include <Config_FeatureMessage.h>
+#include <Config_AttributeMessage.h>
 #include <Config_ValidatorMessage.h>
 #include <Config_ModuleReader.h>
 
@@ -41,14 +42,14 @@ bool Model_Session::save(const char* theFileName, std::list<std::string>& theRes
 void Model_Session::startOperation()
 {
   ROOT_DOC->startOperation();
+  static boost::shared_ptr<Events_Message> aStartedMsg
+    (new Events_Message(Events_Loop::eventByName("StartOperation")));
+  Events_Loop::loop()->send(aStartedMsg);
 }
 
 void Model_Session::finishOperation()
 {
   ROOT_DOC->finishOperation();
-  static boost::shared_ptr<Events_Message> aFinishMsg
-    (new Events_Message(Events_Loop::eventByName("FinishOperation")));
-  Events_Loop::loop()->send(aFinishMsg);
 }
 
 void Model_Session::abortOperation()
@@ -91,22 +92,22 @@ void Model_Session::redo()
 
 FeaturePtr Model_Session::createFeature(string theFeatureID)
 {
-  if (this != myImpl)
+  if (this != myImpl) {
     return myImpl->createFeature(theFeatureID);
+  }
 
-  LoadPluginsInfo();
   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()) {
       Events_Error::send(
-          string("Feature '") + theFeatureID + "' can not be created in document '"
+          string("Feature '") + theFeatureID + "' can be created only in document '"
               + aPlugin.second + "' by the XML definition");
       return FeaturePtr();
     }
     myCurrentPluginName = aPlugin.first;
     if (myPluginObjs.find(myCurrentPluginName) == myPluginObjs.end()) {
       // load plugin library if not yet done
-      Config_ModuleReader::loadLibrary(myCurrentPluginName);
+      Config_ModuleReader::loadPlugin(myCurrentPluginName);
     }
     if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
       FeaturePtr aCreated = myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
@@ -144,12 +145,15 @@ boost::shared_ptr<ModelAPI_Document> Model_Session::activeDocument()
   return myCurrentDoc;
 }
 
-void Model_Session::setActiveDocument(boost::shared_ptr<ModelAPI_Document> theDoc)
+void Model_Session::setActiveDocument(
+  boost::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal)
 {
   if (myCurrentDoc != theDoc) {
     myCurrentDoc = theDoc;
-    static boost::shared_ptr<Events_Message> aMsg(new Events_Message(Events_Loop::eventByName("CurrentDocumentChanged")));
-    Events_Loop::loop()->send(aMsg);
+    if (theSendSignal) {
+      static boost::shared_ptr<Events_Message> aMsg(new Events_Message(Events_Loop::eventByName("CurrentDocumentChanged")));
+      Events_Loop::loop()->send(aMsg);
+    }
   }
 }
 
@@ -191,7 +195,7 @@ boost::shared_ptr<ModelAPI_Document> Model_Session::copy(
   aRT->SetRelocation(aSourceRoot, aTargetRoot);
   TDF_CopyTool::Copy(aDS, aRT);
 
-  aNew->synchronizeFeatures();
+  aNew->synchronizeFeatures(false, true);
   return aNew;
 }
 
@@ -202,17 +206,20 @@ Model_Session::Model_Session()
   ModelAPI_Session::setSession(boost::shared_ptr<ModelAPI_Session>(this));
   // register the configuration reading listener
   Events_Loop* aLoop = Events_Loop::loop();
-  static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
+  static const Events_ID kFeatureEvent = Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
   aLoop->registerListener(this, kFeatureEvent);
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED), 0, true);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED), 0, true);
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED), 0, true);
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_VALIDATOR_LOADED));
+  
+  // load all information about plugins, features and attributes
+  LoadPluginsInfo();
 }
 
 void Model_Session::processEvent(const boost::shared_ptr<Events_Message>& theMessage)
 {
-  static const Events_ID kFeatureEvent = Events_Loop::eventByName("FeatureRegisterEvent");
+  static const Events_ID kFeatureEvent = Events_Loop::eventByName(Config_FeatureMessage::MODEL_EVENT());
   static const Events_ID kValidatorEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
   if (theMessage->eventID() == kFeatureEvent) {
     const boost::shared_ptr<Config_FeatureMessage> aMsg = 
@@ -223,6 +230,18 @@ void Model_Session::processEvent(const boost::shared_ptr<Events_Message>& theMes
         myPlugins[aMsg->id()] = std::pair<std::string, std::string>(
           aMsg->pluginLibrary(), aMsg->documentKind());
       }
+    } else {
+      const boost::shared_ptr<Config_AttributeMessage> aMsgAttr = 
+        boost::dynamic_pointer_cast<Config_AttributeMessage>(theMessage);
+      if (aMsgAttr) {
+        if (!aMsgAttr->isObligatory()) {
+          validators()->registerNotObligatory(aMsgAttr->featureId(), aMsgAttr->attributeId());
+        }
+        if(aMsgAttr->isConcealment()) {
+          validators()->registerConcealment(aMsgAttr->featureId(), aMsgAttr->attributeId());
+        }
+        
+      }
     }
     // plugins information was started to load, so, it will be loaded
     myPluginsInfoLoaded = true;
@@ -249,7 +268,7 @@ void Model_Session::LoadPluginsInfo()
     return;
 
   // Read plugins information from XML files
-  Config_ModuleReader aXMLReader("FeatureRegisterEvent");
+  Config_ModuleReader aXMLReader(Config_FeatureMessage::MODEL_EVENT());
   aXMLReader.readAll();
 }