Salome HOME
Merge with PythonAPI branch
[modules/shaper.git] / src / ModelAPI / ModelAPI_Session.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_Session.hxx
4 // Created:     20 Mar 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef ModelAPI_Session_H_
8 #define ModelAPI_Session_H_
9
10 #include "ModelAPI.h"
11 #include <string>
12 #include <list>
13 #include <memory>
14
15 class ModelAPI_Feature;
16 class ModelAPI_Plugin;
17 class ModelAPI_Document;
18 class ModelAPI_ValidatorsFactory;
19
20 /**\class ModelAPI_Session
21  * \ingroup DataModel
22  * \brief Object that knows (from the initial XML file) which
23  * plugin contains which feature, loads and stores reference to loaded plugins by
24  * the feature functionality request.
25  */
26
27 class MODELAPI_EXPORT ModelAPI_Session
28 {
29  public:
30   /// Returns the real implementation (the alone instance per application) of the plugin manager
31   static std::shared_ptr<ModelAPI_Session> get();
32
33   //! Loads the OCAF document from the file.
34   //! \param theFileName full name of the file to load
35   //! \returns true if file was loaded successfully
36   virtual bool load(const char* theFileName) = 0;
37
38   //! Saves the OCAF document to the file.
39   //! \param theFileName full name of the file to store
40   //! \param theResults the result full file names that were stored by "save"
41   //! \returns true if file was stored successfully
42   virtual bool save(const char* theFileName, std::list<std::string>& theResults) = 0;
43
44   //! Closes all documents
45   virtual void closeAll() = 0;
46
47   //! Starts a new operation (opens a transaction)
48   //! \param theId of operation for history (optional)
49   //! \param theAttachedToNested if it is true, it means that this transaction is attached to the nested 
50   //!          where it is located and will be committed on the next commit with the nested
51   virtual void startOperation(
52     const std::string& theId = "", const bool theAttachedToNested = false) = 0;
53   //! Finishes the previously started operation (closes the transaction)
54   virtual void finishOperation() = 0;
55   //! Aborts the operation 
56   virtual void abortOperation() = 0;
57   //! Returns true if operation has been started, but not yet finished or aborted
58   virtual bool isOperation() = 0;
59   //! Returns true if document was modified (since creation/opening)
60   virtual bool isModified() = 0;
61
62   //! Returns True if there are available Undos
63   virtual bool canUndo() = 0;
64   //! Undoes last operation
65   virtual void undo() = 0;
66   //! Returns True if there are available Redos
67   virtual bool canRedo() = 0;
68   //! Redoes last operation
69   virtual void redo() = 0;
70   //! Returns stack of performed operations (from last to first)
71   virtual std::list<std::string> undoList() = 0;
72   //! Returns stack of rolled back operations (from last rolled back to first)
73   virtual std::list<std::string> redoList() = 0;
74
75   /// Registers the plugin that creates features.
76   /// It is obligatory for each plugin to call this function on loading to be found by 
77   /// the plugin manager on call of the feature)
78   virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
79
80   /// Returns the root document of the application (that may contains sub-documents)
81   virtual std::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
82
83   /// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
84   virtual std::shared_ptr<ModelAPI_Document> document(std::string theDocID) = 0;
85
86   /// Return true if root document has been already created
87   virtual bool hasModuleDocument() = 0;
88
89   /// Returns the current document that used for current work in the application
90   virtual std::shared_ptr<ModelAPI_Document> activeDocument() = 0;
91
92   /// Defines the current document that used for current work in the application
93   virtual void setActiveDocument(
94     std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
95
96   /// Returns all the opened documents of the session (without postponed)
97   virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
98
99   /// Returns true if document is not loaded yet
100   virtual bool isLoadByDemand(const std::string theDocID) = 0;
101
102   /// Copies the document to the new one with the given id
103   virtual std::shared_ptr<ModelAPI_Document> copy(std::shared_ptr<ModelAPI_Document> theSource,
104                                                     std::string theID) = 0;
105
106   /// Returns the validators factory: the only one instance per application
107   virtual ModelAPI_ValidatorsFactory* validators() = 0;
108
109   /// To virtually destroy the fields of successors
110   virtual ~ModelAPI_Session()
111   {
112   }
113
114   /// Returns the global identifier of the current transaction (needed for the update algo)
115   virtual int transactionID() = 0;
116
117  protected:
118   /// Sets the session interface implementation (once per application launch)
119   static void setSession(std::shared_ptr<ModelAPI_Session> theManager);
120 };
121
122 typedef std::shared_ptr<ModelAPI_Session> SessionPtr;
123
124 #endif