SHAPER 9.16.0
Model_Session.h
1// Copyright (C) 2014-2026 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 Model_Session_H_
21#define Model_Session_H_
22
23#include "Model.h"
24#include <ModelAPI_Session.h>
25#include <ModelAPI_Feature.h>
26
27#include <Events_Listener.h>
28#include <map>
29
30#ifdef TINSPECTOR
31#include <TDocStd_Application.hxx>
32#endif
33
34class Model_Document;
35
43{
44 bool myPluginsInfoLoaded;
46 std::map<std::string, std::pair<std::string, std::string> > myPlugins;
47 std::map<std::string, ModelAPI_Plugin*> myPluginObjs;
48 std::string myCurrentPluginName;
49 std::shared_ptr<ModelAPI_Document> myCurrentDoc;
51 std::map<std::string, std::string> myUsePlugins;
52
54 bool myCheckTransactions;
57 std::list<bool> myOperationAttachedToNext;
58 public:
59
63 MODEL_EXPORT virtual bool load(const char* theFileName);
64
69 MODEL_EXPORT virtual bool save(const char* theFileName, std::list<std::string>& theResults, bool doBackup=false);
70
72 MODEL_EXPORT virtual void closeAll();
73
79 MODEL_EXPORT virtual void startOperation(
80 const std::string& theId = "", const bool theAttachedToNested = false);
82 MODEL_EXPORT virtual void finishOperation();
84 MODEL_EXPORT virtual void abortOperation();
86 MODEL_EXPORT virtual bool isOperation();
88 MODEL_EXPORT virtual bool isModified();
89
91 MODEL_EXPORT virtual bool canUndo();
93 MODEL_EXPORT virtual void undo();
95 MODEL_EXPORT virtual bool canRedo();
97 MODEL_EXPORT virtual void redo();
99 MODEL_EXPORT virtual std::list<std::string> undoList();
101 MODEL_EXPORT virtual std::list<std::string> redoList();
103 MODEL_EXPORT virtual void clearUndoRedo();
104
106 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
107
109 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document(int theDocID);
110
112 MODEL_EXPORT virtual bool hasModuleDocument();
113
115 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> activeDocument();
116
118 MODEL_EXPORT virtual void setActiveDocument(
119 std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true);
120
122 MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
123
125 MODEL_EXPORT virtual bool isLoadByDemand(const std::wstring theDocID, const int theDocIndex);
126
130 MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
131
133 MODEL_EXPORT virtual bool checkLicense(const std::string& thePluginName);
134
136 MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
137
139 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> copy(
140 std::shared_ptr<ModelAPI_Document> theSource, const int theDestID);
141
143 MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
144
146 MODEL_EXPORT virtual ModelAPI_FiltersFactory* filters();
147
149 void setCheckTransactions(const bool theCheck)
150 {
151 myCheckTransactions = theCheck;
152 }
153
156
158 MODEL_EXPORT virtual int transactionID();
159
160
162 MODEL_EXPORT virtual bool isAutoUpdateBlocked();
163
165 MODEL_EXPORT virtual void blockAutoUpdate(const bool theBlock);
166
167#ifdef TINSPECTOR
168 MODEL_EXPORT virtual Handle(TDocStd_Application) application();
169#endif
170
171 protected:
173 void LoadPluginsInfo();
174
176 FeaturePtr createFeature(std::string theFeatureID, Model_Document* theDocOwner);
177
179 ModelAPI_Plugin* getPlugin(const std::string& thePluginName);
180
181 friend class Model_Document;
182 friend class Model_Objects;
183};
184
185#endif
Base interface for any event listener.
Definition: Events_Listener.h:37
Manages registering of filters.
Definition: ModelAPI_FiltersFactory.h:35
Interface common for any plugin: allows to use plugin by the plugins manager.
Definition: ModelAPI_Plugin.h:34
Object that knows (from the initial XML file) which plugin contains which feature,...
Definition: ModelAPI_Session.h:42
Manages the registered validators.
Definition: ModelAPI_Validator.h:66
Document for internal data structure of any object storage.
Definition: Model_Document.h:45
Manager of objects of the document.
Definition: Model_Objects.h:46
Object that knows (from the initial XML file) which plugin contains which feature,...
Definition: Model_Session.h:43
virtual std::shared_ptr< ModelAPI_Document > copy(std::shared_ptr< ModelAPI_Document > theSource, const int theDestID)
Copies the document to the new one.
Definition: Model_Session.cpp:390
virtual bool hasModuleDocument()
Return true if root document has been already created.
Definition: Model_Session.cpp:283
Model_Session()
Is called only once, on startup of the application.
Definition: Model_Session.cpp:454
void setCheckTransactions(const bool theCheck)
Sets the flag to check modifications outside the transaction or not.
Definition: Model_Session.h:149
virtual void redo()
Redoes last operation.
Definition: Model_Session.cpp:166
virtual void closeAll()
Closes all documents.
Definition: Model_Session.cpp:74
virtual bool canUndo()
Returns True if there are available Undos.
Definition: Model_Session.cpp:149
virtual std::shared_ptr< ModelAPI_Document > activeDocument()
Returns the current document that used for current work in the application.
Definition: Model_Session.cpp:288
virtual void registerPlugin(ModelAPI_Plugin *thePlugin)
Registers the plugin that creates features.
Definition: Model_Session.cpp:615
ModelAPI_Plugin * getPlugin(const std::string &thePluginName)
Get the plugin by name. If it is not loaded, load plugin.
Definition: Model_Session.cpp:194
virtual std::list< std::shared_ptr< ModelAPI_Document > > allOpenedDocuments()
Returns all the opened documents of the session (without postponed)
Definition: Model_Session.cpp:365
virtual bool isModified()
Returns true if document was modified (since creation/opening)
Definition: Model_Session.cpp:144
virtual std::shared_ptr< ModelAPI_Document > moduleDocument()
Returns the root document of the application (that may contains sub-documents)
Definition: Model_Session.cpp:253
virtual std::list< std::string > redoList()
Returns stack of rolled back operations.
Definition: Model_Session.cpp:179
virtual bool save(const char *theFileName, std::list< std::string > &theResults, bool doBackup=false)
Saves the OCAF document to the file.
Definition: Model_Session.cpp:69
FeaturePtr createFeature(std::string theFeatureID, Model_Document *theDocOwner)
Creates the feature object using plugins functionality.
Definition: Model_Session.cpp:217
virtual void undo()
Undoes last operation.
Definition: Model_Session.cpp:154
virtual void startOperation(const std::string &theId="", const bool theAttachedToNested=false)
Starts a new operation (opens a transaction)
Definition: Model_Session.cpp:84
virtual void processEvent(const std::shared_ptr< Events_Message > &theMessage)
Processes the configuration file reading.
Definition: Model_Session.cpp:472
virtual bool canRedo()
Returns True if there are available Redos.
Definition: Model_Session.cpp:161
virtual bool isLoadByDemand(const std::wstring theDocID, const int theDocIndex)
Returns true if document is not loaded yet.
Definition: Model_Session.cpp:385
virtual void abortOperation()
Aborts the operation.
Definition: Model_Session.cpp:115
virtual void setActiveDocument(std::shared_ptr< ModelAPI_Document > theDoc, bool theSendSignal=true)
Defines the current document that used for current work in the application.
Definition: Model_Session.cpp:313
virtual void finishOperation()
Finishes the previously started operation (closes the transaction)
Definition: Model_Session.cpp:100
virtual bool checkLicense(const std::string &thePluginName)
Verifies the license for the plugin is valid.
Definition: Model_Session.cpp:189
void LoadPluginsInfo()
Loads (if not done yet) the information about the features and plugins.
Definition: Model_Session.cpp:599
virtual ModelAPI_ValidatorsFactory * validators()
Returns the validators factory: the only one instance per application.
Definition: Model_Session.cpp:630
virtual bool isAutoUpdateBlocked()
Returns true if auto-update in the application is blocked.
Definition: Model_Session.cpp:647
virtual std::list< std::string > undoList()
Returns stack of performed operations.
Definition: Model_Session.cpp:174
virtual ModelAPI_FiltersFactory * filters()
Returns the filters factory: the only one instance per application.
Definition: Model_Session.cpp:636
virtual void clearUndoRedo()
Clears undo and redo lists of all documents in the session.
Definition: Model_Session.cpp:184
virtual std::shared_ptr< ModelAPI_Document > document(int theDocID)
Returns the document by ID, loads if not loaded yet. Returns null if no such document.
Definition: Model_Session.cpp:277
virtual void blockAutoUpdate(const bool theBlock)
Set state of the auto-update of features result in the application.
Definition: Model_Session.cpp:655
virtual int transactionID()
Returns the global identifier of the current transaction (needed for the update algo)
Definition: Model_Session.cpp:642
virtual bool isOperation()
Returns true if operation has been started, but not yet finished or aborted.
Definition: Model_Session.cpp:139
virtual bool load(const char *theFileName)
Loads the OCAF document from the file.
Definition: Model_Session.cpp:61