9#include "supernovaecomponent.h"
15#include "kstarslite.h"
18#include "kstars_debug.h"
19#include "ksnotification.h"
20#include "kstarsdata.h"
22#include "skylabeler.h"
24#include "skypainter.h"
25#include "auxiliary/filedownloader.h"
26#include "projections/projector.h"
27#include "auxiliary/kspaths.h"
29#include <QtConcurrent>
30#include <QJsonDocument>
39const QString SupernovaeComponent::tnsDataFilename(
"tns_public_objects.csv");
40const QString SupernovaeComponent::tnsDataFilenameZip(
"tns-daily.csv.gz");
41const QString SupernovaeComponent::tnsDataUrl(
42 "https://indilib.org/jdownloads/kstars/tns-daily.csv.gz");
48 connect(Options::self(), &Options::SupernovaDownloadUrlChanged,
this,
49 &SupernovaeComponent::loadData);
50 connect(Options::self(), &Options::MagnitudeLimitShowSupernovaeChanged,
this,
51 &SupernovaeComponent::loadData);
60 for (
auto so : m_ObjectList)
63 so->updateCoords(num);
64 so->EquatorialToHorizontal(data->
lst(), data->
geo()->
lat());
70 return Options::showSupernovae();
73void SupernovaeComponent::loadData()
75 qDeleteAll(m_ObjectList);
78 objectNames(SkyObject::SUPERNOVA).
clear();
79 objectLists(SkyObject::SUPERNOVA).
clear();
85 io::CSVReader<26, io::trim_chars<
' '>, io::double_quote_escape<
',',
'\"'>,
87 in(sFileName.toLocal8Bit());
89 const char *line = in.next_line();
92 qCritical() <<
"file is empty\n";
96 std::string id,
name, ra_s, dec_s,
type;
98 std::string host_name;
100 std::string reporting_group, disc_datasource, classifying_group, assoc_group,
101 disc_internal_name, disc_instrument, classifying_instrument;
102 int tns_at, is_public;
103 std::string end_prop_period;
104 double discovery_mag;
105 std::string discovery_filter, discovery_date_s,
sender, remarks,
106 discovery_bibcode, classification_bibcode, ext_catalog;
109 id, name, ra_s, dec_s, type, redshift, host_name, host_redshift,
110 reporting_group, disc_datasource, classifying_group, assoc_group,
111 disc_internal_name, disc_instrument, classifying_instrument, tns_at,
112 is_public, end_prop_period, discovery_mag, discovery_filter, discovery_date_s,
113 sender, remarks, discovery_bibcode, classification_bibcode, ext_catalog))
115 auto discovery_date =
123 QString(discovery_date_s.c_str()), redshift, discovery_mag, discovery_date);
125 objectNames(SkyObject::SUPERNOVA).append(
QString(
name.c_str()));
128 objectLists(SkyObject::SUPERNOVA)
129 .append(QPair<QString, const SkyObject *>(qname, sup));
132 m_DataLoading =
false;
135 catch (io::error::can_not_open_file &ex)
137 qCCritical(KSTARS) <<
"could not open file " << sFileName.toLocal8Bit() <<
"\n";
140 catch (std::exception &ex)
142 qCCritical(KSTARS) <<
"unknown exception happened:" << ex.what() <<
"\n";
152 double rBest = maxrad;
154 for (
auto &so : m_ObjectList)
156 double r = so->angularDistanceTo(p).Degrees();
171 double lgmin = log10(MINZOOM);
172 double lgz = log10(Options::zoomFactor());
174 return 14.0 + 2.222 * (lgz - lgmin) +
175 2.222 * log10(
static_cast<double>(Options::starDensity()));
183 else if (!m_DataLoaded)
187 m_DataLoading =
true;
194 double refage = Options::supernovaDetectionAge();
195 bool hostOnly = Options::supernovaeHostOnly();
196 bool classifiedOnly = Options::supernovaeClassifiedOnly();
198 for (
auto so : m_ObjectList)
201 float mag = sup->
mag();
202 float age = sup->getAgeDays();
205 if (mag >
float(Options::magnitudeLimitShowSupernovae()))
216 if (mag > maglim && Options::limitSupernovaeByZoom())
220 if (classifiedOnly && type ==
"")
228void SupernovaeComponent::notifyNewSupernovae()
237 if (sup->getMagnitude() > float(Options::magnitudeLimitAlertSupernovae()))
246 if (!latestList.
empty())
248 NotifyUpdatesUI * ui =
new NotifyUpdatesUI(0);
249 ui->addItems(latestList);
260 delete (downloadJob);
261 downloadJob =
new FileDownloader();
262 QString url = Options::supernovaDownloadUrl();
268 qInfo() <<
"fetching data from web: " << url <<
"\n";
269 downloadJob->setProgressDialogEnabled(
true,
i18n(
"Supernovae Update"),
270 i18n(
"Downloading Supernovae updates..."));
272 QObject::connect(downloadJob, SIGNAL(downloaded()),
this, SLOT(downloadReady()));
277 downloadJob->get(
QUrl(url));
284 qInfo() <<
"fetching data from local file at: " << fname <<
"\n";
287 qInfo() <<
"copy returned: " << res <<
"\n";
295void SupernovaeComponent::unzipData()
306 auto fhz = gzopen(ifpath.c_str(),
"rb");
307 auto fout = fopen(ofpath.c_str(),
"wb");
311 printf(
"Error: Failed to gzopen %s\n", ifpath.c_str());
314 unsigned char unzipBuffer[8192];
315 unsigned int unzippedBytes;
318 unzippedBytes = gzread(fhz, unzipBuffer, 8192);
319 if (unzippedBytes > 0)
321 fwrite(unzipBuffer, 1, unzippedBytes, fout);
332void SupernovaeComponent::downloadReady()
343 downloadJob->deleteLater();
346void SupernovaeComponent::downloadError(
const QString &errorString)
348 KSNotification::error(
i18n(
"Error downloading supernova data: %1", errorString));
349 downloadJob->deleteLater();
const CachingDms * lat() const
There are several time-dependent values used in position calculations, that are not specific to an ob...
KStarsData is the backbone of KStars.
void setFullTimeUpdate()
The Sky is updated more frequently than the moon, which is updated more frequently than the planets.
static KStarsLite * Instance()
KStarsData * data() const
static KStars * Instance()
KStarsData * data() const
An abstract parent class, to be inherited by SkyComponents that store a QList of SkyObjects.
void appendListObject(SkyObject *object)
Add an object to the Object list.
SkyComposite is a kind of container class for SkyComponent objects.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Draws things on the sky, without regard to backend.
virtual bool drawSupernova(Supernova *sup)=0
Draw a Supernova.
The sky coordinates of a point in the sky.
Represents the supernova object.
QString getHostGalaxy() const
void slotTriggerDataFileUpdate()
This initiates updating of the data file.
void draw(SkyPainter *skyp) override
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
static float zoomMagnitudeLimit()
void update(KSNumbers *num=nullptr) override
Update the sky positions of this component.
An angle, stored as degrees, but expressible in many ways.
QString i18n(const char *text, const TYPE &arg...)
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QDateTime fromString(QStringView string, QStringView format, QCalendar cal)
QString filePath(const QString &fileName) const const
bool copy(const QString &fileName, const QString &newName)
void append(QList< T > &&value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * sender() const const
QString right(qsizetype n) const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
std::string toStdString() const const
QTextStream & dec(QTextStream &stream)
QFuture< T > run(Function function,...)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl fromLocalFile(const QString &localFile)