From: ouv Date: Fri, 16 Aug 2013 08:21:14 +0000 (+0000) Subject: 1) Export Image operation. X-Git-Tag: BR_hydro_v_0_1~111 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fe02bb085711fbb88046f31bd30a4590d7263c7a;p=modules%2Fhydro.git 1) Export Image operation. 2) Code optimization. --- diff --git a/src/HYDROGUI/CMakeLists.txt b/src/HYDROGUI/CMakeLists.txt index f5f3459a..7cf264b8 100644 --- a/src/HYDROGUI/CMakeLists.txt +++ b/src/HYDROGUI/CMakeLists.txt @@ -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 diff --git a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx index 83372230..0e57e372 100644 --- a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx @@ -22,20 +22,16 @@ #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 #include #include -#include #include #include -#include 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( 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 index 00000000..f8b7c7e2 --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ExportImageOp.cxx @@ -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 + +#include + +#include + +#include + +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 index 00000000..b71127ea --- /dev/null +++ b/src/HYDROGUI/HYDROGUI_ExportImageOp.h @@ -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 diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx index a5c99edd..a7983555 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx @@ -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() ) { diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index ea02a008..567dab1f 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -39,7 +39,6 @@ #include #include -#include #include #include #include @@ -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( 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 ) diff --git a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx index 737b19f3..3b7e1e59 100644 --- a/src/HYDROGUI/HYDROGUI_ObjSelector.cxx +++ b/src/HYDROGUI/HYDROGUI_ObjSelector.cxx @@ -24,11 +24,11 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" +#include "HYDROGUI_Tool.h" #include #include -#include #include #include @@ -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( 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 ); } diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index e921a532..634c20b7 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -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 ); diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 116d7a30..c44fd694 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -30,6 +30,7 @@ enum OperationId RedoId, ImportImageId, EditImageId, + ExportImageId, CreatePolylineId, EditPolylineId, FuseId, diff --git a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx index 47e0a2b6..305af96e 100644 --- a/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ShowHideOp.cxx @@ -22,18 +22,14 @@ #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 #include -#include - -#include - 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( 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 ); } } diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index b2d571e6..685ee64f 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -2,6 +2,10 @@ @default + + IMAGE_FILTER + Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *) + INSUFFICIENT_INPUT_DATA Insufficient input data @@ -41,6 +45,17 @@ Do you really want to delete the selected object(s)? + + HYDROGUI_ExportImageOp + + EXPORT_IMAGE + Export image + + + EXPORT_IMAGE_TO_FILE + Export image to file + + HYDROGUI_InputPanel @@ -70,18 +85,10 @@ ACTIVATE_POINT_C_SELECTION Activate point C selection - - BROWSE_IMAGE_FILE - Browse image file - FILE_NAME File name - - IMAGE_FILTER - Image files (*.bmp *.jpg *.jpeg *.png);;All files (*.* *) - IMAGE_NAME Image name @@ -144,6 +151,10 @@ DSK_EDIT_POLYLINE Edit polyline + + DSK_EXPORT_IMAGE + Export image + DSK_FUSE_IMAGES Fuse images @@ -208,6 +219,10 @@ MEN_EDIT_POLYLINE Create polyline + + MEN_EXPORT_IMAGE + Export image + MEN_FUSE_IMAGES Fuse images @@ -264,6 +279,10 @@ STB_EDIT_POLYLINE Edit polyline + + STB_EXPORT_IMAGE + Export image + STB_FUSE_IMAGES Fuse images