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 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347
|
/* MainWindow for StellarSolver Tester Application, developed by Robert Lancaster, 2020
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
*/
//Qt Includes
#include <QUuid>
#include <QDebug>
#include <QImageReader>
#include <QTableWidgetItem>
#include <QPainter>
#include <QDesktopServices>
#include <QShortcut>
#include <QThread>
#include <QInputDialog>
#include <QtConcurrent>
#include <QToolTip>
#include <QtGlobal>
#include <QMessageBox>
//System Includes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#ifndef _MSC_VER
#include <sys/time.h>
#include <libgen.h>
#include <getopt.h>
#include <dirent.h>
#endif
#include <time.h>
#include <assert.h>
//Project Includes
#include "version.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow() :
QMainWindow(),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->show();
//The Options at the top of the Window
connect(ui->ImageLoad, &QAbstractButton::clicked, this, &MainWindow::imageLoad );
ui->ImageLoad->setToolTip("Loads an Image into the Viewer");
connect(ui->ImageSave, &QAbstractButton::clicked, this, &MainWindow::imageSave );
ui->ImageSave->setToolTip("Saves the Image to a FITS file. If the image has been solved, it saves that too.");
connect(ui->zoomIn, &QAbstractButton::clicked, this, &MainWindow::zoomIn );
ui->zoomIn->setToolTip("Zooms In on the Image");
connect(ui->zoomOut, &QAbstractButton::clicked, this, &MainWindow::zoomOut );
ui->zoomOut->setToolTip("Zooms Out on the Image");
connect(ui->AutoScale, &QAbstractButton::clicked, this, &MainWindow::autoScale );
ui->AutoScale->setToolTip("Rescales the image based on the available space");
// Keyboard shortcuts -- if you add more, remember to add to the helpPopup() method below.
QShortcut *s = new QShortcut(QKeySequence(QKeySequence::ZoomIn), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::zoomIn);
s = new QShortcut(QKeySequence(QKeySequence::ZoomOut), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::zoomOut);
s = new QShortcut(QKeySequence(tr("Ctrl+0")), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::autoScale);
s = new QShortcut(QKeySequence(QKeySequence::Open), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::imageLoad );
s = new QShortcut(QKeySequence(QKeySequence::MoveToNextChar), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::panRight);
s = new QShortcut(QKeySequence(QKeySequence::MoveToPreviousChar), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::panLeft);
s = new QShortcut(QKeySequence(QKeySequence::MoveToNextLine), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::panDown);
s = new QShortcut(QKeySequence(QKeySequence::MoveToPreviousLine), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::panUp);
s = new QShortcut(QKeySequence(QKeySequence::Quit), ui->Image);
connect(s, &QShortcut::activated, this, &QCoreApplication::quit);
s = new QShortcut(QKeySequence(tr("Ctrl+l")), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::toggleLogDisplay);
s = new QShortcut(QKeySequence(QKeySequence::FullScreen), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::toggleFullScreen);
s = new QShortcut(QKeySequence(QKeySequence::HelpContents), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::helpPopup);
s = new QShortcut(QKeySequence("?"), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::helpPopup);
s = new QShortcut(QKeySequence("h"), ui->Image);
connect(s, &QShortcut::activated, this, &MainWindow::helpPopup);
//The Options at the bottom of the Window
ui->trials->setToolTip("The number of times to Star Extract or Solve to get an average time that it takes.");
connect(ui->startExtraction, &QAbstractButton::clicked, this, &MainWindow::extractButtonClicked );
connect(ui->startSolving, &QAbstractButton::clicked, this, &MainWindow::solveButtonClicked );
connect(ui->editExtractorProfile, &QAbstractButton::clicked, this, [this]()
{
ui->optionsProfile->setCurrentIndex(ui->extractionProfile->currentIndex());
ui->optionsTab->setCurrentIndex(1);
ui->extractionProfile->setCurrentIndex(0);
});
connect(ui->editSolverProfile, &QAbstractButton::clicked, this, [this]()
{
ui->optionsProfile->setCurrentIndex(ui->solverProfile->currentIndex());
ui->optionsTab->setCurrentIndex(1);
ui->solverProfile->setCurrentIndex(0);
});
connect(ui->Abort, &QAbstractButton::clicked, this, &MainWindow::abort );
ui->Abort->setToolTip("Aborts the current process if one is running.");
connect(ui->ClearStars, &QAbstractButton::clicked, this, &MainWindow::clearStars );
ui->ClearStars->setToolTip("Clears the star table and the stars from the image");
connect(ui->ClearResults, &QAbstractButton::clicked, this, &MainWindow::clearResults );
ui->ClearResults->setToolTip("Clears the Results Table");
//The Options for the StellarSolver Options
ui->optionsProfile->setToolTip("The Options Profile currently in the options box. Selecting a profile will reset all the Star Extractor and Solver settings to that profile.");
connect(ui->optionsProfile, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::loadOptionsProfile);
ui->addOptionProfile->setToolTip("Adds the current options in the left option pane to a new profile");
connect(ui->addOptionProfile, &QAbstractButton::clicked, this, [this]()
{
bool ok;
QString name = QInputDialog::getText(this, tr("New Options Profile"),
tr("What would you like your profile to be called?"), QLineEdit::Normal,
"", &ok);
if (ok && !name.isEmpty())
{
optionsAreSaved = true;
SSolver::Parameters params = getSettingsFromUI();
params.listName = name;
ui->optionsProfile->setCurrentIndex(0); //So we don't trigger any loading of any other profiles
optionsList.append(params);
ui->optionsProfile->addItem(name);
ui->extractionProfile->addItem(name);
ui->solverProfile->addItem(name);
ui->optionsProfile->setCurrentText(name);
}
});
ui->removeOptionProfile->setToolTip("Removes the selected profile from the list of profiles");
connect(ui->removeOptionProfile, &QAbstractButton::clicked, this, [this]()
{
int item = ui->optionsProfile->currentIndex();
if(item < 1)
{
QMessageBox::critical(this, "Message", "You can't delete this profile");
return;
}
ui->optionsProfile->setCurrentIndex(0); //So we don't trigger any loading of any other profiles
ui->optionsProfile->removeItem(item);
ui->extractionProfile->removeItem(item);
ui->solverProfile->removeItem(item);
optionsList.removeAt(item - 1);
});
ui->saveSettings->setToolTip("Saves a file with Options Profiles to a desired location");
connect(ui->saveSettings, &QPushButton::clicked, this, &MainWindow::saveOptionsProfiles);
ui->loadSettings->setToolTip("Loads a file with Options Profiles from a saved location");
connect(ui->loadSettings, &QPushButton::clicked, this, &MainWindow::loadOptionsProfiles);
QWidget *extractorOptions = ui->optionsBox->widget(0);
QWidget *starFilterOptions = ui->optionsBox->widget(1);
QWidget *astrometryOptions = ui->optionsBox->widget(2);
QList<QLineEdit *> lines;
lines = extractorOptions->findChildren<QLineEdit *>();
lines.append(starFilterOptions->findChildren<QLineEdit *>());
lines.append(astrometryOptions->findChildren<QLineEdit *>());
foreach(QLineEdit *line, lines)
connect(line, &QLineEdit::textEdited, this, &MainWindow::settingJustChanged);
QList<QCheckBox *> checks;
checks = extractorOptions->findChildren<QCheckBox *>();
checks.append(starFilterOptions->findChildren<QCheckBox *>());
checks.append(astrometryOptions->findChildren<QCheckBox *>());
foreach(QCheckBox *check, checks)
connect(check, &QCheckBox::stateChanged, this, &MainWindow::settingJustChanged);
QList<QComboBox *> combos;
combos = extractorOptions->findChildren<QComboBox *>();
combos.append(starFilterOptions->findChildren<QComboBox *>());
combos.append(astrometryOptions->findChildren<QComboBox *>());
foreach(QComboBox *combo, combos)
connect(combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::settingJustChanged);
QList<QSpinBox *> spins;
spins = extractorOptions->findChildren<QSpinBox *>();
spins.append(starFilterOptions->findChildren<QSpinBox *>());
spins.append(astrometryOptions->findChildren<QSpinBox *>());
foreach(QSpinBox *spin, spins)
connect(spin, QOverload<int>::of(&QSpinBox::valueChanged), this, &MainWindow::settingJustChanged);
//Hides the panels into the sides and bottom
ui->vertSplitter->setSizes(QList<int>() << ui->vertSplitter->height() << 0 );
ui->horSplitter->setSizes(QList<int>() << 100 << ui->horSplitter->width() / 2 << 0 );
//Settings for the External Star Extractor and Solver
ui->configFilePath->setToolTip("The path to the Astrometry.cfg file used by astrometry.net for configuration.");
ui->sextractorPath->setToolTip("The path to the external SExtractor executable");
ui->solverPath->setToolTip("The path to the external Astrometry.net solve-field executable");
ui->astapPath->setToolTip("The path to the external ASTAP executable");
ui->watneyPath->setToolTip("The path to the external Watney Astrometry Solver executable");
ui->basePath->setToolTip("The base path where SExtractor and astrometry.net temporary files are saved on your computer");
ui->openTemp->setToolTip("Opens the directory (above) to where the external solvers save their files");
ui->wcsPath->setToolTip("The path to wcsinfo for the external Astrometry.net");
ui->cleanupTemp->setToolTip("This option allows the program to clean up temporary files created when running various processes");
ui->generateAstrometryConfig->setToolTip("Determines whether to generate an astrometry.cfg file based on the options in the options panel or to use the external config file above.");
ui->onlineServer->setToolTip("This is the server that StellarSolver will use for the Online solves. This will typically be nova.astrometry.net, but it could also be an ANSVR server or a custom one.");
ui->apiKey->setToolTip("This is the api key used for astrometry.net online. You can enter your own and then have access to your solves later.");
connect(ui->openTemp, &QAbstractButton::clicked, this, [this]()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(ui->basePath->text()));
});
//StellarSolver Tester Options
connect(ui->showStars, &QAbstractButton::clicked, this, &MainWindow::updateImage );
ui->setSubFrame->setToolTip("Sets or clears the Subframe for Star Extraction if desired");
connect(ui->setSubFrame, &QAbstractButton::clicked, this, &MainWindow::setSubframe );
connect(ui->setPathsAutomatically, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int num)
{
ExternalProgramPaths paths = StellarSolver::getDefaultExternalPaths((SSolver::ComputerSystemType) num);
ui->sextractorPath->setText(paths.sextractorBinaryPath);
ui->configFilePath->setText(paths.confPath);
ui->solverPath->setText(paths.solverPath);
ui->astapPath->setText(paths.astapBinaryPath);
ui->watneyPath->setText(paths.watneyBinaryPath);
ui->wcsPath->setText(paths.wcsPath);
});
ui->setPathsAutomatically->setToolTip("This allows you to select the default values of typical configurations of paths to external files/programs on different systems from a dropdown");
//Star Extractor Settings
ui->apertureShape->setToolTip("This selects whether to instruct the Star Extractor to use Ellipses or Circles for flux calculations");
ui->kron_fact->setToolTip("This sets the Kron Factor for use with the kron radius for flux calculations.");
ui->subpix->setToolTip("The subpix setting. The instructions say to make it 5");
ui->r_min->setToolTip("The minimum radius for stars for flux calculations.");
//no inflags???;
ui->magzero->setToolTip("This is the 'zero' magnitude used for settting the magnitude scale for the stars in the image during star extraction.");
ui->minarea->setToolTip("This is the minimum area in pixels for a star detection, smaller stars are ignored.");
ui->thresh_multiple->setToolTip("Add the multiple times the rms background level to the detection threshold.");
ui->thresh_offset->setToolTip("Add this offset to the detection threshold");
ui->deblend_thresh->setToolTip("The number of thresholds the intensity range is divided up into");
ui->deblend_contrast->setToolTip("The percentage of flux a separate peak must # have to be considered a separate object");
ui->cleanCheckBox->setToolTip("Attempts to 'clean' the image to remove artifacts caused by bright objects");
ui->clean_param->setToolTip("The cleaning parameter, not sure what it does.");
//The Convolution Filter Parameters
ui->convFilterType->setToolTip("This allows you to choose the type of Convolution Filter Generated");
ui->fwhm->setToolTip("This allows you to set the FWHM in Pixels for Convolution Filter Generation");
ui->showConv->setToolTip("Loads the convolution filter into a window for viewing");
ui->partition->setToolTip("Whether or not to partition the image during SEP operations for Internal SEP. This can greatly speed up star extraction, but at the cost of possibly missing some objects. For solving, Focusing, and guiding operations, this doesn't matter, but for doing science, you might want to turn it off.");
connect(ui->showConv,&QPushButton::clicked,this,[this](){
if(!convInspector)
{
convInspector = new QDialog(this);
convInspector->setWindowTitle("Convolution Filter Inspector");
convInspector->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
convTable = new QTableWidget(this);
QGridLayout *layout = new QGridLayout(this);
convTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
convTable->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
convTable->horizontalHeader()->hide();
convTable->verticalHeader()->hide();
convInspector->setLayout(layout);
layout->addWidget(convTable);
}
convInspector->show();
reloadConvTable();
});
connect(ui->convFilterType,QOverload<int>::of(&QComboBox::currentIndexChanged),this, &MainWindow::reloadConvTable);
connect(ui->fwhm,QOverload<int>::of(&QSpinBox::valueChanged),this, &MainWindow::reloadConvTable);
//Star Filter Settings
connect(ui->resortQT, &QCheckBox::stateChanged, this, [this]()
{
ui->resort->setChecked(ui->resortQT->isChecked());
});
ui->resortQT->setToolTip("This resorts the stars based on magnitude. It MUST be checked for the next couple of filters to be enabled.");
ui->maxSize->setToolTip("This is the maximum diameter of stars to include in pixels");
ui->minSize->setToolTip("This is the minimum diameter of stars to include in pixels");
ui->maxEllipse->setToolTip("Stars are typically round, this filter divides stars' semi major and minor axes and rejects stars with distorted shapes greater than this number (1 is perfectly round)");
ui->initialKeep->setToolTip("Keep just this number of stars in the list based upon star size. They will be the biggest in the list. If there are less than this number, they will all be kept. This filter is primarily for HFR operations, so they take less time.");
ui->keepNum->setToolTip("Keep just this number of star in the list based on magnitude. They will be the brightest in the list. If there are less than this number, they will all be kept. This filter is mainly for the solver, so that it takes less time.");
ui->brightestPercent->setToolTip("Removes the brightest % of stars from the image");
ui->dimmestPercent->setToolTip("Removes the dimmest % of stars from the image");
ui->saturationLimit->setToolTip("Removes stars above a certain % of the saturation limit of an image of this data type");
//Astrometry Settings
ui->inParallel->setToolTip("Loads the Astrometry index files in parallel. This can speed it up, but uses more resources");
ui->multiAlgo->setToolTip("Allows solving in multiple threads or multiple cores with several algorithms");
ui->solverTimeLimit->setToolTip("This is the maximum time the Astrometry.net solver should spend on the image before giving up");
ui->minWidth->setToolTip("Sets a the minimum degree limit in the scales for Astrometry to search if the scale parameter isn't set");
ui->maxWidth->setToolTip("Sets a the maximum degree limit in the scales for Astrometry to search if the scale parameter isn't set");
connect(ui->resort, &QCheckBox::stateChanged, this, [this]()
{
ui->resortQT->setChecked(ui->resort->isChecked());
});
ui->autoDown->setToolTip("This determines whether to automatically downsample or use the parameter below.");
ui->downsample->setToolTip("This downsamples or bins the image to hopefully make it solve faster.");
ui->resort->setToolTip("This resorts the stars based on magnitude. It usually makes it solve faster.");
ui->use_scale->setToolTip("Whether or not to use the estimated image scale below to try to speed up the solve");
ui->scale_low->setToolTip("The minimum size for the estimated image scale");
ui->scale_high->setToolTip("The maximum size for the estimated image scale");
ui->units->setToolTip("The units for the estimated image scale");
ui->use_position->setToolTip("Whether or not to use the estimated position below to try to speed up the solve");
ui->ra->setToolTip("The estimated RA of the object in decimal form in hours not degrees");
ui->raString->setToolTip("The display of how the RA looks in H:M:S form");
connect(ui->ra, &QLineEdit::textChanged, this, [this]()
{
char rastr[32];
double ra = ui->ra->text().toDouble() * 15;
ra2hmsstring(ra, rastr);
ui->raString->setText(rastr);
});
ui->dec->setToolTip("The estimated DEC of the object in decimal form in degrees");
ui->deString->setToolTip("The display of how the DEC looks in D:M:S form");
connect(ui->dec, &QLineEdit::textChanged, this, [this]()
{
char decstr[32];
double de = ui->dec->text().toDouble();
dec2dmsstring(de, decstr);
ui->deString->setText(decstr);
});
ui->radius->setToolTip("The search radius (degrees) of a circle centered on this position for astrometry.net to search for solutions");
ui->oddsToKeep->setToolTip("The Astrometry oddsToKeep Parameter. This may need to be changed or removed");
ui->oddsToSolve->setToolTip("The Astrometry oddsToSolve Parameter. This may need to be changed or removed");
ui->oddsToTune->setToolTip("The Astrometry oddsToTune Parameter. This may need to be changed or removed");
ui->logToFile->setToolTip("Whether the stellarsolver should just output to the log window or whether it should log to a file.");
ui->logFileName->setToolTip("The name and path of the file to log to, if this is blank, it will automatically log to a file in the temp Directory with an automatically generated name.");
ui->logLevel->setToolTip("The verbosity level of the log to be displayed in the log window or saved to a file.");
connect(ui->indexFolderPaths, &QComboBox::currentTextChanged, this, [this]()
{
loadIndexFilesListInFolder();
});
ui->indexFolderPaths->setToolTip("The paths on your compute to search for index files. To add another, just start typing in the box. To select one to look at, use the drop down.");
connect(ui->removeIndexPath, &QPushButton::clicked, this, [this]()
{
ui->indexFolderPaths->removeItem( ui->indexFolderPaths->currentIndex());
});
ui->removeIndexPath->setToolTip("Removes the selected path in the index folder paths dropdown so that it won't get passed to the solver");
connect(ui->addIndexPath, &QPushButton::clicked, this, [this]()
{
QString dir = QFileDialog::getExistingDirectory(this, "Load Index File Directory",
QDir::homePath(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if (dir.isEmpty())
return;
ui->indexFolderPaths->addItem( dir );
ui->indexFolderPaths->setCurrentIndex(ui->indexFolderPaths->count() - 1);
});
ui->addIndexPath->setToolTip("Adds a path the user selects to the list of index folder paths");
ui->singleIndexNum->setToolTip("The number of the index series to use in solving, if selected");
ui->singleHealpix->setToolTip("The healpix (sky position) of the index series to use in solving, if selected");
ui->useAllIndexes->setToolTip("Whether to use all the index files, or just the one index series selected");
connect(ui->useAllIndexes, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int ind)
{
ui->singleIndexNum->setReadOnly(ind == 0 || ind == 2);
ui->singleHealpix->setReadOnly(ind == 0 || ind == 2);
if(ind == 0)
{
ui->singleIndexNum->clear();
ui->singleHealpix->clear();
}
else if(ind == 0) // ?? this condition can't succeed ??
{
if(ui->singleIndexNum->text() == "")
{
ui->singleIndexNum->setText("4");
ui->singleHealpix->clear();
}
}
else
{
ui->singleIndexNum->setText(lastIndexNumber);
ui->singleHealpix->setText(lastHealpix);
}
});
connect(ui->singleIndexNum, &QLineEdit::textChanged, this, &MainWindow::loadIndexFilesToUse);
connect(ui->singleHealpix, &QLineEdit::textChanged, this, &MainWindow::loadIndexFilesToUse);
connect(ui->useAllIndexes, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::loadIndexFilesToUse);
//Behaviors and Settings for the StarTable
connect(this, &MainWindow::readyForStarTable, this, &MainWindow::displayTable);
ui->starTable->setSelectionBehavior(QAbstractItemView::SelectRows);
connect(ui->starTable, &QTableWidget::itemSelectionChanged, this, &MainWindow::starClickedInTable);
ui->starTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
connect(ui->exportStarTable, &QAbstractButton::clicked, this, &MainWindow::saveStarTable);
ui->showStars->setToolTip("This toggles the stars circles on and off in the image");
connect(ui->starOptions, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::updateImage);
ui->starOptions->setToolTip("This allows you to select different types of star circles to put on the stars. Warning, some require HFR to have been calculated first.");
connect(ui->showFluxInfo, &QCheckBox::stateChanged, this, [this]()
{
showFluxInfo = ui->showFluxInfo->isChecked();
updateHiddenStarTableColumns();
});
ui->showFluxInfo->setToolTip("This toggles whether to show or hide the HFR, peak, Flux columns in the star table after star extraction.");
connect(ui->showStarShapeInfo, &QCheckBox::stateChanged, this, [this]()
{
showStarShapeInfo = ui->showStarShapeInfo->isChecked();
updateHiddenStarTableColumns();
});
ui->showStarShapeInfo->setToolTip("This toggles whether to show or hide the information about each star's semi-major axis, semi-minor axis, and orientation in the star table after star extraction.");
//Behaviors for the Mouse over the Image to interact with the StartList and the UI
connect(ui->Image, &ImageLabel::mouseMoved, this, &MainWindow::mouseMovedOverImage);
connect(ui->Image, &ImageLabel::mouseClicked, this, &MainWindow::mouseClickedInImage);
connect(ui->Image, &ImageLabel::mouseDown, this, &MainWindow::mousePressedInImage);
//Behavior and settings for the Results Table
setupResultsTable();
ui->resultsTable->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->resultsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
connect(ui->exportResultsTable, &QAbstractButton::clicked, this, &MainWindow::saveResultsTable);
ui->exportResultsTable->setToolTip("Exports the log of processes executed during this session to a CSV file for further analysis");
connect(ui->showExtractorParams, &QCheckBox::stateChanged, this, [this]()
{
showExtractorParams = ui->showExtractorParams->isChecked();
updateHiddenResultsTableColumns();
});
ui->showExtractorParams->setToolTip("This toggles whether to show or hide the Star Extractor Settings in the Results table at the bottom");
connect(ui->showAstrometryParams, &QCheckBox::stateChanged, this, [this]()
{
showAstrometryParams = ui->showAstrometryParams->isChecked();
updateHiddenResultsTableColumns();
});
ui->showAstrometryParams->setToolTip("This toggles whether to show or hide the Astrometry Settings in the Results table at the bottom");
connect(ui->showSolutionDetails, &QCheckBox::stateChanged, this, [this]()
{
showSolutionDetails = ui->showSolutionDetails->isChecked();
updateHiddenResultsTableColumns();
});
ui->showSolutionDetails->setToolTip("This toggles whether to show or hide the Solution Details in the Results table at the bottom");
setWindowTitle(StellarSolver::getVersion());
ui->progressBar->setTextVisible(false);
timerMonitor.setInterval(1000); //1 sec intervals
connect(&timerMonitor, &QTimer::timeout, this, [this]()
{
ui->status->setText(QString("Processing Trial %1: %2 s").arg(currentTrial).arg(((int)processTimer.elapsed() / 1000) + 1));
});
setWindowIcon(QIcon(":/StellarSolverIcon.png"));
//This Load the saved settings for the StellarSolver
QSettings programSettings("Astrometry Freeware", "StellarSolver");
//These will set the index
int index = 0;
#if defined(Q_OS_MACOS)
if(QFile("/usr/local/bin/solve-field").exists())
index = 2;
else
index = 3;
#elif defined(Q_OS_LINUX)
index = 0;
#else //Windows
index = 4;
#endif
index = programSettings.value("setPathsIndex", index).toInt();
ui->setPathsAutomatically->setCurrentIndex(index);
//These load the default settings from the StellarSolver using a temporary object
StellarSolver temp(processType, stats, m_ImageBuffer, this);
ExternalProgramPaths paths = temp.getDefaultExternalPaths();
ui->sextractorPath->setText(programSettings.value("sextractorBinaryPath", paths.sextractorBinaryPath).toString());
ui->configFilePath->setText(programSettings.value("confPath", paths.confPath).toString());
ui->solverPath->setText(programSettings.value("solverPath", paths.solverPath).toString());
ui->astapPath->setText(programSettings.value("astapBinaryPath", paths.astapBinaryPath).toString());
ui->watneyPath->setText(programSettings.value("watneyBinaryPath", paths.watneyBinaryPath).toString());
ui->wcsPath->setText(programSettings.value("wcsPath", paths.wcsPath).toString());
ui->cleanupTemp->setChecked(programSettings.value("cleanupTemporaryFiles", temp.property("CleanupTemporaryFiles")).toBool());
ui->generateAstrometryConfig->setChecked(programSettings.value("autoGenerateAstroConfig", temp.property("AutoGenerateAstroConfig")).toBool());
ui->onlineServer->setText(programSettings.value("onlineServer", "http://nova.astrometry.net").toString());
ui->apiKey->setText(programSettings.value("apiKey", "iczikaqstszeptgs").toString());
ui->basePath->setText(QDir::tempPath());
sendSettingsToUI(temp.getCurrentParameters());
optionsList = temp.getBuiltInProfiles();
foreach(SSolver::Parameters param, optionsList)
{
ui->optionsProfile->addItem(param.listName);
ui->extractionProfile->addItem(param.listName);
ui->solverProfile->addItem(param.listName);
}
optionsAreSaved = true; //This way the next command won't trigger the unsaved warning.
ui->optionsProfile->setCurrentIndex(0);
ui->extractionProfile->setCurrentIndex(programSettings.value("starExtractionProfile", 5).toInt());
ui->solverProfile->setCurrentIndex(programSettings.value("solverProfile", 4).toInt());
QString storedPaths = programSettings.value("indexFolderPaths", "").toString();
QStringList indexFilePaths;
if(storedPaths == "")
indexFilePaths = temp.getDefaultIndexFolderPaths();
else
indexFilePaths = storedPaths.split(",");
foreach(QString pathName, indexFilePaths)
ui->indexFolderPaths->addItem(pathName);
loadIndexFilesListInFolder();
loadIndexFilesToUse();
ui->imageScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->imageScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui->imageScrollArea->verticalScrollBar()->setMinimum(0);
ui->imageScrollArea->verticalScrollBar()->setMaximum(5000);
ui->imageScrollArea->horizontalScrollBar()->setMinimum(0);
ui->imageScrollArea->horizontalScrollBar()->setMaximum(5000);
ui->imageScrollArea->verticalScrollBar()->setValue(2500);
ui->imageScrollArea->horizontalScrollBar()->setValue(2500);
connect(&stellarSolver, &StellarSolver::logOutput, this, &MainWindow::logOutput);
}
void MainWindow::settingJustChanged()
{
if(ui->optionsProfile->currentIndex() != 0 )
ui->optionsProfile->setCurrentIndex(0);
optionsAreSaved = false;
}
void MainWindow::reloadConvTable()
{
if(convInspector && convInspector->isVisible())
{
convTable->clear();
QVector<float> convFilter =
StellarSolver::generateConvFilter((SSolver::ConvFilterType) ui->convFilterType->currentIndex(), ui->fwhm->value());
int size = sqrt(convFilter.size());
double max = *std::max_element(convFilter.constBegin(), convFilter.constEnd());
convTable->setRowCount(size);
convTable->setColumnCount(size);
int i = 0;
for(int r = 0; r < size; r++)
{
convTable->setRowHeight(r, 50);
for(int c = 0; c < size; c++)
{
convTable->setColumnWidth(c, 50);
QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(convFilter.at(i), 'g', 4));
double col = convFilter.at(i)/max * 255;
QFont font = newItem->font();
font.setPixelSize(10);
newItem->setFont(font);
newItem->setFlags(newItem->flags() ^ Qt::ItemIsEditable);
newItem->setBackground(QBrush(QColor(col,col,col)));
newItem->setForeground(QBrush(Qt::yellow));
convTable->setItem(r,c,newItem);
i++;
}
}
//convInspector->resize(size* 50 + 60, size * 50 + 60);
int dialogWidth = convTable->horizontalHeader()->length() + 40;
int dialogHeight= convTable->verticalHeader()->length() + 40;
convInspector->resize(dialogWidth, dialogHeight);
}
}
void MainWindow::loadOptionsProfile()
{
if(ui->optionsProfile->currentIndex() == 0)
return;
SSolver::Parameters oldOptions = getSettingsFromUI();
if( !optionsAreSaved )
{
if(QMessageBox::question(this, "Abort?",
"You made unsaved changes in the settings, do you really wish to overwrite them?") == QMessageBox::No)
{
ui->optionsProfile->setCurrentIndex(0);
return;
}
optionsAreSaved = true; //They just got overwritten
}
SSolver::Parameters newOptions = optionsList.at(ui->optionsProfile->currentIndex() - 1);
QList<QWidget *> controls = ui->optionsBox->findChildren<QWidget *>();
foreach(QWidget *control, controls)
control->blockSignals(true);
sendSettingsToUI(newOptions);
foreach(QWidget *control, controls)
control->blockSignals(false);
reloadConvTable();
}
MainWindow::~MainWindow()
{
delete ui;
if(m_ImageBuffer)
delete[] m_ImageBuffer;
}
//This method clears the stars and star displays
void MainWindow::clearStars()
{
ui->starTable->clearContents();
ui->starTable->setRowCount(0);
ui->starTable->setColumnCount(0);
selectedStar = 0;
stars.clear();
updateImage();
}
//This method clears the tables and displays when the user requests it.
void MainWindow::clearResults()
{
ui->logDisplay->clear();
ui->resultsTable->clearContents();
ui->resultsTable->setRowCount(0);
}
//These methods are for the logging of information to the textfield at the bottom of the window.
void MainWindow::logOutput(QString text)
{
ui->logDisplay->appendPlainText(text);
ui->logDisplay->show();
}
void MainWindow::toggleFullScreen()
{
if (isFullScreen())
showNormal();
else
showFullScreen();
}
void MainWindow::toggleLogDisplay()
{
if (ui->tabWidget->isVisible())
ui->tabWidget->hide();
else
ui->tabWidget->show();
}
void MainWindow::helpPopup()
{
QString helpMessage =
QString("<table>"
"<tr><td>Zoom In: </td><td>%1</td></tr>"
"<tr><td>Zoom Out: </td><td>%2</td></tr>\n"
"<tr><td>Pan Up: </td><td>%3</td></tr>\n"
"<tr><td>Pan Down: </td><td>%4</td></tr>\n"
"<tr><td>Pan Left: </td><td>%5</td></tr>\n"
"<tr><td>Pan Right: </td><td>%6</td></tr>\n"
"<tr><td>AutoScale: </td><td>%7</td></tr>\n"
"<tr><td>LoadImage: </td><td>%8</td></tr>\n"
"<tr><td>Quit: </td><td>%9</td></tr>\n"
"<tr><td>Toggle Log Display: </td><td>%10</td></tr>\n"
"<tr><td>Toggle Full Screen: </td><td>%11</td></tr>\n"
"<tr><td>Help: </td><td>%12</td></tr>\n"
"</table>"
)
.arg(QKeySequence(QKeySequence::ZoomIn).toString(QKeySequence::NativeText))
.arg(QKeySequence(QKeySequence::ZoomOut).toString(QKeySequence::NativeText))
.arg(QKeySequence(QKeySequence::MoveToPreviousLine).toString(QKeySequence::NativeText))
.arg(QKeySequence(QKeySequence::MoveToNextLine).toString(QKeySequence::NativeText))
.arg(QKeySequence(QKeySequence::MoveToPreviousChar).toString(QKeySequence::NativeText))
.arg(QKeySequence(QKeySequence::MoveToNextChar).toString(QKeySequence::NativeText))
.arg("Ctrl+0")
.arg(QKeySequence(QKeySequence::Open).toString(QKeySequence::NativeText))
.arg(QKeySequence(QKeySequence::Quit).toString(QKeySequence::NativeText))
.arg("Ctrl+l")
.arg(QKeySequence(QKeySequence::FullScreen).toString(QKeySequence::NativeText))
.arg(QKeySequence(QKeySequence::HelpContents).toString(QKeySequence::NativeText));
QMessageBox *msgBox = new QMessageBox(this);
msgBox->setIcon( QMessageBox::Information );
msgBox->setText(helpMessage);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->show();
}
void MainWindow::setSubframe()
{
if(useSubframe)
{
useSubframe = false;
ui->setSubFrame->setChecked(false);
}
else
{
settingSubframe = true;
ui->mouseInfo->setText("Please select your subframe now.");
}
updateImage();
}
void MainWindow::startProcessMonitor()
{
ui->status->setText(QString("Processing Trial %1").arg(currentTrial));
ui->progressBar->setRange(0, 0);
timerMonitor.start();
processTimer.start();
}
void MainWindow::stopProcessMonitor()
{
timerMonitor.stop();
ui->progressBar->setRange(0, 10);
ui->status->setText("No Process Running");
}
//I wrote this method because we really want to do this before all 4 processes
//It was getting repetitive.
bool MainWindow::prepareForProcesses()
{
if(ui->vertSplitter->sizes().size() - 1 < 10)
ui->vertSplitter->setSizes(QList<int>() << ui->vertSplitter->height() / 2 << 100 );
ui->logDisplay->verticalScrollBar()->setValue(ui->logDisplay->verticalScrollBar()->maximum());
if(!imageLoaded)
{
logOutput("Please Load an Image First");
return false;
}
if(stellarSolver.isRunning())
{
const SSolver::ProcessType type = static_cast<SSolver::ProcessType>(stellarSolver.property("ProcessType").toInt());
if(type == SOLVE && !stellarSolver.solvingDone())
{
if(QMessageBox::question(this, "Abort?", "StellarSolver is solving now. Abort it?") == QMessageBox::No)
return false;
}
else if((type == EXTRACT || type == EXTRACT_WITH_HFR) && !extractorComplete())
{
if(QMessageBox::question(this, "Abort?", "StellarSolver is extracting sources now. Abort it?") == QMessageBox::No)
return false;
}
stellarSolver.abortAndWait();
}
numberOfTrials = ui->trials->value();
totalTime = 0;
currentTrial = 0;
lastSolution = FITSImage::Solution();
hasHFRData = false;
return true;
}
//I wrote this method to display the table after star extraction has occured.
void MainWindow::displayTable()
{
sortStars();
updateStarTableFromList();
if(ui->horSplitter->sizes().size() - 1 < 10)
ui->horSplitter->setSizes(QList<int>() << ui->optionsBox->width() << ui->horSplitter->width() / 2 << 200 );
updateImage();
}
//This method is intended to load a list of the index files to display as feedback to the user.
void MainWindow::loadIndexFilesListInFolder()
{
QString currentPath = ui->indexFolderPaths->currentText();
QDir dir(currentPath);
ui->indexFiles->clear();
if(dir.exists())
{
dir.setNameFilters(QStringList() << "*.fits" << "*.fit");
if(dir.entryList().count() == 0)
ui->indexFiles->addItem("No index files in Folder");
ui->indexFiles->addItems(dir.entryList());
}
else
ui->indexFiles->addItem("Invalid Folder");
}
//This loads and updates the list of files we will use, if not autoindexing.
void MainWindow::loadIndexFilesToUse()
{
// Convert the UI to a QStringList of directories to search.
QStringList dirList;
for(int i = 0; i < ui->indexFolderPaths->count(); i++)
dirList << ui->indexFolderPaths->itemText(i);
indexFileList.clear();
if (ui->useAllIndexes->currentIndex() == 0)
// Get all the fits files.
indexFileList = StellarSolver::getIndexFiles(dirList, -1, -1);
else
{
// Constraining the index files by index and possibly healpix.
int healpix = -1;
if (!ui->singleHealpix->text().isEmpty())
healpix = ui->singleHealpix->text().toShort();
int index = ui->singleIndexNum->text().toShort();
indexFileList = StellarSolver::getIndexFiles(dirList, index, healpix);
}
// Strip directory paths for the UI.
QStringList filenames;
for (int i = 0; i < indexFileList.count(); ++i)
{
QFileInfo f(indexFileList[i]);
filenames.append(f.fileName());
}
// Add the filenames (without the full path) to the UI.
ui->indexFilesToUse->clear();
ui->indexFilesToUse->addItems(filenames);
}
//The following methods are meant for starting the star extractor and image solver.
//The methods run when the buttons are clicked. They call the methods inside StellarSolver and ExternalExtractorSovler
//This method responds when the user clicks the Star Extraction Button
void MainWindow::extractButtonClicked()
{
if(!prepareForProcesses())
return;
int type = ui->extractorTypeForExtraction->currentIndex();
switch(type)
{
case 0:
processType = EXTRACT;
m_ExtractorType = EXTRACTOR_INTERNAL;
break;
case 1:
processType = EXTRACT_WITH_HFR;
m_ExtractorType = EXTRACTOR_INTERNAL;
break;
case 2:
processType = EXTRACT;
m_ExtractorType = EXTRACTOR_EXTERNAL;
break;
case 3:
processType = EXTRACT_WITH_HFR;
m_ExtractorType = EXTRACTOR_EXTERNAL;
break;
}
profileSelection = ui->extractionProfile->currentIndex();
extractImage();
}
//This method responds when the user clicks the Star Extraction Button
void MainWindow::solveButtonClicked()
{
if(!prepareForProcesses())
return;
processType = SOLVE;
profileSelection = ui->solverProfile->currentIndex();
solveImage();
}
void MainWindow::extractImage()
{
//This makes sure the solver is done before starting another time
//That way the timer is accurate.
while(stellarSolver.isRunning())
qApp->processEvents();
currentTrial++;
clearStars();
//Since this tester uses it many times, it doesn't *need* to replace the stellarsolver every time
//resetStellarSolver();
stellarSolver.setProperty("ExtractorType", m_ExtractorType);
stellarSolver.setProperty("ProcessType", processType);
//These set the StellarSolver Parameters
if(profileSelection == 0)
stellarSolver.setParameters(getSettingsFromUI());
else
stellarSolver.setParameters(optionsList.at(profileSelection - 1));
setupExternalExtractorSolverIfNeeded();
setupStellarSolverParameters();
if(useSubframe)
stellarSolver.setUseSubframe(subframe);
else
stellarSolver.clearSubFrame();
stellarSolver.setColorChannel(ui->channelSelection->currentIndex());
connect(&stellarSolver, &StellarSolver::ready, this, &MainWindow::extractorComplete);
startProcessMonitor();
stellarSolver.start();
}
//This method runs when the user clicks the Solve buttton
void MainWindow::solveImage()
{
//This makes sure the solver is done before starting another time
//That way the timer is accurate.
while(stellarSolver.isRunning())
qApp->processEvents();
currentTrial++;
//Since this tester uses it many times, it doesn't *need* to replace the stellarsolver every time
//resetStellarSolver();
m_ExtractorType = (SSolver::ExtractorType) ui->extractorTypeForSolving->currentIndex();
solverType = (SSolver::SolverType) ui->solverType->currentIndex();
stellarSolver.setProperty("ProcessType", processType);
stellarSolver.setProperty("ExtractorType", m_ExtractorType);
stellarSolver.setProperty("SolverType", solverType);
//These set the StellarSolver Parameters
if(profileSelection == 0)
stellarSolver.setParameters(getSettingsFromUI());
else
stellarSolver.setParameters(optionsList.at(profileSelection - 1));
setupStellarSolverParameters();
setupExternalExtractorSolverIfNeeded();
stellarSolver.clearSubFrame();
//Setting the initial search scale settings
if(ui->use_scale->isChecked())
stellarSolver.setSearchScale(ui->scale_low->text().toDouble(), ui->scale_high->text().toDouble(),
(SSolver::ScaleUnits)ui->units->currentIndex());
else
stellarSolver.setProperty("UseScale", false);
//Setting the initial search location settings
if(ui->use_position->isChecked())
stellarSolver.setSearchPositionRaDec(ui->ra->text().toDouble(), ui->dec->text().toDouble());
else
stellarSolver.setProperty("UsePosition", false);
stellarSolver.setColorChannel(ui->channelSelection->currentIndex());
connect(&stellarSolver, &StellarSolver::ready, this, &MainWindow::solverComplete);
startProcessMonitor();
stellarSolver.start();
}
//This sets up the External SExtractor and Solver and sets settings specific to them
void MainWindow::setupExternalExtractorSolverIfNeeded()
{
// External options
stellarSolver.setProperty("FileToProcess", fileToProcess);
stellarSolver.setProperty("BasePath", ui->basePath->text());
stellarSolver.setProperty("CleanupTemporaryFiles", ui->cleanupTemp->isChecked());
stellarSolver.setProperty("AutoGenerateAstroConfig", ui->generateAstrometryConfig->isChecked());
// External File Paths
ExternalProgramPaths externalPaths;
externalPaths.sextractorBinaryPath = ui->sextractorPath->text();
externalPaths.confPath = ui->configFilePath->text();
externalPaths.solverPath = ui->solverPath->text();
externalPaths.astapBinaryPath = ui->astapPath->text();
externalPaths.watneyBinaryPath = ui->watneyPath->text();
externalPaths.wcsPath = ui->wcsPath->text();
stellarSolver.setExternalFilePaths(externalPaths);
//Online Options
stellarSolver.setProperty("BasePath", ui->basePath->text());
stellarSolver.setProperty("AstrometryAPIKey", ui->apiKey->text());
stellarSolver.setProperty("AstrometryAPIURL", ui->onlineServer->text());
}
void MainWindow::setupStellarSolverParameters()
{
stellarSolver.clearIndexFileAndFolderPaths();
if(ui->useAllIndexes->currentIndex() == 0)
{
QStringList indexFolderPaths;
for(int i = 0; i < ui->indexFolderPaths->count(); i++)
{
indexFolderPaths << ui->indexFolderPaths->itemText(i);
}
stellarSolver.setIndexFolderPaths(indexFolderPaths);
}
else
{
stellarSolver.setIndexFilePaths(indexFileList);
}
//These setup Logging if desired
stellarSolver.setProperty("LogToFile", ui->logToFile->isChecked());
QString filename = ui->logFileName->text();
if(filename != "" && QFileInfo(filename).dir().exists() && !QFileInfo(filename).isDir())
stellarSolver.setProperty("LogFileName", filename);
stellarSolver.setLogLevel((SSolver::logging_level)ui->logLevel->currentIndex());
stellarSolver.setSSLogLevel((SSolver::SSolverLogLevel)ui->stellarSolverLogLevel->currentIndex());
}
//This sets all the settings for either internal SEP or external SExtractor
//based on the requested settings in the mainwindow interface.
//If you are implementing the StellarSolver Library in your progra, you may choose to change some or all of these settings or use the defaults.
SSolver::Parameters MainWindow::getSettingsFromUI()
{
SSolver::Parameters params;
params.listName = "Custom";
params.description = ui->description->toPlainText();
//These are to pass the parameters to the internal star extractor
params.apertureShape = (SSolver::Shape) ui->apertureShape->currentIndex();
params.kron_fact = ui->kron_fact->text().toDouble();
params.subpix = ui->subpix->text().toInt() ;
params.r_min = ui->r_min->text().toFloat();
//params.inflags
params.magzero = ui->magzero->text().toFloat();
params.minarea = ui->minarea->text().toFloat();
params.threshold_bg_multiple = ui->thresh_multiple->text().toFloat();
params.threshold_offset = ui->thresh_offset->text().toFloat();
params.deblend_thresh = ui->deblend_thresh->text().toInt();
params.deblend_contrast = ui->deblend_contrast->text().toFloat();
params.clean = (ui->cleanCheckBox->isChecked()) ? 1 : 0;
params.clean_param = ui->clean_param->text().toDouble();
params.convFilterType = (SSolver::ConvFilterType)ui->convFilterType->currentIndex();
params.fwhm = ui->fwhm->text().toInt();
params.partition = ui->partition->isChecked();
//Star Filter Settings
params.resort = ui->resort->isChecked();
params.maxSize = ui->maxSize->text().toDouble();
params.minSize = ui->minSize->text().toDouble();
params.maxEllipse = ui->maxEllipse->text().toDouble();
params.initialKeep = ui->initialKeep->text().toInt();
params.keepNum = ui->keepNum->text().toInt();
params.removeBrightest = ui->brightestPercent->text().toDouble();
params.removeDimmest = ui->dimmestPercent->text().toDouble();
params.saturationLimit = ui->saturationLimit->text().toDouble();
//Settings that usually get set by the config file
params.maxwidth = ui->maxWidth->text().toDouble();
params.minwidth = ui->minWidth->text().toDouble();
params.inParallel = ui->inParallel->isChecked();
params.multiAlgorithm = (SSolver::MultiAlgo)ui->multiAlgo->currentIndex();
params.solverTimeLimit = ui->solverTimeLimit->text().toInt();
params.resort = ui->resort->isChecked();
params.autoDownsample = ui->autoDown->isChecked();
params.downsample = ui->downsample->value();
params.search_radius = ui->radius->text().toDouble();
//Setting the settings to know when to stop or keep searching for solutions
params.logratio_tokeep = ui->oddsToKeep->text().toDouble();
params.logratio_totune = ui->oddsToTune->text().toDouble();
params.logratio_tosolve = ui->oddsToSolve->text().toDouble();
return params;
}
void MainWindow::sendSettingsToUI(SSolver::Parameters a)
{
ui->description->setText(a.description);
//Star Extractor Settings
ui->apertureShape->setCurrentIndex(a.apertureShape);
connect(ui->apertureShape, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::settingJustChanged);
ui->kron_fact->setText(QString::number(a.kron_fact));
ui->subpix->setText(QString::number(a.subpix));
ui->r_min->setText(QString::number(a.r_min));
ui->magzero->setText(QString::number(a.magzero));
ui->minarea->setText(QString::number(a.minarea));
ui->thresh_multiple->setText(QString::number(a.threshold_bg_multiple));
ui->thresh_offset->setText(QString::number(a.threshold_offset));
ui->deblend_thresh->setText(QString::number(a.deblend_thresh));
ui->deblend_contrast->setText(QString::number(a.deblend_contrast));
ui->cleanCheckBox->setChecked(a.clean == 1);
ui->clean_param->setText(QString::number(a.clean_param));
ui->convFilterType->setCurrentIndex(a.convFilterType);
connect(ui->convFilterType, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::settingJustChanged);
ui->fwhm->setValue(a.fwhm);
ui->partition->setChecked(a.partition);
//Star Filter Settings
ui->maxSize->setText(QString::number(a.maxSize));
ui->minSize->setText(QString::number(a.minSize));
ui->maxEllipse->setText(QString::number(a.maxEllipse));
ui->initialKeep->setText(QString::number(a.initialKeep));
ui->keepNum->setText(QString::number(a.keepNum));
ui->brightestPercent->setText(QString::number(a.removeBrightest));
ui->dimmestPercent->setText(QString::number(a.removeDimmest));
ui->saturationLimit->setText(QString::number(a.saturationLimit));
//Astrometry Settings
ui->autoDown->setChecked(a.autoDownsample);
ui->downsample->setValue(a.downsample);
ui->inParallel->setChecked(a.inParallel);
ui->multiAlgo->setCurrentIndex(a.multiAlgorithm);
ui->solverTimeLimit->setText(QString::number(a.solverTimeLimit));
ui->minWidth->setText(QString::number(a.minwidth));
ui->maxWidth->setText(QString::number(a.maxwidth));
ui->radius->setText(QString::number(a.search_radius));
ui->resort->setChecked(a.resort);
//Astrometry Log Ratio Settings
ui->oddsToKeep->setText(QString::number(a.logratio_tokeep));
ui->oddsToSolve->setText(QString::number(a.logratio_tosolve));
ui->oddsToTune->setText(QString::number(a.logratio_totune));
}
//This runs when the star extractor is complete.
//It reports the time taken, prints a message, loads the star extraction stars to the startable, and adds the star extraction stats to the results table.
bool MainWindow::extractorComplete()
{
elapsed = processTimer.elapsed() / 1000.0;
disconnect(&stellarSolver, &StellarSolver::ready, this, &MainWindow::extractorComplete);
if(!stellarSolver.failed() && stellarSolver.extractionDone())
{
totalTime += elapsed; //Only add to total time if it was successful
stars = stellarSolver.getStarList();
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
if(stellarSolver.isCalculatingHFR())
logOutput(QString(stellarSolver.getCommandString() + " with HFR success! Got %1 stars").arg(stars.size()));
else
logOutput(QString(stellarSolver.getCommandString() + " success! Got %1 stars").arg(stars.size()));
logOutput(QString("Star Extraction took a total of: %1 second(s).").arg( elapsed));
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
if(currentTrial < numberOfTrials)
{
extractImage();
return true;
}
stopProcessMonitor();
hasHFRData = stellarSolver.isCalculatingHFR();
}
else
{
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
logOutput(QString(stellarSolver.getCommandString() + "failed after %1 second(s).").arg( elapsed));
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
stopProcessMonitor();
if(currentTrial == 1)
return false;
currentTrial--; //This solve was NOT successful so it should not be counted in the average.
}
emit readyForStarTable();
ui->resultsTable->insertRow(ui->resultsTable->rowCount());
addExtractionToTable();
QTimer::singleShot(100, this, [this]()
{
ui->resultsTable->verticalScrollBar()->setValue(ui->resultsTable->verticalScrollBar()->maximum());
});
return true;
}
//This runs when the solver is complete. It reports the time taken, prints a message, and adds the solution to the results table.
bool MainWindow::solverComplete()
{
elapsed = processTimer.elapsed() / 1000.0;
disconnect(&stellarSolver, &StellarSolver::ready, this, &MainWindow::solverComplete);
if(!stellarSolver.failed() && stellarSolver.solvingDone())
{
totalTime += elapsed; //Only add to the total time if it was successful
ui->progressBar->setRange(0, 10);
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
logOutput(QString(stellarSolver.getCommandString() + " took a total of: %1 second(s).").arg( elapsed));
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
lastSolution = stellarSolver.getSolution();
if(currentTrial < numberOfTrials)
{
solveImage();
return true;
}
stopProcessMonitor();
}
else
{
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
logOutput(QString(stellarSolver.getCommandString() + "failed after %1 second(s).").arg( elapsed));
logOutput("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
stopProcessMonitor();
if(currentTrial == 1)
return false;
currentTrial--; //This solve was NOT successful so it should not be counted in the average.
}
ui->resultsTable->insertRow(ui->resultsTable->rowCount());
addExtractionToTable();
if(stellarSolver.solvingDone())
addSolutionToTable(stellarSolver.getSolution());
else
addSolutionToTable(lastSolution);
short solutionIndexNumber =stellarSolver.getSolutionIndexNumber();
lastIndexNumber = QString::number(stellarSolver.getSolutionIndexNumber());
lastHealpix = QString::number(stellarSolver.getSolutionHealpix());
if(solutionIndexNumber != -1 && ui->useAllIndexes->currentIndex() == 2)
{
ui->singleIndexNum->setText(lastIndexNumber);
ui->singleHealpix->setText(lastHealpix);
loadIndexFilesToUse();
}
if(ui->autoUpdateScaleAndPosition->isChecked())
{
FITSImage::Solution s = stellarSolver.getSolution();
ui->ra->setText(QString::number(s.ra / 15));
ui->dec->setText(QString::number(s.dec));
double scale_low;
double scale_high;
switch(ui->units->currentIndex())
{
case SSolver::ARCMIN_WIDTH:
scale_low = s.fieldHeight;
scale_high = s.fieldWidth;
break;
case SSolver::ARCSEC_PER_PIX:
scale_low = s.pixscale * 0.9;
scale_high = s.pixscale * 1.1;
break;
case SSolver::DEG_WIDTH:
scale_low = s.fieldHeight / 60;
scale_high = s.fieldWidth / 60;
break;
default:
scale_low = s.fieldHeight;
scale_high = s.fieldWidth;
break;
}
ui->scale_low->setText(QString::number(scale_low));
ui->scale_high->setText(QString::number(scale_high));
}
QTimer::singleShot(100, this, [this]()
{
ui->resultsTable->verticalScrollBar()->setValue(ui->resultsTable->verticalScrollBar()->maximum());
});
if(stellarSolver.hasWCSData())
{
hasWCSData = true;
stars = stellarSolver.getStarList();
hasHFRData = stellarSolver.isCalculatingHFR();
if(stars.count() > 0)
emit readyForStarTable();
}
return true;
}
//This method will attempt to abort the star extractor, sovler, and any other processes currently being run, no matter which type
void MainWindow::abort()
{
numberOfTrials = currentTrial;
if(stellarSolver.isRunning())
{
stellarSolver.abort();
logOutput("Aborting Process. . .");
}
else
logOutput("No Processes Running.");
}
//This method is meant to clear out the Astrometry settings that should change with each image
//They might be loaded from a fits file, but if the file doesn't contain them, they should be cleared.
void MainWindow::clearAstrometrySettings()
{
//Note that due to connections, it automatically sets the variable as well.
ui->use_scale->setChecked(false);
ui->scale_low->setText("");
ui->scale_high->setText("");
ui->use_position->setChecked(false);
ui->ra->setText("");
ui->dec->setText("");
}
//The following methods deal with the loading and displaying of the image
//I wrote this method to select the file name for the image and call the methods in the image loader to load it
bool MainWindow::imageLoad()
{
if(stellarSolver.isRunning())
{
QMessageBox::critical(nullptr, "Message", "A Process is currently running on the image, please wait until it is completed");
return false;
}
QString fileURL = QFileDialog::getOpenFileName(nullptr, "Load Image", dirPath,
"Images (*.fits *.fit *.bmp *.gif *.jpg *.jpeg *.png *.tif *.tiff *.pbm *.pgm *.ppm *.xbm *.xpm)");
if (fileURL.isEmpty())
return false;
QFileInfo fileInfo(fileURL);
if(!fileInfo.exists())
return false;
dirPath = fileInfo.absolutePath();
fileToProcess = fileURL;
clearAstrometrySettings();
fileio imageLoader;
imageLoader.logToSignal = true;
connect(&imageLoader, &fileio::logOutput, this, &MainWindow::logOutput);
if(imageLoader.loadImage(fileToProcess))
{
imageLoaded = true;
clearImageBuffers();
lastIndexNumber = "4"; //This will reset the filtering for index files
lastHealpix = "";
if(ui->useAllIndexes != 0)
{
ui->singleIndexNum->setText(lastIndexNumber);
ui->singleHealpix->setText(lastHealpix);
}
loadIndexFilesToUse();
m_ImageBuffer = imageLoader.getImageBuffer();
stats = imageLoader.getStats();
m_HeaderRecords = imageLoader.getRecords();
clearAstrometrySettings();
if(imageLoader.position_given)
{
ui->use_position->setChecked(true);
ui->ra->setText(QString::number(imageLoader.ra));
ui->dec->setText(QString::number(imageLoader.dec));
};
if(imageLoader.scale_given)
{
ui->use_scale->setChecked(true);
ui->scale_low->setText(QString::number(imageLoader.scale_low));
ui->scale_high->setText(QString::number(imageLoader.scale_high));
ui->units->setCurrentIndex(imageLoader.scale_units);
}
clearStars();
ui->horSplitter->setSizes(QList<int>() << ui->optionsBox->width() << ui->horSplitter->width() << 0 );
ui->fileNameDisplay->setText("Image: " + fileURL);
rawImage = imageLoader.getRawQImage();
autoScale();
hasWCSData = false;
stellarSolver.loadNewImageBuffer(stats, m_ImageBuffer);
return true;
}
return false;
}
bool MainWindow::imageSave()
{
if(!imageLoaded)
{
QMessageBox::critical(nullptr, "Message", "Please load an image before trying to save one.");
return false;
}
if(stellarSolver.isRunning())
{
QMessageBox::critical(nullptr, "Message", "A Process is currently running on the image, please wait until it is completed");
return false;
}
QString fileURL = QFileDialog::getSaveFileName(nullptr, "Save Image", dirPath,
"Images (*.fit)");
if (fileURL.isEmpty())
return false;
QFileInfo fileInfo(fileURL);
if(fileInfo.exists())
{
QMessageBox::critical(nullptr, "Message", "Please select another name, the file exists");
return false;
}
QString savePath = fileInfo.absoluteFilePath();
fileio imageSaver;
imageSaver.logToSignal = true;
connect(&imageSaver, &fileio::logOutput, this, &MainWindow::logOutput);
if(hasWCSData)
imageSaver.saveAsFITS(savePath, stats, m_ImageBuffer, stellarSolver.getSolution(), m_HeaderRecords, true);
else
imageSaver.saveAsFITS(savePath, stats, m_ImageBuffer, stellarSolver.getSolution(), m_HeaderRecords, false);
return true;
}
void adjustScrollBar(QScrollBar *scrollBar, double factor)
{
scrollBar->setValue(int(factor * scrollBar->value()
+ ((factor - 1) * scrollBar->pageStep()/2)));
}
void slideScrollBar(QScrollBar *scrollBar, double factor)
{
constexpr double panFactor = 10.0;
const int newValue = std::min(scrollBar->maximum(),
std::max(0, (int) (scrollBar->value() + factor * scrollBar->pageStep()/panFactor)));
scrollBar->setValue(newValue);
}
void MainWindow::panLeft()
{
if(!imageLoaded)
return;
slideScrollBar(ui->imageScrollArea->horizontalScrollBar(), -1);
}
void MainWindow::panRight()
{
if(!imageLoaded)
return;
slideScrollBar(ui->imageScrollArea->horizontalScrollBar(), 1);
}
void MainWindow::panUp()
{
if(!imageLoaded)
return;
slideScrollBar(ui->imageScrollArea->verticalScrollBar(), 1);
}
void MainWindow::panDown()
{
if(!imageLoaded)
return;
slideScrollBar(ui->imageScrollArea->verticalScrollBar(), -1);
}
//This method reacts when the user clicks the zoom in button
void MainWindow::zoomIn()
{
if(!imageLoaded)
return;
constexpr double zoomFactor = 1.5;
currentZoom *= zoomFactor;
adjustScrollBar(ui->imageScrollArea->verticalScrollBar(), zoomFactor);
adjustScrollBar(ui->imageScrollArea->horizontalScrollBar(), zoomFactor);
updateImage();
}
//This method reacts when the user clicks the zoom out button
void MainWindow::zoomOut()
{
if(!imageLoaded)
return;
constexpr double zoomFactor = 1.5;
currentZoom /= zoomFactor;
adjustScrollBar(ui->imageScrollArea->verticalScrollBar(), 1.0/zoomFactor);
adjustScrollBar(ui->imageScrollArea->horizontalScrollBar(), 1.0/zoomFactor);
updateImage();
}
//This code was copied and pasted and modified from rescale in Fitsview in KStars
//This method reacts when the user clicks the autoscale button and is called when the image is first loaded.
void MainWindow::autoScale()
{
if(!imageLoaded)
return;
int w = (stats.width + sampling - 1) / sampling;
int h = (stats.height + sampling - 1) / sampling;
double width = ui->imageScrollArea->rect().width();
double height = ui->imageScrollArea->rect().height() - 30; //The minus 30 is due to the image filepath label
// Find the zoom level which will enclose the current FITS in the current window size
double zoomX = ( width / w);
double zoomY = ( height / h);
(zoomX < zoomY) ? currentZoom = zoomX : currentZoom = zoomY;
updateImage();
}
//This method is intended to get the position and size of the star for rendering purposes
//It is used to draw circles/ellipses for the stars and to detect when the mouse is over a star
QRect MainWindow::getStarSizeInImage(FITSImage::Star star, bool &accurate)
{
accurate = true;
double width = 0;
double height = 0;
double a = star.a;
double b = star.b;
double HFR = star.HFR;
int starOption = ui->starOptions->currentIndex();
//This is so that the star will appear on the screen even though it has invalid size info.
//The External Astrometry.net solver does not report star sizes, nor does the online solver.
if((a <= 0 || b <= 0) && (starOption == 0 || starOption == 1))
{
a = 5;
b = 5;
accurate = false;
}
if((HFR <= 0) && (starOption == 2 || starOption == 3))
{
HFR = 5;
accurate = false;
}
switch(starOption)
{
case 0: //Ellipse from Star Extraction
width = 2 * a ;
height = 2 * b;
break;
case 1: //Circle from Star Extraction
{
double size = 2 * sqrt( pow(a, 2) + pow(b, 2) );
width = size;
height = size;
}
break;
case 2: //HFD Size, based on HFR, 2 x radius is the diameter
width = 2 * HFR;
height = 2 * HFR;
break;
case 3: //2 x HFD size, based on HFR, 4 x radius is 2 x the diameter
width = 4 * HFR;
height = 4 * HFR;
break;
}
double starx = star.x * currentWidth / stats.width ;
double stary = star.y * currentHeight / stats.height;
double starw = width * currentWidth / stats.width;
double starh = height * currentHeight / stats.height;
return QRect(starx - starw, stary - starh, starw * 2, starh * 2);
}
//This method is very loosely based on updateFrame in Fitsview in Kstars
//It will redraw the image when the user loads an image, zooms in, zooms out, or autoscales
//It will also redraw the image when a change needs to be made in how the circles for the stars are displayed such as highlighting one star
void MainWindow::updateImage()
{
if(!imageLoaded || rawImage.isNull())
return;
int w = (stats.width + sampling - 1) / sampling;
int h = (stats.height + sampling - 1) / sampling;
currentWidth = static_cast<int> (w * (currentZoom));
currentHeight = static_cast<int> (h * (currentZoom));
scaledImage = rawImage.scaled(currentWidth, currentHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap renderedImage = QPixmap::fromImage(scaledImage);
if(ui->showStars->isChecked())
{
QPainter p(&renderedImage);
for(int starnum = 0 ; starnum < stars.size() ; starnum++)
{
FITSImage::Star star = stars.at(starnum);
bool accurate;
QRect starInImage = getStarSizeInImage(star, accurate);
p.save();
p.translate(starInImage.center());
p.rotate(star.theta);
p.translate(-starInImage.center());
if(starnum == selectedStar)
{
QPen highlighter(QColor("yellow"));
highlighter.setWidth(4);
p.setPen(highlighter);
p.setOpacity(1);
}
else
{
if(accurate)
{
QPen highlighter(QColor("green"));
highlighter.setWidth(2);
p.setPen(highlighter);
p.setOpacity(1);
}
else
{
p.setPen(QColor("red"));
p.setOpacity(0.6);
}
}
p.drawEllipse(starInImage);
p.restore();
}
if(useSubframe)
{
QPen highlighter(QColor("green"));
highlighter.setWidth(2);
p.setPen(highlighter);
p.setOpacity(1);
double x = subframe.x() * currentWidth / stats.width ;
double y = subframe.y() * currentHeight / stats.height;
double w = subframe.width() * currentWidth / stats.width;
double h = subframe.height() * currentHeight / stats.height;
p.drawRect(QRect(x, y, w, h));
}
p.end();
}
ui->Image->setPixmap(renderedImage);
ui->Image->setFixedSize(renderedImage.size());
}
//This method was copied and pasted from Fitsdata in KStars
//It clears the image buffer out.
void MainWindow::clearImageBuffers()
{
delete[] m_ImageBuffer;
m_ImageBuffer = nullptr;
}
//I wrote this method to respond when the user's mouse is over a star
//It displays details about that particular star in a tooltip and highlights it in the image
//It also displays the x and y position of the mouse in the image and the pixel value at that spot now.
void MainWindow::mouseMovedOverImage(QPoint location)
{
if(imageLoaded)
{
double x = location.x() * stats.width / currentWidth;
double y = location.y() * stats.height / currentHeight;
if(x < 0)
x = 0;
if(y < 0)
y = 0;
if(x > stats.width)
x = stats.width;
if(y > stats.height)
y = stats.height;
if(settingSubframe)
{
int subX = subframe.x();
int subY = subframe.y();
int w = x - subX;
int h = y - subY;
subframe = QRect(subX, subY, w, h);
updateImage();
}
QString mouseText = "";
if(hasWCSData)
{
QPointF wcsPixelPoint(x, y);
FITSImage::wcs_point wcsCoord;
if(stellarSolver.pixelToWCS(wcsPixelPoint, wcsCoord))
{
mouseText = QString("RA: %1, DEC: %2").arg(StellarSolver::raString(wcsCoord.ra),
StellarSolver::decString(wcsCoord.dec));
}
else
{
mouseText = QString("WCS Data not fully loaded");
}
}
else
mouseText = QString("X: %1, Y: %2").arg(x).arg(y);
if(stats.channels == 1)
mouseText = mouseText + QString(", Value: %1").arg(getValue(x, y, 0));
else
mouseText = mouseText + QString(", Value: R: %1, G: %2, B: %3").arg(getValue(x, y, 0), getValue(x, y, 1), getValue(x, y, 2));
if(useSubframe)
mouseText = mouseText + QString(", Subframe X: %1, Y: %2, W: %3, H: %4").arg(subframe.x()).arg(subframe.y()).arg(
subframe.width()).arg(subframe.height());
ui->mouseInfo->setText(mouseText);
bool starFound = false;
for(int i = 0 ; i < stars.size() ; i ++)
{
FITSImage::Star star = stars.at(i);
bool accurate;
QRect starInImage = getStarSizeInImage(star, accurate);
if(starInImage.contains(location))
{
QString text = QString("Star: %1, x: %2, y: %3\nmag: %4, flux: %5, peak:%6").arg(i + 1).arg(star.x).arg(star.y).arg(
star.mag).arg(star.flux).arg(star.peak);
if(hasHFRData)
text += ", " + QString("HFR: %1").arg(star.HFR);
if(hasWCSData)
text += "\n" + QString("RA: %1, DEC: %2").arg(StellarSolver::raString(star.ra), StellarSolver::decString(star.dec));
QToolTip::showText(QCursor::pos(), text, ui->Image);
selectedStar = i;
starFound = true;
updateImage();
}
}
if(!starFound)
QToolTip::hideText();
}
}
//This function is based upon code in the method mouseMoveEvent in FITSLabel in KStars
//It is meant to get the value from the image buffer at a particular pixel location for the display
//when the mouse is over a certain pixel
QString MainWindow::getValue(int x, int y, int channel)
{
if (m_ImageBuffer == nullptr)
return "";
int index = y * stats.width + x + channel * stats.width * stats.height;
QString stringValue = "";
switch (stats.dataType)
{
case TBYTE:
stringValue = QLocale().toString(m_ImageBuffer[index]);
break;
case TSHORT:
stringValue = QLocale().toString((reinterpret_cast<int16_t *>(m_ImageBuffer))[index]);
break;
case TUSHORT:
stringValue = QLocale().toString((reinterpret_cast<uint16_t *>(m_ImageBuffer))[index]);
break;
case TLONG:
stringValue = QLocale().toString((reinterpret_cast<int32_t *>(m_ImageBuffer))[index]);
break;
case TULONG:
stringValue = QLocale().toString((reinterpret_cast<uint32_t *>(m_ImageBuffer))[index]);
break;
case TFLOAT:
stringValue = QLocale().toString((reinterpret_cast<float *>(m_ImageBuffer))[index], 'f', 5);
break;
case TLONGLONG:
stringValue = QLocale().toString(static_cast<int>((reinterpret_cast<int64_t *>(m_ImageBuffer))[index]));
break;
case TDOUBLE:
stringValue = QLocale().toString((reinterpret_cast<float *>(m_ImageBuffer))[index], 'f', 5);
break;
default:
break;
}
return stringValue;
}
//I wrote the is method to respond when the user clicks on a star
//It highlights the row in the star table that corresponds to that star
void MainWindow::mouseClickedInImage(QPoint location)
{
if(settingSubframe)
settingSubframe = false;
for(int i = 0 ; i < stars.size() ; i ++)
{
bool accurate;
QRect starInImage = getStarSizeInImage(stars.at(i), accurate);
if(starInImage.contains(location))
ui->starTable->selectRow(i);
}
}
void MainWindow::mousePressedInImage(QPoint location)
{
if(settingSubframe)
{
if(!useSubframe)
{
useSubframe = true;
ui->setSubFrame->setChecked(true);
double x = location.x() * stats.width / currentWidth;
double y = location.y() * stats.height / currentHeight;
subframe = QRect(x, y, 0, 0);
}
}
}
//THis method responds to row selections in the table and higlights the star you select in the image
void MainWindow::starClickedInTable()
{
if(ui->starTable->selectedItems().count() > 0)
{
QTableWidgetItem *currentItem = ui->starTable->selectedItems().first();
selectedStar = ui->starTable->row(currentItem);
FITSImage::Star star = stars.at(selectedStar);
double starx = star.x * currentWidth / stats.width ;
double stary = star.y * currentHeight / stats.height;
updateImage();
ui->imageScrollArea->ensureVisible(starx, stary);
}
}
//This sorts the stars by magnitude for display purposes
void MainWindow::sortStars()
{
if(stars.size() > 1)
{
//Note that a star is dimmer when the mag is greater!
//We want to sort in decreasing order though!
std::sort(stars.begin(), stars.end(), [](const FITSImage::Star & s1, const FITSImage::Star & s2)
{
return s1.mag < s2.mag;
});
}
}
//This is a helper function that I wrote for the methods below
//It add a column with a particular name to the specified table
void addColumnToTable(QTableWidget *table, QString heading)
{
int colNum = table->columnCount();
table->insertColumn(colNum);
table->setHorizontalHeaderItem(colNum, new QTableWidgetItem(heading));
}
//This is a method I wrote to hide the desired columns in a table based on their name
void setColumnHidden(QTableWidget *table, QString colName, bool hidden)
{
for(int c = 0; c < table->columnCount() ; c ++)
{
if(table->horizontalHeaderItem(c)->text() == colName)
table->setColumnHidden(c, hidden);
}
}
//This is a helper function that I wrote for the methods below
//It sets the value of a cell in the column of the specified name in the last row in the table
bool setItemInColumn(QTableWidget *table, QString colName, QString value)
{
int row = table->rowCount() - 1;
for(int c = 0; c < table->columnCount() ; c ++)
{
if(table->horizontalHeaderItem(c)->text() == colName)
{
table->setItem(row, c, new QTableWidgetItem(value));
return true;
}
}
return false;
}
//This copies the stars into the table
void MainWindow::updateStarTableFromList()
{
QTableWidget *table = ui->starTable;
table->clearContents();
table->setRowCount(0);
table->setColumnCount(0);
selectedStar = 0;
addColumnToTable(table, "MAG_AUTO");
addColumnToTable(table, "RA (J2000)");
addColumnToTable(table, "DEC (J2000)");
addColumnToTable(table, "X_IMAGE");
addColumnToTable(table, "Y_IMAGE");
addColumnToTable(table, "FLUX_AUTO");
addColumnToTable(table, "PEAK");
if(hasHFRData)
addColumnToTable(table, "HFR");
addColumnToTable(table, "a");
addColumnToTable(table, "b");
addColumnToTable(table, "theta");
for(int i = 0; i < stars.size(); i ++)
{
table->insertRow(table->rowCount());
FITSImage::Star star = stars.at(i);
setItemInColumn(table, "MAG_AUTO", QString::number(star.mag));
setItemInColumn(table, "X_IMAGE", QString::number(star.x));
setItemInColumn(table, "Y_IMAGE", QString::number(star.y));
if(hasWCSData)
{
setItemInColumn(table, "RA (J2000)", StellarSolver::raString(star.ra));
setItemInColumn(table, "DEC (J2000)", StellarSolver::decString(star.dec));
}
setItemInColumn(table, "FLUX_AUTO", QString::number(star.flux));
setItemInColumn(table, "PEAK", QString::number(star.peak));
if(hasHFRData)
setItemInColumn(table, "HFR", QString::number(star.HFR));
setItemInColumn(table, "a", QString::number(star.a));
setItemInColumn(table, "b", QString::number(star.b));
setItemInColumn(table, "theta", QString::number(star.theta));
}
updateHiddenStarTableColumns();
}
void MainWindow::updateHiddenStarTableColumns()
{
QTableWidget *table = ui->starTable;
setColumnHidden(table, "FLUX_AUTO", !showFluxInfo);
setColumnHidden(table, "PEAK", !showFluxInfo);
setColumnHidden(table, "RA (J2000)", !hasWCSData);
setColumnHidden(table, "DEC (J2000)", !hasWCSData);
setColumnHidden(table, "a", !showStarShapeInfo);
setColumnHidden(table, "b", !showStarShapeInfo);
setColumnHidden(table, "theta", !showStarShapeInfo);
}
//Note: The next 3 functions are designed to work in an easily editable way.
//To add new columns to this table, just add them to the first function
//To have it fill the column when a Star Extraction or Solve is complete, add it to one or both of the next two functions
//So that the column gets setup and then gets filled in.
//This method sets up the results table to start with.
void MainWindow::setupResultsTable()
{
QTableWidget *table = ui->resultsTable;
//These are in the order that they will appear in the table.
addColumnToTable(table, "Avg Time");
addColumnToTable(table, "# Trials");
addColumnToTable(table, "Command");
addColumnToTable(table, "Profile");
addColumnToTable(table, "Loglvl");
addColumnToTable(table, "Stars");
//Star Extractor Parameters
addColumnToTable(table, "Shape");
addColumnToTable(table, "Kron");
addColumnToTable(table, "Subpix");
addColumnToTable(table, "r_min");
addColumnToTable(table, "minarea");
addColumnToTable(table, "thresh_mult");
addColumnToTable(table, "thresh_off");
addColumnToTable(table, "d_thresh");
addColumnToTable(table, "d_cont");
addColumnToTable(table, "clean");
addColumnToTable(table, "clean param");
addColumnToTable(table, "conv");
addColumnToTable(table, "fwhm");
addColumnToTable(table, "part");
//Star Filtering Parameters
addColumnToTable(table, "Max Size");
addColumnToTable(table, "Min Size");
addColumnToTable(table, "Max Ell");
addColumnToTable(table, "Ini Keep");
addColumnToTable(table, "Keep #");
addColumnToTable(table, "Cut Bri");
addColumnToTable(table, "Cut Dim");
addColumnToTable(table, "Sat Lim");
//Astrometry Parameters
addColumnToTable(table, "Pos?");
addColumnToTable(table, "Scale?");
addColumnToTable(table, "Resort?");
addColumnToTable(table, "AutoDown");
addColumnToTable(table, "Down");
addColumnToTable(table, "in ||");
addColumnToTable(table, "Multi");
addColumnToTable(table, "# Thread");
//Results
addColumnToTable(table, "RA (J2000)");
addColumnToTable(table, "DEC (J2000)");
addColumnToTable(table, "RA ERR \"");
addColumnToTable(table, "DEC ERR \"");
addColumnToTable(table, "Orientation˚");
addColumnToTable(table, "Field Width \'");
addColumnToTable(table, "Field Height \'");
addColumnToTable(table, "PixScale \"");
addColumnToTable(table, "Parity");
addColumnToTable(table, "Channel");
addColumnToTable(table, "Field");
updateHiddenResultsTableColumns();
}
//This adds a Star extraction to the Results Table
//To add, remove, or change the way certain columns are filled when a star extraction is finished, edit them here.
void MainWindow::addExtractionToTable()
{
QTableWidget *table = ui->resultsTable;
SSolver::Parameters params = stellarSolver.getCurrentParameters();
setItemInColumn(table, "Avg Time", QString::number(totalTime / currentTrial));
setItemInColumn(table, "# Trials", QString::number(currentTrial));
if(stellarSolver.isCalculatingHFR())
setItemInColumn(table, "Command", stellarSolver.getCommandString() + " w/HFR");
else
setItemInColumn(table, "Command", stellarSolver.getCommandString());
setItemInColumn(table, "Profile", params.listName);
setItemInColumn(table, "Loglvl", stellarSolver.getLogLevelString());
setItemInColumn(table, "Stars", QString::number(stellarSolver.getNumStarsFound()));
//Star Extractor Parameters
setItemInColumn(table, "Shape", stellarSolver.getShapeString());
setItemInColumn(table, "Kron", QString::number(params.kron_fact));
setItemInColumn(table, "Subpix", QString::number(params.subpix));
setItemInColumn(table, "r_min", QString::number(params.r_min));
setItemInColumn(table, "minarea", QString::number(params.minarea));
setItemInColumn(table, "thresh_mult", QString::number(params.threshold_bg_multiple));
setItemInColumn(table, "thresh_off", QString::number(params.threshold_offset));
setItemInColumn(table, "d_thresh", QString::number(params.deblend_thresh));
setItemInColumn(table, "d_cont", QString::number(params.deblend_contrast));
setItemInColumn(table, "clean", QString::number(params.clean));
setItemInColumn(table, "clean param", QString::number(params.clean_param));
setItemInColumn(table, "conv", stellarSolver.getConvFilterString());
setItemInColumn(table, "fwhm", QString::number(params.fwhm));
setItemInColumn(table, "part", QString::number(params.partition));
setItemInColumn(table, "Channel", FITSImage::getColorChannelText(stellarSolver.getColorChannel()));
setItemInColumn(table, "Field", ui->fileNameDisplay->text());
//StarFilter Parameters
setItemInColumn(table, "Max Size", QString::number(params.maxSize));
setItemInColumn(table, "Min Size", QString::number(params.minSize));
setItemInColumn(table, "Max Ell", QString::number(params.maxEllipse));
setItemInColumn(table, "Ini Keep", QString::number(params.initialKeep));
setItemInColumn(table, "Keep #", QString::number(params.keepNum));
setItemInColumn(table, "Cut Bri", QString::number(params.removeBrightest));
setItemInColumn(table, "Cut Dim", QString::number(params.removeDimmest));
setItemInColumn(table, "Sat Lim", QString::number(params.saturationLimit));
}
//This adds a solution to the Results Table
//To add, remove, or change the way certain columns are filled when a solve is finished, edit them here.
void MainWindow::addSolutionToTable(FITSImage::Solution solution)
{
QTableWidget *table = ui->resultsTable;
SSolver::Parameters params = stellarSolver.getCurrentParameters();
setItemInColumn(table, "Avg Time", QString::number(totalTime / currentTrial));
setItemInColumn(table, "# Trials", QString::number(currentTrial));
setItemInColumn(table, "Command", stellarSolver.getCommandString());
setItemInColumn(table, "Profile", params.listName);
//Astrometry Parameters
setItemInColumn(table, "Pos?", stellarSolver.property("UsePosition").toString());
setItemInColumn(table, "Scale?", stellarSolver.property("UseScale").toString());
setItemInColumn(table, "Resort?", QVariant(params.resort).toString());
setItemInColumn(table, "AutoDown", QVariant(params.autoDownsample).toString());
setItemInColumn(table, "Down", QVariant(params.downsample).toString());
setItemInColumn(table, "in ||", QVariant(params.inParallel).toString());
setItemInColumn(table, "Multi", stellarSolver.getMultiAlgoString());
setItemInColumn(table, "# Thread", QVariant(stellarSolver.getNumThreads()).toString());
//Results
setItemInColumn(table, "RA (J2000)", StellarSolver::raString(solution.ra));
setItemInColumn(table, "DEC (J2000)", StellarSolver::decString(solution.dec));
if(solution.raError == 0)
setItemInColumn(table, "RA ERR \"", "--");
else
setItemInColumn(table, "RA ERR \"", QString::number(solution.raError, 'f', 2));
if(solution.decError == 0)
setItemInColumn(table, "DEC ERR \"", "--");
else
setItemInColumn(table, "DEC ERR \"", QString::number(solution.decError, 'f', 2));
setItemInColumn(table, "Orientation˚", QString::number(solution.orientation));
setItemInColumn(table, "Field Width \'", QString::number(solution.fieldWidth));
setItemInColumn(table, "Field Height \'", QString::number(solution.fieldHeight));
setItemInColumn(table, "PixScale \"", QString::number(solution.pixscale));
setItemInColumn(table, "Parity", FITSImage::getShortParityText(solution.parity).toUtf8().data());
setItemInColumn(table, "Channel", FITSImage::getColorChannelText(stellarSolver.getColorChannel()));
setItemInColumn(table, "Field", ui->fileNameDisplay->text());
}
//I wrote this method to hide certain columns in the Results Table if the user wants to reduce clutter in the table.
void MainWindow::updateHiddenResultsTableColumns()
{
QTableWidget *table = ui->resultsTable;
//Star Extractor Params
setColumnHidden(table, "Shape", !showExtractorParams);
setColumnHidden(table, "Kron", !showExtractorParams);
setColumnHidden(table, "Subpix", !showExtractorParams);
setColumnHidden(table, "r_min", !showExtractorParams);
setColumnHidden(table, "minarea", !showExtractorParams);
setColumnHidden(table, "thresh_mult", !showExtractorParams);
setColumnHidden(table, "thresh_off", !showExtractorParams);
setColumnHidden(table, "d_thresh", !showExtractorParams);
setColumnHidden(table, "d_cont", !showExtractorParams);
setColumnHidden(table, "clean", !showExtractorParams);
setColumnHidden(table, "clean param", !showExtractorParams);
setColumnHidden(table, "conv", !showExtractorParams);
setColumnHidden(table, "fwhm", !showExtractorParams);
setColumnHidden(table, "part", !showExtractorParams);
//Star Filtering Parameters
setColumnHidden(table, "Max Size", !showExtractorParams);
setColumnHidden(table, "Min Size", !showExtractorParams);
setColumnHidden(table, "Max Ell", !showExtractorParams);
setColumnHidden(table, "Ini Keep", !showExtractorParams);
setColumnHidden(table, "Keep #", !showExtractorParams);
setColumnHidden(table, "Cut Bri", !showExtractorParams);
setColumnHidden(table, "Cut Dim", !showExtractorParams);
setColumnHidden(table, "Sat Lim", !showExtractorParams);
//Astrometry Parameters
setColumnHidden(table, "Pos?", !showAstrometryParams);
setColumnHidden(table, "Scale?", !showAstrometryParams);
setColumnHidden(table, "Resort?", !showAstrometryParams);
setColumnHidden(table, "AutoDown", !showAstrometryParams);
setColumnHidden(table, "Down", !showAstrometryParams);
setColumnHidden(table, "in ||", !showAstrometryParams);
setColumnHidden(table, "Multi", !showAstrometryParams);
setColumnHidden(table, "# Thread", !showAstrometryParams);
//Results
setColumnHidden(table, "RA (J2000)", !showSolutionDetails);
setColumnHidden(table, "DEC (J2000)", !showSolutionDetails);
setColumnHidden(table, "RA ERR \"", !showSolutionDetails);
setColumnHidden(table, "DEC ERR \"", !showSolutionDetails);
setColumnHidden(table, "Orientation˚", !showSolutionDetails);
setColumnHidden(table, "Field Width \'", !showSolutionDetails);
setColumnHidden(table, "Field Height \'", !showSolutionDetails);
setColumnHidden(table, "PixScale \"", !showSolutionDetails);
setColumnHidden(table, "Parity", !showSolutionDetails);
}
//This will write the Results table to a csv file if the user desires
//Then the user can analyze the solution information in more detail to try to perfect star extractor and solver parameters
void MainWindow::saveResultsTable()
{
if (ui->resultsTable->rowCount() == 0)
return;
QUrl exportFile = QFileDialog::getSaveFileUrl(this, "Export Results Table", dirPath,
"CSV File (*.csv)");
if (exportFile.isEmpty()) // if user presses cancel
return;
if (exportFile.toLocalFile().endsWith(QLatin1String(".csv")) == false)
exportFile.setPath(exportFile.toLocalFile() + ".csv");
QString path = exportFile.toLocalFile();
if (QFile::exists(path))
{
int r = QMessageBox::question(this, "Overwrite it?",
QString("A file named \"%1\" already exists. Do you want to overwrite it?").arg(exportFile.fileName()));
if (r == QMessageBox::No)
return;
}
if (!exportFile.isValid())
{
QString message = QString("Invalid URL: %1").arg(exportFile.url());
QMessageBox::warning(this, "Invalid URL", message);
return;
}
QFile file;
file.setFileName(path);
if (!file.open(QIODevice::WriteOnly))
{
QString message = QString("Unable to write to file %1").arg(path);
QMessageBox::warning(this, "Could Not Open File", message);
return;
}
QTextStream outstream(&file);
for (int c = 0; c < ui->resultsTable->columnCount(); c++)
{
outstream << ui->resultsTable->horizontalHeaderItem(c)->text() << ',';
}
outstream << "\n";
for (int r = 0; r < ui->resultsTable->rowCount(); r++)
{
for (int c = 0; c < ui->resultsTable->columnCount(); c++)
{
QTableWidgetItem *cell = ui->resultsTable->item(r, c);
if (cell)
outstream << cell->text() << ',';
else
outstream << " " << ',';
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
outstream << Qt::endl;
#else
outstream << endl;
#endif
}
QMessageBox::information(this, "Message", QString("Results Table Saved as: %1").arg(path));
file.close();
}
//This will write the Star table to a csv file if the user desires
//Then the user can analyze the solution information in more detail to try to analyze the stars found or try to perfect star extractor parameters
void MainWindow::saveStarTable()
{
if (ui->starTable->rowCount() == 0)
return;
QUrl exportFile = QFileDialog::getSaveFileUrl(this, "Export Star Table", dirPath,
"CSV File (*.csv)");
if (exportFile.isEmpty()) // if user presses cancel
return;
if (exportFile.toLocalFile().endsWith(QLatin1String(".csv")) == false)
exportFile.setPath(exportFile.toLocalFile() + ".csv");
QString path = exportFile.toLocalFile();
if (QFile::exists(path))
{
int r = QMessageBox::question(this, "Overwrite it?",
QString("A file named \"%1\" already exists. Do you want to overwrite it?").arg(exportFile.fileName()));
if (r == QMessageBox::No)
return;
}
if (!exportFile.isValid())
{
QString message = QString("Invalid URL: %1").arg(exportFile.url());
QMessageBox::warning(this, "Invalid URL", message);
return;
}
QFile file;
file.setFileName(path);
if (!file.open(QIODevice::WriteOnly))
{
QString message = QString("Unable to write to file %1").arg(path);
QMessageBox::warning(this, "Could Not Open File", message);
return;
}
QTextStream outstream(&file);
for (int c = 0; c < ui->starTable->columnCount(); c++)
{
outstream << ui->starTable->horizontalHeaderItem(c)->text() << ',';
}
outstream << "\n";
for (int r = 0; r < ui->starTable->rowCount(); r++)
{
for (int c = 0; c < ui->starTable->columnCount(); c++)
{
QTableWidgetItem *cell = ui->starTable->item(r, c);
if (cell)
outstream << cell->text() << ',';
else
outstream << " " << ',';
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
outstream << Qt::endl;
#else
outstream << endl;
#endif
}
QMessageBox::information(this, "Message", QString("Star Table Saved as: %1").arg(path));
file.close();
}
void MainWindow::saveOptionsProfiles()
{
QString fileURL = QFileDialog::getSaveFileName(nullptr, "Save Options Profiles", dirPath,
"INI files(*.ini)");
if (fileURL.isEmpty())
return;
QSettings settings(fileURL, QSettings::IniFormat);
for(int i = 0 ; i < optionsList.count(); i++)
{
SSolver::Parameters params = optionsList.at(i);
settings.beginGroup(params.listName);
QMap<QString, QVariant> map = SSolver::Parameters::convertToMap(params);
QMapIterator<QString, QVariant> it(map);
while(it.hasNext())
{
it.next();
settings.setValue(it.key(), it.value());
}
settings.endGroup();
}
}
void MainWindow::loadOptionsProfiles()
{
QString fileURL = QFileDialog::getOpenFileName(nullptr, "Load Options Profiles File", dirPath,
"INI files(*.ini)");
if (fileURL.isEmpty())
return;
if(!QFileInfo::exists(fileURL))
{
QMessageBox::warning(this, "Message", "The file doesn't exist");
return;
}
ui->optionsProfile->blockSignals(true);
ui->optionsProfile->clear();
ui->optionsProfile->addItem("Unsaved Options");
optionsList = StellarSolver::loadSavedOptionsProfiles(fileURL);
foreach(SSolver::Parameters params, optionsList)
ui->optionsProfile->addItem(params.listName);
ui->optionsProfile->blockSignals(false);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
QSettings programSettings("Astrometry Freeware", "StellarSolver");
programSettings.setValue("setPathsIndex", ui->setPathsAutomatically->currentIndex());
programSettings.setValue("sextractorBinaryPath", ui->sextractorPath->text());
programSettings.setValue("starExtractionProfile", ui->extractionProfile->currentIndex());
programSettings.setValue("confPath", ui->configFilePath->text());
programSettings.setValue("solverPath", ui->solverPath->text());
programSettings.setValue("solverProfile", ui->solverProfile->currentIndex());
programSettings.setValue("astapBinaryPath", ui->astapPath->text());
programSettings.setValue("watneyBinaryPath", ui->watneyPath->text());
programSettings.setValue("wcsPath", ui->wcsPath->text());
programSettings.setValue("cleanupTemporaryFiles", ui->cleanupTemp->isChecked());
programSettings.setValue("autoGenerateAstroConfig", ui->generateAstrometryConfig->isChecked());
programSettings.setValue("onlineServer", ui->onlineServer->text());
programSettings.setValue("apiKey", ui->apiKey->text());
QStringList items;
for(int i = 0; i < ui->indexFolderPaths->count(); i++)
{
items << ui->indexFolderPaths->itemText(i);
}
programSettings.setValue("indexFolderPaths", items.join(","));
programSettings.sync();
event->accept();
}
|