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