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 #pragma comment(lib, "C:/libecw-master/lib/NCSUtild.lib")
23 #pragma comment(lib, "C:/libecw-master/lib/NCSEcwd.lib")
25 #include "HYDROData.h"
26 #include <NCollection_Sequence.hxx>
27 #include <TDF_Label.hxx>
30 #include <Standard_Type.hxx>
44 class TDataStd_ReferenceList;
45 class HYDROData_Entity;
48 ///! Kind of an object in a document
49 typedef int ObjectKind;
51 const ObjectKind KIND_UNKNOWN = 0; ///! Unrecognized object
52 const ObjectKind KIND_IMAGE = 1;
53 const ObjectKind KIND_POLYLINE = 2;
54 const ObjectKind KIND_BATHYMETRY = 3;
55 const ObjectKind KIND_ALTITUDE = 4;
56 const ObjectKind KIND_IMMERSIBLE_ZONE = 5;
57 const ObjectKind KIND_RIVER = 6;
58 const ObjectKind KIND_STREAM = 7;
59 const ObjectKind KIND_CONFLUENCE = 8;
60 const ObjectKind KIND_CHANNEL = 9;
61 const ObjectKind KIND_OBSTACLE = 10;
62 const ObjectKind KIND_DIGUE = 11;
63 const ObjectKind KIND_PROFILE = 12;
64 const ObjectKind KIND_PROFILEUZ = 13;
65 const ObjectKind KIND_POLYLINEXY = 14;
66 const ObjectKind KIND_CALCULATION = 15;
67 const ObjectKind KIND_ZONE = 16;
68 const ObjectKind KIND_REGION = 17;
69 const ObjectKind KIND_VISUAL_STATE = 18;
70 const ObjectKind KIND_ARTIFICIAL_OBJECT = 19;
71 const ObjectKind KIND_NATURAL_OBJECT = 20;
72 const ObjectKind KIND_DUMMY_3D = 21;
73 const ObjectKind KIND_SHAPES_GROUP = 22;
74 const ObjectKind KIND_SPLIT_GROUP = 23;
75 const ObjectKind KIND_STREAM_ALTITUDE = 24;
76 const ObjectKind KIND_OBSTACLE_ALTITUDE = 25;
77 const ObjectKind KIND_STRICKLER_TABLE = 26;
78 const ObjectKind KIND_LAND_COVER_OBSOLETE = 27;
79 const ObjectKind KIND_CHANNEL_ALTITUDE = 28;
80 const ObjectKind KIND_LAND_COVER_MAP = 29;
81 const ObjectKind KIND_DTM = 30;
82 const ObjectKind KIND_LAST = KIND_DTM;
84 class MapOfTreatedObjects : public QMap<QString,Handle(Standard_Transient)>
88 class HYDRODATA_EXPORT HYDROData_SequenceOfObjects : public NCollection_Sequence<Handle(HYDROData_Entity)>
91 HYDROData_SequenceOfObjects();
92 HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& );
93 HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle(HYDROData_Entity)>& );
96 ///! Is Equal for HYDROData_Entity mapping
97 HYDRODATA_EXPORT bool IsEqual(const Handle(HYDROData_Entity)& theObj1, const Handle(HYDROData_Entity)& theObj2);
99 /**\class HYDROData_Entity
100 * \brief Generic class of any object in the data model.
102 * Interface for getting access to the object that belong to the data model.
103 * Managed by Document. Provides access to the common properties:
104 * kind of an object, name.
106 class HYDROData_Entity : public MMgt_TShared
110 * Enumeration of tags corresponding to the persistent object parameters.
114 DataTag_First = 0, ///< first tag, to reserve
115 DataTag_ZLevel, ///< z-level of object presentation
117 DataTag_DefaultName, ///< to keep the automatic name, useful in Python dump
128 Geom_3d = Geom_2d | Geom_Z,
129 Geom_2d_and_groups = Geom_2d | Geom_Groups,
130 Geom_All = Geom_3d | Geom_Groups | Geom_No,
134 DEFINE_STANDARD_RTTIEXT(HYDROData_Entity, MMgt_TShared);
137 * Returns the kind of this object. Must be redefined in all objects of known type.
139 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
142 * Returns the name of this object.
144 HYDRODATA_EXPORT virtual QString GetName() const;
147 * Returns the default name of this object.
149 HYDRODATA_EXPORT virtual QString GetDefaultName() const;
152 * Updates the name of this object.
154 HYDRODATA_EXPORT void SetName( const QString& theName, bool isDefault = false );
157 * Returns the name of this object valid for Python script.
159 HYDRODATA_EXPORT virtual QString GetObjPyName() const;
162 * Dump object to Python script representation.
163 * Base implementation returns empty list,
164 * You should reimplement this function in your derived class if it
165 * has Python API and can be imported/exported from/to Python script.
167 HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath,
168 MapOfTreatedObjects& theTreatedObjects ) const;
171 * Updates object state. Base implementation dose nothing.
173 HYDRODATA_EXPORT virtual void Update();
175 HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
178 * Checks that object has 2D presentation. Base implementation returns false.
180 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
183 * Show object at the top of other model objects.
185 HYDRODATA_EXPORT virtual void Show();
189 * Returns data of object wrapped to QVariant.
190 * Base implementation returns null value.
192 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
196 HYDRODATA_EXPORT virtual void ClearChanged();
197 HYDRODATA_EXPORT virtual void Changed( Geometry );
199 HYDRODATA_EXPORT bool IsMustBeUpdated( Geometry ) const;
202 * Returns flag indicating that object is updateble or not.
204 HYDRODATA_EXPORT virtual bool CanBeUpdated() const;
208 * Checks is object exists in the data structure.
209 * \returns true is object is not exists in the data model
211 HYDRODATA_EXPORT bool IsRemoved() const;
214 * Removes object and it child sub-objects from the data structure.
216 HYDRODATA_EXPORT virtual void Remove();
219 * Returns flag indicating that object can be removed or not.
220 * Reimplement this method in class which can't be removed
221 * separately with it parent object.
222 * Base implementaiton returns always TRUE.
224 HYDRODATA_EXPORT virtual bool CanRemove();
227 * Copies all properties of this to the destinated object.
228 * Objects must be the same type.
229 * \param theDestination initialized object (from any document) - target of copying
231 HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination,
232 bool isGenerateNewName ) const;
235 * Returns the label of this object.
237 HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
241 * Returns father object. For object created under root document label
242 * this method always return NULL object.
244 HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
248 * Returns the list of all reference objects of this object.
249 * Base implementation always return empty list.
251 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
255 * Returns the z-level for object presentation, -1 if no z-level.
257 HYDRODATA_EXPORT virtual bool GetZLevel( Standard_Integer& theLevel ) const;
260 * Set the z-level for object presentation.
262 HYDRODATA_EXPORT virtual void SetZLevel( const Standard_Integer& theLevel );
265 * Remove the z-level of object presentation.
267 HYDRODATA_EXPORT virtual void RemoveZLevel();
270 Add in Python script the find instruction, to retrieve the Python object in the document by the object name.
271 @param theScript the script
272 @param defName the name to use, if not default name.
274 void findPythonReferenceObject( QStringList& theScript,
275 QString defName = QString()) const;
278 Add in Python script the set name instruction.
279 @param theScript the script
280 @param defName the name to use, if not default name.
282 void SetNameInDumpPython(QStringList& theScript,
283 QString theName = QString()) const;
286 * Internal method that used to store the color attribute
287 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
288 * \param theColor color to save
290 HYDRODATA_EXPORT void SetColor( const QColor& theColor, const int theTag = 0 );
293 * Internal method that used to retreive the color attribute
294 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
295 * \param theDefColor default color to return if attribute has not been set before
297 HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
301 friend class HYDROData_Iterator;
304 * Creates new object in the internal data structure. Use higher level objects
305 * to create objects with real content.
307 HYDRODATA_EXPORT HYDROData_Entity( Geometry );
310 * Destructs properties of the object and object itself, removes it from the document.
312 virtual HYDRODATA_EXPORT ~HYDROData_Entity();
315 * Put the object to the label of the document.
316 * \param theLabel new label of the object
318 HYDRODATA_EXPORT virtual void SetLabel( const TDF_Label& theLabel );
321 * Internal method that used to store the byte array attribute
322 * \param theTag tag of a label to store attribute (for 0 this is myLab)
323 * \param theData pointer to bytes array
324 * \param theLen number of bytes in byte array that must be stored
326 void SaveByteArray(const int theTag, const char* theData, const int theLen);
329 * Internal method that used to retreive the content of byte array attribute
330 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
331 * \param theLen number of bytes in byte array
332 * \returns pointer to the internal data structure wit harray content,
333 * or NULL if array size is zero
335 const char* ByteArray(const int theTag, int& theLen) const;
338 * Internal method that used to store the reference object label attribute
339 * \param theObj pointer to reference object
340 * \param theTag tag of a label to store attribute (for 0 this is myLab)
342 int NbReferenceObjects( const int theTag = 0 ) const;
345 * Internal method that used to check object for entry into the reference list
346 * \param theObj pointer to reference object
347 * \param theTag tag of a label to store attribute (for 0 this is myLab)
349 bool HasReference( const Handle(HYDROData_Entity)& theObj,
350 const int theTag = 0 ) const;
353 * Internal method that used to store the reference object label attribute
354 * \param theObj pointer to reference object
355 * \param theTag tag of a label to store attribute (for 0 this is myLab)
357 void AddReferenceObject( const Handle(HYDROData_Entity)& theObj,
358 const int theTag = 0 );
361 * Internal method that used to store the reference object label attribute
362 * \param theObj pointer to reference object
363 * \param theTag tag of a label to store attribute (for 0 this is myLab)
364 * \param theIndex index in the list of references
365 - if more that len then just append it to the end of list
366 - if less than zero then prepend to the list
367 - indexing starts from 0
369 void SetReferenceObject( const Handle(HYDROData_Entity)& theObj,
370 const int theTag = 0,
371 const int theIndex = 0 );
374 * Internal method that used to store the reference object label attribute
375 * \param theObj pointer to reference object
376 * \param theTag tag of a label to store attribute (for 0 this is myLab)
377 * \param theBeforeIndex index in the list of references
378 - if more that len then just append it to the end of list
379 - if less than zero then prepend to the list
380 - indexing starts from 0
382 void InsertReferenceObject( const Handle(HYDROData_Entity)& theObj,
383 const int theTag = 0,
384 const int theBeforeIndex = 0 );
387 * Internal method that used to store the reference object label attribute
388 * \param theObjects sequence with pointers to reference objects
389 * \param theTag tag of a label to store attribute (for 0 this is myLab)
391 void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
392 const int theTag = 0 );
395 * Internal method that used to retreive the reference object(s) attribute
396 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
397 * \param theIndex index in the list of references
398 * - indexing starts from 0
399 * \returns pointer to reference object or NULL if label is not set
401 Handle(HYDROData_Entity) GetReferenceObject( const int theTag = 0,
402 const int theIndex = 0 ) const;
404 HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
407 * Internal method that used to remove the reference object attribute
408 * \param theRefLabel reference object label to remove
409 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
411 void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
414 * Internal method that used to remove the reference object attribute
415 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
416 * \param theIndex index in the list of references
417 * - indexing starts from 0
419 void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
422 * Internal method that used to clear list of the reference objects attribute
423 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
425 void ClearReferenceObjects( const int theTag = 0 );
429 HYDRODATA_EXPORT virtual bool CompareLabels(const Handle(HYDROData_Entity)& theOtherObj);
434 * Dump the initial object creation to a Python script.
435 * You should call it from DumpToPython implementation before
436 * dumping fields of the object.
438 HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
441 * Returns an object type name as a string for dumping to Python.
443 QString getPyTypeID() const;
445 void setPythonReferenceObject( const QString& thePyScriptPath,
446 MapOfTreatedObjects& theTreatedObjects,
447 QStringList& theScript,
448 const Handle(HYDROData_Entity)& theRefObject,
449 const QString& theMethod ) const;
451 bool checkObjectPythonDefinition( const QString& thePyScriptPath,
452 MapOfTreatedObjects& theTreatedObjects,
453 QStringList& theScript,
454 const Handle(HYDROData_Entity)& theRefObject ) const;
456 void setPythonObjectColor( QStringList& theScript,
457 const QColor& theColor,
458 const QColor& theDefaultColor,
459 const QString& theMethod ) const;
462 Handle(TDataStd_ReferenceList) getReferenceList( const int theTag,
463 const bool theIsCreate ) const;
465 void SetShape( int theTag, const TopoDS_Shape& theShape );
466 TopoDS_Shape GetShape( int theTag ) const;
468 void SetDouble( int theTag, double theValue );
469 double GetDouble( int theTag, double theDefValue = 0.0 ) const;
471 void SetInteger( int theTag, int theValue );
472 int GetInteger( int theTag, int theDefValue = 0 ) const;
475 int GetGeomChangeFlag() const;
478 /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
479 TDF_Label myLab; ///< label of this object