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