Salome HOME
Issue #2612 : Re-calculate model after modification of parameters
[modules/shaper.git] / src / ModelAPI / ModelAPI_Session.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef ModelAPI_Session_H_
22 #define ModelAPI_Session_H_
23
24 #include "ModelAPI.h"
25 #include <string>
26 #include <list>
27 #include <memory>
28
29 class ModelAPI_Feature;
30 class ModelAPI_Plugin;
31 class ModelAPI_Document;
32 class ModelAPI_ValidatorsFactory;
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  public:
44   /// Returns the real implementation (the alone instance per application) of the plugin manager
45   static std::shared_ptr<ModelAPI_Session> get();
46
47   //! Loads the OCAF document from the file.
48   //! \param theFileName full name of the file to load
49   //! \returns true if file was loaded successfully
50   virtual bool load(const char* theFileName) = 0;
51
52   //! Saves the OCAF document to the file.
53   //! \param theFileName full name of the file to store
54   //! \param theResults the result full file names that were stored by "save"
55   //! \returns true if file was stored successfully
56   virtual bool save(const char* theFileName, std::list<std::string>& theResults) = 0;
57
58   //! Closes all documents
59   virtual void closeAll() = 0;
60
61   //! Starts a new operation (opens a transaction)
62   //! \param theId of operation for history (optional)
63   //! \param theAttachedToNested if it is true,
64   //!          it means that this transaction is attached to the nested
65   //!          where it is located and will be committed on the next commit with the nested
66   virtual void startOperation(
67     const std::string& theId = "", const bool theAttachedToNested = false) = 0;
68   //! Finishes the previously started operation (closes the transaction)
69   virtual void finishOperation() = 0;
70   //! Aborts the operation
71   virtual void abortOperation() = 0;
72   //! Returns true if operation has been started, but not yet finished or aborted
73   virtual bool isOperation() = 0;
74   //! Returns true if document was modified (since creation/opening)
75   virtual bool isModified() = 0;
76
77   //! Returns True if there are available Undos
78   virtual bool canUndo() = 0;
79   //! Undoes last operation
80   virtual void undo() = 0;
81   //! Returns True if there are available Redos
82   virtual bool canRedo() = 0;
83   //! Redoes last operation
84   virtual void redo() = 0;
85   //! Returns stack of performed operations (from last to first)
86   virtual std::list<std::string> undoList() = 0;
87   //! Returns stack of rolled back operations (from last rolled back to first)
88   virtual std::list<std::string> redoList() = 0;
89
90   /// Registers the plugin that creates features.
91   /// It is obligatory for each plugin to call this function on loading to be found by
92   /// the plugin manager on call of the feature)
93   virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
94
95   /// Returns the root document of the application (that may contains sub-documents)
96   virtual std::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
97
98   /// Returns the document by ID. Returns null if no such document.
99   virtual std::shared_ptr<ModelAPI_Document> document(int theDocID) = 0;
100
101   /// Return true if root document has been already created
102   virtual bool hasModuleDocument() = 0;
103
104   /// Returns the current document that used for current work in the application
105   virtual std::shared_ptr<ModelAPI_Document> activeDocument() = 0;
106
107   /// Defines the current document that used for current work in the application
108   virtual void setActiveDocument(
109     std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
110
111   /// Returns all the opened documents of the session (without postponed)
112   virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
113
114   /// Returns true if document is not loaded yet
115   virtual bool isLoadByDemand(const std::string theDocID, const int theDocIndex) = 0;
116
117   /// Copies the document to the new one with the given id
118   virtual std::shared_ptr<ModelAPI_Document> copy(
119     std::shared_ptr<ModelAPI_Document> theSource, const int theDestID) =0;
120
121   /// Returns the validators factory: the only one instance per application
122   virtual ModelAPI_ValidatorsFactory* validators() = 0;
123
124   /// To virtually destroy the fields of successors
125   virtual ~ModelAPI_Session()
126   {
127   }
128
129   /// Returns the global identifier of the current transaction (needed for the update algo)
130   virtual int transactionID() = 0;
131
132   /// Returns true if auto-update in the application is blocked
133   virtual bool isAutoUpdateBlocked() = 0;
134
135   /// Set state of the auto-update of features result in the application
136   virtual void blockAutoUpdate(const bool theBlock) = 0;
137
138  protected:
139   /// Sets the session interface implementation (once per application launch)
140   static void setSession(std::shared_ptr<ModelAPI_Session> theManager);
141 };
142
143 typedef std::shared_ptr<ModelAPI_Session> SessionPtr;
144
145 #endif