2 #include "HYDROData_Region.h"
4 #include "HYDROData_CalculationCase.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_Iterator.h"
7 #include "HYDROData_Zone.h"
11 #define PYTHON_REGION_ID "KIND_REGION"
13 IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity)
14 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Region, HYDROData_Entity)
17 HYDROData_Region::HYDROData_Region()
22 HYDROData_Region::~HYDROData_Region()
26 QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
30 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
31 if ( aDocument.IsNull() )
34 QString aDocName = aDocument->GetDocPyName();
35 QString aRegionName = GetName();
37 aResList << QString( "%1 = %2.CreateObject( %3 );" )
38 .arg( aRegionName ).arg( aDocName ).arg( PYTHON_REGION_ID );
39 aResList << QString( "%1.SetName( \"%2\" );" )
40 .arg( aRegionName ).arg( aRegionName );
41 aResList << QString( "" );
43 HYDROData_SequenceOfObjects aZones = GetZones();
44 HYDROData_SequenceOfObjects::Iterator anIter( aZones );
45 for ( ; anIter.More(); anIter.Next() )
47 Handle(HYDROData_Zone) aRefZone =
48 Handle(HYDROData_Zone)::DownCast( anIter.Value() );
49 if ( !aRefZone.IsNull() )
50 setPythonReferenceObject( theTreatedObjects, aResList, aRefZone, "AddZone" );
52 aResList << QString( "" );
57 void HYDROData_Region::Remove()
59 Handle(HYDROData_CalculationCase) aFatherCalc =
60 Handle(HYDROData_CalculationCase)::DownCast( GetFatherObject() );
62 HYDROData_Entity::Remove();
64 if ( !aFatherCalc.IsNull() )
65 aFatherCalc->UpdateRegionsOrder();
68 bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
70 if ( theZone.IsNull() )
73 if ( HasReference( theZone, DataTag_Zone ) )
74 return false; // Object is already in reference list
76 // Move the zone from other region
77 Handle(HYDROData_Region) aFatherRegion =
78 Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
79 if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab )
81 Handle(HYDROData_Zone) aNewZone = addNewZone();
82 theZone->CopyTo( aNewZone );
84 aFatherRegion->RemoveZone( theZone );
86 theZone->SetLabel( aNewZone->Label() );
90 AddReferenceObject( theZone, DataTag_Zone );
96 HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const
98 return GetReferenceObjects( DataTag_Zone );
101 void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone )
103 if ( theZone.IsNull() )
106 RemoveReferenceObject( theZone->Label(), DataTag_Zone );
108 // Remove zone from data model
109 Handle(HYDROData_Region) aFatherRegion =
110 Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
111 if ( !aFatherRegion.IsNull() && aFatherRegion->Label() == myLab )
114 // If the last zone has been removed from region we remove this region
115 HYDROData_SequenceOfObjects aRefZones = GetZones();
116 if ( aRefZones.IsEmpty() )
120 void HYDROData_Region::RemoveZones()
122 ClearReferenceObjects( DataTag_Zone );
123 myLab.FindChild( DataTag_ChildZone ).ForgetAllAttributes( true );
126 Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
128 TDF_Label aNewLab = myLab.FindChild( DataTag_ChildZone ).NewChild();
130 Handle(HYDROData_Zone) aNewZone =
131 Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );