]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make events for Model and GUI about the features reading independent
authormpv <mikhail.ponikarov@opencascade.com>
Fri, 11 Apr 2014 10:52:33 +0000 (14:52 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Fri, 11 Apr 2014 10:52:33 +0000 (14:52 +0400)
src/Config/Config_FeatureReader.cpp
src/Config/Config_FeatureReader.h
src/Config/Config_ModuleReader.cpp
src/Config/Config_ModuleReader.h
src/Model/Model_Document.cxx
src/Model/Model_Events.cxx
src/Model/Model_Events.h
src/Model/Model_PluginManager.cxx
src/XGUI/XGUI_Workshop.cpp

index 1cb2ef83da1768002d6d7df81ad528b8c6e61bea..204c83487bd2454e4bf0349bff205004eb2ce1f1 100644 (file)
 
 
 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
-                                           const std::string& theLibraryName)
+                                           const std::string& theLibraryName,
+                                           const char* theEventGenerated)
     : Config_XMLReader(theXmlFile),
-      myLibraryName(theLibraryName)
+      myLibraryName(theLibraryName),
+      myEventGenerated(theEventGenerated ? theEventGenerated : "FeatureEvent")
 {
 }
 
@@ -35,7 +37,7 @@ Config_FeatureReader::~Config_FeatureReader()
 
 void Config_FeatureReader::processNode(xmlNodePtr theNode)
 {
-  static Event_ID aMenuItemEvent = Event_Loop::eventByName("FeatureEvent");
+  Event_ID aMenuItemEvent = Event_Loop::eventByName(myEventGenerated);
   if (isNode(theNode, NODE_FEATURE, NULL)) {
     Event_Loop* aEvLoop = Event_Loop::loop();
     Config_FeatureMessage aMessage(aMenuItemEvent, this);
index da5fa77fea93a188d7db3ca6b4ffe831dffee718..7b5322bba036468272244794f370455f610c1fdb 100644 (file)
@@ -20,7 +20,8 @@ class Config_FeatureReader: public Config_XMLReader
 {
 public:
   Config_FeatureReader(const std::string& theXmlFile,
-                       const std::string& theLibraryName = "");
+                       const std::string& theLibraryName = "",
+                       const char* theEventGenerated = 0);
   virtual ~Config_FeatureReader();
 
 protected:
@@ -33,6 +34,8 @@ private:
   std::string myLastWorkbench;
   std::string myLastGroup;
   std::string myLibraryName;
+  /// event generated on feature data sending, by default it is "FeatureEvent"
+  const char* myEventGenerated;
 };
 
 #endif /* CONFIG_FEATUREREADER_H_ */
index d77e6b830fd7ee091cf6d1ab7b5083c768d65de9..54c12d1d51e7119136e2452db9d966f274fb72e9 100644 (file)
@@ -18,8 +18,8 @@
 
 
 
-Config_ModuleReader::Config_ModuleReader()
-    : Config_XMLReader("plugins.xml"), myIsAutoImport(false)
+Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
+    : Config_XMLReader("plugins.xml"), myIsAutoImport(false), myEventGenerated(theEventGenerated)
 {
 }
 
@@ -63,7 +63,7 @@ void Config_ModuleReader::importPlugin(const std::string& thePluginName,
   if(thePluginLibrary.empty()) {
     aReader = new Config_FeatureReader(thePluginName);
   } else {
-    aReader = new Config_FeatureReader(thePluginName, thePluginLibrary);
+    aReader = new Config_FeatureReader(thePluginName, thePluginLibrary, myEventGenerated);
   }
   aReader->readAll();
 }
index 33567bdd27aa495af8caad59436d0c9ba8a0fbed..7083315b1426b42a3bbedfd57e521c2d7081a503 100644 (file)
@@ -19,7 +19,7 @@ class Config_ModuleReader: public Config_XMLReader
 {
 
 public:
-  CONFIG_EXPORT Config_ModuleReader();
+  CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
   CONFIG_EXPORT virtual ~Config_ModuleReader();
 
   CONFIG_EXPORT void setAutoImport(bool enabled);
@@ -37,7 +37,7 @@ protected:
 private:
   bool myIsAutoImport;
   std::map<std::string, std::string> myPluginsMap;
-
+  const char* myEventGenerated;
 
 };
 
index 0e976420c45652ec8dd63448b16428dce0790e84..03a497213a70ee1d715857eeccb4a9514e7f29bc 100644 (file)
@@ -222,7 +222,8 @@ void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeatu
   TDF_Label anObjLab = aGroupLab.NewChild();
   std::shared_ptr<Model_Data> aData(new Model_Data);
   aData->setLabel(anObjLab);
-  aData->setDocument(Model_Application::getApplication()->getDocument(myID));
+  shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
+  aData->setDocument(aThis);
   theFeature->setData(aData);
   setUniqueName(theFeature);
   theFeature->initAttributes();
@@ -234,7 +235,7 @@ void Model_Document::addFeature(const std::shared_ptr<ModelAPI_Feature> theFeatu
 
   // event: feature is added
   static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
-  ModelAPI_FeatureUpdatedMessage aMsg(theFeature, anEvent);
+  ModelAPI_FeatureUpdatedMessage aMsg(aThis, theFeature, anEvent);
   Event_Loop::loop()->send(aMsg);
 }
 
@@ -349,6 +350,7 @@ void Model_Document::setUniqueName(
 
 void Model_Document::synchronizeFeatures()
 {
+  shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(myID);
   // iterate groups labels
   TDF_ChildIDIterator aGroupsIter(myDoc->Main().FindChild(TAG_OBJECTS),
     TDataStd_Comment::GetID(), Standard_False);
@@ -400,8 +402,7 @@ void Model_Document::synchronizeFeatures()
       if (aDSTag > aFeatureTag) { // feature is removed
         aFIter = aFeatures.erase(aFIter);
         // event: model is updated
-        ModelAPI_FeatureDeletedMessage aMsg(
-          Model_Application::getApplication()->getDocument(myID), aGroupName);
+        ModelAPI_FeatureDeletedMessage aMsg(aThis, aGroupName);
         Event_Loop::loop()->send(aMsg);
       } else if (aDSTag < aFeatureTag) { // a new feature is inserted
         // create a feature
@@ -417,7 +418,7 @@ void Model_Document::synchronizeFeatures()
         aFeature->initAttributes();
         // event: model is updated
         static Event_ID anEvent = Event_Loop::eventByName(EVENT_FEATURE_CREATED);
-        ModelAPI_FeatureUpdatedMessage aMsg(aFeature, anEvent);
+        ModelAPI_FeatureUpdatedMessage aMsg(aThis, aFeature, anEvent);
         Event_Loop::loop()->send(aMsg);
 
         if (aFIter == aFeatures.end()) {
index f9ddb0f110f31bb1d391bbcc6b90ed055c136277..dc35573ebae8a405ab2eab7f77800ebcdb2d41f0 100644 (file)
@@ -6,8 +6,9 @@
 #include <Event_Loop.h>
 
 ModelAPI_FeatureUpdatedMessage::ModelAPI_FeatureUpdatedMessage(
+  const std::shared_ptr<ModelAPI_Document>& theDoc,
   const std::shared_ptr<ModelAPI_Feature>& theFeature, const Event_ID& theEvent)
-  : Event_Message(theEvent, 0), myFeature(theFeature)
+  : Event_Message(theEvent, 0), myFeature(theFeature), myDoc(theDoc)
 {}
 
 ModelAPI_FeatureDeletedMessage::ModelAPI_FeatureDeletedMessage(
index e969458d69291573f8fe47fab8ef7fba80e78acd..0fc4f329c0efefbb302b0a02a73091d9cea15561 100644 (file)
@@ -22,14 +22,19 @@ static const char * EVENT_FEATURE_DELETED = "FeatureDeleted";
 
 /// Message that feature was changed (used for Object Browser update)
 class ModelAPI_FeatureUpdatedMessage : public Event_Message {
+  std::shared_ptr<ModelAPI_Document> myDoc; ///< document owner of the feature
   std::shared_ptr<ModelAPI_Feature> myFeature; ///< which feature is changed
 public:
   /// sender is not important, all information is located in the feature
-  ModelAPI_FeatureUpdatedMessage(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  ModelAPI_FeatureUpdatedMessage(
+    const std::shared_ptr<ModelAPI_Document>& theDoc,
+    const std::shared_ptr<ModelAPI_Feature>& theFeature,
     const Event_ID& theEvent);
 
   /// Returns the feature that has been updated
   std::shared_ptr<ModelAPI_Feature> feature() {return myFeature;}
+  /// Returns the document that has been updated
+  std::shared_ptr<ModelAPI_Document> document() {return myDoc;}
 };
 
 /// Message that feature was deleted (used for Object Browser update)
index 724f30e2639c812c5af0569a209a28f09259f6cc..eb279208afff32ba365016d136eac30c71cb7297 100644 (file)
@@ -64,7 +64,7 @@ Model_PluginManager::Model_PluginManager()
 {
   myPluginsInfoLoaded = false;
   //TODO(sbh): Implement static method to extract event id [SEID]
-  static Event_ID aFeatureEvent = Event_Loop::eventByName("FeatureEvent");
+  static Event_ID aFeatureEvent = Event_Loop::eventByName("FeatureRegisterEvent");
 
   ModelAPI_PluginManager::SetPluginManager(std::shared_ptr<ModelAPI_PluginManager>(this));
   // register the configuration reading listener
@@ -92,7 +92,7 @@ void Model_PluginManager::LoadPluginsInfo()
     return;
 
   // Read plugins information from XML files
-  Config_ModuleReader aXMLReader;
+  Config_ModuleReader aXMLReader("FeatureRegisterEvent");
   aXMLReader.setAutoImport(true);
   aXMLReader.readAll();
 }
index 4dbd97a532de5a6a1e3e2a0f73e4489d29724885..6ff419ecf47d15b95119e5bb89382974e945abdc 100644 (file)
@@ -135,9 +135,10 @@ XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
 //******************************************************
 void XGUI_Workshop::processEvent(const Event_Message* theMessage)
 {
-  const Config_FeatureMessage* aFeatureMsg =
-      dynamic_cast<const Config_FeatureMessage*>(theMessage);
-  if (aFeatureMsg) {
+  static Event_ID aFeatureId = Event_Loop::loop()->eventByName("FeatureEvent");
+  if (theMessage->eventID() == aFeatureId) {
+    const Config_FeatureMessage* aFeatureMsg =
+        dynamic_cast<const Config_FeatureMessage*>(theMessage);
     addFeature(aFeatureMsg);
     return;
   }