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