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