Salome HOME
Convert the altitude for bathymetry to negative number during it reading from the...
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.h
1
2 #ifndef HYDROData_Entity_HeaderFile
3 #define HYDROData_Entity_HeaderFile
4
5 #include "HYDROData.h"
6
7 #include <NCollection_Sequence.hxx>
8
9 #include <TDF_Label.hxx>
10
11 #include <QMap>
12
13 class QColor;
14 class QString;
15 class QVariant;
16 class QStringList;
17 class Handle(TDataStd_ReferenceList);
18 class Handle_HYDROData_Entity;
19
20 ///! Kind of an object in a document
21 typedef int ObjectKind;
22
23 const ObjectKind KIND_UNKNOWN           = 0; ///! Unrecognized object
24 const ObjectKind KIND_IMAGE             = 1;
25 const ObjectKind KIND_POLYLINE          = 2;
26 const ObjectKind KIND_BATHYMETRY        = 3;
27 const ObjectKind KIND_ALTITUDE          = 4;
28 const ObjectKind KIND_IMMERSIBLE_ZONE   = 5;
29 const ObjectKind KIND_RIVER             = 6;
30 const ObjectKind KIND_STREAM            = 7;
31 const ObjectKind KIND_CONFLUENCE        = 8;
32 const ObjectKind KIND_CHANNEL           = 9;
33 const ObjectKind KIND_OBSTACLE          = 10;
34 const ObjectKind KIND_DIGUE             = 11;
35 const ObjectKind KIND_PROFILE           = 12;
36 const ObjectKind KIND_PROFILEUZ         = 13;
37 const ObjectKind KIND_POLYLINEXY        = 14;
38 const ObjectKind KIND_CALCULATION       = 15;
39 const ObjectKind KIND_ZONE              = 16;
40 const ObjectKind KIND_REGION            = 17;
41 const ObjectKind KIND_VISUAL_STATE      = 18;
42 const ObjectKind KIND_ARTIFICIAL_OBJECT = 19;
43 const ObjectKind KIND_NATURAL_OBJECT    = 20;
44 const ObjectKind KIND_LAST              = KIND_NATURAL_OBJECT;
45
46 DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared)
47
48 typedef QMap<QString,Handle(Standard_Transient)> MapOfTreatedObjects;
49
50 typedef NCollection_Sequence<Handle_HYDROData_Entity> HYDROData_SequenceOfObjects;
51
52
53 /**\class HYDROData_Entity
54  * \brief Generic class of any object in the data model.
55  *
56  * Interface for getting access to the object that belong to the data model.
57  * Managed by Document. Provides access to the common properties: 
58  * kind of an object, name.
59  */
60 class HYDROData_Entity : public MMgt_TShared
61 {
62
63 protected:
64
65   /**
66    * Enumeration of tags corresponding to the persistent object parameters.
67    */
68   enum DataTag
69   {
70     DataTag_First = 0     ///< first tag, to reserve
71     // ...
72   };
73
74 public:
75   DEFINE_STANDARD_RTTI(HYDROData_Entity);
76
77   /**
78    * Returns the kind of this object. Must be redefined in all objects of known type.
79    */
80   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
81
82   /**
83    * Returns the name of this object.
84    */
85   HYDRODATA_EXPORT virtual QString GetName() const;
86
87   /**
88    * Updates the name of this object.
89    */
90   HYDRODATA_EXPORT virtual void SetName( const QString& theName );
91
92   /**
93    * Dump object to Python script representation.
94    * Base implementation returns empty list,
95    * You should reimplement this function in your derived class if it
96    * has Python API and can be imported/exported from/to Python script.
97    */
98   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
99
100   /**
101    * Updates object state. Base implementation dose nothing.
102    */
103   HYDRODATA_EXPORT virtual void Update();
104
105   /**
106    * Returns data of object wrapped to QVariant.
107    * Base implementation returns null value.
108    */
109   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
110
111   /**
112    * Sets the "MustBeUpdated" flag: if object is depended on updated features.
113    * \param theFlag is true for objects that must be updated, false for up-to-date
114    */
115   HYDRODATA_EXPORT void SetToUpdate( bool theFlag );
116
117   /**
118    * Returns the "MustBeUpdated" flag: is object data must be updated or not
119    * \returns false if object is up to date
120    */
121   HYDRODATA_EXPORT bool IsMustBeUpdated() const;
122
123   /**
124    * Checks is object exists in the data structure.
125    * \returns true is object is not exists in the data model
126    */
127   HYDRODATA_EXPORT bool IsRemoved() const;
128
129   /**
130    * Removes object and it child sub-objects from the data structure.
131    */
132   HYDRODATA_EXPORT virtual void Remove();
133
134   /**
135    * Returns unique integer identifier of the object (may be used for ordering of objects)
136    */
137   HYDRODATA_EXPORT inline int ID() const { return myLab.Tag(); }
138
139   /**
140    * Copies all properties of this to the destinated object.
141    * Objects must be the same type.
142    * \param theDestination initialized object (from any document) - target of copying
143    */
144   HYDRODATA_EXPORT void CopyTo( Handle_HYDROData_Entity theDestination ) const;
145
146   /**
147    * Returns the label of this object.
148    */
149   HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
150
151   /**
152    * Returns father object. For object created under root document label
153    * this method always return NULL object.
154    */
155   HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
156
157 protected:
158
159   friend class HYDROData_Iterator;
160
161   /**
162    * Creates new object in the internal data structure. Use higher level objects 
163    * to create objects with real content.
164    */
165   HYDRODATA_EXPORT HYDROData_Entity();
166
167   /**
168    * Destructs properties of the object and object itself, removes it from the document.
169    */
170   virtual HYDRODATA_EXPORT ~HYDROData_Entity();
171
172   /**
173    * Put the object to the label of the document.
174    * \param theLabel new label of the object
175    */
176   HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
177
178   /**
179    * Internal method that used to store the byte array attribute
180    * \param theTag tag of a label to store attribute (for 0 this is myLab)
181    * \param theData pointer to bytes array
182    * \param theLen number of bytes in byte array that must be stored
183    */
184   void SaveByteArray(const int theTag, const char* theData, const int theLen);
185
186   /**
187    * Internal method that used to retreive the content of byte array attribute
188    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
189    * \param theLen number of bytes in byte array
190    * \returns pointer to the internal data structure wit harray content, 
191    *          or NULL if array size is zero
192    */
193   const char* ByteArray(const int theTag, int& theLen) const;
194
195   /**
196    * Internal method that used to store the reference object label attribute
197    * \param theObj pointer to reference object
198    * \param theTag tag of a label to store attribute (for 0 this is myLab)
199    */
200   int NbReferenceObjects( const int theTag = 0 ) const;
201
202   /**
203    * Internal method that used to check object for entry into the reference list
204    * \param theObj pointer to reference object
205    * \param theTag tag of a label to store attribute (for 0 this is myLab)
206    */
207   bool HasReference( const Handle_HYDROData_Entity& theObj,
208                      const int                      theTag = 0 ) const;
209
210   /**
211    * Internal method that used to store the reference object label attribute
212    * \param theObj pointer to reference object
213    * \param theTag tag of a label to store attribute (for 0 this is myLab)
214    */
215   void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
216                            const int                      theTag = 0 );
217
218   /**
219    * Internal method that used to store the reference object label attribute
220    * \param theObj pointer to reference object
221    * \param theTag tag of a label to store attribute (for 0 this is myLab)
222    * \param theIndex index in the list of references 
223              - if more that len then just append it to the end of list
224              - if less than zero then prepend to the list
225              - indexing starts from 0
226    */
227   void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
228                            const int                      theTag = 0,
229                            const int                      theIndex = 0 );
230
231   /**
232    * Internal method that used to store the reference object label attribute
233    * \param theObj pointer to reference object
234    * \param theTag tag of a label to store attribute (for 0 this is myLab)
235    * \param theBeforeIndex index in the list of references 
236              - if more that len then just append it to the end of list
237              - if less than zero then prepend to the list
238              - indexing starts from 0
239    */
240   void InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
241                               const int                      theTag = 0,
242                               const int                      theBeforeIndex = 0 );
243
244   /**
245    * Internal method that used to store the reference object label attribute
246    * \param theObjects sequence with pointers to reference objects
247    * \param theTag tag of a label to store attribute (for 0 this is myLab)
248    */
249   void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
250                             const int                          theTag = 0 );
251
252   /**
253    * Internal method that used to retreive the reference object(s) attribute
254    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
255    * \param theIndex index in the list of references 
256    *        - indexing starts from 0
257    * \returns pointer to reference object or NULL if label is not set
258    */
259   Handle_HYDROData_Entity GetReferenceObject( const int theTag   = 0,
260                                               const int theIndex = 0 ) const;
261
262   HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
263
264   /**
265    * Internal method that used to remove the reference object attribute
266    * \param theRefLabel reference object label to remove
267    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
268    */
269   void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
270
271   /**
272    * Internal method that used to remove the reference object attribute
273    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
274    * \param theIndex index in the list of references 
275    *        - indexing starts from 0
276    */
277   void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
278
279   /**
280    * Internal method that used to clear list of the reference objects attribute
281    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
282    */
283   void ClearReferenceObjects( const int theTag = 0 );
284
285   /**
286    * Internal method that used to store the color attribute
287    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
288    * \param theColor color to save
289    */
290   void SetColor( const QColor& theColor, const int theTag = 0 );
291
292   /**
293    * Internal method that used to retreive the color attribute
294    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
295    * \param theDefColor default color to return if attribute has not been set before
296    */
297   QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
298
299  
300 protected:
301
302   void setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
303                                  QStringList&                    theScript,
304                                  const Handle(HYDROData_Entity)& theRefObject,
305                                  const QString&                  theMethod ) const;
306 protected:
307
308   Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
309                                                    const bool theIsCreate ) const;
310
311
312 protected:
313   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
314   TDF_Label myLab; ///< label of this object
315 };
316
317 ///! Is Equal for HYDROData_Entity mapping
318 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
319
320 #endif