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