Salome HOME
Merge remote-tracking branch 'origin/BR_LAND_COVER' into BR_v14_rc
[modules/hydro.git] / src / HYDROData / HYDROData_Entity.cxx
index 4c1ed735f799d96d7bd44f9056b8f72733311ff0..bd47a0901b01a77cefa535af91340f540d39da8c 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)
@@ -65,6 +85,11 @@ void HYDROData_Entity::Update()
   SetToUpdate( false );
 }
 
+void HYDROData_Entity::UpdateLocalCS( double theDx, double theDy )
+{
+  //On the base level no actions are necessary
+}
+
 bool HYDROData_Entity::IsHas2dPrs() const
 {
   return false;
@@ -144,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
@@ -551,6 +599,8 @@ QString HYDROData_Entity::getPyTypeID() const
     case KIND_SPLITTED_GROUP:    return "KIND_SPLITTED_GROUP";
     case KIND_STREAM_ALTITUDE:   return "KIND_STREAM_ALTITUDE";
     case KIND_OBSTACLE_ALTITUDE: return "KIND_OBSTACLE_ALTITUDE";
+    case KIND_STRICKLER_TABLE:   return "KIND_STRICKLER_TABLE";
+    case KIND_LAND_COVER:        return "KIND_LAND_COVER";
     default:                     return "KIND_UNKNOWN"; ///! Unrecognized object
   }
 }
@@ -615,4 +665,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() );
+}