]> SALOME platform Git repositories - modules/shaper.git/blob - src/Config/Config_FeatureReader.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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.h>
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 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile)
36     : Config_XMLReader(theXmlFile),
37       myFetchWidgetCfg(false)
38 {
39   myLibraryName = "";
40
41 #ifdef _DEBUG
42   if (!Event_Loop::loop()) {
43     std::cout << "Config_FeatureReader::importWorkbench: "
44         << "No event loop registered" << std::endl;
45   }
46 #endif
47 }
48
49 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
50                                            const std::string& theLibraryName)
51     : Config_XMLReader(theXmlFile),
52       myLibraryName(theLibraryName),
53       myFetchWidgetCfg(false)
54 {
55 #ifdef _DEBUG
56   if (!Event_Loop::loop()) {
57     std::cout << "Config_FeatureReader::importWorkbench: "
58         << "No event loop registered" << std::endl;
59   }
60 #endif
61 }
62
63 Config_FeatureReader::~Config_FeatureReader()
64 {
65 }
66
67 std::string Config_FeatureReader::featureWidgetCfg(std::string theFeatureName)
68 {
69   myFetchWidgetCfg = true;
70   readAll();
71   myFetchWidgetCfg = false;
72   return myWidgetCfg;
73 }
74
75 void Config_FeatureReader::processNode(xmlNodePtr theNode)
76 {
77   static Event_ID aMenuItemEvent = Event_Loop::eventByName("RegisterFeature");
78   if (isNode(theNode, NODE_FEATURE, NULL)) {
79     if (myFetchWidgetCfg) {
80       xmlBufferPtr buffer = xmlBufferCreate();
81       int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
82       myWidgetCfg = std::string((char*) buffer->content);
83     } else {
84       Event_Loop* aEvLoop = Event_Loop::loop();
85       Config_FeatureMessage aMessage(aMenuItemEvent, this);
86       fillFeature(theNode, aMessage);
87       aEvLoop->send(aMessage);
88     }
89   }
90   //The m_last* variables always defined before fillFeature() call. XML is a tree.
91   if (isNode(theNode, NODE_GROUP, NULL)) {
92     myLastGroup = getProperty(theNode, _ID);
93   }
94   if (isNode(theNode, NODE_WORKBENCH, NULL)) {
95     myLastWorkbench = getProperty(theNode, _ID);
96   }
97 }
98
99 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
100 {
101   return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
102 }
103
104 void Config_FeatureReader::fillFeature(xmlNodePtr theRoot, Config_FeatureMessage& outFtMessage)
105 {
106   outFtMessage.setId(getProperty(theRoot, _ID));
107   outFtMessage.setText(getProperty(theRoot, FEATURE_TEXT));
108   outFtMessage.setTooltip(getProperty(theRoot, FEATURE_TOOLTIP));
109   outFtMessage.setIcon(getProperty(theRoot, FEATURE_ICON));
110   outFtMessage.setKeysequence(getProperty(theRoot, FEATURE_KEYSEQUENCE));
111   outFtMessage.setGroupId(myLastGroup);
112   outFtMessage.setWorkbenchId(myLastWorkbench);
113   outFtMessage.setPluginLibrary(myLibraryName);
114 }