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