Salome HOME
c97105421512fd83b16efbab28bdd012501b3666
[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   //! Starts a new operation (opens a tansaction)
44   virtual void startOperation() = 0;
45   //! Finishes the previously started operation (closes the transaction)
46   virtual void finishOperation() = 0;
47   //! Aborts the operation 
48   virtual void abortOperation() = 0;
49   //! Returns true if operation has been started, but not yet finished or aborted
50   virtual bool isOperation() = 0;
51   //! Returns true if document was modified (since creation/opening)
52   virtual bool isModified() = 0;
53
54   //! Returns True if there are available Undos
55   virtual bool canUndo() = 0;
56   //! Undoes last operation
57   virtual void undo() = 0;
58   //! Returns True if there are available Redos
59   virtual bool canRedo() = 0;
60   //! Redoes last operation
61   virtual void redo() = 0;
62
63   /// Registers the plugin that creates features.
64   /// It is obligatory for each plugin to call this function on loading to be found by 
65   /// the plugin manager on call of the feature)
66   virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
67
68   /// Returns the root document of the application (that may contains sub-documents)
69   virtual boost::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
70
71   /// Return true if root document has been already created
72   virtual bool hasModuleDocument() = 0;
73
74   /// Returns the current document that used for current work in the application
75   virtual boost::shared_ptr<ModelAPI_Document> activeDocument() = 0;
76
77   /// Defines the current document that used for current work in the application
78   virtual void setActiveDocument(
79     boost::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
80
81   /// Returns all the opened documents of the session (without postponed)
82   virtual std::list<boost::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
83
84   /// Copies the document to the new one with the given id
85   virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
86                                                     std::string theID) = 0;
87
88   /// Returns the validators factory: the only one instance per application
89   virtual ModelAPI_ValidatorsFactory* validators() = 0;
90
91   /// Is needed for python wrapping by swig, call Get to get an instance
92   ModelAPI_Session();
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