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