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