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