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