1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: Model_Session.hxx
4 // Created: 20 Mar 2014
5 // Author: Mikhail PONIKAROV
7 #ifndef Model_Session_H_
8 #define Model_Session_H_
11 #include <ModelAPI_Session.h>
12 #include <ModelAPI_Feature.h>
14 #include <Events_Listener.h>
19 /**\class Model_Session
21 * \brief Object that knows (from the initial XML file) which
22 * plugin contains which feature, loads and stores reference to loaded plugins by
23 * the feature functionality request.
25 class Model_Session : public ModelAPI_Session, public Events_Listener
27 bool myPluginsInfoLoaded; ///< it true if plugins information is loaded
28 /// map of feature IDs to plugin name and document kind
29 std::map<std::string, std::pair<std::string, std::string> > myPlugins;
30 std::map<std::string, ModelAPI_Plugin*> myPluginObjs; ///< instances of the already plugins
31 std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently
32 std::shared_ptr<ModelAPI_Document> myCurrentDoc; ///< current working document
33 bool myCheckTransactions; ///< if true, generates error if document is updated outside of transaction
34 bool myOperationAttachedToNext; ///< the current operation must be committed twice, with nested
37 //! Loads the OCAF document from the file.
38 //! \param theFileName full name of the file to load
39 //! \returns true if file was loaded successfully
40 MODEL_EXPORT virtual bool load(const char* theFileName);
42 //! Saves the OCAF document to the file.
43 //! \param theFileName full name of the file to store
44 //! \param theResults the result full file names that were stored by "save"
45 //! \returns true if file was stored successfully
46 MODEL_EXPORT virtual bool save(const char* theFileName, std::list<std::string>& theResults);
48 //! Closes all documents
49 MODEL_EXPORT virtual void closeAll();
51 //! Starts a new operation (opens a transaction)
52 //! \param theId string-identifier of the started transaction
53 //! \param theAttachedToNested if it is true, it means that this transaction is attached to the nested
54 //! where it is located and will be committed on the next commit with the nested
55 MODEL_EXPORT virtual void startOperation(
56 const std::string& theId = "", const bool theAttachedToNested = false);
57 //! Finishes the previously started operation (closes the transaction)
58 MODEL_EXPORT virtual void finishOperation();
59 //! Aborts the operation
60 MODEL_EXPORT virtual void abortOperation();
61 //! Returns true if operation has been started, but not yet finished or aborted
62 MODEL_EXPORT virtual bool isOperation();
63 //! Returns true if document was modified (since creation/opening)
64 MODEL_EXPORT virtual bool isModified();
66 //! Returns True if there are available Undos
67 MODEL_EXPORT virtual bool canUndo();
68 //! Undoes last operation
69 MODEL_EXPORT virtual void undo();
70 //! Returns True if there are available Redos
71 MODEL_EXPORT virtual bool canRedo();
72 //! Redoes last operation
73 MODEL_EXPORT virtual void redo();
74 //! Returns stack of performed operations
75 MODEL_EXPORT virtual std::list<std::string> undoList();
76 //! Returns stack of rolled back operations
77 MODEL_EXPORT virtual std::list<std::string> redoList();
79 /// Returns the root document of the application (that may contains sub-documents)
80 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> moduleDocument();
82 /// Returns the document by ID, loads if not loaded yet. Returns null if no such document.
83 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> document(int theDocID);
85 /// Return true if root document has been already created
86 MODEL_EXPORT virtual bool hasModuleDocument();
88 /// Returns the current document that used for current work in the application
89 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> activeDocument();
91 /// Defines the current document that used for current work in the application
92 MODEL_EXPORT virtual void setActiveDocument(
93 std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true);
95 /// Returns all the opened documents of the session (without postponed)
96 MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
98 /// Returns true if document is not loaded yet
99 MODEL_EXPORT virtual bool isLoadByDemand(const std::string theDocID);
101 /// Registers the plugin that creates features.
102 /// It is obligatory for each plugin to call this function on loading to be found by
103 /// the plugin manager on call of the feature)
104 MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin);
106 /// Processes the configuration file reading
107 MODEL_EXPORT virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
109 /// Copies the document to the new one
110 MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> copy(
111 std::shared_ptr<ModelAPI_Document> theSource, const int theDestID);
113 /// Returns the validators factory: the only one instance per application
114 MODEL_EXPORT virtual ModelAPI_ValidatorsFactory* validators();
116 /// Sets the flag to check modifications outside the transaction or not
117 void setCheckTransactions(const bool theCheck)
119 myCheckTransactions = theCheck;
122 /// Is called only once, on startup of the application
125 /// Returns the global identifier of the current transaction (needed for the update algo)
126 MODEL_EXPORT virtual int transactionID();
129 /// Loads (if not done yet) the information about the features and plugins
130 void LoadPluginsInfo();
132 /// Creates the feature object using plugins functionality
133 FeaturePtr createFeature(std::string theFeatureID, Model_Document* theDocOwner);
135 friend class Model_Document;
136 friend class Model_Objects;