1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ExportImageOp.h"
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_Tool.h"
24 #include <HYDROData_Image.h>
26 #include <LightApp_Application.h>
28 #include <SUIT_Desktop.h>
29 #include <SUIT_FileDlg.h>
31 HYDROGUI_ExportImageOp::HYDROGUI_ExportImageOp( HYDROGUI_Module* theModule )
32 : HYDROGUI_Operation( theModule )
34 setName( tr( "EXPORT_IMAGE" ) );
37 HYDROGUI_ExportImageOp::~HYDROGUI_ExportImageOp()
41 void HYDROGUI_ExportImageOp::startOperation()
43 HYDROGUI_Operation::startOperation();
45 Handle(HYDROData_Image) anImageObj =
46 Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
47 if( !anImageObj.IsNull() )
49 QImage anImage = anImageObj->Image();
50 QTransform aTransform = anImageObj->Trsf();
52 // Scale image to it origin imported size
53 double aCoefX = aTransform.m11() < 0 ? -1.0 : 1.0;
54 double aCoefY = aTransform.m22() < 0 ? -1.0 : 1.0;
55 aTransform.scale( aCoefX * ( 1 / aTransform.m11() ), aCoefY * ( 1 / aTransform.m22() ) );
57 anImage = anImage.transformed( aTransform, Qt::SmoothTransformation );
59 // Invert the Y axis direction from down to up
60 anImage = anImage.transformed( QTransform::fromScale( 1, -1 ), Qt::SmoothTransformation );
62 QString aFilter( tr( "IMAGE_FILTER" ) );
63 QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(),
64 "", aFilter, tr( "EXPORT_IMAGE_TO_FILE" ), false );
65 if( !aFileName.isEmpty() )
66 anImage.save( aFileName );