1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
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>
27 #include <Events_Loop.h>
28 #include <libxml/parser.h>
29 #include <libxml/tree.h>
37 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName)
38 : Config_XMLReader(theXmlFileName)
42 Config_ValidatorReader::~Config_ValidatorReader()
46 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
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);
57 //Process SOURCE nodes.
58 Config_XMLReader::processNode(theNode);
61 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
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.
72 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
77 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
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);
95 aEvLoop->send(aMessage);