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