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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 * Config_WidgetAPI.cpp
23 * Created on: Apr 1, 2014
27 #include <Config_WidgetAPI.h>
28 #include <Config_Keywords.h>
29 #include <Config_Common.h>
31 #include <libxml/parser.h>
32 #include <libxml/tree.h>
36 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
38 myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
39 myCurrentNode = xmlDocGetRootElement(myDoc);
40 myFeatureId = getProperty(_ID);
43 Config_WidgetAPI::~Config_WidgetAPI()
48 bool Config_WidgetAPI::toNextWidget()
50 //Skip all non-element node, stop if next node is null
51 xmlNodePtr aNextNode = myCurrentNode;
53 aNextNode = aNextNode->next;
54 } while (aNextNode && !isElementNode(aNextNode));
60 myCurrentNode = aNextNode;
64 bool Config_WidgetAPI::toChildWidget()
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
72 while (aChildNode && !isElementNode(aChildNode)) {
73 aChildNode = aChildNode->next;
75 if (aChildNode != NULL) {
76 myCurrentNode = aChildNode;
83 bool Config_WidgetAPI::toParentWidget()
86 myCurrentNode = myCurrentNode->parent;
88 return myCurrentNode != NULL;
91 std::string Config_WidgetAPI::widgetType() const
93 std::string result = "";
95 result = std::string((char *) myCurrentNode->name);
100 bool Config_WidgetAPI::isGroupBoxWidget() const
102 return isNode(myCurrentNode, WDG_GROUP, WDG_OPTIONALBOX,
106 bool Config_WidgetAPI::isPagedWidget() const
108 return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
112 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
114 return ::getProperty(myCurrentNode, thePropName);
117 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
119 return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault);
122 std::string Config_WidgetAPI::featureId() const
127 std::string Config_WidgetAPI::widgetId() const
129 return getProperty(_ID);
132 std::string Config_WidgetAPI::widgetIcon() const
134 return getProperty(ATTR_ICON);
137 std::string Config_WidgetAPI::widgetLabel() const
139 return getProperty(ATTR_LABEL);
142 std::string Config_WidgetAPI::widgetTooltip() const
144 return getProperty(ATTR_TOOLTIP);