]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Fix for the bug #135: It is impossible to rename bathymetry: Rename operation is...
authorrkv <rkv@opencascade.com>
Tue, 3 Dec 2013 09:15:26 +0000 (09:15 +0000)
committerrkv <rkv@opencascade.com>
Tue, 3 Dec 2013 09:15:26 +0000 (09:15 +0000)
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataModel.h
src/HYDROGUI/HYDROGUI_Module.h
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index ba34e1e62721aff393d7b80e60dae89b21a62afc..d37789b5b61a58d9ed59202acb78f75c39300ea1 100644 (file)
@@ -849,3 +849,24 @@ bool HYDROGUI_DataModel::createNewRegion( Handle(HYDROData_CalculationCase) theC
   }
   return isOk;
 }
+
+bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QString& theName )
+{
+  if ( theName.isEmpty() )
+    return false;
+
+  try 
+  {
+    getDocument()->StartOperation();
+    theEntity->SetName( theName );
+    getDocument()->CommitOperation( HYDROGUI_Tool::ToExtString( tr("RENAME_TO").arg( theName ) ) );
+    module()->application()->activeStudy()->Modified();
+  }
+  catch ( Standard_Failure )
+  {
+    getDocument()->AbortOperation();
+    return false;
+  }
+  return true;
+}
+
index 060a3db56936e155a39dc47c94da2856ac9c7488..e4d2bcb741332fb518c670838618dbe457f4981d 100644 (file)
@@ -220,6 +220,11 @@ public:
    */
   bool paste();
 
+  /**
+   * Rename the object
+   */
+  bool rename( Handle(HYDROData_Entity) theEntity, const QString& theName );
+
   /**
    * Creates the GUI data object according to the model object.
    * \param theParent a created object will be appended as a child of this object
index 3b09238fa18238279c59bc3058b903541c9b24ed..dc1e7cbc24122262c43fe051787cf3e3f11290b4 100644 (file)
@@ -150,6 +150,18 @@ public:
 
   QStringList                     GetGeomObjectsToImport();
 
+  /**
+   * Returns true if the object with the given entry can be renamed.
+   * @param theEntry the object entry
+   */
+  virtual bool                    renameAllowed( const QString& theEntry ) const;
+  /**
+   * Returns true if the object with the given entry is renamed.
+   * @param theEntry the object entry
+   * @param theName the new name
+   */
+  virtual bool                    renameObject( const QString& theEntry, const QString& theName );
+
 protected:
   CAM_DataModel*                  createDataModel();
 
index 79622a50b0ae4b2fe1251c8b6a9d737e03c004a5..de2587d5fd6a841012ccef2219de54a878c8412b 100644 (file)
@@ -50,6 +50,7 @@
 #include "HYDROGUI_ImportProfilesOp.h"
 #include "HYDROGUI_GeoreferencementOp.h"
 #include "HYDROGUI_SetColorOp.h"
+#include "HYDROGUI_Tool.h"
 
 #include <HYDROData_Document.h>
 #include <HYDROData_Obstacle.h>
@@ -70,6 +71,7 @@
 #include <SUIT_Desktop.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
 
 #include <QAction>
 #include <QApplication>
@@ -478,3 +480,49 @@ QStringList HYDROGUI_Module::GetGeomObjectsToImport()
 {
   return myGeomObjectsToImport;
 }
+
+/**
+ * Returns true if the object with the given entry can be renamed.
+ * @param theEntry the object entry
+ */
+bool HYDROGUI_Module::renameAllowed( const QString& theEntry ) const
+{
+  // Allow to rename all HYDRO objects
+  Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
+  return !anEntity.IsNull();
+}
+/**
+ * Returns true if the object with the given entry is renamed.
+ * @param theEntry the object entry
+ * @param theName the new name
+ */
+bool HYDROGUI_Module::renameObject( const QString& theEntry, const QString& theName )
+{
+  Handle(HYDROData_Entity) anEntity = getDataModel()->objectByEntry( theEntry );
+  bool aRes = !anEntity.IsNull();
+  if ( aRes )
+  {
+    HYDROGUI_DataModel* aModel = getDataModel();
+    if( aModel )
+    {
+      if( anEntity->GetName() != theName )
+      {
+        // check that there are no other objects with the same name in the document
+        Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( this, theName );
+        aRes = anObject.IsNull();
+        if ( aRes )
+        {
+          aRes = aModel->rename( anEntity, theName );
+        }
+        else
+        {
+          // Inform the user that the name is already used
+          QString aTitle = QObject::tr( "INSUFFICIENT_INPUT_DATA" );
+          QString aMessage = QObject::tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( theName );
+          SUIT_MessageBox::critical( getApp()->desktop(), aTitle, aMessage );
+        }
+      }
+    }
+  }
+  return aRes;
+}
index b94d2147ff4dadd8db4ffeaf1cb2dec7dc937d6f..bd1226123c10c22c42f0ab9fa743c5c671011263 100644 (file)
@@ -3,6 +3,10 @@
   
   <context>
     <name>@default</name>
+    <message>
+      <source>RENAME_TO</source>
+      <translation>Rename to %1</translation>
+    </message>
     <message>
       <source>DEFAULT_IMAGE_NAME</source>
       <translation>Image</translation>