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