From b5b34ba96a5ee7b61e7f225746da9941b3595290 Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 16 Sep 2013 11:45:32 +0000 Subject: [PATCH] Copy/paste functionality for images, polylines and calculation cases. --- src/HYDROGUI/CMakeLists.txt | 2 + src/HYDROGUI/HYDROGUI.vcproj | 28 +++++++- src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx | 74 ++++++++++++++++++++ src/HYDROGUI/HYDROGUI_CopyPasteOp.h | 43 ++++++++++++ src/HYDROGUI/HYDROGUI_DataModel.cxx | 82 +++++++++++++++++++++++ src/HYDROGUI/HYDROGUI_DataModel.h | 25 +++++++ src/HYDROGUI/HYDROGUI_Module.cxx | 24 +++++-- src/HYDROGUI/HYDROGUI_Module.h | 2 + src/HYDROGUI/HYDROGUI_Operations.cxx | 11 +++ src/HYDROGUI/HYDROGUI_Operations.h | 3 + src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 46 ++++++++++--- 11 files changed, 323 insertions(+), 17 deletions(-) create mode 100644 src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx create mode 100644 src/HYDROGUI/HYDROGUI_CopyPasteOp.h diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index 17b7c093..3cbf03ff 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -7,6 +7,7 @@ set(PROJECT_HEADERS HYDROGUI_CalculationDlg.h HYDROGUI_CalculationOp.h HYDROGUI_ColorWidget.h + HYDROGUI_CopyPasteOp.h HYDROGUI_DataModel.h HYDROGUI_DataObject.h HYDROGUI_DeleteOp.h @@ -48,6 +49,7 @@ set(PROJECT_SOURCES HYDROGUI_CalculationDlg.cxx HYDROGUI_CalculationOp.cxx HYDROGUI_ColorWidget.cxx + HYDROGUI_CopyPasteOp.cxx HYDROGUI_DataModel.cxx HYDROGUI_DataObject.cxx HYDROGUI_DeleteOp.cxx diff --git a/src/HYDROGUI/HYDROGUI.vcproj b/src/HYDROGUI/HYDROGUI.vcproj index dd4d2ad6..50be70ba 100644 --- a/src/HYDROGUI/HYDROGUI.vcproj +++ b/src/HYDROGUI/HYDROGUI.vcproj @@ -1,7 +1,7 @@ + + @@ -308,7 +312,7 @@ @@ -322,7 +326,7 @@ @@ -341,6 +345,20 @@ /> + + + + + @@ -815,6 +833,10 @@ RelativePath=".\moc\moc_HYDROGUI_ColorWidget.cxx" > + + diff --git a/src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx b/src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx new file mode 100644 index 00000000..e1e3067d --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx @@ -0,0 +1,74 @@ +// Copyright (C) 2007-2013 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 +// +// 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. +// +// 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 "HYDROGUI_CopyPasteOp.h" + +#include "HYDROGUI_DataModel.h" +#include "HYDROGUI_Module.h" +#include "HYDROGUI_UpdateFlags.h" + +HYDROGUI_CopyPasteOp::HYDROGUI_CopyPasteOp( HYDROGUI_Module* theModule, + const bool theIsPaste ) +: HYDROGUI_Operation( theModule ), + myIsPaste( theIsPaste ) +{ + setName( tr( "COPY_PASTE" ) ); +} + +HYDROGUI_CopyPasteOp::~HYDROGUI_CopyPasteOp() +{ +} + +void HYDROGUI_CopyPasteOp::startOperation() +{ + HYDROGUI_Operation::startOperation(); + + HYDROGUI_DataModel* aModel = module()->getDataModel(); + + bool anIsOk = false; + int aFlags = 0; + if( myIsPaste ) + { + startDocOperation(); + + anIsOk = aModel->paste(); + aFlags = UF_Controls | UF_Model; + + if( anIsOk ) + commitDocOperation(); + else + abortDocOperation(); + } + else + { + anIsOk = aModel->copy(); + aFlags = UF_Controls; + } + + if( anIsOk ) + { + module()->update( aFlags ); + commit(); + } + else + abort(); +} diff --git a/src/HYDROGUI/HYDROGUI_CopyPasteOp.h b/src/HYDROGUI/HYDROGUI_CopyPasteOp.h new file mode 100644 index 00000000..15fe4015 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_CopyPasteOp.h @@ -0,0 +1,43 @@ +// Copyright (C) 2007-2013 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 +// +// 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. +// +// 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 +// + +#ifndef HYDROGUI_COPYPASTEOP_H +#define HYDROGUI_COPYPASTEOP_H + +#include "HYDROGUI_Operation.h" + +class HYDROGUI_CopyPasteOp : public HYDROGUI_Operation +{ + Q_OBJECT + +public: + HYDROGUI_CopyPasteOp( HYDROGUI_Module* theModule, const bool theIsPaste ); + virtual ~HYDROGUI_CopyPasteOp(); + +protected: + virtual void startOperation(); + +private: + bool myIsPaste; +}; + +#endif diff --git a/src/HYDROGUI/HYDROGUI_DataModel.cxx b/src/HYDROGUI/HYDROGUI_DataModel.cxx index d1fff032..e9462628 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.cxx +++ b/src/HYDROGUI/HYDROGUI_DataModel.cxx @@ -57,6 +57,8 @@ #include #include +static HYDROData_SequenceOfObjects myCopyingObjects; + HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule ) : LightApp_DataModel( theModule ) { @@ -415,6 +417,86 @@ bool HYDROGUI_DataModel::redo() return true; } +bool HYDROGUI_DataModel::canCopy() +{ + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() ); + if( aSeq.Length() != 1 ) + return false; + + Handle(HYDROData_Object) anObject = aSeq.First(); + if( anObject.IsNull() ) + return false; + + ObjectKind aKind = anObject->GetKind(); + if( aKind == KIND_IMAGE || + aKind == KIND_POLYLINE || + aKind == KIND_CALCULATION ) + return true; + + return false; +} + +bool HYDROGUI_DataModel::canPaste() +{ + for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex ); + if( !anObject.IsNull() && !anObject->IsRemoved() ) + return true; + } + return false; +} + +bool HYDROGUI_DataModel::copy() +{ + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( (HYDROGUI_Module*)module() ); + changeCopyingObjects( aSeq ); + return true; +} + +bool HYDROGUI_DataModel::paste() +{ + bool anIsChanged = false; + for( int anIndex = 1, aLength = myCopyingObjects.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Object) anObject = myCopyingObjects.Value( anIndex ); + if( !anObject.IsNull() && !anObject->IsRemoved() ) + { + ObjectKind aKind = anObject->GetKind(); + Handle(HYDROData_Object) aClone = getDocument()->CreateObject( aKind ); + if( !aClone.IsNull() ) + { + anObject->CopyTo( aClone ); + anIsChanged = true; + + // generate a new unique name for the clone object: + // case 1: Image_1 -> Image_2 + // case 2: ImageObj -> ImageObj_1 + QString aName = aClone->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 = HYDROGUI_Tool::GenerateObjectName( (HYDROGUI_Module*)module(), aPrefix ); + aClone->SetName( aName ); + } + } + } + return anIsChanged; +} + +void HYDROGUI_DataModel::changeCopyingObjects( const HYDROData_SequenceOfObjects& theSeq ) +{ + myCopyingObjects.Assign( theSeq ); +} + Handle(HYDROData_Document) HYDROGUI_DataModel::getDocument() const { int aStudyId = module()->application()->activeStudy()->id(); diff --git a/src/HYDROGUI/HYDROGUI_DataModel.h b/src/HYDROGUI/HYDROGUI_DataModel.h index 1c5de1d7..9c1ff225 100644 --- a/src/HYDROGUI/HYDROGUI_DataModel.h +++ b/src/HYDROGUI/HYDROGUI_DataModel.h @@ -190,6 +190,31 @@ public: */ bool redo(); + /** + * Check if it is possible to perform 'copy' operation + */ + bool canCopy(); + + /** + * Check if it is possible to perform 'paste' operation + */ + bool canPaste(); + + /** + * Perform the 'copy' operation + */ + bool copy(); + + /** + * Perform the 'paste' operation + */ + bool paste(); + + /** + * Update the sequence of the objects to be copied + */ + static void changeCopyingObjects( const HYDROData_SequenceOfObjects& ); + protected: /** * Returns the document for the current study diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index f011cfe9..28f98579 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -114,6 +114,8 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) LightApp_Application* anApp = getApp(); SUIT_Desktop* aDesktop = anApp->desktop(); + getApp()->setEditEnabled( false ); // hide SalomeApp copy/paste actions + setMenuShown( true ); setToolShown( true ); @@ -139,9 +141,14 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) myObjectStateMap.clear(); + // clear the data model's list of copying objects + HYDROGUI_DataModel::changeCopyingObjects( HYDROData_SequenceOfObjects() ); + setMenuShown( false ); setToolShown( false ); + getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions + return LightApp_Module::deactivateModule( theStudy ); } @@ -207,11 +214,12 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient, { if( ImageComposer_Operator* anOperator = aFactory->Operator( anImage ) ) { - if( dynamic_cast( anOperator ) ) + QString anOperatorName = anOperator->name(); + if( anOperatorName == ImageComposer_FuseOperator::Type() ) anIsFusedImage = true; - else if( dynamic_cast( anOperator ) ) + else if( anOperatorName == ImageComposer_CutOperator::Type() ) anIsCutImage = true; - else if( dynamic_cast( anOperator ) ) + else if( anOperatorName == ImageComposer_CropOperator::Type() ) anIsSplittedImage = true; } } @@ -343,8 +351,14 @@ void HYDROGUI_Module::updateCommandsStatus() updateUndoRedoControls(); - // to do - //action( ... )->setEnabled( ... ); + action( CopyId )->setEnabled( getDataModel()->canCopy() ); + action( PasteId )->setEnabled( getDataModel()->canPaste() ); +} + +void HYDROGUI_Module::selectionChanged() +{ + LightApp_Module::selectionChanged(); + updateCommandsStatus(); } HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index f258db2e..0e637e5f 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -79,6 +79,8 @@ public: virtual void update( const int ); virtual void updateCommandsStatus(); + virtual void selectionChanged(); + HYDROGUI_DataModel* getDataModel() const; HYDROGUI_Displayer* getDisplayer() const; diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index b0f255bd..08dc8a38 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -22,6 +22,7 @@ #include "HYDROGUI_Operations.h" +#include "HYDROGUI_CopyPasteOp.h" #include "HYDROGUI_DataModel.h" #include "HYDROGUI_DeleteOp.h" #include "HYDROGUI_ExportImageOp.h" @@ -71,6 +72,9 @@ void HYDROGUI_Module::createActions() createAction( SaveVisualStateId, "SAVE_VISUAL_STATE" ); createAction( LoadVisualStateId, "LOAD_VISUAL_STATE" ); + createAction( CopyId, "COPY", "", Qt::CTRL + Qt::Key_C ); + createAction( PasteId, "PASTE", "", Qt::CTRL + Qt::Key_V ); + createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I ); createAction( EditImportedImageId, "EDIT_IMPORTED_IMAGE" ); createAction( ObserveImageId, "OBSERVE_IMAGE" ); @@ -113,6 +117,9 @@ void HYDROGUI_Module::createMenus() int anEditMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 5 ); createMenu( UndoId, anEditMenu ); createMenu( RedoId, anEditMenu ); + createMenu( separator(), anEditMenu ); + createMenu( CopyId, anEditMenu ); + createMenu( PasteId, anEditMenu ); int aHydroMenu = 6; // Edit menu id == 5, View menu id == 10 int aHydroId = createMenu( tr( "MEN_DESK_HYDRO" ), -1, -1, aHydroMenu ); @@ -239,6 +246,10 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case LoadVisualStateId: anOp = new HYDROGUI_VisualStateOp( aModule, theId == LoadVisualStateId ); break; + case CopyId: + case PasteId: + anOp = new HYDROGUI_CopyPasteOp( aModule, theId == PasteId ); + break; case ImportImageId: case EditImportedImageId: anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImportedImageId ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 008e2526..92f9869f 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -33,6 +33,9 @@ enum OperationId UndoId, RedoId, + CopyId, + PasteId, + ImportImageId, EditImportedImageId, ObserveImageId, diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index 0a8796b6..70729b30 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -32,10 +32,18 @@ does not exist or you have not enough permissions to open it. INPUT_VALID_DATA Please enter valid data and try again. + + LOAD_ERROR + Study could not be loaded + OBJECT_EXISTS_IN_DOCUMENT Object with name '%1' already exists in the document. + + SAVE_ERROR + Study could not be saved + @@ -69,19 +77,15 @@ does not exist or you have not enough permissions to open it. Edit calculation Case - + - HYDROGUI_DataModel + HYDROGUI_CopyPasteOp - LOAD_ERROR - Study could not be loaded - - - SAVE_ERROR - Study could not be saved + COPY_PASTE + Copy/paste - + HYDROGUI_DeleteOp @@ -255,6 +259,10 @@ file cannot be correctly imported for a Bathymetry definition. DSK_CREATE_POLYLINE Create polyline + + DSK_COPY + Copy + DSK_CUT_IMAGES Cut images @@ -319,6 +327,10 @@ file cannot be correctly imported for a Bathymetry definition. DSK_OBSERVE_IMAGE Observe image + + DSK_PASTE + Paste + DSK_REDO Redo @@ -359,6 +371,10 @@ file cannot be correctly imported for a Bathymetry definition. MEN_CREATE_POLYLINE Create polyline + + MEN_COPY + Copy + MEN_CUT_IMAGES Cut images @@ -427,6 +443,10 @@ file cannot be correctly imported for a Bathymetry definition. MEN_OBSERVE_IMAGE Observe image + + MEN_PASTE + Paste + MEN_REDO Redo @@ -467,6 +487,10 @@ file cannot be correctly imported for a Bathymetry definition. STB_CREATE_POLYLINE Create polyline + + STB_COPY + Copy + STB_CUT_IMAGES Cut images @@ -531,6 +555,10 @@ file cannot be correctly imported for a Bathymetry definition. STB_OBSERVE_IMAGE Observe image + + STB_PASTE + Paste + STB_REDO Redo -- 2.39.2