Salome HOME
Merge remote-tracking branch 'origin/Dev_0.6'
[modules/shaper.git] / src / Model / Model_Session.h
1 // File:        Model_Session.hxx
2 // Created:     20 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_Session_H_
6 #define Model_Session_H_
7
8 #include "Model.h"
9 #include <ModelAPI_Session.h>
10 #include <ModelAPI_Feature.h>
11
12 #include <Events_Listener.h>
13 #include <map>
14
15 class Model_Document;
16
17 /**\class Model_Session
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_Session : public ModelAPI_Session, public Events_Listener
24 {
25   bool myPluginsInfoLoaded;  ///< it true if plugins information is loaded
26   /// map of feature IDs to plugin name and document kind
27   std::map<std::string, std::pair<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   std::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
34   //! Loads the OCAF document from the file.
35   //! \param theFileName full name of the file to load
36   //! \param theStudyID identifier of the SALOME study to associate with loaded file
37   //! \returns true if file was loaded successfully
38   MODEL_EXPORT virtual bool load(const char* theFileName);
39
40   //! Saves the OCAF document to the file.
41   //! \param theFileName full name of the file to store
42   //! \param theResults the result full file names that were stored by "save"
43   //! \returns true if file was stored successfully
44   MODEL_EXPORT virtual bool save(const char* theFileName, std::list<std::string>& theResults);
45
46   //! Closes all documents
47   MODEL_EXPORT virtual void closeAll();
48
49   //! Starts a new operation (opens a tansaction)
50   MODEL_EXPORT virtual void startOperation();
51   //! Finishes the previously started operation (closes the transaction)
52   MODEL_EXPORT virtual void finishOperation();
53   //! Aborts the operation 
54   MODEL_EXPORT virtual void abortOperation();
55   //! Returns true if operation has been started, but not yet finished or aborted
56   MODEL_EXPORT virtual bool isOperation();
57   //! Returns true if document was modified (since creation/opening)
58   MODEL_EXPORT virtual bool isModified();
59
60   //! Returns True if there are available Undos
61   MODEL_EXPORT virtual bool canUndo();
62   //! Undoes last operation
63   MODEL_EXPORT virtual void undo();
64   //! Returns True if there are available Redos
65   MODEL_EXPORT virtual bool canRedo();
66   //! Redoes last operation
67   MODEL_EXPORT virtual void redo();
68
69   /// Returns the root document of the application (that may contains sub-documents)
70   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
71
72   /// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
73   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document(std::string theDocID);
74
75   /// Return true if root document has been already created
76   MODEL_EXPORT virtual bool hasModuleDocument();
77
78   /// Returns the current document that used for current work in the application
79   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> activeDocument();
80
81   /// Defines the current document that used for current work in the application
82   MODEL_EXPORT virtual void setActiveDocument(
83     std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true);
84
85   /// Returns all the opened documents of the session (without postponed)
86   MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
87
88   /// Registers the plugin that creates features.
89   /// It is obligatory for each plugin to call this function on loading to be found by 
90   /// the plugin manager on call of the feature)
91   MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
92
93   /// Processes the configuration file reading
94   MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
95
96   /// Copies the document to the new one wit hthe given id
97   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> copy(
98       std::shared_ptr<ModelAPI_Document> theSource, std::string theID);
99
100   /// Returns the validators factory: the only one instance per application
101   MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
102
103   void setCheckTransactions(const bool theCheck)
104   {
105     myCheckTransactions = theCheck;
106   }
107
108   /// Is called only once, on startup of the application
109   Model_Session();
110
111  protected:
112   /// Loads (if not done yet) the information about the features and plugins
113   void LoadPluginsInfo();
114
115   /// Creates the feature object using plugins functionality
116   virtual FeaturePtr createFeature(std::string theFeatureID);
117 };
118
119 #endif