]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #671 - Removing object used in feature creation with optional parameters. ...
authorspo <sergey.pokhodenko@opencascade.com>
Mon, 6 Jul 2015 13:48:14 +0000 (16:48 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Mon, 6 Jul 2015 13:50:06 +0000 (16:50 +0300)
src/Config/Config_Common.cpp
src/Config/Config_Common.h
src/Config/Config_FeatureReader.cpp

index a36be0325bf6a47e47170197d9c8ea0b5d9a9ccc..bb5ddeed9b001da3700fd3298a3e8eb7e1e79d4f 100644 (file)
@@ -17,6 +17,7 @@
 \r
 #include <string>\r
 #include <algorithm> // for std::transform\r
+#include <vector>\r
 \r
 bool isElementNode(xmlNodePtr theNode)\r
 {\r
@@ -55,12 +56,14 @@ bool isAttributeNode(xmlNodePtr theNode)
     return false;\r
   // it's parent is "feature" or "source" or page ("case" or "box")\r
   if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, \r
+                         WDG_GROUP, WDG_CHECK_GROUP,\r
                          WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL))\r
     return false;\r
 \r
   //it should not be a "source" or a "validator" node\r
   bool isLogical = isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL);\r
   bool isPagedContainer = isNode(theNode, WDG_TOOLBOX, WDG_TOOLBOX_BOX,\r
+                                          WDG_GROUP, WDG_CHECK_GROUP,\r
                                           WDG_SWITCH, WDG_SWITCH_CASE,  NULL);\r
   return !isLogical && !isPagedContainer;\r
 }\r
@@ -140,6 +143,39 @@ bool hasParent(xmlNodePtr theNode, const char* theNodeName, ...)
   return false;\r
 }\r
 \r
+bool hasParentRecursive(xmlNodePtr theNode, const std::vector<const char*>& theNodeNames)\r
+{\r
+  if (!hasParent(theNode)) {\r
+    return false; // have no parents at all\r
+  }\r
+  xmlNodePtr aNode = theNode->parent;\r
+  const xmlChar* aName = aNode->name;\r
+  if (!aName || !isElementNode(aNode)) {\r
+    return false;\r
+  }\r
+  for (size_t anIndex = 0; anIndex < theNodeNames.size(); ++anIndex) {\r
+    if (!xmlStrcmp(aName, (const xmlChar *) theNodeNames[anIndex]))\r
+      return true;\r
+  }\r
+  return hasParentRecursive(aNode, theNodeNames);\r
+}\r
+\r
+bool hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...)\r
+{\r
+  std::vector<const char*> aNodeNames;\r
+  va_list args;  // define argument list variable\r
+  va_start(args, theNodeName);  // init list; point to last defined argument\r
+  aNodeNames.push_back(theNodeName);\r
+  while (true) {\r
+    char *anArg = va_arg (args, char*);  // get next argument\r
+    if (anArg == NULL)\r
+      break;\r
+    aNodeNames.push_back(anArg);\r
+  }\r
+  va_end(args);  // cleanup the system stack\r
+  return hasParentRecursive(theNode, aNodeNames);\r
+}\r
+\r
 bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId,\r
                       std::list<std::string>& outValidatorParameters)\r
 {\r
index 1850f8a7bd642373ed74ebdc4d262b443403410a..52776d764f7623c1b75ea912f176d713e68e2b91 100644 (file)
@@ -81,6 +81,12 @@ CONFIG_EXPORT bool hasParent(xmlNodePtr theNode);
  */
 CONFIG_EXPORT bool hasParent(xmlNodePtr theNode, const char* theNodeName, ...);
 
+/*!
+ * Checks if the given node has any valid parent in hierarchy with any of the given node names.
+ */
+CONFIG_EXPORT bool hasParentRecursive(xmlNodePtr theNode, const char* theNodeName, ...);
+
+
 /*!
  * Returns named property for an id node as std::string and the parameters of the node.
  */
index 2b024061a5335aa2ee405d36c6ddaca7726516e1..8a3b5f19b4548361cdc8423271dd4e55dfcfe6b7 100644 (file)
@@ -72,11 +72,11 @@ void Config_FeatureReader::processNode(xmlNodePtr theNode)
         aMessage->setObligatory(getBooleanAttribute(theNode, ATTR_OBLIGATORY, true));
         aMessage->setConcealment(getBooleanAttribute(theNode, ATTR_CONCEALMENT, false));
         // nested "paged" widgets are not allowed, this issue may be resolved here:
-        if (hasParent(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, NULL)) {
-          const char* kWdgCase = hasParent(theNode, WDG_SWITCH_CASE, NULL)
+        if (hasParentRecursive(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, NULL)) {
+          const char* kWdgCase = hasParentRecursive(theNode, WDG_SWITCH_CASE, NULL)
                                  ? WDG_SWITCH_CASE
                                  : WDG_TOOLBOX_BOX;
-          const char* kWdgSwitch = hasParent(theNode, WDG_SWITCH_CASE, NULL)
+          const char* kWdgSwitch = hasParentRecursive(theNode, WDG_SWITCH_CASE, NULL)
                                    ? WDG_SWITCH
                                    : WDG_TOOLBOX;
           aMessage->setCaseId(restoreAttribute(kWdgCase, _ID));
@@ -106,6 +106,7 @@ bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
   bool result = isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
   if(!result && myIsProcessWidgets) {
     result = isNode(theNode, NODE_FEATURE, 
+                             WDG_GROUP, WDG_CHECK_GROUP,
                              WDG_TOOLBOX, WDG_TOOLBOX_BOX,
                              WDG_SWITCH, WDG_SWITCH_CASE, NULL);
   }