From: mpv Date: Fri, 11 Apr 2014 10:52:33 +0000 (+0400) Subject: Make events for Model and GUI about the features reading independent X-Git-Tag: V_0.1~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ec70f37d26f584bdd46983837b01407429f29478;p=modules%2Fshaper.git Make events for Model and GUI about the features reading independent --- diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 1cb2ef83d..204c83487 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -23,9 +23,11 @@ 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); diff --git a/src/Config/Config_FeatureReader.h b/src/Config/Config_FeatureReader.h index da5fa77fe..7b5322bba 100644 --- a/src/Config/Config_FeatureReader.h +++ b/src/Config/Config_FeatureReader.h @@ -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_ */ diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index d77e6b830..54c12d1d5 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -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(); } diff --git a/src/Config/Config_ModuleReader.h b/src/Config/Config_ModuleReader.h index 33567bdd2..7083315b1 100644 --- a/src/Config/Config_ModuleReader.h +++ b/src/Config/Config_ModuleReader.h @@ -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 myPluginsMap; - + const char* myEventGenerated; }; diff --git a/src/Model/Model_Document.cxx b/src/Model/Model_Document.cxx index 0e976420c..03a497213 100644 --- a/src/Model/Model_Document.cxx +++ b/src/Model/Model_Document.cxx @@ -222,7 +222,8 @@ void Model_Document::addFeature(const std::shared_ptr theFeatu TDF_Label anObjLab = aGroupLab.NewChild(); std::shared_ptr aData(new Model_Data); aData->setLabel(anObjLab); - aData->setDocument(Model_Application::getApplication()->getDocument(myID)); + shared_ptr 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 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 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()) { diff --git a/src/Model/Model_Events.cxx b/src/Model/Model_Events.cxx index f9ddb0f11..dc35573eb 100644 --- a/src/Model/Model_Events.cxx +++ b/src/Model/Model_Events.cxx @@ -6,8 +6,9 @@ #include ModelAPI_FeatureUpdatedMessage::ModelAPI_FeatureUpdatedMessage( + const std::shared_ptr& theDoc, const std::shared_ptr& theFeature, const Event_ID& theEvent) - : Event_Message(theEvent, 0), myFeature(theFeature) + : Event_Message(theEvent, 0), myFeature(theFeature), myDoc(theDoc) {} ModelAPI_FeatureDeletedMessage::ModelAPI_FeatureDeletedMessage( diff --git a/src/Model/Model_Events.h b/src/Model/Model_Events.h index e969458d6..0fc4f329c 100644 --- a/src/Model/Model_Events.h +++ b/src/Model/Model_Events.h @@ -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 myDoc; ///< document owner of the feature std::shared_ptr myFeature; ///< which feature is changed public: /// sender is not important, all information is located in the feature - ModelAPI_FeatureUpdatedMessage(const std::shared_ptr& theFeature, + ModelAPI_FeatureUpdatedMessage( + const std::shared_ptr& theDoc, + const std::shared_ptr& theFeature, const Event_ID& theEvent); /// Returns the feature that has been updated std::shared_ptr feature() {return myFeature;} + /// Returns the document that has been updated + std::shared_ptr document() {return myDoc;} }; /// Message that feature was deleted (used for Object Browser update) diff --git a/src/Model/Model_PluginManager.cxx b/src/Model/Model_PluginManager.cxx index 724f30e26..eb279208a 100644 --- a/src/Model/Model_PluginManager.cxx +++ b/src/Model/Model_PluginManager.cxx @@ -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(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(); } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 4dbd97a53..6ff419ecf 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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(theMessage); - if (aFeatureMsg) { + static Event_ID aFeatureId = Event_Loop::loop()->eventByName("FeatureEvent"); + if (theMessage->eventID() == aFeatureId) { + const Config_FeatureMessage* aFeatureMsg = + dynamic_cast(theMessage); addFeature(aFeatureMsg); return; }