diff --git a/kstars/ekos/align/opsastrometryindexfiles.cpp b/kstars/ekos/align/opsastrometryindexfiles.cpp index c581270a4..d152cbcbe 100644 --- a/kstars/ekos/align/opsastrometryindexfiles.cpp +++ b/kstars/ekos/align/opsastrometryindexfiles.cpp @@ -1,551 +1,553 @@ #include "opsastrometryindexfiles.h" #include "align.h" #include "kstars.h" #include "ksutils.h" #include "Options.h" #include "kspaths.h" #include "ksnotification.h" #include #include namespace Ekos { OpsAstrometryIndexFiles::OpsAstrometryIndexFiles(Align *parent) : QDialog(KStars::Instance()) { setupUi(this); downloadSpeed = 100; actualdownloadSpeed = downloadSpeed; alignModule = parent; manager = new QNetworkAccessManager(); //Get a pointer to the KConfigDialog // m_ConfigDialog = KConfigDialog::exists( "alignsettings" ); connect(openIndexFileDirectory, SIGNAL(clicked()), this, SLOT(slotOpenIndexFileDirectory())); astrometryIndex[2.8] = "00"; astrometryIndex[4.0] = "01"; astrometryIndex[5.6] = "02"; astrometryIndex[8] = "03"; astrometryIndex[11] = "04"; astrometryIndex[16] = "05"; astrometryIndex[22] = "06"; astrometryIndex[30] = "07"; astrometryIndex[42] = "08"; astrometryIndex[60] = "09"; astrometryIndex[85] = "10"; astrometryIndex[120] = "11"; astrometryIndex[170] = "12"; astrometryIndex[240] = "13"; astrometryIndex[340] = "14"; astrometryIndex[480] = "15"; astrometryIndex[680] = "16"; astrometryIndex[1000] = "17"; astrometryIndex[1400] = "18"; astrometryIndex[2000] = "19"; QList checkboxes = findChildren(); - connect(indexLocations,static_cast(&QComboBox::currentIndexChanged), this, &OpsAstrometryIndexFiles::slotUpdate); + connect(indexLocations, static_cast(&QComboBox::currentIndexChanged), this, &OpsAstrometryIndexFiles::slotUpdate); for (auto &checkBox : checkboxes) { - connect(checkBox, &QCheckBox::clicked, this,&OpsAstrometryIndexFiles::downloadOrDeleteIndexFiles); + connect(checkBox, &QCheckBox::clicked, this, &OpsAstrometryIndexFiles::downloadOrDeleteIndexFiles); } QList progressBars = findChildren(); QList qLabels = findChildren(); QList qButtons = findChildren(); for (auto &bar : progressBars) { if(bar->objectName().contains("progress")) { bar->setVisible(false); bar->setTextVisible(false); } } for (auto &button : qButtons) { if(button->objectName().contains("cancel")) { button->setVisible(false); } } for (QLabel * label : qLabels) { if(label->text().contains("info") || label->text().contains("perc")) { label->setVisible(false); } } } void OpsAstrometryIndexFiles::showEvent(QShowEvent *) { - QStringList astrometryDataDirs =KSUtils::getAstrometryDataDirs(); + QStringList astrometryDataDirs = KSUtils::getAstrometryDataDirs(); if (astrometryDataDirs.count() == 0) return; indexLocations->clear(); - if(astrometryDataDirs.count()>1) + if(astrometryDataDirs.count() > 1) indexLocations->addItem("All Sources"); indexLocations->addItems(astrometryDataDirs); slotUpdate(); } void OpsAstrometryIndexFiles::slotUpdate() { QList checkboxes = findChildren(); for (auto &checkBox : checkboxes) { checkBox->setChecked(false); } - if(indexLocations->count()==0) + if(indexLocations->count() == 0) return; double fov_w, fov_h, fov_pixscale; // Values in arcmins. Scale in arcsec per pixel alignModule->getFOVScale(fov_w, fov_h, fov_pixscale); double fov_check = qMax(fov_w, fov_h); FOVOut->setText(QString("%1' x %2'").arg(QString::number(fov_w, 'f', 2), QString::number(fov_h, 'f', 2))); QStringList nameFilter("*.fits"); if (Options::astrometrySolverIsInternal()) KSUtils::configureLocalAstrometryConfIfNecessary(); QStringList astrometryDataDirs = KSUtils::getAstrometryDataDirs();; bool allDirsSelected = (indexLocations->currentIndex() == 0 && astrometryDataDirs.count() > 1); bool folderIsWriteable; QStringList astrometryDataDirsToIndex; if(allDirsSelected) { folderDetails->setText(i18n("Downloads Disabled, this is not a directory, it is a list of all index files.")); folderIsWriteable = false; astrometryDataDirsToIndex = astrometryDataDirs; openIndexFileDirectory->setEnabled(false); } else { QString folderPath = indexLocations->currentText(); folderIsWriteable = QFileInfo(folderPath).isWritable(); if(folderIsWriteable) folderDetails->setText(i18n("Downloads Enabled, the directory exists and is writeable.")); else folderDetails->setText(i18n("Downloads Disabled, directory permissions issue.")); if(!QFileInfo(folderPath).exists()) folderDetails->setText(i18n("Downloads Disabled, directory does not exist.")); astrometryDataDirsToIndex << folderPath; openIndexFileDirectory->setEnabled(true); } folderDetails->setCursorPosition(0); //This loop checks all the folders that are supposed to be checked for the files //It checks the box if it finds them - for(QString astrometryDataDir:astrometryDataDirsToIndex) + for(QString astrometryDataDir : astrometryDataDirsToIndex) { QDir directory(astrometryDataDir); QStringList indexList = directory.entryList(nameFilter); for (auto &indexName : indexList) { if (fileCountMatches(directory, indexName)) { indexName = indexName.replace('-', '_').left(10); QCheckBox *indexCheckBox = findChild(indexName); if (indexCheckBox) indexCheckBox->setChecked(true); } } } for (auto &checkBox : checkboxes) { checkBox->setEnabled(folderIsWriteable); checkBox->setIcon(QIcon(":/icons/astrometry-optional.svg")); checkBox->setToolTip(i18n("Optional")); checkBox->setStyleSheet(""); } float last_skymarksize = 2; for (auto &skymarksize : astrometryIndex.keys()) { if ((skymarksize >= 0.40 * fov_check && skymarksize <= 0.9 * fov_check) || (fov_check > last_skymarksize && fov_check < skymarksize)) { QString indexName1 = "index_41" + astrometryIndex.value(skymarksize); QString indexName2 = "index_42" + astrometryIndex.value(skymarksize); QCheckBox *indexCheckBox1 = findChild(indexName1); QCheckBox *indexCheckBox2 = findChild(indexName2); if (indexCheckBox1) { indexCheckBox1->setIcon(QIcon(":/icons/astrometry-required.svg")); indexCheckBox1->setToolTip(i18n("Required")); } if (indexCheckBox2) { indexCheckBox2->setIcon(QIcon(":/icons/astrometry-required.svg")); indexCheckBox2->setToolTip(i18n("Required")); } } else if (skymarksize >= 0.10 * fov_check && skymarksize <= fov_check) { QString indexName1 = "index_41" + astrometryIndex.value(skymarksize); QString indexName2 = "index_42" + astrometryIndex.value(skymarksize); QCheckBox *indexCheckBox1 = findChild(indexName1); QCheckBox *indexCheckBox2 = findChild(indexName2); if (indexCheckBox1) { indexCheckBox1->setIcon(QIcon(":/icons/astrometry-recommended.svg")); indexCheckBox1->setToolTip(i18n("Recommended")); } if (indexCheckBox2) { indexCheckBox2->setIcon(QIcon(":/icons/astrometry-recommended.svg")); indexCheckBox2->setToolTip(i18n("Recommended")); } } last_skymarksize = skymarksize; } //This loop goes over all the directories and adds a stylesheet to change the look of the checkbox text //if the File is installed in any directory. Note that this indicator is then used below in the //Index File download function to check if they really want to do install a file that is installed. - for(QString astrometryDataDir:astrometryDataDirs) + for(QString astrometryDataDir : astrometryDataDirs) { QDir directory(astrometryDataDir); QStringList indexList = directory.entryList(nameFilter); for (auto &indexName : indexList) { if (fileCountMatches(directory, indexName)) { indexName = indexName.replace('-', '_').left(10); QCheckBox *indexCheckBox = findChild(indexName); if (indexCheckBox) indexCheckBox->setStyleSheet("QCheckBox{font-weight: bold; color:green}"); } } } } bool OpsAstrometryIndexFiles::fileCountMatches(QDir directory, QString indexName) { QString indexNameMatch = indexName.left(10) + "*.fits"; QStringList list = directory.entryList(QStringList(indexNameMatch)); int count = 0; if(indexName.contains("4207") || indexName.contains("4206") || indexName.contains("4205")) count = 12; else if(indexName.contains("4204") || indexName.contains("4203") || indexName.contains("4202") || indexName.contains("4201") || indexName.contains("4200")) count = 48; else count = 1; return list.count() == count; } void OpsAstrometryIndexFiles::slotOpenIndexFileDirectory() { - if(indexLocations->count()==0) + if(indexLocations->count() == 0) return; QUrl path = QUrl::fromLocalFile(indexLocations->currentText()); QDesktopServices::openUrl(path); } bool OpsAstrometryIndexFiles::astrometryIndicesAreAvailable() { QNetworkReply *response = manager->get(QNetworkRequest(QUrl("http://broiler.astrometry.net"))); QTimer timeout(this); timeout.setInterval(5000); timeout.setSingleShot(true); timeout.start(); while (!response->isFinished()) { if (!timeout.isActive()) { response->deleteLater(); return false; } qApp->processEvents(); } timeout.stop(); bool wasSuccessful = (response->error() == QNetworkReply::NoError); response->deleteLater(); return wasSuccessful; } void OpsAstrometryIndexFiles::downloadIndexFile(const QString &URL, const QString &fileN, QCheckBox *checkBox, int currentIndex, int maxIndex, double fileSize) { QTime downloadTime; downloadTime.start(); QString indexString = QString::number(currentIndex); if (currentIndex < 10) indexString = '0' + indexString; QString indexSeriesName = checkBox->text().remove('&'); QProgressBar *indexDownloadProgress = findChild(indexSeriesName.replace('-', '_').left(10) + "_progress"); QLabel *indexDownloadInfo = findChild(indexSeriesName.replace('-', '_').left(10) + "_info"); QPushButton *indexDownloadCancel = findChild(indexSeriesName.replace('-', '_').left(10) + "_cancel"); QLabel *indexDownloadPerc = findChild(indexSeriesName.replace('-', '_').left(10) + "_perc"); setDownloadInfoVisible(indexSeriesName, checkBox, true); if(indexDownloadInfo) { if (indexDownloadProgress && maxIndex > 0) indexDownloadProgress->setValue(currentIndex * 100 / maxIndex); indexDownloadInfo->setText("(" + QString::number(currentIndex) + '/' + QString::number(maxIndex + 1) + ") "); } QString indexURL = URL; indexURL.replace('*', indexString); QNetworkReply *response = manager->get(QNetworkRequest(QUrl(indexURL))); //Shut it down after too much time elapses. //If the filesize is less than 4 MB, it sets the timeout for 1 minute or 60000 ms. //If it's larger, it assumes a bad download rate of 1 Mbps (100 bytes/ms) //and the calculation estimates the time in milliseconds it would take to download. int timeout = 60000; if(fileSize > 4000000) timeout = fileSize / downloadSpeed; //qDebug()<<"Filesize: "<< fileSize << ", timeout: " << timeout; QMetaObject::Connection *cancelConnection = new QMetaObject::Connection(); QMetaObject::Connection *replyConnection = new QMetaObject::Connection(); QMetaObject::Connection *percentConnection = new QMetaObject::Connection(); if(indexDownloadPerc) { *percentConnection = connect(response, &QNetworkReply::downloadProgress, [ = ](qint64 bytesReceived, qint64 bytesTotal) { if (indexDownloadProgress) { indexDownloadProgress->setValue(bytesReceived); indexDownloadProgress->setMaximum(bytesTotal); } indexDownloadPerc->setText(QString::number(bytesReceived * 100 / bytesTotal) + '%'); }); } timeoutTimer.disconnect(); connect(&timeoutTimer, &QTimer::timeout, [&]() { KSNotification::error(i18n("Download Timed out. Either the network is not fast enough, the file is not accessible, or you are not connected.")); disconnectDownload(cancelConnection, replyConnection, percentConnection); if(response) { response->abort(); response->deleteLater(); } setDownloadInfoVisible(indexSeriesName, checkBox, false); }); timeoutTimer.start(timeout); *cancelConnection = connect(indexDownloadCancel, &QPushButton::clicked, [ = ]() { qDebug() << "Download Cancelled."; timeoutTimer.stop(); disconnectDownload(cancelConnection, replyConnection, percentConnection); if(response) { response->abort(); response->deleteLater(); } setDownloadInfoVisible(indexSeriesName, checkBox, false); }); *replyConnection = connect(response, &QNetworkReply::finished, this, [ = ]() { timeoutTimer.stop(); if(response) { disconnectDownload(cancelConnection, replyConnection, percentConnection); setDownloadInfoVisible(indexSeriesName, checkBox, false); response->deleteLater(); if (response->error() != QNetworkReply::NoError) return; QByteArray responseData = response->readAll(); QString indexFileN = fileN; indexFileN.replace('*', indexString); QFile file(indexFileN); if (QFileInfo(QFileInfo(file).path()).isWritable()) { if (!file.open(QIODevice::WriteOnly)) { KSNotification::error(i18n("File Write Error")); slotUpdate(); return; } else { file.write(responseData.data(), responseData.size()); file.close(); int downloadedFileSize = QFileInfo(file).size(); int dtime = downloadTime.elapsed(); actualdownloadSpeed = (actualdownloadSpeed + (downloadedFileSize / dtime)) / 2; qDebug() << "Filesize: " << downloadedFileSize << ", time: " << dtime << ", inst speed: " << downloadedFileSize / dtime << ", averaged speed: " << actualdownloadSpeed; } } else { KSNotification::error(i18n("Astrometry Folder Permissions Error")); } if (currentIndex == maxIndex) { slotUpdate(); } else downloadIndexFile(URL, fileN, checkBox, currentIndex + 1, maxIndex, fileSize); } }); } void OpsAstrometryIndexFiles::setDownloadInfoVisible(QString indexSeriesName, QCheckBox *checkBox, bool set) { + Q_UNUSED(checkBox); + QProgressBar *indexDownloadProgress = findChild(indexSeriesName.replace('-', '_').left(10) + "_progress"); QLabel *indexDownloadInfo = findChild(indexSeriesName.replace('-', '_').left(10) + "_info"); QPushButton *indexDownloadCancel = findChild(indexSeriesName.replace('-', '_').left(10) + "_cancel"); QLabel *indexDownloadPerc = findChild(indexSeriesName.replace('-', '_').left(10) + "_perc"); if (indexDownloadProgress) indexDownloadProgress->setVisible(set); if (indexDownloadInfo) indexDownloadInfo->setVisible(set); if (indexDownloadCancel) indexDownloadCancel->setVisible(set); if (indexDownloadPerc) indexDownloadPerc->setVisible(set); } void OpsAstrometryIndexFiles::disconnectDownload(QMetaObject::Connection *cancelConnection, QMetaObject::Connection *replyConnection, QMetaObject::Connection *percentConnection) { if(cancelConnection) disconnect(*cancelConnection); if(replyConnection) disconnect(*replyConnection); if(percentConnection) disconnect(*percentConnection); } void OpsAstrometryIndexFiles::downloadOrDeleteIndexFiles(bool checked) { QCheckBox *checkBox = qobject_cast(QObject::sender()); if (indexLocations->count() == 0) return; QString astrometryDataDir = indexLocations->currentText(); if(!QFileInfo(astrometryDataDir).exists()) { KSNotification::sorry(i18n("The selected Index File directory does not exist. Please either create it or choose another.")); } if (checkBox) { QString indexSeriesName = checkBox->text().remove('&'); QString filePath = astrometryDataDir + '/' + indexSeriesName; QString fileNumString = indexSeriesName.mid(8, 2); int indexFileNum = fileNumString.toInt(); if (checked) { if(!checkBox->styleSheet().isEmpty()) //This means that the checkbox has a stylesheet so the index file was installed someplace. { if (KMessageBox::Cancel == KMessageBox::warningContinueCancel( nullptr, i18n("The file %1 already exists in another directory. Are you sure you want to download it to this directory as well?", indexSeriesName), i18n("Install File(s)"), KStandardGuiItem::cont(), KStandardGuiItem::cancel(), "install_index_files_warning")) { slotUpdate(); return; } } checkBox->setChecked(!checked); if (astrometryIndicesAreAvailable()) { QString URL; if (indexSeriesName.startsWith(QLatin1String("index-41"))) URL = "http://broiler.astrometry.net/~dstn/4100/" + indexSeriesName; else if (indexSeriesName.startsWith(QLatin1String("index-42"))) URL = "http://broiler.astrometry.net/~dstn/4200/" + indexSeriesName; int maxIndex = 0; if (indexFileNum < 8 && URL.contains("*")) { maxIndex = 11; if (indexFileNum < 5) maxIndex = 47; } double fileSize = 1E11 * qPow(astrometryIndex.key(fileNumString), -1.909); //This estimates the file size based on skymark size obtained from the index number. if(maxIndex != 0) fileSize /= maxIndex; //FileSize is divided between multiple files for some index series. downloadIndexFile(URL, filePath, checkBox, 0, maxIndex, fileSize); } else { KSNotification::sorry(i18n("Could not contact Astrometry Index Server: broiler.astrometry.net")); } } else { if (KMessageBox::Continue == KMessageBox::warningContinueCancel( nullptr, i18n("Are you sure you want to delete these index files? %1", indexSeriesName), i18n("Delete File(s)"), KStandardGuiItem::cont(), KStandardGuiItem::cancel(), "delete_index_files_warning")) { if (QFileInfo(astrometryDataDir).isWritable()) { QStringList nameFilter("*.fits"); QDir directory(astrometryDataDir); QStringList indexList = directory.entryList(nameFilter); for (auto &fileName : indexList) { if (fileName.contains(indexSeriesName.left(10))) { if (!directory.remove(fileName)) { KSNotification::error(i18n("File Delete Error")); slotUpdate(); return; } slotUpdate(); } } } else { KSNotification::error(i18n("Astrometry Folder Permissions Error")); slotUpdate(); } } } } } } diff --git a/kstars/tools/eclipsetool/lunareclipsehandler.cpp b/kstars/tools/eclipsetool/lunareclipsehandler.cpp index 69551df27..815938cf4 100644 --- a/kstars/tools/eclipsetool/lunareclipsehandler.cpp +++ b/kstars/tools/eclipsetool/lunareclipsehandler.cpp @@ -1,246 +1,256 @@ /*************************************************************************** lunareclipsehandler.cpp - K Desktop Planetarium ------------------- begin : Tue 18/09/2018 copyright : (C) 2018 Valentin Boettcher email : valentin@boettcher.cf ***************************************************************************/ /*************************************************************************** * * * This program 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. * * * ***************************************************************************/ #include "lunareclipsehandler.h" #include "skymapcomposite.h" #include "solarsystemcomposite.h" #include "dms.h" LunarEclipseHandler::LunarEclipseHandler(QObject * parent) : EclipseHandler(parent), m_sun(), m_moon(), m_shadow(&m_moon, &m_sun, &m_Earth) { } EclipseHandler::EclipseVector LunarEclipseHandler::computeEclipses(long double startJD, long double endJD) { m_mode = CLOSEST_APPROACH; const long double SEARCH_INTERVAL = 5.l; // Days QVector eclipses; QVector fullMoons = getFullMoons(startJD, endJD); int total = fullMoons.length(); if (total == 0) return eclipses; - float step = 1/total; + float step = 1 / total; float progress = 0; - connect(this, &ApproachSolver::solverMadeProgress, this, [&, this] (int dProgress) { + connect(this, &ApproachSolver::solverMadeProgress, this, [ &, this] (int dProgress) + { float tmpProgress = roundf(progress + step * dProgress); - if (tmpProgress > progress) { + if (tmpProgress > progress) + { progress = tmpProgress; emit signalProgress(static_cast(progress)); } }); - for(auto date : fullMoons) { - findClosestApproach(date, date + SEARCH_INTERVAL, [&eclipses, this] (long double JD, dms) { + for(auto date : fullMoons) + { + findClosestApproach(date, date + SEARCH_INTERVAL, [&eclipses, this] (long double JD, dms) + { EclipseEvent::ECLIPSE_TYPE type; updatePositions(JD); KSEarthShadow::ECLIPSE_TYPE extended_type = m_shadow.getEclipseType(); - switch (extended_type) { - case KSEarthShadow::FULL_PENUMBRA: - case KSEarthShadow::FULL_UMBRA: - type = EclipseEvent::FULL; - break; - case KSEarthShadow::NONE: - return; - default: - type = EclipseEvent::PARTIAL; - break; + switch (extended_type) + { + case KSEarthShadow::FULL_PENUMBRA: + case KSEarthShadow::FULL_UMBRA: + type = EclipseEvent::FULL; + break; + case KSEarthShadow::NONE: + return; + default: + type = EclipseEvent::PARTIAL; + break; } EclipseEvent_s event = std::make_shared(JD, *getGeoLocation(), type, extended_type); emit signalEventFound(event); eclipses.append(event); }); progress++; - emit signalProgress(static_cast(roundf(100*(progress/total)))); + emit signalProgress(static_cast(roundf(100 * (progress / total)))); } emit signalProgress(100); emit signalComputationFinished(); return eclipses; } // FIXME: (Valentin) This doesn't work for now. We need another method. LunarEclipseDetails LunarEclipseHandler::findEclipseDetails(LunarEclipseEvent *event) { -// const long double INTERVAL = 1.l; + Q_UNUSED(event); + // const long double INTERVAL = 1.l; -// const long double JD = event->getJD(); -// const long double start = JD - INTERVAL; -// const long double stop = JD + INTERVAL; + // const long double JD = event->getJD(); + // const long double start = JD - INTERVAL; + // const long double stop = JD + INTERVAL; LunarEclipseDetails details; -// details.available = true; -// details.eclipseTimes.insert(JD, LunarEclipseDetails::CLOSEST_APPROACH); + // details.available = true; + // details.eclipseTimes.insert(JD, LunarEclipseDetails::CLOSEST_APPROACH); -// auto type = event->getDetailedType(); -// auto findBoth = [&](LunarEclipseDetails::EVENT ev1 /* first (temporal) */, LunarEclipseDetails::EVENT ev2) { -// QMap tmpApproaches; + // auto type = event->getDetailedType(); + // auto findBoth = [&](LunarEclipseDetails::EVENT ev1 /* first (temporal) */, LunarEclipseDetails::EVENT ev2) { + // QMap tmpApproaches; -// QPair out; -// findPrecise(&out, JD, 0.001, -1); -// details.eclipseTimes.insert(out.first, ev1); + // QPair out; + // findPrecise(&out, JD, 0.001, -1); + // details.eclipseTimes.insert(out.first, ev1); -// findPrecise(&out, JD, 0.001, 1); -// details.eclipseTimes.insert(out.first, ev2); -// }; + // findPrecise(&out, JD, 0.001, 1); + // details.eclipseTimes.insert(out.first, ev2); + // }; -// // waterfall method... + // // waterfall method... -// if(type == KSEarthShadow::NONE) { -// details.available = false; -// return details; -// } + // if(type == KSEarthShadow::NONE) { + // details.available = false; + // return details; + // } -// if(type == KSEarthShadow::FULL_UMBRA) { -// m_mode = UMBRA_IMMERSION; -// findBoth(LunarEclipseDetails::BEGIN_FULL_PENUMRA, LunarEclipseDetails::END_FULL_PENUMRA); + // if(type == KSEarthShadow::FULL_UMBRA) { + // m_mode = UMBRA_IMMERSION; + // findBoth(LunarEclipseDetails::BEGIN_FULL_PENUMRA, LunarEclipseDetails::END_FULL_PENUMRA); -// m_mode = UMBRA_CONTACT; -// findBoth(LunarEclipseDetails::BEGIN_UMBRA_CONTACT, LunarEclipseDetails::END_UMBRA_CONTACT); -// } + // m_mode = UMBRA_CONTACT; + // findBoth(LunarEclipseDetails::BEGIN_UMBRA_CONTACT, LunarEclipseDetails::END_UMBRA_CONTACT); + // } -//// if(type == KSEarthShadow::FULL_PENUMBRA || type == KSEarthShadow::FULL_UMBRA) { + //// if(type == KSEarthShadow::FULL_PENUMBRA || type == KSEarthShadow::FULL_UMBRA) { -//// m_mode = UMR -//// }; - return details; + //// m_mode = UMR + //// }; + return details; } LunarEclipseHandler::~LunarEclipseHandler() { } void LunarEclipseHandler::updatePositions(long double jd) { KStarsDateTime t(jd); KSNumbers num(jd); CachingDms LST(getGeoLocation()->GSTtoLST(t.gst())); const CachingDms * LAT = getGeoLocation()->lat(); m_Earth.findPosition(&num); m_sun.findPosition(&num, LAT, &LST, &m_Earth); m_moon.findPosition(&num, LAT, &LST, &m_Earth); m_shadow.findPosition(&num, LAT, &LST, &m_Earth); } dms LunarEclipseHandler::findDistance() { dms moon_rad = dms(m_moon.angSize() / 120); dms pen_rad = dms(m_shadow.getPenumbraAngSize() / 60); dms um_rad = dms(m_shadow.getUmbraAngSize() / 60); dms dist = findSkyPointDistance(&m_shadow, &m_moon); - switch (m_mode) { - case CLOSEST_APPROACH: - return dist; - case PENUMBRA_CONTACT: - return dist - (moon_rad + pen_rad); - case PUNUMBRA_IMMERSION: - return dist + moon_rad - pen_rad; - case UMBRA_CONTACT: - return dist - (moon_rad + um_rad); - case UMBRA_IMMERSION: - return dist + moon_rad - um_rad; + switch (m_mode) + { + case CLOSEST_APPROACH: + return dist; + case PENUMBRA_CONTACT: + return dist - (moon_rad + pen_rad); + case PUNUMBRA_IMMERSION: + return dist + moon_rad - pen_rad; + case UMBRA_CONTACT: + return dist - (moon_rad + um_rad); + case UMBRA_IMMERSION: + return dist + moon_rad - um_rad; } return dms(); } double LunarEclipseHandler::getMaxSeparation() { const double SEP_QUALITY = 0.1; // we use the penumbra as meassure :) if(m_mode == CLOSEST_APPROACH) return (m_shadow.getPenumbraAngSize() + m_moon.angSize()) / 60; else return SEP_QUALITY; } QVector LunarEclipseHandler::getFullMoons(long double startJD, long double endJD) { const long double NEXT_STEP = 0.5l; const long double INTERVAL = 26.5l; - long double & currentJD = startJD; + long double ¤tJD = startJD; QVector fullMoons; - while(currentJD <= endJD) { + while(currentJD <= endJD) + { KStarsDateTime t(currentJD); KSNumbers num(currentJD); CachingDms LST = getGeoLocation()->GSTtoLST(t.gst()); m_sun.updateCoords(&num, true, getGeoLocation()->lat(), &LST, true); m_moon.updateCoords(&num, true, getGeoLocation()->lat(), &LST, true); m_moon.findPhase(&m_sun); - if(m_moon.illum() > 0.9) { + if(m_moon.illum() > 0.9) + { fullMoons.append(currentJD); currentJD += INTERVAL; continue; } currentJD += NEXT_STEP; } return fullMoons; } LunarEclipseEvent::LunarEclipseEvent(long double jd, GeoLocation geoPlace, EclipseEvent::ECLIPSE_TYPE type, KSEarthShadow::ECLIPSE_TYPE detailed_type) : EclipseEvent (jd, geoPlace, type), m_detailedType { detailed_type } { m_details.available = false; } QString LunarEclipseEvent::getExtraInfo() { switch(m_detailedType) { - case KSEarthShadow::FULL_UMBRA: - return "Full Umbral"; - case KSEarthShadow::FULL_PENUMBRA: - return "Full Penumbral"; - case KSEarthShadow::PARTIAL: - case KSEarthShadow::NONE: - return ""; + case KSEarthShadow::FULL_UMBRA: + return "Full Umbral"; + case KSEarthShadow::FULL_PENUMBRA: + return "Full Penumbral"; + case KSEarthShadow::PARTIAL: + case KSEarthShadow::NONE: + return ""; } return ""; } SkyObject *LunarEclipseEvent::getEclipsingObjectFromSkyComposite() { return KStarsData::Instance()->skyComposite()->solarSystemComposite()->moon(); } void LunarEclipseEvent::slotShowDetails() { - if(!m_details.available) { + if(!m_details.available) + { LunarEclipseHandler handler; GeoLocation loc = getGeolocation(); handler.setGeoLocation(&loc); handler.findEclipseDetails(this); } }