Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / Config / Config_WidgetAPI.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * Config_WidgetAPI.cpp
22  *
23  *  Created on: Apr 1, 2014
24  *      Author: sbh
25  */
26
27 #include <Config_WidgetAPI.h>
28 #include <Config_Keywords.h>
29 #include <Config_Common.h>
30
31 #include <libxml/parser.h>
32 #include <libxml/tree.h>
33
34 #include <string>
35
36 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
37 {
38   myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
39   myCurrentNode = xmlDocGetRootElement(myDoc);
40   myFeatureId = getProperty(_ID);
41 }
42
43 Config_WidgetAPI::~Config_WidgetAPI()
44 {
45   xmlFreeDoc(myDoc);
46 }
47
48 bool Config_WidgetAPI::toNextWidget()
49 {
50   //Skip all non-element node, stop if next node is null
51   xmlNodePtr aNextNode = myCurrentNode;
52   do {
53     aNextNode = aNextNode->next;
54   } while (aNextNode && !isElementNode(aNextNode));
55
56   if (!aNextNode) {
57     toParentWidget();
58     return false;
59   }
60   myCurrentNode = aNextNode;
61   return true;
62 }
63
64 bool Config_WidgetAPI::toChildWidget()
65 {
66   if (myCurrentNode && hasChild(myCurrentNode)) {
67     xmlNodePtr aChildNode = myCurrentNode->children;
68     // it is possible that among child nodes, there is no an element node, so
69     // we should not change the current node until not-zero node is found
70     // otherwise, it may happens that the current node is null and the node tree information
71     // is lost
72     while (aChildNode && !isElementNode(aChildNode)) {
73       aChildNode = aChildNode->next;
74     }
75     if (aChildNode != NULL) {
76       myCurrentNode = aChildNode;
77       return true;
78     }
79   }
80   return false;
81 }
82
83 bool Config_WidgetAPI::toParentWidget()
84 {
85   if (myCurrentNode) {
86     myCurrentNode = myCurrentNode->parent;
87   }
88   return myCurrentNode != NULL;
89 }
90
91 std::string Config_WidgetAPI::widgetType() const
92 {
93   std::string result = "";
94   if (myCurrentNode) {
95     result = std::string((char *) myCurrentNode->name);
96   }
97   return result;
98 }
99
100 bool Config_WidgetAPI::isGroupBoxWidget() const
101 {
102   return isNode(myCurrentNode, WDG_GROUP, WDG_OPTIONALBOX,
103                 NULL);
104 }
105
106 bool Config_WidgetAPI::isPagedWidget() const
107 {
108   return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
109                 NULL);
110 }
111
112 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
113 {
114   return ::getProperty(myCurrentNode, thePropName);
115 }
116
117 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
118 {
119   return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
120 }
121
122 std::string Config_WidgetAPI::featureId() const
123 {
124   return myFeatureId;
125 }
126
127 std::string Config_WidgetAPI::widgetId() const
128 {
129   return getProperty(_ID);
130 }
131
132 std::string Config_WidgetAPI::widgetIcon() const
133 {
134   return getProperty(ATTR_ICON);
135 }
136
137 std::string Config_WidgetAPI::widgetLabel() const
138 {
139   return getProperty(ATTR_LABEL);
140 }
141
142 std::string Config_WidgetAPI::widgetTooltip() const
143 {
144   return getProperty(ATTR_TOOLTIP);
145 }