Salome HOME
0eb2bfdaa5ac4975e8f554eae979df7dccb930a2
[modules/shaper.git] / src / Config / Config_FeatureReader.cpp
1 /*
2  * Config_FeatureReader.cpp
3  *
4  *  Created on: Mar 20, 2014
5  *      Author: sbh
6  */
7
8 #include <Config_FeatureReader.h>
9
10 #include <Event_Loop.hxx>
11
12 #include <libxml\parser.h>
13 #include <libxml\tree.h>
14
15 #ifdef _DEBUG
16 #include <iostream>
17 #endif
18
19 //Hardcoded xml entities
20 // * Nodes
21
22 // * Properties
23 const static char* FEATURE_ID = "id";
24 const static char* FEATURE_TEXT = "text";
25 const static char* FEATURE_TOOLTIP = "tooltip";
26 const static char* FEATURE_ICON = "icon";
27 const static char* FEATURE_KEYSEQUENCE = "keysequence";
28 const static char* FEATURE_GROUP_NAME = "name";
29
30
31
32
33 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile)
34     : Config_XMLReader(theXmlFile)
35 {
36   #ifdef _DEBUG
37   if(!Event_Loop::Loop()) {
38     std::cout << "Config_FeatureReader::importWorkbench: "
39         << "No event loop registered" << std::endl;
40   }
41   #endif
42 }
43
44 Config_FeatureReader::~Config_FeatureReader()
45 {
46 }
47
48 void Config_FeatureReader::processNode(xmlNodePtr theNode)
49 {
50   if(isNode(theNode,"feature")) {
51     Event_Loop* aEvLoop = Event_Loop::Loop();
52     Config_FeatureMessage aMessage(aEvLoop->EventByName("Feature"), this);
53     fillFeature(theNode, aMessage);
54     xmlNodePtr aGroupNode = theNode->parent;
55     if(aGroupNode) {
56       std::string aGroupName = getProperty(aGroupNode, FEATURE_GROUP_NAME);
57       aMessage.m_group = aGroupName;
58     }
59     aEvLoop->Send(aMessage);
60   }
61 }
62
63 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
64 {
65   return isNode(theNode, "workbench")
66       || isNode(theNode, "group");
67 //      || isNode(theNode, "feature");
68 }
69
70 void Config_FeatureReader::fillFeature(xmlNodePtr theRoot,
71                                        Config_FeatureMessage& outFtMessage)
72 {
73   outFtMessage.m_id = getProperty(theRoot, FEATURE_ID);
74   outFtMessage.m_text = getProperty(theRoot, FEATURE_TEXT);
75   outFtMessage.m_tooltip = getProperty(theRoot, FEATURE_TOOLTIP);
76   outFtMessage.m_icon = getProperty(theRoot, FEATURE_ICON);
77   outFtMessage.m_keysequence = getProperty(theRoot, FEATURE_KEYSEQUENCE);
78 }