Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / Config / Config_ModuleReader.cpp
1 /*
2  * Config_ModuleReader.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_ModuleReader.h>
11 #include <Config_FeatureReader.h>
12
13 #include <libxml/parser.h>
14 #include <libxml/tree.h>
15
16 #ifdef _DEBUG
17 #include <iostream>
18 #endif
19
20
21
22 Config_ModuleReader::Config_ModuleReader(const char* theEventGenerated)
23     : Config_XMLReader("plugins.xml"), myIsAutoImport(false), myEventGenerated(theEventGenerated)
24 {
25 }
26
27 Config_ModuleReader::~Config_ModuleReader()
28 {
29 }
30
31 /*
32  * Get module name from plugins.xml
33  * (property "module")
34  */
35 std::string Config_ModuleReader::getModuleName()
36 {
37   xmlNodePtr aRoot = findRoot();
38   return getProperty(aRoot, PLUGINS_MODULE);
39 }
40
41 /*
42  *
43  */
44 void Config_ModuleReader::processNode(xmlNodePtr theNode)
45 {
46   if (isNode(theNode, NODE_PLUGIN, NULL)) {
47     std::string aPluginConf = getProperty(theNode, PLUGIN_CONFIG);
48     std::string aPluginLibrary = getProperty(theNode, PLUGIN_LIBRARY);
49     if (myIsAutoImport)
50       importPlugin(aPluginConf, aPluginLibrary);
51     myPluginsMap[aPluginLibrary] = aPluginConf;
52   }
53 }
54
55 bool Config_ModuleReader::processChildren(xmlNodePtr theNode)
56 {
57   return isNode(theNode, NODE_PLUGINS, NULL);
58 }
59
60 void Config_ModuleReader::importPlugin(const std::string& thePluginName,
61                                        const std::string& thePluginLibrary)
62 {
63   Config_FeatureReader* aReader;
64   if(thePluginLibrary.empty()) {
65     aReader = new Config_FeatureReader(thePluginName);
66   } else {
67     aReader = new Config_FeatureReader(thePluginName, thePluginLibrary, myEventGenerated);
68   }
69   aReader->readAll();
70 }
71
72 void Config_ModuleReader::setAutoImport(bool theEnabled)
73 {
74   myIsAutoImport = theEnabled;
75 }
76
77 const std::map<std::string, std::string>& Config_ModuleReader::plugins() const
78 {
79   return myPluginsMap;
80 }