Skip to content

Commit

Permalink
Added tool to reset TLE sources in Satellites plugin (partially #2458)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed May 28, 2022
1 parent 2a06d6c commit 8bf87aa
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 345 deletions.
137 changes: 68 additions & 69 deletions plugins/Satellites/src/Satellites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,47 @@ bool Satellites::configureGui(bool show)
void Satellites::restoreDefaults(void)
{
restoreDefaultSettings();
restoreDefaultTleSources();
restoreDefaultCatalog();
loadCatalog();
loadSettings();
}

void Satellites::restoreDefaultTleSources()
{
// Format: group name, auto-add flag
const QMap<QString, bool> celestrak={
{ "visual", true }, { "stations", true }, { "last-30-days", false }, { "active", false }, { "analyst", false },
{ "science", true }, { "noaa", false }, { "goes", false }, { "amateur", true }, { "gnss", true },
{ "gps-ops", true }, { "galileo", true }, { "iridium", false }, { "iridium-NEXT", false }, { "geo", false },
{ "weather", false }, { "resource", false }, { "sarsat", false }, { "dmc", false }, { "tdrss", false },
{ "argos", false }, { "intelsat", false }, { "gorizont", false }, { "raduga", false }, { "molniya", false },
{ "orbcomm", false }, { "globalstar", false }, { "x-comm", false }, { "other-comm", false }, { "glo-ops", true },
{ "beidou", true }, { "sbas", false }, { "nnss", false }, { "engineering", false }, { "education", false },
{ "geodetic", false }, { "radar", false }, { "cubesat", false }, { "other", false }, { "oneweb", true },
{ "starlink", true }, { "planet", false }, { "spire", false }
};
// Details: https://www.celestrak.com/NORAD/documentation/gp-data-formats.php
QString celestrackBaseURL = "https://www.celestrak.com/NORAD/elements/gp.php?GROUP=%1&FORMAT=TLE";
QStringList urls;
// TLE sources from Celestrak
for (auto group = celestrak.begin(); group != celestrak.end(); ++group)
{
QString url = celestrackBaseURL.arg(group.key());
if (group.value()) // Auto-add ON!
urls << QString("1,%1").arg(url);
else
urls << url;
}
// Other sources and supplemental data from Celestrack
urls << "1,http://www.celestrak.com/NORAD/elements/supplemental/starlink.txt"
<< "https://www.amsat.org/amsat/ftp/keps/current/nasabare.txt"
<< "https://www.prismnet.com/~mmccants/tles/classfd.zip";

saveTleSources(urls);
loadSettings();
}

void Satellites::restoreDefaultSettings()
{
QSettings* conf = StelApp::getInstance().getSettings();
Expand Down Expand Up @@ -682,55 +718,6 @@ void Satellites::restoreDefaultSettings()
conf->setValue("cf_rcs_max", 100.);

conf->endGroup(); // saveTleSources() opens it for itself

// TLE update sources
QStringList urls;
urls << "1,http://www.celestrak.com/NORAD/elements/visual.txt" // Auto-add ON!
<< "http://www.celestrak.com/NORAD/elements/tle-new.txt"
<< "http://www.celestrak.com/NORAD/elements/active.txt"
<< "http://www.celestrak.com/NORAD/elements/analyst.txt"
<< "1,http://www.celestrak.com/NORAD/elements/science.txt"
<< "http://www.celestrak.com/NORAD/elements/noaa.txt"
<< "http://www.celestrak.com/NORAD/elements/goes.txt"
<< "1,http://www.celestrak.com/NORAD/elements/amateur.txt"
<< "1,http://www.celestrak.com/NORAD/elements/gps-ops.txt"
<< "1,http://www.celestrak.com/NORAD/elements/galileo.txt"
<< "http://www.celestrak.com/NORAD/elements/iridium.txt"
<< "http://www.celestrak.com/NORAD/elements/iridium-NEXT.txt"
<< "http://www.celestrak.com/NORAD/elements/geo.txt"
<< "1,http://www.celestrak.com/NORAD/elements/stations.txt"
<< "http://www.celestrak.com/NORAD/elements/weather.txt"
<< "http://www.celestrak.com/NORAD/elements/resource.txt"
<< "http://www.celestrak.com/NORAD/elements/sarsat.txt"
<< "http://www.celestrak.com/NORAD/elements/dmc.txt"
<< "http://www.celestrak.com/NORAD/elements/tdrss.txt"
<< "http://www.celestrak.com/NORAD/elements/argos.txt"
<< "http://www.celestrak.com/NORAD/elements/intelsat.txt"
<< "http://www.celestrak.com/NORAD/elements/gorizont.txt"
<< "http://www.celestrak.com/NORAD/elements/raduga.txt"
<< "http://www.celestrak.com/NORAD/elements/molniya.txt"
<< "http://www.celestrak.com/NORAD/elements/orbcomm.txt"
<< "http://www.celestrak.com/NORAD/elements/globalstar.txt"
<< "http://www.celestrak.com/NORAD/elements/x-comm.txt"
<< "http://www.celestrak.com/NORAD/elements/other-comm.txt"
<< "1,http://www.celestrak.com/NORAD/elements/glo-ops.txt"
<< "1,http://www.celestrak.com/NORAD/elements/beidou.txt"
<< "http://www.celestrak.com/NORAD/elements/sbas.txt"
<< "http://www.celestrak.com/NORAD/elements/nnss.txt"
<< "http://www.celestrak.com/NORAD/elements/engineering.txt"
<< "http://www.celestrak.com/NORAD/elements/education.txt"
<< "http://www.celestrak.com/NORAD/elements/geodetic.txt"
<< "http://www.celestrak.com/NORAD/elements/radar.txt"
<< "http://www.celestrak.com/NORAD/elements/cubesat.txt"
<< "http://www.celestrak.com/NORAD/elements/other.txt"
<< "1,http://www.celestrak.com/NORAD/elements/supplemental/starlink.txt"
<< "https://www.amsat.org/amsat/ftp/keps/current/nasabare.txt"
<< "http://www.celestrak.com/NORAD/elements/oneweb.txt"
<< "http://www.celestrak.com/NORAD/elements/planet.txt"
<< "http://www.celestrak.com/NORAD/elements/spire.txt"
<< "https://www.prismnet.com/~mmccants/tles/classfd.zip";

saveTleSources(urls);
}

void Satellites::restoreDefaultCatalog()
Expand Down Expand Up @@ -1373,7 +1360,19 @@ bool Satellites::add(const TleData& tleData)
if (tleData.sourceURL.contains("celestrak.com", Qt::CaseInsensitive))
{
// add groups, based on CelesTrak's groups
QString fileName = QUrl(tleData.sourceURL).fileName().toLower().replace(".txt", "");
QString fileName;
if (tleData.sourceURL.contains(".txt", Qt::CaseInsensitive))
fileName = QUrl(tleData.sourceURL).fileName().toLower().replace(".txt", "");
else
{
// New format of source: https://www.celestrak.com/NORAD/elements/gp.php?GROUP=GROUP_NAME&FORMAT=tle
QStringList query = QUrl(tleData.sourceURL).query().toLower().split("&");
for(int i=0; i<query.size(); i++)
{
if (query.at(i).trimmed().contains("group"))
fileName = query.at(i).trimmed().replace("group=", "");
}
}
if (!satGroups.contains(fileName))
satGroups.append(fileName);

Expand Down Expand Up @@ -2830,14 +2829,14 @@ void Satellites::createSuperGroupsList()
earthresources = "earth resources", gps = "gps", glonass = "glonass",
geostationary = "geostationary";
satSuperGroupsMap = {
{ "geo", communications },
{ "geo", geostationary },
{ "gpz", communications },
{ "gpz", geostationary },
{ "geo", communications },
{ "geo", geostationary },
{ "gpz", communications },
{ "gpz", geostationary },
{ "gpz-plus", communications },
{ "gpz-plus", geostationary },
{ "intelsat", communications },
{ "ses", communications },
{ "ses", communications },
{ "iridium", communications },
{ "iridium-NEXT", communications },
{ "starlink", communications },
Expand All @@ -2853,31 +2852,31 @@ void Satellites::createSuperGroupsList()
{ "raduga", communications },
{ "raduga", geostationary },
{ "molniya", communications },
{ "gnss", navigation },
{ "gps", navigation },
{ "gnss", navigation },
{ "gps", navigation },
{ "gps-ops", navigation },
{ "gps-ops", gps },
{ "glonass", navigation },
{ "glo-ops", navigation },
{ "glo-ops", glonass },
{ "galileo", navigation },
{ "beidou", navigation },
{ "sbas", navigation },
{ "nnss", navigation },
{ "galileo", navigation },
{ "beidou", navigation },
{ "sbas", navigation },
{ "nnss", navigation },
{ "musson", navigation },
{ "science", scientific },
{ "geodetic", scientific },
{ "engineering", scientific },
{ "education", scientific },
{ "goes", scientific },
{ "goes", earthresources },
{ "goes", scientific },
{ "goes", earthresources },
{ "resource", earthresources },
{ "sarsat", earthresources },
{ "dmc", earthresources },
{ "tdrss", earthresources },
{ "argos", earthresources },
{ "planet", earthresources },
{ "spire", earthresources }
{ "sarsat", earthresources },
{ "dmc", earthresources },
{ "tdrss", earthresources },
{ "argos", earthresources },
{ "planet", earthresources },
{ "spire", earthresources }
};
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/Satellites/src/Satellites.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ class Satellites : public StelObjectModule
//! main config.ini (if one already exists), and populating it with default values. It also
//! creates the default satellites.json file from the resource embedded in the plugin lib/dll file.
void restoreDefaults(void);
//! Delete TLE sources in main config.ini, then create with default values.
void restoreDefaultTleSources();

//! Read (or re-read) the plugin's settings from the configuration file.
//! This will be called from init() and also when restoring defaults
Expand Down
14 changes: 14 additions & 0 deletions plugins/Satellites/src/gui/SatellitesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void SatellitesDialog::createDialogContent()
ui->deleteSourceButton->setFixedSize(bs);
ui->editSourceButton->setFixedSize(bs);
ui->saveSourceButton->setFixedSize(bs);
ui->resetSourcesButton->setFixedSize(bs);

// Settings tab / updates group
// These controls are refreshed by updateSettingsPage(), which in
Expand Down Expand Up @@ -276,6 +277,7 @@ void SatellitesDialog::createDialogContent()
connect(ui->addSourceButton, SIGNAL(clicked()), this, SLOT(addSourceRow()));
connect(ui->editSourceButton, SIGNAL(clicked()), this, SLOT(editSourceRow()));
connect(ui->saveSourceButton, SIGNAL(clicked()), this, SLOT(saveEditedSource()));
connect(ui->resetSourcesButton, SIGNAL(clicked()), this, SLOT(restoreTleSources()));
connect(plugin, SIGNAL(satGroupVisibleChanged()), this, SLOT(updateSatelliteAndSaveData()));
connect(plugin, SIGNAL(settingsChanged()), this, SLOT(toggleCheckableSources()));
connect(plugin, SIGNAL(customFilterChanged()), this, SLOT(updateFilteredSatellitesList()));
Expand Down Expand Up @@ -1032,6 +1034,18 @@ void SatellitesDialog::restoreDefaults(void)
qDebug() << "[Satellites] restore defaults is canceled...";
}

void SatellitesDialog::restoreTleSources(void)
{
if (askConfirmation())
{
qDebug() << "[Satellites] restore TLE sources...";
GETSTELMODULE(Satellites)->restoreDefaultTleSources();
populateSourcesList();
}
else
qDebug() << "[Satellites] restore TLE sources is canceled...";
}

void SatellitesDialog::updateSettingsPage()
{
Satellites* plugin = GETSTELMODULE(Satellites);
Expand Down
1 change: 1 addition & 0 deletions plugins/Satellites/src/gui/SatellitesDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ private slots:
//@}

void restoreDefaults(void);
void restoreTleSources(void);
void saveSettings(void);
void addSatellites(const TleDataList& newSatellites);
void removeSatellites();
Expand Down
28 changes: 28 additions & 0 deletions plugins/Satellites/src/gui/satellitesDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,34 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="resetSourcesButton">
<property name="toolTip">
<string>Reset sources list to it defaults</string>
</property>
<property name="icon">
<iconset resource="../../../../data/gui/guiRes.qrc">
<normaloff>:/graphicGui/uibtDownload.png</normaloff>
<disabledoff>:/graphicGui/uibtDownload-disabled.png</disabledoff>:/graphicGui/uibtDownload.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit 8bf87aa

Please sign in to comment.