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