Salome HOME
993297ad76778812ca1343d005e611208f6ef2eb
[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 #include <QString>
10
11 ///! Kind of an object in a document
12 typedef int ObjectKind;
13 ///! Unrecognized object
14 const ObjectKind KIND_UNKNOWN = 0;
15 const ObjectKind KIND_IMAGE = 1;
16 const ObjectKind KIND_POLYLINE = 2;
17 const ObjectKind KIND_VISUAL_STATE = 3;
18
19 DEFINE_STANDARD_HANDLE(HYDROData_Object, MMgt_TShared)
20
21 /**\class HYDROData_Object
22  * \brief Generic class of any object in the data model.
23  *
24  * Interface for getting access to the object that belong to the data model.
25  * Managed by Document. Provides access to the common properties: 
26  * kind of an object, name.
27  */
28 class HYDROData_Object : public MMgt_TShared
29 {
30 protected:
31   /**
32    * Enumeration of tags corresponding to the persistent object parameters.
33    */
34   enum DataTag
35   {
36     DataTag_First = 0,    ///< first tag, to reserve
37     DataTag_ViewId,       ///< visual state, array of view ids
38     DataTag_Visibility,   ///< visual state, array of visibility states
39     DataTag_Transparency, ///< visual state, array of transparency values
40     DataTag_ZValue        ///< visual state, array of z-values
41   };
42
43 public:
44   /**
45    * Visual state data.
46    */
47   struct VisualState
48   {
49     bool Visibility;
50     double Transparency;
51     double ZValue;
52     VisualState() : Visibility( false ), Transparency( 1.0 ), ZValue( 0.0 ) {}
53   };
54   typedef QMap        < int, VisualState > ViewId2VisualStateMap;
55   typedef QMapIterator< int, VisualState > ViewId2VisualStateMapIterator;
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    * Returns the object visibility state for the view with specified id.
77    * \param theViewId view id
78    * \returns visibility state
79    */
80   HYDRODATA_EXPORT bool IsVisible( const int theViewId ) const;
81
82   /**
83    * Sets the object visibility state for the view with specified id.
84    * \param theViewId view id
85    * \param theVal visibility state
86    */
87   HYDRODATA_EXPORT void SetVisible( const int theViewId,
88                                     const bool theVal );
89
90   /**
91    * Checks is object exists in the data structure.
92    * \returns true is object is not exists in the data model
93    */
94   HYDRODATA_EXPORT bool IsRemoved() const;
95
96   /**
97    * Removes object from the data structure.
98    */
99   HYDRODATA_EXPORT void Remove();
100
101   /**
102    * Returns unique integer identifier of the object (may be used for ordering of objects)
103    */
104   HYDRODATA_EXPORT inline int ID() const {return myLab.Tag();}
105
106   /**
107    * Copies all properties of this to the destinated object.
108    * Objects must be the same type.
109    * \param theDestination initialized object (from any document) - target of copying
110    */
111   HYDRODATA_EXPORT void CopyTo(Handle_HYDROData_Object theDestination) const;
112
113   /**
114    * Returns the label of this object.
115    */
116   HYDRODATA_EXPORT TDF_Label& Label() {return myLab;}
117
118 protected:
119
120   friend class HYDROData_Iterator;
121
122   /**
123    * Creates new object in the internal data structure. Use higher level objects 
124    * to create objects with real content.
125    */
126   HYDRODATA_EXPORT HYDROData_Object();
127
128   /**
129    * Destructs properties of the object and object itself, removes it from the document.
130    */
131   virtual HYDRODATA_EXPORT ~HYDROData_Object();
132
133   /**
134    * Put the object to the label of the document.
135    * \param theLabel new label of the object
136    */
137   HYDRODATA_EXPORT virtual void SetLabel(TDF_Label theLabel);
138
139   /**
140    * Internal method that used to store the byte array attribute
141    * \param theTag tag of a label to store attribute (for 0 this is myLab)
142    * \param theData pointer to bytes array
143    * \param theLen number of bytes in byte array that must be stored
144    */
145   void SaveByteArray(const int theTag, const char* theData, const int theLen);
146
147   /**
148    * Internal method that used to retreive the content of byte array attribute
149    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
150    * \param theLen number of bytes in byte array
151    * \returns pointer to the internal data structure wit harray content, 
152    *          or NULL if array size is zero
153    */
154   const char* ByteArray(const int theTag, int& theLen);
155
156   /**
157    * Returns the map containing the visual states for the specified views.
158    * \param theMap map of visual states
159    */
160   void GetViewId2VisualStateMap( ViewId2VisualStateMap& theMap ) const;
161
162   /**
163    * Sets the map containing the visual states for the specified views.
164    * \param theMap map of visual states
165    */
166   void SetViewId2VisualStateMap( const ViewId2VisualStateMap& theMap );
167
168 protected:
169   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
170   TDF_Label myLab; ///< label of this object
171 };
172
173 typedef NCollection_Sequence<Handle_HYDROData_Object> HYDROData_SequenceOfObjects;
174
175 ///! Is Equal for HYDROData_Object mapping
176 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2);
177
178 #endif