]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Object.h
Salome HOME
Base implementation of Zone data object (Feature #31).
[modules/hydro.git] / src / HYDROData / HYDROData_Object.h
1 #ifndef HYDROData_Object_HeaderFile
2 #define HYDROData_Object_HeaderFile
3
4 #include <HYDROData.h>
5
6 #include <NCollection_Sequence.hxx>
7 #include <TDF_Label.hxx>
8 #include <QMap>
9
10 class QString;
11 class QVariant;
12 class QStringList;
13 class Handle(TDataStd_ReferenceList);
14 class Handle_HYDROData_Object;
15
16 ///! Kind of an object in a document
17 typedef int ObjectKind;
18 ///! Unrecognized object
19 const ObjectKind KIND_UNKNOWN        = 0;
20 const ObjectKind KIND_IMAGE          = 1;
21 const ObjectKind KIND_POLYLINE       = 2;
22 const ObjectKind KIND_VISUAL_STATE   = 3;
23 const ObjectKind KIND_BATHYMETRY     = 4;
24 const ObjectKind KIND_CALCULATION    = 5;
25 const ObjectKind KIND_PROFILE        = 6;
26 const ObjectKind KIND_PROFILES_GROUP = 7;
27 const ObjectKind KIND_GUIDE_LINE     = 8;
28 const ObjectKind KIND_ZONE           = 9;
29
30 DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared)
31
32 typedef QMap<QString,Handle(Standard_Transient)> MapOfTreatedObjects;
33
34 typedef NCollection_Sequence<Handle_HYDROData_Object> HYDROData_SequenceOfObjects;
35
36
37 /**\class HYDROData_Object
38  * \brief Generic class of any object in the data model.
39  *
40  * Interface for getting access to the object that belong to the data model.
41  * Managed by Document. Provides access to the common properties: 
42  * kind of an object, name.
43  */
44 class HYDROData_Object : public MMgt_TShared
45 {
46 protected:
47   /**
48    * Enumeration of tags corresponding to the persistent object parameters.
49    */
50   enum DataTag
51   {
52     DataTag_First = 0     ///< first tag, to reserve
53     // ...
54   };
55
56 public:
57   DEFINE_STANDARD_RTTI(HYDROData_Object);
58
59   /**
60    * Returns the kind of this object. Must be redefined in all objects of known type.
61    */
62   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_UNKNOWN;}
63
64   /**
65    * Returns the name of this object.
66    */
67   HYDRODATA_EXPORT QString GetName() const;
68
69   /**
70    * Updates the name of this object.
71    */
72   HYDRODATA_EXPORT void SetName(const QString& theName);
73
74   /**
75    * Dump object to Python script representation.
76    * Base implementation returns empty list,
77    * You should reimplement this function in your derived class if it
78    * has Python API and can be imported/exported from/to Python script.
79    */
80   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
81
82   /**
83    * Updates object state.
84    * Base implementation dose nothing.
85    * \param theIsForce force reupdating of data object
86    */
87   HYDRODATA_EXPORT virtual void Update( const bool theIsForce = true );
88
89   /**
90    * Returns data of object wrapped to QVariant.
91    * Base implementation returns null value.
92    */
93   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
94
95   /**
96    * Checks is object exists in the data structure.
97    * \returns true is object is not exists in the data model
98    */
99   HYDRODATA_EXPORT bool IsRemoved() const;
100
101   /**
102    * Removes object from the data structure.
103    */
104   HYDRODATA_EXPORT void Remove();
105
106   /**
107    * Returns unique integer identifier of the object (may be used for ordering of objects)
108    */
109   HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();}
110
111   /**
112    * Copies all properties of this to the destinated object.
113    * Objects must be the same type.
114    * \param theDestination initialized object (from any document) - target of copying
115    */
116   HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Object theDestination) const;
117
118   /**
119    * Returns the label of this object.
120    */
121   HYDRODATA_EXPORT TDF_Label& Label() {return myLab;}
122
123 protected:
124
125   friend class HYDROData_Iterator;
126
127   /**
128    * Creates new object in the internal data structure. Use higher level objects 
129    * to create objects with real content.
130    */
131   HYDRODATA_EXPORT HYDROData_Object();
132
133   /**
134    * Destructs properties of the object and object itself, removes it from the document.
135    */
136   virtual HYDRODATA_EXPORT ~HYDROData_Object();
137
138   /**
139    * Put the object to the label of the document.
140    * \param theLabel new label of the object
141    */
142   HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
143
144   /**
145    * Internal method that used to store the byte array attribute
146    * \param theTag tag of a label to store attribute (for 0 this is myLab)
147    * \param theData pointer to bytes array
148    * \param theLen number of bytes in byte array that must be stored
149    */
150   void SaveByteArray(const int theTag, const char* theData, const int theLen);
151
152   /**
153    * Internal method that used to retreive the content of byte array attribute
154    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
155    * \param theLen number of bytes in byte array
156    * \returns pointer to the internal data structure wit harray content, 
157    *          or NULL if array size is zero
158    */
159   const char* ByteArray(const int theTag, int& theLen) const;
160
161   /**
162    * Internal method that used to store the reference object label attribute
163    * \param theObj pointer to reference object
164    * \param theTag tag of a label to store attribute (for 0 this is myLab)
165    */
166   int NbReferenceObjects( const int theTag = 0 ) const;
167
168   /**
169    * Internal method that used to store the reference object label attribute
170    * \param theObj pointer to reference object
171    * \param theTag tag of a label to store attribute (for 0 this is myLab)
172    */
173   void AddReferenceObject( const Handle_HYDROData_Object& theObj,
174                            const int                      theTag = 0 );
175
176   /**
177    * Internal method that used to store the reference object label attribute
178    * \param theObj pointer to reference object
179    * \param theTag tag of a label to store attribute (for 0 this is myLab)
180    * \param theIndex index in the list of references 
181              - if more that len then just append it to the end of list
182              - if less than zero then prepend to the list
183              - indexing starts from 0
184    */
185   void SetReferenceObject( const Handle_HYDROData_Object& theObj,
186                            const int                      theTag = 0,
187                            const int                      theIndex = 0 );
188
189   /**
190    * Internal method that used to retreive the reference object(s) attribute
191    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
192    * \param theIndex index in the list of references 
193    *        - indexing starts from 0
194    * \returns pointer to reference object or NULL if label is not set
195    */
196   Handle_HYDROData_Object GetReferenceObject( const int theTag   = 0,
197                                               const int theIndex = 0 ) const;
198
199   HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
200
201   /**
202    * Internal method that used to remove the reference object attribute
203    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
204    * \param theIndex index in the list of references 
205    *        - indexing starts from 0
206    */
207   void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
208
209   /**
210    * Internal method that used to clear list of the reference objects attribute
211    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
212    */
213   void ClearReferenceObjects( const int theTag = 0 );
214
215 protected:
216
217   Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
218                                                    const bool theIsCreate ) const;
219
220 protected:
221   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
222   TDF_Label myLab; ///< label of this object
223 };
224
225 ///! Is Equal for HYDROData_Object mapping
226 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2);
227
228 #endif