1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301
|
// --------------------------------------------------------------------------
// OpenMS -- Open-Source Mass Spectrometry
// --------------------------------------------------------------------------
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
//
// This software is released under a three-clause BSD license:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of any author or any participating institution
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
// For a full list of authors, refer to the file AUTHORS.
// --------------------------------------------------------------------------
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// --------------------------------------------------------------------------
// $Maintainer: Johannes Junker $
// $Authors: Johannes Junker, Chris Bielow $
// --------------------------------------------------------------------------
#include <OpenMS/VISUAL/TOPPASScene.h>
#include <OpenMS/VISUAL/TOPPASVertex.h>
#include <OpenMS/VISUAL/TOPPASWidget.h>
#include <OpenMS/VISUAL/TOPPASInputFileListVertex.h>
#include <OpenMS/VISUAL/TOPPASOutputFileListVertex.h>
#include <OpenMS/VISUAL/TOPPASToolVertex.h>
#include <OpenMS/VISUAL/TOPPASMergerVertex.h>
#include <OpenMS/VISUAL/TOPPASResources.h>
#include <OpenMS/VISUAL/DIALOGS/TOPPASIOMappingDialog.h>
#include <OpenMS/VISUAL/DIALOGS/TOPPASOutputFilesDialog.h>
#include <OpenMS/VISUAL/DIALOGS/TOPPASVertexNameDialog.h>
#include <OpenMS/CONCEPT/LogStream.h>
#include <OpenMS/CONCEPT/VersionInfo.h>
#include <OpenMS/DATASTRUCTURES/Map.h>
#include <OpenMS/SYSTEM/File.h>
#include <OpenMS/FORMAT/ParamXMLFile.h>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QSet>
#include <QtCore/QTextStream>
#include <QtGui/QMessageBox>
namespace OpenMS
{
void FakeProcess::start(const QString& /*program*/, const QStringList& /*arguments*/, OpenMode /*mode = ReadWrite*/)
{
// don't do anything...
//std::cout << "fake process " << program.toStdString() << " called.\n";
emit finished(0, QProcess::NormalExit);
}
TOPPASScene::TOPPASScene(QObject* parent, const QString& tmp_path, bool gui) :
QGraphicsScene(parent),
action_mode_(AM_NEW_EDGE),
vertices_(),
edges_(),
hover_edge_(0),
potential_target_(0),
file_name_(),
tmp_path_(tmp_path),
gui_(gui),
out_dir_(File::getUserDirectory().toQString()),
changed_(false),
running_(false),
user_specified_out_dir_(false),
clipboard_(0),
dry_run_(true),
threads_active_(0),
allowed_threads_(1),
resume_source_(0)
{
/* ATTENTION!
The following line is important! Without it, we get
hard-to-reproduce segmentation faults and
"pure virtual method calls" due to a bug in Qt!
(http://lists.trolltech.com/qt4-preview-feedback/2006-09/thread00124-0.html)
*/
setItemIndexMethod(QGraphicsScene::NoIndex);
}
TOPPASScene::~TOPPASScene()
{
// Delete all items in a controlled way:
foreach(TOPPASVertex * vertex, vertices_)
{
vertex->blockSignals(true); // do not propagate changes, remove output files, etc..
vertex->setSelected(true);
}
foreach(TOPPASEdge * edge, edges_)
{
edge->blockSignals(true); // do not propagate changes, remove output files, etc..
edge->setSelected(true);
}
removeSelected();
}
void TOPPASScene::setActionMode(ActionMode mode)
{
action_mode_ = mode;
}
TOPPASScene::ActionMode TOPPASScene::getActionMode()
{
return action_mode_;
}
TOPPASScene::VertexIterator TOPPASScene::verticesBegin()
{
return vertices_.begin();
}
TOPPASScene::VertexIterator TOPPASScene::verticesEnd()
{
return vertices_.end();
}
TOPPASScene::EdgeIterator TOPPASScene::edgesBegin()
{
return edges_.begin();
}
TOPPASScene::EdgeIterator TOPPASScene::edgesEnd()
{
return edges_.end();
}
void TOPPASScene::addVertex(TOPPASVertex* tv)
{
vertices_.push_back(tv);
addItem(tv);
}
void TOPPASScene::addEdge(TOPPASEdge* te)
{
edges_.push_back(te);
addItem(te);
}
void TOPPASScene::itemClicked()
{
}
void TOPPASScene::itemReleased()
{
TOPPASVertex* sender = qobject_cast<TOPPASVertex*>(QObject::sender());
if (!sender)
{
return;
}
// deselect all items except for the one under the cursor, but only if no multiple selection
if (selectedItems().size() <= 1)
{
unselectAll();
sender->setSelected(true);
}
snapToGrid();
}
void TOPPASScene::updateHoveringEdgePos(const QPointF& new_pos)
{
if (!hover_edge_)
{
return;
}
hover_edge_->setHoverPos(new_pos);
TOPPASVertex* target = getVertexAt_(new_pos);
if (target)
{
if (target != potential_target_)
{
potential_target_ = target;
bool ev = isEdgeAllowed_(hover_edge_->getSourceVertex(), target);
if (ev)
{
hover_edge_->setColor(Qt::darkGreen);
}
else
{
hover_edge_->setColor(Qt::red);
}
}
}
else
{
hover_edge_->setColor(Qt::black);
potential_target_ = 0;
}
}
void TOPPASScene::addHoveringEdge(const QPointF& pos)
{
TOPPASVertex* sender = qobject_cast<TOPPASVertex*>(QObject::sender());
if (!sender)
{
return;
}
TOPPASEdge* new_edge = new TOPPASEdge(sender, pos);
hover_edge_ = new_edge;
addEdge(new_edge);
}
void TOPPASScene::finishHoveringEdge()
{
TOPPASVertex* target = getVertexAt_(hover_edge_->endPos());
bool remove_edge = false;
if (target && target != hover_edge_->getSourceVertex())
{
hover_edge_->setTargetVertex(target);
TOPPASVertex* source = hover_edge_->getSourceVertex();
// check for parameter copy action (only if source is a tool node (--> edge is purple already, user expects this to happen))
TOPPASToolVertex* tv_source = qobject_cast<TOPPASToolVertex*>(source);
if (QApplication::keyboardModifiers() && Qt::ControlModifier && tv_source)
{
TOPPASToolVertex* tv_target = qobject_cast<TOPPASToolVertex*>(target);
if (!(tv_source && tv_target))
{
emit messageReady("Copying parameters is only allowed between Tool nodes! No copy was performed!\n");
}
else
{
emit messageReady("Transferring parameters between nodes ...\n");
Param from = tv_source->getParam();
Param to = tv_target->getParam();
Param to_old = to; // backup, to compare
std::stringstream ss;
Logger::LogStream my_log(new Logger::LogStreamBuf());
my_log.insert(ss);
to.update(from, false, my_log);
if (to == to_old)
{
my_log << "All parameters are up to date! Nothing happened!\n";
}
else // update the target parameters
{
tv_target->setParam(to);
changedParameter(TOPPASToolVertex::TOOL_READY); // show *, indicating changed params
}
//ss << "test test";
my_log << " ---------------------------------- " << std::endl; // this will cause a flush... removing this line might cause loss(!) of log content!
my_log.flush(); // bug! this sometimes does not cause the content to be flushed to the stringstream; the cache seems to be inactive as well. also std::endl does not help
emit messageReady(String(ss.str()).toQString());
//std::cerr << ss.str();
}
remove_edge = true;
}
else if (isEdgeAllowed_(hover_edge_->getSourceVertex(), target))
{
source->addOutEdge(hover_edge_);
target->addInEdge(hover_edge_);
hover_edge_->setColor(QColor(255, 165, 0));
connectEdgeSignals(hover_edge_);
TOPPASIOMappingDialog dialog(hover_edge_);
if (dialog.firstExec())
{
hover_edge_->emitChanged();
}
else
{
remove_edge = true;
}
}
else
{
remove_edge = true;
}
}
else
{
remove_edge = true;
}
if (remove_edge)
{
edges_.removeAll(hover_edge_);
removeItem(hover_edge_);
delete hover_edge_;
hover_edge_ = 0;
}
topoSort();
updateEdgeColors();
}
TOPPASVertex* TOPPASScene::getVertexAt_(const QPointF& pos)
{
QList<QGraphicsItem*> target_list = items(pos);
// return first item that is a vertex
TOPPASVertex* target = 0;
for (QList<QGraphicsItem*>::iterator it = target_list.begin(); it != target_list.end(); ++it)
{
target = dynamic_cast<TOPPASVertex*>(*it);
if (target)
{
break;
}
}
return target;
}
void TOPPASScene::copySelected()
{
TOPPASScene* tmp_scene = new TOPPASScene(0, this->getTempDir(), false);
Map<TOPPASVertex*, TOPPASVertex*> vertex_map;
foreach(TOPPASVertex * v, vertices_)
{
if (!v->isSelected())
{
continue;
}
TOPPASVertex* new_v = 0;
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(v);
if (iflv)
{
TOPPASInputFileListVertex* new_iflv = new TOPPASInputFileListVertex(*iflv);
new_v = new_iflv;
}
TOPPASOutputFileListVertex* oflv = qobject_cast<TOPPASOutputFileListVertex*>(v);
if (oflv)
{
TOPPASOutputFileListVertex* new_oflv = new TOPPASOutputFileListVertex(*oflv);
new_v = new_oflv;
}
TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(v);
if (tv)
{
TOPPASToolVertex* new_tv = new TOPPASToolVertex(*tv);
new_v = new_tv;
}
TOPPASMergerVertex* mv = qobject_cast<TOPPASMergerVertex*>(v);
if (mv)
{
TOPPASMergerVertex* new_mv = new TOPPASMergerVertex(*mv);
new_v = new_mv;
}
if (!new_v)
{
std::cerr << "Unknown vertex type! Aborting." << std::endl;
return;
}
vertex_map[v] = new_v;
tmp_scene->addVertex(new_v);
}
foreach(TOPPASEdge * e, edges_)
{
if (!e->isSelected())
{
continue;
}
//check if both source and target node were also selected (otherwise don't copy)
TOPPASVertex* old_source = e->getSourceVertex();
TOPPASVertex* old_target = e->getTargetVertex();
if (!(vertex_map.has(old_source) && vertex_map.has(old_target)))
{
continue;
}
TOPPASEdge* new_e = new TOPPASEdge();
TOPPASVertex* new_source = vertex_map[old_source];
TOPPASVertex* new_target = vertex_map[old_target];
new_e->setSourceVertex(new_source);
new_e->setTargetVertex(new_target);
new_e->setSourceOutParam(e->getSourceOutParam());
new_e->setTargetInParam(e->getTargetInParam());
new_source->addOutEdge(new_e);
new_target->addInEdge(new_e);
tmp_scene->addEdge(new_e);
}
emit selectionCopied(tmp_scene);
}
void TOPPASScene::paste(QPointF pos)
{
emit requestClipboardContent();
if (clipboard_ != 0)
{
include(clipboard_, pos);
}
}
void TOPPASScene::setClipboard(TOPPASScene* clipboard)
{
clipboard_ = clipboard;
}
void TOPPASScene::removeSelected()
{
QList<TOPPASVertex*> vertices_to_be_removed;
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
if ((*it)->isSelected())
{
// also select all in and out edges (will be deleted below)
for (TOPPASVertex::ConstEdgeIterator e_it = (*it)->inEdgesBegin(); e_it != (*it)->inEdgesEnd(); ++e_it)
{
(*e_it)->setSelected(true);
}
for (TOPPASVertex::ConstEdgeIterator e_it = (*it)->outEdgesBegin(); e_it != (*it)->outEdgesEnd(); ++e_it)
{
(*e_it)->setSelected(true);
}
vertices_to_be_removed.push_back(*it);
}
}
QList<TOPPASEdge*> edges_to_be_removed;
for (EdgeIterator it = edgesBegin(); it != edgesEnd(); ++it)
{
if ((*it)->isSelected())
{
edges_to_be_removed.push_back(*it);
}
}
TOPPASEdge* edge;
foreach(edge, edges_to_be_removed)
{
edges_.removeAll(edge);
removeItem(edge); // remove from scene
delete edge;
}
TOPPASVertex* vertex;
foreach(vertex, vertices_to_be_removed)
{
vertices_.removeAll(vertex);
removeItem(vertex); // remove from scene
delete vertex;
}
topoSort();
updateEdgeColors();
setChanged(true);
}
bool TOPPASScene::isEdgeAllowed_(TOPPASVertex* u, TOPPASVertex* v)
{
if (u == 0 ||
v == 0 ||
u == v ||
// edges leading to input files make no sense:
qobject_cast<TOPPASInputFileListVertex*>(v) ||
// neither do edges coming from output files:
qobject_cast<TOPPASOutputFileListVertex*>(u) ||
// nor edges from input to output without a tool in between:
(qobject_cast<TOPPASInputFileListVertex*>(u)
&& qobject_cast<TOPPASOutputFileListVertex*>(v)) ||
// nor multiple incoming edges for a single output file/list node
(qobject_cast<TOPPASOutputFileListVertex*>(v)
&& v->inEdgesBegin() != v->inEdgesEnd()) ||
// nor mergers connected directly to an output node
(qobject_cast<TOPPASMergerVertex*>(u)
&& qobject_cast<TOPPASOutputFileListVertex*>(v)))
{
return false;
}
// does this edge already exist?
for (TOPPASVertex::ConstEdgeIterator it = u->outEdgesBegin(); it != u->outEdgesEnd(); ++it)
{
if ((*it)->getTargetVertex() == v)
{
return false;
}
}
//insert edge between u and v for testing, is removed afterwards
TOPPASEdge* test_edge = new TOPPASEdge(u, QPointF());
test_edge->setTargetVertex(v);
u->addOutEdge(test_edge);
v->addInEdge(test_edge);
addEdge(test_edge);
bool graph_has_cycles = false;
//find back edges via DFS
foreach(TOPPASVertex * vertex, vertices_)
{
vertex->setDFSColor(TOPPASVertex::DFS_WHITE);
vertex->setDFSParent(0);
}
foreach(TOPPASVertex * vertex, vertices_)
{
if (vertex->getDFSColor() == TOPPASVertex::DFS_WHITE)
{
graph_has_cycles = dfsVisit_(vertex);
if (graph_has_cycles)
{
break;
}
}
}
// remove priorly inserted edge
edges_.removeAll(test_edge);
removeItem(test_edge);
delete test_edge;
return !graph_has_cycles;
}
void TOPPASScene::updateEdgeColors()
{
foreach(TOPPASEdge * edge, edges_)
{
edge->updateColor();
}
update(sceneRect());
}
bool TOPPASScene::dfsVisit_(TOPPASVertex* vertex)
{
vertex->setDFSColor(TOPPASVertex::DFS_GRAY);
for (TOPPASVertex::ConstEdgeIterator it = vertex->outEdgesBegin(); it != vertex->outEdgesEnd(); ++it)
{
TOPPASVertex* target = (*it)->getTargetVertex();
if (target->getDFSColor() == TOPPASVertex::DFS_WHITE)
{
target->setDFSParent(vertex);
if (dfsVisit_(target))
{
// back edge found
return true;
}
}
else if (target->getDFSColor() == TOPPASVertex::DFS_GRAY)
{
// back edge found
return true;
}
}
vertex->setDFSColor(TOPPASVertex::DFS_BLACK);
return false;
}
void TOPPASScene::resetDownstream(TOPPASVertex* vertex)
{
//reset all nodes
vertex->reset(true);
for (TOPPASVertex::ConstEdgeIterator it = vertex->outEdgesBegin(); it != vertex->outEdgesEnd(); ++it)
{
TOPPASVertex* target = (*it)->getTargetVertex();
this->resetDownstream(target);
}
}
void TOPPASScene::runPipeline()
{
error_occured_ = false;
resume_source_ = 0; // we are not resuming, so reset the resume node
// reset all nodes
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
(*it)->reset(true);
}
update(sceneRect());
// check if pipeline OK
if (!sanityCheck_(gui_))
{
if (!gui_)
emit pipelineExecutionFailed(); // the user cannot interact. End processing.
return;
}
// ask for output directory
if (!askForOutputDir(true))
{
return;
}
std::vector<bool> runs;
runs.push_back(true); // iterate through dry run and normal run
runs.push_back(false);
foreach(bool dry_run_state, runs)
{
this->dry_run_ = dry_run_state;
setPipelineRunning();
std::cout << "current dry-run state: " << dry_run_state << "\n";
//reset all nodes
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
(*it)->reset(true);
}
update(sceneRect());
//reset logfile
QFile logfile(out_dir_ + QDir::separator() + "TOPPAS.log");
if (logfile.exists())
logfile.remove();
//reset processes
topp_processes_queue_.clear();
// start at input nodes
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
if (error_occured_)
break; // someone raised an error
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(*it);
if (iflv)
{
iflv->run();
}
}
} // foreach
}
bool TOPPASScene::store(const String& file)
{
Param save_param;
save_param.setValue("info:version", DataValue(VersionInfo::getVersion()));
save_param.setValue("info:num_vertices", DataValue(vertices_.size()));
save_param.setValue("info:num_edges", DataValue(edges_.size()));
save_param.setValue("info:description", DataValue(String("<![CDATA[") + String(this->description_text_) + String("]]>")));
// store all vertices (together with all parameters)
foreach(TOPPASVertex * tv, vertices_)
{
String id(tv->getTopoNr() - 1);
// common for all vertices
save_param.setValue("vertices:" + id + ":recycle_output", DataValue(tv->isRecyclingEnabled() ? "true" : "false"));
// vertex subclasses
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(tv);
if (iflv)
{
// store file names relative to toppas file
QDir save_dir(File::path(file).toQString());
const QStringList& files_qt = iflv->getFileNames();
StringList files;
foreach(const QString &file_qt, files_qt)
{
files.push_back(save_dir.relativeFilePath(file_qt));
}
save_param.setValue("vertices:" + id + ":toppas_type", DataValue("input file list"));
save_param.setValue("vertices:" + id + ":file_names", DataValue(files));
save_param.setValue("vertices:" + id + ":x_pos", DataValue(tv->x()));
save_param.setValue("vertices:" + id + ":y_pos", DataValue(tv->y()));
continue;
}
TOPPASOutputFileListVertex* oflv = qobject_cast<TOPPASOutputFileListVertex*>(tv);
if (oflv)
{
save_param.setValue("vertices:" + id + ":toppas_type", DataValue("output file list"));
save_param.setValue("vertices:" + id + ":x_pos", DataValue(tv->x()));
save_param.setValue("vertices:" + id + ":y_pos", DataValue(tv->y()));
continue;
}
TOPPASToolVertex* ttv = qobject_cast<TOPPASToolVertex*>(tv);
if (ttv)
{
save_param.setValue("vertices:" + id + ":toppas_type", DataValue("tool"));
save_param.setValue("vertices:" + id + ":tool_name", DataValue(ttv->getName()));
save_param.setValue("vertices:" + id + ":tool_type", DataValue(ttv->getType()));
save_param.insert("vertices:" + id + ":parameters:", ttv->getParam());
save_param.setValue("vertices:" + id + ":x_pos", DataValue(tv->x()));
save_param.setValue("vertices:" + id + ":y_pos", DataValue(tv->y()));
continue;
}
TOPPASMergerVertex* mv = qobject_cast<TOPPASMergerVertex*>(tv);
if (mv)
{
save_param.setValue("vertices:" + id + ":toppas_type", DataValue("merger"));
save_param.setValue("vertices:" + id + ":x_pos", DataValue(tv->x()));
save_param.setValue("vertices:" + id + ":y_pos", DataValue(tv->y()));
save_param.setValue("vertices:" + id + ":round_based", DataValue(mv->roundBasedMode() ? "true" : "false"));
continue;
}
}
//store all edges
int counter = 0;
foreach(TOPPASEdge * te, edges_)
{
if (!((te->getEdgeStatus() == TOPPASEdge::ES_VALID) || (te->getEdgeStatus() == TOPPASEdge::ES_NOT_READY_YET)))
{ // do not allow to store an invalid pipeline, e.g., after a "param refresh()", since this might lead to inconsistencies when storing the edge mapping parameters (segfaults even).
// alternatively, we could discard invalid edges during loading, but then the user looses the information where edges were present (currently they become red)
return false;
}
if (!(te->getSourceVertex() && te->getTargetVertex()))
{
continue;
}
save_param.setValue("edges:" + String(counter) + ":source/target:", DataValue(String(te->getSourceVertex()->getTopoNr() - 1) + "/" + String(te->getTargetVertex()->getTopoNr() - 1)));
//save_param.setValue("edges:"+String(counter)+":source_out_param:", DataValue(te->getSourceOutParam()));
//save_param.setValue("edges:"+String(counter)+":target_in_param:", DataValue(te->getTargetInParam()));
QVector<TOPPASToolVertex::IOInfo> files;
String v = "__no_name__";
if (te->getSourceOutParam() >= 0)
{
TOPPASToolVertex* tv_src = qobject_cast<TOPPASToolVertex*>(te->getSourceVertex());
if (tv_src)
{
tv_src->getOutputParameters(files);
//std::cout << "#p: " << files.size() << " . " << te->getSourceOutParam() << "\n";
v = files[te->getSourceOutParam()].param_name;
}
}
save_param.setValue("edges:" + String(counter) + ":source_out_param:", DataValue(v));
v = "__no_name__";
if (te->getTargetInParam() >= 0)
{
TOPPASToolVertex* tv_src = qobject_cast<TOPPASToolVertex*>(te->getTargetVertex());
if (tv_src)
{
tv_src->getInputParameters(files);
//std::cout << "#p: " << files.size() << " . " << te->getTargetInParam() << "\n";
v = files[te->getTargetInParam()].param_name;
}
}
save_param.setValue("edges:" + String(counter) + ":target_in_param:", DataValue(v));
++counter;
}
//save file
ParamXMLFile paramFile;
paramFile.store(file, save_param);
setChanged(false);
file_name_ = file;
return true; // success
}
QString TOPPASScene::getDescription() const
{
return description_text_;
}
///
void TOPPASScene::setDescription(const QString& desc)
{
description_text_ = desc;
}
void TOPPASScene::load(const String& file)
{
file_name_ = file;
if (File::empty(file)) // allow opening of 0-byte files as pretend they are empty, new TOPPAS files
{
return;
}
Param load_param;
ParamXMLFile paramFile;
paramFile.load(file, load_param);
// check for TOPPAS file version. Deny loading if too old or too new
// get version of TOPPAS file
String file_version = "1.8.0"; // default (were we did not have the tag)
if (load_param.exists("info:version"))
{
file_version = load_param.getValue("info:version");
}
VersionInfo::VersionDetails v_file = VersionInfo::VersionDetails::create(file_version);
VersionInfo::VersionDetails v_this_low = VersionInfo::VersionDetails::create("1.9.0"); // last compatible TOPPAS file version
VersionInfo::VersionDetails v_this_high = VersionInfo::VersionDetails::create(VersionInfo::getVersion()); // last compatible TOPPAS file version
if (v_file < v_this_low)
{
if (!this->gui_)
{
std::cerr << "The TOPPAS file is too old! Please update the file using TOPPAS or INIUpdater!" << std::endl;
}
else if (this->gui_)
{
if (QMessageBox::warning(0, tr("Old TOPPAS file -- convert and override?"), tr("The TOPPAS file you downloaded was created with an old incompatible version of TOPPAS.\n"
"Shall we try to convert the file?! The original file will be overridden, but a backup file will be saved in the same directory.\n")
, QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
{
return;
}
// only update in GUI mode, as in non-GUI mode, we'd create infinite recursive calls when instantiating TOPPASScene in INIUpdater
#ifdef OPENMS_WINDOWSPLATFORM
String extra_quotes = "\""; // note: double quoting required for Windows, as outer quotes are required by cmd.exe (arghh)...
#else
String extra_quotes = "";
#endif
String cmd = extra_quotes + "\"" + File::findExecutable("INIUpdater") + "\" -in \"" + file + "\" -i " + extra_quotes;
std::cerr << cmd << "\n\n";
if (std::system(cmd.c_str()))
{
QMessageBox::warning(0, tr("INIUpdater failed"), tr("Updating using the INIUpdater tool failed. Please submit a bug report!\n"), QMessageBox::Ok);
return;
}
// reload updated file
ParamXMLFile paramFile;
paramFile.load(file, load_param);
}
}
else if (v_file > v_this_high)
{
if (this->gui_ && QMessageBox::warning(0, tr("TOPPAS file too new"), tr("The TOPPAS file you downloaded was created with a more recent version of TOPPAS. Shall we will try to open it?\n"
"If this fails, update to the new TOPPAS version.\n"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::No)
return;
}
Param vertices_param = load_param.copy("vertices:", true);
Param edges_param = load_param.copy("edges:", true);
bool pre_1_9_toppas = true;
if (load_param.exists("info:version"))
pre_1_9_toppas = false; // using param names instead of indices for connecting edges
if (load_param.exists("info:description"))
{
String text = String(load_param.getValue("info:description")).toQString();
text.substitute("<![CDATA[", "");
text.substitute("]]>", "");
description_text_ = text.trim().toQString();
}
String current_type, current_id;
TOPPASVertex* current_vertex = 0;
QVector<TOPPASVertex*> vertex_vector;
vertex_vector.resize((Size)(int)load_param.getValue("info:num_vertices"));
//load all vertices
for (Param::ParamIterator it = vertices_param.begin(); it != vertices_param.end(); ++it)
{
StringList substrings;
it.getName().split(':', substrings);
if (substrings.back() == "toppas_type") // next node (all nodes have a "toppas_type")
{
current_vertex = 0;
current_type = (it->value).toString();
current_id = substrings[0];
Int index = current_id.toInt();
if (current_type == "input file list")
{
StringList file_names = vertices_param.getValue(current_id + ":file_names");
QStringList file_names_qt;
for (StringList::const_iterator str_it = file_names.begin(); str_it != file_names.end(); ++str_it)
{
QString f = str_it->toQString();
if (QDir::isRelativePath(f)) // prepend path of toppas file to relative path of the input files
{
f = File::path(file).toQString() + "/" + f;
}
file_names_qt.push_back(QDir::cleanPath(f));
}
TOPPASInputFileListVertex* iflv = new TOPPASInputFileListVertex(file_names_qt);
current_vertex = iflv;
}
else if (current_type == "output file list")
{
TOPPASOutputFileListVertex* oflv = new TOPPASOutputFileListVertex();
connectOutputVertexSignals(oflv);
current_vertex = oflv;
}
else if (current_type == "tool")
{
String tool_name = vertices_param.getValue(current_id + ":tool_name");
String tool_type = vertices_param.getValue(current_id + ":tool_type");
Param param_param = vertices_param.copy(current_id + ":parameters:", true);
TOPPASToolVertex* tv = new TOPPASToolVertex(tool_name, tool_type);
tv->setParam(param_param);
connectToolVertexSignals(tv);
current_vertex = tv;
}
else if (current_type == "merger")
{
String rb = "true";
if (vertices_param.exists(current_id + ":round_based"))
{
rb = vertices_param.getValue(current_id + ":round_based");
}
TOPPASMergerVertex* mv = new TOPPASMergerVertex(rb == "true");
connectMergerVertexSignals(mv);
current_vertex = mv;
}
else
{
std::cerr << "Unknown vertex type '" << current_type << "'" << std::endl;
}
if (current_vertex)
{
float x = vertices_param.getValue(current_id + ":x_pos");
float y = vertices_param.getValue(current_id + ":y_pos");
current_vertex->setPos(QPointF(x, y));
// vertex parameters:
if (vertices_param.exists(current_id + ":recycle_output")) // only since TOPPAS 1.9, so does not need to exist
{
String recycle = vertices_param.getValue(current_id + ":recycle_output");
current_vertex->setRecycling(recycle == "true" ? true : false);
}
addVertex(current_vertex);
connectVertexSignals(current_vertex);
// temporarily block signals in order that the first topo sort does not set the changed flag
current_vertex->blockSignals(true);
if (index >= vertex_vector.size())
{
std::cerr << "Unexpected vertex ID!" << std::endl;
}
else
{
if (vertex_vector[index] != 0)
{
std::cerr << "Vertex occupied!" << std::endl;
}
else
{
vertex_vector[index] = current_vertex;
}
}
}
else
{
std::cerr << "Current vertex not available." << std::endl;
}
}
}
//load all edges
for (Param::ParamIterator it = edges_param.begin(); it != edges_param.end(); ++it)
{
const String& edge = (it->value).toString();
StringList edge_substrings;
edge.split('/', edge_substrings);
if (edge_substrings.size() != 2)
{
std::cerr << "Invalid edge format" << std::endl;
break;
}
Int index_1 = edge_substrings[0].toInt();
Int index_2 = edge_substrings[1].toInt();
if (index_1 >= vertex_vector.size() || index_2 >= vertex_vector.size())
{
std::cerr << "Invalid vertex index" << std::endl;
}
else
{
TOPPASVertex* tv_1 = vertex_vector[index_1];
TOPPASVertex* tv_2 = vertex_vector[index_2];
TOPPASEdge* edge = new TOPPASEdge();
edge->setSourceVertex(tv_1);
edge->setTargetVertex(tv_2);
tv_1->addOutEdge(edge);
tv_2->addInEdge(edge);
connectEdgeSignals(edge);
addEdge(edge);
String source_out_param = (++it)->value;
String target_in_param = (++it)->value;
if (pre_1_9_toppas) // just indices stored - no way we can check
{
edge->setSourceOutParam(source_out_param.toInt());
edge->setTargetInParam(target_in_param.toInt());
}
else
{
QVector<TOPPASToolVertex::IOInfo> files;
Int src_index = -1;
Int tgt_index = -1;
TOPPASToolVertex* tv_src = qobject_cast<TOPPASToolVertex*>(tv_1);
if (source_out_param != "__no_name__" && tv_src)
{
tv_src->getOutputParameters(files);
// search for the name
for (int i = 0; i < files.size(); ++i)
{
if (files[i].param_name == source_out_param)
{
src_index = i;
break;
}
}
if (src_index == -1)
logTOPPOutput(String("Could not find output parameter called '" + source_out_param + "'. Check edge!").toQString());
}
tv_src = qobject_cast<TOPPASToolVertex*>(tv_2);
if (target_in_param != "__no_name__" && tv_src)
{
tv_src->getInputParameters(files);
// search for the name
for (int i = 0; i < files.size(); ++i)
{
if (files[i].param_name == target_in_param)
{
tgt_index = i;
break;
}
}
if (tgt_index == -1)
logTOPPOutput(String("Could not find input parameter called '" + target_in_param + "'. Check edge!").toQString());
}
edge->setSourceOutParam(src_index);
edge->setTargetInParam(tgt_index);
}
}
}
if (pre_1_9_toppas) // just indices stored - no way we can check
{
logTOPPOutput(String("Your TOPPAS file was build with an old version of TOPPAS and is susceptible to errors when used with new versions of OpenMS. "
"Check every edge for correct input/output parameter names and store the workflow using the current version of TOPPAS "
"(e.g using the \"Save as ...\" functionality to make the workflow more robust to changes in future versions of TOPP tools!").toQString());
}
/*
if (!views().empty())
{
TOPPASWidget* tw = qobject_cast<TOPPASWidget*>(views().first());
if (tw)
{
QRectF scene_rect = itemsBoundingRect();
tw->fitInView(scene_rect, Qt::KeepAspectRatio);
tw->scale(0.75, 0.75);
setSceneRect(tw->mapToScene(tw->rect()).boundingRect());
}
}
*/
topoSort();
// unblock signals again
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
(*it)->blockSignals(false);
}
updateEdgeColors();
}
void TOPPASScene::include(TOPPASScene* tmp_scene, QPointF pos)
{
QRectF new_bounding_rect = tmp_scene->itemsBoundingRect();
QRectF our_bounding_rect = itemsBoundingRect();
qreal x_offset, y_offset;
if (pos == QPointF())
{
y_offset = our_bounding_rect.bottom() - new_bounding_rect.top() + 40.0;
x_offset = our_bounding_rect.left() - new_bounding_rect.left();
}
else
{
x_offset = pos.x() - new_bounding_rect.left();
y_offset = pos.y() - new_bounding_rect.top();
}
Map<TOPPASVertex*, TOPPASVertex*> vertex_map;
for (VertexIterator it = tmp_scene->verticesBegin(); it != tmp_scene->verticesEnd(); ++it)
{
TOPPASVertex* v = *it;
TOPPASVertex* new_v = 0;
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(v);
if (iflv)
{
TOPPASInputFileListVertex* new_iflv = new TOPPASInputFileListVertex(*iflv);
new_v = new_iflv;
}
TOPPASOutputFileListVertex* oflv = qobject_cast<TOPPASOutputFileListVertex*>(v);
if (oflv)
{
TOPPASOutputFileListVertex* new_oflv = new TOPPASOutputFileListVertex(*oflv);
new_v = new_oflv;
connectOutputVertexSignals(new_oflv);
}
TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(v);
if (tv)
{
TOPPASToolVertex* new_tv = new TOPPASToolVertex(*tv);
new_v = new_tv;
connectToolVertexSignals(new_tv);
}
TOPPASMergerVertex* mv = qobject_cast<TOPPASMergerVertex*>(v);
if (mv)
{
TOPPASMergerVertex* new_mv = new TOPPASMergerVertex(*mv);
new_v = new_mv;
connectMergerVertexSignals(new_mv);
}
if (!new_v)
{
std::cerr << "Unknown vertex type! Aborting." << std::endl;
return;
}
vertex_map[v] = new_v;
new_v->moveBy(x_offset, y_offset);
connectVertexSignals(new_v);
addVertex(new_v);
// temporarily block signals in order that the first topo sort does not set the changed flag
new_v->blockSignals(true);
}
// add all edges (are not copied by copy constructors of vertices)
for (EdgeIterator it = tmp_scene->edgesBegin(); it != tmp_scene->edgesEnd(); ++it)
{
TOPPASEdge* new_e = new TOPPASEdge();
TOPPASVertex* old_source = (*it)->getSourceVertex();
TOPPASVertex* old_target = (*it)->getTargetVertex();
TOPPASVertex* new_source = vertex_map[old_source];
TOPPASVertex* new_target = vertex_map[old_target];
new_e->setSourceVertex(new_source);
new_e->setTargetVertex(new_target);
new_e->setSourceOutParam((*it)->getSourceOutParam());
new_e->setTargetInParam((*it)->getTargetInParam());
new_source->addOutEdge(new_e);
new_target->addInEdge(new_e);
connectEdgeSignals(new_e);
addEdge(new_e);
}
if (!views().empty())
{
TOPPASWidget* tw = qobject_cast<TOPPASWidget*>(views().first());
if (tw)
{
QRectF scene_rect = itemsBoundingRect();
tw->fitInView(scene_rect, Qt::KeepAspectRatio);
tw->scale(0.75, 0.75);
setSceneRect(tw->mapToScene(tw->rect()).boundingRect());
}
}
topoSort();
// unblock signals again
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
(*it)->blockSignals(false);
}
updateEdgeColors();
}
const String& TOPPASScene::getSaveFileName()
{
return file_name_;
}
void TOPPASScene::setSaveFileName(const String& name)
{
file_name_ = name;
}
void TOPPASScene::unselectAll()
{
const QList<QGraphicsItem*>& all_items = items();
foreach(QGraphicsItem * item, all_items)
{
item->setSelected(false);
}
update(sceneRect());
}
void TOPPASScene::checkIfWeAreDone()
{
if (dry_run_)
return;
if (resume_source_)
{
switch (resume_source_->getSubtreeStatus())
{
case TOPPASVertex::TV_UNFINISHED:
return; // still processing
break;
case TOPPASVertex::TV_ALLFINISHED:
break; // ok, go to bottom
case TOPPASVertex::TV_UNFINISHED_INBRANCH:
setPipelineRunning(false);
emit pipelineErrorSlot("Resume cannot continue due to missing subtree.");
break;
}
}
else
{
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it) // check if all nodes are done
{
if (!(*it)->isFinished())
return;
}
}
setPipelineRunning(false);
emit entirePipelineFinished();
}
void TOPPASScene::pipelineErrorSlot(const QString /*msg*/)
{
error_occured_ = true;
setPipelineRunning(false);
abortPipeline();
emit pipelineExecutionFailed();
}
void TOPPASScene::writeToLogFile_(const QString& text)
{
QFile logfile(out_dir_ + QDir::separator() + "TOPPAS.log");
if (!logfile.open(QIODevice::Append | QIODevice::Text))
{
std::cerr << "Could not write to logfile '" << String(logfile.fileName()) << "'" << std::endl;
return;
}
QTextStream ts(&logfile);
ts << "\n" << text << "\n";
logfile.close();
}
void TOPPASScene::logTOPPOutput(const QString& out)
{
TOPPASToolVertex* sender = qobject_cast<TOPPASToolVertex*>(QObject::sender());
if (!sender)
{
//return;
}
String text = String(out);
if (!gui_)
{
std::cout << std::endl << text << std::endl;
}
emit messageReady(out); // let TOPPAS know about it
writeToLogFile_(text.toQString());
}
void TOPPASScene::logToolStarted()
{
TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
if (tv)
{
String text = tv->getName();
String type = tv->getType();
if (type != "")
{
text += " (" + type + ")";
}
text += " started. Processing ...";
if (!gui_)
{
std::cout << std::endl << text << std::endl;
}
writeToLogFile_(text.toQString());
}
}
void TOPPASScene::logToolFinished()
{
TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
if (tv)
{
String text = tv->getName();
String type = tv->getType();
if (type != "")
{
text += " (" + type + ")";
}
text += " finished!";
if (!gui_)
{
std::cout << std::endl << text << std::endl;
}
writeToLogFile_(text.toQString());
}
}
void TOPPASScene::logToolFailed()
{
TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
if (tv)
{
String text = tv->getName();
String type = tv->getType();
if (type != "")
{
text += " (" + type + ")";
}
text += " failed!";
if (!gui_)
{
std::cout << std::endl << text << std::endl;
}
writeToLogFile_(text.toQString());
}
}
void TOPPASScene::logToolCrashed()
{
TOPPASToolVertex* tv = qobject_cast<TOPPASToolVertex*>(QObject::sender());
if (tv)
{
String text = tv->getName();
String type = tv->getType();
if (type != "")
{
text += " (" + type + ")";
}
text += " crashed!";
if (!gui_)
{
std::cout << std::endl << text << std::endl;
}
writeToLogFile_(text.toQString());
}
}
void TOPPASScene::logOutputFileWritten(const String& file)
{
String text = "Output file '" + file + "' written.";
if (!gui_)
{
std::cout << std::endl << text << std::endl;
}
writeToLogFile_(text.toQString());
}
void TOPPASScene::topoSort()
{
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
(*it)->setTopoSortMarked(false);
}
bool topo_sort_finished = false;
UInt topo_counter = 1;
while (!topo_sort_finished)
{
bool some_vertex_not_finished = false;
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
if ((*it)->isTopoSortMarked())
{
continue;
}
some_vertex_not_finished = true;
bool has_predecessors = false;
for (TOPPASVertex::ConstEdgeIterator e_it = (*it)->inEdgesBegin(); e_it != (*it)->inEdgesEnd(); ++e_it)
{
TOPPASVertex* v = (*e_it)->getSourceVertex();
if (!(v->isTopoSortMarked()))
{
has_predecessors = true;
break;
}
}
if (!has_predecessors)
{
//update name of input node
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(*it);
if (iflv)
{
//check if key was modified by user. if yes, don't update it
QString old_topo_nr = QString::number((*it)->getTopoNr());
if (old_topo_nr == iflv->getKey() || iflv->getKey() == "")
{
iflv->setKey(QString::number(topo_counter));
}
}
(*it)->setTopoNr(topo_counter);
(*it)->setTopoSortMarked(true);
++topo_counter;
}
}
if (!some_vertex_not_finished)
{
topo_sort_finished = true;
}
}
update(sceneRect());
}
const QString& TOPPASScene::getOutDir()
{
return out_dir_;
}
const QString& TOPPASScene::getTempDir()
{
return tmp_path_;
}
void TOPPASScene::setOutDir(const QString& dir)
{
QDir d(dir);
out_dir_ = d.absolutePath();
user_specified_out_dir_ = true;
}
void TOPPASScene::moveSelectedItems(qreal dx, qreal dy)
{
setActionMode(AM_MOVE);
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
if (!(*it)->isSelected())
{
continue;
}
for (TOPPASVertex::ConstEdgeIterator e_it = (*it)->inEdgesBegin(); e_it != (*it)->inEdgesEnd(); ++e_it)
{
(*e_it)->prepareResize();
}
for (TOPPASVertex::ConstEdgeIterator e_it = (*it)->outEdgesBegin(); e_it != (*it)->outEdgesEnd(); ++e_it)
{
(*e_it)->prepareResize();
}
(*it)->moveBy(dx, dy);
}
setChanged(true);
}
void TOPPASScene::snapToGrid()
{
int grid_step = 20;
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
//only make selected nodes snap (those might have been moved)
if (!(*it)->isSelected())
{
continue;
}
int x_int = (int)((*it)->x());
int y_int = (int)((*it)->y());
int prev_grid_x = x_int - (x_int % grid_step);
int prev_grid_y = y_int - (y_int % grid_step);
int new_x = prev_grid_x;
int new_y = prev_grid_y;
if (x_int - prev_grid_x > (grid_step / 2))
{
new_x += grid_step;
}
if (y_int - prev_grid_y > (grid_step / 2))
{
new_y += grid_step;
}
(*it)->setPos(QPointF(new_x, new_y));
}
update(sceneRect());
}
bool TOPPASScene::saveIfChanged()
{
// Save changes
if (gui_ && changed_)
{
QString name = file_name_ == "" ? "Untitled" : File::basename(file_name_).toQString();
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(views().first(), "Save changes?",
"'" + name + "' has been modified.\n\nDo you want to save your changes?",
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)
{
emit saveMe();
if (changed_)
{
//user has not saved the file (aborted save dialog)
return false;
}
}
else if (ret == QMessageBox::Cancel)
{
return false;
}
}
return true;
}
void TOPPASScene::setChanged(bool b)
{
if (changed_ != b)
{
changed_ = b;
emit mainWindowNeedsUpdate();
}
}
bool TOPPASScene::wasChanged()
{
return changed_;
}
bool TOPPASScene::isPipelineRunning()
{
return running_;
}
void TOPPASScene::abortPipeline()
{
emit terminateCurrentPipeline();
resetProcessesQueue();
setPipelineRunning(false);
}
void TOPPASScene::resetProcessesQueue()
{
topp_processes_queue_.clear();
}
void TOPPASScene::setPipelineRunning(bool b)
{
running_ = b;
if (!running_) // whenever we stop the pipeline and user is not looking, the icon should flash
{
resume_source_ = 0;
QApplication::alert(0); // flash Taskbar || Dock
}
}
void TOPPASScene::processFinished()
{
--threads_active_;
// try to run next in line
runNextProcess();
}
bool TOPPASScene::askForOutputDir(bool always_ask)
{
if (gui_)
{
if (always_ask || !user_specified_out_dir_)
{
TOPPASOutputFilesDialog tofd(out_dir_, allowed_threads_);
if (tofd.exec())
{
setOutDir(tofd.getDirectory());
setAllowedThreads(tofd.getNumJobs());
}
else
{
return false;
}
}
}
return true;
}
void TOPPASScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
{
QPointF scene_pos = event->scenePos();
QGraphicsItem* clicked_item = itemAt(scene_pos);
QMenu menu;
if (clicked_item == 0)
{
QAction* new_action = menu.addAction("Paste");
emit requestClipboardContent();
if (clipboard_ == 0)
{
new_action->setEnabled(false);
}
}
else
{
if (!clicked_item->isSelected())
{
unselectAll();
}
clicked_item->setSelected(true);
// check which kinds of items are selected and display a context menu containing only actions compatible with all of them
bool found_tool = false;
bool found_input = false;
bool found_output = false;
bool found_merger = false;
bool found_edge = false;
bool disable_resume = false;
//bool disable_toppview = true;
foreach(TOPPASEdge * edge, edges_)
{
if (edge->isSelected())
{
found_edge = true;
break;
}
}
foreach(TOPPASVertex * tv, vertices_)
{
if (!tv->isSelected())
{
continue;
}
if (qobject_cast<TOPPASToolVertex*>(tv))
{
found_tool = true;
// all predecessor nodes finished successfully? if not, disable resuming
for (ConstEdgeIterator it = tv->inEdgesBegin(); it != tv->inEdgesEnd(); ++it)
{
TOPPASToolVertex* pred_ttv = qobject_cast<TOPPASToolVertex*>((*it)->getSourceVertex());
if (pred_ttv && (pred_ttv->getStatus() != TOPPASToolVertex::TOOL_SUCCESS))
{
disable_resume = true;
break;
}
}
continue;
}
if (qobject_cast<TOPPASInputFileListVertex*>(tv))
{
found_input = true;
continue;
}
if (qobject_cast<TOPPASOutputFileListVertex*>(tv))
{
found_output = true;
continue;
}
if (qobject_cast<TOPPASMergerVertex*>(tv))
{
found_merger = true;
continue;
}
}
if (this->isPipelineRunning())
disable_resume = true;
QSet<QString> action;
if (found_tool)
{
action.insert("Edit parameters");
action.insert("Resume");
action.insert("Open files in TOPPView");
action.insert("Open containing folder");
//action.insert("Toggle breakpoint");
}
if (found_input)
{
action.insert("Change name");
action.insert("Change files");
action.insert("Open files in TOPPView");
action.insert("Open containing folder");
}
if (found_output)
{
action.insert("Open files in TOPPView");
action.insert("Open containing folder");
}
if (found_edge)
{
action.insert("Edit I/O mapping");
}
if (found_input || found_tool || found_merger)
{
action.insert("Toggle recycling mode");
}
QList<QSet<QString> > all_actions;
all_actions.push_back(action);
QSet<QString> supported_actions_set = all_actions.first();
foreach(const QSet<QString>&action_set, all_actions)
{
supported_actions_set.intersect(action_set);
}
QList<QString> supported_actions = supported_actions_set.toList();
supported_actions << "Copy" << "Cut" << "Remove";
foreach(const QString &supported_action, supported_actions)
{
QAction* new_action = menu.addAction(supported_action);
if (supported_action == "Resume" && disable_resume)
{
new_action->setEnabled(false);
}
}
}
// ------ execute action ------
QAction* selected_action = menu.exec(event->screenPos());
if (selected_action)
{
QString text = selected_action->text();
if (text == "Remove")
{
removeSelected();
event->accept();
return;
}
if (text == "Copy")
{
copySelected();
event->accept();
return;
}
if (text == "Cut")
{
copySelected();
removeSelected();
event->accept();
return;
}
if (text == "Paste")
{
paste(event->scenePos());
event->accept();
return;
}
foreach(QGraphicsItem * gi, selectedItems())
{
if (text == "Toggle recycling mode")
{
TOPPASVertex* tv = dynamic_cast<TOPPASVertex*>(gi);
if (tv)
{
tv->invertRecylingMode();
tv->update(tv->boundingRect());
}
continue;
}
TOPPASEdge* edge = dynamic_cast<TOPPASEdge*>(gi);
if (edge)
{
if (text == "Edit I/O mapping")
{
edge->showIOMappingDialog();
}
continue;
}
TOPPASToolVertex* ttv = dynamic_cast<TOPPASToolVertex*>(gi);
if (ttv)
{
if (text == "Edit parameters")
{
ttv->editParam();
}
else if (text == "Resume")
{
if (askForOutputDir(false))
{
setPipelineRunning();
resume_source_ = ttv;
resetDownstream(ttv);
ttv->run();
}
}
else if (text == "Toggle breakpoint")
{
ttv->toggleBreakpoint();
ttv->update(ttv->boundingRect());
}
else if (text == "Open files in TOPPView")
{
QStringList all_out_files = ttv->getFileNames();
emit openInTOPPView(all_out_files);
}
else if (text == "Open containing folder")
{
ttv->openContainingFolder();
}
continue;
}
TOPPASInputFileListVertex* ifv = dynamic_cast<TOPPASInputFileListVertex*>(gi);
if (ifv)
{
if (text == "Open files in TOPPView")
{
QStringList in_files = ifv->getFileNames();
emit openInTOPPView(in_files);
}
else if (text == "Open containing folder")
{
ifv->openContainingFolder();
}
else if (text == "Change files")
{
ifv->showFilesDialog();
}
else if (text == "Change name")
{
TOPPASVertexNameDialog dlg(ifv->getKey());
if (dlg.exec())
{
ifv->setKey(dlg.getName());
}
}
continue;
}
TOPPASOutputFileListVertex* ofv = dynamic_cast<TOPPASOutputFileListVertex*>(gi);
if (ofv)
{
if (text == "Open files in TOPPView")
{
QStringList out_files = ofv->getFileNames();
emit openInTOPPView(out_files);
}
else if (text == "Open containing folder")
{
ofv->openContainingFolder();
}
continue;
}
}
}
event->accept();
}
void TOPPASScene::enqueueProcess(const TOPPProcess& process)
{
topp_processes_queue_ << process;
}
void TOPPASScene::runNextProcess()
{
static bool used = false;
if (used)
return;
used = true;
while (!topp_processes_queue_.empty() && threads_active_ < allowed_threads_)
{
++threads_active_; // will be decreased, once the tool finishes
TOPPProcess tp = topp_processes_queue_.first();
topp_processes_queue_.pop_front();
FakeProcess* p = qobject_cast<FakeProcess*>(tp.proc);
if (p)
{
p->start(tp.command, tp.args);
}
else
{
tp.tv->emitToolStarted();
tp.proc->start(tp.command, tp.args);
}
}
used = false;
checkIfWeAreDone();
}
bool TOPPASScene::sanityCheck_(bool allowUserOverride)
{
QStringList strange_vertices;
// ----- are there any input nodes and are files specified? ----
/// check if we have any input nodes
QVector<TOPPASInputFileListVertex*> input_nodes;
foreach(TOPPASVertex * tv, vertices_)
{
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(tv);
if (iflv)
{
input_nodes.push_back(iflv);
}
}
if (input_nodes.empty())
{
if (allowUserOverride)
{
QMessageBox::warning(0, "No input files", "The pipeline does not contain any input file nodes!");
}
else
{
std::cerr << "The pipeline does not contain any input file nodes!" << std::endl;
}
return false;
}
/// warn about empty input nodes
foreach(TOPPASInputFileListVertex * iflv, input_nodes)
{
if ((iflv->outgoingEdgesCount() > 0) && (iflv->getFileNames().empty())) // allow disconnected input node with empty file list
{
strange_vertices.push_back(QString::number(iflv->getTopoNr()));
}
}
if (!strange_vertices.empty())
{
if (allowUserOverride)
{
QMessageBox::warning(views().first(), "Empty input file nodes",
QString("Node")
+ (strange_vertices.size() > 1 ? "s " : " ")
+ strange_vertices.join(", ")
+ (strange_vertices.size() > 1 ? " have " : " has ")
+ " an empty input file list!");
}
else
{
std::cerr << "Pipeline contains input file nodes without specified files!" << std::endl;
}
return false;
}
/// check if input files exist
strange_vertices.clear();
foreach(TOPPASInputFileListVertex * iflv, input_nodes)
{
if ((iflv->outgoingEdgesCount() > 0) && (!iflv->fileNamesValid())) // allow disconnected input node with invalid files
{
strange_vertices.push_back(QString::number(iflv->getTopoNr()));
}
}
if (!strange_vertices.empty())
{
if (allowUserOverride)
{
QMessageBox::warning(views().first(), "Input file names wrong",
QString("Node")
+ (strange_vertices.size() > 1 ? "s " : " ")
+ strange_vertices.join(", ")
+ (strange_vertices.size() > 1 ? " have " : " has ")
+ " invalid (non-existing) input files!");
}
else
{
std::cerr << "Pipeline contains input file nodes with invalid (non-existing) input files!" << std::endl;
}
return false;
}
// ----- are there nodes without parents (besides input nodes)? -----
strange_vertices.clear();
foreach(TOPPASVertex * tv, vertices_)
{
if (qobject_cast<TOPPASInputFileListVertex*>(tv)) // input nodes don't need a parent
{
continue;
}
if (tv->inEdgesBegin() == tv->inEdgesEnd())
{
strange_vertices << QString::number(tv->getTopoNr());
tv->markUnreachable();
}
}
if (!strange_vertices.empty())
{
if (allowUserOverride)
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(views().first(), "Nodes without incoming edges",
QString("Node")
+ (strange_vertices.size() > 1 ? "s " : " ")
+ strange_vertices.join(", ")
+ " will never be reached.\n\nDo you still want to run the pipeline?",
QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No)
{
return false;
}
}
//else
//{
// assume the pipeline was tested in the gui, continue
//}
}
// ----- are there nodes without children (besides output nodes)? -----
strange_vertices.clear();
foreach(TOPPASVertex * tv, vertices_)
{
if (qobject_cast<TOPPASOutputFileListVertex*>(tv))
{
continue;
}
if (tv->outEdgesBegin() == tv->outEdgesEnd())
{
strange_vertices << QString::number(tv->getTopoNr());
}
}
if (!strange_vertices.empty())
{
if (allowUserOverride)
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(views().first(), "Nodes without outgoing edges",
QString("Node")
+ (strange_vertices.size() > 1 ? "s " : " ")
+ strange_vertices.join(", ")
+ (strange_vertices.size() > 1 ? " have " : " has ")
+ "no outgoing edges.\n\nDo you still want to run the pipeline?",
QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No)
{
return false;
}
}
//else
//{
// assume the pipeline was tested in the gui, continue
//}
}
// check edges
bool edges_ok = true;
foreach(TOPPASEdge * edge, edges_)
{
if (edge->getEdgeStatus() != TOPPASEdge::ES_VALID)
{
edges_ok = false;
break;
}
}
if (!edges_ok)
{
if (allowUserOverride)
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(views().first(), "Invalid edges detected", "Invalid edges detected. Do you still want to run the pipeline?",
QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::No)
{
return false;
}
} else
{ // do not allow silent execution with invalid edges
return false;
}
}
return true;
}
void TOPPASScene::connectVertexSignals(TOPPASVertex* tv)
{
connect(tv, SIGNAL(clicked()), this, SLOT(itemClicked()));
connect(tv, SIGNAL(released()), this, SLOT(itemReleased()));
connect(tv, SIGNAL(hoveringEdgePosChanged(const QPointF &)), this, SLOT(updateHoveringEdgePos(const QPointF &)));
connect(tv, SIGNAL(newHoveringEdge(const QPointF &)), this, SLOT(addHoveringEdge(const QPointF &)));
connect(tv, SIGNAL(finishHoveringEdge()), this, SLOT(finishHoveringEdge()));
connect(tv, SIGNAL(itemDragged(qreal, qreal)), this, SLOT(moveSelectedItems(qreal, qreal)));
connect(tv, SIGNAL(parameterChanged(const bool)), this, SLOT(changedParameter(const bool)));
}
void TOPPASScene::connectToolVertexSignals(TOPPASToolVertex* ttv)
{
connect(ttv, SIGNAL(toppOutputReady(const QString &)), this, SLOT(logTOPPOutput(const QString &)));
connect(ttv, SIGNAL(toolStarted()), this, SLOT(logToolStarted()));
connect(ttv, SIGNAL(toolFinished()), this, SLOT(logToolFinished()));
connect(ttv, SIGNAL(toolFailed()), this, SLOT(logToolFailed()));
connect(ttv, SIGNAL(toolCrashed()), this, SLOT(logToolCrashed()));
connect(ttv, SIGNAL(toolFailed(const QString &)), this, SLOT(pipelineErrorSlot(QString)));
connect(ttv, SIGNAL(toolCrashed()), this, SLOT(pipelineErrorSlot()));
connect(ttv, SIGNAL(somethingHasChanged()), this, SLOT(abortPipeline()));
}
void TOPPASScene::connectMergerVertexSignals(TOPPASMergerVertex* tmv)
{
connect(tmv, SIGNAL(mergeFailed(QString)), this, SLOT(pipelineErrorSlot(QString)));
connect(tmv, SIGNAL(somethingHasChanged()), this, SLOT(abortPipeline()));
}
void TOPPASScene::connectOutputVertexSignals(TOPPASOutputFileListVertex* oflv)
{
connect(oflv, SIGNAL(outputFileWritten(const String &)), this, SLOT(logOutputFileWritten(const String &)));
}
void TOPPASScene::connectEdgeSignals(TOPPASEdge* e)
{
TOPPASVertex* source = e->getSourceVertex();
TOPPASVertex* target = e->getTargetVertex();
connect(e, SIGNAL(somethingHasChanged()), source, SLOT(outEdgeHasChanged()));
connect(e, SIGNAL(somethingHasChanged()), target, SLOT(inEdgeHasChanged()));
connect(e, SIGNAL(somethingHasChanged()), this, SLOT(abortPipeline()));
}
void TOPPASScene::changedParameter(const bool invalidates_running_pipeline)
{
if (invalidates_running_pipeline) // abort only if TTV's new parameters invalidate the results
{
abortPipeline();
}
setChanged(true); // to allow "Store" of pipeline
resetDownstream(dynamic_cast<TOPPASVertex*>(sender()));
}
void TOPPASScene::loadResources(const TOPPASResources& resources)
{
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(*it);
if (iflv)
{
const QString& key = iflv->getKey();
const QList<TOPPASResource>& resource_list = resources.get(key);
QStringList files;
foreach(const TOPPASResource &res, resource_list)
{
files << res.getLocalFile();
}
iflv->setFilenames(files);
}
}
}
void TOPPASScene::createResources(TOPPASResources& resources)
{
resources.clear();
QStringList used_keys;
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(*it);
if (iflv)
{
QString key = iflv->getKey();
if (used_keys.contains(key))
{
if (gui_)
{
QMessageBox::warning(0, "Non-unique input node names", "Some of the input nodes have the same names. Cannot create resource file.");
}
else
{
std::cerr << "Some of the input nodes have the same names. Cannot create resource file." << std::endl;
}
return;
}
used_keys << key;
QList<TOPPASResource> resource_list;
QStringList files = iflv->getFileNames();
foreach(const QString &file, files)
{
resource_list << TOPPASResource(file);
}
resources.add(key, resource_list);
}
}
}
TOPPASScene::RefreshStatus TOPPASScene::refreshParameters()
{
bool sane_before = sanityCheck_(false);
bool change = false;
for (VertexIterator it = verticesBegin(); it != verticesEnd(); ++it)
{
TOPPASToolVertex* ttv = qobject_cast<TOPPASToolVertex*>(*it);
if (ttv && ttv->refreshParameters())
{
change = true;
}
}
TOPPASScene::RefreshStatus result;
if (!change) result = ST_REFRESH_NOCHANGE;
else if (!sanityCheck_(false))
{
if (sane_before) result = ST_REFRESH_CHANGEINVALID;
else result = ST_REFRESH_REMAINSINVALID;
}
else result = ST_REFRESH_CHANGED;
return result;
}
void TOPPASScene::setAllowedThreads(int num_jobs)
{
if (num_jobs < 1)
return;
allowed_threads_ = num_jobs;
}
bool TOPPASScene::isDryRun() const
{
return dry_run_;
}
void TOPPASScene::quitWithError()
{
exit(1);
}
TOPPASEdge* TOPPASScene::getHoveringEdge()
{
return hover_edge_;
}
} //namespace OpenMS
|