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