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