Salome HOME
Useful methods for sketch operations managements
[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 : EVENT_FEATURE_LOADED)
32 {
33 }
34
35 Config_FeatureReader::~Config_FeatureReader()
36 {
37 }
38
39 std::list<std::string> Config_FeatureReader::features() const
40 {
41   return myFeatures;
42 }
43
44 void Config_FeatureReader::processNode(xmlNodePtr theNode)
45 {
46   Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
47   if (isNode(theNode, NODE_FEATURE, NULL)) {
48     Events_Loop* aEvLoop = Events_Loop::loop();
49     Config_FeatureMessage aMessage(aMenuItemEvent, this);
50     fillFeature(theNode, aMessage);
51     myFeatures.push_back(getProperty(theNode, _ID));
52     //If a feature has xml definition for it's widget:
53     aMessage.setUseInput(hasChild(theNode));
54     aEvLoop->send(aMessage);
55   }
56   //The m_last* variables always defined before fillFeature() call. XML is a tree.
57   if (isNode(theNode, NODE_GROUP, NULL)) {
58     myLastGroup = getProperty(theNode, _ID);
59   }
60   if (isNode(theNode, NODE_WORKBENCH, NULL)) {
61     myLastWorkbench = getProperty(theNode, _ID);
62   }
63   //Process SOURCE nodes.
64   Config_XMLReader::processNode(theNode);
65 }
66
67 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
68 {
69   return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
70 }
71
72 void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFtMessage)
73 {
74   outFtMessage.setId(getProperty(theRoot, _ID));
75   outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
76   outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
77   outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
78   outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
79   outFtMessage.setGroupId(myLastGroup);
80   outFtMessage.setWorkbenchId(myLastWorkbench);
81   outFtMessage.setPluginLibrary(myLibraryName);
82   outFtMessage.setNestedFeatures(getProperty(theRoot, FEATURE_NESTED));
83 }