2 * Config_FeatureReader.cpp
4 * Created on: Mar 20, 2014
8 #include <Config_Keywords.h>
9 #include <Config_Common.h>
10 #include <Config_FeatureMessage.h>
11 #include <Config_AttributeMessage.h>
12 #include <Config_FeatureReader.h>
13 #include <Events_Message.h>
14 #include <Events_Loop.h>
16 #include <libxml/parser.h>
17 #include <libxml/tree.h>
18 #include <libxml/xmlstring.h>
28 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
29 const std::string& theLibraryName,
30 const char* theEventGenerated)
31 : Config_XMLReader(theXmlFile),
32 myLibraryName(theLibraryName),
33 myEventGenerated(theEventGenerated ? theEventGenerated : Config_FeatureMessage::GUI_EVENT()),
34 myIsProcessWidgets(theEventGenerated != NULL)
38 Config_FeatureReader::~Config_FeatureReader()
42 std::list<std::string> Config_FeatureReader::features() const
47 void Config_FeatureReader::processNode(xmlNodePtr theNode)
49 Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
50 if (isNode(theNode, NODE_FEATURE, NULL)) {
51 storeAttribute(theNode, _ID);
52 boost::shared_ptr<Config_FeatureMessage> aMessage(new Config_FeatureMessage(aMenuItemEvent, this));
53 fillFeature(theNode, aMessage);
54 myFeatures.push_back(getProperty(theNode, _ID));
55 //If a feature has xml definition for it's widget:
56 aMessage->setUseInput(hasChild(theNode));
57 Events_Loop::loop()->send(aMessage);
58 //The m_last* variables always defined before fillFeature() call. XML is a tree.
59 } else if (isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL)) {
60 storeAttribute(theNode, _ID);
61 storeAttribute(theNode, WORKBENCH_DOC);
62 } else if (myIsProcessWidgets && isWidgetNode(theNode)) {
63 boost::shared_ptr<Config_AttributeMessage> aMessage(new Config_AttributeMessage(aMenuItemEvent, this));
64 aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
65 aMessage->setAttributeId(getProperty(theNode, _ID));
66 aMessage->setObligatory(getBooleanAttribute(theNode, ATTRIBUTE_OBLIGATORY, true));
67 aMessage->setConcealment(getBooleanAttribute(theNode, ATTRIBUTE_CONCEALMENT, false));
68 Events_Loop::loop()->send(aMessage);
70 //Process SOURCE, VALIDATOR nodes.
71 Config_XMLReader::processNode(theNode);
74 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
76 bool result = isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
77 if(!result && myIsProcessWidgets) {
78 result = isNode(theNode, NODE_FEATURE, NULL);
83 void Config_FeatureReader::fillFeature(xmlNodePtr theNode,
84 const boost::shared_ptr<Config_FeatureMessage>& outFeatureMessage)
86 outFeatureMessage->setId(getProperty(theNode, _ID));
87 outFeatureMessage->setPluginLibrary(myLibraryName);
88 outFeatureMessage->setNestedFeatures(getProperty(theNode, FEATURE_NESTED));
90 bool isInternal = getBooleanAttribute(theNode, ATTRIBUTE_INTERNAL, false);
91 outFeatureMessage->setInternal(isInternal);
93 //Internal feature has no visual representation.
96 outFeatureMessage->setText(getProperty(theNode, FEATURE_TEXT));
97 outFeatureMessage->setTooltip(getProperty(theNode, FEATURE_TOOLTIP));
98 outFeatureMessage->setIcon(getProperty(theNode, FEATURE_ICON));
99 outFeatureMessage->setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE));
100 outFeatureMessage->setGroupId(restoreAttribute(NODE_GROUP, _ID));
101 outFeatureMessage->setWorkbenchId(restoreAttribute(NODE_WORKBENCH, _ID));
102 outFeatureMessage->setDocumentKind(restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC));
105 void Config_FeatureReader::storeAttribute(xmlNodePtr theNode,
106 const char* theNodeAttribute)
108 std::string aKey = getNodeName(theNode) + ":" + std::string(theNodeAttribute);
109 std::string aValue = getProperty(theNode, theNodeAttribute);
110 if(!aValue.empty()) {
111 myParentAttributes[aKey] = aValue;
115 std::string Config_FeatureReader::restoreAttribute(xmlNodePtr theNode,
116 const char* theNodeAttribute)
118 return restoreAttribute(getNodeName(theNode).c_str(), theNodeAttribute);
120 std::string Config_FeatureReader::restoreAttribute(const char* theNodeName,
121 const char* theNodeAttribute)
123 std::string aKey = std::string(theNodeName) + ":" + std::string(theNodeAttribute);
124 std::string result = "";
125 if(myParentAttributes.find(aKey) != myParentAttributes.end()) {
126 result = myParentAttributes[aKey];