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