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 #include <Config_Keywords.h>
10 #include <Config_Common.h>
11
12 #include <libxml/parser.h>
13 #include <libxml/tree.h>
14
15 #include <string>
16
17 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
18 {
19   myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
20   myCurrentNode = xmlDocGetRootElement(myDoc);
21 }
22
23 Config_WidgetAPI::~Config_WidgetAPI()
24 {
25   xmlFreeDoc(myDoc);
26 }
27
28 bool Config_WidgetAPI::toNextWidget()
29 {
30   //Skip all non-element node, stop if next node is null
31   xmlNodePtr aNextNode = myCurrentNode;
32   do {
33     aNextNode = aNextNode->next;
34   } while (aNextNode && !isElementNode(aNextNode));
35
36   if (!aNextNode) {
37     toParentWidget();
38     return false;
39   }
40   myCurrentNode = aNextNode;
41   return true;
42 }
43
44 bool Config_WidgetAPI::toChildWidget()
45 {
46   if (myCurrentNode && hasChild(myCurrentNode)) {
47     myCurrentNode = myCurrentNode->children;
48     while (!isElementNode(myCurrentNode)) {
49       myCurrentNode = myCurrentNode->next;
50     }
51     return true;
52   }
53   return false;
54 }
55
56 bool Config_WidgetAPI::toParentWidget()
57 {
58   if (myCurrentNode) {
59     myCurrentNode = myCurrentNode->parent;
60   }
61   return myCurrentNode != NULL;
62 }
63
64 std::string Config_WidgetAPI::widgetType() const
65 {
66   std::string result = "";
67   if (myCurrentNode) {
68     result = std::string((char *) myCurrentNode->name);
69   }
70   return result;
71 }
72
73 bool Config_WidgetAPI::isContainerWidget() const
74 {
75   return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
76   NULL);
77 }
78
79 bool Config_WidgetAPI::isPagedWidget() const
80 {
81   return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
82   NULL);
83 }
84
85 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
86 {
87   return ::getProperty(myCurrentNode, thePropName);
88 }
89
90 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
91 {
92   return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
93 }
94
95 std::string Config_WidgetAPI::widgetId() const
96 {
97   return getProperty(_ID);
98 }
99
100 std::string Config_WidgetAPI::widgetIcon() const
101 {
102   return getProperty(ANY_WDG_ICON);
103 }
104
105 std::string Config_WidgetAPI::widgetLabel() const
106 {
107   return getProperty(ANY_WDG_LABEL);
108 }
109
110 std::string Config_WidgetAPI::widgetTooltip() const
111 {
112   return getProperty(ANY_WDG_TOOLTIP);
113 }