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