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