7#include "planetviewer.h"
9#include "ksfilereader.h"
11#include "kstarsdata.h"
13#include "skyobjects/ksplanet.h"
14#include "skyobjects/ksplanetbase.h"
15#include "widgets/timespinbox.h"
17#include <KLocalizedString>
19#include <kplotobject.h>
20#include <kplotpoint.h>
21#include <kplotwidget.h>
30#include <qtskipemptyparts.h>
37PlanetViewer::PlanetViewer(
QWidget *parent) :
QDialog(parent), scale(1.0), isClockRunning(false), tmr(this)
43 pw =
new PlanetViewerUI(
this);
48 setLayout(mainLayout);
50 setWindowTitle(
i18nc(
"@title:window",
"Solar System Viewer"));
55 pw->map->setLimits(-48.0, 48.0, -48.0, 48.0);
57 ->setLabel(
i18nc(
"axis label for x-coordinate of solar system viewer. AU means astronomical unit.",
60 ->setLabel(
i18nc(
"axis label for y-coordinate of solar system viewer. AU means astronomical unit.",
63 pw->TimeStep->setDaysOnly(
true);
64 pw->TimeStep->tsbox()->setValue(1);
69 pw->DateBox->setDate(data->
lt().
date());
72 pw->map->QWidget::setFocus();
76 PlanetList.append(KSPlanetBase::createPlanet(KSPlanetBase::MERCURY));
77 PlanetList.append(KSPlanetBase::createPlanet(KSPlanetBase::VENUS));
79 PlanetList.append(KSPlanetBase::createPlanet(KSPlanetBase::MARS));
80 PlanetList.append(KSPlanetBase::createPlanet(KSPlanetBase::JUPITER));
81 PlanetList.append(KSPlanetBase::createPlanet(KSPlanetBase::SATURN));
82 PlanetList.append(KSPlanetBase::createPlanet(KSPlanetBase::URANUS));
83 PlanetList.append(KSPlanetBase::createPlanet(KSPlanetBase::NEPTUNE));
89 for (
int i = 0; i < PlanetList.count(); ++i)
91 PlanetList[i]->findPosition(&num,
nullptr,
nullptr);
92 LastUpdate[i] = int(ut.date().toJulianDay());
96 UpdateInterval[0] = 0;
97 UpdateInterval[1] = 0;
98 UpdateInterval[2] = 0;
99 UpdateInterval[3] = 1;
100 UpdateInterval[4] = 5;
101 UpdateInterval[5] = 13;
102 UpdateInterval[6] = 38;
103 UpdateInterval[7] = 75;
108 connect(&tmr, SIGNAL(timeout()), SLOT(tick()));
109 connect(pw->TimeStep, SIGNAL(scaleChanged(
float)), SLOT(setTimeScale(
float)));
110 connect(pw->RunButton, SIGNAL(clicked()), SLOT(slotRunClock()));
111 connect(pw->ZoomInButton, SIGNAL(clicked()), pw->map, SLOT(slotZoomIn()));
112 connect(pw->ZoomOutButton, SIGNAL(clicked()), pw->map, SLOT(slotZoomOut()));
113 connect(pw->DateBox, SIGNAL(dateChanged(
QDate)), SLOT(slotChangeDate()));
114 connect(pw->TodayButton, SIGNAL(clicked()), SLOT(slotToday()));
115 connect(
this, SIGNAL(closeClicked()), SLOT(slotCloseWindow()));
118QString PlanetViewer::planetName(uint i)
const
120 return PlanetList[i]->name();
123void PlanetViewer::tick()
126 ut.setDJD(ut.djd() + scale * 0.1);
127 pw->DateBox->setDate(ut.date());
132void PlanetViewer::setTimeScale(
float f)
137void PlanetViewer::slotRunClock()
139 isClockRunning = !isClockRunning;
143 pw->RunButton->setIcon(
156void PlanetViewer::slotChangeDate()
158 ut.setDate(pw->DateBox->date());
162void PlanetViewer::slotCloseWindow()
168 isClockRunning =
false;
173void PlanetViewer::updatePlanets()
175 KSNumbers num(ut.djd());
179 for (
int i = 0; i < PlanetList.count(); ++i)
181 if (abs(
int(ut.date().toJulianDay()) - LastUpdate[i]) > UpdateInterval[i])
183 KSPlanetBase *p = PlanetList[i];
189 QList<KPlotPoint *> points = planet[i]->points();
190 points.
at(0)->setX(p->
rsun() * c * c2);
191 points.
at(0)->setY(p->
rsun() * s * c2);
193 if (centerPlanet() == p->
name())
195 QRectF dataRect = pw->map->dataRect();
196 double xc = (dataRect.
right() + dataRect.
left()) * 0.5;
197 double yc = (dataRect.
bottom() + dataRect.
top()) * 0.5;
198 double dx = points.
at(0)->x() - xc;
199 double dy = points.
at(0)->y() - yc;
200 pw->map->setLimits(dataRect.
x() + dx, dataRect.
right() + dx, dataRect.
y() + dy, dataRect.
bottom() + dy);
203 LastUpdate[i] = int(ut.date().toJulianDay());
212void PlanetViewer::slotToday()
214 pw->DateBox->setDate(KStarsData::Instance()->lt().date());
222void PlanetViewer::initPlotObjects()
226 ksun->addPoint(0.0, 0.0);
227 pw->map->addPlotObject(ksun);
230 for (
int i = 0; i < PlanetList.count(); ++i)
232 KSPlanetBase *p = PlanetList[i];
236 QString orbitFileName =
237 (p->
isMajorPlanet() ? (
dynamic_cast<KSPlanet *
>(p))->untranslatedName().toLower() : p->
name().
toLower()) +
".orbit";
238 if (KSUtils::openDataFile(orbitFile, orbitFileName))
240 KSFileReader fileReader(orbitFile);
242 while (fileReader.hasMoreLines())
244 QString line = fileReader.readLine();
246 if (fields.size() == 3)
248 x = fields[0].toDouble();
249 y = fields[1].toDouble();
255 pw->map->addPlotObject(orbit);
258 for (
int i = 0; i < PlanetList.count(); ++i)
260 KSPlanetBase *p = PlanetList[i];
267 pw->map->addPlotObject(planet[i]);
273void PlanetViewer::keyPressEvent(
QKeyEvent *e)
void addPoint(const QPointF &p, const QString &label=QString(), double barWidth=0.0)
There are several time-dependent values used in position calculations, that are not specific to an ob...
void findPosition(const KSNumbers *num, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, const KSPlanetBase *Earth=nullptr)
Find position, including correction for Figure-of-the-Earth.
const dms & helEcLat() const
const dms & helEcLong() const
bool isMajorPlanet() const
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
KStarsData is the backbone of KStars.
const KStarsDateTime & lt() const
const KStarsDateTime & ut() const
QString translatedName() const
virtual QString name(void) const
void SinCos(double &s, double &c) const
Compute Sine and Cosine of the angle simultaneously.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QIcon fromTheme(const QString &name)
const_reference at(qsizetype i) const const
qreal bottom() const const
qreal right() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString toLower() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)