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