7#include "cometscomponent.h"
12#include "ksfilereader.h"
14#include "kstarsdata.h"
16#include "ksnotification.h"
17#include "kstars_debug.h"
21#include "kstarslite.h"
24#include "skylabeler.h"
25#include "skypainter.h"
26#include "solarsystemcomposite.h"
27#include "auxiliary/filedownloader.h"
28#include "auxiliary/kspaths.h"
29#include "projections/projector.h"
30#include "skyobjects/kscomet.h"
33#include <QHttpMultiPart>
35#include <QStandardPaths>
47 return Options::showComets();
79void CometsComponent::loadData()
84 qCInfo(KSTARS) <<
"Loading comets";
87 objectNames(SkyObject::COMET).
clear();
88 objectLists(SkyObject::COMET).
clear();
94 KSUtils::MPCParser com_parser(file_name);
99 name = get(
"Designation_and_name").toString();
101 int perihelion_year, perihelion_month, perihelion_day, perihelion_hour, perihelion_minute, perihelion_second;
104 double perihelion_distance = get(
"Perihelion_dist").toDouble();
106 double eccentricity = get(
"e").toDouble();
108 double perihelion_argument = get(
"Peri").toDouble();
110 double ascending_node = get(
"Node").toDouble();
112 double inclination = get(
"i").toDouble();
115 perihelion_year = get(
"Year_of_perihelion").toInt();
116 perihelion_month = get(
"Month_of_perihelion").toInt();
118 double peri_day = get(
"Day_of_perihelion").toDouble();
119 perihelion_day =
static_cast<int>(peri_day);
120 double peri_hour = (peri_day - perihelion_day) * 24;
121 perihelion_hour =
static_cast<int>(peri_hour);
122 perihelion_minute =
static_cast<int>((peri_hour - perihelion_hour) * 60);
123 perihelion_second = ( (( peri_hour - perihelion_hour) * 60) - perihelion_minute) * 60;
126 QTime(perihelion_hour, perihelion_minute, perihelion_second)).
djd();
129 orbit_class = get(
"Orbit_type").toString();
130 double absolute_magnitude = get(
"H").toDouble();
131 double slope_parameter = get(
"G").toDouble();
138 dms(perihelion_argument),
151 objectNames(SkyObject::COMET).append(com->
name());
152 objectLists(SkyObject::COMET).append(QPair<QString, const SkyObject *>(com->
name(), com));
155 catch (
const std::runtime_error &)
157 qCInfo(KSTARS) <<
"Loading comets failed.";
158 qCInfo(KSTARS) <<
" -> was trying to read " + file_name;
254 if (!
selected() || Options::zoomFactor() < 1 * MINZOOM)
257 bool hideLabels = !Options::showCometNames() || (SkyMap::Instance()->isSlewing() && Options::hideLabels());
258 double rsunLabelLimit = Options::maxRadCometName();
264 for (
auto so : m_ObjectList)
267 double mag = com->
mag();
268 if (std::isnan(mag) == 0)
271 if (drawn && !(hideLabels || com->
rsun() >= rsunLabelLimit))
307void CometsComponent::updateDataFile(
bool isAutoUpdate)
309 delete (downloadJob);
310 downloadJob =
new FileDownloader();
312 if (isAutoUpdate ==
false)
313 downloadJob->setProgressDialogEnabled(
true,
i18n(
"Comets Update"),
314 i18n(
"Downloading comets updates..."));
316 connect(downloadJob, SIGNAL(downloaded()),
this, SLOT(downloadReady()));
319 if (isAutoUpdate ==
false)
322 QUrl url =
QUrl(
"https://www.minorplanetcenter.net/Extended_Files/cometels.json.gz");
323 downloadJob->get(url);
326void CometsComponent::downloadReady()
329 QByteArray data = downloadJob->downloadedData();
333 .filePath(
"cometels.json.gz"));
340 qCWarning(KSTARS) <<
"Failed writing comet data to" << file.fileName();
346 if (foc && foc->
type() == SkyObject::COMET)
348 focusedComet = foc->
name();
353 if (foc && foc->
type() == SkyObject::COMET)
355 focusedComet = foc->
name();
375 downloadJob->deleteLater();
431void CometsComponent::downloadError(
const QString &errorString)
433 KSNotification::error(
i18n(
"Error downloading asteroids data: %1", errorString));
434 qCCritical(KSTARS) << errorString;
435 downloadJob->deleteLater();
CometsComponent(SolarSystemComposite *parent)
Default constructor.
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
A subclass of KSPlanetBase that implements comets.
void setOrbitClass(QString orbit_class)
Sets the comet's orbit class.
void setAngularSize(double size)
set the planet's angular size, in km.
void setFullTimeUpdate()
The Sky is updated more frequently than the moon, which is updated more frequently than the planets.
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
static KStarsLite * Instance()
KStarsData * data() const
static KStars * Instance()
KStarsData * data() const
void appendListObject(SkyObject *object)
Add an object to the Object list.
virtual void emitProgressText(const QString &message)
Emit signal about progress.
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
void setFocusObject(SkyObject *o)
Set the FocusObject pointer to the argument.
SkyObject * focusObject() const
Retrieve the object which is centered in the sky map.
void setFocusObject(SkyObject *o)
Set the FocusObject pointer to the argument.
SkyObject * focusObject() const
Retrieve the object which is centered in the sky map.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
virtual QString name(void) const
Draws things on the sky, without regard to backend.
virtual bool drawComet(KSComet *com)=0
Draw a comet in the sky.
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
The solar system composite manages all planets, asteroids and comets.
An angle, stored as degrees, but expressible in many ways.
QString i18n(const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const