Salome HOME
Dump to Python script correction.
[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 protected:
141
142   friend class HYDROData_Iterator;
143
144   /**
145    * Creates new object in the internal data structure. Use higher level objects 
146    * to create objects with real content.
147    */
148   HYDRODATA_EXPORT HYDROData_Entity();
149
150   /**
151    * Destructs properties of the object and object itself, removes it from the document.
152    */
153   virtual HYDRODATA_EXPORT ~HYDROData_Entity();
154
155   /**
156    * Put the object to the label of the document.
157    * \param theLabel new label of the object
158    */
159   HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
160
161   /**
162    * Internal method that used to store the byte array attribute
163    * \param theTag tag of a label to store attribute (for 0 this is myLab)
164    * \param theData pointer to bytes array
165    * \param theLen number of bytes in byte array that must be stored
166    */
167   void SaveByteArray(const int theTag, const char* theData, const int theLen);
168
169   /**
170    * Internal method that used to retreive the content of byte array attribute
171    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
172    * \param theLen number of bytes in byte array
173    * \returns pointer to the internal data structure wit harray content, 
174    *          or NULL if array size is zero
175    */
176   const char* ByteArray(const int theTag, int& theLen) const;
177
178   /**
179    * Internal method that used to store the reference object label attribute
180    * \param theObj pointer to reference object
181    * \param theTag tag of a label to store attribute (for 0 this is myLab)
182    */
183   int NbReferenceObjects( const int theTag = 0 ) 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   void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
191                            const int                      theTag = 0 );
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    * \param theIndex index in the list of references 
198              - if more that len then just append it to the end of list
199              - if less than zero then prepend to the list
200              - indexing starts from 0
201    */
202   void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
203                            const int                      theTag = 0,
204                            const int                      theIndex = 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 theBeforeIndex 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 InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
216                               const int                      theTag = 0,
217                               const int                      theBeforeIndex = 0 );
218
219   /**
220    * Internal method that used to store the reference object label attribute
221    * \param theObjects sequence with pointers to reference objects
222    * \param theTag tag of a label to store attribute (for 0 this is myLab)
223    */
224   void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
225                             const int                          theTag = 0 );
226
227   /**
228    * Internal method that used to retreive the reference object(s) attribute
229    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
230    * \param theIndex index in the list of references 
231    *        - indexing starts from 0
232    * \returns pointer to reference object or NULL if label is not set
233    */
234   Handle_HYDROData_Entity GetReferenceObject( const int theTag   = 0,
235                                               const int theIndex = 0 ) const;
236
237   HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
238
239   /**
240    * Internal method that used to remove the reference object attribute
241    * \param theRefLabel reference object label to remove
242    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
243    */
244   void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
245
246   /**
247    * Internal method that used to remove the reference object attribute
248    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
249    * \param theIndex index in the list of references 
250    *        - indexing starts from 0
251    */
252   void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
253
254   /**
255    * Internal method that used to clear list of the reference objects attribute
256    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
257    */
258   void ClearReferenceObjects( const int theTag = 0 );
259
260   /**
261    * Internal method that used to store the color attribute
262    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
263    * \param theColor color to save
264    */
265   void SetColor( const QColor& theColor, const int theTag = 0 );
266
267   /**
268    * Internal method that used to retreive the color attribute
269    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
270    * \param theDefColor default color to return if attribute has not been set before
271    */
272   QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
273
274  
275 protected:
276
277   void setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
278                                  QStringList&                    theScript,
279                                  const Handle(HYDROData_Entity)& theRefObject,
280                                  const QString&                  theMethod ) const;
281 protected:
282
283   Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
284                                                    const bool theIsCreate ) const;
285
286
287 protected:
288   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
289   TDF_Label myLab; ///< label of this object
290 };
291
292 ///! Is Equal for HYDROData_Entity mapping
293 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
294
295 #endif