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