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"
23 #include <NCollection_Sequence.hxx>
24 #include <TDF_Label.hxx>
27 #include <Standard_Type.hxx>
28 #include <MMgt_TShared.hxx>
41 class TDataStd_ReferenceList;
42 class HYDROData_Entity;
45 ///! Kind of an object in a document
46 typedef int ObjectKind;
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_LAST = KIND_BC_POLYGON+1;
82 class MapOfTreatedObjects : public QMap<QString,Handle(Standard_Transient)>
86 class HYDRODATA_EXPORT HYDROData_SequenceOfObjects : public NCollection_Sequence<Handle(HYDROData_Entity)>
89 HYDROData_SequenceOfObjects();
90 HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& );
91 HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle(HYDROData_Entity)>& );
94 ///! Is Equal for HYDROData_Entity mapping
95 HYDRODATA_EXPORT bool IsEqual(const Handle(HYDROData_Entity)& theObj1, const Handle(HYDROData_Entity)& theObj2);
97 /**\class HYDROData_Entity
98 * \brief Generic class of any object in the data model.
100 * Interface for getting access to the object that belong to the data model.
101 * Managed by Document. Provides access to the common properties:
102 * kind of an object, name.
104 class HYDROData_Entity : public MMgt_TShared
108 * Enumeration of tags corresponding to the persistent object parameters.
112 DataTag_First = 0, ///< first tag, to reserve
113 DataTag_ZLevel, ///< z-level of object presentation
115 DataTag_DefaultName, ///< to keep the automatic name, useful in Python dump
126 Geom_3d = Geom_2d | Geom_Z,
127 Geom_2d_and_groups = Geom_2d | Geom_Groups,
128 Geom_All = Geom_3d | Geom_Groups | Geom_No,
132 DEFINE_STANDARD_RTTIEXT(HYDROData_Entity, MMgt_TShared);
134 HYDRODATA_EXPORT static QString Type( ObjectKind );
135 HYDRODATA_EXPORT virtual QString GetType() const;
138 * Returns the kind of this object. Must be redefined in all objects of known type.
140 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
143 * Returns the name of this object.
145 HYDRODATA_EXPORT virtual QString GetName() const;
148 * Returns the default name of this object.
150 HYDRODATA_EXPORT virtual QString GetDefaultName() const;
153 * Updates the name of this object.
155 HYDRODATA_EXPORT void SetName( const QString& theName, bool isDefault = false );
158 * Returns the name of this object valid for Python script.
160 HYDRODATA_EXPORT virtual QString GetObjPyName() const;
163 * Dump object to Python script representation.
164 * Base implementation returns empty list,
165 * You should reimplement this function in your derived class if it
166 * has Python API and can be imported/exported from/to Python script.
168 HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
169 MapOfTreatedObjects& theTreatedObjects ) const;
172 * Updates object state. Base implementation dose nothing.
174 HYDRODATA_EXPORT virtual void Update();
176 HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
179 * Checks that object has 2D presentation. Base implementation returns false.
181 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
184 * Show object at the top of other model objects.
186 HYDRODATA_EXPORT virtual void Show();
190 * Returns data of object wrapped to QVariant.
191 * Base implementation returns null value.
193 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
197 HYDRODATA_EXPORT virtual void ClearChanged();
198 HYDRODATA_EXPORT virtual void Changed( Geometry );
200 HYDRODATA_EXPORT bool IsMustBeUpdated( Geometry ) const;
203 * Returns flag indicating that object is updateble or not.
205 HYDRODATA_EXPORT virtual bool CanBeUpdated() const;
209 * Checks is object exists in the data structure.
210 * \returns true is object is not exists in the data model
212 HYDRODATA_EXPORT bool IsRemoved() const;
215 * Removes object and it child sub-objects from the data structure.
217 HYDRODATA_EXPORT virtual void Remove();
220 * Returns flag indicating that object can be removed or not.
221 * Reimplement this method in class which can't be removed
222 * separately with it parent object.
223 * Base implementaiton returns always TRUE.
225 HYDRODATA_EXPORT virtual bool CanRemove();
228 * Copies all properties of this to the destinated object.
229 * Objects must be the same type.
230 * \param theDestination initialized object (from any document) - target of copying
232 HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination,
233 bool isGenerateNewName ) const;
236 * Returns the label of this object.
238 HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
242 * Returns father object. For object created under root document label
243 * this method always return NULL object.
245 HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
249 * Returns the list of all reference objects of this object.
250 * Base implementation always return empty list.
252 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
256 * Returns the z-level for object presentation, -1 if no z-level.
258 HYDRODATA_EXPORT virtual bool GetZLevel( Standard_Integer& theLevel ) const;
261 * Set the z-level for object presentation.
263 HYDRODATA_EXPORT virtual void SetZLevel( const Standard_Integer& theLevel );
266 * Remove the z-level of object presentation.
268 HYDRODATA_EXPORT virtual void RemoveZLevel();
271 Add in Python script the find instruction, to retrieve the Python object in the document by the object name.
272 @param theScript the script
273 @param defName the name to use, if not default name.
275 void findPythonReferenceObject( QStringList& theScript,
276 QString defName = QString()) const;
279 Add in Python script the set name instruction.
280 @param theScript the script
281 @param defName the name to use, if not default name.
283 void SetNameInDumpPython(QStringList& theScript,
284 QString theName = QString()) const;
287 * Internal method that used to store the color attribute
288 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
289 * \param theColor color to save
291 HYDRODATA_EXPORT void SetColor( const QColor& theColor, const int theTag = 0 );
294 * Internal method that used to retreive the color attribute
295 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
296 * \param theDefColor default color to return if attribute has not been set before
298 HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
302 friend class HYDROData_Iterator;
305 * Creates new object in the internal data structure. Use higher level objects
306 * to create objects with real content.
308 HYDRODATA_EXPORT HYDROData_Entity( Geometry );
311 * Destructs properties of the object and object itself, removes it from the document.
313 virtual HYDRODATA_EXPORT ~HYDROData_Entity();
316 * Put the object to the label of the document.
317 * \param theLabel new label of the object
319 HYDRODATA_EXPORT virtual void SetLabel( const TDF_Label& theLabel );
322 * Internal method that used to store the byte array attribute
323 * \param theTag tag of a label to store attribute (for 0 this is myLab)
324 * \param theData pointer to bytes array
325 * \param theLen number of bytes in byte array that must be stored
327 void SaveByteArray(const int theTag, const char* theData, const int theLen);
330 * Internal method that used to retreive the content of byte array attribute
331 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
332 * \param theLen number of bytes in byte array
333 * \returns pointer to the internal data structure wit harray content,
334 * or NULL if array size is zero
336 const char* ByteArray(const int theTag, int& theLen) const;
339 * Internal method that used to store the reference object label attribute
340 * \param theObj pointer to reference object
341 * \param theTag tag of a label to store attribute (for 0 this is myLab)
343 int NbReferenceObjects( const int theTag = 0 ) const;
346 * Internal method that used to check object for entry into the reference list
347 * \param theObj pointer to reference object
348 * \param theTag tag of a label to store attribute (for 0 this is myLab)
350 bool HasReference( const Handle(HYDROData_Entity)& theObj,
351 const int theTag = 0 ) const;
354 * Internal method that used to store the reference object label attribute
355 * \param theObj pointer to reference object
356 * \param theTag tag of a label to store attribute (for 0 this is myLab)
358 void AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
359 const int theTag = 0 );
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 theIndex 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
370 void SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
371 const int theTag = 0,
372 const int theIndex = 0 );
375 * Internal method that used to store the reference object label attribute
376 * \param theObj pointer to reference object
377 * \param theTag tag of a label to store attribute (for 0 this is myLab)
378 * \param theBeforeIndex index in the list of references
379 - if more that len then just append it to the end of list
380 - if less than zero then prepend to the list
381 - indexing starts from 0
383 void InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
384 const int theTag = 0,
385 const int theBeforeIndex = 0 );
388 * Internal method that used to store the reference object label attribute
389 * \param theObjects sequence with pointers to reference objects
390 * \param theTag tag of a label to store attribute (for 0 this is myLab)
392 void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
393 const int theTag = 0 );
396 * Internal method that used to retreive the reference object(s) attribute
397 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
398 * \param theIndex index in the list of references
399 * - indexing starts from 0
400 * \returns pointer to reference object or NULL if label is not set
402 Handle(HYDROData_Entity) GetReferenceObject( const int theTag = 0,
403 const int theIndex = 0 ) const;
405 HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
408 * Internal method that used to remove the reference object attribute
409 * \param theRefLabel reference object label to remove
410 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
412 void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
415 * Internal method that used to remove the reference object attribute
416 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
417 * \param theIndex index in the list of references
418 * - indexing starts from 0
420 void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
423 * Internal method that used to clear list of the reference objects attribute
424 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
426 void ClearReferenceObjects( const int theTag = 0 );
430 HYDRODATA_EXPORT virtual bool CompareLabels(const Handle(HYDROData_Entity)& theOtherObj);
435 * Dump the initial object creation to a Python script.
436 * You should call it from DumpToPython implementation before
437 * dumping fields of the object.
439 HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
442 * Returns an object type name as a string for dumping to Python.
444 QString getPyTypeID() const;
446 void setPythonReferenceObject( const QString& thePyScriptPath,
447 MapOfTreatedObjects& theTreatedObjects,
448 QStringList& theScript,
449 const Handle(HYDROData_Entity)& theRefObject,
450 const QString& theMethod ) const;
452 bool checkObjectPythonDefinition( const QString& thePyScriptPath,
453 MapOfTreatedObjects& theTreatedObjects,
454 QStringList& theScript,
455 const Handle(HYDROData_Entity)& theRefObject ) const;
457 void setPythonObjectColor( QStringList& theScript,
458 const QColor& theColor,
459 const QColor& theDefaultColor,
460 const QString& theMethod ) const;
463 Handle(TDataStd_ReferenceList) getReferenceList( const int theTag,
464 const bool theIsCreate ) const;
466 void SetShape( int theTag, const TopoDS_Shape& theShape );
467 TopoDS_Shape GetShape( int theTag ) const;
469 void SetDouble( int theTag, double theValue );
470 double GetDouble( int theTag, double theDefValue = 0.0 ) const;
472 void SetInteger( int theTag, int theValue );
473 int GetInteger( int theTag, int theDefValue = 0 ) const;
476 int GetGeomChangeFlag() const;
479 /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
480 TDF_Label myLab; ///< label of this object