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