From d5985aa1399ef1c21f3d9eafe4414afa1d07fc14 Mon Sep 17 00:00:00 2001 From: adv Date: Tue, 29 Oct 2013 12:05:26 +0000 Subject: [PATCH] The Regions and Zones management corrected for Calculation case. --- src/HYDROData/HYDROData_Calculation.cxx | 47 ++++++++++++++++++------- src/HYDROData/HYDROData_Calculation.h | 19 ++++++++-- src/HYDROData/HYDROData_Region.cxx | 20 +++++++---- src/HYDROData/HYDROData_Region.h | 5 +-- 4 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/HYDROData/HYDROData_Calculation.cxx b/src/HYDROData/HYDROData_Calculation.cxx index c70d300a..ff8415a6 100644 --- a/src/HYDROData/HYDROData_Calculation.cxx +++ b/src/HYDROData/HYDROData_Calculation.cxx @@ -97,13 +97,13 @@ void HYDROData_Calculation::SplitGeometryObjects() const HYDROData_SplitToZonesTool::SplitData& aSplitData = anIter.next(); // Create new region - Handle(HYDROData_Region) aRegion = AddNewRegion(); + Handle(HYDROData_Region) aRegion = addNewRegion(); QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" ); aRegion->SetName( aRegionName ); // Add the zone for region - Handle(HYDROData_Zone) aRegionZone = aRegion->AddNewZone(); + Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone(); QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" ); aRegionZone->SetName( aZoneName ); @@ -159,18 +159,26 @@ void HYDROData_Calculation::RemoveGeometryObjects() ClearReferenceObjects( DataTag_GeometryObject ); } -Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion() +Handle(HYDROData_Region) HYDROData_Calculation::AddNewRegion( const Handle(HYDROData_Zone)& theZone ) { - TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild(); + Handle(HYDROData_Region) aNewRegion = addNewRegion(); + if ( aNewRegion.IsNull() ) + return aNewRegion; - Handle(HYDROData_Region) aNewRegion = - Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) ); - AddRegion( aNewRegion ); + // Generate new name for new region + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( this ); + if ( !aDocument.IsNull() ) + { + QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" ); + aNewRegion->SetName( aNewRegionName ); + } + + aNewRegion->AddZone( theZone ); return aNewRegion; } -bool HYDROData_Calculation::AddRegion( Handle(HYDROData_Region)& theRegion ) +bool HYDROData_Calculation::AddRegion( const Handle(HYDROData_Region)& theRegion ) { if ( theRegion.IsNull() ) return false; @@ -183,12 +191,12 @@ bool HYDROData_Calculation::AddRegion( Handle(HYDROData_Region)& theRegion ) Handle(HYDROData_Calculation)::DownCast( theRegion->GetFatherObject() ); if ( !aFatherCalc.IsNull() && aFatherCalc->Label() != myLab ) { - Handle(HYDROData_Region) aNewRegion = AddNewRegion(); + Handle(HYDROData_Region) aNewRegion = addNewRegion(); theRegion->CopyTo( aNewRegion ); aFatherCalc->RemoveRegion( theRegion ); - theRegion = aNewRegion; + theRegion->SetLabel( aNewRegion->Label() ); } AddReferenceObject( theRegion, DataTag_Region ); @@ -202,13 +210,16 @@ HYDROData_SequenceOfObjects HYDROData_Calculation::GetRegions() const void HYDROData_Calculation::RemoveRegion( const Handle(HYDROData_Region)& theRegion ) { - if ( theRegion.IsNull() || !HasReference( theRegion, DataTag_Region ) ) + if ( theRegion.IsNull() ) return; RemoveReferenceObject( theRegion->Label(), DataTag_Region ); // Remove region from data model - theRegion->Remove(); + Handle(HYDROData_Calculation) aFatherCalc = + Handle(HYDROData_Calculation)::DownCast( theRegion->GetFatherObject() ); + if ( !aFatherCalc.IsNull() && aFatherCalc->Label() == myLab ) + theRegion->Remove(); } void HYDROData_Calculation::RemoveRegions() @@ -216,3 +227,15 @@ void HYDROData_Calculation::RemoveRegions() ClearReferenceObjects( DataTag_Region ); myLab.FindChild( ChildTag_Region ).ForgetAllAttributes( true ); } + +Handle(HYDROData_Region) HYDROData_Calculation::addNewRegion() +{ + TDF_Label aNewLab = myLab.FindChild( ChildTag_Region ).NewChild(); + + Handle(HYDROData_Region) aNewRegion = + Handle(HYDROData_Region)::DownCast( HYDROData_Iterator::CreateObject( aNewLab, KIND_REGION ) ); + AddRegion( aNewRegion ); + + return aNewRegion; +} + diff --git a/src/HYDROData/HYDROData_Calculation.h b/src/HYDROData/HYDROData_Calculation.h index 4e7856ab..1590c257 100644 --- a/src/HYDROData/HYDROData_Calculation.h +++ b/src/HYDROData/HYDROData_Calculation.h @@ -7,6 +7,7 @@ class Handle(HYDROData_Object); class Handle(HYDROData_Region); +class Handle(HYDROData_Zone); DEFINE_STANDARD_HANDLE(HYDROData_Calculation, HYDROData_Entity) @@ -85,16 +86,19 @@ public: /** - * Add new one region for calculation case. + * Add new one child region for calculation case. * The new region is added into the list of reference regions. + * The label of theZone is changed during this operation + * because of new region becomes the new parent for this zone. */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion(); + HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion( const Handle(HYDROData_Zone)& theZone ); /** * Add new one reference region for calculation case. + * The label of theRegion is changed in case if old parent is not this calculation. */ - HYDRODATA_EXPORT virtual bool AddRegion( Handle(HYDROData_Region)& theRegion ); + HYDRODATA_EXPORT virtual bool AddRegion( const Handle(HYDROData_Region)& theRegion ); /** * Returns all reference regions of calculation case. @@ -111,6 +115,15 @@ public: */ HYDRODATA_EXPORT virtual void RemoveRegions(); +private: + + /** + * Add new one region for calculation case. + * The new region is added into the list of reference regions. + */ + HYDRODATA_EXPORT virtual Handle(HYDROData_Region) addNewRegion(); + + protected: friend class HYDROData_Iterator; diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 10275833..a9b9923f 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -53,7 +53,7 @@ QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjec return aResList; } -bool HYDROData_Region::AddZone( Handle(HYDROData_Zone)& theZone ) +bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone ) { if ( theZone.IsNull() ) return false; @@ -66,12 +66,12 @@ bool HYDROData_Region::AddZone( Handle(HYDROData_Zone)& theZone ) Handle(HYDROData_Region)::DownCast( theZone->GetFatherObject() ); if ( !aFatherRegion.IsNull() && aFatherRegion->Label() != myLab ) { - Handle(HYDROData_Zone) aNewZone = AddNewZone(); + Handle(HYDROData_Zone) aNewZone = addNewZone(); theZone->CopyTo( aNewZone ); aFatherRegion->RemoveZone( theZone ); - theZone = aNewZone; + theZone->SetLabel( aNewZone->Label() ); } AddReferenceObject( theZone, DataTag_Zone ); @@ -85,13 +85,21 @@ HYDROData_SequenceOfObjects HYDROData_Region::GetZones() const void HYDROData_Region::RemoveZone( const Handle(HYDROData_Zone)& theZone ) { - if ( theZone.IsNull() || !HasReference( theZone, DataTag_Zone ) ) + if ( theZone.IsNull() ) return; RemoveReferenceObject( theZone->Label(), DataTag_Zone ); // Remove zone from data model - theZone->Remove(); + 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() @@ -100,7 +108,7 @@ void HYDROData_Region::RemoveZones() myLab.FindChild( ChildTag_Zone ).ForgetAllAttributes( true ); } -Handle(HYDROData_Zone) HYDROData_Region::AddNewZone() +Handle(HYDROData_Zone) HYDROData_Region::addNewZone() { TDF_Label aNewLab = myLab.FindChild( ChildTag_Zone ).NewChild(); diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index 6a4fd316..5a331837 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -51,8 +51,9 @@ public: /** * Add new one reference zone for region. + * The label of theZone is changed in case if old parent is not this region. */ - HYDRODATA_EXPORT virtual bool AddZone( Handle(HYDROData_Zone)& theZone ); + HYDRODATA_EXPORT virtual bool AddZone( const Handle(HYDROData_Zone)& theZone ); /** * Returns all reference zone of region. @@ -76,7 +77,7 @@ protected: * Create new one reference zone for region on child label. * The new zone is added into the list of reference zones. */ - HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) AddNewZone(); + HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) addNewZone(); protected: -- 2.39.2