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