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