]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Session.h
Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / ModelAPI / ModelAPI_Session.h
1 // File:        ModelAPI_Session.hxx
2 // Created:     20 Mar 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef ModelAPI_Session_H_
6 #define ModelAPI_Session_H_
7
8 #include "ModelAPI.h"
9 #include <string>
10 #include <list>
11 #include <boost/shared_ptr.hpp>
12
13 class ModelAPI_Feature;
14 class ModelAPI_Plugin;
15 class ModelAPI_Document;
16 class ModelAPI_ValidatorsFactory;
17
18 /**\class ModelAPI_Session
19  * \ingroup DataModel
20  * \brief Object that knows (from the initial XML file) which
21  * plugin contains which feature, loads and stores reference to loaded plugins by
22  * the feature functionality request.
23  */
24
25 class MODELAPI_EXPORT ModelAPI_Session
26 {
27  public:
28   /// Returns the real implementation (the alone instance per application) of the plugin manager
29   static boost::shared_ptr<ModelAPI_Session> get();
30
31   //! Loads the OCAF document from the file.
32   //! \param theFileName full name of the file to load
33   //! \param theStudyID identifier of the SALOME study to associate with loaded file
34   //! \returns true if file was loaded successfully
35   virtual bool load(const char* theFileName) = 0;
36
37   //! Saves the OCAF document to the file.
38   //! \param theFileName full name of the file to store
39   //! \param theResults the result full file names that were stored by "save"
40   //! \returns true if file was stored successfully
41   virtual bool save(const char* theFileName, std::list<std::string>& theResults) = 0;
42
43   //! Closes all documents
44   virtual void closeAll() = 0;
45
46   //! Starts a new operation (opens a tansaction)
47   virtual void startOperation() = 0;
48   //! Finishes the previously started operation (closes the transaction)
49   virtual void finishOperation() = 0;
50   //! Aborts the operation 
51   virtual void abortOperation() = 0;
52   //! Returns true if operation has been started, but not yet finished or aborted
53   virtual bool isOperation() = 0;
54   //! Returns true if document was modified (since creation/opening)
55   virtual bool isModified() = 0;
56
57   //! Returns True if there are available Undos
58   virtual bool canUndo() = 0;
59   //! Undoes last operation
60   virtual void undo() = 0;
61   //! Returns True if there are available Redos
62   virtual bool canRedo() = 0;
63   //! Redoes last operation
64   virtual void redo() = 0;
65
66   /// Registers the plugin that creates features.
67   /// It is obligatory for each plugin to call this function on loading to be found by 
68   /// the plugin manager on call of the feature)
69   virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
70
71   /// Returns the root document of the application (that may contains sub-documents)
72   virtual boost::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
73
74   /// Return true if root document has been already created
75   virtual bool hasModuleDocument() = 0;
76
77   /// Returns the current document that used for current work in the application
78   virtual boost::shared_ptr<ModelAPI_Document> activeDocument() = 0;
79
80   /// Defines the current document that used for current work in the application
81   virtual void setActiveDocument(
82     boost::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
83
84   /// Returns all the opened documents of the session (without postponed)
85   virtual std::list<boost::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
86
87   /// Copies the document to the new one with the given id
88   virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
89                                                     std::string theID) = 0;
90
91   /// Returns the validators factory: the only one instance per application
92   virtual ModelAPI_ValidatorsFactory* validators() = 0;
93
94   /// To virtually destroy the fields of successors
95   virtual ~ModelAPI_Session()
96   {
97   }
98
99  protected:
100   /// Creates the feature object using plugins functionality
101   virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
102
103   static void setSession(boost::shared_ptr<ModelAPI_Session> theManager);
104
105   friend class Model_Document;
106 };
107
108 typedef boost::shared_ptr<ModelAPI_Session> SessionPtr;
109
110 #endif