SHAPER  9.12.0
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
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 or email :
18 //
20 #ifndef Model_Session_H_
21 #define Model_Session_H_
23 #include "Model.h"
24 #include <ModelAPI_Session.h>
25 #include <ModelAPI_Feature.h>
27 #include <Events_Listener.h>
28 #include <map>
30 #ifdef TINSPECTOR
31 #include <TDocStd_Application.hxx>
32 #endif
34 class Model_Document;
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;
54  bool myCheckTransactions;
57  std::list<bool> myOperationAttachedToNext;
58  public:
63  MODEL_EXPORT virtual bool load(const char* theFileName);
69  MODEL_EXPORT virtual bool save(const char* theFileName, std::list<std::string>& theResults);
72  MODEL_EXPORT virtual void closeAll();
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();
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();
106  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
109  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document(int theDocID);
112  MODEL_EXPORT virtual bool hasModuleDocument();
115  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> activeDocument();
118  MODEL_EXPORT virtual void setActiveDocument(
119  std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true);
122  MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
125  MODEL_EXPORT virtual bool isLoadByDemand(const std::wstring theDocID, const int theDocIndex);
130  MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
133  MODEL_EXPORT virtual bool checkLicense(const std::string& thePluginName);
136  MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
139  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> copy(
140  std::shared_ptr<ModelAPI_Document> theSource, const int theDestID);
143  MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
146  MODEL_EXPORT virtual ModelAPI_FiltersFactory* filters();
149  void setCheckTransactions(const bool theCheck)
150  {
151  myCheckTransactions = theCheck;
152  }
155  Model_Session();
158  MODEL_EXPORT virtual int transactionID();
162  MODEL_EXPORT virtual bool isAutoUpdateBlocked();
165  MODEL_EXPORT virtual void blockAutoUpdate(const bool theBlock);
167 #ifdef TINSPECTOR
168  MODEL_EXPORT virtual Handle(TDocStd_Application) application();
169 #endif
171  protected:
173  void LoadPluginsInfo();
176  FeaturePtr createFeature(std::string theFeatureID, Model_Document* theDocOwner);
179  ModelAPI_Plugin* getPlugin(const std::string& thePluginName);
181  friend class Model_Document;
182  friend class Model_Objects;
183 };
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:44
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:389
virtual bool hasModuleDocument()
Return true if root document has been already created.
Definition: Model_Session.cpp:282
Is called only once, on startup of the application.
Definition: Model_Session.cpp:453
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:165
virtual void closeAll()
Closes all documents.
Definition: Model_Session.cpp:73
virtual bool canUndo()
Returns True if there are available Undos.
Definition: Model_Session.cpp:148
virtual std::shared_ptr< ModelAPI_Document > activeDocument()
Returns the current document that used for current work in the application.
Definition: Model_Session.cpp:287
virtual void registerPlugin(ModelAPI_Plugin *thePlugin)
Registers the plugin that creates features.
Definition: Model_Session.cpp:614
ModelAPI_Plugin * getPlugin(const std::string &thePluginName)
Get the plugin by name. If it is not loaded, load plugin.
Definition: Model_Session.cpp:193
virtual std::list< std::shared_ptr< ModelAPI_Document > > allOpenedDocuments()
Returns all the opened documents of the session (without postponed)
Definition: Model_Session.cpp:364
virtual bool isModified()
Returns true if document was modified (since creation/opening)
Definition: Model_Session.cpp:143
virtual std::shared_ptr< ModelAPI_Document > moduleDocument()
Returns the root document of the application (that may contains sub-documents)
Definition: Model_Session.cpp:252
virtual std::list< std::string > redoList()
Returns stack of rolled back operations.
Definition: Model_Session.cpp:178
FeaturePtr createFeature(std::string theFeatureID, Model_Document *theDocOwner)
Creates the feature object using plugins functionality.
Definition: Model_Session.cpp:216
virtual bool save(const char *theFileName, std::list< std::string > &theResults)
Saves the OCAF document to the file.
Definition: Model_Session.cpp:68
virtual void undo()
Undoes last operation.
Definition: Model_Session.cpp:153
virtual void startOperation(const std::string &theId="", const bool theAttachedToNested=false)
Starts a new operation (opens a transaction)
Definition: Model_Session.cpp:83
virtual void processEvent(const std::shared_ptr< Events_Message > &theMessage)
Processes the configuration file reading.
Definition: Model_Session.cpp:471
virtual bool canRedo()
Returns True if there are available Redos.
Definition: Model_Session.cpp:160
virtual bool isLoadByDemand(const std::wstring theDocID, const int theDocIndex)
Returns true if document is not loaded yet.
Definition: Model_Session.cpp:384
virtual void abortOperation()
Aborts the operation.
Definition: Model_Session.cpp:114
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:312
virtual void finishOperation()
Finishes the previously started operation (closes the transaction)
Definition: Model_Session.cpp:99
virtual bool checkLicense(const std::string &thePluginName)
Verifies the license for the plugin is valid.
Definition: Model_Session.cpp:188
void LoadPluginsInfo()
Loads (if not done yet) the information about the features and plugins.
Definition: Model_Session.cpp:598
virtual ModelAPI_ValidatorsFactory * validators()
Returns the validators factory: the only one instance per application.
Definition: Model_Session.cpp:629
virtual bool isAutoUpdateBlocked()
Returns true if auto-update in the application is blocked.
Definition: Model_Session.cpp:646
virtual std::list< std::string > undoList()
Returns stack of performed operations.
Definition: Model_Session.cpp:173
virtual ModelAPI_FiltersFactory * filters()
Returns the filters factory: the only one instance per application.
Definition: Model_Session.cpp:635
virtual void clearUndoRedo()
Clears undo and redo lists of all documents in the session.
Definition: Model_Session.cpp:183
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:276
virtual void blockAutoUpdate(const bool theBlock)
Set state of the auto-update of features result in the application.
Definition: Model_Session.cpp:654
virtual int transactionID()
Returns the global identifier of the current transaction (needed for the update algo)
Definition: Model_Session.cpp:641
virtual bool isOperation()
Returns true if operation has been started, but not yet finished or aborted.
Definition: Model_Session.cpp:138
virtual bool load(const char *theFileName)
Loads the OCAF document from the file.
Definition: Model_Session.cpp:60