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