1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModelAPI_Session_H_
21 #define ModelAPI_Session_H_
29 #include <Standard_Handle.hxx>
30 #include <TDocStd_Application.hxx>
33 class ModelAPI_Feature;
34 class ModelAPI_Plugin;
35 class ModelAPI_Document;
36 class ModelAPI_ValidatorsFactory;
37 class ModelAPI_FiltersFactory;
39 /**\class ModelAPI_Session
41 * \brief Object that knows (from the initial XML file) which
42 * plugin contains which feature, loads and stores reference to loaded plugins by
43 * the feature functionality request.
46 class MODELAPI_EXPORT ModelAPI_Session
49 /// Returns the real implementation (the alone instance per application) of the plugin manager
50 static std::shared_ptr<ModelAPI_Session> get();
52 //! Loads the OCAF document from the file.
53 //! \param theFileName full name of the file to load
54 //! \returns true if file was loaded successfully
55 virtual bool load(const char* theFileName) = 0;
57 //! Saves the OCAF document to the file.
58 //! \param theFileName full name of the file to store
59 //! \param theResults the result full file names that were stored by "save"
60 //! \returns true if file was stored successfully
61 virtual bool save(const char* theFileName, std::list<std::string>& theResults) = 0;
63 //! Closes all documents
64 virtual void closeAll() = 0;
66 //! Starts a new operation (opens a transaction)
67 //! \param theId of operation for history (optional)
68 //! \param theAttachedToNested if it is true,
69 //! it means that this transaction is attached to the nested
70 //! where it is located and will be committed on the next commit with the nested
71 virtual void startOperation(
72 const std::string& theId = "", const bool theAttachedToNested = false) = 0;
73 //! Finishes the previously started operation (closes the transaction)
74 virtual void finishOperation() = 0;
75 //! Aborts the operation
76 virtual void abortOperation() = 0;
77 //! Returns true if operation has been started, but not yet finished or aborted
78 virtual bool isOperation() = 0;
79 //! Returns true if document was modified (since creation/opening)
80 virtual bool isModified() = 0;
82 //! Returns True if there are available Undos
83 virtual bool canUndo() = 0;
84 //! Undoes last operation
85 virtual void undo() = 0;
86 //! Returns True if there are available Redos
87 virtual bool canRedo() = 0;
88 //! Redoes last operation
89 virtual void redo() = 0;
90 //! Returns stack of performed operations (from last to first)
91 virtual std::list<std::string> undoList() = 0;
92 //! Returns stack of rolled back operations (from last rolled back to first)
93 virtual std::list<std::string> redoList() = 0;
95 /// Registers the plugin that creates features.
96 /// It is obligatory for each plugin to call this function on loading to be found by
97 /// the plugin manager on call of the feature)
98 virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
100 /// Verifies the license for the plugin is valid
101 virtual bool checkLicense(const std::string& thePluginName) = 0;
103 /// Returns the root document of the application (that may contains sub-documents)
104 virtual std::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
106 /// Returns the document by ID. Returns null if no such document.
107 virtual std::shared_ptr<ModelAPI_Document> document(int theDocID) = 0;
109 /// Return true if root document has been already created
110 virtual bool hasModuleDocument() = 0;
112 /// Returns the current document that used for current work in the application
113 virtual std::shared_ptr<ModelAPI_Document> activeDocument() = 0;
115 /// Defines the current document that used for current work in the application
116 virtual void setActiveDocument(
117 std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
119 /// Returns all the opened documents of the session (without postponed)
120 virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
122 /// Returns true if document is not loaded yet
123 virtual bool isLoadByDemand(const std::wstring theDocID, const int theDocIndex) = 0;
125 /// Copies the document to the new one with the given id
126 virtual std::shared_ptr<ModelAPI_Document> copy(
127 std::shared_ptr<ModelAPI_Document> theSource, const int theDestID) =0;
129 /// Returns the validators factory: the only one instance per application
130 virtual ModelAPI_ValidatorsFactory* validators() = 0;
132 /// Returns the filters factory: the only one instance per application
133 virtual ModelAPI_FiltersFactory* filters() = 0;
135 /// To virtually destroy the fields of successors
136 virtual ~ModelAPI_Session()
140 /// Returns the global identifier of the current transaction (needed for the update algo)
141 virtual int transactionID() = 0;
143 /// Returns true if auto-update in the application is blocked
144 virtual bool isAutoUpdateBlocked() = 0;
146 /// Set state of the auto-update of features result in the application
147 virtual void blockAutoUpdate(const bool theBlock) = 0;
150 virtual Handle(TDocStd_Application) application() = 0;
154 /// Sets the session interface implementation (once per application launch)
155 static void setSession(std::shared_ptr<ModelAPI_Session> theManager);
158 typedef std::shared_ptr<ModelAPI_Session> SessionPtr;