Salome HOME
Issue #2059 point in sketch is created not on selected line of external sketchPlane...
[modules/shaper.git] / src / Config / Config_ModuleReader.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_XMLModuleReader.h
5  *
6  *  Created on: Mar 20, 2014
7  *      Author: sbh
8  */
9
10 #ifndef CONFIG_MODULEREADER_H_
11 #define CONFIG_MODULEREADER_H_
12
13 #include <Config_def.h>
14 #include <Config_XMLReader.h>
15
16 #include <map>
17 #include <list>
18 #include <set>
19 #include <string>
20
21 /*!
22  * \class Config_ModuleReader
23  * \ingroup Config
24  * \brief Class to process plugins.xml - definition of plugins (scripts, libraries).
25  */
26 class Config_ModuleReader : public Config_XMLReader
27 {
28   enum PluginType {
29     Binary = 0,
30     Intrenal = 1,
31     Python = 2
32   };
33
34  public:
35   /// Constructor
36   CONFIG_EXPORT Config_ModuleReader(const char* theEventGenerated = 0);
37   /// Destructor
38   CONFIG_EXPORT virtual ~Config_ModuleReader();
39   /// Returns map that describes which file contains a feature
40   /// (the feature is key, the file is value)
41   CONFIG_EXPORT const std::map<std::string, std::string>& featuresInFiles() const;
42   /// Returns list of module's xml files
43   CONFIG_EXPORT const std::set<std::string>& modulePluginFiles() const;
44   /// Returns module name: an xml attribute from the root of the plugins.xml:
45   /// e.g \code <plugins module="PartSet"> \endcode
46   CONFIG_EXPORT std::string getModuleName();
47   /// Detects type of the given plugin and loads it using loadLibrary or loadScript.
48   CONFIG_EXPORT static void loadPlugin(const std::string& thePluginName);
49   /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform
50   CONFIG_EXPORT static void loadLibrary(const std::string& theLibName);
51   /// loads the python module with specified name
52   /// \param theFileName name of the script
53   /// \param theSendErr send error message in case of faile
54   CONFIG_EXPORT static void loadScript(const std::string& theFileName, bool theSendErr = true);
55   /*!
56    * Extends set of modules,  used for dependency checking (if there is no
57    * required module in the set, a plugin will not be loaded)
58    */
59   CONFIG_EXPORT static void addDependencyModule(const std::string& theModuleName);
60
61  protected:
62   /// Recursively process the given xmlNode
63   virtual void processNode(xmlNodePtr aNode);
64   /// Defines if the reader should process children of the given node
65   virtual bool processChildren(xmlNodePtr aNode);
66   /// check if dependencies of the given node are in the list of loaded modules
67   bool hasRequiredModules(xmlNodePtr aNode) const;
68   /// reads info about plugin's features from plugin xml description
69   std::list<std::string> importPlugin(const std::string& thePluginLibrary,
70                                       const std::string& thePluginFile);
71   /// stores information about plugin in the internal cache
72   std::string addPlugin(const std::string& aPluginLibrary,
73                         const std::string& aPluginScript,
74                         const std::string& aPluginConf);
75   /// Save feature in myFeaturesInFiles.
76   /// Generates an error if the feature name is already registered.
77   void addFeature(const std::string& theFeatureName, const std::string& thePluginConfig);
78
79  private:
80   std::map<std::string, std::string> myFeaturesInFiles; ///< a feature name is key, a file is value
81   std::set<std::string> myPluginFiles; ///< a feature name is key, a file is value
82   /// a plugin name is key, a plugin type is value
83   static std::map<std::string, PluginType> myPluginTypes;
84   static std::set<std::string> myDependencyModules; ///< set of loaded modules
85   const char* myEventGenerated; ///< gives ability to send Feature_Messages to various listeners
86 };
87
88 #endif /* CONFIG_XMLMODULEREADER_H_ */