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>
32 class TDataStd_ReferenceList;
33 class HYDROData_Entity;
36 ///! Kind of an object in a document
37 typedef int ObjectKind;
39 const ObjectKind KIND_UNKNOWN = 0; ///! Unrecognized object
40 const ObjectKind KIND_IMAGE = 1;
41 const ObjectKind KIND_POLYLINE = 2;
42 const ObjectKind KIND_BATHYMETRY = 3;
43 const ObjectKind KIND_ALTITUDE = 4;
44 const ObjectKind KIND_IMMERSIBLE_ZONE = 5;
45 const ObjectKind KIND_RIVER = 6;
46 const ObjectKind KIND_STREAM = 7;
47 const ObjectKind KIND_CONFLUENCE = 8;
48 const ObjectKind KIND_CHANNEL = 9;
49 const ObjectKind KIND_OBSTACLE = 10;
50 const ObjectKind KIND_DIGUE = 11;
51 const ObjectKind KIND_PROFILE = 12;
52 const ObjectKind KIND_PROFILEUZ = 13;
53 const ObjectKind KIND_POLYLINEXY = 14;
54 const ObjectKind KIND_CALCULATION = 15;
55 const ObjectKind KIND_ZONE = 16;
56 const ObjectKind KIND_REGION = 17;
57 const ObjectKind KIND_VISUAL_STATE = 18;
58 const ObjectKind KIND_ARTIFICIAL_OBJECT = 19;
59 const ObjectKind KIND_NATURAL_OBJECT = 20;
60 const ObjectKind KIND_DUMMY_3D = 21;
61 const ObjectKind KIND_SHAPES_GROUP = 22;
62 const ObjectKind KIND_SPLIT_GROUP = 23;
63 const ObjectKind KIND_STREAM_ALTITUDE = 24;
64 const ObjectKind KIND_OBSTACLE_ALTITUDE = 25;
65 const ObjectKind KIND_STRICKLER_TABLE = 26;
66 const ObjectKind KIND_LAND_COVER_OBSOLETE = 27;
67 const ObjectKind KIND_CHANNEL_ALTITUDE = 28;
68 const ObjectKind KIND_LAND_COVER_MAP = 29;
69 const ObjectKind KIND_DTM = 30;
70 const ObjectKind KIND_LAST = KIND_DTM;
72 class MapOfTreatedObjects : public QMap<QString,Handle(Standard_Transient)>
76 class HYDRODATA_EXPORT HYDROData_SequenceOfObjects : public NCollection_Sequence<Handle(HYDROData_Entity)>
79 HYDROData_SequenceOfObjects();
80 HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& );
81 HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle(HYDROData_Entity)>& );
84 ///! Is Equal for HYDROData_Entity mapping
85 HYDRODATA_EXPORT bool IsEqual(const Handle(HYDROData_Entity)& theObj1, const Handle(HYDROData_Entity)& theObj2);
87 /**\class HYDROData_Entity
88 * \brief Generic class of any object in the data model.
90 * Interface for getting access to the object that belong to the data model.
91 * Managed by Document. Provides access to the common properties:
92 * kind of an object, name.
94 class HYDROData_Entity : public MMgt_TShared
98 * Enumeration of tags corresponding to the persistent object parameters.
102 DataTag_First = 0, ///< first tag, to reserve
103 DataTag_ZLevel, ///< z-level of object presentation
105 DataTag_DefaultName, ///< to keep the automatic name, useful in Python dump
116 Geom_3d = Geom_2d | Geom_Z,
117 Geom_2d_and_groups = Geom_2d | Geom_Groups,
118 Geom_All = Geom_3d | Geom_Groups | Geom_No,
122 DEFINE_STANDARD_RTTIEXT(HYDROData_Entity, MMgt_TShared);
125 * Returns the kind of this object. Must be redefined in all objects of known type.
127 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
130 * Returns the name of this object.
132 HYDRODATA_EXPORT virtual QString GetName() const;
135 * Returns the default name of this object.
137 HYDRODATA_EXPORT virtual QString GetDefaultName() const;
140 * Updates the name of this object.
142 HYDRODATA_EXPORT void SetName( const QString& theName, bool isDefault = false );
145 * Returns the name of this object valid for Python script.
147 HYDRODATA_EXPORT virtual QString GetObjPyName() const;
150 * Dump object to Python script representation.
151 * Base implementation returns empty list,
152 * You should reimplement this function in your derived class if it
153 * has Python API and can be imported/exported from/to Python script.
155 HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
156 MapOfTreatedObjects& theTreatedObjects ) const;
159 * Updates object state. Base implementation dose nothing.
161 HYDRODATA_EXPORT virtual void Update();
163 HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
166 * Checks that object has 2D presentation. Base implementation returns false.
168 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
171 * Show object at the top of other model objects.
173 HYDRODATA_EXPORT virtual void Show();
177 * Returns data of object wrapped to QVariant.
178 * Base implementation returns null value.
180 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
184 HYDRODATA_EXPORT virtual void ClearChanged();
185 HYDRODATA_EXPORT virtual void Changed( Geometry );
187 HYDRODATA_EXPORT bool IsMustBeUpdated( Geometry ) const;
190 * Returns flag indicating that object is updateble or not.
192 HYDRODATA_EXPORT virtual bool CanBeUpdated() const;
196 * Checks is object exists in the data structure.
197 * \returns true is object is not exists in the data model
199 HYDRODATA_EXPORT bool IsRemoved() const;
202 * Removes object and it child sub-objects from the data structure.
204 HYDRODATA_EXPORT virtual void Remove();
207 * Returns flag indicating that object can be removed or not.
208 * Reimplement this method in class which can't be removed
209 * separately with it parent object.
210 * Base implementaiton returns always TRUE.
212 HYDRODATA_EXPORT virtual bool CanRemove();
215 * Copies all properties of this to the destinated object.
216 * Objects must be the same type.
217 * \param theDestination initialized object (from any document) - target of copying
219 HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination,
220 bool isGenerateNewName ) const;
223 * Returns the label of this object.
225 HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
229 * Returns father object. For object created under root document label
230 * this method always return NULL object.
232 HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
236 * Returns the list of all reference objects of this object.
237 * Base implementation always return empty list.
239 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
243 * Returns the z-level for object presentation, -1 if no z-level.
245 HYDRODATA_EXPORT virtual bool GetZLevel( Standard_Integer& theLevel ) const;
248 * Set the z-level for object presentation.
250 HYDRODATA_EXPORT virtual void SetZLevel( const Standard_Integer& theLevel );
253 * Remove the z-level of object presentation.
255 HYDRODATA_EXPORT virtual void RemoveZLevel();
258 Add in Python script the find instruction, to retrieve the Python object in the document by the object name.
259 @param theScript the script
260 @param defName the name to use, if not default name.
262 void findPythonReferenceObject( QStringList& theScript,
263 QString defName = QString()) const;
266 Add in Python script the set name instruction.
267 @param theScript the script
268 @param defName the name to use, if not default name.
270 void SetNameInDumpPython(QStringList& theScript,
271 QString theName = QString()) const;
274 * Internal method that used to store the color attribute
275 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
276 * \param theColor color to save
278 HYDRODATA_EXPORT void SetColor( const QColor& theColor, const int theTag = 0 );
281 * Internal method that used to retreive the color attribute
282 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
283 * \param theDefColor default color to return if attribute has not been set before
285 HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
289 friend class HYDROData_Iterator;
292 * Creates new object in the internal data structure. Use higher level objects
293 * to create objects with real content.
295 HYDRODATA_EXPORT HYDROData_Entity( Geometry );
298 * Destructs properties of the object and object itself, removes it from the document.
300 virtual HYDRODATA_EXPORT ~HYDROData_Entity();
303 * Put the object to the label of the document.
304 * \param theLabel new label of the object
306 HYDRODATA_EXPORT virtual void SetLabel( const TDF_Label& theLabel );
309 * Internal method that used to store the byte array attribute
310 * \param theTag tag of a label to store attribute (for 0 this is myLab)
311 * \param theData pointer to bytes array
312 * \param theLen number of bytes in byte array that must be stored
314 void SaveByteArray(const int theTag, const char* theData, const int theLen);
317 * Internal method that used to retreive the content of byte array attribute
318 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
319 * \param theLen number of bytes in byte array
320 * \returns pointer to the internal data structure wit harray content,
321 * or NULL if array size is zero
323 const char* ByteArray(const int theTag, int& theLen) const;
326 * Internal method that used to store the reference object label attribute
327 * \param theObj pointer to reference object
328 * \param theTag tag of a label to store attribute (for 0 this is myLab)
330 int NbReferenceObjects( const int theTag = 0 ) const;
333 * Internal method that used to check object for entry into the reference list
334 * \param theObj pointer to reference object
335 * \param theTag tag of a label to store attribute (for 0 this is myLab)
337 bool HasReference( const Handle(HYDROData_Entity)& theObj,
338 const int theTag = 0 ) const;
341 * Internal method that used to store the reference object label attribute
342 * \param theObj pointer to reference object
343 * \param theTag tag of a label to store attribute (for 0 this is myLab)
345 void AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
346 const int theTag = 0 );
349 * Internal method that used to store the reference object label attribute
350 * \param theObj pointer to reference object
351 * \param theTag tag of a label to store attribute (for 0 this is myLab)
352 * \param theIndex index in the list of references
353 - if more that len then just append it to the end of list
354 - if less than zero then prepend to the list
355 - indexing starts from 0
357 void SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
358 const int theTag = 0,
359 const int theIndex = 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 theBeforeIndex 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 InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
371 const int theTag = 0,
372 const int theBeforeIndex = 0 );
375 * Internal method that used to store the reference object label attribute
376 * \param theObjects sequence with pointers to reference objects
377 * \param theTag tag of a label to store attribute (for 0 this is myLab)
379 void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
380 const int theTag = 0 );
383 * Internal method that used to retreive the reference object(s) attribute
384 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
385 * \param theIndex index in the list of references
386 * - indexing starts from 0
387 * \returns pointer to reference object or NULL if label is not set
389 Handle(HYDROData_Entity) GetReferenceObject( const int theTag = 0,
390 const int theIndex = 0 ) const;
392 HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
395 * Internal method that used to remove the reference object attribute
396 * \param theRefLabel reference object label to remove
397 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
399 void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
402 * Internal method that used to remove the reference object attribute
403 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
404 * \param theIndex index in the list of references
405 * - indexing starts from 0
407 void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
410 * Internal method that used to clear list of the reference objects attribute
411 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
413 void ClearReferenceObjects( const int theTag = 0 );
417 virtual bool CompareLabels(const Handle(HYDROData_Entity)& theOtherObj);
422 * Dump the initial object creation to a Python script.
423 * You should call it from DumpToPython implementation before
424 * dumping fields of the object.
426 HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
429 * Returns an object type name as a string for dumping to Python.
431 QString getPyTypeID() const;
433 void setPythonReferenceObject( const QString& thePyScriptPath,
434 MapOfTreatedObjects& theTreatedObjects,
435 QStringList& theScript,
436 const Handle(HYDROData_Entity)& theRefObject,
437 const QString& theMethod ) const;
439 bool checkObjectPythonDefinition( const QString& thePyScriptPath,
440 MapOfTreatedObjects& theTreatedObjects,
441 QStringList& theScript,
442 const Handle(HYDROData_Entity)& theRefObject ) const;
444 void setPythonObjectColor( QStringList& theScript,
445 const QColor& theColor,
446 const QColor& theDefaultColor,
447 const QString& theMethod ) const;
450 Handle(TDataStd_ReferenceList) getReferenceList( const int theTag,
451 const bool theIsCreate ) const;
453 void SetShape( int theTag, const TopoDS_Shape& theShape );
454 TopoDS_Shape GetShape( int theTag ) const;
456 void SetDouble( int theTag, double theValue );
457 double GetDouble( int theTag, double theDefValue = 0.0 ) const;
459 void SetInteger( int theTag, int theValue );
460 int GetInteger( int theTag, int theDefValue = 0 ) const;
463 int GetGeomChangeFlag() const;
466 /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
467 TDF_Label myLab; ///< label of this object