Salome HOME
Merge branch 'master' into cgt/devCEA
[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   myFeatureId = getProperty(_ID);
24 }
25
26 Config_WidgetAPI::~Config_WidgetAPI()
27 {
28   xmlFreeDoc(myDoc);
29 }
30
31 bool Config_WidgetAPI::toNextWidget()
32 {
33   //Skip all non-element node, stop if next node is null
34   xmlNodePtr aNextNode = myCurrentNode;
35   do {
36     aNextNode = aNextNode->next;
37   } while (aNextNode && !isElementNode(aNextNode));
38
39   if (!aNextNode) {
40     toParentWidget();
41     return false;
42   }
43   myCurrentNode = aNextNode;
44   return true;
45 }
46
47 bool Config_WidgetAPI::toChildWidget()
48 {
49   if (myCurrentNode && hasChild(myCurrentNode)) {
50     xmlNodePtr aChildNode = myCurrentNode->children;
51     // it is possible that among child nodes, there is no an element node, so
52     // we should not change the current node until not-zero node is found
53     // otherwise, it may happens that the current node is null and the node tree information
54     // is lost
55     while (aChildNode && !isElementNode(aChildNode)) {
56       aChildNode = aChildNode->next;
57     }
58     if (aChildNode != NULL) {
59       myCurrentNode = aChildNode;
60       return true;
61     }
62   }
63   return false;
64 }
65
66 bool Config_WidgetAPI::toParentWidget()
67 {
68   if (myCurrentNode) {
69     myCurrentNode = myCurrentNode->parent;
70   }
71   return myCurrentNode != NULL;
72 }
73
74 std::string Config_WidgetAPI::widgetType() const
75 {
76   std::string result = "";
77   if (myCurrentNode) {
78     result = std::string((char *) myCurrentNode->name);
79   }
80   return result;
81 }
82
83 bool Config_WidgetAPI::isGroupBoxWidget() const
84 {
85   return isNode(myCurrentNode, WDG_GROUP, WDG_OPTIONALBOX,
86                 NULL);
87 }
88
89 bool Config_WidgetAPI::isPagedWidget() const
90 {
91   return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
92                 NULL);
93 }
94
95 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
96 {
97   return ::getProperty(myCurrentNode, thePropName);
98 }
99
100 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
101 {
102   return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
103 }
104
105 std::string Config_WidgetAPI::featureId() const
106 {
107   return myFeatureId;
108 }
109
110 std::string Config_WidgetAPI::widgetId() const
111 {
112   return getProperty(_ID);
113 }
114
115 std::string Config_WidgetAPI::widgetIcon() const
116 {
117   return getProperty(ATTR_ICON);
118 }
119
120 std::string Config_WidgetAPI::widgetLabel() const
121 {
122   return getProperty(ATTR_LABEL);
123 }
124
125 std::string Config_WidgetAPI::widgetTooltip() const
126 {
127   return getProperty(ATTR_TOOLTIP);
128 }