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