Salome HOME
Advanced version of plugin reader with ability to extract xml information about featu...
[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 const static char* NODE_WORKBENCH = "workbench";
22 const static char* NODE_GROUP = "group";
23 const static char* NODE_FEATURE = "feature";
24
25 // * Properties
26 const static char* _ID = "id";
27 //const static char* WORKBENCH_ID = "id";
28 //const static char* GROUP_ID = "id";
29 //const static char* FEATURE_ID = "id";
30 const static char* FEATURE_TEXT = "text";
31 const static char* FEATURE_TOOLTIP = "tooltip";
32 const static char* FEATURE_ICON = "icon";
33 const static char* FEATURE_KEYSEQUENCE = "keysequence";
34
35
36 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile)
37     : Config_XMLReader(theXmlFile),
38       m_fetchWidgetCfg(false)
39 {
40   #ifdef _DEBUG
41   if(!Event_Loop::Loop()) {
42     std::cout << "Config_FeatureReader::importWorkbench: "
43         << "No event loop registered" << std::endl;
44   }
45   #endif
46 }
47
48 Config_FeatureReader::~Config_FeatureReader()
49 {
50 }
51
52 std::string Config_FeatureReader::featureWidgetCfg(std::string theFeatureName)
53 {
54   m_fetchWidgetCfg = true;
55   readAll();
56   m_fetchWidgetCfg = false;
57   return m_widgetCfg;
58 }
59
60 void Config_FeatureReader::processNode(xmlNodePtr theNode)
61 {
62   if(isNode(theNode, NODE_FEATURE, NULL)) {
63     if(m_fetchWidgetCfg) {
64       xmlBufferPtr buffer = xmlBufferCreate();
65       int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
66       m_widgetCfg = std::string((char*)buffer->content);
67     } else {
68       Event_Loop* aEvLoop = Event_Loop::Loop();
69       Config_FeatureMessage aMessage(aEvLoop->EventByName("menu_item"), this);
70       fillFeature(theNode, aMessage);
71       aEvLoop->Send(aMessage);
72     }
73   }
74   //The m_last* variables always defined before fillFeature() call. XML is a tree.
75   if(isNode(theNode, NODE_GROUP, NULL)) {
76     m_lastGroup = getProperty(theNode, _ID);
77   }
78   if(isNode(theNode, NODE_WORKBENCH, NULL)) {
79     m_lastWorkbench = getProperty(theNode, _ID);
80   }
81 }
82
83 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
84 {
85   return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
86 }
87
88 void Config_FeatureReader::fillFeature(xmlNodePtr theRoot,
89                                        Config_FeatureMessage& outFtMessage)
90 {
91   outFtMessage.setId(getProperty(theRoot, _ID));
92   outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
93   outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
94   outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
95   outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
96   outFtMessage.setGroupId(m_lastGroup);
97   outFtMessage.setWorkbenchId(m_lastWorkbench);
98
99 }