1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <Config_WidgetAPI.h>
22 #include <Config_Keywords.h>
23 #include <Config_Common.h>
25 #include <libxml/parser.h>
26 #include <libxml/tree.h>
30 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
32 myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
33 myCurrentNode = xmlDocGetRootElement(myDoc);
34 myFeatureId = getProperty(_ID);
37 Config_WidgetAPI::~Config_WidgetAPI()
42 bool Config_WidgetAPI::toNextWidget()
44 //Skip all non-element node, stop if next node is null
45 xmlNodePtr aNextNode = myCurrentNode;
47 aNextNode = aNextNode->next;
48 } while (aNextNode && !isElementNode(aNextNode));
54 myCurrentNode = aNextNode;
58 bool Config_WidgetAPI::toChildWidget()
60 if (myCurrentNode && hasChild(myCurrentNode)) {
61 xmlNodePtr aChildNode = myCurrentNode->children;
62 // it is possible that among child nodes, there is no an element node, so
63 // we should not change the current node until not-zero node is found
64 // otherwise, it may happens that the current node is null and the node tree information
66 while (aChildNode && !isElementNode(aChildNode)) {
67 aChildNode = aChildNode->next;
69 if (aChildNode != NULL) {
70 myCurrentNode = aChildNode;
77 bool Config_WidgetAPI::toParentWidget()
80 myCurrentNode = myCurrentNode->parent;
82 return myCurrentNode != NULL;
85 std::string Config_WidgetAPI::widgetType() const
87 std::string result = "";
89 result = std::string((char *) myCurrentNode->name);
94 bool Config_WidgetAPI::isGroupBoxWidget() const
96 return isNode(myCurrentNode, WDG_GROUP, WDG_OPTIONALBOX,
100 bool Config_WidgetAPI::isPagedWidget() const
102 return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, WDG_RADIOBOX,
106 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
108 return ::getProperty(myCurrentNode, thePropName);
111 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
113 return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
116 std::string Config_WidgetAPI::featureId() const
121 std::string Config_WidgetAPI::widgetId() const
123 return getProperty(_ID);
126 std::string Config_WidgetAPI::widgetIcon() const
128 return getProperty(ATTR_ICON);
131 std::string Config_WidgetAPI::widgetLabel() const
133 return getProperty(ATTR_LABEL);
136 std::string Config_WidgetAPI::widgetTooltip() const
138 return getProperty(ATTR_TOOLTIP);