Salome HOME
Dump to python corrected.
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
index a239b55f0592e5132c73faa1eb8ad7630eae5859..072b0d2290baa22a03bf24b3bb9c701281c0d07c 100644 (file)
 #include <QStringList>
 #include <QTextStream>
 
+#include <limits>
+
+static int aMaxNameId = std::numeric_limits<int>::max();
+
 void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
                                          const QStringList& theStrings,
                                          const QString&     theSep )
@@ -91,8 +95,7 @@ QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& th
     aName = thePrefix;
   } else {
     int anId = 1;
-    int aMaxId = std::numeric_limits<int>::max();
-    while( anId < aMaxId )
+    while( anId < aMaxNameId )
     {
       aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
 
@@ -189,3 +192,22 @@ void HYDROData_Tool::UpdateChildObjectName( const QString&                  theO
   theObject->SetName( anObjName );
 }
 
+QString HYDROData_Tool::GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
+                                               const QString&             thePrefix )
+{
+  QString aName = thePrefix;
+  if ( !theTreatedObjects.contains( aName ) )
+    return aName;
+
+  int anId = 1;
+  while( anId < aMaxNameId )
+  {
+    aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
+
+    // check that there are no other objects with the same name
+    if ( !theTreatedObjects.contains( aName ) )
+      break;
+  }
+
+  return aName;
+}
\ No newline at end of file