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