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