From: isn Date: Tue, 17 Oct 2017 12:07:33 +0000 (+0300) Subject: refs #1338 X-Git-Tag: v2.1~66^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FBR_1338;p=modules%2Fhydro.git refs #1338 --- diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 63a816a3..ff5dd298 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -674,31 +674,31 @@ void HYDROData_CalculationCase::UpdateRegionsOrder() if ( aDocument.IsNull() ) return; + QString aRegsPref = CALCULATION_REGIONS_PREF; + std::map IndToRegion; //index in the name of region to region itself HYDROData_SequenceOfObjects aRegions = GetRegions(); HYDROData_SequenceOfObjects::Iterator anIter( aRegions ); + QString aName; + int aVal; for ( ; anIter.More(); anIter.Next() ) { - Handle(HYDROData_Region) aRegion = - Handle(HYDROData_Region)::DownCast( anIter.Value() ); + Handle(HYDROData_Region) aRegion = Handle(HYDROData_Region)::DownCast( anIter.Value() ); if ( aRegion.IsNull() ) continue; - aRegion->SetName( "" ); + if (HYDROData_Tool::ExtractGeneratedObjectName(aRegion->GetName(), aVal, aName) && aName == aRegsPref) + IndToRegion[aVal] = aRegion; } - 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 ); - } + int nbR = aRegions.Length(); + std::map::iterator it = IndToRegion.begin(); + for( int i = 1; it != IndToRegion.end(); ++it ) + if (it->first <= nbR + 1) + { + QString aNewName = QString("%1_%2").arg(aRegsPref).arg(QString::number(i)); + it->second->SetName(aNewName); + i++; + } } void HYDROData_CalculationCase::RemoveRegion( const Handle(HYDROData_Region)& theRegion ) diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index b45c2970..812bccb6 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -70,6 +70,20 @@ void HYDROData_Tool::WriteStringsToFile( QFile& theFile, anOutStream << aWriteStr.toUtf8() << theSep << theSep; } +bool HYDROData_Tool::ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName) +{ + QStringList aLs = theName.split('_'); + bool ok = false; + QString last = aLs.last(); + outValue = last.toInt(&ok); + if (!ok) + return false; + int last_len = last.length(); + int total_len = theName.length(); + thePrefName = theName.left(total_len-last_len-1); + return true; +} + QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc, const QString& thePrefix, const QStringList& theUsedNames, diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index 359ddf5b..25bcf370 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -62,6 +62,9 @@ public: const QString& thePrefix, const QStringList& theUsedNames = QStringList(), const bool theIsTryToUsePurePrefix = false ); + + + static bool ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName); /** * \brief Checks the type of object.