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