Salome HOME
refs #561: the draft data model for Strickler table
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index fc5fe6c2d82493c5dc07de427a120fdc2e67090f..fe5be13a4d3088d33280f2cae71fbe9c12e696ea 100644 (file)
@@ -1,3 +1,20 @@
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "HYDROData_Entity.h"
 
@@ -46,7 +63,10 @@ QString HYDROData_Entity::GetName() const
 
 QString HYDROData_Entity::GetObjPyName() const
 {
-  return GetName().replace(" ", "_");
+  QString aName = GetName();
+  aName.replace(QRegExp("[\\W]"), "_");
+
+  return aName;
 }
 
 void HYDROData_Entity::SetName(const QString& theName)
@@ -149,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
@@ -620,4 +663,14 @@ void HYDROData_Entity::setPythonObjectColor( QStringList&         theScript,
               .arg( theColor.blue() ).arg( theColor.alpha() );
 }
 
-
+void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects,
+                                                  QStringList& theScript ) const
+{
+  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+  if ( aDocument.IsNull() )
+    return;
+    
+  theScript << QString( "%1 = %2.FindObjectByName( \"%3\" );" ).arg( GetObjPyName() )
+                                                               .arg( aDocument->GetDocPyName() )
+                                                               .arg( GetName() );
+}