diff --git a/apps/OpenSpace/ext/launcher/src/profile/horizonsdialog.cpp b/apps/OpenSpace/ext/launcher/src/profile/horizonsdialog.cpp index 5ab9d2e33a..1f5a8a1247 100644 --- a/apps/OpenSpace/ext/launcher/src/profile/horizonsdialog.cpp +++ b/apps/OpenSpace/ext/launcher/src/profile/horizonsdialog.cpp @@ -928,7 +928,7 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { if (std::filesystem::is_regular_file(errorFile)) { std::filesystem::remove(errorFile); } - return true; + break; } case openspace::HorizonsResultCode::Empty: { _errorMsg->setText("The horizons file is empty"); @@ -938,6 +938,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { ); appendLog(msg, LogLevel::Error); } + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::ErrorSize: { @@ -951,6 +953,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { styleLabel(_startLabel, true); styleLabel(_endLabel, true); styleLabel(_stepLabel, true); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::ErrorSpan: @@ -959,6 +963,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { HorizonsDialog::LogLevel::Error ); styleLabel(_stepLabel, true); + + std::filesystem::remove(_horizonsFile.file()); break; case openspace::HorizonsResultCode::ErrorTimeRange: { std::string msg = fmt::format( @@ -974,7 +980,7 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { msg = fmt::format("Latest Horizons error: {}", _latestHorizonsError); appendLog(msg, LogLevel::Error); } - return false; + break; } msg = fmt::format( @@ -983,6 +989,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { ); appendLog(msg, HorizonsDialog::LogLevel::Info); _importTimeButton->show(); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::ErrorNoObserver: { @@ -997,6 +1005,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { ); appendLog(msg, HorizonsDialog::LogLevel::Info); styleLabel(_centerLabel, true); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::ErrorObserverTargetSame: { @@ -1007,6 +1017,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { appendLog(msg, HorizonsDialog::LogLevel::Error); styleLabel(_targetLabel, true); styleLabel(_centerLabel, true); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::ErrorNoData: { @@ -1017,6 +1029,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { _targetName, _observerName, _startTime, _endTime ); appendLog(msg, HorizonsDialog::LogLevel::Error); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::MultipleObserverStations: { @@ -1047,7 +1061,7 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { msg = fmt::format("Latest Horizons error: {}", _latestHorizonsError); appendLog(msg, LogLevel::Error); } - return false; + break; } _chooseObserverCombo->clear(); for (const std::string& station : matchingstations) { @@ -1058,6 +1072,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { } _chooseObserverCombo->setCurrentIndex(0); _chooseObserverCombo->show(); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::MultipleObserver: { @@ -1080,7 +1096,7 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { ); appendLog(msg, LogLevel::Error); } - return false; + break; } _chooseObserverCombo->clear(); for (const std::string& observer : matchingObservers) { @@ -1091,6 +1107,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { } _chooseObserverCombo->setCurrentIndex(0); _chooseObserverCombo->show(); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::ErrorNoTarget: { @@ -1105,6 +1123,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { ); appendLog(msg, HorizonsDialog::LogLevel::Info); styleLabel(_targetLabel, true); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::MultipleTarget: { @@ -1136,7 +1156,7 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { msg = fmt::format("Latest Horizons error: {}", _latestHorizonsError); appendLog(msg, LogLevel::Error); } - return false; + break; } _chooseTargetCombo->clear(); for (const std::string& target : matchingTargets) { @@ -1147,6 +1167,8 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { } _chooseTargetCombo->setCurrentIndex(0); _chooseTargetCombo->show(); + + std::filesystem::remove(_horizonsFile.file()); break; } case openspace::HorizonsResultCode::UnknownError: { @@ -1158,7 +1180,7 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { appendLog(msg, LogLevel::Error); } _errorMsg->setText("An unknown error occured"); - return false; + break; } default: { if (!_latestHorizonsError.empty()) { @@ -1171,8 +1193,6 @@ bool HorizonsDialog::handleResult(openspace::HorizonsResultCode& result) { break; } } - - std::filesystem::remove(_horizonsFile.file()); - return false; + return result == openspace::HorizonsResultCode::Valid; } #endif // OPENSPACE_MODULE_SPACE_ENABLED diff --git a/modules/space/horizonsfile.cpp b/modules/space/horizonsfile.cpp index 5c4cc24ed9..912296f21b 100644 --- a/modules/space/horizonsfile.cpp +++ b/modules/space/horizonsfile.cpp @@ -75,12 +75,13 @@ namespace { return ""; } - size_t startPos = 0; - while ((startPos = string.find(from, startPos)) != std::string::npos) { - string.replace(startPos, from.length(), to); + size_t pos = string.find(from); + while (pos != std::string::npos) { + string.replace(pos, from.length(), to); // In case 'to' contains 'from', ex replacing 'x' with 'yx' - startPos += to.length(); + size_t offset = pos + to.length(); + pos = string.find(from, offset); } return string; } @@ -726,6 +727,33 @@ std::vector HorizonsFile::parseMatches(const std::string& startPhra return std::vector(); } +// Parse the valid time range from the horizons file +// Example of how it can look (MRO): +// Trajectory files (from MRO Nav., JPL) Start (TDB) End (TDB) +// -------------------------------------- ----------------- ----------------- +// mro_cruise 2005-Aug-12 12:42 2006-Mar-10 22:06 +// mro_ab 2006-Mar-10 22:06 2006-Sep-12 06:40 +// misc reconstruction(mro_psp1 - 61) 2006-Sep-12 06:40 2022-Jan-01 01:01 +// mro_psp_rec 2022-Jan-01 01:01 2022-Jan-30 22:40 +// mro_psp 2022-Jan-30 22:40 2022-Apr-04 02:27 +// ******************************************************************************* +// +// Another example (Gaia): +// Trajectory name Start Stop +// -------------------------------------------- ----------- ----------- +// ORB1_20220201_000001 2013-Dec-19 2026-Sep-14 +// ******************************************************************************* +// +// Another example (Tesla): +// Trajectory name Start (TDB) Stop (TDB) +// -------------------------------- ----------------- ----------------- +// tesla_s10 2018-Feb-07 03:00 2090-Jan-01 00:00 +// +// So the number of trajectory files can differ and they can have time info or not. +// The first row is parsed for both the start and end time. +// All other lines are only parsed for the end time and updates the previously parsed end +// time. Assumes that there are no gaps in the data coverage and that the files are sorted +// in respect to time. std::pair HorizonsFile::parseValidTimeRange( const std::string& startPhrase, const std::string& endPhrase, @@ -765,6 +793,7 @@ std::pair HorizonsFile::parseValidTimeRange( // There will be one empty line before the list of time ranges, skip std::getline(fileStream, line); + // In the first file parse both start and end time // From the first line get the start time std::string startTime, endTime; std::getline(fileStream, line); @@ -802,6 +831,7 @@ std::pair HorizonsFile::parseValidTimeRange( return { "", "" }; } + // In the other lines only parse the end time and update it // Get the end time from the last trajectery while (fileStream.good()) { if (line.find(endPhrase) != std::string::npos || line.empty() || line == " ") { diff --git a/modules/space/translation/horizonstranslation.cpp b/modules/space/translation/horizonstranslation.cpp index 31f7ac30d5..33eb02e47b 100644 --- a/modules/space/translation/horizonstranslation.cpp +++ b/modules/space/translation/horizonstranslation.cpp @@ -47,7 +47,7 @@ namespace { "HorizonsTextFile", "Horizons Text File", "This value is the path to the file or files generated by Horizons with " - "either a Vector table or an Observer table with the correct settings." + "either a Vector table or an Observer table with the correct settings (see wiki)." }; struct [[codegen::Dictionary(HorizonsTranslation)]] Parameters {