Salome HOME
Merge branch 'master' of newgeom:newgeom.git
authorsbh <sergey.belash@opencascade.com>
Wed, 9 Jul 2014 13:29:08 +0000 (17:29 +0400)
committersbh <sergey.belash@opencascade.com>
Wed, 9 Jul 2014 13:29:08 +0000 (17:29 +0400)
13 files changed:
src/Config/CMakeLists.txt
src/Config/Config_Common.cpp
src/Config/Config_Common.h
src/Config/Config_FeatureMessage.cpp
src/Config/Config_FeatureMessage.h
src/Config/Config_FeatureReader.cpp
src/Config/Config_Keywords.h
src/Config/Config_ValidatorMessage.cpp [new file with mode: 0644]
src/Config/Config_ValidatorMessage.h [new file with mode: 0644]
src/Config/Config_WidgetAPI.cpp
src/Config/Config_WidgetReader.cpp
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h

index 2e826fc24573c1fd7d81786dfab9ed2bec2c2292..aa7ea19e4b193254b0f5a06615dfbb560a492052 100644 (file)
@@ -14,6 +14,7 @@ SET(PROJECT_HEADERS
   Config_WidgetReader.h
   Config_PointerMessage.h
   Config_Common.h
+  Config_ValidatorMessage.h
  )
  
 SET(PROJECT_SOURCES
@@ -25,6 +26,7 @@ SET(PROJECT_SOURCES
   Config_WidgetReader.cpp
   Config_PointerMessage.cpp
   Config_Common.cpp
+  Config_ValidatorMessage.cpp
 )
 
 SET(XML_RESOURCES
index 97a2a6d677778471faeaf0fd489027d2d73363ec..84e6328a26eacf9259c3cd9dc0f6031ff5a86ca6 100644 (file)
@@ -6,10 +6,13 @@
  */
 
 #include "Config_Common.h"
+#include <Config_Keywords.h>
 
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
+#include <sstream> //for stringstream
+
 bool isElementNode(xmlNodePtr theNode)
 {
   return theNode->type == XML_ELEMENT_NODE;
@@ -51,6 +54,31 @@ bool hasChild(xmlNodePtr theNode)
   return false;
 }
 
+bool getValidatorInfo(xmlNodePtr theNode,
+                      std::string& outValidatorId,
+                      std::list<std::string>& outValidatorParameters)
+{
+  //Validator id:
+  char* anIdProp = (char*) xmlGetProp(theNode, BAD_CAST _ID);
+  if (!anIdProp || anIdProp[0] == 0) {
+    return false;
+  }
+  outValidatorId = std::string(anIdProp);
+
+  //Validator parameters:
+  char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST VALIDATOR_PARAMETERS);
+  if (aParamProp && aParamProp[0] != 0) {
+    std::string aPropString = std::string(aParamProp);
+    std::stringstream aPropStringStream(aPropString);
+    char COMMA_DELIM = ',';
+    std::string aValidatorParameter;
+    while (std::getline(aPropStringStream, aValidatorParameter, ',')) {
+      outValidatorParameters.push_back(aValidatorParameter);
+    }
+  }
+  return true;
+}
+
 std::string library(const std::string& theLibName)
 {
   std::string aLibName = theLibName;
index 2a579b91e126403d14d7f74cc698988be479a285..4a204f59b3a88cb12de1145639911f4ce84ad8ce 100644 (file)
@@ -11,6 +11,7 @@
 #include "Config_def.h"
 
 #include <string>
+#include <list>
 #include <stdarg.h>
 
 //>> Forward declaration of xmlNodePtr.
@@ -49,6 +50,13 @@ CONFIG_EXPORT bool isNode(xmlNodePtr theNode, const char* theNodeName, ...);
  */
 CONFIG_EXPORT bool hasChild(xmlNodePtr theNode);
 
+/*
+ *
+ */
+CONFIG_EXPORT bool getValidatorInfo(xmlNodePtr theNode,
+                                    std::string& outValidatorId,
+                                    std::list<std::string>& outValidatorParameters);
+
 /*!
  \brief Convert the given parameter to the platform-specific library name.
 
index 7b0f603371f6c7823df85b0e33fb086efefe7322..041405eb394acc22b21eec10e2015d6ca1fc8a00 100644 (file)
@@ -21,6 +21,11 @@ Config_FeatureMessage::Config_FeatureMessage(const Events_ID theId, const void*
   myNestedFeatures = "";
 }
 
+Config_FeatureMessage::~Config_FeatureMessage()
+{
+
+}
+
 const std::string& Config_FeatureMessage::icon() const
 {
   return myIcon;
index 2613c992636fef61ddaeade5dafdb19730a76638..752169fb4d0bb673653ed465d3881663ee15abfc 100644 (file)
@@ -33,6 +33,7 @@ class Config_FeatureMessage: public Events_Message
 public:\r
   //const Events_ID theID, const void* theSender = 0\r
   CONFIG_EXPORT Config_FeatureMessage(const Events_ID theId, const void* theParent = 0);\r
+  CONFIG_EXPORT virtual ~Config_FeatureMessage();\r
 \r
   //Auto-generated getters/setters\r
   CONFIG_EXPORT const std::string& icon() const;\r
index 6e6bbb85f6f7abdbb656619f58b35bce114f308c..bdd6e0801e09f4661816e72a896ac7e7f3d05011 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <string>
 #include <algorithm>
+#include <list>
 
 #ifdef _DEBUG
 #include <iostream>
@@ -53,45 +54,45 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
     //If a feature has xml definition for it's widget:
     aMessage.setUseInput(hasChild(theNode));
     aEvLoop->send(aMessage);
-  }
   //The m_last* variables always defined before fillFeature() call. XML is a tree.
-  if (isNode(theNode, NODE_GROUP, NULL)) {
+  } else if (isNode(theNode, NODE_GROUP, NULL)) {
     myLastGroup = getProperty(theNode, _ID);
-  }
-  if (isNode(theNode, NODE_WORKBENCH, NULL)) {
+  } else if (isNode(theNode, NODE_WORKBENCH, NULL)) {
     myLastWorkbench = getProperty(theNode, _ID);
+  //Process SOURCE, VALIDATOR nodes.
   }
-  //Process SOURCE nodes.
   Config_XMLReader::processNode(theNode);
 }
 
 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
 {
-  return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
+  return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NODE_FEATURE, NULL);
 }
 
-void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFtMessage)
+void Config_FeatureReader::fillFeature(xmlNodePtr theNode,
+                                       Config_FeatureMessage& outFeatureMessage)
 {
-  outFtMessage.setId(getProperty(theRoot, _ID));
-  outFtMessage.setPluginLibrary(myLibraryName);
-  outFtMessage.setNestedFeatures(getProperty(theRoot, FEATURE_NESTED));
-  bool isFtInternal = isInternalFeature(theRoot);
-  outFtMessage.setInternal(isFtInternal);
-  if(isFtInternal) {
+  outFeatureMessage.setId(getProperty(theNode, _ID));
+  outFeatureMessage.setPluginLibrary(myLibraryName);
+  outFeatureMessage.setNestedFeatures(getProperty(theNode, FEATURE_NESTED));
+
+  bool isInternal = isInternalFeature(theNode);
+  outFeatureMessage.setInternal(isInternal);
+  if(isInternal) {
     //Internal feature has no visual representation.
     return;
   }
-  outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
-  outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
-  outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
-  outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
-  outFtMessage.setGroupId(myLastGroup);
-  outFtMessage.setWorkbenchId(myLastWorkbench);
+  outFeatureMessage.setText(getProperty(theNode, FEATURE_TEXT));
+  outFeatureMessage.setTooltip(getProperty(theNode, FEATURE_TOOLTIP));
+  outFeatureMessage.setIcon(getProperty(theNode, FEATURE_ICON));
+  outFeatureMessage.setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE));
+  outFeatureMessage.setGroupId(myLastGroup);
+  outFeatureMessage.setWorkbenchId(myLastWorkbench);
 }
 
-bool Config_FeatureReader::isInternalFeature(xmlNodePtr theRoot)
+bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
 {
-  std::string prop = getProperty(theRoot, FEATURE_INTERNAL);
+  std::string prop = getProperty(theNode, FEATURE_INTERNAL);
   std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
   if(prop.empty() || prop == "false" || prop == "0") {
     return false;
index 37f9194de3619ecb0e1b67743bf037ffd0990d0c..f8f4f222fa7006f14f69bc24363bb8e38cdc017b 100644 (file)
@@ -15,6 +15,7 @@ const static char* NODE_WORKBENCH = "workbench";
 const static char* NODE_GROUP = "group";
 const static char* NODE_FEATURE = "feature";
 const static char* NODE_SOURCE = "source";
+const static char* NODE_VALIDATOR = "validator";
 
 //Widgets
 const static char* WDG_DOUBLEVALUE = "doublevalue";
@@ -37,19 +38,22 @@ const static char* WDG_FEATURE_SELECTOR = "feature_selector";
 const static char* WDG_FEATURE_OR_ATTRIBUTE_SELECTOR = "feature_or_attribute_selector";
 const static char* WDG_DOUBLEVALUE_EDITOR = "doublevalue_editor";
 
+//Common Widget's or Feature's Properties
 const static char* _ID = "id";
-//const static char* WORKBENCH_ID = "id";
-//const static char* GROUP_ID = "id";
-//const static char* FEATURE_ID = "id";
-const static char* FEATURE_TEXT = "title";
 const static char* FEATURE_TOOLTIP = "tooltip";
 const static char* FEATURE_ICON = "icon";
+const static char* FEATURE_TEXT = "title";
 const static char* FEATURE_KEYSEQUENCE = "keysequence";
 const static char* FEATURE_NESTED = "nested";
 const static char* FEATURE_INTERNAL = "internal";
-const static char* SOURCE_FILE = "path";
-
+// TODO: Rename
 const static char* PREVIOUS_FEATURE_PARAM = "previous_feature_param";
+const static char* ANY_WDG_TOOLTIP = FEATURE_TOOLTIP;
+const static char* ANY_WDG_ICON = FEATURE_ICON;
+const static char* ANY_WDG_LABEL = "label";
+
+const static char* SOURCE_FILE = "path";
+const static char* VALIDATOR_PARAMETERS = "parameters";
 
 // doublevalue properties:
 const static char* INFO_WDG_TEXT = FEATURE_TEXT;
diff --git a/src/Config/Config_ValidatorMessage.cpp b/src/Config/Config_ValidatorMessage.cpp
new file mode 100644 (file)
index 0000000..a5ac969
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Config_ValidatorMessage.cpp
+ *
+ *  Created on: 08 èþëÿ 2014 ã.
+ *      Author: sbh
+ */
+
+#include <Config_ValidatorMessage.h>
+
+Config_ValidatorMessage::Config_ValidatorMessage(const Events_ID theId, const void* theParent)
+: Events_Message(theId, theParent)
+{
+  myValidatorId = "";
+  myFeatureId = "";
+  myAttributeId = "";
+}
+
+Config_ValidatorMessage::~Config_ValidatorMessage()
+{
+}
+
+//static const const char* Config_ValidatorMessage::UID() const
+//{
+//  return "ValidatorMessage";
+//}
+
+const std::string& Config_ValidatorMessage::validatorId() const
+{
+  return myValidatorId;
+}
+
+const std::string& Config_ValidatorMessage::featureId() const
+{
+  return myFeatureId;
+}
+
+const std::string& Config_ValidatorMessage::attributeId() const
+{
+  return myAttributeId;
+}
+
+const std::list<std::string>& Config_ValidatorMessage::parameters() const
+{
+  return myVaidatorParameters;
+}
+
+bool Config_ValidatorMessage::isValid() const
+{
+  return !myValidatorId.empty();
+}
+
+void Config_ValidatorMessage::setValidatorId(const std::string& validatorId)
+{
+  myValidatorId = validatorId;
+}
+
+void Config_ValidatorMessage::setValidatorParameters(const std::list<std::string>& parameters)
+{
+  myVaidatorParameters = parameters;
+}
+
+void Config_ValidatorMessage::setFeatureId(const std::string& theId)
+{
+  myFeatureId = theId;
+}
+
+void Config_ValidatorMessage::setAttributeId(const std::string& theId)
+{
+  myAttributeId = theId;
+}
diff --git a/src/Config/Config_ValidatorMessage.h b/src/Config/Config_ValidatorMessage.h
new file mode 100644 (file)
index 0000000..21bbf24
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Config_ValidatorMessage.h
+ *
+ *  Created on: 08 èþëÿ 2014 ã.
+ *      Author: sbh
+ */
+
+#ifndef Config_ValidatorMessage_H_
+#define Config_ValidatorMessage_H_
+
+#include <Events_Message.h>
+#include <Config_def.h>
+
+#include <list>
+#include <string>
+
+/// Event ID that feature is loaded (comes with Config_FeatureMessage)
+static const char * EVENT_VALIDATOR_LOADED = "ValidatorLoaded";
+
+class Config_ValidatorMessage : public Events_Message
+{
+  std::string myValidatorId;
+  std::string myFeatureId;
+  std::string myAttributeId;
+  std::list<std::string> myVaidatorParameters;
+
+public:
+  CONFIG_EXPORT Config_ValidatorMessage(const Events_ID theId, const void* theParent = 0);
+  CONFIG_EXPORT virtual ~Config_ValidatorMessage();
+
+  //CONFIG_EXPORT static const char* UID() const;
+
+  CONFIG_EXPORT const std::string& validatorId() const;
+  const std::string& featureId() const;
+  const std::string& attributeId() const;
+  CONFIG_EXPORT const std::list<std::string>& parameters() const;
+  CONFIG_EXPORT bool isValid() const;
+
+  CONFIG_EXPORT void setValidatorId(const std::string& theId);
+  CONFIG_EXPORT void setFeatureId(const std::string& theId);
+  CONFIG_EXPORT void setAttributeId(const std::string& theId);
+  CONFIG_EXPORT void setValidatorParameters(const std::list<std::string>& parameters);
+};
+
+#endif /* Config_ValidatorMessage_H_ */
index 2fdad673519fcd7f1be6fc49cdbadad3062ffb67..8d295ce05a64e6ae50d8c4adf9ae109f7b26eb4a 100644 (file)
@@ -94,20 +94,20 @@ std::string Config_WidgetAPI::getProperty(const char* thePropName) const
 
 std::string Config_WidgetAPI::widgetId() const
 {
-  return getProperty("id");
+  return getProperty(_ID);
 }
 
-std::string Config_WidgetAPI::widgetTooltip() const
+std::string Config_WidgetAPI::widgetIcon() const
 {
-  return getProperty("tooltip");
+  return getProperty(ANY_WDG_ICON);
 }
 
-std::string Config_WidgetAPI::widgetIcon() const
+std::string Config_WidgetAPI::widgetLabel() const
 {
-  return getProperty("icon");
+  return getProperty(ANY_WDG_LABEL);
 }
 
-std::string Config_WidgetAPI::widgetLabel() const
+std::string Config_WidgetAPI::widgetTooltip() const
 {
-  return getProperty("label");
+  return getProperty(ANY_WDG_TOOLTIP);
 }
index 7ba92f9961f5f6b7a5d7e08f4e2fd54ff1e8b29d..7ce67a2e7ddc98141d8fb185db846342c0d036ab 100644 (file)
@@ -44,7 +44,7 @@ void Config_WidgetReader::processNode(xmlNodePtr theNode)
 {
   if (isNode(theNode, NODE_FEATURE, NULL)) {
     std::string aNodeName = getProperty(theNode, _ID);
-    myWidgetCache[aNodeName] = dumpNode(theNode);;
+    myWidgetCache[aNodeName] = dumpNode(theNode);
     myDescriptionCache[aNodeName] = getProperty(theNode, FEATURE_TEXT);
   }
   //Process SOURCE nodes.
@@ -67,6 +67,9 @@ std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode)
   if (isNode(aChildrenNode, NODE_SOURCE, NULL)) {
     Config_XMLReader aSourceReader = 
       Config_XMLReader(getProperty(aChildrenNode, SOURCE_FILE));
+    //Register all validators in the sourced xml
+    aSourceReader.readAll();
+    //Dump!
     xmlNodePtr aSourceRoot = aSourceReader.findRoot();
     int size = xmlNodeDump(buffer, aSourceRoot->doc, aSourceRoot, 0, 1);
   } else {
index e86579ede4618d8373d487497c83a4cdc106edab..a9bf87dc617c560383505840f9a2a9f5402cbaf1 100644 (file)
@@ -8,6 +8,7 @@
 #include <Config_XMLReader.h>
 #include <Config_Keywords.h>
 #include <Config_Common.h>
+#include <Config_ValidatorMessage.h>
 
 #include <Events_Loop.h>
 #include <libxml/parser.h>
@@ -72,6 +73,8 @@ void Config_XMLReader::processNode(xmlNodePtr theNode)
     #ifdef _DEBUG
     std::cout << "Config_XMLReader::sourced node: " << aSourceFile << std::endl;
     #endif
+  } else if (isNode(theNode, NODE_VALIDATOR, NULL)) {
+    processValidator(theNode);
   }
 }
 
@@ -89,7 +92,9 @@ bool Config_XMLReader::processChildren(xmlNodePtr aNode)
  */
 xmlNodePtr Config_XMLReader::findRoot()
 {
-  myXmlDoc = xmlParseFile(myDocumentPath.c_str());
+  if (myXmlDoc == NULL) {
+    myXmlDoc = xmlParseFile(myDocumentPath.c_str());
+  }
   if (myXmlDoc == NULL) {
 #ifdef _DEBUG
     std::cout << "Config_XMLReader::import: " << "Document " << myDocumentPath
@@ -117,7 +122,10 @@ void Config_XMLReader::readRecursively(xmlNodePtr theParent)
     return;
   xmlNodePtr aNode = theParent->xmlChildrenNode;
   for(; aNode; aNode = aNode->next) {
-    processNode(aNode);
+    //Still no text processing in features...
+    if(isElementNode(aNode)) {
+      processNode(aNode);
+    }
     if (processChildren(aNode)) {
       readRecursively(aNode);
     }
@@ -135,13 +143,32 @@ xmlNodePtr Config_XMLReader::node(void* theNode)
 /*
  * Returns named property for a given node as std::string.
  */
-std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* name)
+std::string Config_XMLReader::getProperty(xmlNodePtr theNode, const char* theName)
 {
   std::string result = "";
-  char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST name);
+  char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST theName);
   if (!aPropChars || aPropChars[0] == 0)
     return result;
   result = std::string(aPropChars);
   return result;
 }
 
+void Config_XMLReader::processValidator(xmlNodePtr theNode)
+{
+  Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
+  Events_Loop* aEvLoop = Events_Loop::loop();
+  Config_ValidatorMessage aMessage(aValidatoEvent, this);
+  std::string aValidatorId;
+  std::list<std::string> aValidatorParameters;
+  getValidatorInfo(theNode, aValidatorId, aValidatorParameters);
+  aMessage.setValidatorId(aValidatorId);
+  aMessage.setValidatorParameters(aValidatorParameters);
+  if(isNode(theNode->parent, NODE_FEATURE, NULL)) {
+    aMessage.setFeatureId(getProperty(theNode->parent, _ID));
+  } else {
+    xmlNodePtr aWdgNode = theNode->parent;
+    aMessage.setAttributeId(getProperty(aWdgNode, _ID));
+    aMessage.setFeatureId(getProperty(aWdgNode->parent, _ID));
+  }
+  aEvLoop->send(aMessage);
+}
index 8915147e9eb5c8b88a550d642e38ec2d6728bd65..47fc97b7b0d997d17b7ea4c8ce04959d9d37729d 100644 (file)
@@ -49,6 +49,7 @@ protected:
 
   xmlNodePtr node(void* theNode);
   std::string getProperty(xmlNodePtr theNode, const char* property);
+  void processValidator(xmlNodePtr theNode);
 
 protected:
   std::string myDocumentPath;