Salome HOME
Dump to python corrected.
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
index d05696b77801cfdc49df41a44322ab9fd036ccaa..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,20 +167,47 @@ bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject
          theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );
 }
 
-void HYDROData_Tool::ExploreShapeToShapes( const TopoDS_Shape&       theInShape,
-                                           const TopAbs_ShapeEnum&   theExpType,
-                                           TopTools_SequenceOfShape& theOutShapes )
+void HYDROData_Tool::UpdateChildObjectName( const QString&                  theOldStr,
+                                            const QString&                  theNewStr,
+                                            const Handle(HYDROData_Entity)& theObject )
 {
-  theOutShapes.Clear();
-
-  if ( theInShape.IsNull() )
+  if ( theObject.IsNull() )
     return;
 
-  TopExp_Explorer anExp( theInShape, theExpType );
-  for ( ; anExp.More(); anExp.Next() )
+  QString anObjName = theObject->GetName();
+  if ( theOldStr.isEmpty() )
   {
-    TopoDS_Shape anExpShape = anExp.Current();
-    theOutShapes.Append( anExpShape );
+    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