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