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