Salome HOME
Merge branch 'master' of newgeom:newgeom
[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(boost::shared_ptr<ModelAPI_Document> theDoc) = 0;
79
80   /// Returns all the opened documents of the session (without postponed)
81   virtual std::list<boost::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
82
83   /// Copies the document to the new one with the given id
84   virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
85                                                     std::string theID) = 0;
86
87   /// Returns the validators factory: the only one instance per application
88   virtual ModelAPI_ValidatorsFactory* validators() = 0;
89
90   /// Is needed for python wrapping by swig, call Get to get an instance
91   ModelAPI_Session();
92
93   /// To virtually destroy the fields of successors
94   virtual ~ModelAPI_Session()
95   {
96   }
97
98  protected:
99   /// Creates the feature object using plugins functionality
100   virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
101
102   static void setSession(boost::shared_ptr<ModelAPI_Session> theManager);
103
104   friend class Model_Document;
105 };
106
107 typedef boost::shared_ptr<ModelAPI_Session> SessionPtr;
108
109 #endif