]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/ModelAPI_Session.h
Salome HOME
Merge remote-tracking branch 'origin/Dev_0.6'
[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 <memory>
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 std::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 std::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
73
74   /// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
75   virtual std::shared_ptr<ModelAPI_Document> document(std::string theDocID) = 0;
76
77   /// Return true if root document has been already created
78   virtual bool hasModuleDocument() = 0;
79
80   /// Returns the current document that used for current work in the application
81   virtual std::shared_ptr<ModelAPI_Document> activeDocument() = 0;
82
83   /// Defines the current document that used for current work in the application
84   virtual void setActiveDocument(
85     std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
86
87   /// Returns all the opened documents of the session (without postponed)
88   virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
89
90   /// Copies the document to the new one with the given id
91   virtual std::shared_ptr<ModelAPI_Document> copy(std::shared_ptr<ModelAPI_Document> theSource,
92                                                     std::string theID) = 0;
93
94   /// Returns the validators factory: the only one instance per application
95   virtual ModelAPI_ValidatorsFactory* validators() = 0;
96
97   /// Is needed for python wrapping by swig, call Get to get an instance
98   ModelAPI_Session();
99
100   /// To virtually destroy the fields of successors
101   virtual ~ModelAPI_Session()
102   {
103   }
104
105  protected:
106   /// Creates the feature object using plugins functionality
107   virtual std::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
108
109   static void setSession(std::shared_ptr<ModelAPI_Session> theManager);
110
111   friend class Model_Document;
112 };
113
114 typedef std::shared_ptr<ModelAPI_Session> SessionPtr;
115
116 #endif