Salome HOME
land cover object is removed from the data model
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #ifndef HYDROData_Entity_HeaderFile
20 #define HYDROData_Entity_HeaderFile
21
22 #include "HYDROData.h"
23
24 #include <NCollection_Sequence.hxx>
25
26 #include <TDF_Label.hxx>
27
28 #include <QMap>
29
30 class QColor;
31 class QString;
32 class QVariant;
33 class QStringList;
34 class Handle(TDataStd_ReferenceList);
35 class Handle_HYDROData_Entity;
36
37 ///! Kind of an object in a document
38 typedef int ObjectKind;
39
40 const ObjectKind KIND_UNKNOWN             = 0; ///! Unrecognized object
41 const ObjectKind KIND_IMAGE               = 1;
42 const ObjectKind KIND_POLYLINE            = 2;
43 const ObjectKind KIND_BATHYMETRY          = 3;
44 const ObjectKind KIND_ALTITUDE            = 4;
45 const ObjectKind KIND_IMMERSIBLE_ZONE     = 5;
46 const ObjectKind KIND_RIVER               = 6;
47 const ObjectKind KIND_STREAM              = 7;
48 const ObjectKind KIND_CONFLUENCE          = 8;
49 const ObjectKind KIND_CHANNEL             = 9;
50 const ObjectKind KIND_OBSTACLE            = 10;
51 const ObjectKind KIND_DIGUE               = 11;
52 const ObjectKind KIND_PROFILE             = 12;
53 const ObjectKind KIND_PROFILEUZ           = 13;
54 const ObjectKind KIND_POLYLINEXY          = 14;
55 const ObjectKind KIND_CALCULATION         = 15;
56 const ObjectKind KIND_ZONE                = 16;
57 const ObjectKind KIND_REGION              = 17;
58 const ObjectKind KIND_VISUAL_STATE        = 18;
59 const ObjectKind KIND_ARTIFICIAL_OBJECT   = 19;
60 const ObjectKind KIND_NATURAL_OBJECT      = 20;
61 const ObjectKind KIND_DUMMY_3D            = 21;
62 const ObjectKind KIND_SHAPES_GROUP        = 22;
63 const ObjectKind KIND_SPLITTED_GROUP      = 23;
64 const ObjectKind KIND_STREAM_ALTITUDE     = 24;
65 const ObjectKind KIND_OBSTACLE_ALTITUDE   = 25;
66 const ObjectKind KIND_STRICKLER_TABLE     = 26;
67 const ObjectKind KIND_LAND_COVER_OBSOLETE = 27;
68 const ObjectKind KIND_LAND_COVER_MAP      = 28;
69 const ObjectKind KIND_LAST                = KIND_LAND_COVER_MAP;
70
71 DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared)
72
73 class MapOfTreatedObjects : public QMap<QString,Handle(Standard_Transient)>
74 {
75 };
76
77 class HYDRODATA_EXPORT HYDROData_SequenceOfObjects : public NCollection_Sequence<Handle_HYDROData_Entity>
78 {
79 public:
80   HYDROData_SequenceOfObjects();
81   HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& );
82   HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle_HYDROData_Entity>& );
83 };
84
85 ///! Is Equal for HYDROData_Entity mapping
86 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
87
88 /**\class HYDROData_Entity
89  * \brief Generic class of any object in the data model.
90  *
91  * Interface for getting access to the object that belong to the data model.
92  * Managed by Document. Provides access to the common properties: 
93  * kind of an object, name.
94  */
95 class HYDROData_Entity : public MMgt_TShared
96 {
97
98 protected:
99
100   /**
101    * Enumeration of tags corresponding to the persistent object parameters.
102    */
103   enum DataTag
104   {
105     DataTag_First  = 0,     ///< first tag, to reserve
106     DataTag_ZLevel,         ///< z-level of object presentation
107   };
108
109 public:
110   DEFINE_STANDARD_RTTI(HYDROData_Entity);
111
112   /**
113    * Returns the kind of this object. Must be redefined in all objects of known type.
114    */
115   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
116
117   /**
118    * Returns the name of this object.
119    */
120   HYDRODATA_EXPORT virtual QString GetName() const;
121
122   /**
123    * Updates the name of this object.
124    */
125   HYDRODATA_EXPORT virtual void SetName( const QString& theName );
126
127   /**
128    * Returns the name of this object valid for Python script.
129    */
130   HYDRODATA_EXPORT virtual QString GetObjPyName() const;
131
132   /**
133    * Dump object to Python script representation.
134    * Base implementation returns empty list,
135    * You should reimplement this function in your derived class if it
136    * has Python API and can be imported/exported from/to Python script.
137    */
138   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
139
140   /**
141    * Updates object state. Base implementation dose nothing.
142    */
143   HYDRODATA_EXPORT virtual void Update();
144
145   HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
146
147   /**
148    * Checks that object has 2D presentation. Base implementation returns false.
149    */
150   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
151
152   /**
153    * Show object at the top of other model objects.
154    */
155   HYDRODATA_EXPORT virtual void Show();
156
157
158   /**
159    * Returns data of object wrapped to QVariant.
160    * Base implementation returns null value.
161    */
162   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
163
164
165   /**
166    * Sets the "MustBeUpdated" flag: if object is depended on updated features.
167    * \param theFlag is true for objects that must be updated, false for up-to-date
168    */
169   HYDRODATA_EXPORT virtual void SetToUpdate( bool theFlag );
170
171   /**
172    * Returns the "MustBeUpdated" flag: is object data must be updated or not
173    * \returns false if object is up to date
174    */
175   HYDRODATA_EXPORT virtual bool IsMustBeUpdated() const;
176
177   /**
178    * Returns flag indicating that object is updateble or not.
179    */
180   HYDRODATA_EXPORT virtual bool CanBeUpdated() const;
181
182
183   /**
184    * Checks is object exists in the data structure.
185    * \returns true is object is not exists in the data model
186    */
187   HYDRODATA_EXPORT bool IsRemoved() const;
188
189   /**
190    * Removes object and it child sub-objects from the data structure.
191    */
192   HYDRODATA_EXPORT virtual void Remove();
193
194   /**
195    * Returns flag indicating that object can be removed or not.
196    * Reimplement this method in class which can't be removed 
197    * separately with it parent object.
198    * Base implementaiton returns always TRUE.
199    */
200   HYDRODATA_EXPORT virtual bool CanRemove();
201
202   /**
203    * Copies all properties of this to the destinated object.
204    * Objects must be the same type.
205    * \param theDestination initialized object (from any document) - target of copying
206    */
207   HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination,
208                                         bool isGenerateNewName ) const;
209
210   /**
211    * Returns the label of this object.
212    */
213   HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
214
215
216   /**
217    * Returns father object. For object created under root document label
218    * this method always return NULL object.
219    */
220   HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
221
222
223   /**
224    * Returns the list of all reference objects of this object.
225    * Base implementation always return empty list.
226    */
227   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
228
229
230   /**
231    * Returns the z-level for object presentation, -1 if no z-level.
232    */
233   HYDRODATA_EXPORT virtual Standard_Boolean GetZLevel( Standard_Integer& theLevel ) const;
234
235   /**
236    * Set the z-level for object presentation.
237    */
238   HYDRODATA_EXPORT virtual void SetZLevel( const Standard_Integer& theLevel );
239
240   /**
241    * Remove the z-level of object presentation.
242    */
243   HYDRODATA_EXPORT virtual void RemoveZLevel();
244
245   /**
246     Find the Python object in the document by the object name.
247     @param theTreatedObjects the map of treated objects
248     @param theScript the script
249   */
250   void findPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
251                                   QStringList&                    theScript ) const;
252
253   /**
254    * Internal method that used to store the color attribute
255    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
256    * \param theColor color to save
257    */
258   HYDRODATA_EXPORT void SetColor( const QColor& theColor, const int theTag = 0 );
259
260   /**
261    * Internal method that used to retreive the color attribute
262    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
263    * \param theDefColor default color to return if attribute has not been set before
264    */
265   HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
266  
267 protected:
268
269   friend class HYDROData_Iterator;
270
271   /**
272    * Creates new object in the internal data structure. Use higher level objects 
273    * to create objects with real content.
274    */
275   HYDRODATA_EXPORT HYDROData_Entity();
276
277   /**
278    * Destructs properties of the object and object itself, removes it from the document.
279    */
280   virtual HYDRODATA_EXPORT ~HYDROData_Entity();
281
282   /**
283    * Put the object to the label of the document.
284    * \param theLabel new label of the object
285    */
286   HYDRODATA_EXPORT virtual void SetLabel( const TDF_Label& theLabel );
287
288   /**
289    * Internal method that used to store the byte array attribute
290    * \param theTag tag of a label to store attribute (for 0 this is myLab)
291    * \param theData pointer to bytes array
292    * \param theLen number of bytes in byte array that must be stored
293    */
294   void SaveByteArray(const int theTag, const char* theData, const int theLen);
295
296   /**
297    * Internal method that used to retreive the content of byte array attribute
298    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
299    * \param theLen number of bytes in byte array
300    * \returns pointer to the internal data structure wit harray content, 
301    *          or NULL if array size is zero
302    */
303   const char* ByteArray(const int theTag, int& theLen) const;
304
305   /**
306    * Internal method that used to store the reference object label attribute
307    * \param theObj pointer to reference object
308    * \param theTag tag of a label to store attribute (for 0 this is myLab)
309    */
310   int NbReferenceObjects( const int theTag = 0 ) const;
311
312   /**
313    * Internal method that used to check object for entry into the reference list
314    * \param theObj pointer to reference object
315    * \param theTag tag of a label to store attribute (for 0 this is myLab)
316    */
317   bool HasReference( const Handle_HYDROData_Entity& theObj,
318                      const int                      theTag = 0 ) const;
319
320   /**
321    * Internal method that used to store the reference object label attribute
322    * \param theObj pointer to reference object
323    * \param theTag tag of a label to store attribute (for 0 this is myLab)
324    */
325   void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
326                            const int                      theTag = 0 );
327
328   /**
329    * Internal method that used to store the reference object label attribute
330    * \param theObj pointer to reference object
331    * \param theTag tag of a label to store attribute (for 0 this is myLab)
332    * \param theIndex index in the list of references 
333              - if more that len then just append it to the end of list
334              - if less than zero then prepend to the list
335              - indexing starts from 0
336    */
337   void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
338                            const int                      theTag = 0,
339                            const int                      theIndex = 0 );
340
341   /**
342    * Internal method that used to store the reference object label attribute
343    * \param theObj pointer to reference object
344    * \param theTag tag of a label to store attribute (for 0 this is myLab)
345    * \param theBeforeIndex index in the list of references 
346              - if more that len then just append it to the end of list
347              - if less than zero then prepend to the list
348              - indexing starts from 0
349    */
350   void InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
351                               const int                      theTag = 0,
352                               const int                      theBeforeIndex = 0 );
353
354   /**
355    * Internal method that used to store the reference object label attribute
356    * \param theObjects sequence with pointers to reference objects
357    * \param theTag tag of a label to store attribute (for 0 this is myLab)
358    */
359   void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
360                             const int                          theTag = 0 );
361
362   /**
363    * Internal method that used to retreive the reference object(s) attribute
364    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
365    * \param theIndex index in the list of references 
366    *        - indexing starts from 0
367    * \returns pointer to reference object or NULL if label is not set
368    */
369   Handle_HYDROData_Entity GetReferenceObject( const int theTag   = 0,
370                                               const int theIndex = 0 ) const;
371
372   HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
373
374   /**
375    * Internal method that used to remove the reference object attribute
376    * \param theRefLabel reference object label to remove
377    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
378    */
379   void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
380
381   /**
382    * Internal method that used to remove the reference object attribute
383    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
384    * \param theIndex index in the list of references 
385    *        - indexing starts from 0
386    */
387   void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
388
389   /**
390    * Internal method that used to clear list of the reference objects attribute
391    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
392    */
393   void ClearReferenceObjects( const int theTag = 0 );
394   
395 protected:
396
397   /**
398    * Dump the initial object creation to a Python script.
399    * You should call it from DumpToPython implementation before 
400    * dumping fields of the object.
401    */
402   HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
403
404   /**
405    * Returns an object type name as a string for dumping to Python.
406    */
407   QString getPyTypeID() const;
408
409   void setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
410                                  QStringList&                    theScript,
411                                  const Handle(HYDROData_Entity)& theRefObject,
412                                  const QString&                  theMethod ) const;
413
414   bool checkObjectPythonDefinition( MapOfTreatedObjects&            theTreatedObjects,
415                                     QStringList&                    theScript,
416                                     const Handle(HYDROData_Entity)& theRefObject ) const;
417
418   void setPythonObjectColor( QStringList&         theScript,
419                              const QColor&        theColor,
420                              const QColor&        theDefaultColor,
421                              const QString&       theMethod ) const;
422
423 protected:
424
425   Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
426                                                    const bool theIsCreate ) const;
427
428
429 protected:
430   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
431   TDF_Label myLab; ///< label of this object
432 };
433
434 #endif