if ( aDocument.IsNull() )
return;
+ QString aRegsPref = CALCULATION_REGIONS_PREF;
+ std::map<int, Handle(HYDROData_Region)> 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<int, Handle(HYDROData_Region)>::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 )
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,
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.