Salome HOME
7ea49e6b1c46daa92c2d930981e8e4854a031190
[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
14 ///! Kind of an object in a document
15 typedef int ObjectKind;
16 ///! Unrecognized object
17 const ObjectKind KIND_UNKNOWN = 0;
18 const ObjectKind KIND_IMAGE = 1;
19 const ObjectKind KIND_POLYLINE = 2;
20 const ObjectKind KIND_VISUAL_STATE = 3;
21 const ObjectKind KIND_BATHYMETRY = 4;
22
23 DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared)
24
25 typedef QMap<QString,Handle(Standard_Transient)> MapOfTreatedObjects;
26
27 /**\class HYDROData_Object
28  * \brief Generic class of any object in the data model.
29  *
30  * Interface for getting access to the object that belong to the data model.
31  * Managed by Document. Provides access to the common properties: 
32  * kind of an object, name.
33  */
34 class HYDROData_Object : public MMgt_TShared
35 {
36 protected:
37   /**
38    * Enumeration of tags corresponding to the persistent object parameters.
39    */
40   enum DataTag
41   {
42     DataTag_First = 0     ///< first tag, to reserve
43     // ...
44   };
45
46 public:
47   DEFINE_STANDARD_RTTI(HYDROData_Object);
48
49   /**
50    * Returns the kind of this object. Must be redefined in all objects of known type.
51    */
52   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_UNKNOWN;}
53
54   /**
55    * Returns the name of this object.
56    */
57   HYDRODATA_EXPORT QString GetName() const;
58
59   /**
60    * Updates the name of this object.
61    */
62   HYDRODATA_EXPORT void SetName(const QString& theName);
63
64   /**
65    * Dump object to Python script representation.
66    * Base implementation returns empty list,
67    * You should reimplement this function in your derived class if it
68    * has Python API and can be imported/exported from/to Python script.
69    */
70   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
71
72   /**
73    * Updates object state.
74    * Base implementation dose nothing.
75    */
76   HYDRODATA_EXPORT virtual void Update();
77
78   /**
79    * Returns data of object wrapped to QVariant.
80    * Base implementation returns null value.
81    */
82   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
83
84   /**
85    * Checks is object exists in the data structure.
86    * \returns true is object is not exists in the data model
87    */
88   HYDRODATA_EXPORT bool IsRemoved() const;
89
90   /**
91    * Removes object from the data structure.
92    */
93   HYDRODATA_EXPORT void Remove();
94
95   /**
96    * Returns unique integer identifier of the object (may be used for ordering of objects)
97    */
98   HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();}
99
100   /**
101    * Copies all properties of this to the destinated object.
102    * Objects must be the same type.
103    * \param theDestination initialized object (from any document) - target of copying
104    */
105   HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Object theDestination) const;
106
107   /**
108    * Returns the label of this object.
109    */
110   HYDRODATA_EXPORT TDF_Label& Label() {return myLab;}
111
112 protected:
113
114   friend class HYDROData_Iterator;
115
116   /**
117    * Creates new object in the internal data structure. Use higher level objects 
118    * to create objects with real content.
119    */
120   HYDRODATA_EXPORT HYDROData_Object();
121
122   /**
123    * Destructs properties of the object and object itself, removes it from the document.
124    */
125   virtual HYDRODATA_EXPORT ~HYDROData_Object();
126
127   /**
128    * Put the object to the label of the document.
129    * \param theLabel new label of the object
130    */
131   HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
132
133   /**
134    * Internal method that used to store the byte array attribute
135    * \param theTag tag of a label to store attribute (for 0 this is myLab)
136    * \param theData pointer to bytes array
137    * \param theLen number of bytes in byte array that must be stored
138    */
139   void SaveByteArray(const int theTag, const char* theData, const int theLen);
140
141   /**
142    * Internal method that used to retreive the content of byte array attribute
143    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
144    * \param theLen number of bytes in byte array
145    * \returns pointer to the internal data structure wit harray content, 
146    *          or NULL if array size is zero
147    */
148   const char* ByteArray(const int theTag, int& theLen) const;
149
150 protected:
151   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
152   TDF_Label myLab; ///< label of this object
153 };
154
155 typedef NCollection_Sequence<Handle_HYDROData_Object> HYDROData_SequenceOfObjects;
156
157 ///! Is Equal for HYDROData_Object mapping
158 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2);
159
160 #endif