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