]> SALOME platform Git repositories - modules/shaper.git/blob - src/Config/Config_ValidatorReader.cpp
Salome HOME
Process validators on the first feature's creation using the Config_ValidatorReader
[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   std::cout << "Config_ValidatorReader created for: " << theXmlFileName << std::endl;
32 }
33
34 Config_ValidatorReader::~Config_ValidatorReader()
35 {
36 }
37
38 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
39 {
40   if (isNode(theNode, NODE_VALIDATOR, NULL)) {
41     processValidator(theNode);
42   } else if (isNode(theNode, NODE_SELFILTER, NULL)) {
43     processSelectionFilter(theNode);
44   } else if (isNode(theNode, NODE_FEATURE, NULL)) {
45     storeAttribute(theNode, _ID);
46   }
47   //Process SOURCE nodes.
48   Config_XMLReader::processNode(theNode);
49 }
50
51 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
52 {
53   return true;
54 }
55
56 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
57 {
58   Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
59   Events_Loop* aEvLoop = Events_Loop::loop();
60   std::shared_ptr<Config_ValidatorMessage> 
61     aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
62   std::string aValidatorId;
63   std::list<std::string> aParameters;
64   getParametersInfo(theNode, aValidatorId, aParameters);
65   aMessage->setValidatorId(aValidatorId);
66   aMessage->setValidatorParameters(aParameters);
67   //TODO(sbh): update feature/attribute id restoring
68   // when "cleanup" technique will be available (v. >= 1.1.0)
69   xmlNodePtr aFeatureOrWdgNode = theNode->parent;
70   if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) {
71     aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID));
72   } else {
73     aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID));
74     aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
75   }
76   aEvLoop->send(aMessage);
77 }
78
79 void Config_ValidatorReader::processSelectionFilter(xmlNodePtr theNode)
80 {
81   Events_ID aFilterEvent = Events_Loop::eventByName(EVENT_SELFILTER_LOADED);
82   Events_Loop* aEvLoop = Events_Loop::loop();
83   std::shared_ptr<Config_SelectionFilterMessage> aMessage =
84       std::make_shared<Config_SelectionFilterMessage>(aFilterEvent, this);
85   std::string aSelectionFilterId;
86   std::list<std::string> aParameters;
87   getParametersInfo(theNode, aSelectionFilterId, aParameters);
88   aMessage->setSelectionFilterId(aSelectionFilterId);
89   aMessage->setFilterParameters(aParameters);
90
91   xmlNodePtr aFeatureOrWdgNode = theNode->parent;
92   if (isNode(aFeatureOrWdgNode, NODE_FEATURE, NULL)) {
93     aMessage->setFeatureId(getProperty(aFeatureOrWdgNode, _ID));
94   } else {
95     aMessage->setAttributeId(getProperty(aFeatureOrWdgNode, _ID));
96     aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
97   }
98   aEvLoop->send(aMessage);
99 }