X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConfig%2FConfig_Common.cpp;h=ce096355a766652d76447cd60d0a40ee58847b82;hb=e32f95642855a63da2727cb324ce2a75632a712f;hp=8c8cde4270d7a27265c77d29be1c0f0e68fbdaf0;hpb=2d1be67088b0864e4511036dfc51eded0dfb7822;p=modules%2Fshaper.git diff --git a/src/Config/Config_Common.cpp b/src/Config/Config_Common.cpp index 8c8cde427..ce096355a 100644 --- a/src/Config/Config_Common.cpp +++ b/src/Config/Config_Common.cpp @@ -17,6 +17,7 @@ #include #include // for std::transform +#include bool isElementNode(xmlNodePtr theNode) { @@ -55,12 +56,14 @@ bool isAttributeNode(xmlNodePtr theNode) return false; // it's parent is "feature" or "source" or page ("case" or "box") if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, + WDG_GROUP, WDG_CHECK_GROUP, WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL)) return false; //it should not be a "source" or a "validator" node bool isLogical = isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL); bool isPagedContainer = isNode(theNode, WDG_TOOLBOX, WDG_TOOLBOX_BOX, + WDG_GROUP, WDG_CHECK_GROUP, WDG_SWITCH, WDG_SWITCH_CASE, NULL); return !isLogical && !isPagedContainer; } @@ -70,7 +73,7 @@ bool isWidgetNode(xmlNodePtr theNode) if(!isElementNode(theNode)) return false; // it's parent is "feature" or "source" or a page ("box", "case") - if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, + if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, WDG_GROUP, WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL)) return false; @@ -140,6 +143,39 @@ bool hasParent(xmlNodePtr theNode, const char* theNodeName, ...) return false; } +bool hasParentRecursive(xmlNodePtr theNode, const std::vector& theNodeNames) +{ + if (!hasParent(theNode)) { + return false; // have no parents at all + } + xmlNodePtr aNode = theNode->parent; + const xmlChar* aName = aNode->name; + if (!aName || !isElementNode(aNode)) { + return false; + } + for (size_t anIndex = 0; anIndex < theNodeNames.size(); ++anIndex) { + if (!xmlStrcmp(aName, (const xmlChar *) theNodeNames[anIndex])) + return true; + } + return hasParentRecursive(aNode, theNodeNames); +} + +bool hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...) +{ + std::vector aNodeNames; + va_list args; // define argument list variable + va_start(args, theNodeName); // init list; point to last defined argument + aNodeNames.push_back(theNodeName); + while (true) { + char *anArg = va_arg (args, char*); // get next argument + if (anArg == NULL) + break; + aNodeNames.push_back(anArg); + } + va_end(args); // cleanup the system stack + return hasParentRecursive(theNode, aNodeNames); +} + bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId, std::list& outValidatorParameters) { @@ -184,6 +220,8 @@ std::string library(const std::string& theLibName) return aLibName; } +bool BothAreSpaces(char lhs, char rhs) { return (lhs == rhs) && (lhs == ' '); } + std::string getProperty(xmlNodePtr theNode, const char* thePropName) { std::string result = ""; @@ -191,6 +229,10 @@ std::string getProperty(xmlNodePtr theNode, const char* thePropName) if (!aPropChars || aPropChars[0] == 0) return result; result = std::string(aPropChars); + + std::string::iterator new_end = std::unique(result.begin(), result.end(), BothAreSpaces); + result.erase(new_end, result.end()); + return result; }