Salome HOME
Porting to SALOME_8.2.0 : Debug visualization selection for AIS_Trihedron axes.
[modules/shaper.git] / src / Config / Config_ValidatorReader.cpp
index d03dff58d7d6784c5bc572fd25639a5dad93c1bc..d15293f6758f18168e946f9be2ca90661ad25615 100644 (file)
@@ -15,7 +15,6 @@
 #include <Config_PropManager.h>
 
 #include <Events_Loop.h>
-#include <Events_Error.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
@@ -42,11 +41,26 @@ void Config_ValidatorReader::processNode(xmlNodePtr theNode)
     processSelectionFilter(theNode);
   } else if (isNode(theNode, NODE_FEATURE, NULL)) {
     storeAttribute(theNode, _ID);
+  } else if (isWidgetNode(theNode)) {
+    storeAttribute(theNode, _ID);
+    // Store widget name to restore it's id on validator/selector processing
+    myCurrentWidget = getNodeName(theNode);
   }
   //Process SOURCE nodes.
   Config_XMLReader::processNode(theNode);
 }
 
+void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
+{
+  if (isNode(theNode, NODE_FEATURE, NULL)) {
+    cleanupAttribute(theNode, _ID);
+  } else if (isWidgetNode(theNode)) {
+    cleanupAttribute(NODE_XMLPARENT, _ID);
+    // Cleanup widget name when leave the widget node.
+    myCurrentWidget = "";
+  }
+}
+
 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
 {
   return true;
@@ -56,21 +70,19 @@ void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
 {
   Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
   Events_Loop* aEvLoop = Events_Loop::loop();
-  std::shared_ptr<Config_ValidatorMessage> 
+  std::shared_ptr<Config_ValidatorMessage>
     aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
   std::string aValidatorId;
   std::list<std::string> aParameters;
   getParametersInfo(theNode, aValidatorId, aParameters);
   aMessage->setValidatorId(aValidatorId);
   aMessage->setValidatorParameters(aParameters);
-  //TODO(sbh): update feature/attribute id restoring
-  // when "cleanup" technique will be available (v. >= 1.1.0)
-  xmlNodePtr aFeatureOrWdgNode = theNode->parent;
-  if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) {
-    aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID));
-  } else {
-    aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID));
-    aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
+  std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
+  aMessage->setFeatureId(aFeatureId);
+  // parent is attribute (widget)
+  if (!myCurrentWidget.empty()) {
+    std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
+    aMessage->setAttributeId(aParentId);
   }
   aEvLoop->send(aMessage);
 }
@@ -79,20 +91,19 @@ void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode)
 {
   Events_ID aFilterEvent = Events_Loop::eventByName(EVENT_SELFILTER_LOADED);
   Events_Loop* aEvLoop = Events_Loop::loop();
-  std::shared_ptr<Config_SelectionFilterMessage> aMessage =
-      std::make_shared<Config_SelectionFilterMessage>(aFilterEvent, this);
+  std::shared_ptr<Config_SelectionFilterMessage> aMessage(
+      new Config_SelectionFilterMessage(aFilterEvent, this));
   std::string aSelectionFilterId;
   std::list<std::string> aParameters;
   getParametersInfo(theNode, aSelectionFilterId, aParameters);
   aMessage->setSelectionFilterId(aSelectionFilterId);
   aMessage->setFilterParameters(aParameters);
-
-  xmlNodePtr aFeatureOrWdgNode = theNode->parent;
-  if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) {
-    aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID));
-  } else {
-    aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID));
-    aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
+  std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
+  aMessage->setFeatureId(aFeatureId);
+  // parent is attribute (widget)
+  if (!myCurrentWidget.empty()) {
+    std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
+    aMessage->setAttributeId(aParentId);
   }
   aEvLoop->send(aMessage);
 }