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