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