Salome HOME
Merge branch 'BR_LAND_COVER_MAP' into BR_quadtree
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ExportImageOp.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ExportImageOp.h"
20
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_Tool2.h"
23
24 #include <HYDROData_Image.h>
25
26 #include <LightApp_Application.h>
27
28 #include <SUIT_Desktop.h>
29 #include <SUIT_FileDlg.h>
30
31 HYDROGUI_ExportImageOp::HYDROGUI_ExportImageOp( HYDROGUI_Module* theModule )
32 : HYDROGUI_Operation( theModule )
33 {
34   setName( tr( "EXPORT_IMAGE" ) );
35 }
36
37 HYDROGUI_ExportImageOp::~HYDROGUI_ExportImageOp()
38 {
39 }
40
41 void HYDROGUI_ExportImageOp::startOperation()
42 {
43   HYDROGUI_Operation::startOperation();
44
45   Handle(HYDROData_Image) anImageObj =
46     Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
47   if( !anImageObj.IsNull() )
48   {
49     QImage anImage = anImageObj->Image();
50     QTransform aTransform = anImageObj->Trsf();
51
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() ) );
56
57     anImage = anImage.transformed( aTransform, Qt::SmoothTransformation );
58     
59     // Invert the Y axis direction from down to up
60     anImage = anImage.transformed( QTransform::fromScale( 1, -1 ), Qt::SmoothTransformation );
61     
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 );
67   }
68
69   commit();
70 }