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