Salome HOME
Process validators on the first feature's creation using the Config_ValidatorReader
authorsbh <sergey.belash@opencascade.com>
Mon, 23 Mar 2015 08:07:32 +0000 (11:07 +0300)
committersbh <sergey.belash@opencascade.com>
Mon, 23 Mar 2015 08:07:32 +0000 (11:07 +0300)
src/Config/CMakeLists.txt
src/Config/Config_FeatureReader.cpp
src/Config/Config_FeatureReader.h
src/Config/Config_ModuleReader.cpp
src/Config/Config_ModuleReader.h
src/Config/Config_ValidatorReader.cpp [new file with mode: 0644]
src/Config/Config_ValidatorReader.h [new file with mode: 0644]
src/Config/Config_WidgetReader.cpp
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/Model/Model_Session.cpp

index c5ee88f7817fc6702c22500e4096b4b5c1a0e977..591c8489afc4d829063bf3c1d5388dd34b1496a1 100644 (file)
@@ -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
index 94274a40ab08361e14807d2e3c6fdbb335023ffb..48f091aa32c9b76caa5e14e75da40e46a9588331 100644 (file)
@@ -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;
-}
index 7f7889aaabfbd07fe0ab741f22162b226c354765..35582ae7e02dfc23ccba76689d39386b0f9e6427 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <string>
 #include <list>
-#include <map>
 
 class Config_FeatureMessage;
 
@@ -46,18 +45,7 @@ class Config_FeatureReader : public Config_XMLReader
   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;
index 74ab766966a98c590d0079cc2405311950aa781f..41ceda577b62f7b4bb1eb58cc767cabcde8e86f2 100644 (file)
@@ -48,6 +48,11 @@ const std::map<std::string, std::string>& Config_ModuleReader::featuresInFiles()
   return myFeaturesInFiles;
 }
 
+const std::set<std::string>& 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);
index a6f8c1e2d4215565dc67b3e9afc059e1a5377e32..bef9c61246a6c149cce31154c9c9dc5eb1d2d5a1 100644 (file)
@@ -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<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();
@@ -70,6 +72,7 @@ class Config_ModuleReader : public Config_XMLReader
 
  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
diff --git a/src/Config/Config_ValidatorReader.cpp b/src/Config/Config_ValidatorReader.cpp
new file mode 100644 (file)
index 0000000..4fd9f6d
--- /dev/null
@@ -0,0 +1,99 @@
+// 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);
+}
diff --git a/src/Config/Config_ValidatorReader.h b/src/Config/Config_ValidatorReader.h
new file mode 100644 (file)
index 0000000..f2ac629
--- /dev/null
@@ -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 <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_ */
index c8ea412d88f56bf539534ffa743644c20b931b02..25d1fdc65c090722c4dddf32bf36ad88068f4cd3 100644 (file)
@@ -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);
index 03af8f4c7e5c4d8b43f1a5e6f7ec5ad1447c881e..ab15f3621e1a43ea35caf6a4a9e9ad298a3f85c4 100644 (file)
@@ -10,8 +10,6 @@
 #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>
@@ -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<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;
 }
index 01e64c39494cecb606212073c5daec89c38fd8a9..8b6f963d1b6bc5e24809285964d2a07e1859cdde 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <cstdarg>
 #include <string>
+#include <map>
 
 //>> 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<std::string, std::string> myCachedAttributes;
 };
 
 #endif /* CONFIG_XMLREADER_H_ */
index 816b87f750d1e391f44a92ef939a0981d5214289..8e0d971254fa9f113b3afdeced8c9d8c168e79cc 100644 (file)
@@ -19,6 +19,7 @@
 #include <Config_AttributeMessage.h>
 #include <Config_ValidatorMessage.h>
 #include <Config_ModuleReader.h>
+#include <Config_ValidatorReader.h>
 #include <ModelAPI_ResultPart.h>
 
 #include <TDF_CopyTool.hxx>
@@ -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<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)