1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4 * http://ugene.net
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include "BioStruct3DGLImageExportTask.h"
23
24 #include <U2Core/U2SafePoints.h>
25
26 #include "BioStruct3DGLWidget.h"
27 #include "gl2ps/gl2ps.h"
28
29 namespace U2 {
30
run()31 void BioStruct3DImageExportToSVGTask::run() {
32 SAFE_POINT_EXT(settings.isSVGFormat(),
33 setError(WRONG_FORMAT_MESSAGE.arg(settings.format).arg("BioStruct3DImageExportToSVGTask")), );
34
35 int opt = GL2PS_NONE;
36 glWidget->writeImage2DToFile(GL2PS_SVG, opt, 2, qPrintable(settings.fileName));
37 // TODO: need check on error
38 }
39
run()40 void BioStruct3DImageExportToPDFTask::run() {
41 SAFE_POINT_EXT(settings.isPDFFormat(),
42 setError(WRONG_FORMAT_MESSAGE.arg(settings.format).arg("BioStruct3DImageExportToPDFTask")), );
43
44 int opt = GL2PS_NONE;
45
46 if (settings.format == "ps") {
47 glWidget->writeImage2DToFile(GL2PS_PS, opt, 2, qPrintable(settings.fileName));
48 return; // TODO: need check on error
49 } else if (settings.format == "pdf") {
50 glWidget->writeImage2DToFile(GL2PS_PDF, opt, 2, qPrintable(settings.fileName));
51 return; // TODO: need check on error
52 }
53 setError(EXPORT_FAIL_MESSAGE.arg(settings.fileName));
54 }
55
run()56 void BioStruct3DImageExportToBitmapTask::run() {
57 SAFE_POINT_EXT(settings.isBitmapFormat(),
58 setError(WRONG_FORMAT_MESSAGE.arg(settings.format).arg("BioStruct3DImageExportToBitmapTask")), );
59
60 glWidget->setImageRenderingMode(true);
61 QPixmap image = glWidget->grab().scaled(settings.imageSize, Qt::KeepAspectRatio);
62 glWidget->setImageRenderingMode(false);
63
64 CHECK_EXT(image.save(settings.fileName, qPrintable(settings.format), settings.imageQuality),
65 setError(EXPORT_FAIL_MESSAGE.arg(settings.fileName)), );
66 }
67
getImageWidth() const68 int BioStruct3DImageExportController::getImageWidth() const {
69 return glWidget->width();
70 }
71
getImageHeight() const72 int BioStruct3DImageExportController::getImageHeight() const {
73 return glWidget->height();
74 }
75
76 } // namespace U2
77