X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConfig%2FConfig_WidgetAPI.cpp;h=214b4bdd5240c2d1280677a42161b677851b2e2f;hb=8f9631c551573523a4dd93f582efd70105bd3c82;hp=14d5fa2aa9b18323806403b393f6de708c78580a;hpb=401394b2e312e5c4ecd6a410b90eb2c159a675bf;p=modules%2Fshaper.git diff --git a/src/Config/Config_WidgetAPI.cpp b/src/Config/Config_WidgetAPI.cpp index 14d5fa2aa..214b4bdd5 100644 --- a/src/Config/Config_WidgetAPI.cpp +++ b/src/Config/Config_WidgetAPI.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + /* * Config_WidgetAPI.cpp * @@ -6,94 +8,167 @@ */ #include +#include +#include -#include -#include +#include +#include +#include -Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml) +Config_WidgetAPI::Config_WidgetAPI(const std::string& theRawXml) { myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str()); - myCurrentNode = NULL; + myCurrentNode = xmlDocGetRootElement(myDoc); } - Config_WidgetAPI::~Config_WidgetAPI() { xmlFreeDoc(myDoc); } -void Config_WidgetAPI::reset() +bool Config_WidgetAPI::toNextWidget() { - xmlNodePtr aRoot = xmlDocGetRootElement(myDoc); - if(aRoot) { - myCurrentNode = aRoot->children; + //Skip all non-element node, stop if next node is null + xmlNodePtr aNextNode = myCurrentNode; + do { + aNextNode = aNextNode->next; + } while (aNextNode && !isElementNode(aNextNode)); + + if (!aNextNode) { + toParentWidget(); + return false; } + myCurrentNode = aNextNode; + return true; } -bool Config_WidgetAPI::nextWidget() +bool Config_WidgetAPI::toChildWidget() { - if(myCurrentNode) { - myCurrentNode = myCurrentNode->next; + if (myCurrentNode && hasChild(myCurrentNode)) { + myCurrentNode = myCurrentNode->children; + while (myCurrentNode && !isElementNode(myCurrentNode)) { + myCurrentNode = myCurrentNode->next; + } + return myCurrentNode != NULL; + } + return false; +} + +bool Config_WidgetAPI::toParentWidget() +{ + if (myCurrentNode) { + myCurrentNode = myCurrentNode->parent; } return myCurrentNode != NULL; } -std::string Config_WidgetAPI::widgetType() +std::list Config_WidgetAPI::attributes() const +{ + std::list aResult; + if (myCurrentNode && hasChild(myCurrentNode)) { + xmlNodePtr anAttributesNode = myCurrentNode->children; + while (anAttributesNode && + (!isElementNode(anAttributesNode) || + std::string((char *) anAttributesNode->name) != NODE_NAME_ATTRIBUTES)) { + anAttributesNode = anAttributesNode->next; + } + if (anAttributesNode && hasChild(anAttributesNode)) { + xmlNodePtr anAttributeNode = anAttributesNode->children; + while (anAttributeNode) { + if (isElementNode(anAttributeNode) && + std::string((char *) anAttributeNode->name) == NODE_NAME_ATTRIBUTE) + aResult.push_back(anAttributeNode); + anAttributeNode = anAttributeNode->next; + } + } + } + return aResult; +} + +std::string Config_WidgetAPI::widgetType() const { std::string result = ""; - if(myCurrentNode) { + if (myCurrentNode) { result = std::string((char *) myCurrentNode->name); } return result; } -std::string Config_WidgetAPI::getProperty(const char* thePropName) +bool Config_WidgetAPI::isGroupBoxWidget() const { - std::string result = ""; - char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName); - if (!aPropChars || aPropChars[0] == 0) - return result; - result = std::string(aPropChars); - return result; + return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP, + NULL); } -std::string Config_WidgetAPI::widgetTooltip() +bool Config_WidgetAPI::isPagedWidget() const { - return getProperty("tooltip"); + return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH, + NULL); } -std::string Config_WidgetAPI::widgetIcon() +std::string Config_WidgetAPI::getProperty(const char* thePropName) const { - return getProperty("icon"); + return ::getProperty(myCurrentNode, thePropName); } -std::string Config_WidgetAPI::widgetLabel() +bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const { - return getProperty("label"); + return ::getBooleanAttribute(myCurrentNode, theAttributeName, theDefault); } -bool Config_WidgetAPI::isNode(xmlNodePtr theNode, const char* theNodeName, ...) +std::string Config_WidgetAPI::widgetId() const { - bool result = false; - const xmlChar* aName = theNode->name; - if (!aName || theNode->type != XML_ELEMENT_NODE) - return false; + return getProperty(_ID); +} - if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) - return true; - - va_list args; // define argument list variable - va_start(args, theNodeName); // init list; point to last defined argument - while(true) { - char *anArg = va_arg (args, char*); // get next argument - if (anArg == NULL) - break; - if (!xmlStrcmp(aName, (const xmlChar *) anArg)) { - va_end(args); // cleanup the system stack - return true; - } +std::string Config_WidgetAPI::widgetIcon() const +{ + return getProperty(ATTR_ICON); +} + +std::string Config_WidgetAPI::widgetLabel() const +{ + return getProperty(ATTR_LABEL); +} + +std::string Config_WidgetAPI::widgetTooltip() const +{ + return getProperty(ATTR_TOOLTIP); +} + +std::list Config_WidgetAPI::getAttributes(const std::string& theRole/* = std::string()*/) const +{ + std::list aResult; + + if (theRole.empty() || theRole == ATTR_MAIN_ROLE) + aResult.push_back(widgetId()); + + if (theRole == ATTR_MAIN_ROLE) + return aResult; + + std::list anAttributes = attributes(); + for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) { + if (theRole.empty() || theRole == ::getProperty(*it, ATTR_ROLE)) + aResult.push_back(::getProperty(*it, ATTR_ID)); } - va_end(args); // cleanup the system stack - return false; + return aResult; +} + +std::string Config_WidgetAPI::getAttributeProperty(const std::string& theAttribute, + const std::string& thePropName) const +{ + if (theAttribute == widgetId()) { + if (thePropName == ATTR_ROLE) + return ATTR_MAIN_ROLE; + return ::getProperty(myCurrentNode, thePropName.c_str()); + } + + std::list anAttributes = attributes(); + for (auto it = anAttributes.begin(); it != anAttributes.end(); ++it) { + if (theAttribute == ::getProperty(*it, ATTR_ID)) + return ::getProperty(*it, thePropName.c_str()); + } + return std::string(); } +