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