Salome HOME
refs #561: the draft data model for Strickler table
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index 01833f9ce9680c7d981c9bbba8a8522e71da2fad..fe5be13a4d3088d33280f2cae71fbe9c12e696ea 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
@@ -173,8 +169,31 @@ HYDROData_Entity::~HYDROData_Entity()
 
 void HYDROData_Entity::CopyTo( const Handle(HYDROData_Entity)& theDestination ) const
 {
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() ) {
+    return;
+  }
+
   TDF_CopyLabel aCopy(myLab, theDestination->Label());
   aCopy.Perform();
+         
+  // generate a new unique name for the clone object:
+  // case 1: Image_1 -> Image_2
+  // case 2: ImageObj -> ImageObj_1
+  QString aName = theDestination->GetName();
+  QString aPrefix = aName;
+  if( aName.contains( '_' ) ) { // case 1
+    QString aSuffix = aName.section( '_', -1 );
+    bool anIsInteger = false;
+    aSuffix.toInt( &anIsInteger );
+    if( anIsInteger )
+      aPrefix = aName.section( '_', 0, -2 );
+  } else { // case 2
+    aPrefix = aName;
+  }
+
+  aName = HYDROData_Tool::GenerateObjectName( aDocument, aPrefix );
+  theDestination->SetName( aName );
 }
 
 Handle(HYDROData_Entity) HYDROData_Entity::GetFatherObject() const