Salome HOME
Image positioning by two points.
[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.
100    * Base implementation dose nothing.
101    * \param theIsForce force reupdating of data object
102    */
103   HYDRODATA_EXPORT virtual void Update( const bool theIsForce = true );
104
105   /**
106    * Returns data of object wrapped to QVariant.
107    * Base implementation returns null value.
108    */
109   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
110
111   /**
112    * Checks is object exists in the data structure.
113    * \returns true is object is not exists in the data model
114    */
115   HYDRODATA_EXPORT bool IsRemoved() const;
116
117   /**
118    * Removes object and it child sub-objects from the data structure.
119    */
120   HYDRODATA_EXPORT virtual void Remove();
121
122   /**
123    * Returns unique integer identifier of the object (may be used for ordering of objects)
124    */
125   HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();}
126
127   /**
128    * Copies all properties of this to the destinated object.
129    * Objects must be the same type.
130    * \param theDestination initialized object (from any document) - target of copying
131    */
132   HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Entity theDestination) const;
133
134   /**
135    * Returns the label of this object.
136    */
137   HYDRODATA_EXPORT TDF_Label& Label() {return myLab;}
138
139   /**
140    * Returns father object. For object created under root document label
141    * this method always return NULL object.
142    */
143   HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
144
145 protected:
146
147   friend class HYDROData_Iterator;
148
149   /**
150    * Creates new object in the internal data structure. Use higher level objects 
151    * to create objects with real content.
152    */
153   HYDRODATA_EXPORT HYDROData_Entity();
154
155   /**
156    * Destructs properties of the object and object itself, removes it from the document.
157    */
158   virtual HYDRODATA_EXPORT ~HYDROData_Entity();
159
160   /**
161    * Put the object to the label of the document.
162    * \param theLabel new label of the object
163    */
164   HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
165
166   /**
167    * Internal method that used to store the byte array attribute
168    * \param theTag tag of a label to store attribute (for 0 this is myLab)
169    * \param theData pointer to bytes array
170    * \param theLen number of bytes in byte array that must be stored
171    */
172   void SaveByteArray(const int theTag, const char* theData, const int theLen);
173
174   /**
175    * Internal method that used to retreive the content of byte array attribute
176    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
177    * \param theLen number of bytes in byte array
178    * \returns pointer to the internal data structure wit harray content, 
179    *          or NULL if array size is zero
180    */
181   const char* ByteArray(const int theTag, int& theLen) const;
182
183   /**
184    * Internal method that used to store the reference object label attribute
185    * \param theObj pointer to reference object
186    * \param theTag tag of a label to store attribute (for 0 this is myLab)
187    */
188   int NbReferenceObjects( const int theTag = 0 ) const;
189
190   /**
191    * Internal method that used to check object for entry into the reference list
192    * \param theObj pointer to reference object
193    * \param theTag tag of a label to store attribute (for 0 this is myLab)
194    */
195   bool HasReference( const Handle_HYDROData_Entity& theObj,
196                      const int                      theTag = 0 ) const;
197
198   /**
199    * Internal method that used to store the reference object label attribute
200    * \param theObj pointer to reference object
201    * \param theTag tag of a label to store attribute (for 0 this is myLab)
202    */
203   void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
204                            const int                      theTag = 0 );
205
206   /**
207    * Internal method that used to store the reference object label attribute
208    * \param theObj pointer to reference object
209    * \param theTag tag of a label to store attribute (for 0 this is myLab)
210    * \param theIndex index in the list of references 
211              - if more that len then just append it to the end of list
212              - if less than zero then prepend to the list
213              - indexing starts from 0
214    */
215   void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
216                            const int                      theTag = 0,
217                            const int                      theIndex = 0 );
218
219   /**
220    * Internal method that used to store the reference object label attribute
221    * \param theObj pointer to reference object
222    * \param theTag tag of a label to store attribute (for 0 this is myLab)
223    * \param theBeforeIndex index in the list of references 
224              - if more that len then just append it to the end of list
225              - if less than zero then prepend to the list
226              - indexing starts from 0
227    */
228   void InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
229                               const int                      theTag = 0,
230                               const int                      theBeforeIndex = 0 );
231
232   /**
233    * Internal method that used to store the reference object label attribute
234    * \param theObjects sequence with pointers to reference objects
235    * \param theTag tag of a label to store attribute (for 0 this is myLab)
236    */
237   void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
238                             const int                          theTag = 0 );
239
240   /**
241    * Internal method that used to retreive the reference object(s) attribute
242    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
243    * \param theIndex index in the list of references 
244    *        - indexing starts from 0
245    * \returns pointer to reference object or NULL if label is not set
246    */
247   Handle_HYDROData_Entity GetReferenceObject( const int theTag   = 0,
248                                               const int theIndex = 0 ) const;
249
250   HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
251
252   /**
253    * Internal method that used to remove the reference object attribute
254    * \param theRefLabel reference object label to remove
255    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
256    */
257   void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
258
259   /**
260    * Internal method that used to remove the reference object attribute
261    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
262    * \param theIndex index in the list of references 
263    *        - indexing starts from 0
264    */
265   void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
266
267   /**
268    * Internal method that used to clear list of the reference objects attribute
269    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
270    */
271   void ClearReferenceObjects( const int theTag = 0 );
272
273   /**
274    * Internal method that used to store the color attribute
275    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
276    * \param theColor color to save
277    */
278   void SetColor( const QColor& theColor, const int theTag = 0 );
279
280   /**
281    * Internal method that used to retreive the color attribute
282    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
283    * \param theDefColor default color to return if attribute has not been set before
284    */
285   QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
286
287  
288 protected:
289
290   void setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
291                                  QStringList&                    theScript,
292                                  const Handle(HYDROData_Entity)& theRefObject,
293                                  const QString&                  theMethod ) const;
294 protected:
295
296   Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
297                                                    const bool theIsCreate ) const;
298
299
300 protected:
301   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
302   TDF_Label myLab; ///< label of this object
303 };
304
305 ///! Is Equal for HYDROData_Entity mapping
306 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
307
308 #endif