Salome HOME
Concealed objects now also ersaed in the viewer
[modules/shaper.git] / src / Config / Config_Common.cpp
index a6a9ee512e055782f0b7ff46968d63088633ab44..a8c6df0a55ceafc3d9983aaa00f667cd963d68fb 100644 (file)
 #include <libxml/parser.h>\r
 #include <libxml/tree.h>\r
 \r
-#include <sstream> //for stringstream\r\r
+#include <sstream> // for stringstream\r
+\r
+#include <string>\r
+#include <algorithm> // for std::transform\r
+\r
 bool isElementNode(xmlNodePtr theNode)\r
 {\r
   return theNode->type == XML_ELEMENT_NODE;\r
@@ -42,6 +46,19 @@ bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
   return false;\r
 }\r
 \r
+bool isWidgetNode(xmlNodePtr theNode)\r
+{\r
+  if(!isElementNode(theNode))\r
+    return false;\r
+  // it's parent is "feature" or "source"\r
+  xmlNodePtr aParentNode = theNode->parent;\r
+  if(!isNode(aParentNode, NODE_FEATURE, NODE_SOURCE, NULL))\r
+    return false;\r
+\r
+  //it should not be a "source" or a "validator" node\r
+  return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NULL);\r
+}\r
+\r
 bool hasChild(xmlNodePtr theNode)\r
 {\r
   xmlNodePtr aNode = theNode->children;\r
@@ -79,6 +96,8 @@ bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId,
 \r
 std::string library(const std::string& theLibName)\r
 {\r
+  if(theLibName.empty())\r
+    return std::string();\r
   std::string aLibName = theLibName;\r
 #ifndef WIN32\r
   static std::string aLibExt( ".so" );\r
@@ -94,3 +113,26 @@ std::string library(const std::string& theLibName)
 \r
   return aLibName;\r
 }\r
+\r
+std::string getProperty(xmlNodePtr theNode, const char* thePropName)\r
+{\r
+  std::string result = "";\r
+  char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST thePropName);\r
+  if (!aPropChars || aPropChars[0] == 0)\r
+    return result;\r
+  result = std::string(aPropChars);\r
+  return result;\r
+}\r
+\r
+bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault)\r
+{\r
+  std::string prop = getProperty(theNode, theAttributeName);\r
+  std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);\r
+  bool result = theDefault;\r
+  if (prop == "true" || prop == "1") {\r
+    result = true;\r
+  } else if (prop == "false" || prop == "0") {\r
+    result = false;\r
+  }\r
+  return result;\r
+}\r