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