Salome HOME
merge BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROData_Entity.h"
20
21 #include "HYDROData_Iterator.h"
22 #include "HYDROData_Tool.h"
23
24 #include <TDataStd_Name.hxx>
25 #include <TDataStd_ByteArray.hxx>
26 #include <TDataStd_UAttribute.hxx>
27 #include <TDataStd_IntegerArray.hxx>
28 #include <TDataStd_BooleanArray.hxx>
29 #include <TDataStd_Integer.hxx>
30 #include <TDataStd_RealArray.hxx>
31 #include <TDataStd_ReferenceList.hxx>
32
33 #include <TDF_CopyLabel.hxx>
34 #include <TDF_ListIteratorOfLabelList.hxx>
35
36 #include <QColor>
37 #include <QString>
38 #include <QStringList>
39 #include <QVariant>
40
41 #define _DEVDEBUG_
42 #include "HYDRO_trace.hxx"
43
44 //static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000");
45
46 IMPLEMENT_STANDARD_HANDLE(HYDROData_Entity,MMgt_TShared)
47 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Entity,MMgt_TShared)
48
49 // is equal function for unique object mapping
50 bool IsEqual(const Handle_HYDROData_Entity& theObj1, const Handle_HYDROData_Entity& theObj2)
51 {
52   if ( !theObj1.IsNull() && !theObj2.IsNull() )
53     return theObj1->Label() == theObj2->Label();
54   return false;
55 }
56
57 QString HYDROData_Entity::GetName() const
58 {
59   Handle(TDataStd_Name) aName;
60   if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
61     TCollection_AsciiString aStr(aName->Get());
62     return QString(aStr.ToCString());
63   }
64   return QString();
65 }
66
67 QString HYDROData_Entity::GetObjPyName() const
68 {
69   QString aName = GetName();
70   aName.replace(QRegExp("[\\W]"), "_");
71
72   return aName;
73 }
74
75 void HYDROData_Entity::SetName(const QString& theName)
76 {
77   TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
78 }
79
80 QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
81 {
82   QStringList anEmptyList;
83   return anEmptyList;
84 }
85
86 void HYDROData_Entity::Update()
87 {
88   ClearChanged();
89 }
90
91 void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
92 {
93   //On the base level no actions are necessary
94 }
95
96 bool HYDROData_Entity::IsHas2dPrs() const
97 {
98   return false;
99 }
100
101 void HYDROData_Entity::Show()
102 {
103   if ( !IsHas2dPrs() )
104     return;
105
106   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
107   if ( aDocument.IsNull() )
108     return;
109
110   aDocument->Show( this );
111 }
112
113 QVariant HYDROData_Entity::GetDataVariant()
114 {
115   return QVariant();
116 }
117
118 void HYDROData_Entity::ClearChanged()
119 {
120   TDataStd_Integer::Set( myLab.FindChild( DataTag_GeomChange ), 0 );
121 }
122
123 int HYDROData_Entity::GetGeomChangeFlag() const
124 {
125   int aGeomChangeFlag = 0;
126   Handle(TDataStd_Integer) aGeomChangeAttr;
127   TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
128   aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
129   if ( !aGeomChangeAttr.IsNull() )
130     aGeomChangeFlag = aGeomChangeAttr->Get();
131   return aGeomChangeFlag;
132 }
133
134 void HYDROData_Entity::Changed( Geometry theChangedGeometry )
135 {
136   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
137   if( aDocument.IsNull() )
138     return;
139
140   int aGeomChangeFlag = 0;
141   Handle(TDataStd_Integer) aGeomChangeAttr;
142   TDF_Label aGeomChangeLab = myLab.FindChild( DataTag_GeomChange );
143   aGeomChangeLab.FindAttribute( TDataStd_Integer::GetID(), aGeomChangeAttr );
144   if ( !aGeomChangeAttr.IsNull() )
145     aGeomChangeFlag = aGeomChangeAttr->Get();
146
147   int aBitsToChange = ( myGeom & theChangedGeometry );
148   if( aBitsToChange == 0 )
149     return;
150
151   aGeomChangeFlag = ( aGeomChangeFlag | aBitsToChange );
152   TDataStd_Integer::Set( aGeomChangeLab, aGeomChangeFlag );
153
154   HYDROData_Iterator anIter( aDocument );
155   for ( ; anIter.More(); anIter.Next() )
156   {
157     Handle(HYDROData_Entity) anObject = anIter.Current();
158     HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
159     for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
160     {
161       Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
162       if( aRefObject->Label()==myLab )
163         anObject->Changed( theChangedGeometry );
164     }
165   }
166 }
167
168 bool HYDROData_Entity::IsMustBeUpdated( Geometry theGeom ) const
169 {
170   return ( ( GetGeomChangeFlag() & theGeom ) != 0 );
171 }
172
173 bool HYDROData_Entity::CanBeUpdated() const
174 {
175   return true;
176 }
177
178 bool HYDROData_Entity::IsRemoved() const
179 {
180   return !myLab.HasAttribute();
181 }
182
183 void HYDROData_Entity::Remove()
184 {
185   return myLab.ForgetAllAttributes( true );
186 }
187
188 bool HYDROData_Entity::CanRemove()
189 {
190   return true;
191 }
192
193 HYDROData_Entity::HYDROData_Entity( Geometry theGeom )
194   : myGeom( theGeom )
195 {
196 }
197
198 HYDROData_Entity::~HYDROData_Entity()
199 {
200 }
201
202 void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination,
203                                bool isGenerateNewName ) const
204 {
205   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
206   if ( aDocument.IsNull() ) {
207     return;
208   }
209
210   TDF_CopyLabel aCopy(myLab, theDestination->Label());
211   aCopy.Perform();
212          
213   if( isGenerateNewName )
214   {
215     // generate a new unique name for the clone object:
216     // case 1: Image_1 -> Image_2
217     // case 2: ImageObj -> ImageObj_1
218     QString aName = theDestination->GetName();
219     QString aPrefix = aName;
220     if( aName.contains( '_' ) ) { // case 1
221       QString aSuffix = aName.section( '_', -1 );
222       bool anIsInteger = false;
223       aSuffix.toInt( &anIsInteger );
224       if( anIsInteger )
225         aPrefix = aName.section( '_', 0, -2 );
226     } else { // case 2
227       aPrefix = aName;
228     }
229
230     aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
231     theDestination->SetName( aName );
232   }
233 }
234
235 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const
236 {
237   Handle(HYDROData_Entity) aFather;
238
239   if ( !myLab.IsNull() )
240   {
241     TDF_Label aFatherLabel = myLab.Father();
242
243     while ( aFather.IsNull() && !aFatherLabel.IsNull() && !aFatherLabel.IsRoot() )
244     {
245       aFather = HYDROData_Iterator::Object( aFatherLabel );
246       aFatherLabel = aFatherLabel.Father();
247     }
248   }
249
250   return aFather;
251 }
252
253 HYDROData_SequenceOfObjects HYDROData_Entity::GetAllReferenceObjects() const
254 {
255   return HYDROData_SequenceOfObjects();
256 }
257
258 Standard_Boolean HYDROData_Entity::GetZLevel( Standard_Integer& theLevel ) const
259 {
260   theLevel = -1;
261
262   TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
263   if ( !aLabel.IsNull() )
264   {
265     Handle(TDataStd_Integer) anIntVal;
266     if ( aLabel.FindAttribute( TDataStd_Integer::GetID(), anIntVal ) )
267     {
268       theLevel = anIntVal->Get();
269       return Standard_True;
270     }
271   }
272
273   return Standard_False;
274 }
275
276 void HYDROData_Entity::SetZLevel( const Standard_Integer& theLevel )
277 {
278   TDataStd_Integer::Set( myLab.FindChild( DataTag_ZLevel ), theLevel );
279 }
280
281 void HYDROData_Entity::RemoveZLevel()
282 {
283   TDF_Label aLabel = myLab.FindChild( DataTag_ZLevel, false );
284   if ( !aLabel.IsNull() )
285     aLabel.ForgetAllAttributes();
286 }
287
288 void HYDROData_Entity::SetLabel( const TDF_Label& theLabel )
289 {
290   myLab = theLabel;
291 }
292
293 void HYDROData_Entity::SaveByteArray( const int   theTag, 
294                                       const char* theData,
295                                       const int   theLen )
296 {
297   TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
298   // array is empty, remove the attribute
299   if (theLen <= 0) {
300     aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
301     return;
302   }
303   // store data of image in byte array
304   Handle(TDataStd_ByteArray) aData;
305   if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
306     aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
307   }
308   // copy bytes one by one
309   if (aData->Length() != theLen) {
310     Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
311     for(int a = 0; a < theLen; a++)
312       aNewData->SetValue(a + 1, theData[a]);
313     aData->ChangeArray(aNewData);
314   } else {
315     for(int a = 0; a < theLen; a++)
316       aData->SetValue(a + 1, theData[a]);
317   }
318 }
319
320 const char* HYDROData_Entity::ByteArray(const int theTag, int& theLen) const
321 {
322   TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
323   Handle(TDataStd_ByteArray) aData;
324   if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
325     return NULL; // return empty image if there is no array
326   theLen = aData->Length();
327   if (theLen)
328     return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
329   return NULL;
330 }
331
332 int HYDROData_Entity::NbReferenceObjects( const int theTag ) const
333 {
334   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
335   return aRefs.IsNull() ? 0 : aRefs->Extent();
336 }
337
338 bool HYDROData_Entity::HasReference( const Handle_HYDROData_Entity& theObj,
339                                      const int                      theTag ) const
340 {
341   if ( theObj.IsNull() )
342     return false;
343
344   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
345   if ( aRefs.IsNull() || aRefs->IsEmpty() )
346     return false;
347
348   TDF_ListIteratorOfLabelList aListIt( aRefs->List() );
349   for ( ; aListIt.More(); aListIt.Next() )
350   {
351     const TDF_Label& aRefLabel = aListIt.Value();
352     if  ( theObj->Label() == aRefLabel )
353       return true;
354   }
355
356   return false;
357 }
358
359 void HYDROData_Entity::AddReferenceObject( const Handle_HYDROData_Entity& theObj,
360                                            const int                      theTag )
361 {
362   if ( theObj.IsNull() )
363     return;
364
365   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
366   aRefs->Append( theObj->Label() );
367 }
368
369 void HYDROData_Entity::SetReferenceObject( const Handle_HYDROData_Entity& theObj,
370                                            const int                      theTag,
371                                            const int                      theIndex )
372 {
373   if ( theObj.IsNull() )
374   {
375     RemoveReferenceObject( theTag, theIndex );
376     return;
377   }
378
379   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
380
381   if ( theIndex >= aRefs->Extent() )
382   {
383     aRefs->Append( theObj->Label() );
384   }
385   else if ( theIndex < 0 )
386   {
387     aRefs->Prepend( theObj->Label() );
388   }
389   else
390   {
391     RemoveReferenceObject( theTag, theIndex );
392
393     Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theIndex );
394
395     aRefs = getReferenceList( theTag, true ); // because reference list can be removed
396     if ( !aBeforeObj.IsNull() )
397       aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
398     else 
399       aRefs->Append( theObj->Label() );
400   }
401 }
402
403 void HYDROData_Entity::InsertReferenceObject( const Handle_HYDROData_Entity& theObj,
404                                               const int                      theTag,
405                                               const int                      theBeforeIndex )
406 {
407   if ( theObj.IsNull() )
408     return;
409
410   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
411
412   if ( theBeforeIndex >= aRefs->Extent() )
413   {
414     aRefs->Append( theObj->Label() );
415   }
416   else if ( theBeforeIndex < 0 )
417   {
418     aRefs->Prepend( theObj->Label() );
419   }
420   else
421   {
422     Handle(HYDROData_Entity) aBeforeObj = GetReferenceObject( theTag, theBeforeIndex );
423     if ( !aBeforeObj.IsNull() )
424       aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
425     else 
426       aRefs->Append( theObj->Label() );
427   }
428 }
429
430 void HYDROData_Entity::SetReferenceObjects( const HYDROData_SequenceOfObjects& theObjects,
431                                             const int                          theTag )
432 {
433   ClearReferenceObjects( theTag );
434   if ( theObjects.IsEmpty() )
435     return;
436
437   HYDROData_SequenceOfObjects::Iterator anIter( theObjects );
438   for ( ; anIter.More(); anIter.Next() )
439     AddReferenceObject( anIter.Value(), theTag );
440 }
441
442 Handle(HYDROData_Entity) HYDROData_Entity::GetReferenceObject( const int theTag,
443                                                                const int theIndex ) const
444 {
445   Handle(HYDROData_Entity) aRes;
446
447   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
448   if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
449     return aRes;
450
451   TDF_ListIteratorOfLabelList anIter( aRefs->List() );
452   for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
453
454   const TDF_Label& aRefLabel = anIter.Value();
455   aRes = HYDROData_Iterator::Object( aRefLabel );
456
457   return aRes;
458 }
459
460 HYDROData_SequenceOfObjects HYDROData_Entity::GetReferenceObjects( const int theTag ) const
461 {
462   HYDROData_SequenceOfObjects aRes;
463
464   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
465   if ( aRefs.IsNull() )
466     return aRes;
467
468   TDF_ListIteratorOfLabelList anIter( aRefs->List() );
469   for ( ; anIter.More(); anIter.Next() )
470   {
471     const TDF_Label& aRefLabel = anIter.Value();
472
473     Handle(HYDROData_Entity) aRefObject = HYDROData_Iterator::Object( aRefLabel );
474     if ( aRefObject.IsNull() )
475       continue;
476
477     aRes.Append( aRefObject );
478   }
479
480   return aRes;
481 }
482
483 void HYDROData_Entity::RemoveReferenceObject( const TDF_Label& theRefLabel,
484                                               const int        theTag )
485 {
486   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
487   if ( aRefs.IsNull() )
488     return;
489
490   if ( aRefs->Extent() == 1 )
491   { 
492     // remove all if only one
493     ClearReferenceObjects( theTag );
494     return;
495   }
496
497   aRefs->Remove( theRefLabel );
498 }
499
500 void HYDROData_Entity::RemoveReferenceObject( const int theTag,
501                                               const int theIndex )
502 {
503   Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
504   if ( aRefs.IsNull() )
505     return;
506
507   if ( aRefs->Extent() == 1 && theIndex == 0 )
508   { 
509     // remove all if only one
510     ClearReferenceObjects( theTag );
511     return;
512   }
513
514   int anIndex = 0;
515   TDF_ListIteratorOfLabelList anIter( aRefs->List() );
516   for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
517
518   if ( anIndex != theIndex || !anIter.More() )
519     return;
520
521   const TDF_Label& aRefLabel = anIter.Value();
522   aRefs->Remove( aRefLabel );
523 }
524
525 void HYDROData_Entity::ClearReferenceObjects( const int theTag )
526 {
527   TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
528   aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
529 }
530
531 Handle(TDataStd_ReferenceList) HYDROData_Entity::getReferenceList( const int theTag,
532                                                                    const bool theIsCreate ) const
533 {
534   TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
535
536   Handle(TDataStd_ReferenceList) aRefs;
537   if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
538     aRefs = TDataStd_ReferenceList::Set( aLabel );
539
540   return aRefs;
541 }
542
543 void HYDROData_Entity::SetColor( const QColor& theColor,
544                                  const int     theTag )
545 {
546   TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
547
548   Handle(TDataStd_IntegerArray) aColorArray;
549   if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
550     aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 );
551
552   aColorArray->SetValue( 1, theColor.red()   );
553   aColorArray->SetValue( 2, theColor.green() );
554   aColorArray->SetValue( 3, theColor.blue()  );
555   aColorArray->SetValue( 4, theColor.alpha() );
556 }
557
558 QColor HYDROData_Entity::GetColor( const QColor& theDefColor,
559                                    const int     theTag ) const
560 {
561   QColor aResColor = theDefColor;
562
563   TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
564
565   Handle(TDataStd_IntegerArray) aColorArray;
566   if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
567   {
568     aResColor.setRed(   aColorArray->Value( 1 ) );
569     aResColor.setGreen( aColorArray->Value( 2 ) );
570     aResColor.setBlue(  aColorArray->Value( 3 ) );
571     aResColor.setAlpha( aColorArray->Value( 4 ) );
572   }
573
574   return aResColor;
575 }
576
577 QStringList HYDROData_Entity::dumpObjectCreation( MapOfTreatedObjects& theTreatedObjects ) const
578 {
579   QStringList aResList;
580
581   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
582   if ( aDocument.IsNull() )
583     return aResList;
584
585   QString aDocName = aDocument->GetDocPyName();
586   QString aName = GetObjPyName();
587
588   aResList << QString( "%1 = %2.CreateObject( %3 );" )
589               .arg( aName ).arg( aDocName ).arg( getPyTypeID() );
590   aResList << QString( "%1.SetName( \"%2\" );" )
591               .arg( aName ).arg( GetName() );
592   aResList << QString( "" );
593
594   if ( IsHas2dPrs() )
595   {
596     // Dump object z-level in viewer
597     Standard_Integer anObjZLevel = -1;
598     if ( GetZLevel( anObjZLevel ) )
599     {
600       aResList << QString( "%1.SetZLevel( %2 );" )
601                   .arg( aName ).arg( anObjZLevel );
602       aResList << QString( "" );
603     }
604   }
605
606   return aResList;
607 }
608
609 QString HYDROData_Entity::getPyTypeID() const
610 {
611   DEBTRACE("HYDROData_Entity::getPyTypeID " << GetKind());
612   switch( GetKind() )
613   {
614     case KIND_IMAGE:             return "KIND_IMAGE";
615     case KIND_POLYLINE:          return "KIND_POLYLINE";
616     case KIND_BATHYMETRY:        return "KIND_BATHYMETRY";
617     case KIND_ALTITUDE:          return "KIND_ALTITUDE";
618     case KIND_IMMERSIBLE_ZONE:   return "KIND_IMMERSIBLE_ZONE";
619     case KIND_RIVER:             return "KIND_RIVER";
620     case KIND_STREAM:            return "KIND_STREAM";
621     case KIND_CONFLUENCE:        return "KIND_CONFLUENCE";
622     case KIND_CHANNEL:           return "KIND_CHANNEL";
623     case KIND_OBSTACLE:          return "KIND_OBSTACLE";
624     case KIND_DIGUE:             return "KIND_DIGUE";
625     case KIND_PROFILE:           return "KIND_PROFILE";
626     case KIND_PROFILEUZ:         return "KIND_PROFILEUZ";
627     case KIND_POLYLINEXY:        return "KIND_POLYLINEXY";
628     case KIND_CALCULATION:       return "KIND_CALCULATION";
629     case KIND_ZONE:              return "KIND_ZONE";
630     case KIND_REGION:            return "KIND_REGION";
631     case KIND_VISUAL_STATE:      return "KIND_VISUAL_STATE";
632     case KIND_ARTIFICIAL_OBJECT: return "KIND_ARTIFICIAL_OBJECT";
633     case KIND_NATURAL_OBJECT:    return "KIND_NATURAL_OBJECT";
634     case KIND_DUMMY_3D:          return "KIND_DUMMY_3D";
635     case KIND_SHAPES_GROUP:      return "KIND_SHAPES_GROUP";
636     case KIND_SPLITTED_GROUP:    return "KIND_SPLITTED_GROUP";
637     case KIND_STREAM_ALTITUDE:   return "KIND_STREAM_ALTITUDE";
638     case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
639     case KIND_STRICKLER_TABLE:   return "KIND_STRICKLER_TABLE";
640     case KIND_LAND_COVER:        return "KIND_LAND_COVER";
641     case KIND_CHANNEL_ALTITUDE:  return "KIND_CHANNEL_ALTITUDE";
642     default:                     return "KIND_UNKNOWN"; ///! Unrecognized object
643   }
644 }
645
646 void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects&            theTreatedObjects,
647                                                  QStringList&                    theScript,
648                                                  const Handle(HYDROData_Entity)& theRefObject,
649                                                  const QString&                  theMethod ) const
650 {
651   if ( !checkObjectPythonDefinition( theTreatedObjects, theScript, theRefObject ) )
652     return;
653
654   QString aRefObjName = theRefObject->GetObjPyName();
655
656   QString anObjName = GetObjPyName();
657   theScript << QString( "%1.%2( %3 );" )
658                .arg( anObjName ).arg( theMethod ).arg( aRefObjName );
659 }
660
661 bool HYDROData_Entity::checkObjectPythonDefinition( MapOfTreatedObjects&            theTreatedObjects,
662                                                     QStringList&                    theScript,
663                                                     const Handle(HYDROData_Entity)& theRefObject ) const
664 {
665   if ( theRefObject.IsNull() )
666     return false;
667
668   QString aRefObjName = theRefObject->GetName();
669   if ( aRefObjName.isEmpty() )
670     return false;
671
672   if ( theTreatedObjects.contains( aRefObjName ) )
673     return true;
674
675   // The definition of reference object must be dumped before this
676   QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects );
677   if ( aRefObjDump.isEmpty() )
678     return false;
679
680   QStringList aTmpList = theScript;
681   theScript = aRefObjDump;
682
683   theScript << QString( "" );
684   theScript << aTmpList;
685
686   theTreatedObjects.insert( aRefObjName, theRefObject );
687
688   return true;
689 }
690
691 void HYDROData_Entity::setPythonObjectColor( QStringList&         theScript,
692                                              const QColor&        theColor,
693                                              const QColor&        theDefaultColor,
694                                              const QString&       theMethod ) const
695 {
696   if ( theColor == theDefaultColor )
697     return; //Do not set the color for object if it like default
698
699   QString anObjName = GetObjPyName();
700   theScript << QString( "%1.%2( QColor( %3, %4, %5, %6 ) );" )
701               .arg( anObjName ).arg( theMethod )
702               .arg( theColor.red()  ).arg( theColor.green() )
703               .arg( theColor.blue() ).arg( theColor.alpha() );
704 }
705
706 void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
707                                                   QStringList& theScript ) const
708 {
709   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
710   if ( aDocument.IsNull() )
711     return;
712     
713   theScript << QString( "%1 = %2.FindObjectByName( \"%3\" );" ).arg( GetObjPyName() )
714                                                                .arg( aDocument->GetDocPyName() )
715                                                                .arg( GetName() );
716 }