]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
1) Export Image operation.
authorouv <ouv@opencascade.com>
Fri, 16 Aug 2013 08:21:14 +0000 (08:21 +0000)
committerouv <ouv@opencascade.com>
Fri, 16 Aug 2013 08:21:14 +0000 (08:21 +0000)
2) Code optimization.

src/HYDROGUI/CMakeLists.txt
src/HYDROGUI/HYDROGUI_DeleteOp.cxx
src/HYDROGUI/HYDROGUI_ExportImageOp.cxx [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ExportImageOp.h [new file with mode: 0644]
src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/HYDROGUI_ObjSelector.cxx
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_Operations.h
src/HYDROGUI/HYDROGUI_ShowHideOp.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index f5f3459aabdeefe08fefb0f4476aaa5131246b03..7cf264b86e51f40eb2773e00ea7595bb7c4198c3 100644 (file)
@@ -8,6 +8,7 @@ set(PROJECT_HEADERS
     HYDROGUI_DataObject.h
     HYDROGUI_DeleteOp.h
     HYDROGUI_Displayer.h
+    HYDROGUI_ExportImageDlg.h
     HYDROGUI_GVSelector.h
     HYDROGUI_ImportImageDlg.h
     HYDROGUI_ImportImageOp.h
@@ -40,6 +41,7 @@ set(PROJECT_SOURCES
     HYDROGUI_DataObject.cxx
     HYDROGUI_DeleteOp.cxx
     HYDROGUI_Displayer.cxx
+    HYDROGUI_ExportImageDlg.cxx
     HYDROGUI_GVSelector.cxx
     HYDROGUI_ImportImageDlg.cxx
     HYDROGUI_ImportImageOp.cxx
index 83372230525666d4519d3f2fb188997e1ff0568a..0e57e37266721a3c221e8627a2c0ec8cf1940b1e 100644 (file)
 
 #include "HYDROGUI_DeleteOp.h"
 
-#include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
-#include "HYDROGUI_Operations.h"
+#include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
-#include <HYDROData_Iterator.h>
 #include <HYDROData_Object.h>
 
 #include <LightApp_Application.h>
-#include <LightApp_DataOwner.h>
 
 #include <SUIT_Desktop.h>
 #include <SUIT_MessageBox.h>
-#include <SUIT_SelectionMgr.h>
 
 HYDROGUI_DeleteOp::HYDROGUI_DeleteOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -51,13 +47,8 @@ void HYDROGUI_DeleteOp::startOperation()
 {
   HYDROGUI_Operation::startOperation();
 
-  HYDROGUI_DataModel* aModel = module()->getDataModel();
-
-  SUIT_SelectionMgr* aSelectionMgr = selectionMgr();
-  SUIT_DataOwnerPtrList anOwners;
-  aSelectionMgr->selected( anOwners );
-
-  if( !anOwners.isEmpty() )
+  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
+  if( !aSeq.IsEmpty() )
   {
     int anAnswer = SUIT_MessageBox::question( module()->getApp()->desktop(),
                                               tr( "DELETE_OBJECTS" ),
@@ -71,14 +62,11 @@ void HYDROGUI_DeleteOp::startOperation()
     }
   }
 
-  foreach( SUIT_DataOwner* aSUITOwner, anOwners )
+  for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
   {
-    if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
-    {
-      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() );
-      if( !anObject.IsNull() )
-        anObject->Remove();
-    }
+    Handle(HYDROData_Object) anObject = aSeq.Value( anIndex );
+    if( !anObject.IsNull() )
+      anObject->Remove();
   }
 
   module()->update( UF_Model | UF_Viewer );
diff --git a/src/HYDROGUI/HYDROGUI_ExportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ExportImageOp.cxx
new file mode 100644 (file)
index 0000000..f8b7c7e
--- /dev/null
@@ -0,0 +1,67 @@
+// 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_ExportImageOp.h"
+
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_Tool.h"
+
+#include <HYDROData_Image.h>
+
+#include <LightApp_Application.h>
+
+#include <SUIT_Desktop.h>
+
+#include <QFileDialog>
+
+HYDROGUI_ExportImageOp::HYDROGUI_ExportImageOp( HYDROGUI_Module* theModule )
+: HYDROGUI_Operation( theModule )
+{
+  setName( tr( "EXPORT_IMAGE" ) );
+}
+
+HYDROGUI_ExportImageOp::~HYDROGUI_ExportImageOp()
+{
+}
+
+void HYDROGUI_ExportImageOp::startOperation()
+{
+  HYDROGUI_Operation::startOperation();
+
+  Handle(HYDROData_Image) anImageObj =
+    Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
+  if( !anImageObj.IsNull() )
+  {
+    QImage anImage = anImageObj->Image();
+    QTransform aTransform = anImageObj->Trsf();
+
+    anImage = anImage.transformed( aTransform, Qt::SmoothTransformation );
+
+    QString aFilter( tr( "IMAGE_FILTER" ) );
+    QString aFileName = QFileDialog::getSaveFileName( module()->getApp()->desktop(),
+                                                      tr( "BROWSE_IMAGE_FILE" ), "", aFilter );
+    if( !aFileName.isEmpty() )
+      anImage.save( aFileName );
+  }
+
+  abort(); // do not commit the document command
+}
diff --git a/src/HYDROGUI/HYDROGUI_ExportImageOp.h b/src/HYDROGUI/HYDROGUI_ExportImageOp.h
new file mode 100644 (file)
index 0000000..b71127e
--- /dev/null
@@ -0,0 +1,40 @@
+// 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_EXPORTIMAGEOP_H
+#define HYDROGUI_EXPORTIMAGEOP_H
+
+#include "HYDROGUI_Operation.h"
+
+class HYDROGUI_ExportImageOp : public HYDROGUI_Operation
+{
+  Q_OBJECT
+
+public:
+  HYDROGUI_ExportImageOp( HYDROGUI_Module* theModule );
+  virtual ~HYDROGUI_ExportImageOp();
+
+protected:
+  virtual void               startOperation();
+};
+
+#endif
index a5c99eddb8251a12784871d2a2d02c3ca8bd7d59..a7983555eab8658137d9405619e35a1db802ceee 100644 (file)
@@ -342,7 +342,7 @@ void HYDROGUI_ImportImageDlg::initializePointSelection()
 void HYDROGUI_ImportImageDlg::onBrowse()
 {
   QString aFilter( tr( "IMAGE_FILTER" ) );
-  QString aFileName = QFileDialog::getOpenFileName( this, tr( "BROWSE_IMAGE_FILE" ), "", aFilter );
+  QString aFileName = QFileDialog::getOpenFileName( this, tr( "IMPORT_IMAGE_FROM_FILE" ), "", aFilter );
   //QString aFileName = "W:/Work/HYDRO/doc/samples/1.bmp";
   if( !aFileName.isEmpty() )
   {
index ea02a0084cd87d459d473b011104c4afbad64ee8..567dab1ff2faa7035bdf8c1d5b144dfe538bb209 100644 (file)
@@ -39,7 +39,6 @@
 #include <GraphicsView_Viewer.h>
 
 #include <LightApp_Application.h>
-#include <LightApp_DataOwner.h>
 #include <LightApp_GVSelector.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_UpdateFlags.h>
@@ -140,13 +139,6 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 {
   HYDROGUI_DataModel* aModel = getDataModel();
 
-  LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr();
-  if( !aSelectionMgr )
-    return;
-
-  SUIT_DataOwnerPtrList anOwners;
-  aSelectionMgr->selected( anOwners );
-
   bool anIsSelection = false;
   bool anIsVisibleInSelection = false;
   bool anIsHiddenInSelection = false;
@@ -154,38 +146,39 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
   bool anIsImage = false;
   bool anIsPolyline = false;
 
-  foreach( SUIT_DataOwner* aSUITOwner, anOwners )
+  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( this );
+  for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
   {
-    if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
+    Handle(HYDROData_Object) anObject = aSeq.Value( anIndex );
+    if( !anObject.IsNull() )
     {
-      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() );
-      if( !anObject.IsNull() )
-      {
-        anIsSelection = true;
+      anIsSelection = true;
 
-        bool aVisibility = anObject->GetVisibility();
-        anIsVisibleInSelection |= aVisibility;
-        anIsHiddenInSelection |= !aVisibility;
+      bool aVisibility = anObject->GetVisibility();
+      anIsVisibleInSelection |= aVisibility;
+      anIsHiddenInSelection |= !aVisibility;
 
-        if( anObject->GetKind() == KIND_IMAGE )
-          anIsImage = true;
+      if( anObject->GetKind() == KIND_IMAGE )
+        anIsImage = true;
 
-        if( anObject->GetKind() == KIND_POLYLINE )
-          anIsPolyline = true;
-      }
+      if( anObject->GetKind() == KIND_POLYLINE )
+        anIsPolyline = true;
     }
   }
 
-  if( anOwners.count() == 1 && anIsImage )
-  {
-    theMenu->addAction( action( EditImageId ) );
-    theMenu->addSeparator();
-  }
-
-  if( anOwners.count() == 1 && anIsPolyline )
+  if( aSeq.Length() == 1 )
   {
-    theMenu->addAction( action( EditPolylineId ) );
-    theMenu->addSeparator();
+    if( anIsImage )
+    {
+      theMenu->addAction( action( EditImageId ) );
+      theMenu->addAction( action( ExportImageId ) );
+      theMenu->addSeparator();
+    }
+    else if( anIsPolyline )
+    {
+      theMenu->addAction( action( EditPolylineId ) );
+      theMenu->addSeparator();
+    }
   }
 
   if( anIsSelection )
index 737b19f3702e83acd49d40a45126fd30efc8ff42..3b7e1e5939c0787fdcaeaf12d2e8647b84d7f221 100644 (file)
 
 #include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
+#include "HYDROGUI_Tool.h"
 
 #include <GraphicsView_Object.h>
 
 #include <LightApp_Application.h>
-#include <LightApp_DataOwner.h>
 #include <LightApp_GVSelector.h>
 #include <LightApp_SelectionMgr.h>
 
@@ -94,27 +94,11 @@ void HYDROGUI_ObjSelector::OnSelectionChanged()
   if( !myBtn->isChecked() )
     return;
 
-  SUIT_SelectionMgr* aSelMgr = myModule->getApp()->selectionMgr();
-  SUIT_DataOwnerPtrList anOwners;
-  aSelMgr->selected( anOwners );
-
-  HYDROGUI_DataModel* aModel = myModule->getDataModel();
-
   QString anObjName;
-  foreach( SUIT_DataOwner* anOwner, anOwners )
-  {
-    LightApp_DataOwner* aGrDOwner = dynamic_cast<LightApp_DataOwner*>( anOwner );
-    if( aGrDOwner )
-    {
-      QString anEntry = aGrDOwner->entry();
-      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anEntry, KIND_IMAGE );
-      if( !anObject.IsNull() )
-      {
-        anObjName = anObject->GetName();
-        break;
-      }
-    }
-  }
+  Handle(HYDROData_Object) anObject = HYDROGUI_Tool::GetSelectedObject( myModule );
+  if( !anObject.IsNull() )
+    anObjName = anObject->GetName();
+
   myObjName->setText( anObjName );
 }
 
index e921a53242f4bd5c38886740d9a288fe72f81e55..634c20b75ec94464192ffaa360130c58eebc22be 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_DeleteOp.h"
+#include "HYDROGUI_ExportImageOp.h"
 #include "HYDROGUI_ImportImageOp.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_PolylineOp.h"
@@ -64,6 +65,7 @@ void HYDROGUI_Module::createActions()
 {
   createAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
   createAction( EditImageId, "EDIT_IMAGE" );
+  createAction( ExportImageId, "EXPORT_IMAGE" );
   createAction( CreatePolylineId, "CREATE_POLYLINE" );
   createAction( EditPolylineId, "EDIT_POLYLINE" ); 
 
@@ -207,6 +209,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
   case EditImageId:
     anOp = new HYDROGUI_ImportImageOp( aModule, theId == EditImageId );
     break;
+  case ExportImageId:
+    anOp = new HYDROGUI_ExportImageOp( aModule );
+    break;
   case CreatePolylineId:
   case EditPolylineId:
     anOp = new HYDROGUI_PolylineOp( aModule, theId == EditPolylineId );
index 116d7a300f96f6867333f94f7e256c650fd156ba..c44fd694169dd9341163c2a97599a34bba0c2683 100644 (file)
@@ -30,6 +30,7 @@ enum OperationId
   RedoId,
   ImportImageId,
   EditImageId,
+  ExportImageId,
   CreatePolylineId,
   EditPolylineId,
   FuseId,
index 47e0a2b6e2362b06018c3b06ca51e5eeed6f6ced..305af96e234f9eebc50c7951f09e45a2df0bacf5 100644 (file)
 
 #include "HYDROGUI_ShowHideOp.h"
 
-#include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_Operations.h"
+#include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Object.h>
 
-#include <LightApp_DataOwner.h>
-
-#include <SUIT_SelectionMgr.h>
-
 HYDROGUI_ShowHideOp::HYDROGUI_ShowHideOp( HYDROGUI_Module* theModule, int theId )
 : HYDROGUI_Operation( theModule ),
   myId( theId )
@@ -59,8 +55,6 @@ void HYDROGUI_ShowHideOp::startOperation()
 {
   HYDROGUI_Operation::startOperation();
 
-  HYDROGUI_DataModel* aModel = module()->getDataModel();
-
   // for all objects
   if( myId == ShowOnlyId || myId == ShowAllId || myId == HideAllId )
   {
@@ -77,19 +71,14 @@ void HYDROGUI_ShowHideOp::startOperation()
   // for selected objects
   if( myId == ShowId || myId == ShowOnlyId || myId == HideId )
   {
-    SUIT_SelectionMgr* aSelectionMgr = selectionMgr();
-    SUIT_DataOwnerPtrList anOwners;
-    aSelectionMgr->selected( anOwners );
+    HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
 
     bool aVisibility = myId == ShowId || myId == ShowOnlyId;
-    foreach( SUIT_DataOwner* aSUITOwner, anOwners )
+    for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
     {
-      if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
-      {
-        Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() );
-        if( !anObject.IsNull() )
-          anObject->SetVisibility( aVisibility ? true : false );
-      }
+      Handle(HYDROData_Object) anObject = aSeq.Value( anIndex );
+      if( !anObject.IsNull() )
+        anObject->SetVisibility( aVisibility ? true : false );
     }
   }
 
index b2d571e69190e7b2f54a775f66c61dcc8b53645b..685ee64f129a91fb6b5792ba270cc546d3ff6dfb 100644 (file)
@@ -2,6 +2,10 @@
 <TS version="1.1" >
   <context>
     <name>@default</name>
+    <message>
+      <source>IMAGE_FILTER</source>
+      <translation>Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *)</translation>
+    </message>
     <message>
       <source>INSUFFICIENT_INPUT_DATA</source>
       <translation>Insufficient input data</translation>
       <translation>Do you really want to delete the selected object(s)?</translation>
     </message>
   </context>
+  <context>
+    <name>HYDROGUI_ExportImageOp</name>
+    <message>
+      <source>EXPORT_IMAGE</source>
+      <translation>Export image</translation>
+    </message>
+    <message>
+      <source>EXPORT_IMAGE_TO_FILE</source>
+      <translation>Export image to file</translation>
+    </message>
+  </context>
   <context>
     <name>HYDROGUI_InputPanel</name>
     <message>
       <source>ACTIVATE_POINT_C_SELECTION</source>
       <translation>Activate point C selection</translation>
     </message>
-    <message>
-      <source>BROWSE_IMAGE_FILE</source>
-      <translation>Browse image file</translation>
-    </message>
     <message>
       <source>FILE_NAME</source>
       <translation>File name</translation>
     </message>
-    <message>
-      <source>IMAGE_FILTER</source>
-      <translation>Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *)</translation>
-    </message>
     <message>
       <source>IMAGE_NAME</source>
       <translation>Image name</translation>
       <source>DSK_EDIT_POLYLINE</source>
       <translation>Edit polyline</translation>
     </message>
+    <message>
+      <source>DSK_EXPORT_IMAGE</source>
+      <translation>Export image</translation>
+    </message>
     <message>
       <source>DSK_FUSE_IMAGES</source>
       <translation>Fuse images</translation>
       <source>MEN_EDIT_POLYLINE</source>
       <translation>Create polyline</translation>
     </message>
+    <message>
+      <source>MEN_EXPORT_IMAGE</source>
+      <translation>Export image</translation>
+    </message>
     <message>
       <source>MEN_FUSE_IMAGES</source>
       <translation>Fuse images</translation>
       <source>STB_EDIT_POLYLINE</source>
       <translation>Edit polyline</translation>
     </message>
+    <message>
+      <source>STB_EXPORT_IMAGE</source>
+      <translation>Export image</translation>
+    </message>
     <message>
       <source>STB_FUSE_IMAGES</source>
       <translation>Fuse images</translation>