Salome HOME
Issue #353 constraint on 2 segments from not acive sketches
[modules/shaper.git] / src / Config / Config_Common.cpp
index 9c4df7f57c539174f1496979685e7d8b48c113e9..8ffc9e126b6938135b3cde07239281aae9969115 100644 (file)
@@ -27,7 +27,6 @@ bool isElementNode(xmlNodePtr theNode)
 \r
 bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)\r
 {\r
-  bool result = false;\r
   const xmlChar* aName = theNode->name;\r
   if (!aName || !isElementNode(theNode)) {\r
     return false;\r
@@ -50,19 +49,44 @@ bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
   return false;\r
 }\r
 \r
+bool isAttributeNode(xmlNodePtr theNode)\r
+{\r
+  if(!isElementNode(theNode))\r
+    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_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_SWITCH, WDG_SWITCH_CASE,  NULL);\r
+  return !isLogical && !isPagedContainer;\r
+}\r
+\r
 bool isWidgetNode(xmlNodePtr theNode)\r
 {\r
   if(!isElementNode(theNode))\r
     return false;\r
   // it's parent is "feature" or "source"\r
-  xmlNodePtr aParentNode = theNode->parent;\r
-  if(!isNode(aParentNode, NODE_FEATURE, NODE_SOURCE, NULL))\r
+  if(!hasParent(theNode, NODE_FEATURE, NODE_SOURCE, \r
+                         WDG_TOOLBOX_BOX, WDG_SWITCH_CASE, NULL))\r
     return false;\r
 \r
   //it should not be a "source" or a "validator" node\r
   return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NODE_SELFILTER, NULL);\r
 }\r
 \r
+// widget api?\r
+bool isCaseNode(xmlNodePtr theNode)\r
+{\r
+  if(!isElementNode(theNode))\r
+    return false;\r
+\r
+  return isNode(theNode, WDG_SWITCH_CASE, WDG_TOOLBOX_BOX, NULL);\r
+}\r
+\r
 bool hasChild(xmlNodePtr theNode)\r
 {\r
   xmlNodePtr aNode = theNode->children;\r
@@ -74,6 +98,48 @@ bool hasChild(xmlNodePtr theNode)
   return false;\r
 }\r
 \r
+bool hasParent(xmlNodePtr theNode)\r
+{\r
+  xmlNodePtr aNode = theNode->parent;\r
+  if (!aNode) {\r
+    return false;\r
+  }\r
+  for (; aNode; aNode = aNode->next) {\r
+    if (isElementNode(theNode)) {\r
+      return true;\r
+    }\r
+  }\r
+  return false;\r
+}\r
+\r
+bool hasParent(xmlNodePtr theNode, const char* theNodeName, ...)\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
+  if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {\r
+    return true;\r
+  }\r
+  va_list args;  // define argument list variable\r
+  va_start(args, theNodeName);  // init list; point to last defined argument\r
+  while (true) {\r
+    char *anArg = va_arg (args, char*);  // get next argument\r
+    if (anArg == NULL)\r
+      break;\r
+    if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {\r
+      va_end(args);  // cleanup the system stack\r
+      return true;\r
+    }\r
+  }\r
+  va_end(args);  // cleanup the system stack\r
+  return false;\r
+}\r
+\r
 bool getParametersInfo(xmlNodePtr theNode, std::string& outPropertyId,\r
                       std::list<std::string>& outValidatorParameters)\r
 {\r