]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1338 BR_1338
authorisn <isn@opencascade.com>
Tue, 17 Oct 2017 12:07:33 +0000 (15:07 +0300)
committerisn <isn@opencascade.com>
Thu, 26 Oct 2017 09:20:21 +0000 (12:20 +0300)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h

index 63a816a341f9bda7ceb03c594587cef78294e38f..ff5dd2980a6078f20982a483ab1d1b56403585eb 100644 (file)
@@ -674,31 +674,31 @@ void HYDROData_CalculationCase::UpdateRegionsOrder()
   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 )
index b45c2970d3c220b85e956b9e578b388318c434c3..812bccb6b8ed006f2ee6e5335d57fa1a3339a3b5 100644 (file)
@@ -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,
index 359ddf5b136bfd64c594d1fedd4f1da711eaeb5b..25bcf370861ee194a4fe7746a8db10e9648f51c9 100644 (file)
@@ -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.