From: rkv Date: Tue, 3 Dec 2013 09:15:26 +0000 (+0000) Subject: Fix for the bug #135: It is impossible to rename bathymetry: Rename operation is... X-Git-Tag: BR_hydro_v_0_4~84 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=79d802c86c6ccf353dbc6ed29a59f2d8136372d0;p=modules%2Fhydro.git Fix for the bug #135: It is impossible to rename bathymetry: Rename operation is available via object browser. --- diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index ba34e1e6..d37789b5 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -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; +} + diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 060a3db5..e4d2bcb7 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -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 diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index 3b09238f..dc1e7cbc 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -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(); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 79622a50..de2587d5 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -50,6 +50,7 @@ #include "HYDROGUI_ImportProfilesOp.h" #include "HYDROGUI_GeoreferencementOp.h" #include "HYDROGUI_SetColorOp.h" +#include "HYDROGUI_Tool.h" #include #include @@ -70,6 +71,7 @@ #include #include #include +#include #include #include @@ -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; +} diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index b94d2147..bd122612 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -3,6 +3,10 @@ @default + + RENAME_TO + Rename to %1 + DEFAULT_IMAGE_NAME Image