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