Satellites.cpp   Satellites.cpp 
skipping to change at line 29 skipping to change at line 29
#include "StelProjector.hpp" #include "StelProjector.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelLocation.hpp" #include "StelLocation.hpp"
#include "StelNavigator.hpp" #include "StelNavigator.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelLocaleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelIniParser.hpp" #include "StelIniParser.hpp"
#include "Satellites.hpp" #include "Satellites.hpp"
#include "Satellite.hpp" #include "Satellite.hpp"
#include "Planet.hpp" #include "Planet.hpp"
#include "SolarSystem.hpp" #include "SolarSystem.hpp"
#include "StelJsonParser.hpp" #include "StelJsonParser.hpp"
#include "SatellitesDialog.hpp" #include "SatellitesDialog.hpp"
#include "LabelMgr.hpp"
#include "StelTranslator.hpp"
#include <plugin_config.h>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QKeyEvent> #include <QKeyEvent>
#include <QAction> #include <QAction>
#include <QProgressBar> #include <QProgressBar>
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QFile> #include <QFile>
#include <QTimer> #include <QTimer>
skipping to change at line 63 skipping to change at line 68
return new Satellites(); return new Satellites();
} }
StelPluginInfo SatellitesStelPluginInterface::getPluginInfo() const StelPluginInfo SatellitesStelPluginInterface::getPluginInfo() const
{ {
// Allow to load the resources when used as a static plugin // Allow to load the resources when used as a static plugin
Q_INIT_RESOURCE(Satellites); Q_INIT_RESOURCE(Satellites);
StelPluginInfo info; StelPluginInfo info;
info.id = "Satellites"; info.id = "Satellites";
info.displayedName = "Satellites"; info.displayedName = q_("Satellites");
info.authors = "Matthew Gates"; info.authors = "Matthew Gates, Jose Luis Canales";
info.contact = "http://stellarium.org/"; info.contact = "http://stellarium.org/";
info.description = "Prediction of artificial satellite posit ions in Earth orbit based on NORAD TLE data"; info.description = q_("Prediction of artificial satellite po sitions in Earth orbit based on NORAD TLE data");
return info; return info;
} }
Q_EXPORT_PLUGIN2(Satellites, SatellitesStelPluginInterface) Q_EXPORT_PLUGIN2(Satellites, SatellitesStelPluginInterface)
Satellites::Satellites() Satellites::Satellites()
: pxmapGlow(NULL), pxmapOnIcon(NULL), pxmapOffIcon(NULL), toolbarBut : pxmapGlow(NULL), pxmapOnIcon(NULL), pxmapOffIcon(NULL), toolbarBut
ton(NULL), earth(NULL), defaultHintColor(0.,0.4,0.6), progressBar(NULL) ton(NULL),
earth(NULL), defaultHintColor(0.0, 0.4, 0.6), defaultOrbitColor(0.
0, 0.3, 0.6),
progressBar(NULL)
{ {
setObjectName("Satellites"); setObjectName("Satellites");
configDialog = new SatellitesDialog(); configDialog = new SatellitesDialog();
} }
void Satellites::deinit() void Satellites::deinit()
{ {
Satellite::hintTexture.clear(); Satellite::hintTexture.clear();
texPointer.clear(); texPointer.clear();
configDialog->setVisible(false);
} }
Satellites::~Satellites() Satellites::~Satellites()
{ {
delete configDialog; delete configDialog;
} }
void Satellites::init() void Satellites::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
skipping to change at line 113 skipping to change at line 119
restoreDefaultConfigIni(); restoreDefaultConfigIni();
} }
// populate settings from main config file. // populate settings from main config file.
readSettingsFromConfig(); readSettingsFromConfig();
satellitesJsonPath = StelFileMgr::findFile("modules/Satellit es", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/satellites.json"; satellitesJsonPath = StelFileMgr::findFile("modules/Satellit es", (StelFileMgr::Flags)(StelFileMgr::Directory|StelFileMgr::Writable)) + "/satellites.json";
// Load and find resources used in the plugin // Load and find resources used in the plugin
texPointer = StelApp::getInstance().getTextureManager().crea teTexture("textures/pointeur5.png"); texPointer = StelApp::getInstance().getTextureManager().crea teTexture("textures/pointeur5.png");
Satellite::hintTexture = StelApp::getInstance().getTextureMa nager().createTexture(":/satellites/satellite_hint.png"); Satellite::hintTexture = StelApp::getInstance().getTextureMa nager().createTexture(":/satellites/hint.png");
// key bindings and other actions // key bindings and other actions
// TRANSLATORS: Title of a group of key bindings in the Help
window
QString groupName = N_("Plugin Key Bindings");
StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui()); StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance() .getGui());
gui->addGuiActions("actionShow_Satellite_ConfigDialog", "Sat gui->addGuiActions("actionShow_Satellite_ConfigDialog", N_("
ellite Config Dialog", "Alt+Z", "Plugin Key Bindings", true, false); Satellites configuration window"), "Alt+Z", groupName, true);
gui->addGuiActions("actionShow_Satellite_Hints", "Satellite gui->addGuiActions("actionShow_Satellite_Hints", N_("Satelli
Hints", "Ctrl+Z", "Plugin Key Bindings", true, false); te hints"), "Ctrl+Z", groupName, true, false);
gui->getGuiActions("actionShow_Satellite_Hints")->setChecked gui->getGuiActions("actionShow_Satellite_Hints")->setChecked
(hintFader); (getFlagHints());
gui->addGuiActions("actionShow_Satellite_Labels", "Satellite gui->addGuiActions("actionShow_Satellite_Labels", N_("Satell
Labels", "Shift+Z", "Plugin Key Bindings", true, false); ite labels"), "Shift+Z", groupName, true, false);
gui->getGuiActions("actionShow_Satellite_Labels")->setChecke d(Satellite::showLabels); gui->getGuiActions("actionShow_Satellite_Labels")->setChecke d(Satellite::showLabels);
// Gui toolbar button // Gui toolbar button
pxmapGlow = new QPixmap(":/graphicGui/glow32x32.png"); pxmapGlow = new QPixmap(":/graphicGui/glow32x32.png");
pxmapOnIcon = new QPixmap(":/satellites/bt_satellites_on.png "); pxmapOnIcon = new QPixmap(":/satellites/bt_satellites_on.png ");
pxmapOffIcon = new QPixmap(":/satellites/bt_satellites_off.p ng"); pxmapOffIcon = new QPixmap(":/satellites/bt_satellites_off.p ng");
toolbarButton = new StelButton(NULL, *pxmapOnIcon, *pxmapOff Icon, *pxmapGlow, gui->getGuiActions("actionShow_Satellite_Hints")); toolbarButton = new StelButton(NULL, *pxmapOnIcon, *pxmapOff Icon, *pxmapGlow, gui->getGuiActions("actionShow_Satellite_Hints"));
gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr oup"); gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGr oup");
connect(gui->getGuiActions("actionShow_Satellite_ConfigDialo g"), SIGNAL(toggled(bool)), configDialog, SLOT(setVisible(bool))); connect(gui->getGuiActions("actionShow_Satellite_ConfigDialo g"), SIGNAL(toggled(bool)), configDialog, SLOT(setVisible(bool)));
connect(configDialog, SIGNAL(visibleChanged(bool)), gui->get GuiActions("actionShow_Satellite_ConfigDialog"), SLOT(setChecked(bool)));
connect(gui->getGuiActions("actionShow_Satellite_Hints"), SI GNAL(toggled(bool)), this, SLOT(setFlagHints(bool))); connect(gui->getGuiActions("actionShow_Satellite_Hints"), SI GNAL(toggled(bool)), this, SLOT(setFlagHints(bool)));
connect(gui->getGuiActions("actionShow_Satellite_Labels"), S IGNAL(toggled(bool)), this, SLOT(setFlagLabels(bool))); connect(gui->getGuiActions("actionShow_Satellite_Labels"), S IGNAL(toggled(bool)), this, SLOT(setFlagLabels(bool)));
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Satellites::init error: " << e.what(); qWarning() << "Satellites::init error: " << e.what();
return; return;
} }
// A timer for hiding alert messages
messageTimer = new QTimer(this);
messageTimer->setSingleShot(true); // recurring check for update
messageTimer->setInterval(9000); // 6 seconds should be enough
time
messageTimer->stop();
connect(messageTimer, SIGNAL(timeout()), this, SLOT(messageTimeout()
));
// If the json file does not already exist, create it from the resou rce in the QT resource // If the json file does not already exist, create it from the resou rce in the QT resource
if(!QFileInfo(satellitesJsonPath).exists()) if(QFileInfo(satellitesJsonPath).exists())
{ {
qDebug() << "Satellites::init satellites.json does not exist if (getJsonFileVersion() != PLUGIN_VERSION)
- copying default file to " << satellitesJsonPath; {
restoreDefaultJsonFile(); displayMessage(q_("The old satellites.json file is n
o longer compatible - using default file"), "#bb0000");
restoreDefaultJsonFile();
}
} }
else else
{ {
qDebug() << "Satellites::init using satellite.json file: " < qDebug() << "Satellites::init satellites.json does not exist
< satellitesJsonPath; - copying default file to " << satellitesJsonPath;
restoreDefaultJsonFile();
} }
qDebug() << "Satellites::init using satellite.json file: " << satell
itesJsonPath;
// create satellites according to content os satellites.json file // create satellites according to content os satellites.json file
readJsonFile(); readJsonFile();
// Set up download manager and the update schedule // Set up download manager and the update schedule
downloadMgr = new QNetworkAccessManager(this); downloadMgr = new QNetworkAccessManager(this);
connect(downloadMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(up dateDownloadComplete(QNetworkReply*))); connect(downloadMgr, SIGNAL(finished(QNetworkReply*)), this, SLOT(up dateDownloadComplete(QNetworkReply*)));
updateState = CompleteNoUpdates; updateState = CompleteNoUpdates;
updateTimer = new QTimer(this); updateTimer = new QTimer(this);
updateTimer->setSingleShot(false); // recurring check for update updateTimer->setSingleShot(false); // recurring check for update
updateTimer->setInterval(13000); // check once every 13 seconds to see if it is time for an update updateTimer->setInterval(13000); // check once every 13 seconds to see if it is time for an update
skipping to change at line 184 skipping to change at line 207
{ {
normalStyleSheet = styleSheetFile.readAll(); normalStyleSheet = styleSheetFile.readAll();
} }
styleSheetFile.close(); styleSheetFile.close();
styleSheetFile.setFileName(":/satellites/nightStyle.css"); styleSheetFile.setFileName(":/satellites/nightStyle.css");
if(styleSheetFile.open(QFile::ReadOnly|QFile::Text)) if(styleSheetFile.open(QFile::ReadOnly|QFile::Text))
{ {
nightStyleSheet = styleSheetFile.readAll(); nightStyleSheet = styleSheetFile.readAll();
} }
styleSheetFile.close(); styleSheetFile.close();
} }
void Satellites::setStelStyle(const QString&) bool Satellites::backupJsonFile(bool deleteOriginal)
{ {
configDialog->updateStyle(); QFile old(satellitesJsonPath);
if (!old.exists())
{
qWarning() << "Satellites::backupJsonFile no file to backup"
;
return false;
}
QString backupPath = satellitesJsonPath + ".old";
if (QFileInfo(backupPath).exists())
QFile(backupPath).remove();
if (old.copy(backupPath))
{
if (deleteOriginal)
{
if (!old.remove())
{
qWarning() << "Satellites::backupJsonFile WA
RNING - could not remove old satellites.json file";
return false;
}
}
}
else
{
qWarning() << "Satellites::backupJsonFile WARNING - failed t
o copy satellites.json to satellites.json.old";
return false;
}
return true;
}
void Satellites::setStelStyle(const QString& mode)
{
foreach(const SatelliteP& sat, satellites)
{
if (sat->initialized)
{
sat->setNightColors(mode=="night_color");
}
}
} }
const StelStyle Satellites::getModuleStyleSheet(const StelStyle& style) const StelStyle Satellites::getModuleStyleSheet(const StelStyle& style)
{ {
StelStyle pluginStyle(style); StelStyle pluginStyle(style);
if (style.confSectionName == "color") if (style.confSectionName == "color")
{ {
pluginStyle.qtStyleSheet.append(normalStyleSheet); pluginStyle.qtStyleSheet.append(normalStyleSheet);
} }
else else
{ {
pluginStyle.qtStyleSheet.append(nightStyleSheet); pluginStyle.qtStyleSheet.append(nightStyleSheet);
} }
return pluginStyle; return pluginStyle;
} }
double Satellites::getCallOrder(StelModuleActionName actionName) const double Satellites::getCallOrder(StelModuleActionName actionName) const
{ {
if (actionName==StelModule::ActionDraw) if (actionName==StelModule::ActionDraw)
return StelApp::getInstance().getModuleMgr().getModule("Star Mgr")->getCallOrder(actionName)+1.; return StelApp::getInstance().getModuleMgr().getModule("Sola rSystem")->getCallOrder(actionName)+1.;
return 0; return 0;
} }
QList<StelObjectP> Satellites::searchAround(const Vec3d& av, double limitFo v, const StelCore*) const QList<StelObjectP> Satellites::searchAround(const Vec3d& av, double limitFo v, const StelCore*) const
{ {
QList<StelObjectP> result; QList<StelObjectP> result;
if (!hintFader || StelApp::getInstance().getCore()->getNavigator()-> getCurrentLocation().planetName != earth->getEnglishName()) if (!hintFader || StelApp::getInstance().getCore()->getNavigator()-> getCurrentLocation().planetName != earth->getEnglishName())
return result; return result;
Vec3d v(av); Vec3d v(av);
skipping to change at line 316 skipping to change at line 379
gui->getGuiActions("actionShow_Satellite_ConfigDialog")->set Checked(true); gui->getGuiActions("actionShow_Satellite_ConfigDialog")->set Checked(true);
} }
return true; return true;
} }
void Satellites::restoreDefaults(void) void Satellites::restoreDefaults(void)
{ {
restoreDefaultConfigIni(); restoreDefaultConfigIni();
restoreDefaultJsonFile(); restoreDefaultJsonFile();
readJsonFile();
readSettingsFromConfig(); readSettingsFromConfig();
} }
void Satellites::restoreDefaultConfigIni(void) void Satellites::restoreDefaultConfigIni(void)
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
conf->beginGroup("Satellites"); conf->beginGroup("Satellites");
// delete all existing Satellite settings... // delete all existing Satellite settings...
conf->remove(""); conf->remove("");
conf->setValue("show_satellite_hints", true); conf->setValue("show_satellite_hints", false);
conf->setValue("show_satellite_labels", true); conf->setValue("show_satellite_labels", true);
conf->setValue("updates_enabled", true); conf->setValue("updates_enabled", true);
conf->setValue("show_satellites", true);
conf->setValue("hint_color", "0.0,0.4,0.6"); conf->setValue("hint_color", "0.0,0.4,0.6");
conf->setValue("hint_font_size", 10); conf->setValue("hint_font_size", 10);
conf->setValue("tle_url0", "http://celestrak.com/NORAD/elements/noaa .txt"); conf->setValue("tle_url0", "http://celestrak.com/NORAD/elements/noaa .txt");
conf->setValue("tle_url1", "http://celestrak.com/NORAD/elements/goes .txt"); conf->setValue("tle_url1", "http://celestrak.com/NORAD/elements/goes .txt");
conf->setValue("tle_url2", "http://celestrak.com/NORAD/elements/gps- ops.txt"); conf->setValue("tle_url2", "http://celestrak.com/NORAD/elements/gps- ops.txt");
conf->setValue("tle_url3", "http://celestrak.com/NORAD/elements/gali leo.txt"); conf->setValue("tle_url3", "http://celestrak.com/NORAD/elements/gali leo.txt");
conf->setValue("tle_url4", "http://celestrak.com/NORAD/elements/visu al.txt"); conf->setValue("tle_url4", "http://celestrak.com/NORAD/elements/visu al.txt");
conf->setValue("tle_url5", "http://celestrak.com/NORAD/elements/amat eur.txt"); conf->setValue("tle_url5", "http://celestrak.com/NORAD/elements/amat eur.txt");
conf->setValue("tle_url6", "http://celestrak.com/NORAD/elements/irid ium.txt"); conf->setValue("tle_url6", "http://celestrak.com/NORAD/elements/irid ium.txt");
conf->setValue("tle_url7", "http://celestrak.com/NORAD/elements/tle- new.txt");
conf->setValue("update_frequency_hours", 72); conf->setValue("update_frequency_hours", 72);
conf->setValue("orbit_line_flag", true);
conf->setValue("orbit_line_segments", 90);
conf->setValue("orbit_fade_segments", 5);
conf->setValue("orbit_segment_duration", 20);
conf->endGroup(); conf->endGroup();
} }
void Satellites::restoreDefaultJsonFile(void) void Satellites::restoreDefaultJsonFile(void)
{ {
if (QFileInfo(satellitesJsonPath).exists())
backupJsonFile(true);
QFile src(":/satellites/satellites.json"); QFile src(":/satellites/satellites.json");
if (!src.copy(satellitesJsonPath)) if (!src.copy(satellitesJsonPath))
{ {
qWarning() << "Satellites::restoreDefaultJsonFile cannot cop y json resource to " + satellitesJsonPath; qWarning() << "Satellites::restoreDefaultJsonFile cannot cop y json resource to " + satellitesJsonPath;
} }
else else
{ {
qDebug() << "Satellites::init copied default satellites.json to " << satellitesJsonPath; qDebug() << "Satellites::init copied default satellites.json to " << satellitesJsonPath;
// The resource is read only, and the new file inherits this ... make sure the new file // The resource is read only, and the new file inherits this ... make sure the new file
// is writable by the Stellarium process so that updates can be done. // is writable by the Stellarium process so that updates can be done.
QFile dest(satellitesJsonPath); QFile dest(satellitesJsonPath);
dest.setPermissions(dest.permissions() | QFile::WriteOwner); dest.setPermissions(dest.permissions() | QFile::WriteOwner);
// Make sure that in the case where an online update has pre viously been done, but // Make sure that in the case where an online update has pre viously been done, but
// the json file has been manually removed, that an update i s schreduled in a timely // the json file has been manually removed, that an update i s schreduled in a timely
// manner // manner
StelApp::getInstance().getSettings()->remove("Satellites/las t_update"); StelApp::getInstance().getSettings()->remove("Satellites/las t_update");
lastUpdate = QDateTime::fromString("2001-05-25T12:00:00", Qt
::ISODate);
} }
} }
void Satellites::readSettingsFromConfig(void) void Satellites::readSettingsFromConfig(void)
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
conf->beginGroup("Satellites"); conf->beginGroup("Satellites");
// populate updateUrls from tle_url? keys // populate updateUrls from tle_url? keys
QRegExp keyRE("^tle_url\\d+$"); QRegExp keyRE("^tle_url\\d+$");
skipping to change at line 387 skipping to change at line 458
if (keyRE.exactMatch(key)) if (keyRE.exactMatch(key))
{ {
QString s = conf->value(key, "").toString(); QString s = conf->value(key, "").toString();
if (!s.isEmpty() && s!="") if (!s.isEmpty() && s!="")
updateUrls << s; updateUrls << s;
} }
} }
// updater related settings... // updater related settings...
updateFrequencyHours = conf->value("update_frequency_hours", 72).toI nt(); updateFrequencyHours = conf->value("update_frequency_hours", 72).toI nt();
lastUpdate = QDateTime::fromString(conf->value("last_update", "2009- // last update default is the first Towell Day. <3 DA
01-01 12:00:00").toString(), "yyyy-MM-dd HH:mm:ss"); lastUpdate = QDateTime::fromString(conf->value("last_update", "2001-
hintFader = conf->value("show_satellite_hints", true).toBool(); 05-25T12:00:00").toString(), Qt::ISODate);
setFlagHints(conf->value("show_satellite_hints", false).toBool());
Satellite::showLabels = conf->value("show_satellite_labels", true).t oBool(); Satellite::showLabels = conf->value("show_satellite_labels", true).t oBool();
updatesEnabled = conf->value("updates_enabled", true).toBool(); updatesEnabled = conf->value("updates_enabled", true).toBool();
// Get a font for labels // Get a font for labels
labelFont.setPixelSize(conf->value("hint_font_size", 10).toInt()); labelFont.setPixelSize(conf->value("hint_font_size", 10).toInt());
// orbit drawing params
Satellite::orbitLinesFlag = conf->value("orbit_line_flag", true).toB
ool();
Satellite::orbitLineSegments = conf->value("orbit_line_segments", 90
).toInt();
Satellite::orbitLineFadeSegments = conf->value("orbit_fade_segments"
, 5).toInt();
Satellite::orbitLineSegmentDuration = conf->value("orbit_segment_dur
ation", 20).toInt();
conf->endGroup(); conf->endGroup();
} }
int Satellites::readJsonFile(void) void Satellites::saveSettingsToConfig(void)
{ {
// First, delete all existing Satellite objects... QSettings* conf = StelApp::getInstance().getSettings();
satellites.clear(); conf->beginGroup("Satellites");
// update tle urls... first clear the existing ones in the file
QRegExp keyRE("^tle_url\\d+$");
foreach(QString key, conf->childKeys())
{
if (keyRE.exactMatch(key))
conf->remove(key);
}
// populate updateUrls from tle_url? keys
int n=0;
foreach(QString url, updateUrls)
{
QString key = QString("tle_url%1").arg(n++);
conf->setValue(key, url);
}
// updater related settings...
conf->setValue("update_frequency_hours", updateFrequencyHours);
conf->setValue("show_satellite_hints", getFlagHints());
conf->setValue("show_satellite_labels", Satellite::showLabels);
conf->setValue("updates_enabled", updatesEnabled );
// Get a font for labels
conf->setValue("hint_font_size", labelFont.pixelSize());
// orbit drawing params
conf->setValue("orbit_line_flag", Satellite::orbitLinesFlag);
conf->setValue("orbit_line_segments", Satellite::orbitLineSegments);
conf->setValue("orbit_fade_segments", Satellite::orbitLineFadeSegmen
ts);
conf->setValue("orbit_segment_duration", Satellite::orbitLineSegment
Duration);
conf->endGroup();
}
void Satellites::readJsonFile(void)
{
setTleMap(loadTleMap());
}
const QString Satellites::getJsonFileVersion(void)
{
QString jsonVersion("unknown");
QFile satelliteJsonFile(satellitesJsonPath); QFile satelliteJsonFile(satellitesJsonPath);
if (!satelliteJsonFile.open(QIODevice::ReadOnly)) if (!satelliteJsonFile.open(QIODevice::ReadOnly))
{ {
qWarning() << "Satellites::init cannot open " << satellitesJ sonPath; qWarning() << "Satellites::init cannot open " << satellitesJ sonPath;
return 0; return jsonVersion;
} }
int numReadOk = 0;
QVariantMap map; QVariantMap map;
map = StelJsonParser::parse(&satelliteJsonFile).toMap(); map = StelJsonParser::parse(&satelliteJsonFile).toMap();
if (map.contains("creator"))
{
QString creator = map.value("creator").toString();
QRegExp vRx(".*(\\d+\\.\\d+\\.\\d+).*");
if (vRx.exactMatch(creator))
{
jsonVersion = vRx.capturedTexts().at(1);
}
}
satelliteJsonFile.close();
qDebug() << "Satellites::getJsonFileVersion() version from file:" <<
jsonVersion;
return jsonVersion;
}
bool Satellites::saveTleMap(const QVariantMap& map, QString path)
{
if (path.isEmpty())
path = satellitesJsonPath;
QFile jsonFile(path);
StelJsonParser parser;
if (jsonFile.exists())
jsonFile.remove();
if (!jsonFile.open(QIODevice::WriteOnly))
{
qWarning() << "Satellites::saveTleMap() cannot open for writ
ing:" << path;
return false;
}
else
{
qDebug() << "Satellites::saveTleMap() writing to:" << path;
parser.write(map, &jsonFile);
jsonFile.close();
return true;
}
}
QVariantMap Satellites::loadTleMap(QString path)
{
if (path.isEmpty())
path = satellitesJsonPath;
QVariantMap map;
QFile jsonFile(path);
if (!jsonFile.open(QIODevice::ReadOnly))
qWarning() << "Satellites::loadTleMap cannot open " << path;
else
map = StelJsonParser::parse(&jsonFile).toMap();
jsonFile.close();
return map;
}
void Satellites::setTleMap(const QVariantMap& map)
{
int numReadOk = 0;
QVariantList defaultHintColorMap; QVariantList defaultHintColorMap;
defaultHintColorMap << defaultHintColor[0] << defaultHintColor[1] << defaultHintColor[2]; defaultHintColorMap << defaultHintColor[0] << defaultHintColor[1] << defaultHintColor[2];
if (map.contains("hintColor")) if (map.contains("hintColor"))
{ {
defaultHintColorMap = map.value("hintColor").toList(); defaultHintColorMap = map.value("hintColor").toList();
defaultHintColor.set(defaultHintColorMap.at(0).toDouble(), d efaultHintColorMap.at(1).toDouble(), defaultHintColorMap.at(2).toDouble()); defaultHintColor.set(defaultHintColorMap.at(0).toDouble(), d efaultHintColorMap.at(1).toDouble(), defaultHintColorMap.at(2).toDouble());
} }
satellites.clear();
QVariantMap satMap = map.value("satellites").toMap(); QVariantMap satMap = map.value("satellites").toMap();
foreach(QString designation, satMap.keys()) foreach(QString designation, satMap.keys())
{ {
QVariantMap satData = satMap.value(designation).toMap(); QVariantMap satData = satMap.value(designation).toMap();
satData["designation"] = designation; satData["designation"] = designation;
if (!satData.contains("hintColor")) if (!satData.contains("hintColor"))
satData["hintColor"] = defaultHintColorMap; satData["hintColor"] = defaultHintColorMap;
if (!satData.contains("orbitColor"))
satData["orbitColor"] = satData["hintColor"];
SatelliteP sat(new Satellite(satData)); SatelliteP sat(new Satellite(satData));
if (sat->initialized) if (sat->initialized)
{ {
satellites.append(sat); satellites.append(sat);
numReadOk++; numReadOk++;
} }
} }
satelliteJsonFile.close(); }
return numReadOk;
QVariantMap Satellites::getTleMap(void)
{
QVariantMap map;
QVariantList defHintCol;
defHintCol << Satellite::roundToDp(defaultHintColor[0],3)
<< Satellite::roundToDp(defaultHintColor[1],3)
<< Satellite::roundToDp(defaultHintColor[2],3);
map["creator"] = QString("Satellites plugin version %1 (updated)").a
rg(PLUGIN_VERSION);
map["hintColor"] = defHintCol;
map["shortName"] = "satellite orbital data";
QVariantMap sats;
foreach(const SatelliteP& sat, satellites)
{
QVariantMap satMap = sat->getMap();
if (satMap["orbitColor"] == satMap["hintColor"])
satMap.remove("orbitColor");
if (satMap["hintColor"].toList() == defHintCol)
satMap.remove("hintColor");
if (satMap.contains("designation"))
satMap.remove("designation");
sats[sat->designation] = satMap;
}
map["satellites"] = sats;
return map;
} }
QStringList Satellites::getGroups(void) const QStringList Satellites::getGroups(void) const
{ {
QStringList groups; QStringList groups;
foreach (const SatelliteP& sat, satellites) foreach (const SatelliteP& sat, satellites)
{ {
if (sat->initialized) if (sat->initialized)
{ {
foreach(QString group, sat->groupIDs) foreach(QString group, sat->groupIDs)
skipping to change at line 534 skipping to change at line 746
void Satellites::checkForUpdate(void) void Satellites::checkForUpdate(void)
{ {
if (updatesEnabled && lastUpdate.addSecs(updateFrequencyHours * 3600 ) <= QDateTime::currentDateTime()) if (updatesEnabled && lastUpdate.addSecs(updateFrequencyHours * 3600 ) <= QDateTime::currentDateTime())
updateTLEs(); updateTLEs();
} }
void Satellites::updateTLEs(void) void Satellites::updateTLEs(void)
{ {
if (updateState==Satellites::Updating) if (updateState==Satellites::Updating)
{ {
qWarning() << "Satellites::updateTLEs already updating... w ill not start again current update is complete"; qWarning() << "Satellites: already updating... will not sta rt again current update is complete.";
return; return;
} }
else else
{ {
qDebug() << "Satellites::updateTLEs starting update"; qDebug() << "Satellites: starting update...";
} }
lastUpdate = QDateTime::currentDateTime(); lastUpdate = QDateTime::currentDateTime();
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
conf->setValue("Satellites/last_update", lastUpdate.toString("yyyy-M M-dd HH:mm:ss")); conf->setValue("Satellites/last_update", lastUpdate.toString(Qt::ISO Date));
if (updateUrls.size() == 0) if (updateUrls.size() == 0)
{ {
qWarning() << "Satellites::updateTLEs no update URLs are def qWarning() << "Satellites::updateTLEs no update URLs are def
ined... nothing to do"; ined... nothing to do.";
emit(TleUpdateComplete(0)); emit(tleUpdateComplete(0,satellites.count(),satellites.count
()));
return; return;
} }
updateState = Satellites::Updating; updateState = Satellites::Updating;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
updateFiles.clear(); updateFiles.clear();
numberDownloadsComplete = 0; numberDownloadsComplete = 0;
if (progressBar==NULL) if (progressBar==NULL)
progressBar = StelApp::getInstance().getGui()->addProgressBa r(); progressBar = StelApp::getInstance().getGui()->addProgressBa r();
skipping to change at line 588 skipping to change at line 800
qWarning() << "Satellites::updateDownloadComplete FAILED to download" << reply->url() << " Error: " << reply->errorString(); qWarning() << "Satellites::updateDownloadComplete FAILED to download" << reply->url() << " Error: " << reply->errorString();
} }
else else
{ {
// download completed successfully. // download completed successfully.
try try
{ {
QString partialName = QString("tle%1.txt").arg(numbe rDownloadsComplete); QString partialName = QString("tle%1.txt").arg(numbe rDownloadsComplete);
QString tleTmpFilePath = StelFileMgr::findFile("modu les/Satellites", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Dire ctory)) + "/" + partialName; QString tleTmpFilePath = StelFileMgr::findFile("modu les/Satellites", StelFileMgr::Flags(StelFileMgr::Writable|StelFileMgr::Dire ctory)) + "/" + partialName;
QFile tmpFile(tleTmpFilePath); QFile tmpFile(tleTmpFilePath);
tmpFile.remove(); if (tmpFile.exists())
tmpFile.remove();
tmpFile.open(QIODevice::WriteOnly | QIODevice::Text) ; tmpFile.open(QIODevice::WriteOnly | QIODevice::Text) ;
tmpFile.write(reply->readAll()); tmpFile.write(reply->readAll());
tmpFile.close(); tmpFile.close();
updateFiles << tleTmpFilePath; updateFiles << tleTmpFilePath;
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
qWarning() << "Satellites::updateDownloadComplete: c annot write TLE data to file:" << e.what(); qWarning() << "Satellites::updateDownloadComplete: c annot write TLE data to file:" << e.what();
} }
} }
numberDownloadsComplete++; numberDownloadsComplete++;
if (progressBar) if (progressBar)
progressBar->setValue(numberDownloadsComplete); progressBar->setValue(numberDownloadsComplete);
// all downloads are complete... do the update. // all downloads are complete... do the update.
if (numberDownloadsComplete >= updateUrls.size()) if (numberDownloadsComplete >= updateUrls.size())
{ {
updateFromFiles(); updateFromFiles(updateFiles, true);
} }
} }
void Satellites::observerLocationChanged(StelLocation loc) void Satellites::observerLocationChanged(StelLocation loc)
{ {
foreach(const SatelliteP& sat, satellites) foreach(const SatelliteP& sat, satellites)
{ {
if (sat->initialized && sat->visible) if (sat->initialized && sat->visible)
sat->setObserverLocation(&loc); sat->setObserverLocation(&loc);
} }
recalculateOrbitLines();
}
void Satellites::setOrbitLinesFlag(bool b)
{
Satellite::orbitLinesFlag = b;
} }
void Satellites::updateFromFiles(void) bool Satellites::getOrbitLinesFlag(void)
{
return Satellite::orbitLinesFlag;
}
void Satellites::recalculateOrbitLines(void)
{
foreach(const SatelliteP& sat, satellites)
{
if (sat->initialized && sat->visible && sat->orbitVisible)
sat->recalculateOrbitLines();
}
}
void Satellites::displayMessage(const QString& message, const QString hexCo
lor)
{
messageIDs << GETSTELMODULE(LabelMgr)->labelScreen(message, 30, 30 +
(20*messageIDs.count()), true, 16, hexColor);
messageTimer->start();
}
void Satellites::messageTimeout(void)
{
foreach(int i, messageIDs)
{
GETSTELMODULE(LabelMgr)->deleteLabel(i);
}
}
void Satellites::saveTleData(QString path)
{
saveTleMap(getTleMap(), path);
}
void Satellites::updateFromFiles(QStringList paths, bool deleteFiles)
{ {
// define a map of new TLE data - the key is the satellite designati on // define a map of new TLE data - the key is the satellite designati on
QMap< QString, QPair<QString, QString> > newTLE; QMap< QString, QPair<QString, QString> > newTLE;
if (progressBar) if (progressBar)
{ {
progressBar->setValue(0); progressBar->setValue(0);
progressBar->setMaximum(updateFiles.size() + 1); progressBar->setMaximum(paths.size() + 1);
progressBar->setFormat("TLE updating %v/%m"); progressBar->setFormat("TLE updating %v/%m");
} }
foreach(QString tleFilePath, updateFiles) foreach(QString tleFilePath, paths)
{ {
QFile tleFile(tleFilePath); QFile tleFile(tleFilePath);
if (tleFile.open(QIODevice::ReadOnly|QIODevice::Text)) if (tleFile.open(QIODevice::ReadOnly|QIODevice::Text))
{ {
int lineNumber = 0; int lineNumber = 0;
QString thisSatId(""); QString thisSatId("");
QPair<QString, QString> tleLines; QPair<QString, QString> tleLines;
while (!tleFile.atEnd()) { while (!tleFile.atEnd()) {
QString line = QString(tleFile.readLine()).t rimmed(); QString line = QString(tleFile.readLine()).t rimmed();
if (line.length() < 65) // this is a new des ignation if (line.length() < 65) // this is a new des ignation
{ {
if (thisSatId!="" && !tleLines.first .isEmpty() && !tleLines.second.isEmpty()) if (thisSatId!="" && !tleLines.first .isEmpty() && !tleLines.second.isEmpty())
{ {
newTLE[thisSatId] = tleLines ; newTLE[thisSatId] = tleLines ;
} }
thisSatId = line; thisSatId = line;
thisSatId.replace(QRegExp("\\[[^\\]] *\\]\\s*$"),""); // remove things in square brackets thisSatId.replace(QRegExp("\\s*\\[([ ^\\]])*\\]\\s*$"),""); // remove things in square brackets
tleLines.first = QString(); tleLines.first = QString();
tleLines.second = QString(); tleLines.second = QString();
} }
else else
{ {
if (QRegExp("^1 .*").exactMatch(line )) if (QRegExp("^1 .*").exactMatch(line ))
tleLines.first = line; tleLines.first = line;
else if (QRegExp("^2 .*").exactMatch (line)) else if (QRegExp("^2 .*").exactMatch (line))
tleLines.second = line; tleLines.second = line;
else else
qDebug() << "Satellites::upd ateFromFiles unprocessed line " << lineNumber << " in file " << tleFilePat h; qDebug() << "Satellites::upd ateFromFiles(): unprocessed line " << lineNumber << " in file " << tleFile Path;
} }
} }
if (thisSatId!="" && !tleLines.first.isEmpty() && !t leLines.second.isEmpty()) if (thisSatId!="" && !tleLines.first.isEmpty() && !t leLines.second.isEmpty())
{ {
newTLE[thisSatId] = tleLines; newTLE[thisSatId] = tleLines;
} }
tleFile.close(); tleFile.close();
if (deleteFiles)
tleFile.remove();
if (progressBar) if (progressBar)
progressBar->setValue(progressBar->value() + 1); progressBar->setValue(progressBar->value() + 1);
} }
tleFile.remove(); // clean up downloaded TLE files
} }
QFile satelliteJsonFile(satellitesJsonPath);
StelJsonParser parser;
QVariantMap map;
if (!satelliteJsonFile.open(QIODevice::ReadOnly))
{
qWarning() << "Satellites::updateFromFiles cannot open for r
eading " << satellitesJsonPath;
}
else
{
map = parser.parse(&satelliteJsonFile).toMap();
satelliteJsonFile.close();
}
// Right, we should now have a map of all the elements we downloaded . For each satellite // Right, we should now have a map of all the elements we downloaded . For each satellite
// which this module is managing, see if it exists with an updated e lement, and update it if so... // which this module is managing, see if it exists with an updated e lement, and update it if so...
int numUpdated = 0; int numUpdated = 0;
QVariantList defCol; int totalSats = 0;
defCol << (double)defaultHintColor[0] << (double)defaultHintColor[1] int numMissing = 0;
<< (double)defaultHintColor[2];
map["creator"] = "Satellites plugin (update)";
map["hintColor"] = defCol;
map["shortName"] = "satellite orbital data";
QVariantMap sats = map["satellites"].toMap();
foreach(const SatelliteP& sat, satellites) foreach(const SatelliteP& sat, satellites)
{ {
totalSats++;
if (newTLE.contains(sat->designation)) if (newTLE.contains(sat->designation))
{ {
if (sat->elements[1] != newTLE[sat->designation].fir if ( sat->tleElements.first != newTLE[sat->design
st || sat->elements[2] != newTLE[sat->designation].second) ation].first
|| sat->tleElements.second != newTLE[sat->design
ation].second)
{ {
QVariantMap satMap = sat->getMap();
satMap.remove("designation");
if (satMap["hintColor"].toList() == defCol)
satMap.remove("hintColor");
// We have updated TLE elements for this sat ellite // We have updated TLE elements for this sat ellite
// update the satellites.json file sat->setNewTleElements(newTLE[sat->designati
satMap["tle1"] = newTLE[sat->designation].fi on].first, newTLE[sat->designation].second);
rst;
satMap["tle2"] = newTLE[sat->designation].se // we reset this to "now" when we started th
cond; e update.
strncpy(sat->elements[1], qPrintable(newTLE[ sat->lastUpdated = lastUpdate;
sat->designation].first), 80);
strncpy(sat->elements[2], qPrintable(newTLE[
sat->designation].second), 80);
numUpdated++; numUpdated++;
qDebug() << "updated orbital elements for: "
<< sat->designation;
sats[sat->designation] = satMap;
} }
} }
else
{
qWarning() << "Satellites: could not update orbital
elements for" << sat->designation <<": no entry found in the source TLE lis
ts.";
numMissing++;
}
} }
map["satellites"] = sats;
if (numUpdated>0) if (numUpdated>0)
{ {
satelliteJsonFile.remove(); saveTleMap(getTleMap());
if (!satelliteJsonFile.open(QIODevice::WriteOnly))
{
qWarning() << "Satellites::updateFromFiles cannot op
en for writing " << satellitesJsonPath;
}
else
{
qDebug() << "Satellites::updateFromFiles Writing upd
ated JSON file";
parser.write(map, &satelliteJsonFile);
satelliteJsonFile.close();
}
} }
delete progressBar; delete progressBar;
progressBar = NULL; progressBar = NULL;
qDebug() << "Satellites::updateFromFiles updated orbital elements fo qDebug() << "Satellites: updated" << numUpdated << "/" << totalSats
r " << numUpdated << " satellites"; << "satellites. Update URLs contained" << newTLE.size() <<
"objects. "
<< "There were" << numMissing << "satellies missing from th
e update URLs";
if (numUpdated==0) if (numUpdated==0)
updateState = CompleteNoUpdates; updateState = CompleteNoUpdates;
else else
updateState = CompleteUpdates; updateState = CompleteUpdates;
emit(updateStateChanged(updateState)); emit(updateStateChanged(updateState));
emit(TleUpdateComplete(numUpdated)); emit(tleUpdateComplete(numUpdated, totalSats, numMissing));
} }
void Satellites::update(double deltaTime) void Satellites::update(double deltaTime)
{ {
if (StelApp::getInstance().getCore()->getNavigator()->getCurrentLoca tion().planetName != earth->getEnglishName() || (!hintFader && hintFader.ge tInterstate() <= 0.)) if (StelApp::getInstance().getCore()->getNavigator()->getCurrentLoca tion().planetName != earth->getEnglishName() || (!hintFader && hintFader.ge tInterstate() <= 0.))
return; return;
hintFader.update((int)(deltaTime*1000)); hintFader.update((int)(deltaTime*1000));
foreach(const SatelliteP& sat, satellites) foreach(const SatelliteP& sat, satellites)
skipping to change at line 776 skipping to change at line 1006
StelProjectorP prj = core->getProjection(StelCore::FrameAltAz); StelProjectorP prj = core->getProjection(StelCore::FrameAltAz);
StelPainter painter(prj); StelPainter painter(prj);
painter.setFont(labelFont); painter.setFont(labelFont);
Satellite::hintBrightness = hintFader.getInterstate(); Satellite::hintBrightness = hintFader.getInterstate();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
Satellite::hintTexture->bind(); Satellite::hintTexture->bind();
Satellite::viewportHalfspace = painter.getProjector()->getBoundingCa p();
foreach (const SatelliteP& sat, satellites) foreach (const SatelliteP& sat, satellites)
{ {
if (sat && sat->initialized && sat->visible) if (sat && sat->initialized && sat->visible)
sat->draw(core, painter, 1.0); sat->draw(core, painter, 1.0);
} }
if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer()) if (GETSTELMODULE(StelObjectMgr)->getFlagSelectedObjectPointer())
drawPointer(core, painter); drawPointer(core, painter);
} }
 End of changes. 66 change blocks. 
108 lines changed or deleted 357 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/