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