1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <Config_WidgetAPI.h>
21 #include <Config_Keywords.h>
22 #include <Config_Common.h>
24 #include <libxml/parser.h>
25 #include <libxml/tree.h>
29 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
31 myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
32 myCurrentNode = xmlDocGetRootElement(myDoc);
33 myFeatureId = getProperty(_ID);
36 Config_WidgetAPI::~Config_WidgetAPI()
41 bool Config_WidgetAPI::toNextWidget()
43 //Skip all non-element node, stop if next node is null
44 xmlNodePtr aNextNode = myCurrentNode;
46 aNextNode = aNextNode->next;
47 } while (aNextNode && !isElementNode(aNextNode));
53 myCurrentNode = aNextNode;
57 bool Config_WidgetAPI::toChildWidget()
59 if (myCurrentNode && hasChild(myCurrentNode)) {
60 xmlNodePtr aChildNode = myCurrentNode->children;
61 // it is possible that among child nodes, there is no an element node, so
62 // we should not change the current node until not-zero node is found
63 // otherwise, it may happens that the current node is null and the node tree information
65 while (aChildNode && !isElementNode(aChildNode)) {
66 aChildNode = aChildNode->next;
68 if (aChildNode != NULL) {
69 myCurrentNode = aChildNode;
76 bool Config_WidgetAPI::toParentWidget()
79 myCurrentNode = myCurrentNode->parent;
81 return myCurrentNode != NULL;
84 std::string Config_WidgetAPI::widgetType() const
86 std::string result = "";
88 result = std::string((char *) myCurrentNode->name);
93 bool Config_WidgetAPI::isGroupBoxWidget() const
95 return isNode(myCurrentNode, WDG_GROUP, WDG_OPTIONALBOX,
99 bool Config_WidgetAPI::isPagedWidget() const
101 return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, WDG_RADIOBOX,
105 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
107 return ::getProperty(myCurrentNode, thePropName);
110 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
112 return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
115 std::string Config_WidgetAPI::featureId() const
120 std::string Config_WidgetAPI::widgetId() const
122 return getProperty(_ID);
125 std::string Config_WidgetAPI::widgetIcon() const
127 return getProperty(ATTR_ICON);
130 std::string Config_WidgetAPI::widgetLabel() const
132 return getProperty(ATTR_LABEL);
135 std::string Config_WidgetAPI::widgetTooltip() const
137 return getProperty(ATTR_TOOLTIP);