Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / Config / Config_WidgetAPI.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_WidgetAPI.cpp
5  *
6  *  Created on: Apr 1, 2014
7  *      Author: sbh
8  */
9
10 #include <Config_WidgetAPI.h>
11 #include <Config_Keywords.h>
12 #include <Config_Common.h>
13
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
16
17 #include <string>
18
19 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
20 {
21   myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
22   myCurrentNode = xmlDocGetRootElement(myDoc);
23 }
24
25 Config_WidgetAPI::~Config_WidgetAPI()
26 {
27   xmlFreeDoc(myDoc);
28 }
29
30 bool Config_WidgetAPI::toNextWidget()
31 {
32   //Skip all non-element node, stop if next node is null
33   xmlNodePtr aNextNode = myCurrentNode;
34   do {
35     aNextNode = aNextNode->next;
36   } while (aNextNode && !isElementNode(aNextNode));
37
38   if (!aNextNode) {
39     toParentWidget();
40     return false;
41   }
42   myCurrentNode = aNextNode;
43   return true;
44 }
45
46 bool Config_WidgetAPI::toChildWidget()
47 {
48   if (myCurrentNode && hasChild(myCurrentNode)) {
49     myCurrentNode = myCurrentNode->children;
50     while (myCurrentNode && !isElementNode(myCurrentNode)) {
51       myCurrentNode = myCurrentNode->next;
52     }
53     return myCurrentNode != NULL;
54   }
55   return false;
56 }
57
58 bool Config_WidgetAPI::toParentWidget()
59 {
60   if (myCurrentNode) {
61     myCurrentNode = myCurrentNode->parent;
62   }
63   return myCurrentNode != NULL;
64 }
65
66 std::string Config_WidgetAPI::widgetType() const
67 {
68   std::string result = "";
69   if (myCurrentNode) {
70     result = std::string((char *) myCurrentNode->name);
71   }
72   return result;
73 }
74
75 bool Config_WidgetAPI::isGroupBoxWidget() const
76 {
77   return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
78                 NULL);
79 }
80
81 bool Config_WidgetAPI::isPagedWidget() const
82 {
83   return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
84                 NULL);
85 }
86
87 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
88 {
89   return ::getProperty(myCurrentNode, thePropName);
90 }
91
92 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
93 {
94   return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
95 }
96
97 std::string Config_WidgetAPI::widgetId() const
98 {
99   return getProperty(_ID);
100 }
101
102 std::string Config_WidgetAPI::widgetIcon() const
103 {
104   return getProperty(ATTR_ICON);
105 }
106
107 std::string Config_WidgetAPI::widgetLabel() const
108 {
109   return getProperty(ATTR_LABEL);
110 }
111
112 std::string Config_WidgetAPI::widgetTooltip() const
113 {
114   return getProperty(ATTR_TOOLTIP);
115 }