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