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