Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelAPI / ModelAPI_Session.h
1 // Copyright (C) 2014-2023  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModelAPI_Session_H_
21 #define ModelAPI_Session_H_
22
23 #include "ModelAPI.h"
24 #include <string>
25 #include <list>
26 #include <memory>
27
28 class ModelAPI_Feature;
29 class ModelAPI_Plugin;
30 class ModelAPI_Document;
31 class ModelAPI_ValidatorsFactory;
32 class ModelAPI_FiltersFactory;
33
34 /**\class ModelAPI_Session
35  * \ingroup DataModel
36  * \brief Object that knows (from the initial XML file) which
37  * plugin contains which feature, loads and stores reference to loaded plugins by
38  * the feature functionality request.
39  */
40
41 class MODELAPI_EXPORT ModelAPI_Session
42 {
43 protected:
44   bool myIsLoading; ///< keeps the state of the loading of the document
45
46  public:
47   /// Returns the real implementation (the alone instance per application) of the plugin manager
48   static std::shared_ptr<ModelAPI_Session> get();
49
50   //! Loads the OCAF document from the file.
51   //! \param theFileName full name of the file to load
52   //! \returns true if file was loaded successfully
53   virtual bool load(const char* theFileName) = 0;
54
55   //! Returns true if a loading process is performed (so, no need to react on a new part creation)
56   virtual bool isLoading() { return myIsLoading; };
57
58   //! Saves the OCAF document to the file.
59   //! \param theFileName full name of the file to store
60   //! \param theResults the result full file names that were stored by "save"
61   //! \returns true if file was stored successfully
62   virtual bool save(const char* theFileName, std::list<std::string>& theResults) = 0;
63
64   //! Closes all documents
65   virtual void closeAll() = 0;
66
67   //! Starts a new operation (opens a transaction)
68   //! \param theId of operation for history (optional)
69   //! \param theAttachedToNested if it is true,
70   //!          it means that this transaction is attached to the nested
71   //!          where it is located and will be committed on the next commit with the nested
72   virtual void startOperation(
73     const std::string& theId = "", const bool theAttachedToNested = false) = 0;
74   //! Finishes the previously started operation (closes the transaction)
75   virtual void finishOperation() = 0;
76   //! Aborts the operation
77   virtual void abortOperation() = 0;
78   //! Returns true if operation has been started, but not yet finished or aborted
79   virtual bool isOperation() = 0;
80   //! Returns true if document was modified (since creation/opening)
81   virtual bool isModified() = 0;
82
83   //! Returns True if there are available Undos
84   virtual bool canUndo() = 0;
85   //! Undoes last operation
86   virtual void undo() = 0;
87   //! Returns True if there are available Redos
88   virtual bool canRedo() = 0;
89   //! Redoes last operation
90   virtual void redo() = 0;
91   //! Returns stack of performed operations (from last to first)
92   virtual std::list<std::string> undoList() = 0;
93   //! Returns stack of rolled back operations (from last rolled back to first)
94   virtual std::list<std::string> redoList() = 0;
95   //! Clears undo and redo lists of all documents in the session
96   virtual void clearUndoRedo() = 0;
97
98   /// Registers the plugin that creates features.
99   /// It is obligatory for each plugin to call this function on loading to be found by
100   /// the plugin manager on call of the feature)
101   virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
102
103   /// Verifies the license for the plugin is valid
104   virtual bool checkLicense(const std::string& thePluginName) = 0;
105
106   /// Returns the root document of the application (that may contains sub-documents)
107   virtual std::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
108
109   /// Returns the document by ID. Returns null if no such document.
110   virtual std::shared_ptr<ModelAPI_Document> document(int theDocID) = 0;
111
112   /// Return true if root document has been already created
113   virtual bool hasModuleDocument() = 0;
114
115   /// Returns the current document that used for current work in the application
116   virtual std::shared_ptr<ModelAPI_Document> activeDocument() = 0;
117
118   /// Defines the current document that used for current work in the application
119   virtual void setActiveDocument(
120     std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
121
122   /// Returns all the opened documents of the session (without postponed)
123   virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
124
125   /// Returns true if document is not loaded yet
126   virtual bool isLoadByDemand(const std::wstring theDocID, const int theDocIndex) = 0;
127
128   /// Copies the document to the new one with the given id
129   virtual std::shared_ptr<ModelAPI_Document> copy(
130     std::shared_ptr<ModelAPI_Document> theSource, const int theDestID) =0;
131
132   /// Returns the validators factory: the only one instance per application
133   virtual ModelAPI_ValidatorsFactory* validators() = 0;
134
135   /// Returns the filters factory: the only one instance per application
136   virtual ModelAPI_FiltersFactory* filters() = 0;
137
138   /// To virtually destroy the fields of successors
139   virtual ~ModelAPI_Session()
140   {
141   }
142
143   /// Returns the global identifier of the current transaction (needed for the update algo)
144   virtual int transactionID() = 0;
145
146   /// Returns true if auto-update in the application is blocked
147   virtual bool isAutoUpdateBlocked() = 0;
148
149   /// Set state of the auto-update of features result in the application
150   virtual void blockAutoUpdate(const bool theBlock) = 0;
151
152  protected:
153   /// Sets the session interface implementation (once per application launch)
154   static void setSession(std::shared_ptr<ModelAPI_Session> theManager);
155 };
156
157 typedef std::shared_ptr<ModelAPI_Session> SessionPtr;
158
159 #endif