From 85eaba6cfd3cd0b88d4228afee4670ad75985377 Mon Sep 17 00:00:00 2001 From: adv Date: Tue, 12 Nov 2013 07:44:13 +0000 Subject: [PATCH] Update names of regions in calculation case if its order has been changed (Bug #47). --- src/HYDROData/HYDROData_CalculationCase.cxx | 48 +++++++++++++++++++-- src/HYDROData/HYDROData_CalculationCase.h | 5 +++ src/HYDROData/HYDROData_Region.cxx | 12 ++++++ src/HYDROData/HYDROData_Region.h | 7 +++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 7bfffe60..326af741 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -11,6 +11,9 @@ #include "HYDROData_Tool.h" #include "HYDROData_Zone.h" +#define CALCULATION_REGIONS_PREF GetName() + "_Reg" +#define CALCULATION_ZONES_PREF GetName() + "_Zone" + #define PYTHON_CALCULATION_ID "KIND_CALCULATION" IMPLEMENT_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity) @@ -92,6 +95,9 @@ void HYDROData_CalculationCase::SplitGeometryObjects() if ( aSplitedZones.isEmpty() ) return; + QString aRegsPref = CALCULATION_REGIONS_PREF; + QString aZonesPref = CALCULATION_ZONES_PREF; + // Create result regions for case, by default one zone for one region HYDROData_SplitToZonesTool::SplitDataListIterator anIter( aSplitedZones ); while( anIter.hasNext() ) @@ -101,13 +107,13 @@ void HYDROData_CalculationCase::SplitGeometryObjects() // Create new region Handle(HYDROData_Region) aRegion = addNewRegion(); - QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" ); + QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref ); aRegion->SetName( aRegionName ); // Add the zone for region Handle(HYDROData_Zone) aRegionZone = aRegion->addNewZone(); - QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, "Zone" ); + QString aZoneName = HYDROData_Tool::GenerateObjectName( aDocument, aZonesPref ); aRegionZone->SetName( aZoneName ); aRegionZone->SetShape( aSplitData.Face() ); @@ -206,7 +212,9 @@ Handle(HYDROData_Region) HYDROData_CalculationCase::AddNewRegion( const Handle(H Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); if ( !aDocument.IsNull() ) { - QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, "Region" ); + QString aRegsPref = CALCULATION_REGIONS_PREF; + + QString aNewRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref ); aNewRegion->SetName( aNewRegionName ); } @@ -248,6 +256,40 @@ HYDROData_SequenceOfObjects HYDROData_CalculationCase::GetRegions() const return GetReferenceObjects( DataTag_Region ); } +void HYDROData_CalculationCase::UpdateRegionsOrder() +{ + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) + return; + + HYDROData_SequenceOfObjects aRegions = GetRegions(); + + HYDROData_SequenceOfObjects::Iterator anIter( aRegions ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Region) aRegion = + Handle(HYDROData_Region)::DownCast( anIter.Value() ); + if ( aRegion.IsNull() ) + continue; + + aRegion->SetName( "" ); + } + + QString aRegsPref = CALCULATION_REGIONS_PREF; + + anIter.Init( aRegions ); + for ( ; anIter.More(); anIter.Next() ) + { + Handle(HYDROData_Region) aRegion = + Handle(HYDROData_Region)::DownCast( anIter.Value() ); + if ( aRegion.IsNull() ) + continue; + + QString aRegionName = HYDROData_Tool::GenerateObjectName( aDocument, aRegsPref ); + aRegion->SetName( aRegionName ); + } +} + void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion ) { if ( theRegion.IsNull() ) diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index d6d6ac45..77edbf77 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -115,6 +115,11 @@ public: */ HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetRegions() const; + /** + * Updates names of regions to correct order. + */ + HYDRODATA_EXPORT virtual void UpdateRegionsOrder(); + /** * Removes reference region from calculation case. */ diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 6e0a0f1d..82a3b7c8 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -1,6 +1,7 @@ #include "HYDROData_Region.h" +#include "HYDROData_CalculationCase.h" #include "HYDROData_Document.h" #include "HYDROData_Iterator.h" #include "HYDROData_Zone.h" @@ -53,6 +54,17 @@ QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjec return aResList; } +void HYDROData_Region::Remove() +{ + Handle(HYDROData_CalculationCase) aFatherCalc = + Handle(HYDROData_CalculationCase)::DownCast( GetFatherObject() ); + + HYDROData_Entity::Remove(); + + if ( !aFatherCalc.IsNull() ) + aFatherCalc->UpdateRegionsOrder(); +} + bool HYDROData_Region::AddZone( const Handle(HYDROData_Zone)& theZone ) { if ( theZone.IsNull() ) diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index 5ba5bf96..f0d2075f 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -41,6 +41,13 @@ public: HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + /** + * Removes object and it child sub-objects from the data structure. + * Reimplemented to update names of regions in father calculation. + */ + HYDRODATA_EXPORT virtual void Remove(); + + /** * Add new one reference zone for region. * The label of theZone is changed in case if old parent is not this region. -- 2.39.2