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