]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Document.h
Salome HOME
API for objects presentation order.
[modules/hydro.git] / src / HYDROData / HYDROData_Document.h
1 #ifndef HYDROData_Document_HeaderFile
2 #define HYDROData_Document_HeaderFile
3
4 #include <HYDROData.h>
5 #include <HYDROData_Entity.h>
6
7 #include <TDocStd_Document.hxx>
8
9 class QFile;
10
11 /**
12  * Errors that could appear on document open/save actions.
13  * If there is no error, it is "OK".
14  */
15 enum Data_DocError {
16   DocError_OK = 0, ///< success
17   DocError_ResourcesProblem, ///< resources files are invalid or not found
18   DocError_CanNotOpen, ///< can not open file for reading or writing
19   DocError_InvalidVersion, ///< version of document is different than expected
20   DocError_InvalidFormat, ///< format of the document is bad
21   DocError_UnknownProblem ///< problem has unknown nature
22 };
23
24 DEFINE_STANDARD_HANDLE(HYDROData_Document, MMgt_TShared)
25
26 /**\class HYDROData_Document
27  *
28  * \brief Document for internal data structure of any object storage. Corresponds to the SALOME study.
29  *
30  * Document contains all data of the Study specific to this module.
31  * Also it provides acces to this data: open/save, transactions management etc.
32  * to provide access to all stored data.
33  */
34
35 class HYDROData_Document : public MMgt_TShared
36 {
37 public:
38
39   DEFINE_STANDARD_RTTI(HYDROData_Document);
40
41   //! Returns the existing document or creates new if it is not exist
42   HYDRODATA_EXPORT static Handle(HYDROData_Document) Document(const int theStudyID);
43
44   //! Returns the document by object
45   HYDRODATA_EXPORT static Handle(HYDROData_Document) Document( 
46     const TDF_Label& theObjectLabel );
47
48 public:
49
50   //! Returns true if data model contains document for this study
51   HYDRODATA_EXPORT static bool HasDocument(const int theStudyID);
52
53   //! Get study id by document instance, if document doesn't exists return false
54   HYDRODATA_EXPORT static bool DocumentId( const Handle(HYDROData_Document)& theDocument,
55                                            int&                              theDocId );
56
57 public:
58
59   //! Loads the OCAF document from the file.
60   //! \param theFileName full name of the file to load
61   //! \param theStudyID identifier of the SALOME study to associate with loaded file
62   //! \returns error status (OK in case of success)
63   HYDRODATA_EXPORT static Data_DocError Load(const char* theFileName, const int theStudyID);
64
65   //! Saves the OCAF document to the file.
66   //! \param theFileName full name of the file to store
67   //! \returns error status (OK in case of success)
68   HYDRODATA_EXPORT Data_DocError Save(const char* theFileName);
69
70   //! Removes document data
71   HYDRODATA_EXPORT void Close();
72
73 public:
74
75   // Returns name of document instance in python dump script
76   HYDRODATA_EXPORT QString GetDocPyName() const;
77
78   //! Dump study document to Python script representation.
79   //! \param theFileName full name of the file to store
80   //! \returns true if document has been successfuly dumped
81   HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName,
82                                       const bool     theIsMultiFile ) const;
83
84   //! Dump model data to Python script representation.
85   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects,
86                                                      const bool           theIsMultiFile ) const;
87
88 public:
89
90   // Methods to work with objects presentation.
91
92   //! Returns the order of objects presentation. Objects in returned sequence
93   //! are order from top to low depending on z-level parameter. Objects that
94   //! have no z-level parameter are located at the end of sequence and
95   //! sorted alphabetically.
96   //! Only the following types of objects considered:
97   //!   1. KIND_IMAGE
98   //!   2. KIND_IMMERSIBLE_ZONE
99   //!   3. KIND_CHANNEL
100   //!   4. KIND_RIVER
101   //!   5. KIND_STREAM
102   //!   6. KIND_OBSTACLE
103   //!   7. KIND_DIGUE
104   //!   8. KIND_POLYLINEXY
105   //!   9. KIND_ZONE
106   //! \param theIsAll if flag is true then all objects will be included,
107   //!                 otherwise only objects which have the z-level parameter
108   //! \returns ordered sequence of objects
109   HYDRODATA_EXPORT HYDROData_SequenceOfObjects GetObjectsLayerOrder( 
110     const Standard_Boolean theIsAll = Standard_True ) const;
111
112   //! Sets the order of objects presentation.
113   HYDRODATA_EXPORT void SetObjectsLayerOrder( const HYDROData_SequenceOfObjects& theOrder );
114
115   //! Show object at the top of other model objects. If the object
116   //! already has the z-level parameter then nothing will be done.
117   HYDRODATA_EXPORT void Show( const Handle_HYDROData_Entity& theObject );
118
119   //! Show sequence of objects at the top of other model objects.
120   //! The objects from the sequence will be sorted alphabetically at first.
121   HYDRODATA_EXPORT void Show( const HYDROData_SequenceOfObjects& theObjects );
122
123
124 public:
125
126   //! Starts a new operation (opens a tansaction)
127   HYDRODATA_EXPORT void StartOperation();
128   //! Finishes the previously started operation (closes the transaction)
129   HYDRODATA_EXPORT void CommitOperation(
130     const TCollection_ExtendedString& theName = TCollection_ExtendedString());
131   //! Aborts the operation 
132   HYDRODATA_EXPORT void AbortOperation();
133   //! Returns true if operation has been started, but not yet finished or aborted
134   HYDRODATA_EXPORT bool IsOperation();
135   //! Returns true if document was modified (since creation/opening)
136   HYDRODATA_EXPORT bool IsModified();
137
138 public:
139
140   //! Returns True if there are available Undos
141   HYDRODATA_EXPORT bool CanUndo();
142   //! Returns a list of stored undo actions
143   HYDRODATA_EXPORT const TDF_DeltaList& GetUndos();
144   //! Clears a list of stored undo actions
145   HYDRODATA_EXPORT void ClearUndos();
146   //! Undoes last operation
147   HYDRODATA_EXPORT void Undo();
148
149   //! Returns True if there are available Redos
150   HYDRODATA_EXPORT bool CanRedo();
151   //! Returns a list of stored undo actions
152   HYDRODATA_EXPORT const TDF_DeltaList& GetRedos();
153   //! Clears a list of stored undo actions
154   HYDRODATA_EXPORT void ClearRedos();
155   //! Redoes last operation
156   HYDRODATA_EXPORT void Redo();
157
158 public:
159
160   //! Creates and locates in the document a new object
161   //! \param theKind kind of the created object, can not be UNKNOWN
162   //! \returns the created object
163   HYDRODATA_EXPORT Handle(HYDROData_Entity) CreateObject(const ObjectKind theKind);
164
165
166   //! Find the data object with the specified name.
167   HYDRODATA_EXPORT Handle(HYDROData_Entity) FindObjectByName( 
168     const QString&   theName, 
169     const ObjectKind theObjectKind = KIND_UNKNOWN ) const;
170
171   //! Find the data objects with the specified names.
172   HYDRODATA_EXPORT HYDROData_SequenceOfObjects FindObjectsByNames(
173     const QStringList& theNames, 
174     const ObjectKind   theObjectKind = KIND_UNKNOWN ) const;
175
176 protected:
177
178   friend class HYDROData_Iterator;
179   friend class test_HYDROData_Document;
180
181   //! Creates new document: private because "Document" method must be used instead of direct creation.
182   HYDRODATA_EXPORT HYDROData_Document();
183   //! Creates new document by existing OCAF structure
184   HYDRODATA_EXPORT HYDROData_Document(const Handle(TDocStd_Document)& theDoc);
185   //! Deletes all high-level data, managed this document
186   HYDRODATA_EXPORT ~HYDROData_Document();
187
188   //! Returns the new identifier of the new object (may be used for correct ordering of objects)
189   HYDRODATA_EXPORT int NewID();
190
191   //! Returns the label where the objects are located (used by Iterator)
192   HYDRODATA_EXPORT TDF_Label LabelOfObjects();
193
194 private:
195   
196   // Dump header Python part in to file \c theFile
197   bool DumpToPython( QFile&               theFile,
198                      MapOfTreatedObjects& theTreatedObjects ) const;
199
200   // Dump objects of type \c theObjectKind to file \c theFile
201   bool dumpPartitionToPython( QFile&               theFile,
202                               const bool           theIsMultiFile,
203                               MapOfTreatedObjects& theDumpedObjects,
204                               const ObjectKind&    theObjectKind ) const;
205
206 private:
207   Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
208   int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
209 };
210
211 #endif