Salome HOME
Warnings correction for moc files generation
[modules/shaper.git] / src / Config / Config_ValidatorReader.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_ValidatorReader.cpp
5  *
6  *  Created on: Mar 20, 2015
7  *      Author: sbh
8  */
9
10 #include <Config_ValidatorReader.h>
11 #include <Config_Keywords.h>
12 #include <Config_Common.h>
13 #include <Config_ValidatorMessage.h>
14 #include <Config_PropManager.h>
15
16 #include <Events_Loop.h>
17 #include <libxml/parser.h>
18 #include <libxml/tree.h>
19
20 #include <fstream>
21
22 #ifdef _DEBUG
23 #include <iostream>
24 #endif
25
26 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName)
27 : Config_XMLReader(theXmlFileName)
28 {
29 }
30
31 Config_ValidatorReader::~Config_ValidatorReader()
32 {
33 }
34
35 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
36 {
37   if (isNode(theNode, NODE_VALIDATOR, NULL)) {
38     processValidator(theNode);
39   } else if (isNode(theNode, NODE_FEATURE, NULL)) {
40     storeAttribute(theNode, _ID);
41   } else if (isWidgetNode(theNode)) {
42     storeAttribute(theNode, _ID);
43     // Store widget name to restore it's id on validator/selector processing
44     myCurrentWidget = getNodeName(theNode);
45   }
46   //Process SOURCE nodes.
47   Config_XMLReader::processNode(theNode);
48 }
49
50 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
51 {
52   if (isNode(theNode, NODE_FEATURE, NULL)) {
53     cleanupAttribute(theNode, _ID);
54   } else if (isWidgetNode(theNode)) {
55     cleanupAttribute(NODE_XMLPARENT, _ID);
56     // Cleanup widget name when leave the widget node.
57     myCurrentWidget = "";
58   }
59 }
60
61 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
62 {
63   return true;
64 }
65
66 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
67 {
68   Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
69   Events_Loop* aEvLoop = Events_Loop::loop();
70   std::shared_ptr<Config_ValidatorMessage>
71     aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
72   std::string aValidatorId;
73   std::list<std::string> aParameters;
74   getParametersInfo(theNode, aValidatorId, aParameters);
75   aMessage->setValidatorId(aValidatorId);
76   aMessage->setValidatorParameters(aParameters);
77   std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
78   aMessage->setFeatureId(aFeatureId);
79   // parent is attribute (widget)
80   if (!myCurrentWidget.empty()) {
81     std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
82     aMessage->setAttributeId(aParentId);
83   }
84   aEvLoop->send(aMessage);
85 }