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";
86 qDeleteAll(m_ObjectList);
89 objectNames(SkyObject::COMET).
clear();
90 objectLists(SkyObject::COMET).
clear();
96 KSUtils::MPCParser com_parser(file_name);
101 name = get(
"Designation_and_name").toString();
103 int perihelion_year, perihelion_month, perihelion_day, perihelion_hour, perihelion_minute, perihelion_second;
106 double perihelion_distance = get(
"Perihelion_dist").toDouble();
108 double eccentricity = get(
"e").toDouble();
110 double perihelion_argument = get(
"Peri").toDouble();
112 double ascending_node = get(
"Node").toDouble();
114 double inclination = get(
"i").toDouble();
117 perihelion_year = get(
"Year_of_perihelion").toInt();
118 perihelion_month = get(
"Month_of_perihelion").toInt();
120 double peri_day = get(
"Day_of_perihelion").toDouble();
121 perihelion_day =
static_cast<int>(peri_day);
122 double peri_hour = (peri_day - perihelion_day) * 24;
123 perihelion_hour =
static_cast<int>(peri_hour);
124 perihelion_minute =
static_cast<int>((peri_hour - perihelion_hour) * 60);
125 perihelion_second = ( (( peri_hour - perihelion_hour) * 60) - perihelion_minute) * 60;
128 QTime(perihelion_hour, perihelion_minute, perihelion_second)).
djd();
131 orbit_class = get(
"Orbit_type").toString();
132 double absolute_magnitude = get(
"H").toDouble();
133 double slope_parameter = get(
"G").toDouble();
140 dms(perihelion_argument),
153 objectNames(SkyObject::COMET).append(com->
name());
154 objectLists(SkyObject::COMET).append(QPair<QString, const SkyObject *>(com->
name(), com));
157 catch (
const std::runtime_error&)
159 qCInfo(KSTARS) <<
"Loading comets failed.";
160 qCInfo(KSTARS) <<
" -> was trying to read " + file_name;
256 if (!
selected() || Options::zoomFactor() < 1 * MINZOOM)
259 bool hideLabels = !Options::showCometNames() || (SkyMap::Instance()->isSlewing() && Options::hideLabels());
260 double rsunLabelLimit = Options::maxRadCometName();
266 for (
auto so : m_ObjectList)
269 double mag = com->
mag();
270 if (std::isnan(mag) == 0)
273 if (drawn && !(hideLabels || com->
rsun() >= rsunLabelLimit))
309void CometsComponent::updateDataFile(
bool isAutoUpdate)
311 delete (downloadJob);
312 downloadJob =
new FileDownloader();
314 if (isAutoUpdate ==
false)
315 downloadJob->setProgressDialogEnabled(
true,
i18n(
"Comets Update"),
316 i18n(
"Downloading comets updates..."));
318 connect(downloadJob, SIGNAL(downloaded()),
this, SLOT(downloadReady()));
321 if (isAutoUpdate ==
false)
324 QUrl url =
QUrl(
"https://www.minorplanetcenter.net/Extended_Files/cometels.json.gz");
325 downloadJob->get(url);
328void CometsComponent::downloadReady()
331 QByteArray data = downloadJob->downloadedData();
335 .filePath(
"cometels.json.gz"));
342 qCWarning(KSTARS) <<
"Failed writing comet data to" << file.fileName();
348 if (foc && foc->
type() == SkyObject::COMET)
350 focusedComet = foc->
name();
355 if (foc && foc->
type() == SkyObject::COMET)
357 focusedComet = foc->
name();
377 downloadJob->deleteLater();
433void CometsComponent::downloadError(
const QString &errorString)
435 KSNotification::error(
i18n(
"Error downloading asteroids data: %1", errorString));
436 qCCritical(KSTARS) << errorString;
437 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