1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
6 * Created on: Apr 1, 2014
10 #include <Config_WidgetAPI.h>
11 #include <Config_Keywords.h>
12 #include <Config_Common.h>
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
19 Config_WidgetAPI::Config_WidgetAPI(const std::string& theRawXml)
21 myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
22 myCurrentNode = xmlDocGetRootElement(myDoc);
25 Config_WidgetAPI::~Config_WidgetAPI()
30 bool Config_WidgetAPI::toNextWidget()
32 //Skip all non-element node, stop if next node is null
33 xmlNodePtr aNextNode = myCurrentNode;
35 aNextNode = aNextNode->next;
36 } while (aNextNode && !isElementNode(aNextNode));
42 myCurrentNode = aNextNode;
46 bool Config_WidgetAPI::toChildWidget()
48 if (myCurrentNode && hasChild(myCurrentNode)) {
49 myCurrentNode = myCurrentNode->children;
50 while (myCurrentNode && !isElementNode(myCurrentNode)) {
51 myCurrentNode = myCurrentNode->next;
53 return myCurrentNode != NULL;
58 bool Config_WidgetAPI::toParentWidget()
61 myCurrentNode = myCurrentNode->parent;
63 return myCurrentNode != NULL;
66 std::list<xmlNodePtr> Config_WidgetAPI::attributes() const
68 std::list<xmlNodePtr> aResult;
69 if (myCurrentNode && hasChild(myCurrentNode)) {
70 xmlNodePtr anAttributesNode = myCurrentNode->children;
71 while (anAttributesNode &&
72 (!isElementNode(anAttributesNode) ||
73 std::string((char *) anAttributesNode->name) != NODE_NAME_ATTRIBUTES)) {
74 anAttributesNode = anAttributesNode->next;
76 if (anAttributesNode && hasChild(anAttributesNode)) {
77 xmlNodePtr anAttributeNode = anAttributesNode->children;
78 while (anAttributeNode) {
79 if (isElementNode(anAttributeNode) &&
80 std::string((char *) anAttributeNode->name) == NODE_NAME_ATTRIBUTE)
81 aResult.push_back(anAttributeNode);
82 anAttributeNode = anAttributeNode->next;
89 std::string Config_WidgetAPI::widgetType() const
91 std::string result = "";
93 result = std::string((char *) myCurrentNode->name);
98 bool Config_WidgetAPI::isGroupBoxWidget() const
100 return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
104 bool Config_WidgetAPI::isPagedWidget() const
106 return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
110 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
112 return ::getProperty(myCurrentNode, thePropName);
115 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
117 return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
120 std::string Config_WidgetAPI::widgetId() const
122 return getProperty(_ID);
125 std::string Config_WidgetAPI::widgetIcon() const
127 return getProperty(ATTR_ICON);
130 std::string Config_WidgetAPI::widgetLabel() const
132 return getProperty(ATTR_LABEL);
135 std::string Config_WidgetAPI::widgetTooltip() const
137 return getProperty(ATTR_TOOLTIP);
140 std::list<std::string> Config_WidgetAPI::getAttributes(const std::string& theRole/* = std::string()*/) const
142 std::list<std::string> aResult;
144 if (theRole.empty() || theRole == ATTR_MAIN_ROLE)
145 aResult.push_back(widgetId());
147 if (theRole == ATTR_MAIN_ROLE)
150 std::list<xmlNodePtr> anAttributes = attributes();
151 for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) {
152 if (theRole.empty() || theRole == ::getProperty(*it, ATTR_ROLE))
153 aResult.push_back(::getProperty(*it, ATTR_ID));
158 std::string Config_WidgetAPI::getAttributeProperty(const std::string& theAttribute,
159 const std::string& thePropName) const
161 if (theAttribute == widgetId()) {
162 if (thePropName == ATTR_ROLE)
163 return ATTR_MAIN_ROLE;
164 return ::getProperty(myCurrentNode, thePropName.c_str());
167 std::list<xmlNodePtr> anAttributes = attributes();
168 for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) {
169 if (theAttribute == ::getProperty(*it, ATTR_ID))
170 return ::getProperty(*it, thePropName.c_str());
172 return std::string();