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