Salome HOME
Bug #490: batch mode error.
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.h
1
2 #ifndef HYDROData_Entity_HeaderFile
3 #define HYDROData_Entity_HeaderFile
4
5 #include "HYDROData.h"
6
7 #include <NCollection_Sequence.hxx>
8
9 #include <TDF_Label.hxx>
10
11 #include <QMap>
12
13 class QColor;
14 class QString;
15 class QVariant;
16 class QStringList;
17 class Handle(TDataStd_ReferenceList);
18 class Handle_HYDROData_Entity;
19
20 ///! Kind of an object in a document
21 typedef int ObjectKind;
22
23 const ObjectKind KIND_UNKNOWN           = 0; ///! Unrecognized object
24 const ObjectKind KIND_IMAGE             = 1;
25 const ObjectKind KIND_POLYLINE          = 2;
26 const ObjectKind KIND_BATHYMETRY        = 3;
27 const ObjectKind KIND_ALTITUDE          = 4;
28 const ObjectKind KIND_IMMERSIBLE_ZONE   = 5;
29 const ObjectKind KIND_RIVER             = 6;
30 const ObjectKind KIND_STREAM            = 7;
31 const ObjectKind KIND_CONFLUENCE        = 8;
32 const ObjectKind KIND_CHANNEL           = 9;
33 const ObjectKind KIND_OBSTACLE          = 10;
34 const ObjectKind KIND_DIGUE             = 11;
35 const ObjectKind KIND_PROFILE           = 12;
36 const ObjectKind KIND_PROFILEUZ         = 13;
37 const ObjectKind KIND_POLYLINEXY        = 14;
38 const ObjectKind KIND_CALCULATION       = 15;
39 const ObjectKind KIND_ZONE              = 16;
40 const ObjectKind KIND_REGION            = 17;
41 const ObjectKind KIND_VISUAL_STATE      = 18;
42 const ObjectKind KIND_ARTIFICIAL_OBJECT = 19;
43 const ObjectKind KIND_NATURAL_OBJECT    = 20;
44 const ObjectKind KIND_DUMMY_3D          = 21;
45 const ObjectKind KIND_SHAPES_GROUP      = 22;
46 const ObjectKind KIND_SPLITTED_GROUP    = 23;
47 const ObjectKind KIND_STREAM_ALTITUDE   = 24;
48 const ObjectKind KIND_OBSTACLE_ALTITUDE = 25;
49 const ObjectKind KIND_LAST              = KIND_OBSTACLE_ALTITUDE;
50
51 DEFINE_STANDARD_HANDLE(HYDROData_Entity, MMgt_TShared)
52
53 typedef QMap<QString,Handle(Standard_Transient)> MapOfTreatedObjects;
54
55 typedef NCollection_Sequence<Handle_HYDROData_Entity> HYDROData_SequenceOfObjects;
56
57 ///! Is Equal for HYDROData_Entity mapping
58 HYDRODATA_EXPORT bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2);
59
60 /**\class HYDROData_Entity
61  * \brief Generic class of any object in the data model.
62  *
63  * Interface for getting access to the object that belong to the data model.
64  * Managed by Document. Provides access to the common properties: 
65  * kind of an object, name.
66  */
67 class HYDROData_Entity : public MMgt_TShared
68 {
69
70 protected:
71
72   /**
73    * Enumeration of tags corresponding to the persistent object parameters.
74    */
75   enum DataTag
76   {
77     DataTag_First  = 0,     ///< first tag, to reserve
78     DataTag_ZLevel,         ///< z-level of object presentation
79   };
80
81 public:
82   DEFINE_STANDARD_RTTI(HYDROData_Entity);
83
84   /**
85    * Returns the kind of this object. Must be redefined in all objects of known type.
86    */
87   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_UNKNOWN; }
88
89   /**
90    * Returns the name of this object.
91    */
92   HYDRODATA_EXPORT virtual QString GetName() const;
93
94   /**
95    * Updates the name of this object.
96    */
97   HYDRODATA_EXPORT virtual void SetName( const QString& theName );
98
99   /**
100    * Returns the name of this object valid for Python script.
101    */
102   HYDRODATA_EXPORT virtual QString GetObjPyName() const;
103
104   /**
105    * Dump object to Python script representation.
106    * Base implementation returns empty list,
107    * You should reimplement this function in your derived class if it
108    * has Python API and can be imported/exported from/to Python script.
109    */
110   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
111
112   /**
113    * Updates object state. Base implementation dose nothing.
114    */
115   HYDRODATA_EXPORT virtual void Update();
116
117   HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy );
118
119   /**
120    * Checks that object has 2D presentation. Base implementation returns false.
121    */
122   HYDRODATA_EXPORT virtual bool IsHas2dPrs() const;
123
124   /**
125    * Show object at the top of other model objects.
126    */
127   HYDRODATA_EXPORT virtual void Show();
128
129
130   /**
131    * Returns data of object wrapped to QVariant.
132    * Base implementation returns null value.
133    */
134   HYDRODATA_EXPORT virtual QVariant GetDataVariant();
135
136
137   /**
138    * Sets the "MustBeUpdated" flag: if object is depended on updated features.
139    * \param theFlag is true for objects that must be updated, false for up-to-date
140    */
141   HYDRODATA_EXPORT virtual void SetToUpdate( bool theFlag );
142
143   /**
144    * Returns the "MustBeUpdated" flag: is object data must be updated or not
145    * \returns false if object is up to date
146    */
147   HYDRODATA_EXPORT virtual bool IsMustBeUpdated() const;
148
149   /**
150    * Returns flag indicating that object is updateble or not.
151    */
152   HYDRODATA_EXPORT virtual bool CanBeUpdated() const;
153
154
155   /**
156    * Checks is object exists in the data structure.
157    * \returns true is object is not exists in the data model
158    */
159   HYDRODATA_EXPORT bool IsRemoved() const;
160
161   /**
162    * Removes object and it child sub-objects from the data structure.
163    */
164   HYDRODATA_EXPORT virtual void Remove();
165
166   /**
167    * Returns flag indicating that object can be removed or not.
168    * Reimplement this method in class which can't be removed 
169    * separately with it parent object.
170    * Base implementaiton returns always TRUE.
171    */
172   HYDRODATA_EXPORT virtual bool CanRemove();
173
174   /**
175    * Copies all properties of this to the destinated object.
176    * Objects must be the same type.
177    * \param theDestination initialized object (from any document) - target of copying
178    */
179   HYDRODATA_EXPORT void CopyTo( const Handle(HYDROData_Entity)& theDestination ) const;
180
181   /**
182    * Returns the label of this object.
183    */
184   HYDRODATA_EXPORT TDF_Label& Label() { return myLab; }
185
186
187   /**
188    * Returns father object. For object created under root document label
189    * this method always return NULL object.
190    */
191   HYDRODATA_EXPORT virtual Handle(HYDROData_Entity) GetFatherObject() const;
192
193
194   /**
195    * Returns the list of all reference objects of this object.
196    * Base implementation always return empty list.
197    */
198   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
199
200
201   /**
202    * Returns the z-level for object presentation, -1 if no z-level.
203    */
204   HYDRODATA_EXPORT virtual Standard_Boolean GetZLevel( Standard_Integer& theLevel ) const;
205
206   /**
207    * Set the z-level for object presentation.
208    */
209   HYDRODATA_EXPORT virtual void SetZLevel( const Standard_Integer& theLevel );
210
211   /**
212    * Remove the z-level of object presentation.
213    */
214   HYDRODATA_EXPORT virtual void RemoveZLevel();
215
216   /**
217     Find the Python object in the document by the object name.
218     @param theTreatedObjects the map of treated objects
219     @param theScript the script
220   */
221   void findPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
222                                   QStringList&                    theScript ) const;
223  
224 protected:
225
226   friend class HYDROData_Iterator;
227
228   /**
229    * Creates new object in the internal data structure. Use higher level objects 
230    * to create objects with real content.
231    */
232   HYDRODATA_EXPORT HYDROData_Entity();
233
234   /**
235    * Destructs properties of the object and object itself, removes it from the document.
236    */
237   virtual HYDRODATA_EXPORT ~HYDROData_Entity();
238
239   /**
240    * Put the object to the label of the document.
241    * \param theLabel new label of the object
242    */
243   HYDRODATA_EXPORT virtual void SetLabel( const TDF_Label& theLabel );
244
245   /**
246    * Internal method that used to store the byte array attribute
247    * \param theTag tag of a label to store attribute (for 0 this is myLab)
248    * \param theData pointer to bytes array
249    * \param theLen number of bytes in byte array that must be stored
250    */
251   void SaveByteArray(const int theTag, const char* theData, const int theLen);
252
253   /**
254    * Internal method that used to retreive the content of byte array attribute
255    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
256    * \param theLen number of bytes in byte array
257    * \returns pointer to the internal data structure wit harray content, 
258    *          or NULL if array size is zero
259    */
260   const char* ByteArray(const int theTag, int& theLen) const;
261
262   /**
263    * Internal method that used to store the reference object label attribute
264    * \param theObj pointer to reference object
265    * \param theTag tag of a label to store attribute (for 0 this is myLab)
266    */
267   int NbReferenceObjects( const int theTag = 0 ) const;
268
269   /**
270    * Internal method that used to check object for entry into the reference list
271    * \param theObj pointer to reference object
272    * \param theTag tag of a label to store attribute (for 0 this is myLab)
273    */
274   bool HasReference( const Handle_HYDROData_Entity& theObj,
275                      const int                      theTag = 0 ) const;
276
277   /**
278    * Internal method that used to store the reference object label attribute
279    * \param theObj pointer to reference object
280    * \param theTag tag of a label to store attribute (for 0 this is myLab)
281    */
282   void AddReferenceObject( const Handle_HYDROData_Entity& theObj,
283                            const int                      theTag = 0 );
284
285   /**
286    * Internal method that used to store the reference object label attribute
287    * \param theObj pointer to reference object
288    * \param theTag tag of a label to store attribute (for 0 this is myLab)
289    * \param theIndex index in the list of references 
290              - if more that len then just append it to the end of list
291              - if less than zero then prepend to the list
292              - indexing starts from 0
293    */
294   void SetReferenceObject( const Handle_HYDROData_Entity& theObj,
295                            const int                      theTag = 0,
296                            const int                      theIndex = 0 );
297
298   /**
299    * Internal method that used to store the reference object label attribute
300    * \param theObj pointer to reference object
301    * \param theTag tag of a label to store attribute (for 0 this is myLab)
302    * \param theBeforeIndex index in the list of references 
303              - if more that len then just append it to the end of list
304              - if less than zero then prepend to the list
305              - indexing starts from 0
306    */
307   void InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
308                               const int                      theTag = 0,
309                               const int                      theBeforeIndex = 0 );
310
311   /**
312    * Internal method that used to store the reference object label attribute
313    * \param theObjects sequence with pointers to reference objects
314    * \param theTag tag of a label to store attribute (for 0 this is myLab)
315    */
316   void SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
317                             const int                          theTag = 0 );
318
319   /**
320    * Internal method that used to retreive the reference object(s) attribute
321    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
322    * \param theIndex index in the list of references 
323    *        - indexing starts from 0
324    * \returns pointer to reference object or NULL if label is not set
325    */
326   Handle_HYDROData_Entity GetReferenceObject( const int theTag   = 0,
327                                               const int theIndex = 0 ) const;
328
329   HYDROData_SequenceOfObjects GetReferenceObjects( const int theTag = 0 ) const;
330
331   /**
332    * Internal method that used to remove the reference object attribute
333    * \param theRefLabel reference object label to remove
334    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
335    */
336   void RemoveReferenceObject( const TDF_Label& theRefLabel, const int theTag = 0 );
337
338   /**
339    * Internal method that used to remove the reference object attribute
340    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
341    * \param theIndex index in the list of references 
342    *        - indexing starts from 0
343    */
344   void RemoveReferenceObject( const int theTag = 0, const int theIndex = 0 );
345
346   /**
347    * Internal method that used to clear list of the reference objects attribute
348    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
349    */
350   void ClearReferenceObjects( const int theTag = 0 );
351
352   /**
353    * Internal method that used to store the color attribute
354    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
355    * \param theColor color to save
356    */
357   void SetColor( const QColor& theColor, const int theTag = 0 );
358
359   /**
360    * Internal method that used to retreive the color attribute
361    * \param theTag tag of a label that keeps the attribute (for 0 this is myLab)
362    * \param theDefColor default color to return if attribute has not been set before
363    */
364   QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const;
365    
366 protected:
367
368   /**
369    * Dump the initial object creation to a Python script.
370    * You should call it from DumpToPython implementation before 
371    * dumping fields of the object.
372    */
373   HYDRODATA_EXPORT virtual QStringList dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const;
374
375   /**
376    * Returns an object type name as a string for dumping to Python.
377    */
378   QString getPyTypeID() const;
379
380   void setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
381                                  QStringList&                    theScript,
382                                  const Handle(HYDROData_Entity)& theRefObject,
383                                  const QString&                  theMethod ) const;
384
385   bool checkObjectPythonDefinition( MapOfTreatedObjects&            theTreatedObjects,
386                                     QStringList&                    theScript,
387                                     const Handle(HYDROData_Entity)& theRefObject ) const;
388
389   void setPythonObjectColor( QStringList&         theScript,
390                              const QColor&        theColor,
391                              const QColor&        theDefaultColor,
392                              const QString&       theMethod ) const;
393
394 protected:
395
396   Handle(TDataStd_ReferenceList) getReferenceList( const int  theTag,
397                                                    const bool theIsCreate ) const;
398
399
400 protected:
401   /// Array of pointers to the properties of this object; index in this array is returned by \a AddProperty.
402   TDF_Label myLab; ///< label of this object
403 };
404
405 #endif