Config_PropManager.h
Config_AttributeMessage.h
Config_SelectionFilterMessage.h
+ Config_ValidatorReader.h
)
SET(PROJECT_SOURCES
Config_PropManager.cpp
Config_AttributeMessage.cpp
Config_SelectionFilterMessage.cpp
+ Config_ValidatorReader.cpp
)
SET(XML_RESOURCES
Events_Loop::loop()->send(aMessage);
}
}
- //Process SOURCE, VALIDATOR nodes.
+ //Process SOURCE nodes.
Config_XMLReader::processNode(theNode);
}
}
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;
-}
#include <string>
#include <list>
-#include <map>
class Config_FeatureMessage;
void fillFeature(xmlNodePtr theRoot,
const std::shared_ptr<Config_FeatureMessage>& 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<std::string, std::string> myParentAttributes;
std::string myLibraryName;
std::list<std::string> myFeatures;
return myFeaturesInFiles;
}
+const std::set<std::string>& Config_ModuleReader::modulePluginFiles() const
+{
+ return myPluginFiles;
+}
+
/*!
* Get module name from plugins.xml
* (property "module")
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);
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<std::string, std::string>& featuresInFiles() const;
+ /// Returns list of module's xml files
+ CONFIG_EXPORT const std::set<std::string>& modulePluginFiles() const;
/// Returns module name: an xml attribute from the root of the plugins.xml:
/// e.g \code <plugins module="PartSet"> \endcode
CONFIG_EXPORT std::string getModuleName();
private:
std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
+ std::set<std::string> myPluginFiles; ///< a feature name is key, a file is value
static std::map<std::string, PluginType> myPluginTypes; ///< a plugin name is key, a plugin type is value
static std::set<std::string> myDependencyModules; ///< set of loaded modules
const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * Config_ValidatorReader.cpp
+ *
+ * Created on: Mar 20, 2015
+ * Author: sbh
+ */
+
+#include <Config_ValidatorReader.h>
+#include <Config_Keywords.h>
+#include <Config_Common.h>
+#include <Config_ValidatorMessage.h>
+#include <Config_SelectionFilterMessage.h>
+#include <Config_PropManager.h>
+
+#include <Events_Loop.h>
+#include <Events_Error.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#include <fstream>
+
+#ifdef _DEBUG
+#include <iostream>
+#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<Config_ValidatorMessage>
+ aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
+ std::string aValidatorId;
+ std::list<std::string> 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<Config_SelectionFilterMessage> aMessage =
+ std::make_shared<Config_SelectionFilterMessage>(aFilterEvent, this);
+ std::string aSelectionFilterId;
+ std::list<std::string> 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);
+}
--- /dev/null
+// 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 <Config_def.h>
+#include <Config_XMLReader.h>
+
+#include <cstdarg>
+#include <string>
+
+/*!
+ * \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_ */
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);
#include <Config_XMLReader.h>
#include <Config_Keywords.h>
#include <Config_Common.h>
-#include <Config_ValidatorMessage.h>
-#include <Config_SelectionFilterMessage.h>
#include <Config_PropManager.h>
#include <Events_Loop.h>
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);
}
}
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<Config_ValidatorMessage>
- aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
- std::string aValidatorId;
- std::list<std::string> 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<Config_SelectionFilterMessage> aMessage =
- std::make_shared<Config_SelectionFilterMessage>(aFilterEvent, this);
- std::string aSelectionFilterId;
- std::list<std::string> 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;
}
#include <cstdarg>
#include <string>
+#include <map>
//>> Forward declaration of xmlNodePtr.
typedef struct _xmlNode xmlNode;
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<std::string, std::string> myCachedAttributes;
};
#endif /* CONFIG_XMLREADER_H_ */
#include <Config_AttributeMessage.h>
#include <Config_ValidatorMessage.h>
#include <Config_ModuleReader.h>
+#include <Config_ValidatorReader.h>
#include <ModelAPI_ResultPart.h>
#include <TDF_CopyTool.hxx>
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)