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 <drivers/GTKeyboardDriver.h>
23 #include <drivers/GTMouseDriver.h>
24 #include <primitives/GTAction.h>
25 #include <primitives/GTToolbar.h>
26 #include <primitives/PopupChooser.h>
27 #include <system/GTClipboard.h>
28 #include <utils/GTKeyboardUtils.h>
29 #include <utils/GTThread.h>
30 
31 #include <U2Core/U2SafePoints.h>
32 
33 #include <U2Gui/MainWindow.h>
34 
35 #include <U2View/BaseWidthController.h>
36 #include <U2View/MSAEditorConsensusArea.h>
37 #include <U2View/MSAEditorOverviewArea.h>
38 #include <U2View/MaEditorFactory.h>
39 #include <U2View/MaEditorNameList.h>
40 #include <U2View/MaEditorSelection.h>
41 #include <U2View/MaGraphOverview.h>
42 #include <U2View/MaSimpleOverview.h>
43 #include <U2View/RowHeightController.h>
44 
45 #include "GTUtilsMdi.h"
46 #include "GTUtilsMsaEditor.h"
47 #include "GTUtilsMsaEditorSequenceArea.h"
48 #include "GTUtilsOptionPanelMSA.h"
49 #include "GTUtilsProjectTreeView.h"
50 #include "api/GTMSAEditorStatusWidget.h"
51 #include "runnables/ugene/corelibs/U2View/ov_msa/BuildTreeDialogFiller.h"
52 
53 namespace U2 {
54 using namespace HI;
55 
56 #define GT_CLASS_NAME "GTUtilsMsaEditor"
57 
58 #define GT_METHOD_NAME "getActiveMsaEditorWindow"
getActiveMsaEditorWindow(GUITestOpStatus & os)59 QWidget *GTUtilsMsaEditor::getActiveMsaEditorWindow(GUITestOpStatus &os) {
60     QWidget *widget = GTUtilsMdi::getActiveObjectViewWindow(os, MsaEditorFactory::ID);
61     GTThread::waitForMainThread();
62     return widget;
63 }
64 #undef GT_METHOD_NAME
65 
66 #define GT_METHOD_NAME "checkMsaEditorWindowIsActive"
checkMsaEditorWindowIsActive(GUITestOpStatus & os)67 void GTUtilsMsaEditor::checkMsaEditorWindowIsActive(GUITestOpStatus &os) {
68     getActiveMsaEditorWindow(os);
69 }
70 #undef GT_METHOD_NAME
71 
72 #define GT_METHOD_NAME "checkNoMsaEditorWindowIsOpened"
checkNoMsaEditorWindowIsOpened(GUITestOpStatus & os)73 void GTUtilsMsaEditor::checkNoMsaEditorWindowIsOpened(GUITestOpStatus &os) {
74     GTUtilsMdi::checkNoObjectViewWindowIsOpened(os, MsaEditorFactory::ID);
75 }
76 #undef GT_METHOD_NAME
77 
78 #define GT_METHOD_NAME "getGraphOverviewTopLeftPixelColor"
getGraphOverviewPixelColor(GUITestOpStatus & os,const QPoint & point)79 QColor GTUtilsMsaEditor::getGraphOverviewPixelColor(GUITestOpStatus &os, const QPoint &point) {
80     return GTWidget::getColor(os, getGraphOverview(os), point);
81 }
82 
getSimpleOverviewPixelColor(GUITestOpStatus & os,const QPoint & point)83 QColor GTUtilsMsaEditor::getSimpleOverviewPixelColor(GUITestOpStatus &os, const QPoint &point) {
84     return GTWidget::getColor(os, getSimpleOverview(os), point);
85 }
86 #undef GT_METHOD_NAME
87 
88 #define GT_METHOD_NAME "getEditor"
getEditor(GUITestOpStatus & os)89 MSAEditor *GTUtilsMsaEditor::getEditor(GUITestOpStatus &os) {
90     MsaEditorWgt *editorUi = getEditorUi(os);
91     return editorUi->getEditor();
92 }
93 #undef GT_METHOD_NAME
94 
95 #define GT_METHOD_NAME "getEditorUi"
getEditorUi(GUITestOpStatus & os)96 MsaEditorWgt *GTUtilsMsaEditor::getEditorUi(GUITestOpStatus &os) {
97     checkMsaEditorWindowIsActive(os);
98     MsaEditorWgt *msaEditorWgt = nullptr;
99     // For some reason MsaEditorWgt is not within normal widgets hierarchy (wrong parent?), so can't use GTWidget::findWidget here.
100     for (int time = 0; time < GT_OP_WAIT_MILLIS && msaEditorWgt == nullptr; time += GT_OP_CHECK_MILLIS) {
101         GTGlobals::sleep(time > 0 ? GT_OP_CHECK_MILLIS : 0);
102         MainWindow *mainWindow = AppContext::getMainWindow();
103         QWidget *activeWindow = mainWindow == nullptr ? nullptr : mainWindow->getMDIManager()->getActiveWindow();
104         if (activeWindow == nullptr) {
105             continue;
106         }
107         msaEditorWgt = activeWindow->findChild<MsaEditorWgt *>();
108     }
109     GT_CHECK_RESULT(msaEditorWgt != nullptr, "MSA Editor widget is not found", nullptr);
110     return msaEditorWgt;
111 }
112 #undef GT_METHOD_NAME
113 
114 #define GT_METHOD_NAME "getGraphOverview"
getGraphOverview(GUITestOpStatus & os)115 MaGraphOverview *GTUtilsMsaEditor::getGraphOverview(GUITestOpStatus &os) {
116     QWidget *activeWindow = getActiveMsaEditorWindow(os);
117     MaGraphOverview *result = GTWidget::findExactWidget<MaGraphOverview *>(os, MSAEditorOverviewArea::OVERVIEW_AREA_OBJECT_NAME + QString("_graph"), activeWindow);
118     GT_CHECK_RESULT(nullptr != result, "MaGraphOverview is not found", nullptr);
119     return result;
120 }
121 #undef GT_METHOD_NAME
122 
123 #define GT_METHOD_NAME "getSimpleOverview"
getSimpleOverview(GUITestOpStatus & os)124 MaSimpleOverview *GTUtilsMsaEditor::getSimpleOverview(GUITestOpStatus &os) {
125     QWidget *activeWindow = getActiveMsaEditorWindow(os);
126     MaSimpleOverview *result = GTWidget::findExactWidget<MaSimpleOverview *>(os, MSAEditorOverviewArea::OVERVIEW_AREA_OBJECT_NAME + QString("_simple"), activeWindow);
127     GT_CHECK_RESULT(nullptr != result, "MaSimpleOverview is not found", nullptr);
128     return result;
129 }
130 #undef GT_METHOD_NAME
131 
132 #define GT_METHOD_NAME "getTreeView"
getTreeView(GUITestOpStatus & os)133 MSAEditorTreeViewerUI *GTUtilsMsaEditor::getTreeView(GUITestOpStatus &os) {
134     QWidget *activeWindow = getActiveMsaEditorWindow(os);
135     return GTWidget::findExactWidget<MSAEditorTreeViewerUI *>(os, "treeView", activeWindow);
136 }
137 #undef GT_METHOD_NAME
138 
139 #define GT_METHOD_NAME "getNameListArea"
getNameListArea(GUITestOpStatus & os)140 MaEditorNameList *GTUtilsMsaEditor::getNameListArea(GUITestOpStatus &os) {
141     QWidget *activeWindow = getActiveMsaEditorWindow(os);
142     MaEditorNameList *result = GTWidget::findExactWidget<MaEditorNameList *>(os, "msa_editor_name_list", activeWindow);
143     GT_CHECK_RESULT(result != nullptr, "MaGraphOverview is not found", nullptr);
144     return result;
145 }
146 #undef GT_METHOD_NAME
147 
148 #define GT_METHOD_NAME "getConsensusArea"
getConsensusArea(GUITestOpStatus & os)149 MSAEditorConsensusArea *GTUtilsMsaEditor::getConsensusArea(GUITestOpStatus &os) {
150     QWidget *activeWindow = getActiveMsaEditorWindow(os);
151     return GTWidget::findExactWidget<MSAEditorConsensusArea *>(os, "consArea", activeWindow);
152 }
153 #undef GT_METHOD_NAME
154 
155 #define GT_METHOD_NAME "getSequenceNameRect"
getSequenceArea(GUITestOpStatus & os)156 MSAEditorSequenceArea *GTUtilsMsaEditor::getSequenceArea(GUITestOpStatus &os) {
157     return GTUtilsMSAEditorSequenceArea::getSequenceArea(os);
158 }
159 #undef GT_METHOD_NAME
160 
161 #define GT_METHOD_NAME "getSequenceNameRectByName"
getSequenceNameRect(GUITestOpStatus & os,const QString & sequenceName)162 QRect GTUtilsMsaEditor::getSequenceNameRect(GUITestOpStatus &os, const QString &sequenceName) {
163     MaEditorNameList *nameList = getNameListArea(os);
164     GT_CHECK_RESULT(nameList != nullptr, "MSAEditorNameList not found", QRect());
165 
166     QStringList rowNames = GTUtilsMSAEditorSequenceArea::getCurrentRowNames(os);
167     int viewRowIndex = rowNames.indexOf(sequenceName);
168     GT_CHECK_RESULT(viewRowIndex >= 0, QString("Sequence '%1' not found").arg(sequenceName), QRect());
169     return getSequenceNameRect(os, viewRowIndex);
170 }
171 #undef GT_METHOD_NAME
172 
173 #define GT_METHOD_NAME "getSequenceNameRectByIndex"
getSequenceNameRect(GUITestOpStatus & os,int viewRowIndex)174 QRect GTUtilsMsaEditor::getSequenceNameRect(GUITestOpStatus &os, int viewRowIndex) {
175     GT_CHECK_RESULT(viewRowIndex >= 0, QString("Sequence '%1' not found").arg(viewRowIndex), QRect());
176 
177     U2Region nameListYRegion = getEditorUi(os)->getRowHeightController()->getScreenYRegionByViewRowIndex(viewRowIndex);
178     MaEditorNameList *nameList = getNameListArea(os);
179     QPoint topLeftPoint = nameList->mapToGlobal(QPoint(0, (int)nameListYRegion.startPos));
180     QPoint bottomRightPoint = nameList->mapToGlobal(QPoint(nameList->width(), (int)nameListYRegion.endPos()));
181     return QRect(topLeftPoint, bottomRightPoint);
182 }
183 #undef GT_METHOD_NAME
184 
185 #define GT_METHOD_NAME "getColumnHeaderRect"
getColumnHeaderRect(GUITestOpStatus & os,int column)186 QRect GTUtilsMsaEditor::getColumnHeaderRect(GUITestOpStatus &os, int column) {
187     MSAEditorConsensusArea *consensusArea = getConsensusArea(os);
188     GT_CHECK_RESULT(nullptr != consensusArea, "Consensus area is NULL", QRect());
189     MSAEditorSequenceArea *sequenceArea = getSequenceArea(os);
190     GT_CHECK_RESULT(nullptr != sequenceArea, "Sequence area is NULL", QRect());
191     MSAEditor *editor = getEditor(os);
192     GT_CHECK_RESULT(nullptr != editor, "MSA Editor is NULL", QRect());
193 
194     BaseWidthController *baseWidthController = editor->getUI()->getBaseWidthController();
195     return QRect(consensusArea->mapToGlobal(QPoint(baseWidthController->getBaseScreenOffset(column),
196                                                    consensusArea->geometry().top())),
197                  QSize(baseWidthController->getBaseWidth(),
198                        consensusArea->height()));
199 }
200 #undef GT_METHOD_NAME
201 
202 #define GT_METHOD_NAME "replaceSequence"
replaceSequence(GUITestOpStatus & os,const QString & sequenceToReplace,int targetPosition)203 void GTUtilsMsaEditor::replaceSequence(GUITestOpStatus &os, const QString &sequenceToReplace, int targetPosition) {
204     clickSequenceName(os, sequenceToReplace);
205 
206     targetPosition = qMax(0, qMin(getSequencesCount(os) - 1, targetPosition));
207     const QString targetSequenceName = GTUtilsMSAEditorSequenceArea::getNameList(os)[targetPosition];
208 
209     const QPoint dragFrom = getSequenceNameRect(os, sequenceToReplace).center();
210     const QPoint dragTo = getSequenceNameRect(os, targetSequenceName).center();
211 
212     GTMouseDriver::moveTo(dragFrom);
213     GTMouseDriver::press();
214     GTMouseDriver::moveTo(dragTo);
215     GTMouseDriver::release();
216     GTThread::waitForMainThread();
217 }
218 #undef GT_METHOD_NAME
219 
220 #define GT_METHOD_NAME "replaceSequence"
replaceSequence(GUITestOpStatus & os,int rowNumber,int targetPosition)221 void GTUtilsMsaEditor::replaceSequence(GUITestOpStatus &os, int rowNumber, int targetPosition) {
222     const QStringList names = GTUtilsMSAEditorSequenceArea::getNameList(os);
223     GT_CHECK(0 <= rowNumber && rowNumber <= names.size(), "Row number is out of boundaries");
224     replaceSequence(os, names[rowNumber], targetPosition);
225 }
226 #undef GT_METHOD_NAME
227 
228 #define GT_METHOD_NAME "removeColumn"
removeColumn(GUITestOpStatus & os,int column)229 void GTUtilsMsaEditor::removeColumn(GUITestOpStatus &os, int column) {
230     clickColumn(os, column);
231     GTKeyboardDriver::keyClick(Qt::Key_Delete);
232 }
233 #undef GT_METHOD_NAME
234 
235 #define GT_METHOD_NAME "removeRows"
removeRows(GUITestOpStatus & os,int firstRowNumber,int lastRowNumber)236 void GTUtilsMsaEditor::removeRows(GUITestOpStatus &os, int firstRowNumber, int lastRowNumber) {
237     selectRows(os, firstRowNumber, lastRowNumber);
238     GTKeyboardDriver::keyClick(Qt::Key_Delete);
239 }
240 #undef GT_METHOD_NAME
241 
242 #define GT_METHOD_NAME "moveToSequence"
moveToSequence(GUITestOpStatus & os,int rowNumber)243 void GTUtilsMsaEditor::moveToSequence(GUITestOpStatus &os, int rowNumber) {
244     const QRect sequenceNameRect = getSequenceNameRect(os, rowNumber);
245     GTMouseDriver::moveTo(sequenceNameRect.center());
246 }
247 #undef GT_METHOD_NAME
248 
249 #define GT_METHOD_NAME "moveToSequenceName"
moveToSequenceName(GUITestOpStatus & os,const QString & sequenceName)250 void GTUtilsMsaEditor::moveToSequenceName(GUITestOpStatus &os, const QString &sequenceName) {
251     QRect sequenceNameRect = getSequenceNameRect(os, sequenceName);
252     GTMouseDriver::moveTo(sequenceNameRect.center());
253 }
254 #undef GT_METHOD_NAME
255 
256 #define GT_METHOD_NAME "clickSequence"
clickSequence(GUITestOpStatus & os,int rowNumber,Qt::MouseButton mouseButton)257 void GTUtilsMsaEditor::clickSequence(GUITestOpStatus &os, int rowNumber, Qt::MouseButton mouseButton) {
258     moveToSequence(os, rowNumber);
259     GTMouseDriver::click(mouseButton);
260 }
261 #undef GT_METHOD_NAME
262 
263 #define GT_METHOD_NAME "clickSequenceName"
clickSequenceName(GUITestOpStatus & os,const QString & sequenceName,const Qt::MouseButton & mouseButton,const Qt::KeyboardModifiers & modifiers)264 void GTUtilsMsaEditor::clickSequenceName(GUITestOpStatus &os, const QString &sequenceName, const Qt::MouseButton &mouseButton, const Qt::KeyboardModifiers &modifiers) {
265     moveToSequenceName(os, sequenceName);
266 
267     QList<Qt::Key> modifierKeys = GTKeyboardDriver::modifiersToKeys(modifiers);
268     for (auto key : qAsConst(modifierKeys)) {
269         GTKeyboardDriver::keyPress(key);
270     }
271     GTMouseDriver::click(mouseButton);
272     for (auto key : qAsConst(modifierKeys)) {
273         GTKeyboardDriver::keyRelease(key);
274     }
275 }
276 #undef GT_METHOD_NAME
277 
278 #define GT_METHOD_NAME "moveToColumn"
moveToColumn(GUITestOpStatus & os,int column)279 void GTUtilsMsaEditor::moveToColumn(GUITestOpStatus &os, int column) {
280     GTUtilsMSAEditorSequenceArea::scrollToPosition(os, QPoint(column, 1));
281     const QRect columnHeaderRect = getColumnHeaderRect(os, column);
282     GTMouseDriver::moveTo(columnHeaderRect.center());
283 }
284 #undef GT_METHOD_NAME
285 
286 #define GT_METHOD_NAME "clickColumn"
clickColumn(GUITestOpStatus & os,int column,Qt::MouseButton mouseButton)287 void GTUtilsMsaEditor::clickColumn(GUITestOpStatus &os, int column, Qt::MouseButton mouseButton) {
288     moveToColumn(os, column);
289     GTMouseDriver::click(mouseButton);
290 }
291 #undef GT_METHOD_NAME
292 
293 #define GT_METHOD_NAME "selectRows"
selectRows(GUITestOpStatus & os,int firstRowNumber,int lastRowNumber,GTGlobals::UseMethod method)294 void GTUtilsMsaEditor::selectRows(GUITestOpStatus &os, int firstRowNumber, int lastRowNumber, GTGlobals::UseMethod method) {
295     switch (method) {
296         case GTGlobals::UseKey:
297             clickSequence(os, firstRowNumber);
298             GTKeyboardDriver::keyPress(Qt::Key_Shift);
299             clickSequence(os, lastRowNumber);
300             GTKeyboardDriver::keyRelease(Qt::Key_Shift);
301             break;
302         case GTGlobals::UseMouse:
303             GTMouseDriver::dragAndDrop(getSequenceNameRect(os, firstRowNumber).center(),
304                                        getSequenceNameRect(os, lastRowNumber).center());
305             break;
306         case GTGlobals::UseKeyBoard:
307             GT_CHECK(false, "Not implemented");
308         default:
309             GT_CHECK(false, "An unknown method");
310     }
311 }
312 #undef GT_METHOD_NAME
313 
314 #define GT_METHOD_NAME "selectRowsByName"
selectRowsByName(HI::GUITestOpStatus & os,const QStringList & rowNames)315 void GTUtilsMsaEditor::selectRowsByName(HI::GUITestOpStatus &os, const QStringList &rowNames) {
316     for (const QString &rowName : qAsConst(rowNames)) {
317         clickSequenceName(os, rowName, Qt::LeftButton, Qt::ControlModifier);
318     }
319 }
320 #undef GT_METHOD_NAME
321 
322 #define GT_METHOD_NAME "selectColumns"
selectColumns(GUITestOpStatus & os,int firstColumnNumber,int lastColumnNumber,GTGlobals::UseMethod method)323 void GTUtilsMsaEditor::selectColumns(GUITestOpStatus &os, int firstColumnNumber, int lastColumnNumber, GTGlobals::UseMethod method) {
324     switch (method) {
325         case GTGlobals::UseKey:
326             clickColumn(os, firstColumnNumber);
327             GTKeyboardDriver::keyPress(Qt::Key_Shift);
328             clickColumn(os, lastColumnNumber);
329             GTKeyboardDriver::keyRelease(Qt::Key_Shift);
330             break;
331         case GTGlobals::UseMouse:
332             GTMouseDriver::dragAndDrop(getColumnHeaderRect(os, firstColumnNumber).center(),
333                                        getColumnHeaderRect(os, lastColumnNumber).center());
334             break;
335         case GTGlobals::UseKeyBoard:
336             GT_CHECK(false, "Not implemented");
337         default:
338             GT_CHECK(false, "An unknown method");
339     }
340 }
341 #undef GT_METHOD_NAME
342 
343 #define GT_METHOD_NAME "clearSelection"
clearSelection(GUITestOpStatus & os)344 void GTUtilsMsaEditor::clearSelection(GUITestOpStatus &os) {
345     Q_UNUSED(os);
346     GTKeyboardDriver::keyClick(Qt::Key_Escape);
347 }
348 #undef GT_METHOD_NAME
349 
350 #define GT_METHOD_NAME "checkSelection"
checkSelection(HI::GUITestOpStatus & os,const QList<QRect> & expectedRects)351 void GTUtilsMsaEditor::checkSelection(HI::GUITestOpStatus &os, const QList<QRect> &expectedRects) {
352     MSAEditor *msaEditor = GTUtilsMsaEditor::getEditor(os);
353     QList<QRect> selectedRects = msaEditor->getSelection().getRectList();
354     CHECK_SET_ERR(selectedRects.size() == expectedRects.size(), QString("Expected selection size: %1, actual: %2").arg(expectedRects.size()).arg(selectedRects.size()));
355     for (int i = 0; i < selectedRects.size(); i++) {
356         QRect expectedRect = expectedRects[i];
357         QRect selectedRect = selectedRects[i];
358         CHECK_SET_ERR(selectedRect == expectedRect,
359                       QString("Selection rect is not equal to the expected one, idx: %1, rect: (x:%2, y:%3, w: %4, h: %5), expected: (x: %6, y: %7, w: %8, h: %9)")
360                           .arg(i)
361                           .arg(selectedRect.x())
362                           .arg(selectedRect.y())
363                           .arg(selectedRect.width())
364                           .arg(selectedRect.height())
365                           .arg(expectedRect.x())
366                           .arg(expectedRect.y())
367                           .arg(expectedRect.width())
368                           .arg(expectedRect.height()));
369     }
370 }
371 #undef GT_METHOD_NAME
372 
373 #define GT_METHOD_NAME "getReferenceSequenceName"
getReferenceSequenceName(GUITestOpStatus & os)374 QString GTUtilsMsaEditor::getReferenceSequenceName(GUITestOpStatus &os) {
375     return GTUtilsOptionPanelMsa::getReference(os);
376 }
377 #undef GT_METHOD_NAME
378 
379 #define GT_METHOD_NAME "toggleCollapsingMode"
toggleCollapsingMode(GUITestOpStatus & os)380 void GTUtilsMsaEditor::toggleCollapsingMode(GUITestOpStatus &os) {
381     Q_UNUSED(os);
382     GTWidget::click(os, GTToolbar::getWidgetForActionTooltip(os, GTToolbar::getToolbar(os, MWTOOLBAR_ACTIVEMDI), "Switch on/off collapsing"));
383 }
384 #undef GT_METHOD_NAME
385 
386 #define GT_METHOD_NAME "isSequenceCollapsed"
isSequenceCollapsed(GUITestOpStatus & os,const QString & seqName)387 bool GTUtilsMsaEditor::isSequenceCollapsed(GUITestOpStatus &os, const QString &seqName) {
388     QStringList names = GTUtilsMSAEditorSequenceArea::getNameList(os);
389     GT_CHECK_RESULT(names.contains(seqName), "sequence " + seqName + " not found in name list", false);
390     QStringList visiablenames = GTUtilsMSAEditorSequenceArea::getVisibleNames(os);
391 
392     return !visiablenames.contains(seqName);
393 }
394 #undef GT_METHOD_NAME
395 
396 #define GT_METHOD_NAME "toggleCollapsingMode"
toggleCollapsingGroup(GUITestOpStatus & os,const QString & groupName)397 void GTUtilsMsaEditor::toggleCollapsingGroup(GUITestOpStatus &os, const QString &groupName) {
398     Q_UNUSED(os);
399 
400     const QRect sequenceNameRect = getSequenceNameRect(os, groupName);
401     QPoint magicExpandButtonOffset;
402 #ifdef Q_OS_WIN
403     magicExpandButtonOffset = QPoint(15, 10);
404 #else
405     magicExpandButtonOffset = QPoint(15, 5);
406 #endif
407     GTMouseDriver::moveTo(sequenceNameRect.topLeft() + magicExpandButtonOffset);
408     GTMouseDriver::click();
409 }
410 #undef GT_METHOD_NAME
411 
412 #define GT_METHOD_NAME "getSequencesCount"
getSequencesCount(GUITestOpStatus & os)413 int GTUtilsMsaEditor::getSequencesCount(GUITestOpStatus &os) {
414     QWidget *statusWidget = GTWidget::findWidget(os, "msa_editor_status_bar");
415     return GTMSAEditorStatusWidget::getSequencesCount(os, statusWidget);
416 }
417 #undef GT_METHOD_NAME
418 
419 #define GT_METHOD_NAME "getWholeData"
getWholeData(GUITestOpStatus & os)420 QStringList GTUtilsMsaEditor::getWholeData(GUITestOpStatus &os) {
421     const QStringList names = GTUtilsMSAEditorSequenceArea::getNameList(os);
422     GT_CHECK_RESULT(!names.isEmpty(), "The name list is empty", QStringList());
423 
424     clickSequenceName(os, names.first());
425     GTKeyboardDriver::keyPress(Qt::Key_Shift);
426     clickSequenceName(os, names.last());
427     GTKeyboardDriver::keyRelease(Qt::Key_Shift);
428 
429     GTKeyboardUtils::copy();
430     GTGlobals::sleep(500);
431 
432     return GTClipboard::text(os).split('\n');
433 }
434 #undef GT_METHOD_NAME
435 
436 #define GT_METHOD_NAME "undo"
undo(GUITestOpStatus & os)437 void GTUtilsMsaEditor::undo(GUITestOpStatus &os) {
438     getActiveMsaEditorWindow(os);
439     GTWidget::click(os, GTToolbar::getWidgetForActionObjectName(os, GTToolbar::getToolbar(os, MWTOOLBAR_ACTIVEMDI), "msa_action_undo"));
440 }
441 #undef GT_METHOD_NAME
442 
443 #define GT_METHOD_NAME "redo"
redo(GUITestOpStatus & os)444 void GTUtilsMsaEditor::redo(GUITestOpStatus &os) {
445     getActiveMsaEditorWindow(os);
446     GTWidget::click(os, GTToolbar::getWidgetForActionObjectName(os, GTToolbar::getToolbar(os, MWTOOLBAR_ACTIVEMDI), "msa_action_redo"));
447 }
448 #undef GT_METHOD_NAME
449 
450 #define GT_METHOD_NAME "zoomIn"
zoomIn(GUITestOpStatus & os)451 void GTUtilsMsaEditor::zoomIn(GUITestOpStatus &os) {
452     QToolBar *toolbar = GTToolbar::getToolbar(os, "mwtoolbar_activemdi");
453     QWidget *zoomInButton = GTToolbar::getWidgetForActionObjectName(os, toolbar, "Zoom In");
454     GTWidget::click(os, zoomInButton);
455 }
456 #undef GT_METHOD_NAME
457 
458 #define GT_METHOD_NAME "zoomOut"
zoomOut(GUITestOpStatus & os)459 void GTUtilsMsaEditor::zoomOut(GUITestOpStatus &os) {
460     QToolBar *toolbar = GTToolbar::getToolbar(os, "mwtoolbar_activemdi");
461     QWidget *zoomOutButton = GTToolbar::getWidgetForActionObjectName(os, toolbar, "Zoom Out");
462     GTWidget::click(os, zoomOutButton);
463 }
464 #undef GT_METHOD_NAME
465 
466 #define GT_METHOD_NAME "isUndoEnabled"
isUndoEnabled(GUITestOpStatus & os)467 bool GTUtilsMsaEditor::isUndoEnabled(GUITestOpStatus &os) {
468     getActiveMsaEditorWindow(os);
469     return GTToolbar::getWidgetForActionObjectName(os, GTToolbar::getToolbar(os, MWTOOLBAR_ACTIVEMDI), "msa_action_undo")->isEnabled();
470 }
471 #undef GT_METHOD_NAME
472 
473 #define GT_METHOD_NAME "isRedoEnabled"
isRedoEnabled(GUITestOpStatus & os)474 bool GTUtilsMsaEditor::isRedoEnabled(GUITestOpStatus &os) {
475     getActiveMsaEditorWindow(os);
476     return GTToolbar::getWidgetForActionObjectName(os, GTToolbar::getToolbar(os, MWTOOLBAR_ACTIVEMDI), "msa_action_redo")->isEnabled();
477 }
478 #undef GT_METHOD_NAME
479 
480 #define GT_METHOD_NAME "buildPhylogeneticTree"
buildPhylogeneticTree(GUITestOpStatus & os,const QString & pathToSave)481 void GTUtilsMsaEditor::buildPhylogeneticTree(GUITestOpStatus &os, const QString &pathToSave) {
482     GTUtilsDialog::waitForDialog(os, new BuildTreeDialogFiller(os, pathToSave, 0, 0, true));
483     GTToolbar::clickButtonByTooltipOnToolbar(os, MWTOOLBAR_ACTIVEMDI, "Build Tree");
484 }
485 #undef GT_METHOD_NAME
486 
487 #define GT_METHOD_NAME "closeActiveTreeTab"
closeActiveTreeTab(GUITestOpStatus & os)488 void GTUtilsMsaEditor::closeActiveTreeTab(GUITestOpStatus &os) {
489     QWidget *treeTabWidget = GTWidget::findWidget(os, "msa_editor_tree_tab_area", getActiveMsaEditorWindow(os));
490 
491     QTabBar *tabBar = treeTabWidget->findChild<QTabBar *>();
492     GT_CHECK(tabBar != nullptr, "Tree tab widget must have a tab bar!");
493 
494     int tabIndex = tabBar->currentIndex();
495     GT_CHECK(tabIndex >= 0, "TabBar must have a current tab!");
496 
497     QWidget *closeTabButton = tabBar->tabButton(tabIndex, QTabBar::RightSide);
498     if (closeTabButton == nullptr) {
499         closeTabButton = tabBar->tabButton(tabIndex, QTabBar::RightSide);
500         GT_CHECK(closeTabButton != nullptr, "TabBar must have close button!");
501     }
502     GTWidget::click(os, closeTabButton);
503 }
504 #undef GT_METHOD_NAME
505 
506 #define GT_METHOD_NAME "dragAndDropSequenceFromProject"
dragAndDropSequenceFromProject(GUITestOpStatus & os,const QStringList & pathToSequence)507 void GTUtilsMsaEditor::dragAndDropSequenceFromProject(GUITestOpStatus &os, const QStringList &pathToSequence) {
508     GTUtilsProjectTreeView::dragAndDrop(os, pathToSequence, getEditorUi(os));
509 }
510 #undef GT_METHOD_NAME
511 
512 #define GT_METHOD_NAME "activateAlignSequencesToAlignmentMenu"
activateAlignSequencesToAlignmentMenu(HI::GUITestOpStatus & os,const QString & partOfMenuItemText)513 void GTUtilsMsaEditor::activateAlignSequencesToAlignmentMenu(HI::GUITestOpStatus &os, const QString &partOfMenuItemText) {
514     GTUtilsDialog::waitForDialog(os, new PopupChooserByText(os, {partOfMenuItemText}, GTGlobals::UseMouse, Qt::MatchContains));
515     GTToolbar::clickButtonByTooltipOnToolbar(os, MWTOOLBAR_ACTIVEMDI, "Align sequence(s) to this alignment");
516 }
517 #undef GT_METHOD_NAME
518 
519 #define GT_METHOD_NAME "checkAlignSequencesToAlignmentMenu"
checkAlignSequencesToAlignmentMenu(HI::GUITestOpStatus & os,const QString & partOfMenuItemText,const PopupChecker::CheckOption & checkOption)520 void GTUtilsMsaEditor::checkAlignSequencesToAlignmentMenu(HI::GUITestOpStatus &os, const QString &partOfMenuItemText, const PopupChecker::CheckOption &checkOption) {
521     GTUtilsDialog::waitForDialog(os, new PopupCheckerByText(os, {partOfMenuItemText}, checkOption, GTGlobals::UseMouse, Qt::MatchContains));
522     GTToolbar::clickButtonByTooltipOnToolbar(os, MWTOOLBAR_ACTIVEMDI, "Align sequence(s) to this alignment");
523     GTKeyboardDriver::keyClick(Qt::Key_Escape);
524 }
525 #undef GT_METHOD_NAME
526 
527 #define GT_METHOD_NAME "setReference"
setReference(GUITestOpStatus & os,const QString & sequenceName)528 void GTUtilsMsaEditor::setReference(GUITestOpStatus &os, const QString &sequenceName) {
529     GTUtilsDialog::waitForDialog(os, new PopupChooserByText(os, QStringList() << "Set this sequence as reference", GTGlobals::UseMouse));
530     clickSequenceName(os, sequenceName, Qt::RightButton);
531     GTGlobals::sleep(100);
532 }
533 #undef GT_METHOD_NAME
534 
535 #undef GT_CLASS_NAME
536 
537 }  // namespace U2
538