Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / Model / Model_PluginManager.h
1 // File:        Model_PluginManager.hxx
2 // Created:     20 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_PluginManager_HeaderFile
6 #define Model_PluginManager_HeaderFile
7
8 #include "Model.h"
9 #include <ModelAPI_PluginManager.h>
10 #include <ModelAPI_Feature.h>
11
12 #include <Events_Listener.h>
13 #include <map>
14
15 class Model_Document;
16
17 /**\class Model_PluginManager
18  * \ingroup DataModel
19  * \brief Object that knows (from the initial XML file) which
20  * plugin contains which feature, loads and stores reference to loaded plugins by
21  * the feature functionality request.
22  */
23 class Model_PluginManager : public ModelAPI_PluginManager, public Events_Listener
24 {
25   bool myPluginsInfoLoaded; ///< it true if plugins information is loaded
26   /// map of feature IDs to plugin name
27   std::map<std::string, std::string> myPlugins;
28   std::map<std::string, ModelAPI_Plugin*> myPluginObjs; ///< instances of the already plugins
29   std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently
30   boost::shared_ptr<ModelAPI_Document> myCurrentDoc; ///< current working document
31   bool myCheckTransactions; ///< if true, generates error if document is updated outside of transaction
32 public:
33   /// Returns the root document of the application (that may contains sub-documents)
34   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> rootDocument();
35
36   /// Return true if root document has been already created
37   MODEL_EXPORT virtual bool hasRootDocument();
38
39   /// Returns the current document that used for current work in the application
40   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> currentDocument();
41
42   /// Defines the current document that used for current work in the application
43   MODEL_EXPORT virtual void setCurrentDocument(boost::shared_ptr<ModelAPI_Document> theDoc);
44
45   /// Registers the plugin that creates features.
46   /// It is obligatory for each plugin to call this function on loading to be found by 
47   /// the plugin manager on call of the feature)
48   MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
49
50   /// Processes the configuration file reading
51   MODEL_EXPORT virtual void processEvent(const Events_Message* theMessage);
52
53   /// Copies the document to the new one wit hthe given id
54   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_Document> copy(
55     boost::shared_ptr<ModelAPI_Document> theSource, std::string theID);
56
57   /// Returns the validators factory: the only one instance per application
58   MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
59
60   void setCheckTransactions(const bool theCheck) {myCheckTransactions = theCheck;}
61
62   /// Is called only once, on startup of the application
63   Model_PluginManager();
64
65 protected:
66   /// Loads (if not done yet) the information about the features and plugins
67   void LoadPluginsInfo();
68
69   /// Creates the feature object using plugins functionality
70   virtual FeaturePtr createFeature(std::string theFeatureID);
71 };
72
73 #endif