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