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)
55 geoPlace = data->
geo();
56 geoBatch = data->
geo();
58 LocationBatch->setText(geoBatch->
fullName());
61QTime modCalcDayLength::lengthOfDay(
const QTime &setQTime,
const QTime &riseQTime)
64 int dds = riseQTime.
secsTo(setQTime);
70void modCalcDayLength::slotLocation()
87void modCalcDayLength::slotLocationBatch()
96 LocationBatch->setText(geoBatch->
fullName());
131 QTime daylength = lengthOfDay(ssTime, srTime);
139 ssAzString =
i18n(
"Circumpolar");
141 srAzString =
i18n(
"Circumpolar");
143 ssTimeString =
"--:--";
144 srTimeString =
"--:--";
146 daylengthString =
"24:00";
150 ssAzString =
i18n(
"Does not rise");
152 srAzString =
i18n(
"Does not set");
154 ssTimeString =
"--:--";
155 srTimeString =
"--:--";
157 daylengthString =
"00:00";
186 msAzString =
i18n(
"Circumpolar");
188 mrAzString =
i18n(
"Circumpolar");
190 msTimeString =
"--:--";
191 mrTimeString =
"--:--";
196 msAzString =
i18n(
"Does not rise");
198 mrAzString =
i18n(
"Does not rise");
200 msTimeString =
"--:--";
201 mrTimeString =
"--:--";
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"));
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());
283 ostream <<
"# " <<
i18nc(
"%1 is a location on earth",
"Almanac for %1", geoBatch->
fullName())
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());
345 while (!istream.
atEnd())
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
const CachingDms * lat() const
const CachingDms * lng() const
Provides necessary information about the Moon.
QString phaseName() const
void findPhase(const KSSun *Sun=nullptr)
Determine the phase angle of the moon, and assign the appropriate moon image.
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.
Child class of KSPlanetBase; encapsulates information about the Sun.
KStarsData is the backbone of KStars.
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.
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.
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 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 toString(QDate date, FormatType format) const const
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)
QTime addSecs(int s) const const
bool isValid(int h, int m, int s, int ms)
int secsTo(QTime t) const const