Salome HOME
Adaptation to SALOME environment (Issue #31)
[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_Keywords.h>
9 #include <Config_Common.h>
10 #include <Config_FeatureMessage.h>
11 #include <Config_FeatureReader.h>
12 #include <Events_Message.h>
13 #include <Events_Loop.h>
14
15 #include <libxml/parser.h>
16 #include <libxml/tree.h>
17 #include <libxml/xmlstring.h>
18
19 #include <string>
20
21 #ifdef _DEBUG
22 #include <iostream>
23 #endif
24
25
26 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
27                                            const std::string& theLibraryName,
28                                            const char* theEventGenerated)
29     : Config_XMLReader(theXmlFile),
30       myLibraryName(theLibraryName),
31       myEventGenerated(theEventGenerated ? theEventGenerated : "FeatureEvent")
32 {
33 }
34
35 Config_FeatureReader::~Config_FeatureReader()
36 {
37 }
38
39 void Config_FeatureReader::processNode(xmlNodePtr theNode)
40 {
41   Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
42   if (isNode(theNode, NODE_FEATURE, NULL)) {
43     Events_Loop* aEvLoop = Events_Loop::loop();
44     Config_FeatureMessage aMessage(aMenuItemEvent, this);
45     fillFeature(theNode, aMessage);
46     //If a feature has xml definition for it's widget:
47     aMessage.setUseInput(hasChild(theNode));
48     aEvLoop->send(aMessage);
49   }
50   //The m_last* variables always defined before fillFeature() call. XML is a tree.
51   if (isNode(theNode, NODE_GROUP, NULL)) {
52     myLastGroup = getProperty(theNode, _ID);
53   }
54   if (isNode(theNode, NODE_WORKBENCH, NULL)) {
55     myLastWorkbench = getProperty(theNode, _ID);
56   }
57 }
58
59 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
60 {
61   return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
62 }
63
64 void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFtMessage)
65 {
66   outFtMessage.setId(getProperty(theRoot, _ID));
67   outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
68   outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
69   outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
70   outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
71   outFtMessage.setGroupId(myLastGroup);
72   outFtMessage.setWorkbenchId(myLastWorkbench);
73   outFtMessage.setPluginLibrary(myLibraryName);
74 }