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 <base_dialogs/GTFileDialog.h>
23 #include <primitives/GTCheckBox.h>
24 #include <primitives/GTComboBox.h>
25 #include <primitives/GTLineEdit.h>
26 #include <primitives/GTRadioButton.h>
27 #include <primitives/GTSpinBox.h>
28 #include <primitives/GTWidget.h>
29 
30 #include <QApplication>
31 #include <QDialogButtonBox>
32 #include <QDir>
33 
34 #include "ExportSequencesDialogFiller.h"
35 
36 namespace U2 {
37 
38 QString ExportSelectedRegionFiller::defaultExportPath = "";
39 
40 #define GT_CLASS_NAME "GTUtilsDialog::ExportSelectedRegionFiller"
ExportSelectedRegionFiller(HI::GUITestOpStatus & _os,const QString & _path,const QString & _name,bool translate,const QString & seqName,bool saveAllAminoFrames)41 ExportSelectedRegionFiller::ExportSelectedRegionFiller(HI::GUITestOpStatus &_os, const QString &_path, const QString &_name, bool translate, const QString &seqName, bool saveAllAminoFrames)
42     : Filler(_os, "U2__ExportSequencesDialog"), name(_name), seqName(seqName), translate(translate),
43       saveAllAminoFrames(saveAllAminoFrames) {
44     path = GTFileDialog::toAbsoluteNativePath(_path, true);
45 }
46 
ExportSelectedRegionFiller(GUITestOpStatus & os,const QString & filePath)47 ExportSelectedRegionFiller::ExportSelectedRegionFiller(GUITestOpStatus &os, const QString &filePath)
48     : Filler(os, "U2__ExportSequencesDialog"),
49       translate(false),
50       saveAllAminoFrames(true) {
51     path = QFileInfo(filePath).dir().path() + "/";
52     name = QFileInfo(filePath).fileName();
53 }
54 
ExportSelectedRegionFiller(HI::GUITestOpStatus & os,CustomScenario * customScenario)55 ExportSelectedRegionFiller::ExportSelectedRegionFiller(HI::GUITestOpStatus &os, CustomScenario *customScenario)
56     : Filler(os, "U2__ExportSequencesDialog", customScenario),
57       translate(false), saveAllAminoFrames(true) {
58 }
59 
60 #define GT_METHOD_NAME "commonScenario"
commonScenario()61 void ExportSelectedRegionFiller::commonScenario() {
62     QWidget *dialog = QApplication::activeModalWidget();
63     GT_CHECK(dialog != nullptr, "dialog not found");
64 
65     QLineEdit *lineEdit = qobject_cast<QLineEdit *>(GTWidget::findWidget(os, "fileNameEdit", dialog));
66     GT_CHECK(lineEdit != nullptr, "File name line edit not found");
67     defaultExportPath = GTLineEdit::copyText(os, lineEdit);
68     GTLineEdit::setText(os, lineEdit, path + name);
69 
70     if (!seqName.isEmpty()) {
71         QCheckBox *customSeqCheckBox = dialog->findChild<QCheckBox *>("customSeqNameBox");
72         GT_CHECK(customSeqCheckBox != nullptr, "Sequence name checkbox not found");
73         GTCheckBox::setChecked(os, customSeqCheckBox, true);
74         QLineEdit *sequenceNameEdit = qobject_cast<QLineEdit *>(GTWidget::findWidget(os, "sequenceNameEdit", dialog));
75         GT_CHECK(sequenceNameEdit != nullptr, "Sequence name line edit not found");
76         GTLineEdit::setText(os, sequenceNameEdit, seqName);
77     }
78 
79     QCheckBox *translateButton = qobject_cast<QCheckBox *>(GTWidget::findWidget(os, "translateButton"));
80     CHECK_SET_ERR(translateButton != nullptr, "translateButton not found!");
81     GTCheckBox::setChecked(os, translateButton, translate);
82 
83     if (translate) {
84         QCheckBox *allTFramesButton = qobject_cast<QCheckBox *>(GTWidget::findWidget(os, "allTFramesButton"));
85         GTCheckBox::setChecked(os, allTFramesButton, saveAllAminoFrames);
86     }
87 
88     GTUtilsDialog::clickButtonBox(os, dialog, QDialogButtonBox::Ok);
89 }
90 #undef GT_METHOD_NAME
91 
setPath(const QString & value)92 void ExportSelectedRegionFiller::setPath(const QString &value) {
93     path = value;
94 }
95 
setName(const QString & value)96 void ExportSelectedRegionFiller::setName(const QString &value) {
97     name = value;
98 }
99 
100 #undef GT_CLASS_NAME
101 
102 #define GT_CLASS_NAME "GTUtilsDialog::exportSequenceOfSelectedAnnotationsFiller"
ExportSequenceOfSelectedAnnotationsFiller(HI::GUITestOpStatus & _os,const QString & _path,FormatToUse _format,MergeOptions _options,int _gapLength,bool _addDocToProject,bool _exportWithAnnotations,GTGlobals::UseMethod method)103 ExportSequenceOfSelectedAnnotationsFiller::ExportSequenceOfSelectedAnnotationsFiller(HI::GUITestOpStatus &_os, const QString &_path, FormatToUse _format, MergeOptions _options, int _gapLength, bool _addDocToProject, bool _exportWithAnnotations, GTGlobals::UseMethod method)
104     : Filler(_os, "U2__ExportSequencesDialog"), gapLength(_gapLength), format(_format), addToProject(_addDocToProject),
105       exportWithAnnotations(false), options(_options), useMethod(method) {
106     exportWithAnnotations = _exportWithAnnotations;
107     path = GTFileDialog::toAbsoluteNativePath(_path);
108 
109     comboBoxItems[Fasta] = "FASTA";
110     comboBoxItems[Fastq] = "FASTQ";
111     comboBoxItems[Gff] = "GFF";
112     comboBoxItems[Genbank] = "GenBank";
113 
114     mergeRadioButtons[SaveAsSeparate] = "separateButton";
115     mergeRadioButtons[Merge] = "mergeButton";
116 }
117 
118 #define GT_METHOD_NAME "commonScenario"
commonScenario()119 void ExportSequenceOfSelectedAnnotationsFiller::commonScenario() {
120     QWidget *dialog = QApplication::activeModalWidget();
121     GT_CHECK(dialog != nullptr, "dialog not found");
122 
123     QLineEdit *fileNameEdit = dialog->findChild<QLineEdit *>("fileNameEdit");
124     GT_CHECK(fileNameEdit != nullptr, "fileNameEdit not found");
125     GTLineEdit::setText(os, fileNameEdit, path);
126 
127     GTGlobals::sleep(200);
128 
129     QComboBox *comboBox = dialog->findChild<QComboBox *>();
130     GT_CHECK(comboBox != nullptr, "ComboBox not found");
131     int index = comboBox->findText(comboBoxItems[format]);
132 
133     GT_CHECK(index != -1, QString("item \"%1\" in combobox not found").arg(comboBoxItems[format]));
134     GTComboBox::selectItemByIndex(os, comboBox, index, useMethod);
135 
136     GTGlobals::sleep(200);
137 
138     QCheckBox *projectCheckBox = dialog->findChild<QCheckBox *>(QString::fromUtf8("addToProjectBox"));
139     GT_CHECK(projectCheckBox != nullptr, "addToProjectBox not found");
140     GTCheckBox::setChecked(os, projectCheckBox, addToProject);
141 
142     GTGlobals::sleep(200);
143 
144     QCheckBox *annotationsCheckBox = dialog->findChild<QCheckBox *>(QString::fromUtf8("withAnnotationsBox"));
145     GT_CHECK(annotationsCheckBox != nullptr, "Check box not found");
146     if (annotationsCheckBox->isEnabled()) {
147         GTCheckBox::setChecked(os, annotationsCheckBox, exportWithAnnotations);
148     }
149 
150     GTGlobals::sleep(200);
151 
152     QRadioButton *mergeButton = dialog->findChild<QRadioButton *>(mergeRadioButtons[options]);
153 
154     GT_CHECK(mergeButton != nullptr, "Radio button " + mergeRadioButtons[options] + " not found");
155     if (mergeButton->isEnabled()) {
156         GTRadioButton::click(os, mergeButton);
157     }
158 
159     GTGlobals::sleep(200);
160 
161     if (gapLength) {
162         QSpinBox *mergeSpinBox = dialog->findChild<QSpinBox *>("mergeSpinBox");
163         GT_CHECK(mergeSpinBox != nullptr, "SpinBox not found");
164         GTSpinBox::setValue(os, mergeSpinBox, gapLength, useMethod);
165     }
166 
167     GTGlobals::sleep(200);
168 
169     GTUtilsDialog::clickButtonBox(os, dialog, QDialogButtonBox::Ok);
170 }
171 #undef GT_METHOD_NAME
172 #undef GT_CLASS_NAME
173 
174 }  // namespace U2
175