Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / Config / Config_WidgetAPI.cpp
1 /*
2  * Config_WidgetAPI.cpp
3  *
4  *  Created on: Apr 1, 2014
5  *      Author: sbh
6  */
7
8 #include <Config_WidgetAPI.h>
9
10 #include <libxml\parser.h>
11 #include <libxml\tree.h>
12
13
14 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
15 {
16   myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
17   myCurrentNode = NULL;
18 }
19
20
21 Config_WidgetAPI::~Config_WidgetAPI()
22 {
23   xmlFreeDoc(myDoc);
24 }
25
26 void Config_WidgetAPI::reset()
27 {
28   xmlNodePtr aRoot = xmlDocGetRootElement(myDoc);
29   if(aRoot) {
30     myCurrentNode = aRoot->children;
31   }
32 }
33
34 bool Config_WidgetAPI::nextWidget()
35 {
36   if(myCurrentNode) {
37     myCurrentNode = myCurrentNode->next;
38   }
39   return myCurrentNode != NULL;
40 }
41
42 std::string Config_WidgetAPI::widgetType()
43 {
44   std::string result = "";
45   if(myCurrentNode) {
46     result = std::string((char *) myCurrentNode->name);
47   }
48   return result;
49 }
50
51 std::string Config_WidgetAPI::getProperty(const char* thePropName)
52 {
53   std::string result = "";
54   char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName);
55   if (!aPropChars || aPropChars[0] == 0)
56     return result;
57   result = std::string(aPropChars);
58   return result;
59 }
60
61 std::string Config_WidgetAPI::widgetTooltip()
62 {
63   return getProperty("tooltip");
64 }
65
66 std::string Config_WidgetAPI::widgetIcon()
67 {
68   return getProperty("icon");
69 }
70
71 std::string Config_WidgetAPI::widgetLabel()
72 {
73   return getProperty("label");
74 }
75
76 bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* theNodeName, ...)
77 {
78   bool result = false;
79   const xmlChar* aName = theNode->name;
80   if (!aName || theNode->type != XML_ELEMENT_NODE)
81     return false;
82
83   if (!xmlStrcmp(aName, (const xmlChar *) theNodeName))
84     return true;
85
86   va_list args; // define argument list variable
87   va_start(args, theNodeName); // init list; point to last defined argument
88   while(true) {
89     char *anArg = va_arg (args, char*); // get next argument
90     if (anArg == NULL)
91       break;
92     if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
93       va_end(args); // cleanup the system stack
94       return true;
95     }
96   }
97   va_end(args); // cleanup the system stack
98   return false;
99 }