7#include "modcalcdaylength.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"
15#include "skyobjects/skyobject.h"
18#include <KLocalizedString>
23modCalcDayLength::modCalcDayLength(
QWidget *parentSplit) :
QFrame(parentSplit)
31 connect(Date, SIGNAL(dateChanged(
QDate)),
this, SLOT(slotComputeAlmanac()));
32 connect(Location, SIGNAL(clicked()),
this, SLOT(slotLocation()));
34 connect(LocationBatch, SIGNAL(clicked()),
this, SLOT(slotLocationBatch()));
35 connect(InputFileBatch, SIGNAL(urlSelected(
QUrl)),
this, SLOT(slotCheckFiles()));
36 connect(OutputFileBatch, SIGNAL(urlSelected(
QUrl)),
this, SLOT(slotCheckFiles()));
37 connect(RunButtonBatch, SIGNAL(clicked()),
this, SLOT(slotRunBatch()));
38 connect(ViewButtonBatch, SIGNAL(clicked()),
this, SLOT(slotViewBatch()));
40 RunButtonBatch->setEnabled(
false);
41 ViewButtonBatch->setEnabled(
false);
46void modCalcDayLength::showCurrentDate(
void)
49 Date->setDate(dt.date());
52void modCalcDayLength::initGeo(
void)
54 KStarsData *data = KStarsData::Instance();
55 geoPlace = data->
geo();
56 geoBatch = data->
geo();
57 Location->setText(geoPlace->fullName());
58 LocationBatch->setText(geoBatch->fullName());
61QTime modCalcDayLength::lengthOfDay(
const QTime &setQTime,
const QTime &riseQTime)
64 int dds = riseQTime.
secsTo(setQTime);
65 QTime dLength = dL.addSecs(dds);
70void modCalcDayLength::slotLocation()
72 QPointer<LocationDialog> ld =
new LocationDialog(
this);
75 GeoLocation *newGeo = ld->selectedCity();
79 Location->setText(geoPlace->fullName());
87void modCalcDayLength::slotLocationBatch()
89 QPointer<LocationDialog> ld =
new LocationDialog(
this);
92 GeoLocation *newGeo = ld->selectedCity();
96 LocationBatch->setText(geoBatch->fullName());
105 long double jd0 = KStarsDateTime(d, QTime(8, 0, 0)).djd();
112 QTime ssTime = Sun.
riseSetTime(KStarsDateTime(jd0), geo,
false);
113 QTime srTime = Sun.
riseSetTime(KStarsDateTime(jd0), geo,
true);
114 QTime stTime = Sun.
transitTime(KStarsDateTime(jd0), geo);
116 dms ssAz = Sun.
riseSetTimeAz(KStarsDateTime(jd0), geo,
false);
117 dms srAz = Sun.
riseSetTimeAz(KStarsDateTime(jd0), geo,
true);
127 ssTimeString = QLocale().toString(ssTime,
"hh:mm:ss");
128 srTimeString = QLocale().toString(srTime,
"hh:mm:ss");
129 stTimeString = QLocale().toString(stTime,
"hh:mm:ss");
131 QTime daylength = lengthOfDay(ssTime, srTime);
133 daylengthString = QLocale().toString(daylength,
"hh:mm:ss");
139 ssAzString =
i18n(
"Circumpolar");
141 srAzString =
i18n(
"Circumpolar");
143 ssTimeString =
"--:--";
144 srTimeString =
"--:--";
145 stTimeString = QLocale().toString(stTime,
"hh:mm:ss");
146 daylengthString =
"24:00";
150 ssAzString =
i18n(
"Does not rise");
152 srAzString =
i18n(
"Does not set");
154 ssTimeString =
"--:--";
155 srTimeString =
"--:--";
156 stTimeString = QLocale().toString(stTime,
"hh:mm:ss");
157 daylengthString =
"00:00";
163 QTime msTime = Moon.
riseSetTime(KStarsDateTime(jd0), geo,
false);
164 QTime mrTime = Moon.
riseSetTime(KStarsDateTime(jd0), geo,
true);
165 QTime mtTime = Moon.
transitTime(KStarsDateTime(jd0), geo);
167 dms msAz = Moon.
riseSetTimeAz(KStarsDateTime(jd0), geo,
false);
168 dms mrAz = Moon.
riseSetTimeAz(KStarsDateTime(jd0), geo,
true);
178 msTimeString = QLocale().toString(msTime,
"hh:mm:ss");
179 mrTimeString = QLocale().toString(mrTime,
"hh:mm:ss");
180 mtTimeString = QLocale().toString(mtTime,
"hh:mm:ss");
186 msAzString =
i18n(
"Circumpolar");
188 mrAzString =
i18n(
"Circumpolar");
190 msTimeString =
"--:--";
191 mrTimeString =
"--:--";
192 mtTimeString = QLocale().toString(mtTime,
"hh:mm:ss");
196 msAzString =
i18n(
"Does not rise");
198 mrAzString =
i18n(
"Does not rise");
200 msTimeString =
"--:--";
201 mrTimeString =
"--:--";
202 mtTimeString = QLocale().toString(mtTime,
"hh:mm:ss");
212 srAzString =
' ' + srAzString;
214 ssAzString =
' ' + ssAzString;
216 mrAzString =
' ' + mrAzString;
218 msAzString =
' ' + msAzString;
221void modCalcDayLength::slotComputeAlmanac()
223 updateAlmanac(Date->date(), geoPlace);
225 SunSet->setText(ssTimeString);
226 SunRise->setText(srTimeString);
227 SunTransit->setText(stTimeString);
228 SunSetAz->setText(ssAzString);
229 SunRiseAz->setText(srAzString);
230 SunTransitAlt->setText(stAltString);
231 DayLength->setText(daylengthString);
233 MoonSet->setText(msTimeString);
234 MoonRise->setText(mrTimeString);
235 MoonTransit->setText(mtTimeString);
236 MoonSetAz->setText(msAzString);
237 MoonRiseAz->setText(mrAzString);
238 MoonTransitAlt->setText(mtAltString);
239 LunarPhase->setText(lunarphaseString);
242void modCalcDayLength::slotCheckFiles()
244 bool flag = !InputFileBatch->lineEdit()->text().isEmpty() && !OutputFileBatch->lineEdit()->text().isEmpty();
245 RunButtonBatch->setEnabled(flag);
248void modCalcDayLength::slotRunBatch()
250 QString inputFileName = InputFileBatch->url().toLocalFile();
254 QFile f(inputFileName);
257 QString message =
i18n(
"Could not open file %1.", f.fileName());
258 KSNotification::sorry(message,
i18n(
"Could Not Open File"));
262 QTextStream istream(&f);
263 processLines(istream);
264 ViewButtonBatch->setEnabled(
true);
270 QString message =
i18n(
"Invalid file: %1", inputFileName);
271 KSNotification::sorry(message,
i18n(
"Invalid file"));
276void modCalcDayLength::processLines(
QTextStream &istream)
278 QFile fOut(OutputFileBatch->url().toLocalFile());
280 QTextStream ostream(&fOut);
283 ostream <<
"# " <<
i18nc(
"%1 is a location on earth",
"Almanac for %1", geoBatch->fullName())
284 << QString(
" [%1, %2]").
arg(geoBatch->lng()->toDMSString(), geoBatch->lat()->toDMSString())
286 <<
"# " <<
"SRise: Sun Rise" <<
Qt::endl
287 <<
"# " <<
"STran: Sun Transit" <<
Qt::endl
288 <<
"# " <<
"SSet: Sun Set" <<
Qt::endl
289 <<
"# " <<
"SRiseAz: Azimuth of Sun Rise" <<
Qt::endl
290 <<
"# " <<
"STranAlt: Altitude of Sun Transit" <<
Qt::endl
291 <<
"# " <<
"SSetAz: Azimuth of Sun Set" <<
Qt::endl
292 <<
"# " <<
"STranAlt: Altitude of Sun Transit" <<
Qt::endl
293 <<
"# " <<
"DayLen: Day Duration in hours" <<
Qt::endl
294 <<
"# " <<
"MRise: Moon Rise" <<
Qt::endl
295 <<
"# " <<
"MTran: Moon Transit" <<
Qt::endl
296 <<
"# " <<
"MSet: Moon Set" <<
Qt::endl
297 <<
"# " <<
"MRiseAz: Azimuth of Moon Rise" <<
Qt::endl
298 <<
"# " <<
"MTranAkt: Altitude of Moon Transit" <<
Qt::endl
299 <<
"# " <<
"MSetAz: Azimuth of Moon Set" <<
Qt::endl
300 <<
"# " <<
"LunarPhase: Lunar Phase and Illumination Percentage" <<
Qt::endl
302 <<
"# Date,SRise,STran,SSet,SRiseAz,STranAlt,SSetAz,DayLen,MRise,MTran,MSet,"
303 <<
"MRiseAz,MTranAlt,MSetAz,LunarPhase" <<
Qt::endl
309 while (!istream.
atEnd())
318 updateAlmanac(d, geoBatch);
320 srTimeString <<
"," <<
321 stTimeString <<
"," <<
322 ssTimeString <<
"," <<
324 stAltString <<
"," <<
326 daylengthString <<
"," <<
327 mrTimeString <<
"," <<
328 mtTimeString <<
"," <<
329 msTimeString <<
"," <<
331 mtAltString <<
"," <<
338void modCalcDayLength::slotViewBatch()
340 QFile fOut(OutputFileBatch->url().toLocalFile());
342 QTextStream istream(&fOut);
345 while (!istream.
atEnd())
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
QString phaseName() const
void findPhase(const KSSun *Sun=nullptr)
Determine the phase angle of the moon, and assign the appropriate moon image.
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.
static KStarsDateTime currentDateTime()
dms riseSetTimeAz(const KStarsDateTime &dt, const GeoLocation *geo, bool rst) const
dms transitAltitude(const KStarsDateTime &dt, const GeoLocation *geo) const
QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo) const
The same iteration technique described in riseSetTime() is used here.
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true) const
Determine the time at which the point will rise or set.
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
const double & Degrees() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void informationList(QWidget *parent, const QString &text, const QStringList &strlist, const QString &title=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
QDate fromString(QStringView string, QStringView format, QCalendar cal)
bool exists() const const
void append(QList< T > &&value)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
QString trimmed() const const
QTextStream & endl(QTextStream &stream)
QString readLine(qint64 maxlen)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isValid(int h, int m, int s, int ms)
int secsTo(QTime t) const const