]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Updating of child objects names.
authoradv <adv@opencascade.com>
Fri, 20 Dec 2013 10:28:07 +0000 (10:28 +0000)
committeradv <adv@opencascade.com>
Fri, 20 Dec 2013 10:28:07 +0000 (10:28 +0000)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h

index 1b72cba377da9bb640b5b57621fd8f1f2e1423d4..198222ab62a76428d734c9c6163ba39374c9eb0f 100644 (file)
@@ -70,12 +70,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName )
       if ( aRegion.IsNull() )
         continue;
 
-      QString aRegionName = aRegion->GetName();
-      if ( aRegionName.startsWith( anOldCaseName ) )
-      {
-        aRegionName.replace( anOldCaseName, theName );
-        aRegion->SetName( aRegionName );
-      }
+      HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
 
       HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
       HYDROData_SequenceOfObjects::Iterator anIter( aZones );
@@ -86,12 +81,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName )
         if ( aRegZone.IsNull() )
           continue;
 
-        QString aRegionZoneName = aRegZone->GetName();
-        if ( aRegionZoneName.startsWith( anOldCaseName ) )
-        {
-          aRegionZoneName.replace( anOldCaseName, theName );
-          aRegZone->SetName( aRegionZoneName );
-        }
+        HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
       }
     }
 
@@ -105,12 +95,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName )
       if ( aGroup.IsNull() )
         continue;
 
-      QString aGroupName = aGroup->GetName();
-      if ( aGroupName.startsWith( anOldCaseName ) )
-      {
-        aGroupName.replace( anOldCaseName, theName );
-        aGroup->SetName( aGroupName );
-      }
+      HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
     }
   }
 
index e507b9f778d4869dcc5e5620458a8082143a4048..ac9045f7698178c401defe6a3e73c454de4d883a 100644 (file)
@@ -163,3 +163,28 @@ 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 );
+}
+
index cf48d52c107b21de103a075864394d1a68db2021..99fd175489791f952786550bde8cdbd7de991b29 100644 (file)
@@ -73,6 +73,16 @@ public:
    */
   static bool                           IsGeometryObject( const Handle(HYDROData_Entity)& theObject );
 
+  /**
+   * \brief Updates the child object name.
+   * \param theOldStr old father object name
+   * \param theNewStr new father object name
+   * \param theObject object to update
+   */
+  static void                           UpdateChildObjectName( const QString&                  theOldStr,
+                                                               const QString&                  theNewStr,
+                                                               const Handle(HYDROData_Entity)& theObject );
+
 };
 
 inline bool ValuesEquals( const double& theFirst, const double& theSecond )