Salome HOME
The obligatory and concealment attribute's properties now registers in model by speci...
[modules/shaper.git] / src / Config / Config_WidgetAPI.cpp
index 14d5fa2aa9b18323806403b393f6de708c78580a..085648e9708b5f6d6f1d96bd5bbd6146aba02608 100644 (file)
  */
 
 #include <Config_WidgetAPI.h>
+#include <Config_Keywords.h>
+#include <Config_Common.h>
 
-#include <libxml\parser.h>
-#include <libxml\tree.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
 
+#include <string>
 
 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
 {
   myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
-  myCurrentNode = NULL;
+  myCurrentNode = xmlDocGetRootElement(myDoc);
 }
 
-
 Config_WidgetAPI::~Config_WidgetAPI()
 {
   xmlFreeDoc(myDoc);
 }
 
-void Config_WidgetAPI::reset()
+bool Config_WidgetAPI::toNextWidget()
+{
+  //Skip all non-element node, stop if next node is null
+  xmlNodePtr aNextNode = myCurrentNode;
+  do {
+    aNextNode = aNextNode->next;
+  } while (aNextNode && !isElementNode(aNextNode));
+
+  if (!aNextNode) {
+    toParentWidget();
+    return false;
+  }
+  myCurrentNode = aNextNode;
+  return true;
+}
+
+bool Config_WidgetAPI::toChildWidget()
 {
-  xmlNodePtr aRoot = xmlDocGetRootElement(myDoc);
-  if(aRoot) {
-    myCurrentNode = aRoot->children;
+  if (myCurrentNode && hasChild(myCurrentNode)) {
+    myCurrentNode = myCurrentNode->children;
+    while (!isElementNode(myCurrentNode)) {
+      myCurrentNode = myCurrentNode->next;
+    }
+    return true;
   }
+  return false;
 }
 
-bool Config_WidgetAPI::nextWidget()
+bool Config_WidgetAPI::toParentWidget()
 {
-  if(myCurrentNode) {
-    myCurrentNode = myCurrentNode->next;
+  if (myCurrentNode) {
+    myCurrentNode = myCurrentNode->parent;
   }
   return myCurrentNode != NULL;
 }
 
-std::string Config_WidgetAPI::widgetType()
+std::string Config_WidgetAPI::widgetType() const
 {
   std::string result = "";
-  if(myCurrentNode) {
+  if (myCurrentNode) {
     result = std::string((char *) myCurrentNode->name);
   }
   return result;
 }
 
-std::string Config_WidgetAPI::getProperty(const char* thePropName)
+bool Config_WidgetAPI::isContainerWidget() const
 {
-  std::string result = "";
-  char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName);
-  if (!aPropChars || aPropChars[0] == 0)
-    return result;
-  result = std::string(aPropChars);
-  return result;
+  return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
+  NULL);
 }
 
-std::string Config_WidgetAPI::widgetTooltip()
+bool Config_WidgetAPI::isPagedWidget() const
 {
-  return getProperty("tooltip");
+  return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
+  NULL);
 }
 
-std::string Config_WidgetAPI::widgetIcon()
+std::string Config_WidgetAPI::getProperty(const char* thePropName) const
 {
-  return getProperty("icon");
+  return ::getProperty(myCurrentNode, thePropName);
 }
 
-std::string Config_WidgetAPI::widgetLabel()
+bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
 {
-  return getProperty("label");
+  return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
 }
 
-bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* theNodeName, ...)
+std::string Config_WidgetAPI::widgetId() const
 {
-  bool result = false;
-  const xmlChar* aName = theNode->name;
-  if (!aName || theNode->type != XML_ELEMENT_NODE)
-    return false;
+  return getProperty(_ID);
+}
 
-  if (!xmlStrcmp(aName, (const xmlChar *) theNodeName))
-    return true;
+std::string Config_WidgetAPI::widgetIcon() const
+{
+  return getProperty(ANY_WDG_ICON);
+}
 
-  va_list args; // define argument list variable
-  va_start(args, theNodeName); // init list; point to last defined argument
-  while(true) {
-    char *anArg = va_arg (args, char*); // get next argument
-    if (anArg == NULL)
-      break;
-    if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
-      va_end(args); // cleanup the system stack
-      return true;
-    }
-  }
-  va_end(args); // cleanup the system stack
-  return false;
+std::string Config_WidgetAPI::widgetLabel() const
+{
+  return getProperty(ANY_WDG_LABEL);
+}
+
+std::string Config_WidgetAPI::widgetTooltip() const
+{
+  return getProperty(ANY_WDG_TOOLTIP);
 }