7#include "modcalcplanets.h"
9#include "geolocation.h"
10#include "kstarsdata.h"
11#include "ksnotification.h"
12#include "dialogs/locationdialog.h"
13#include "skyobjects/ksmoon.h"
14#include "skyobjects/kssun.h"
16modCalcPlanets::modCalcPlanets(
QWidget *parentSplit) :
QFrame(parentSplit)
22 DateTimeBox->setDateTime(dt);
23 DateBoxBatch->setDate(dt.date());
24 UTBoxBatch->setTime(dt.time());
26 geoPlace = KStarsData::Instance()->
geo();
27 LocationButton->setText(geoPlace->fullName());
29 RABox->setUnits(dmsBox::HOURS);
32 connect(PlanetComboBox, SIGNAL(activated(
int)),
this, SLOT(slotComputePosition()));
33 connect(DateTimeBox, SIGNAL(dateTimeChanged(
QDateTime)),
this, SLOT(slotComputePosition()));
34 connect(LocationButton, SIGNAL(clicked()),
this, SLOT(slotLocation()));
36 connect(UTCheckBatch, SIGNAL(clicked()),
this, SLOT(slotUtCheckedBatch()));
37 connect(DateCheckBatch, SIGNAL(clicked()),
this, SLOT(slotDateCheckedBatch()));
38 connect(LatCheckBatch, SIGNAL(clicked()),
this, SLOT(slotLatCheckedBatch()));
39 connect(LongCheckBatch, SIGNAL(clicked()),
this, SLOT(slotLongCheckedBatch()));
40 connect(PlanetCheckBatch, SIGNAL(clicked()),
this, SLOT(slotPlanetsCheckedBatch()));
42 slotComputePosition();
46void modCalcPlanets::slotLocation()
52 geoPlace = ld->selectedCity();
53 LocationButton->setText(geoPlace->
fullName());
54 slotComputePosition();
59void modCalcPlanets::slotComputePosition()
62 long double julianDay = dt.djd();
68 Earth.findPosition(&num);
71 if (PlanetComboBox->currentIndex() == 2)
73 showCoordinates(Earth);
80 std::unique_ptr<KSPlanetBase> p;
82 switch (PlanetComboBox->currentIndex())
85 p.reset(
new KSPlanet(KSPlanetBase::MERCURY));
88 p.reset(
new KSPlanet(KSPlanetBase::VENUS));
91 p.reset(
new KSPlanet(KSPlanetBase::MARS));
94 p.reset(
new KSPlanet(KSPlanetBase::JUPITER));
97 p.reset(
new KSPlanet(KSPlanetBase::SATURN));
100 p.reset(
new KSPlanet(KSPlanetBase::URANUS));
103 p.reset(
new KSPlanet(KSPlanetBase::NEPTUNE));
111 p.reset(
new KSSun());
115 if (p.get() ==
nullptr)
119 p->findPosition(&num, geoPlace->
lat(), &LST, &Earth);
120 p->EquatorialToHorizontal(&LST, geoPlace->
lat());
124void modCalcPlanets::showCoordinates(
const KSPlanetBase &ksp)
128 showEquatorialCoords(ksp.
ra(), ksp.
dec());
129 showTopocentricCoords(ksp.
az(), ksp.
alt());
132void modCalcPlanets::showHeliocentricEclipticCoords(
const dms &hLong,
const dms &hLat,
double dist)
134 HelioLongBox->show(hLong);
135 HelioLatBox->show(hLat);
139void modCalcPlanets::showGeocentricEclipticCoords(
const dms &eLong,
const dms &eLat,
double dist)
141 GeoLongBox->show(eLong);
142 GeoLatBox->show(eLat);
146void modCalcPlanets::showEquatorialCoords(
const dms &ra,
const dms &dec)
152void modCalcPlanets::showTopocentricCoords(
const dms &az,
const dms &el)
158void modCalcPlanets::slotPlanetsCheckedBatch()
160 PlanetComboBoxBatch->setEnabled(!PlanetCheckBatch->isChecked());
163void modCalcPlanets::slotUtCheckedBatch()
165 UTBoxBatch->setEnabled(!UTCheckBatch->isChecked());
168void modCalcPlanets::slotDateCheckedBatch()
170 DateBoxBatch->setEnabled(!DateCheckBatch->isChecked());
173void modCalcPlanets::slotLongCheckedBatch()
175 LongBoxBatch->setEnabled(!LongCheckBatch->isChecked());
178void modCalcPlanets::slotLatCheckedBatch()
180 LatBoxBatch->setEnabled(!LatCheckBatch->isChecked());
183void modCalcPlanets::slotRunBatch()
185 const QString inputFileName = InputFileBoxBatch->url().toLocalFile();
191 QFile f(inputFileName);
194 QString message =
i18n(
"Could not open file %1.", f.fileName());
195 KSNotification::sorry(message,
i18n(
"Could Not Open File"));
205 QString message =
i18n(
"Invalid file: %1", inputFileName);
206 KSNotification::sorry(message,
i18n(
"Invalid file"));
207 InputFileBoxBatch->setUrl(
QUrl());
211unsigned int modCalcPlanets::requiredBatchFields()
215 if (PlanetCheckBatch->isChecked())
217 if (UTCheckBatch->isChecked())
219 if (DateCheckBatch->isChecked())
221 if (LongCheckBatch->isChecked())
223 if (LatCheckBatch->isChecked())
233 const QString outputFileName = OutputFileBoxBatch->url().toLocalFile();
234 QFile fOut(outputFileName);
237 bool lineIsValid =
true;
241 unsigned int i = 0, nline = 0;
244 CachingDms longB, latB, hlongB, hlatB, glongB, glatB, raB, decB, azmB, altB;
245 double rSunB(0.0), rEarthB(0.0);
260 pNamesi18n <<
i18n(
"Mercury") <<
i18n(
"Venus") <<
i18n(
"Earth") <<
i18n(
"Mars") <<
i18n(
"Jupiter") <<
i18n(
"Saturn")
261 <<
i18n(
"Uranus") <<
i18n(
"Neptune")
265 int numberOfRequiredFields = requiredBatchFields();
266 while (!istream.
atEnd())
276 if (fields.count() != numberOfRequiredFields)
279 qWarning() <<
i18n(
"Incorrect number of fields in line %1: ", nline)
280 <<
i18n(
"Present fields %1. ", fields.count())
281 <<
i18n(
"Required fields %1. ", numberOfRequiredFields);
287 if (PlanetCheckBatch->isChecked())
290 int j = pNamesi18n.
indexOf(planetB);
293 qWarning() <<
i18n(
"Unknown planet ") << fields[i] <<
i18n(
" in line %1: ", nline);
301 planetB = PlanetComboBoxBatch->currentText();
303 if (AllRadioBatch->isChecked() || PlanetCheckBatch->isChecked())
305 lineToWrite = planetB;
306 lineToWrite += space;
310 if (UTCheckBatch->isChecked())
315 qWarning() <<
i18n(
"Line %1 contains an invalid time", nline);
324 utB = UTBoxBatch->time();
326 if (AllRadioBatch->isChecked() || UTCheckBatch->isChecked())
330 if (DateCheckBatch->isChecked())
335 qWarning() <<
i18n(
"Line %1 contains an invalid date: ", nline) << fields[i];
344 dtB = DateBoxBatch->date();
346 if (AllRadioBatch->isChecked() || DateCheckBatch->isChecked())
351 if (LongCheckBatch->isChecked())
358 longB = LongBoxBatch->createDms();
360 if (AllRadioBatch->isChecked() || LongCheckBatch->isChecked())
364 if (LatCheckBatch->isChecked())
371 latB = LatBoxBatch->createDms();
373 if (AllRadioBatch->isChecked() || LatCheckBatch->isChecked())
388 if (pn ==
i18n(
"Sun"))
392 else if (pn ==
i18n(
"Moon"))
406 rSunB = kspb->
rsun();
409 glatB = kspb->
ecLat();
418 ostream << lineToWrite;
420 if (HelioEclCheckBatch->isChecked())
422 if (GeoEclCheckBatch->isChecked())
424 if (EquatorialCheckBatch->isChecked())
426 if (HorizontalCheckBatch->isChecked())
438 QString message =
i18n(
"Errors found while parsing some lines in the input file");
439 KSNotification::sorry(message,
i18n(
"Errors in lines"));
a dms subclass that caches its sine and cosine values every time the angle is changed.
static CachingDms fromString(const QString &s, bool deg)
Construct an angle from the given string.
const CachingDms * lat() const
Provides necessary information about the Moon.
There are several time-dependent values used in position calculations, that are not specific to an ob...
A subclass of TrailObject that provides additional information needed for most solar system objects.
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
const dms & ecLat() const
const dms & ecLong() const
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Child class of KSPlanetBase; encapsulates information about the Sun.
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
static KStarsDateTime currentDateTime()
Dialog for changing the geographic location of the observer.
const CachingDms & dec() const
const CachingDms & ra() const
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
An angle, stored as degrees, but expressible in many ways.
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
const QString toHMSString(const bool machineReadable=false, const bool highPrecision=false) const
void processLines(QTextStream &istream)
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
QDate fromString(QStringView string, QStringView format, QCalendar cal)
bool isValid(int year, int month, int day)
bool exists() const const
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
virtual void close() override
const_reference at(qsizetype i) const const
QString toString(QDate date, FormatType format) const const
QString & append(QChar ch)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QByteArray toLocal8Bit() const const
QString trimmed() const const
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
QString readLine(qint64 maxlen)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QTime fromString(QStringView string, QStringView format)
bool isValid(int h, int m, int s, int ms)