1 // File: ModelAPI_Session.hxx
2 // Created: 20 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #ifndef ModelAPI_Session_H_
6 #define ModelAPI_Session_H_
11 #include <boost/shared_ptr.hpp>
13 class ModelAPI_Feature;
14 class ModelAPI_Plugin;
15 class ModelAPI_Document;
16 class ModelAPI_ValidatorsFactory;
18 /**\class ModelAPI_Session
20 * \brief Object that knows (from the initial XML file) which
21 * plugin contains which feature, loads and stores reference to loaded plugins by
22 * the feature functionality request.
25 class MODELAPI_EXPORT ModelAPI_Session
28 /// Returns the real implementation (the alone instance per application) of the plugin manager
29 static boost::shared_ptr<ModelAPI_Session> get();
31 //! Loads the OCAF document from the file.
32 //! \param theFileName full name of the file to load
33 //! \param theStudyID identifier of the SALOME study to associate with loaded file
34 //! \returns true if file was loaded successfully
35 virtual bool load(const char* theFileName) = 0;
37 //! Saves the OCAF document to the file.
38 //! \param theFileName full name of the file to store
39 //! \param theResults the result full file names that were stored by "save"
40 //! \returns true if file was stored successfully
41 virtual bool save(const char* theFileName, std::list<std::string>& theResults) = 0;
43 //! Closes all documents
44 virtual void closeAll() = 0;
46 //! Starts a new operation (opens a tansaction)
47 virtual void startOperation() = 0;
48 //! Finishes the previously started operation (closes the transaction)
49 virtual void finishOperation() = 0;
50 //! Aborts the operation
51 virtual void abortOperation() = 0;
52 //! Returns true if operation has been started, but not yet finished or aborted
53 virtual bool isOperation() = 0;
54 //! Returns true if document was modified (since creation/opening)
55 virtual bool isModified() = 0;
57 //! Returns True if there are available Undos
58 virtual bool canUndo() = 0;
59 //! Undoes last operation
60 virtual void undo() = 0;
61 //! Returns True if there are available Redos
62 virtual bool canRedo() = 0;
63 //! Redoes last operation
64 virtual void redo() = 0;
66 /// Registers the plugin that creates features.
67 /// It is obligatory for each plugin to call this function on loading to be found by
68 /// the plugin manager on call of the feature)
69 virtual void registerPlugin(ModelAPI_Plugin* thePlugin) = 0;
71 /// Returns the root document of the application (that may contains sub-documents)
72 virtual boost::shared_ptr<ModelAPI_Document> moduleDocument() = 0;
74 /// Return true if root document has been already created
75 virtual bool hasModuleDocument() = 0;
77 /// Returns the current document that used for current work in the application
78 virtual boost::shared_ptr<ModelAPI_Document> activeDocument() = 0;
80 /// Defines the current document that used for current work in the application
81 virtual void setActiveDocument(
82 boost::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal = true) = 0;
84 /// Returns all the opened documents of the session (without postponed)
85 virtual std::list<boost::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
87 /// Copies the document to the new one with the given id
88 virtual boost::shared_ptr<ModelAPI_Document> copy(boost::shared_ptr<ModelAPI_Document> theSource,
89 std::string theID) = 0;
91 /// Returns the validators factory: the only one instance per application
92 virtual ModelAPI_ValidatorsFactory* validators() = 0;
94 /// Is needed for python wrapping by swig, call Get to get an instance
97 /// To virtually destroy the fields of successors
98 virtual ~ModelAPI_Session()
103 /// Creates the feature object using plugins functionality
104 virtual boost::shared_ptr<ModelAPI_Feature> createFeature(std::string theFeatureID) = 0;
106 static void setSession(boost::shared_ptr<ModelAPI_Session> theManager);
108 friend class Model_Document;
111 typedef boost::shared_ptr<ModelAPI_Session> SessionPtr;