]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Copy/paste functionality for images, polylines and calculation cases.
authorouv <ouv@opencascade.com>
Mon, 16 Sep 2013 11:45:32 +0000 (11:45 +0000)
committerouv <ouv@opencascade.com>
Mon, 16 Sep 2013 11:45:32 +0000 (11:45 +0000)
src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI.vcproj
src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_CopyPasteOp.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataModel.h
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_Module.h
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index 17b7c093611e226917b15e0994ccd473c8d96843..3cbf03ff5318f3f215e2e503b583a442f4100ec8 100644 (file)
@@ -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
index dd4d2ad632ddf8806d2ac6b0fa06cbebc35ec284..50be70bab5e39b486886bbaa6b9dc8383b929c4c 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="windows-1251"?>
 <VisualStudioProject
        ProjectType="Visual C++"
-       Version="9.00"
+       Version="9,00"
        Name="HYDROGUI"
        ProjectGUID="{D11F0AD0-D002-4A22-A8E6-3F906379206F}"
        RootNamespace="HYDROGUI"
                                RelativePath=".\HYDROGUI_ColorWidget.cxx"
                                >
                        </File>
+                       <File
+                               RelativePath=".\HYDROGUI_CopyPasteOp.cxx"
+                               >
+                       </File>
                        <File
                                RelativePath=".\HYDROGUI_DataModel.cxx"
                                >
                                        <Tool
                                                Name="VCCustomBuildTool"
                                                Description="Generating moc_$(InputName).cxx"
-                                               CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx"
+                                               CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx&#x0D;&#x0A;"
                                                Outputs="moc/moc_$(InputName).cxx"
                                        />
                                </FileConfiguration>
                                        <Tool
                                                Name="VCCustomBuildTool"
                                                Description="Generating moc_$(InputName).cxx"
-                                               CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx"
+                                               CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx&#x0D;&#x0A;"
                                                Outputs="moc/moc_$(InputName).cxx"
                                        />
                                </FileConfiguration>
                                        />
                                </FileConfiguration>
                        </File>
+                       <File
+                               RelativePath=".\HYDROGUI_CopyPasteOp.h"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       >
+                                       <Tool
+                                               Name="VCCustomBuildTool"
+                                               Description="Generating moc_$(InputName).cxx"
+                                               CommandLine="$(QTDIR)\bin\moc.exe $(InputPath) -o moc\moc_$(InputName).cxx"
+                                               Outputs="moc/moc_$(InputName).cxx"
+                                       />
+                               </FileConfiguration>
+                       </File>
                        <File
                                RelativePath=".\HYDROGUI_DataModel.h"
                                >
                                RelativePath=".\moc\moc_HYDROGUI_ColorWidget.cxx"
                                >
                        </File>
+                       <File
+                               RelativePath=".\moc\moc_HYDROGUI_CopyPasteOp.cxx"
+                               >
+                       </File>
                        <File
                                RelativePath=".\moc\moc_HYDROGUI_DeleteOp.cxx"
                                >
diff --git a/src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx b/src/HYDROGUI/HYDROGUI_CopyPasteOp.cxx
new file mode 100644 (file)
index 0000000..e1e3067
--- /dev/null
@@ -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 (file)
index 0000000..15fe401
--- /dev/null
@@ -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
index d1fff0327b08f53aa0fa5cc948799ac3712acd6c..e946262885d0f9613579ec6ed617f0e4c545c507 100644 (file)
@@ -57,6 +57,8 @@
 #include <QApplication>
 #include <QDir>
 
+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();
index 1c5de1d7d7534bb2a77804c5713c163ddf079ccc..9c1ff2255660ee56785d9b5d714bdbcda433ec11 100644 (file)
@@ -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
index f011cfe9ae6b6bbf4013079be6da1f18d03294f2..28f985792ce486a66bcda974899cdd85a7acf50c 100644 (file)
@@ -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<ImageComposer_FuseOperator*>( anOperator ) )
+              QString anOperatorName = anOperator->name();
+              if( anOperatorName == ImageComposer_FuseOperator::Type() )
                 anIsFusedImage = true;
-              else if( dynamic_cast<ImageComposer_CutOperator*>( anOperator ) )
+              else if( anOperatorName == ImageComposer_CutOperator::Type() )
                 anIsCutImage = true;
-              else if( dynamic_cast<ImageComposer_CropOperator*>( 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
index f258db2ecd2dee6d303c48b09335acf0e7fd62cd..0e637e5fe9e27bc0dd485a9a96733b039f43902f 100644 (file)
@@ -79,6 +79,8 @@ public:
   virtual void                    update( const int );
   virtual void                    updateCommandsStatus();
 
+  virtual void                    selectionChanged();
+
   HYDROGUI_DataModel*             getDataModel() const;
   HYDROGUI_Displayer*             getDisplayer() const;
 
index b0f255bdfe6ccc90fb4aa26934525defb43a4daa..08dc8a385d59bec10e0c4c8287b4413d0cbb2968 100644 (file)
@@ -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 );
index 008e2526f1caa7b55d403316e9726abfe4048f44..92f9869fc2841b4be761e134551fe25aca6dd8f7 100644 (file)
@@ -33,6 +33,9 @@ enum OperationId
   UndoId,
   RedoId,
 
+  CopyId,
+  PasteId,
+
   ImportImageId,
   EditImportedImageId,
   ObserveImageId,
index 0a8796b69e19a7bb35824880a7f7d0a7173b1027..70729b307b04cefe5cd523f52a83f2a4927738d8 100644 (file)
@@ -32,10 +32,18 @@ does not exist or you have not enough permissions to open it.</translation>
       <source>INPUT_VALID_DATA</source>
       <translation>Please enter valid data and try again.</translation>
     </message>
+    <message>
+      <source>LOAD_ERROR</source>
+      <translation>Study could not be loaded</translation>
+    </message>
     <message>
       <source>OBJECT_EXISTS_IN_DOCUMENT</source>
       <translation>Object with name '%1' already exists in the document.</translation>
     </message>
+    <message>
+      <source>SAVE_ERROR</source>
+      <translation>Study could not be saved</translation>
+    </message>
   </context>
 
   <context>
@@ -69,19 +77,15 @@ does not exist or you have not enough permissions to open it.</translation>
       <translation>Edit calculation Case</translation>
     </message>
   </context>
-    
+
   <context>
-    <name>HYDROGUI_DataModel</name>
+    <name>HYDROGUI_CopyPasteOp</name>
     <message>
-      <source>LOAD_ERROR</source>
-      <translation>Study could not be loaded</translation>
-    </message>
-    <message>
-      <source>SAVE_ERROR</source>
-      <translation>Study could not be saved</translation>
+      <source>COPY_PASTE</source>
+      <translation>Copy/paste</translation>
     </message>
   </context>
-  
+
   <context>
     <name>HYDROGUI_DeleteOp</name>
     <message>
@@ -255,6 +259,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>DSK_CREATE_POLYLINE</source>
       <translation>Create polyline</translation>
     </message>
+    <message>
+      <source>DSK_COPY</source>
+      <translation>Copy</translation>
+    </message>
     <message>
       <source>DSK_CUT_IMAGES</source>
       <translation>Cut images</translation>
@@ -319,6 +327,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>DSK_OBSERVE_IMAGE</source>
       <translation>Observe image</translation>
     </message>
+    <message>
+      <source>DSK_PASTE</source>
+      <translation>Paste</translation>
+    </message>
     <message>
       <source>DSK_REDO</source>
       <translation>Redo</translation>
@@ -359,6 +371,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>MEN_CREATE_POLYLINE</source>
       <translation>Create polyline</translation>
     </message>
+    <message>
+      <source>MEN_COPY</source>
+      <translation>Copy</translation>
+    </message>
     <message>
       <source>MEN_CUT_IMAGES</source>
       <translation>Cut images</translation>
@@ -427,6 +443,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>MEN_OBSERVE_IMAGE</source>
       <translation>Observe image</translation>
     </message>
+    <message>
+      <source>MEN_PASTE</source>
+      <translation>Paste</translation>
+    </message>
     <message>
       <source>MEN_REDO</source>
       <translation>Redo</translation>
@@ -467,6 +487,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>STB_CREATE_POLYLINE</source>
       <translation>Create polyline</translation>
     </message>
+    <message>
+      <source>STB_COPY</source>
+      <translation>Copy</translation>
+    </message>
     <message>
       <source>STB_CUT_IMAGES</source>
       <translation>Cut images</translation>
@@ -531,6 +555,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>STB_OBSERVE_IMAGE</source>
       <translation>Observe image</translation>
     </message>
+    <message>
+      <source>STB_PASTE</source>
+      <translation>Paste</translation>
+    </message>
     <message>
       <source>STB_REDO</source>
       <translation>Redo</translation>