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