Salome HOME
Undo/Redo operation.
[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 <QString>
9
10 ///! Kind of an object in a document
11 typedef int ObjectKind;
12 ///! Unrecognized object
13 const ObjectKind KIND_UNKNOWN = 0;
14 const ObjectKind KIND_IMAGE = 1;
15
16 DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared)
17
18 /**\class HYDROData_Object
19  * \brief Generic class of any object in the data model.
20  *
21  * Interface for getting access to the object that belong to the data model.
22  * Managed by Document. Provides access to the common properties: 
23  * kind of an object, name.
24  */
25 class HYDROData_Object : public MMgt_TShared
26 {
27 public:
28   DEFINE_STANDARD_RTTI(HYDROData_Object);
29
30   /**
31    * Returns the kind of this object. Must be redefined in all objects of known type.
32    */
33   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const {return KIND_UNKNOWN;}
34
35   /**
36    * Returns the name of this object.
37    */
38   HYDRODATA_EXPORT QString GetName() const;
39
40   /**
41    * Updates the name of this object.
42    */
43   HYDRODATA_EXPORT void SetName(const QString& theName);
44
45   /**
46    * Checks is object exists in the data structure.
47    * \returns true is object is not exists in the data model
48    */
49   HYDRODATA_EXPORT bool IsRemoved() const;
50
51   /**
52    * Removes object from the data structure.
53    */
54   HYDRODATA_EXPORT void Remove();
55
56   /**
57    * Returns unique integer identifier of the object (may be used for ordering of objects)
58    */
59   HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();}
60
61   /**
62    * Copies all properties of this to the destinated object.
63    * Objects must be the same type.
64    * \param theDestination initialized object (from any document) - target of copying
65    */
66   HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Object theDestination) const;
67
68   /**
69    * Returns the label of this object.
70    */
71   HYDRODATA_EXPORT TDF_Label& Label() {return myLab;}
72
73 protected:
74
75   friend class HYDROData_Iterator;
76
77   /**
78    * Creates new object in the internal data structure. Use higher level objects 
79    * to create objects with real content.
80    */
81   HYDRODATA_EXPORT HYDROData_Object();
82
83   /**
84    * Destructs properties of the object and object itself, removes it from the document.
85    */
86   virtual HYDRODATA_EXPORT ~HYDROData_Object();
87
88   /**
89    * Put the object to the label of the document.
90    * \param theLabel new label of the object
91    */
92   HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
93
94   /**
95    * Internal method that used to store the byte array attribute
96    * \param theTag tag of a label to store attribute (for 0 this is myLab)
97    * \param theData pointer to bytes array
98    * \param theLen number of bytes in byte array that must be stored
99    */
100   void SaveByteArray(const int theTag, const char* theData, const int theLen);
101
102   /**
103    * Internal method that used to retreive the content of byte array attribute
104    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
105    * \param theLen number of bytes in byte array
106    * \returns pointer to the internal data structure wit harray content, 
107    *          or NULL if array size is zero
108    */
109   const char* ByteArray(const int theTag, int& theLen);
110
111 protected:
112   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
113   TDF_Label myLab; ///< label of this object
114 };
115
116 typedef NCollection_Sequence<Handle_HYDROData_Object> HYDROData_SequenceOfObjects;
117
118 ///! Is Equal for HYDROData_Object mapping
119 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2);
120
121 #endif