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