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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDROData_Entity_HeaderFile
20 #define HYDROData_Entity_HeaderFile
22 #include "HYDROData.h"
24 #include <NCollection_Sequence.hxx>
26 #include <TDF_Label.hxx>
34 class Handle(TDataStd_ReferenceList);
35 class Handle_HYDROData_Entity;
37 ///! Kind of an object in a document
38 typedef int ObjectKind;
40 const ObjectKind KIND_UNKNOWN = 0; ///! Unrecognized object
41 const ObjectKind KIND_IMAGE = 1;
42 const ObjectKind KIND_POLYLINE = 2;
43 const ObjectKind KIND_BATHYMETRY = 3;
44 const ObjectKind KIND_ALTITUDE = 4;
45 const ObjectKind KIND_IMMERSIBLE_ZONE = 5;
46 const ObjectKind KIND_RIVER = 6;
47 const ObjectKind KIND_STREAM = 7;
48 const ObjectKind KIND_CONFLUENCE = 8;
49 const ObjectKind KIND_CHANNEL = 9;
50 const ObjectKind KIND_OBSTACLE = 10;
51 const ObjectKind KIND_DIGUE = 11;
52 const ObjectKind KIND_PROFILE = 12;
53 const ObjectKind KIND_PROFILEUZ = 13;
54 const ObjectKind KIND_POLYLINEXY = 14;
55 const ObjectKind KIND_CALCULATION = 15;
56 const ObjectKind KIND_ZONE = 16;
57 const ObjectKind KIND_REGION = 17;
58 const ObjectKind KIND_VISUAL_STATE = 18;
59 const ObjectKind KIND_ARTIFICIAL_OBJECT = 19;
60 const ObjectKind KIND_NATURAL_OBJECT = 20;
61 const ObjectKind KIND_DUMMY_3D = 21;
62 const ObjectKind KIND_SHAPES_GROUP = 22;
63 const ObjectKind KIND_SPLITTED_GROUP = 23;
64 const ObjectKind KIND_STREAM_ALTITUDE = 24;
65 const ObjectKind KIND_OBSTACLE_ALTITUDE = 25;
66 const ObjectKind KIND_STRICKLER_TABLE = 26;
67 const ObjectKind KIND_LAND_COVER = 27;
68 const ObjectKind KIND_LAST = KIND_LAND_COVER;
70 DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared)
72 typedef QMap<QString,Handle(Standard_Transient)> MapOfTreatedObjects;
74 typedef NCollection_Sequence<Handle_HYDROData_Entity> HYDROData_SequenceOfObjects;
76 ///! Is Equal for HYDROData_Entity mapping
77 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
79 /**\class HYDROData_Entity
80 * \brief Generic class of any object in the data model.
82 * Interface for getting access to the object that belong to the data model.
83 * Managed by Document. Provides access to the common properties:
84 * kind of an object, name.
86 class HYDROData_Entity : public MMgt_TShared
92 * Enumeration of tags corresponding to the persistent object parameters.
96 DataTag_First = 0, ///< first tag, to reserve
97 DataTag_ZLevel, ///< z-level of object presentation
101 DEFINE_STANDARD_RTTI(HYDROData_Entity);
104 * Returns the kind of this object. Must be redefined in all objects of known type.
106 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
109 * Returns the name of this object.
111 HYDRODATA_EXPORT virtual QString GetName() const;
114 * Updates the name of this object.
116 HYDRODATA_EXPORT virtual void SetName( const QString& theName );
119 * Returns the name of this object valid for Python script.
121 HYDRODATA_EXPORT virtual QString GetObjPyName() const;
124 * Dump object to Python script representation.
125 * Base implementation returns empty list,
126 * You should reimplement this function in your derived class if it
127 * has Python API and can be imported/exported from/to Python script.
129 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
132 * Updates object state. Base implementation dose nothing.
134 HYDRODATA_EXPORT virtual void Update();
136 HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
139 * Checks that object has 2D presentation. Base implementation returns false.
141 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
144 * Show object at the top of other model objects.
146 HYDRODATA_EXPORT virtual void Show();
150 * Returns data of object wrapped to QVariant.
151 * Base implementation returns null value.
153 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
157 * Sets the "MustBeUpdated" flag: if object is depended on updated features.
158 * \param theFlag is true for objects that must be updated, false for up-to-date
160 HYDRODATA_EXPORT virtual void SetToUpdate( bool theFlag );
163 * Returns the "MustBeUpdated" flag: is object data must be updated or not
164 * \returns false if object is up to date
166 HYDRODATA_EXPORT virtual bool IsMustBeUpdated() const;
169 * Returns flag indicating that object is updateble or not.
171 HYDRODATA_EXPORT virtual bool CanBeUpdated() const;
175 * Checks is object exists in the data structure.
176 * \returns true is object is not exists in the data model
178 HYDRODATA_EXPORT bool IsRemoved() const;
181 * Removes object and it child sub-objects from the data structure.
183 HYDRODATA_EXPORT virtual void Remove();
186 * Returns flag indicating that object can be removed or not.
187 * Reimplement this method in class which can't be removed
188 * separately with it parent object.
189 * Base implementaiton returns always TRUE.
191 HYDRODATA_EXPORT virtual bool CanRemove();
194 * Copies all properties of this to the destinated object.
195 * Objects must be the same type.
196 * \param theDestination initialized object (from any document) - target of copying
198 HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination ) const;
201 * Returns the label of this object.
203 HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
207 * Returns father object. For object created under root document label
208 * this method always return NULL object.
210 HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
214 * Returns the list of all reference objects of this object.
215 * Base implementation always return empty list.
217 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
221 * Returns the z-level for object presentation, -1 if no z-level.
223 HYDRODATA_EXPORT virtual Standard_Boolean GetZLevel( Standard_Integer& theLevel ) const;
226 * Set the z-level for object presentation.
228 HYDRODATA_EXPORT virtual void SetZLevel( const Standard_Integer& theLevel );
231 * Remove the z-level of object presentation.
233 HYDRODATA_EXPORT virtual void RemoveZLevel();
236 Find the Python object in the document by the object name.
237 @param theTreatedObjects the map of treated objects
238 @param theScript the script
240 void findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
241 QStringList& theScript ) const;
244 * Internal method that used to store the color attribute
245 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
246 * \param theColor color to save
248 HYDRODATA_EXPORT void SetColor( const QColor& theColor, const int theTag = 0 );
251 * Internal method that used to retreive the color attribute
252 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
253 * \param theDefColor default color to return if attribute has not been set before
255 HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
259 friend class HYDROData_Iterator;
262 * Creates new object in the internal data structure. Use higher level objects
263 * to create objects with real content.
265 HYDRODATA_EXPORT HYDROData_Entity();
268 * Destructs properties of the object and object itself, removes it from the document.
270 virtual HYDRODATA_EXPORT ~HYDROData_Entity();
273 * Put the object to the label of the document.
274 * \param theLabel new label of the object
276 HYDRODATA_EXPORT virtual void SetLabel( const TDF_Label& theLabel );
279 * Internal method that used to store the byte array attribute
280 * \param theTag tag of a label to store attribute (for 0 this is myLab)
281 * \param theData pointer to bytes array
282 * \param theLen number of bytes in byte array that must be stored
284 void SaveByteArray(const int theTag, const char* theData, const int theLen);
287 * Internal method that used to retreive the content of byte array attribute
288 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
289 * \param theLen number of bytes in byte array
290 * \returns pointer to the internal data structure wit harray content,
291 * or NULL if array size is zero
293 const char* ByteArray(const int theTag, int& theLen) const;
296 * Internal method that used to store the reference object label attribute
297 * \param theObj pointer to reference object
298 * \param theTag tag of a label to store attribute (for 0 this is myLab)
300 int NbReferenceObjects( const int theTag = 0 ) const;
303 * Internal method that used to check object for entry into the reference list
304 * \param theObj pointer to reference object
305 * \param theTag tag of a label to store attribute (for 0 this is myLab)
307 bool HasReference( const Handle_HYDROData_Entity& theObj,
308 const int theTag = 0 ) const;
311 * Internal method that used to store the reference object label attribute
312 * \param theObj pointer to reference object
313 * \param theTag tag of a label to store attribute (for 0 this is myLab)
315 void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
316 const int theTag = 0 );
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 * \param theIndex index in the list of references
323 - if more that len then just append it to the end of list
324 - if less than zero then prepend to the list
325 - indexing starts from 0
327 void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
328 const int theTag = 0,
329 const int theIndex = 0 );
332 * Internal method that used to store the reference object label attribute
333 * \param theObj pointer to reference object
334 * \param theTag tag of a label to store attribute (for 0 this is myLab)
335 * \param theBeforeIndex index in the list of references
336 - if more that len then just append it to the end of list
337 - if less than zero then prepend to the list
338 - indexing starts from 0
340 void InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
341 const int theTag = 0,
342 const int theBeforeIndex = 0 );
345 * Internal method that used to store the reference object label attribute
346 * \param theObjects sequence with pointers to reference objects
347 * \param theTag tag of a label to store attribute (for 0 this is myLab)
349 void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
350 const int theTag = 0 );
353 * Internal method that used to retreive the reference object(s) attribute
354 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
355 * \param theIndex index in the list of references
356 * - indexing starts from 0
357 * \returns pointer to reference object or NULL if label is not set
359 Handle_HYDROData_Entity GetReferenceObject( const int theTag = 0,
360 const int theIndex = 0 ) const;
362 HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
365 * Internal method that used to remove the reference object attribute
366 * \param theRefLabel reference object label to remove
367 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
369 void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
372 * Internal method that used to remove the reference object attribute
373 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
374 * \param theIndex index in the list of references
375 * - indexing starts from 0
377 void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
380 * Internal method that used to clear list of the reference objects attribute
381 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
383 void ClearReferenceObjects( const int theTag = 0 );
388 * Dump the initial object creation to a Python script.
389 * You should call it from DumpToPython implementation before
390 * dumping fields of the object.
392 HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
395 * Returns an object type name as a string for dumping to Python.
397 QString getPyTypeID() const;
399 void setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
400 QStringList& theScript,
401 const Handle(HYDROData_Entity)& theRefObject,
402 const QString& theMethod ) const;
404 bool checkObjectPythonDefinition( MapOfTreatedObjects& theTreatedObjects,
405 QStringList& theScript,
406 const Handle(HYDROData_Entity)& theRefObject ) const;
408 void setPythonObjectColor( QStringList& theScript,
409 const QColor& theColor,
410 const QColor& theDefaultColor,
411 const QString& theMethod ) const;
415 Handle(TDataStd_ReferenceList) getReferenceList( const int theTag,
416 const bool theIsCreate ) const;
420 /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
421 TDF_Label myLab; ///< label of this object