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