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