#include <QStringList>
-#include <TDataStd_Integer.hxx>
-
#define PYTHON_REGION_ID "KIND_REGION"
IMPLEMENT_STANDARD_HANDLE(HYDROData_Region, HYDROData_Entity)
HYDROData_Region::HYDROData_Region()
: HYDROData_Entity()
{
- SetMergeType( Merge_ZMIN );
}
HYDROData_Region::~HYDROData_Region()
return aResList;
}
-Handle(HYDROData_Zone) HYDROData_Region::AddNewZone()
-{
- TDF_Label aNewLab = myLab.FindChild( ChildTag_Zone ).NewChild();
-
- return Handle(HYDROData_Zone)::DownCast(
- HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );
-}
-
-void HYDROData_Region::RemoveChildZones()
+bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
{
- myLab.FindChild( ChildTag_Zone ).ForgetAllAttributes( true );
-}
-
-void HYDROData_Region::SetMergeType( const MergeBathymetriesType& theType )
-{
- Handle(TDataStd_Integer) anInt;
- if ( !myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
- anInt = TDataStd_Integer::Set( myLab, 0 );
- anInt->Set( (int)theType );
-}
-
-HYDROData_Region::MergeBathymetriesType HYDROData_Region::GetMergeType() const
-{
- MergeBathymetriesType aMergeType = Merge_ZMIN;
+ if ( theZone.IsNull() )
+ return false;
- Handle(TDataStd_Integer) anInt;
- if ( myLab.FindChild( DataTag_MergeType ).FindAttribute( TDataStd_Integer::GetID(), anInt ) )
- aMergeType = (MergeBathymetriesType)anInt->Get();
-
- return aMergeType;
-}
-
-int HYDROData_Region::NbZones() const
-{
- return NbReferenceObjects( DataTag_Zone );
-}
-
-void HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone )
-{
- AddReferenceObject( theZone, DataTag_Zone );
-}
+ if ( HasReference( theZone, DataTag_Zone ) )
+ return false; // Object is already in reference list
-void HYDROData_Region::SetZone( const int theIndex,
- const Handle(HYDROData_Zone)& theZone )
-{
- SetReferenceObject( theZone, DataTag_Zone, theIndex );
-}
+ // Move the zone from other region
+ Handle(HYDROData_Region) aFatherRegion =
+ Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
+ if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab )
+ {
+ Handle(HYDROData_Zone) aNewZone = addNewZone();
+ theZone->CopyTo( aNewZone );
-void HYDROData_Region::InsertZone( const int theBeforeIndex,
- const Handle(HYDROData_Zone)& theZone )
-{
- InsertReferenceObject( theZone, DataTag_Zone, theBeforeIndex );
-}
+ aFatherRegion->RemoveZone( theZone );
-void HYDROData_Region::SetZones( const HYDROData_SequenceOfObjects& theZones )
-{
- SetReferenceObjects( theZones, DataTag_Zone );
-}
+ theZone->SetLabel( aNewZone->Label() );
+ }
-Handle(HYDROData_Zone) HYDROData_Region::GetZone( const int theIndex ) const
-{
- return Handle(HYDROData_Zone)::DownCast(
- GetReferenceObject( DataTag_Zone, theIndex ) );
+ AddReferenceObject( theZone, DataTag_Zone );
+ return true;
}
HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const
return;
RemoveReferenceObject( theZone->Label(), DataTag_Zone );
-}
-void HYDROData_Region::RemoveZone( const int theIndex )
-{
- RemoveReferenceObject( DataTag_Zone, theIndex );
+ // Remove zone from data model
+ Handle(HYDROData_Region) aFatherRegion =
+ Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() );
+ if ( !aFatherRegion.IsNull() && aFatherRegion->Label() == myLab )
+ theZone->Remove();
+
+ // If the last zone has been removed from region we remove this region
+ HYDROData_SequenceOfObjects aRefZones = GetZones();
+ if ( aRefZones.IsEmpty() )
+ Remove();
}
void HYDROData_Region::RemoveZones()
{
ClearReferenceObjects( DataTag_Zone );
+ myLab.FindChild( DataTag_ChildZone ).ForgetAllAttributes( true );
}
+Handle(HYDROData_Zone) HYDROData_Region::addNewZone()
+{
+ TDF_Label aNewLab = myLab.FindChild( DataTag_ChildZone ).NewChild();
+
+ Handle(HYDROData_Zone) aNewZone =
+ Handle(HYDROData_Zone)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_ZONE ) );
+ AddZone( aNewZone );
+
+ return aNewZone;
+}