Salome HOME
Dump to python corrected.
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
index e507b9f778d4869dcc5e5620458a8082143a4048..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,7 +95,7 @@ QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& th
     aName = thePrefix;
   } else {
     int anId = 1;
-    while( anId < 1000 )
+    while( anId < aMaxNameId )
     {
       aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
 
@@ -163,3 +167,47 @@ 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 );
+}
+
+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