Salome HOME
Added object, attribute and data model organization in the document.
[modules/shaper.git] / src / Model / Model_Document.h
1 // File:        Model_Document.h
2 // Created:     28 Feb 2014
3 // Author:      Mikhail PONIKAROV
4
5 #ifndef Model_Document_HeaderFile
6 #define Model_Document_HeaderFile
7
8 #include <Model.h>
9 #include <ModelAPI_Document.h>
10 #include <TDocStd_Document.hxx>
11 #include <map>
12
13 class Handle_Model_Document;
14
15 /**\class Model_Document
16  * \ingroup DataModel
17  * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
18  * Document contains all data of te SALOME Study specific to this module
19  * that must be written into the HDF file.
20  * Also it provides acces to this data: open/save, transactions management etc.
21  * to provide access to all stored data.
22  */
23
24 class Model_Document: public ModelAPI_Document
25 {
26 public:
27
28   //! Loads the OCAF document from the file.
29   //! \param theFileName full name of the file to load
30   //! \param theStudyID identifier of the SALOME study to associate with loaded file
31   //! \returns true if file was loaded successfully
32   MODEL_EXPORT bool load(const char* theFileName);
33
34   //! Saves the OCAF document to the file.
35   //! \param theFileName full name of the file to store
36   //! \returns true if file was stored successfully
37   MODEL_EXPORT bool save(const char* theFileName);
38
39   //! Removes document data
40   MODEL_EXPORT void close();
41
42   //! Starts a new operation (opens a tansaction)
43   MODEL_EXPORT void startOperation();
44   //! Finishes the previously started operation (closes the transaction)
45   MODEL_EXPORT void finishOperation();
46   //! Aborts the operation 
47   MODEL_EXPORT void abortOperation();
48   //! Returns true if operation has been started, but not yet finished or aborted
49   MODEL_EXPORT bool isOperation();
50   //! Returns true if document was modified (since creation/opening)
51   MODEL_EXPORT bool isModified();
52
53   //! Returns True if there are available Undos
54   MODEL_EXPORT bool canUndo();
55   //! Undoes last operation
56   MODEL_EXPORT void undo();
57   //! Returns True if there are available Redos
58   MODEL_EXPORT bool canRedo();
59   //! Redoes last operation
60   MODEL_EXPORT void redo();
61
62   //! Adds to the document the new feature of the given group id
63   //! \param theFeature a feature object that will be connected to the document in this method
64   //! \param theGroupID identifier of the groups of objects (must be greater than zero)
65   MODEL_EXPORT virtual void addFeature(std::shared_ptr<ModelAPI_Feature> theFeature,
66     const std::string theGroupID);
67
68   //! Returns the existing feature by the label
69   //! \param theLabel base label of the feature
70   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> feature(TDF_Label& theLabel);
71
72   //! Adds a new sub-document by the identifier, or returns existing one if it is already exist
73   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Document> subDocument(std::string theDocID);
74
75   //! Creates an iterator of the features by the specific groups
76   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Iterator> featuresIterator(
77     const std::string theGroup);
78
79   MODEL_EXPORT virtual const std::string& id() const {return myID;}
80
81 protected:
82
83   //! Returns (creates if needed) the group label
84   TDF_Label groupLabel(const std::string theGroup);
85
86   //! Initializes feature with a unique name in this group (unique name is generated as 
87   //! feature type + "_" + index
88   void setUniqueName(
89     std::shared_ptr<ModelAPI_Feature> theFeature, const std::string theGroupID);
90
91   //! Creates new document with binary file format
92   Model_Document(const std::string theID);
93
94   friend class Model_Application;
95
96 private:
97   std::string myID; ///< identifier of the document in the application
98   Handle_TDocStd_Document myDoc; ///< OCAF document
99   int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
100   std::map<std::string, TDF_Label> myGroups; ///< root labels of the features groups identified by names
101 };
102
103 #endif