Salome HOME
Dump to python corrected.
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
index 68e759d729dc1ba2c6bf485ed9d56df19aa64885..072b0d2290baa22a03bf24b3bb9c701281c0d07c 100644 (file)
@@ -6,10 +6,20 @@
 #include "HYDROData_Iterator.h"
 #include "HYDROData_NaturalObject.h"
 
+#include <TopoDS_Shape.hxx>
+
+#include <TopTools_SequenceOfShape.hxx>
+
+#include <TopExp_Explorer.hxx>
+
 #include <QFile>
 #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 )
@@ -85,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++ ) );
 
@@ -156,3 +166,48 @@ bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject
   return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
          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