Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / Config / Config_ValidatorReader.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <Config_ValidatorReader.h>
22 #include <Config_Keywords.h>
23 #include <Config_Common.h>
24 #include <Config_ValidatorMessage.h>
25 #include <Config_PropManager.h>
26
27 #include <Events_Loop.h>
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
30
31 #include <fstream>
32
33 #ifdef _DEBUG
34 #include <iostream>
35 #endif
36
37 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName)
38 : Config_XMLReader(theXmlFileName)
39 {
40 }
41
42 Config_ValidatorReader::~Config_ValidatorReader()
43 {
44 }
45
46 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
47 {
48   if (isNode(theNode, NODE_VALIDATOR, NULL)) {
49     processValidator(theNode);
50   } else if (isNode(theNode, NODE_FEATURE, NULL)) {
51     storeAttribute(theNode, _ID);
52   } else if (isWidgetNode(theNode)) {
53     storeAttribute(theNode, _ID);
54     // Store widget name to restore it's id on validator/selector processing
55     myCurrentWidget = getNodeName(theNode);
56   }
57   //Process SOURCE nodes.
58   Config_XMLReader::processNode(theNode);
59 }
60
61 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
62 {
63   if (isNode(theNode, NODE_FEATURE, NULL)) {
64     cleanupAttribute(theNode, _ID);
65   } else if (isWidgetNode(theNode)) {
66     cleanupAttribute(NODE_XMLPARENT, _ID);
67     // Cleanup widget name when leave the widget node.
68     myCurrentWidget = "";
69   }
70 }
71
72 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
73 {
74   return true;
75 }
76
77 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
78 {
79   Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
80   Events_Loop* aEvLoop = Events_Loop::loop();
81   std::shared_ptr<Config_ValidatorMessage>
82     aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
83   std::string aValidatorId;
84   std::list<std::string> aParameters;
85   getParametersInfo(theNode, aValidatorId, aParameters);
86   aMessage->setValidatorId(aValidatorId);
87   aMessage->setValidatorParameters(aParameters);
88   std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
89   aMessage->setFeatureId(aFeatureId);
90   // parent is attribute (widget)
91   if (!myCurrentWidget.empty()) {
92     std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
93     aMessage->setAttributeId(aParentId);
94   }
95   aEvLoop->send(aMessage);
96 }