Skip to content

Commit 8bf87aa

Browse files
committed
Added tool to reset TLE sources in Satellites plugin (partially #2458)
1 parent 2a06d6c commit 8bf87aa

File tree

6 files changed

+393
-345
lines changed

6 files changed

+393
-345
lines changed

plugins/Satellites/src/Satellites.cpp

+68-69
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,47 @@ bool Satellites::configureGui(bool show)
621621
void Satellites::restoreDefaults(void)
622622
{
623623
restoreDefaultSettings();
624+
restoreDefaultTleSources();
624625
restoreDefaultCatalog();
625626
loadCatalog();
626627
loadSettings();
627628
}
628629

630+
void Satellites::restoreDefaultTleSources()
631+
{
632+
// Format: group name, auto-add flag
633+
const QMap<QString, bool> celestrak={
634+
{ "visual", true }, { "stations", true }, { "last-30-days", false }, { "active", false }, { "analyst", false },
635+
{ "science", true }, { "noaa", false }, { "goes", false }, { "amateur", true }, { "gnss", true },
636+
{ "gps-ops", true }, { "galileo", true }, { "iridium", false }, { "iridium-NEXT", false }, { "geo", false },
637+
{ "weather", false }, { "resource", false }, { "sarsat", false }, { "dmc", false }, { "tdrss", false },
638+
{ "argos", false }, { "intelsat", false }, { "gorizont", false }, { "raduga", false }, { "molniya", false },
639+
{ "orbcomm", false }, { "globalstar", false }, { "x-comm", false }, { "other-comm", false }, { "glo-ops", true },
640+
{ "beidou", true }, { "sbas", false }, { "nnss", false }, { "engineering", false }, { "education", false },
641+
{ "geodetic", false }, { "radar", false }, { "cubesat", false }, { "other", false }, { "oneweb", true },
642+
{ "starlink", true }, { "planet", false }, { "spire", false }
643+
};
644+
// Details: https://www.celestrak.com/NORAD/documentation/gp-data-formats.php
645+
QString celestrackBaseURL = "https://www.celestrak.com/NORAD/elements/gp.php?GROUP=%1&FORMAT=TLE";
646+
QStringList urls;
647+
// TLE sources from Celestrak
648+
for (auto group = celestrak.begin(); group != celestrak.end(); ++group)
649+
{
650+
QString url = celestrackBaseURL.arg(group.key());
651+
if (group.value()) // Auto-add ON!
652+
urls << QString("1,%1").arg(url);
653+
else
654+
urls << url;
655+
}
656+
// Other sources and supplemental data from Celestrack
657+
urls << "1,http://www.celestrak.com/NORAD/elements/supplemental/starlink.txt"
658+
<< "https://www.amsat.org/amsat/ftp/keps/current/nasabare.txt"
659+
<< "https://www.prismnet.com/~mmccants/tles/classfd.zip";
660+
661+
saveTleSources(urls);
662+
loadSettings();
663+
}
664+
629665
void Satellites::restoreDefaultSettings()
630666
{
631667
QSettings* conf = StelApp::getInstance().getSettings();
@@ -682,55 +718,6 @@ void Satellites::restoreDefaultSettings()
682718
conf->setValue("cf_rcs_max", 100.);
683719

684720
conf->endGroup(); // saveTleSources() opens it for itself
685-
686-
// TLE update sources
687-
QStringList urls;
688-
urls << "1,http://www.celestrak.com/NORAD/elements/visual.txt" // Auto-add ON!
689-
<< "http://www.celestrak.com/NORAD/elements/tle-new.txt"
690-
<< "http://www.celestrak.com/NORAD/elements/active.txt"
691-
<< "http://www.celestrak.com/NORAD/elements/analyst.txt"
692-
<< "1,http://www.celestrak.com/NORAD/elements/science.txt"
693-
<< "http://www.celestrak.com/NORAD/elements/noaa.txt"
694-
<< "http://www.celestrak.com/NORAD/elements/goes.txt"
695-
<< "1,http://www.celestrak.com/NORAD/elements/amateur.txt"
696-
<< "1,http://www.celestrak.com/NORAD/elements/gps-ops.txt"
697-
<< "1,http://www.celestrak.com/NORAD/elements/galileo.txt"
698-
<< "http://www.celestrak.com/NORAD/elements/iridium.txt"
699-
<< "http://www.celestrak.com/NORAD/elements/iridium-NEXT.txt"
700-
<< "http://www.celestrak.com/NORAD/elements/geo.txt"
701-
<< "1,http://www.celestrak.com/NORAD/elements/stations.txt"
702-
<< "http://www.celestrak.com/NORAD/elements/weather.txt"
703-
<< "http://www.celestrak.com/NORAD/elements/resource.txt"
704-
<< "http://www.celestrak.com/NORAD/elements/sarsat.txt"
705-
<< "http://www.celestrak.com/NORAD/elements/dmc.txt"
706-
<< "http://www.celestrak.com/NORAD/elements/tdrss.txt"
707-
<< "http://www.celestrak.com/NORAD/elements/argos.txt"
708-
<< "http://www.celestrak.com/NORAD/elements/intelsat.txt"
709-
<< "http://www.celestrak.com/NORAD/elements/gorizont.txt"
710-
<< "http://www.celestrak.com/NORAD/elements/raduga.txt"
711-
<< "http://www.celestrak.com/NORAD/elements/molniya.txt"
712-
<< "http://www.celestrak.com/NORAD/elements/orbcomm.txt"
713-
<< "http://www.celestrak.com/NORAD/elements/globalstar.txt"
714-
<< "http://www.celestrak.com/NORAD/elements/x-comm.txt"
715-
<< "http://www.celestrak.com/NORAD/elements/other-comm.txt"
716-
<< "1,http://www.celestrak.com/NORAD/elements/glo-ops.txt"
717-
<< "1,http://www.celestrak.com/NORAD/elements/beidou.txt"
718-
<< "http://www.celestrak.com/NORAD/elements/sbas.txt"
719-
<< "http://www.celestrak.com/NORAD/elements/nnss.txt"
720-
<< "http://www.celestrak.com/NORAD/elements/engineering.txt"
721-
<< "http://www.celestrak.com/NORAD/elements/education.txt"
722-
<< "http://www.celestrak.com/NORAD/elements/geodetic.txt"
723-
<< "http://www.celestrak.com/NORAD/elements/radar.txt"
724-
<< "http://www.celestrak.com/NORAD/elements/cubesat.txt"
725-
<< "http://www.celestrak.com/NORAD/elements/other.txt"
726-
<< "1,http://www.celestrak.com/NORAD/elements/supplemental/starlink.txt"
727-
<< "https://www.amsat.org/amsat/ftp/keps/current/nasabare.txt"
728-
<< "http://www.celestrak.com/NORAD/elements/oneweb.txt"
729-
<< "http://www.celestrak.com/NORAD/elements/planet.txt"
730-
<< "http://www.celestrak.com/NORAD/elements/spire.txt"
731-
<< "https://www.prismnet.com/~mmccants/tles/classfd.zip";
732-
733-
saveTleSources(urls);
734721
}
735722

736723
void Satellites::restoreDefaultCatalog()
@@ -1373,7 +1360,19 @@ bool Satellites::add(const TleData& tleData)
13731360
if (tleData.sourceURL.contains("celestrak.com", Qt::CaseInsensitive))
13741361
{
13751362
// add groups, based on CelesTrak's groups
1376-
QString fileName = QUrl(tleData.sourceURL).fileName().toLower().replace(".txt", "");
1363+
QString fileName;
1364+
if (tleData.sourceURL.contains(".txt", Qt::CaseInsensitive))
1365+
fileName = QUrl(tleData.sourceURL).fileName().toLower().replace(".txt", "");
1366+
else
1367+
{
1368+
// New format of source: https://www.celestrak.com/NORAD/elements/gp.php?GROUP=GROUP_NAME&FORMAT=tle
1369+
QStringList query = QUrl(tleData.sourceURL).query().toLower().split("&");
1370+
for(int i=0; i<query.size(); i++)
1371+
{
1372+
if (query.at(i).trimmed().contains("group"))
1373+
fileName = query.at(i).trimmed().replace("group=", "");
1374+
}
1375+
}
13771376
if (!satGroups.contains(fileName))
13781377
satGroups.append(fileName);
13791378

@@ -2830,14 +2829,14 @@ void Satellites::createSuperGroupsList()
28302829
earthresources = "earth resources", gps = "gps", glonass = "glonass",
28312830
geostationary = "geostationary";
28322831
satSuperGroupsMap = {
2833-
{ "geo", communications },
2834-
{ "geo", geostationary },
2835-
{ "gpz", communications },
2836-
{ "gpz", geostationary },
2832+
{ "geo", communications },
2833+
{ "geo", geostationary },
2834+
{ "gpz", communications },
2835+
{ "gpz", geostationary },
28372836
{ "gpz-plus", communications },
28382837
{ "gpz-plus", geostationary },
28392838
{ "intelsat", communications },
2840-
{ "ses", communications },
2839+
{ "ses", communications },
28412840
{ "iridium", communications },
28422841
{ "iridium-NEXT", communications },
28432842
{ "starlink", communications },
@@ -2853,31 +2852,31 @@ void Satellites::createSuperGroupsList()
28532852
{ "raduga", communications },
28542853
{ "raduga", geostationary },
28552854
{ "molniya", communications },
2856-
{ "gnss", navigation },
2857-
{ "gps", navigation },
2855+
{ "gnss", navigation },
2856+
{ "gps", navigation },
28582857
{ "gps-ops", navigation },
28592858
{ "gps-ops", gps },
28602859
{ "glonass", navigation },
28612860
{ "glo-ops", navigation },
28622861
{ "glo-ops", glonass },
2863-
{ "galileo", navigation },
2864-
{ "beidou", navigation },
2865-
{ "sbas", navigation },
2866-
{ "nnss", navigation },
2862+
{ "galileo", navigation },
2863+
{ "beidou", navigation },
2864+
{ "sbas", navigation },
2865+
{ "nnss", navigation },
28672866
{ "musson", navigation },
28682867
{ "science", scientific },
28692868
{ "geodetic", scientific },
28702869
{ "engineering", scientific },
28712870
{ "education", scientific },
2872-
{ "goes", scientific },
2873-
{ "goes", earthresources },
2871+
{ "goes", scientific },
2872+
{ "goes", earthresources },
28742873
{ "resource", earthresources },
2875-
{ "sarsat", earthresources },
2876-
{ "dmc", earthresources },
2877-
{ "tdrss", earthresources },
2878-
{ "argos", earthresources },
2879-
{ "planet", earthresources },
2880-
{ "spire", earthresources }
2874+
{ "sarsat", earthresources },
2875+
{ "dmc", earthresources },
2876+
{ "tdrss", earthresources },
2877+
{ "argos", earthresources },
2878+
{ "planet", earthresources },
2879+
{ "spire", earthresources }
28812880
};
28822881
}
28832882

plugins/Satellites/src/Satellites.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ class Satellites : public StelObjectModule
284284
//! main config.ini (if one already exists), and populating it with default values. It also
285285
//! creates the default satellites.json file from the resource embedded in the plugin lib/dll file.
286286
void restoreDefaults(void);
287+
//! Delete TLE sources in main config.ini, then create with default values.
288+
void restoreDefaultTleSources();
287289

288290
//! Read (or re-read) the plugin's settings from the configuration file.
289291
//! This will be called from init() and also when restoring defaults

plugins/Satellites/src/gui/SatellitesDialog.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void SatellitesDialog::createDialogContent()
158158
ui->deleteSourceButton->setFixedSize(bs);
159159
ui->editSourceButton->setFixedSize(bs);
160160
ui->saveSourceButton->setFixedSize(bs);
161+
ui->resetSourcesButton->setFixedSize(bs);
161162

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

1037+
void SatellitesDialog::restoreTleSources(void)
1038+
{
1039+
if (askConfirmation())
1040+
{
1041+
qDebug() << "[Satellites] restore TLE sources...";
1042+
GETSTELMODULE(Satellites)->restoreDefaultTleSources();
1043+
populateSourcesList();
1044+
}
1045+
else
1046+
qDebug() << "[Satellites] restore TLE sources is canceled...";
1047+
}
1048+
10351049
void SatellitesDialog::updateSettingsPage()
10361050
{
10371051
Satellites* plugin = GETSTELMODULE(Satellites);

plugins/Satellites/src/gui/SatellitesDialog.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ private slots:
107107
//@}
108108

109109
void restoreDefaults(void);
110+
void restoreTleSources(void);
110111
void saveSettings(void);
111112
void addSatellites(const TleDataList& newSatellites);
112113
void removeSatellites();

plugins/Satellites/src/gui/satellitesDialog.ui

+28
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,34 @@
14751475
</property>
14761476
</widget>
14771477
</item>
1478+
<item>
1479+
<spacer name="horizontalSpacer_10">
1480+
<property name="orientation">
1481+
<enum>Qt::Horizontal</enum>
1482+
</property>
1483+
<property name="sizeType">
1484+
<enum>QSizePolicy::Fixed</enum>
1485+
</property>
1486+
<property name="sizeHint" stdset="0">
1487+
<size>
1488+
<width>20</width>
1489+
<height>20</height>
1490+
</size>
1491+
</property>
1492+
</spacer>
1493+
</item>
1494+
<item>
1495+
<widget class="QPushButton" name="resetSourcesButton">
1496+
<property name="toolTip">
1497+
<string>Reset sources list to it defaults</string>
1498+
</property>
1499+
<property name="icon">
1500+
<iconset resource="../../../../data/gui/guiRes.qrc">
1501+
<normaloff>:/graphicGui/uibtDownload.png</normaloff>
1502+
<disabledoff>:/graphicGui/uibtDownload-disabled.png</disabledoff>:/graphicGui/uibtDownload.png</iconset>
1503+
</property>
1504+
</widget>
1505+
</item>
14781506
</layout>
14791507
</item>
14801508
</layout>

0 commit comments

Comments
 (0)