From: sbh Date: Mon, 23 Mar 2015 08:07:32 +0000 (+0300) Subject: Process validators on the first feature's creation using the Config_ValidatorReader X-Git-Tag: V_1.0.2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1d92b37c3a412e565c82b8dce640a035d9f554c2;p=modules%2Fshaper.git Process validators on the first feature's creation using the Config_ValidatorReader --- diff --git a/src/Config/CMakeLists.txt b/src/Config/CMakeLists.txt index c5ee88f78..591c8489a 100644 --- a/src/Config/CMakeLists.txt +++ b/src/Config/CMakeLists.txt @@ -22,6 +22,7 @@ SET(PROJECT_HEADERS Config_PropManager.h Config_AttributeMessage.h Config_SelectionFilterMessage.h + Config_ValidatorReader.h ) SET(PROJECT_SOURCES @@ -38,6 +39,7 @@ SET(PROJECT_SOURCES Config_PropManager.cpp Config_AttributeMessage.cpp Config_SelectionFilterMessage.cpp + Config_ValidatorReader.cpp ) SET(XML_RESOURCES diff --git a/src/Config/Config_FeatureReader.cpp b/src/Config/Config_FeatureReader.cpp index 94274a40a..48f091aa3 100644 --- a/src/Config/Config_FeatureReader.cpp +++ b/src/Config/Config_FeatureReader.cpp @@ -72,7 +72,7 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode) Events_Loop::loop()->send(aMessage); } } - //Process SOURCE, VALIDATOR nodes. + //Process SOURCE nodes. Config_XMLReader::processNode(theNode); } @@ -111,29 +111,3 @@ void Config_FeatureReader::fillFeature(xmlNodePtr theFeatureNode, } outFeatureMessage->setDocumentKind(aDocKind); } - -void Config_FeatureReader::storeAttribute(xmlNodePtr theNode, - const char* theNodeAttribute) -{ - std::string aKey = getNodeName(theNode) + ":" + std::string(theNodeAttribute); - std::string aValue = getProperty(theNode, theNodeAttribute); - if(!aValue.empty()) { - myParentAttributes[aKey] = aValue; - } -} - -std::string Config_FeatureReader::restoreAttribute(xmlNodePtr theNode, - const char* theNodeAttribute) -{ - return restoreAttribute(getNodeName(theNode).c_str(), theNodeAttribute); -} -std::string Config_FeatureReader::restoreAttribute(const char* theNodeName, - const char* theNodeAttribute) -{ - std::string aKey = std::string(theNodeName) + ":" + std::string(theNodeAttribute); - std::string result = ""; - if(myParentAttributes.find(aKey) != myParentAttributes.end()) { - result = myParentAttributes[aKey]; - } - return result; -} diff --git a/src/Config/Config_FeatureReader.h b/src/Config/Config_FeatureReader.h index 7f7889aaa..35582ae7e 100644 --- a/src/Config/Config_FeatureReader.h +++ b/src/Config/Config_FeatureReader.h @@ -16,7 +16,6 @@ #include #include -#include class Config_FeatureMessage; @@ -46,18 +45,7 @@ class Config_FeatureReader : public Config_XMLReader void fillFeature(xmlNodePtr theRoot, const std::shared_ptr& outFeatureMessage); - /// Stores an attribute in internal map for later use. - /// Key is "Node_Name:Node_Attribute" and value is getProperty(theNodeAttribute) - void storeAttribute(xmlNodePtr theNode, const char* theNodeAttribute); - /// Restores an attribute from internal map. - std::string restoreAttribute(xmlNodePtr theNode, const char* theNodeAttribute); - /// Restores an attribute from internal map. - std::string restoreAttribute(const char* theNodeName, const char* theNodeAttribute); - private: - /// A map to store all parent's attributes. - /// The key has from "Node_Name:Node_Attribute" - std::map myParentAttributes; std::string myLibraryName; std::list myFeatures; diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index 74ab76696..41ceda577 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -48,6 +48,11 @@ const std::map& Config_ModuleReader::featuresInFiles() return myFeaturesInFiles; } +const std::set& Config_ModuleReader::modulePluginFiles() const +{ + return myPluginFiles; +} + /*! * Get module name from plugins.xml * (property "module") @@ -64,6 +69,7 @@ void Config_ModuleReader::processNode(xmlNodePtr theNode) if (!hasRequiredModules(theNode)) return; std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG); + if (!aPluginConf.empty()) myPluginFiles.insert(aPluginConf); std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY); std::string aPluginScript = getProperty(theNode, PLUGIN_SCRIPT); std::string aPluginName = addPlugin(aPluginLibrary, aPluginScript, aPluginConf); diff --git a/src/Config/Config_ModuleReader.h b/src/Config/Config_ModuleReader.h index a6f8c1e2d..bef9c6124 100644 --- a/src/Config/Config_ModuleReader.h +++ b/src/Config/Config_ModuleReader.h @@ -38,6 +38,8 @@ class Config_ModuleReader : public Config_XMLReader CONFIG_EXPORT virtual ~Config_ModuleReader(); /// Returns map that describes which file contains a feature (the feature is key, the file is value) CONFIG_EXPORT const std::map& featuresInFiles() const; + /// Returns list of module's xml files + CONFIG_EXPORT const std::set& modulePluginFiles() const; /// Returns module name: an xml attribute from the root of the plugins.xml: /// e.g \code \endcode CONFIG_EXPORT std::string getModuleName(); @@ -70,6 +72,7 @@ class Config_ModuleReader : public Config_XMLReader private: std::map myFeaturesInFiles; ///< a feature name is key, a file is value + std::set myPluginFiles; ///< a feature name is key, a file is value static std::map myPluginTypes; ///< a plugin name is key, a plugin type is value static std::set myDependencyModules; ///< set of loaded modules const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners diff --git a/src/Config/Config_ValidatorReader.cpp b/src/Config/Config_ValidatorReader.cpp new file mode 100644 index 000000000..4fd9f6d79 --- /dev/null +++ b/src/Config/Config_ValidatorReader.cpp @@ -0,0 +1,99 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +/* + * Config_ValidatorReader.cpp + * + * Created on: Mar 20, 2015 + * Author: sbh + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#ifdef _DEBUG +#include +#endif + +Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName) +: Config_XMLReader(theXmlFileName) +{ + std::cout << "Config_ValidatorReader created for: " << theXmlFileName << std::endl; +} + +Config_ValidatorReader::~Config_ValidatorReader() +{ +} + +void Config_ValidatorReader::processNode(xmlNodePtr theNode) +{ + if (isNode(theNode, NODE_VALIDATOR, NULL)) { + processValidator(theNode); + } else if (isNode(theNode, NODE_SELFILTER, NULL)) { + processSelectionFilter(theNode); + } else if (isNode(theNode, NODE_FEATURE, NULL)) { + storeAttribute(theNode, _ID); + } + //Process SOURCE nodes. + Config_XMLReader::processNode(theNode); +} + +bool Config_ValidatorReader::processChildren(xmlNodePtr aNode) +{ + return true; +} + +void Config_ValidatorReader::processValidator(xmlNodePtr theNode) +{ + Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED); + Events_Loop* aEvLoop = Events_Loop::loop(); + std::shared_ptr + aMessage(new Config_ValidatorMessage(aValidatoEvent, this)); + std::string aValidatorId; + std::list aParameters; + getParametersInfo(theNode, aValidatorId, aParameters); + aMessage->setValidatorId(aValidatorId); + aMessage->setValidatorParameters(aParameters); + //TODO(sbh): update feature/attribute id restoring + // when "cleanup" technique will be available (v. >= 1.1.0) + xmlNodePtr aFeatureOrWdgNode = theNode->parent; + if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { + aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); + } else { + aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); + aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID)); + } + aEvLoop->send(aMessage); +} + +void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode) +{ + Events_ID aFilterEvent = Events_Loop::eventByName(EVENT_SELFILTER_LOADED); + Events_Loop* aEvLoop = Events_Loop::loop(); + std::shared_ptr aMessage = + std::make_shared(aFilterEvent, this); + std::string aSelectionFilterId; + std::list aParameters; + getParametersInfo(theNode, aSelectionFilterId, aParameters); + aMessage->setSelectionFilterId(aSelectionFilterId); + aMessage->setFilterParameters(aParameters); + + xmlNodePtr aFeatureOrWdgNode = theNode->parent; + if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { + aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); + } else { + aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); + aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID)); + } + aEvLoop->send(aMessage); +} diff --git a/src/Config/Config_ValidatorReader.h b/src/Config/Config_ValidatorReader.h new file mode 100644 index 000000000..f2ac6293d --- /dev/null +++ b/src/Config/Config_ValidatorReader.h @@ -0,0 +1,60 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +/* + * Config_ValidatorReader.h + * + * Created on: Mar 20, 2015 + * Author: sbh + */ + +#ifndef CONFIG_VALIDATORREADER_H_ +#define CONFIG_VALIDATORREADER_H_ + +#include +#include + +#include +#include + +/*! + * \class Config_ValidatorReader + * \ingroup Config + * \brief Base class for all libxml readers. Provides high-level API + * for all xml operations. +*/ +class Config_ValidatorReader : public Config_XMLReader +{ + public: + /*! + * Constructor + * \param theXmlFile - full path to the xml file which will be processed by the reader + */ + CONFIG_EXPORT Config_ValidatorReader(const std::string& theXmlFile); + CONFIG_EXPORT virtual ~Config_ValidatorReader(); + + protected: + /*! + * \brief Allows to customize reader's behavior for a node. Virtual. + * The default implementation process "source", "validator" and + * "selection_filter" nodes. + */ + virtual void processNode(xmlNodePtr aNode); + /*! + * \brief Defines which nodes should be processed recursively. Virtual. + * The default impl is to read all nodes. + */ + virtual bool processChildren(xmlNodePtr aNode); + + /*! + * \brief Retrieves all the necessary info from the validator node. + * Sends ValidatorLoaded event + */ + void processValidator(xmlNodePtr theNode); + /*! + * \brief Retrieves all the necessary info from the SelectionFilter node. + * Sends SelectionFilterLoaded event + */ + void processSelectionFilter(xmlNodePtr theNode); +}; + +#endif /* CONFIG_VALIDATORREADER_H_ */ diff --git a/src/Config/Config_WidgetReader.cpp b/src/Config/Config_WidgetReader.cpp index c8ea412d8..25d1fdc65 100644 --- a/src/Config/Config_WidgetReader.cpp +++ b/src/Config/Config_WidgetReader.cpp @@ -45,9 +45,9 @@ std::string Config_WidgetReader::featureDescription(const std::string& theFeatur void Config_WidgetReader::processNode(xmlNodePtr theNode) { if (isNode(theNode, NODE_FEATURE, NULL)) { - myCurrentFeature = getProperty(theNode, _ID); - myWidgetCache[myCurrentFeature] = dumpNode(theNode); - myDescriptionCache[myCurrentFeature] = getProperty(theNode, FEATURE_TEXT); + std::string aFeature = getProperty(theNode, _ID); + myWidgetCache[aFeature] = dumpNode(theNode); + myDescriptionCache[aFeature] = getProperty(theNode, FEATURE_TEXT); } //Process SOURCE nodes. Config_XMLReader::processNode(theNode); diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 03af8f4c7..ab15f3621 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include @@ -77,12 +75,8 @@ void Config_XMLReader::processNode(xmlNodePtr theNode) Config_XMLReader aSourceReader = Config_XMLReader(aSourceFile); readRecursively(aSourceReader.findRoot()); #ifdef _DEBUG - std::cout << "Config_XMLReader::sourced node: " << aSourceFile << std::endl; + //std::cout << "Config_XMLReader::sourced node: " << aSourceFile << std::endl; #endif - } else if (isNode(theNode, NODE_VALIDATOR, NULL)) { - processValidator(theNode); - } else if (isNode(theNode, NODE_SELFILTER, NULL)) { - processSelectionFilter(theNode); } } @@ -144,45 +138,26 @@ std::string Config_XMLReader::getNodeName(xmlNodePtr theNode) return result; } -void Config_XMLReader::processValidator(xmlNodePtr theNode) +void Config_XMLReader::storeAttribute(xmlNodePtr theNode, const char* theAttribute) { - Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED); - Events_Loop* aEvLoop = Events_Loop::loop(); - std::shared_ptr - aMessage(new Config_ValidatorMessage(aValidatoEvent, this)); - std::string aValidatorId; - std::list aParameters; - getParametersInfo(theNode, aValidatorId, aParameters); - aMessage->setValidatorId(aValidatorId); - aMessage->setValidatorParameters(aParameters); - xmlNodePtr aFeatureOrWdgNode = theNode->parent; - if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { - aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); - } else { - aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); - aMessage->setFeatureId(myCurrentFeature); + std::string aKey = getNodeName(theNode) + ":" + std::string(theAttribute); + std::string aValue = getProperty(theNode, theAttribute); + if(!aValue.empty()) { + myCachedAttributes[aKey] = aValue; } - aEvLoop->send(aMessage); } -void Config_XMLReader::processSelectionFilter(xmlNodePtr theNode) +std::string Config_XMLReader::restoreAttribute(xmlNodePtr theNode, const char* theAttribute) { - Events_ID aFilterEvent = Events_Loop::eventByName(EVENT_SELFILTER_LOADED); - Events_Loop* aEvLoop = Events_Loop::loop(); - std::shared_ptr aMessage = - std::make_shared(aFilterEvent, this); - std::string aSelectionFilterId; - std::list aParameters; - getParametersInfo(theNode, aSelectionFilterId, aParameters); - aMessage->setSelectionFilterId(aSelectionFilterId); - aMessage->setFilterParameters(aParameters); - - xmlNodePtr aFeatureOrWdgNode = theNode->parent; - if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) { - aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID)); - } else { - aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID)); - aMessage->setFeatureId(myCurrentFeature); + return restoreAttribute(getNodeName(theNode).c_str(), theAttribute); +} + +std::string Config_XMLReader::restoreAttribute(const char* theNodeName, const char* theAttribute) +{ + std::string aKey = std::string(theNodeName) + ":" + std::string(theAttribute); + std::string result = ""; + if(myCachedAttributes.find(aKey) != myCachedAttributes.end()) { + result = myCachedAttributes[aKey]; } - aEvLoop->send(aMessage); + return result; } diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 01e64c394..8b6f963d1 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -14,6 +14,7 @@ #include #include +#include //>> Forward declaration of xmlNodePtr. typedef struct _xmlNode xmlNode; @@ -78,21 +79,20 @@ class Config_XMLReader xmlNodePtr node(void* theNode); /// Gets xml node name std::string getNodeName(xmlNodePtr theNode); - /*! - * \brief Retrieves all the necessary info from the validator node. - * Sends ValidatorLoaded event - */ - void processValidator(xmlNodePtr theNode); - /*! - * \brief Retrieves all the necessary info from the SelectionFilter node. - * Sends SelectionFilterLoaded event - */ - void processSelectionFilter(xmlNodePtr theNode); + /// Stores an attribute in internal map for later use. + /// Key is "Node_Name:Node_Attribute" and value is getProperty(theNodeAttribute) + void storeAttribute(xmlNodePtr theNode, const char* theNodeAttribute); + /// Restores an attribute from internal map. + std::string restoreAttribute(xmlNodePtr theNode, const char* theNodeAttribute); + /// Restores an attribute from internal map. + std::string restoreAttribute(const char* theNodeName, const char* theNodeAttribute); protected: - std::string myCurrentFeature; ///< Name of currently processed feature std::string myDocumentPath; ///< Path to the xml document xmlDocPtr myXmlDoc; ///< Root of the xml document + /// A map to store all parent's attributes. + /// The key has from "Node_Name:Node_Attribute" + std::map myCachedAttributes; }; #endif /* CONFIG_XMLREADER_H_ */ diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 816b87f75..8e0d97125 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -326,8 +327,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 aFiles = aModuleReader.modulePluginFiles(); + std::set::iterator it = aFiles.begin(); + for ( ; it != aFiles.end(); it++ ) { + Config_ValidatorReader aValidatorReader (*it); + aValidatorReader.readAll(); + }; + } void Model_Session::registerPlugin(ModelAPI_Plugin* thePlugin)