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