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>
31 class Handle(TDataStd_ReferenceList);
32 class Handle_HYDROData_Entity;
35 ///! Kind of an object in a document
36 typedef int ObjectKind;
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;
69 DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared)
71 class MapOfTreatedObjects : public QMap<QString,Handle(Standard_Transient)>
75 class HYDRODATA_EXPORT HYDROData_SequenceOfObjects : public NCollection_Sequence<Handle_HYDROData_Entity>
78 HYDROData_SequenceOfObjects();
79 HYDROData_SequenceOfObjects( const HYDROData_SequenceOfObjects& );
80 HYDROData_SequenceOfObjects( const NCollection_Sequence<Handle_HYDROData_Entity>& );
83 ///! Is Equal for HYDROData_Entity mapping
84 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
86 /**\class HYDROData_Entity
87 * \brief Generic class of any object in the data model.
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.
93 class HYDROData_Entity : public MMgt_TShared
97 * Enumeration of tags corresponding to the persistent object parameters.
101 DataTag_First = 0, ///< first tag, to reserve
102 DataTag_ZLevel, ///< z-level of object presentation
114 Geom_3d = Geom_2d | Geom_Z,
115 Geom_2d_and_groups = Geom_2d | Geom_Groups,
116 Geom_All = Geom_3d | Geom_Groups | Geom_No,
120 DEFINE_STANDARD_RTTI(HYDROData_Entity);
123 * Returns the kind of this object. Must be redefined in all objects of known type.
125 HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
128 * Returns the name of this object.
130 HYDRODATA_EXPORT virtual QString GetName() const;
133 * Updates the name of this object.
135 HYDRODATA_EXPORT void SetName( const QString& theName );
138 * Returns the name of this object valid for Python script.
140 HYDRODATA_EXPORT virtual QString GetObjPyName() const;
143 * Dump object to Python script representation.
144 * Base implementation returns empty list,
145 * You should reimplement this function in your derived class if it
146 * has Python API and can be imported/exported from/to Python script.
148 HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
151 * Updates object state. Base implementation dose nothing.
153 HYDRODATA_EXPORT virtual void Update();
155 HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
158 * Checks that object has 2D presentation. Base implementation returns false.
160 HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
163 * Show object at the top of other model objects.
165 HYDRODATA_EXPORT virtual void Show();
169 * Returns data of object wrapped to QVariant.
170 * Base implementation returns null value.
172 HYDRODATA_EXPORT virtual QVariant GetDataVariant();
176 HYDRODATA_EXPORT virtual void ClearChanged();
177 HYDRODATA_EXPORT virtual void Changed( Geometry );
179 HYDRODATA_EXPORT bool IsMustBeUpdated( Geometry ) const;
182 * Returns flag indicating that object is updateble or not.
184 HYDRODATA_EXPORT virtual bool CanBeUpdated() const;
188 * Checks is object exists in the data structure.
189 * \returns true is object is not exists in the data model
191 HYDRODATA_EXPORT bool IsRemoved() const;
194 * Removes object and it child sub-objects from the data structure.
196 HYDRODATA_EXPORT virtual void Remove();
199 * Returns flag indicating that object can be removed or not.
200 * Reimplement this method in class which can't be removed
201 * separately with it parent object.
202 * Base implementaiton returns always TRUE.
204 HYDRODATA_EXPORT virtual bool CanRemove();
207 * Copies all properties of this to the destinated object.
208 * Objects must be the same type.
209 * \param theDestination initialized object (from any document) - target of copying
211 HYDRODATA_EXPORT virtual void CopyTo( const Handle(HYDROData_Entity)& theDestination,
212 bool isGenerateNewName ) const;
215 * Returns the label of this object.
217 HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
221 * Returns father object. For object created under root document label
222 * this method always return NULL object.
224 HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
228 * Returns the list of all reference objects of this object.
229 * Base implementation always return empty list.
231 HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
235 * Returns the z-level for object presentation, -1 if no z-level.
237 HYDRODATA_EXPORT virtual Standard_Boolean GetZLevel( Standard_Integer& theLevel ) const;
240 * Set the z-level for object presentation.
242 HYDRODATA_EXPORT virtual void SetZLevel( const Standard_Integer& theLevel );
245 * Remove the z-level of object presentation.
247 HYDRODATA_EXPORT virtual void RemoveZLevel();
250 Find the Python object in the document by the object name.
251 @param theTreatedObjects the map of treated objects
252 @param theScript the script
254 void findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
255 QStringList& theScript ) const;
258 * Internal method that used to store the color attribute
259 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
260 * \param theColor color to save
262 HYDRODATA_EXPORT void SetColor( const QColor& theColor, const int theTag = 0 );
265 * Internal method that used to retreive the color attribute
266 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
267 * \param theDefColor default color to return if attribute has not been set before
269 HYDRODATA_EXPORT QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
273 friend class HYDROData_Iterator;
276 * Creates new object in the internal data structure. Use higher level objects
277 * to create objects with real content.
279 HYDRODATA_EXPORT HYDROData_Entity( Geometry );
282 * Destructs properties of the object and object itself, removes it from the document.
284 virtual HYDRODATA_EXPORT ~HYDROData_Entity();
287 * Put the object to the label of the document.
288 * \param theLabel new label of the object
290 HYDRODATA_EXPORT virtual void SetLabel( const TDF_Label& theLabel );
293 * Internal method that used to store the byte array attribute
294 * \param theTag tag of a label to store attribute (for 0 this is myLab)
295 * \param theData pointer to bytes array
296 * \param theLen number of bytes in byte array that must be stored
298 void SaveByteArray(const int theTag, const char* theData, const int theLen);
301 * Internal method that used to retreive the content of byte array attribute
302 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
303 * \param theLen number of bytes in byte array
304 * \returns pointer to the internal data structure wit harray content,
305 * or NULL if array size is zero
307 const char* ByteArray(const int theTag, int& theLen) const;
310 * Internal method that used to store the reference object label attribute
311 * \param theObj pointer to reference object
312 * \param theTag tag of a label to store attribute (for 0 this is myLab)
314 int NbReferenceObjects( const int theTag = 0 ) const;
317 * Internal method that used to check object for entry into the reference list
318 * \param theObj pointer to reference object
319 * \param theTag tag of a label to store attribute (for 0 this is myLab)
321 bool HasReference( const Handle_HYDROData_Entity& theObj,
322 const int theTag = 0 ) const;
325 * Internal method that used to store the reference object label attribute
326 * \param theObj pointer to reference object
327 * \param theTag tag of a label to store attribute (for 0 this is myLab)
329 void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
330 const int theTag = 0 );
333 * Internal method that used to store the reference object label attribute
334 * \param theObj pointer to reference object
335 * \param theTag tag of a label to store attribute (for 0 this is myLab)
336 * \param theIndex index in the list of references
337 - if more that len then just append it to the end of list
338 - if less than zero then prepend to the list
339 - indexing starts from 0
341 void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
342 const int theTag = 0,
343 const int theIndex = 0 );
346 * Internal method that used to store the reference object label attribute
347 * \param theObj pointer to reference object
348 * \param theTag tag of a label to store attribute (for 0 this is myLab)
349 * \param theBeforeIndex index in the list of references
350 - if more that len then just append it to the end of list
351 - if less than zero then prepend to the list
352 - indexing starts from 0
354 void InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
355 const int theTag = 0,
356 const int theBeforeIndex = 0 );
359 * Internal method that used to store the reference object label attribute
360 * \param theObjects sequence with pointers to reference objects
361 * \param theTag tag of a label to store attribute (for 0 this is myLab)
363 void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
364 const int theTag = 0 );
367 * Internal method that used to retreive the reference object(s) attribute
368 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
369 * \param theIndex index in the list of references
370 * - indexing starts from 0
371 * \returns pointer to reference object or NULL if label is not set
373 Handle_HYDROData_Entity GetReferenceObject( const int theTag = 0,
374 const int theIndex = 0 ) const;
376 HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
379 * Internal method that used to remove the reference object attribute
380 * \param theRefLabel reference object label to remove
381 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
383 void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
386 * Internal method that used to remove the reference object attribute
387 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
388 * \param theIndex index in the list of references
389 * - indexing starts from 0
391 void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
394 * Internal method that used to clear list of the reference objects attribute
395 * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
397 void ClearReferenceObjects( const int theTag = 0 );
402 * Dump the initial object creation to a Python script.
403 * You should call it from DumpToPython implementation before
404 * dumping fields of the object.
406 HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
409 * Returns an object type name as a string for dumping to Python.
411 QString getPyTypeID() const;
413 void setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
414 QStringList& theScript,
415 const Handle(HYDROData_Entity)& theRefObject,
416 const QString& theMethod ) const;
418 bool checkObjectPythonDefinition( MapOfTreatedObjects& theTreatedObjects,
419 QStringList& theScript,
420 const Handle(HYDROData_Entity)& theRefObject ) const;
422 void setPythonObjectColor( QStringList& theScript,
423 const QColor& theColor,
424 const QColor& theDefaultColor,
425 const QString& theMethod ) const;
428 Handle(TDataStd_ReferenceList) getReferenceList( const int theTag,
429 const bool theIsCreate ) const;
431 void SetShape( int theTag, const TopoDS_Shape& theShape );
432 TopoDS_Shape GetShape( int theTag ) const;
434 int GetGeomChangeFlag() const;
437 /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
438 TDF_Label myLab; ///< label of this object