Salome HOME
d15293f6758f18168e946f9be2ca90661ad25615
[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_SelectionFilterMessage.h>
15 #include <Config_PropManager.h>
16
17 #include <Events_Loop.h>
18 #include <libxml/parser.h>
19 #include <libxml/tree.h>
20
21 #include <fstream>
22
23 #ifdef _DEBUG
24 #include <iostream>
25 #endif
26
27 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName)
28 : Config_XMLReader(theXmlFileName)
29 {
30 }
31
32 Config_ValidatorReader::~Config_ValidatorReader()
33 {
34 }
35
36 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
37 {
38   if (isNode(theNode, NODE_VALIDATOR, NULL)) {
39     processValidator(theNode);
40   } else if (isNode(theNode, NODE_SELFILTER, NULL)) {
41     processSelectionFilter(theNode);
42   } else if (isNode(theNode, NODE_FEATURE, NULL)) {
43     storeAttribute(theNode, _ID);
44   } else if (isWidgetNode(theNode)) {
45     storeAttribute(theNode, _ID);
46     // Store widget name to restore it's id on validator/selector processing
47     myCurrentWidget = getNodeName(theNode);
48   }
49   //Process SOURCE nodes.
50   Config_XMLReader::processNode(theNode);
51 }
52
53 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
54 {
55   if (isNode(theNode, NODE_FEATURE, NULL)) {
56     cleanupAttribute(theNode, _ID);
57   } else if (isWidgetNode(theNode)) {
58     cleanupAttribute(NODE_XMLPARENT, _ID);
59     // Cleanup widget name when leave the widget node.
60     myCurrentWidget = "";
61   }
62 }
63
64 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
65 {
66   return true;
67 }
68
69 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
70 {
71   Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
72   Events_Loop* aEvLoop = Events_Loop::loop();
73   std::shared_ptr<Config_ValidatorMessage>
74     aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
75   std::string aValidatorId;
76   std::list<std::string> aParameters;
77   getParametersInfo(theNode, aValidatorId, aParameters);
78   aMessage->setValidatorId(aValidatorId);
79   aMessage->setValidatorParameters(aParameters);
80   std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
81   aMessage->setFeatureId(aFeatureId);
82   // parent is attribute (widget)
83   if (!myCurrentWidget.empty()) {
84     std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
85     aMessage->setAttributeId(aParentId);
86   }
87   aEvLoop->send(aMessage);
88 }
89
90 void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode)
91 {
92   Events_ID aFilterEvent = Events_Loop::eventByName(EVENT_SELFILTER_LOADED);
93   Events_Loop* aEvLoop = Events_Loop::loop();
94   std::shared_ptr<Config_SelectionFilterMessage> aMessage(
95       new Config_SelectionFilterMessage(aFilterEvent, this));
96   std::string aSelectionFilterId;
97   std::list<std::string> aParameters;
98   getParametersInfo(theNode, aSelectionFilterId, aParameters);
99   aMessage->setSelectionFilterId(aSelectionFilterId);
100   aMessage->setFilterParameters(aParameters);
101   std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
102   aMessage->setFeatureId(aFeatureId);
103   // parent is attribute (widget)
104   if (!myCurrentWidget.empty()) {
105     std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
106     aMessage->setAttributeId(aParentId);
107   }
108   aEvLoop->send(aMessage);
109 }