From 133cc997adbd3968a1acf9022a9755b48a836b7a Mon Sep 17 00:00:00 2001 From: adv Date: Fri, 20 Dec 2013 10:28:07 +0000 Subject: [PATCH] Updating of child objects names. --- src/HYDROData/HYDROData_CalculationCase.cxx | 21 +++-------------- src/HYDROData/HYDROData_Tool.cxx | 25 +++++++++++++++++++++ src/HYDROData/HYDROData_Tool.h | 10 +++++++++ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 1b72cba3..198222ab 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -70,12 +70,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName ) if ( aRegion.IsNull() ) continue; - QString aRegionName = aRegion->GetName(); - if ( aRegionName.startsWith( anOldCaseName ) ) - { - aRegionName.replace( anOldCaseName, theName ); - aRegion->SetName( aRegionName ); - } + HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion ); HYDROData_SequenceOfObjects aZones = aRegion->GetZones(); HYDROData_SequenceOfObjects::Iterator anIter( aZones ); @@ -86,12 +81,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName ) if ( aRegZone.IsNull() ) continue; - QString aRegionZoneName = aRegZone->GetName(); - if ( aRegionZoneName.startsWith( anOldCaseName ) ) - { - aRegionZoneName.replace( anOldCaseName, theName ); - aRegZone->SetName( aRegionZoneName ); - } + HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone ); } } @@ -105,12 +95,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName ) if ( aGroup.IsNull() ) continue; - QString aGroupName = aGroup->GetName(); - if ( aGroupName.startsWith( anOldCaseName ) ) - { - aGroupName.replace( anOldCaseName, theName ); - aGroup->SetName( aGroupName ); - } + HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup ); } } diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index e507b9f7..ac9045f7 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -163,3 +163,28 @@ bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) ); } +void HYDROData_Tool::UpdateChildObjectName( const QString& theOldStr, + const QString& theNewStr, + const Handle(HYDROData_Entity)& theObject ) +{ + if ( theObject.IsNull() ) + return; + + QString anObjName = theObject->GetName(); + if ( theOldStr.isEmpty() ) + { + while ( anObjName.startsWith( '_' ) ) + anObjName.remove( 0, 1 ); + + anObjName.prepend( theNewStr + "_" ); + } + else if ( anObjName.startsWith( theOldStr ) ) + { + anObjName.replace( 0, theOldStr.length(), theNewStr ); + } + else + return; + + theObject->SetName( anObjName ); +} + diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index cf48d52c..99fd1754 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -73,6 +73,16 @@ public: */ static bool IsGeometryObject( const Handle(HYDROData_Entity)& theObject ); + /** + * \brief Updates the child object name. + * \param theOldStr old father object name + * \param theNewStr new father object name + * \param theObject object to update + */ + static void UpdateChildObjectName( const QString& theOldStr, + const QString& theNewStr, + const Handle(HYDROData_Entity)& theObject ); + }; inline bool ValuesEquals( const double& theFirst, const double& theSecond ) -- 2.39.2