Skip to content

Commit f1abc08

Browse files
committed
AstroCalc/Almanac: added ability to compute time when Sun and Moon at custom altitude (fix #4467)
Note: twilight finder use for computation sunrise/sunset time in InfoBox and for shortcuts Visual fixes Fix indentation Fix indentation Update AstroCalcAlmanacWidget.hpp Update AstroCalcAlmanacWidget.cpp
1 parent 0cb193d commit f1abc08

File tree

3 files changed

+442
-150
lines changed

3 files changed

+442
-150
lines changed

src/gui/AstroCalcAlmanacWidget.cpp

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,32 @@
2828

2929
#include <QPushButton>
3030
#include <QToolTip>
31-
#include <QSettings>
3231

3332
AstroCalcAlmanacWidget::AstroCalcAlmanacWidget(QWidget* parent)
34-
: QWidget(parent)
35-
, core(nullptr)
36-
, specMgr(nullptr)
37-
, localeMgr(nullptr)
38-
, sunriseJD(0.)
39-
, sunsetJD(0.)
40-
, moonriseJD(0.)
41-
, moonsetJD(0.)
42-
, civilDawnJD(0.)
43-
, civilDuskJD(0.)
44-
, nauticalDawnJD(0.)
45-
, nauticalDuskJD(0.)
46-
, astronomicalDawnJD(0.)
47-
, astronomicalDuskJD(0.)
33+
: QWidget(parent)
34+
, core(nullptr)
35+
, specMgr(nullptr)
36+
, localeMgr(nullptr)
37+
, sunriseJD(0.)
38+
, sunsetJD(0.)
39+
, moonriseJD(0.)
40+
, moonsetJD(0.)
41+
, civilDawnJD(0.)
42+
, civilDuskJD(0.)
43+
, nauticalDawnJD(0.)
44+
, nauticalDuskJD(0.)
45+
, astronomicalDawnJD(0.)
46+
, astronomicalDuskJD(0.)
4847
, beforeSunriseJD(0.)
4948
, afterSunsetJD(0.)
5049
, minutesJD(0.)
51-
, ui(new Ui_astroCalcAlmanacWidget)
50+
, customSunriseJD(0.)
51+
, customSunsetJD(0.)
52+
, customSunAltitude(-7.) // obvious defaults
53+
, customMoonriseJD(0.)
54+
, customMoonsetJD(0.)
55+
, customMoonAltitude(18.) // obvious defaults
56+
, ui(new Ui_astroCalcAlmanacWidget)
5257
{
5358
}
5459

@@ -67,6 +72,14 @@ void AstroCalcAlmanacWidget::setup()
6772
ui->spinBoxMinutes->setValue(customMinutes);
6873
connect(ui->spinBoxMinutes, SIGNAL(valueChanged(int)), this, SLOT(saveMinutes(int)));
6974

75+
customSunAltitude = conf->value("astro/custom_sun_altitude", -7.0).toDouble();
76+
ui->spinBoxCustomSunAltitude->setValue(customSunAltitude);
77+
connect(ui->spinBoxCustomSunAltitude, SIGNAL(valueChanged(double)), this, SLOT(saveCustomSunAltitue(double)));
78+
79+
customMoonAltitude = conf->value("astro/custom_moon_altitude", 18.0).toDouble();
80+
ui->spinBoxCustomMoonAltitude->setValue(customMoonAltitude);
81+
connect(ui->spinBoxCustomMoonAltitude, SIGNAL(valueChanged(double)), this, SLOT(saveCustomMoonAltitue(double)));
82+
7083
populateData();
7184

7285
connect(core, &StelCore::locationChanged, this, [=](const StelLocation&){ populateData(); });
@@ -107,6 +120,10 @@ void AstroCalcAlmanacWidget::setup()
107120
connect(ui->buttonSunset, &QPushButton::clicked, this, [=](){core->setJD(sunsetJD);});
108121
connect(ui->buttonBeforeSunrise, &QPushButton::clicked, this, [=](){core->setJD(beforeSunriseJD);});
109122
connect(ui->buttonAfterSunset, &QPushButton::clicked, this, [=](){core->setJD(afterSunsetJD);});
123+
connect(ui->buttonCustomSunrise, &QPushButton::clicked, this, [=](){core->setJD(customSunriseJD);});
124+
connect(ui->buttonCustomSunset, &QPushButton::clicked, this, [=](){core->setJD(customSunsetJD);});
125+
connect(ui->buttonCustomMoonrise, &QPushButton::clicked, this, [=](){core->setJD(customMoonriseJD);});
126+
connect(ui->buttonCustomMoonset, &QPushButton::clicked, this, [=](){core->setJD(customMoonsetJD);});
110127
connect(ui->buttonMoonrise, &QPushButton::clicked, this, [=](){core->setJD(moonriseJD);});
111128
connect(ui->buttonMoonset, &QPushButton::clicked, this, [=](){core->setJD(moonsetJD);});
112129
connect(ui->buttonCivilDawn, &QPushButton::clicked, this, [=](){core->setJD(civilDawnJD);});
@@ -143,6 +160,10 @@ void AstroCalcAlmanacWidget::setup()
143160
ui->buttonTomorrow->setFixedSize(button);
144161
ui->buttonBeforeSunrise->setFixedSize(button);
145162
ui->buttonAfterSunset->setFixedSize(button);
163+
ui->buttonCustomSunrise->setFixedSize(button);
164+
ui->buttonCustomSunset->setFixedSize(button);
165+
ui->buttonCustomMoonrise->setFixedSize(button);
166+
ui->buttonCustomMoonset->setFixedSize(button);
146167
}
147168

148169
void AstroCalcAlmanacWidget::retranslate()
@@ -158,6 +179,20 @@ void AstroCalcAlmanacWidget::saveMinutes(int minutes)
158179
setTodayTimes();
159180
}
160181

182+
void AstroCalcAlmanacWidget::saveCustomSunAltitue(double altitude)
183+
{
184+
customSunAltitude = altitude;
185+
conf->setValue("astro/custom_sun_altitude", altitude);
186+
setTodayTimes();
187+
}
188+
189+
void AstroCalcAlmanacWidget::saveCustomMoonAltitue(double altitude)
190+
{
191+
customMoonAltitude = altitude;
192+
conf->setValue("astro/custom_moon_altitude", altitude);
193+
setTodayTimes();
194+
}
195+
161196
void AstroCalcAlmanacWidget::populateData()
162197
{
163198
// Set season labels
@@ -216,7 +251,7 @@ void AstroCalcAlmanacWidget::setSeasonTimes()
216251
const double septemberEquinox = specMgr->getEquinox(year, SpecificTimeMgr::Equinox::September);
217252
const double juneSolstice = specMgr->getSolstice(year, SpecificTimeMgr::Solstice::June);
218253
const double decemberSolstice = specMgr->getSolstice(year, SpecificTimeMgr::Solstice::December);
219-
QString days = qc_("days", "duration");
254+
QString days = qc_("days", "duration");
220255
int jdDepth = 5;
221256
int daysDepth = 2;
222257

@@ -252,11 +287,11 @@ void AstroCalcAlmanacWidget::setTodayTimes()
252287
const double utcShift = utcOffsetHrs / 24.; // Fix DST shift...
253288
PlanetP sun = GETSTELMODULE(SolarSystem)->getSun();
254289
double duration, duration1, duration2;
255-
bool astronomicalTwilightBtn, nauticalTwilightBtn, civilTwilightBtn, sunBtn;
290+
bool astronomicalTwilightBtn, nauticalTwilightBtn, civilTwilightBtn, sunBtn, cstSunBtn;
256291
QString moonrise, moonset, sunrise, sunset, civilTwilightBegin, civilTwilightEnd, nauticalTwilightBegin,
257-
nauticalTwilightEnd, astronomicalTwilightBegin, astronomicalTwilightEnd, dayDuration, nightDuration,
258-
civilTwilightDuration, nauticalTwilightDuration, astronomicalTwilightDuration, beforeSunrise,
259-
afterSunset, dash = QChar(0x2014);
292+
nauticalTwilightEnd, astronomicalTwilightBegin, astronomicalTwilightEnd, dayDuration, nightDuration,
293+
civilTwilightDuration, nauticalTwilightDuration, astronomicalTwilightDuration, beforeSunrise,
294+
afterSunset, customSunrise, customSunset, customMoonrise, customMoonset, dash = QChar(0x2014);
260295

261296
// Moon
262297
Vec4d moon = GETSTELMODULE(SolarSystem)->getMoon()->getRTSTime(core, 0.);
@@ -308,6 +343,48 @@ void AstroCalcAlmanacWidget::setTodayTimes()
308343
}
309344
dayDuration = StelUtils::hoursToHmsStr(duration, true);
310345

346+
// Sun at custom altitude
347+
Vec4d cday = sun->getRTSTime(core, customSunAltitude);
348+
if (cday[3]==0.)
349+
{
350+
customSunriseJD = cday[0];
351+
customSunsetJD = cday[2];
352+
customSunrise = StelUtils::hoursToHmsStr(StelUtils::getHoursFromJulianDay(customSunriseJD+utcShift), true);
353+
customSunset = StelUtils::hoursToHmsStr(StelUtils::getHoursFromJulianDay(customSunsetJD+utcShift), true);
354+
cstSunBtn = true;
355+
}
356+
else
357+
{
358+
customSunrise = customSunset = dash;
359+
cstSunBtn = false;
360+
}
361+
362+
// Moon at custom altitude
363+
Vec4d cmoon = GETSTELMODULE(SolarSystem)->getMoon()->getRTSTime(core, customMoonAltitude);
364+
if (cmoon[3]==30 || cmoon[3]<0 || cmoon[3]>50) // no moonrise on current date
365+
{
366+
customMoonrise = dash;
367+
ui->buttonCustomMoonrise->setEnabled(false);
368+
}
369+
else
370+
{
371+
customMoonriseJD = cmoon[0];
372+
customMoonrise = StelUtils::hoursToHmsStr(StelUtils::getHoursFromJulianDay(customMoonriseJD+utcShift), true);
373+
ui->buttonCustomMoonrise->setEnabled(true);
374+
}
375+
376+
if (cmoon[3]==40 || cmoon[3]<0 || cmoon[3]>50) // no moonset on current date
377+
{
378+
customMoonset = dash;
379+
ui->buttonCustomMoonset->setEnabled(false);
380+
}
381+
else
382+
{
383+
customMoonsetJD = cmoon[2];
384+
customMoonset = StelUtils::hoursToHmsStr(StelUtils::getHoursFromJulianDay(customMoonsetJD+utcShift), true);
385+
ui->buttonCustomMoonset->setEnabled(true);
386+
}
387+
311388
// twilights
312389
Vec4d civilTwilight = sun->getRTSTime(core, -6.);
313390
Vec4d nauticalTwilight = sun->getRTSTime(core, -12.);
@@ -328,6 +405,8 @@ void AstroCalcAlmanacWidget::setTodayTimes()
328405
// TRANSLATORS: duration in minutes
329406
QString minutes = qc_("m", "duration, suffix");
330407
ui->spinBoxMinutes->setSuffix(minutes);
408+
ui->spinBoxCustomSunAltitude->setSuffix("°");
409+
ui->spinBoxCustomMoonAltitude->setSuffix("°");
331410

332411
if (astronomicalTwilight[3]==0.)
333412
{
@@ -355,7 +434,7 @@ void AstroCalcAlmanacWidget::setTodayTimes()
355434
if (day[3]<-99.)
356435
nightDuration = StelUtils::hoursToHmsStr(24., true);
357436
else
358-
nightDuration = StelUtils::hoursToHmsStr(duration, true);
437+
nightDuration = StelUtils::hoursToHmsStr(duration, true);
359438
astronomicalTwilightBtn = false;
360439
}
361440
astronomicalTwilightDuration = StelUtils::hoursToHmsStr(duration, true);
@@ -427,6 +506,10 @@ void AstroCalcAlmanacWidget::setTodayTimes()
427506
ui->labelAfterSunset->setText(afterSunset);
428507
ui->labelMoonRise->setText(moonrise);
429508
ui->labelMoonSet->setText(moonset);
509+
ui->labelCustomSunrise->setText(customSunrise);
510+
ui->labelCustomSunset->setText(customSunset);
511+
ui->labelCustomMoonrise->setText(customMoonrise);
512+
ui->labelCustomMoonset->setText(customMoonset);
430513

431514
// buttons
432515
ui->buttonSunrise->setEnabled(sunBtn);
@@ -439,6 +522,8 @@ void AstroCalcAlmanacWidget::setTodayTimes()
439522
ui->buttonNauticalDusk->setEnabled(nauticalTwilightBtn);
440523
ui->buttonCivilDawn->setEnabled(civilTwilightBtn);
441524
ui->buttonCivilDusk->setEnabled(civilTwilightBtn);
525+
ui->buttonCustomSunrise->setEnabled(cstSunBtn);
526+
ui->buttonCustomSunset->setEnabled(cstSunBtn);
442527

443528
// spinboxes
444529
ui->spinBoxMinutes->setEnabled(sunBtn);

src/gui/AstroCalcAlmanacWidget.hpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,39 @@
2222

2323
#include <memory>
2424
#include <QWidget>
25-
#include "StelDialog.hpp"
25+
#include <QSettings>
2626
#include "ui_astroCalcAlmanacWidget.h"
2727

2828
class AstroCalcAlmanacWidget : public QWidget
2929
{
30-
Q_OBJECT
30+
Q_OBJECT
3131
public:
32-
AstroCalcAlmanacWidget(QWidget* parent = nullptr);
33-
void setup();
34-
void retranslate();
32+
AstroCalcAlmanacWidget(QWidget* parent = nullptr);
33+
void setup();
34+
void retranslate();
3535

3636
private slots:
37-
void setSeasonLabels();
38-
void setSeasonTimes();
39-
void setTodayTimes();
40-
void saveMinutes(int minutes);
37+
void setSeasonLabels();
38+
void setSeasonTimes();
39+
void setTodayTimes();
40+
void saveMinutes(int minutes);
41+
void saveCustomSunAltitue(double altitude);
42+
void saveCustomMoonAltitue(double altitude);
4143

4244
private:
43-
class StelCore* core;
44-
class SpecificTimeMgr* specMgr;
45-
class StelLocaleMgr* localeMgr;
46-
QSettings* conf;
45+
class StelCore* core;
46+
class SpecificTimeMgr* specMgr;
47+
class StelLocaleMgr* localeMgr;
48+
QSettings* conf;
4749

48-
double sunriseJD, sunsetJD, moonriseJD, moonsetJD, civilDawnJD, civilDuskJD, nauticalDawnJD, nauticalDuskJD, astronomicalDawnJD, astronomicalDuskJD, beforeSunriseJD, afterSunsetJD, minutesJD;
50+
double sunriseJD, sunsetJD, moonriseJD, moonsetJD, civilDawnJD, civilDuskJD, nauticalDawnJD, nauticalDuskJD, astronomicalDawnJD, astronomicalDuskJD,
51+
beforeSunriseJD, afterSunsetJD, minutesJD, customSunriseJD, customSunsetJD, customSunAltitude, customMoonriseJD, customMoonsetJD, customMoonAltitude;
4952

50-
void populateData();
51-
// method to get a formatted string for date and time of equinox/solstice
52-
QString getFormattedDateTime(const double JD, const double utcShift);
53+
void populateData();
54+
// method to get a formatted string for date and time of equinox/solstice
55+
QString getFormattedDateTime(const double JD, const double utcShift);
5356

54-
std::unique_ptr<Ui_astroCalcAlmanacWidget> ui;
57+
std::unique_ptr<Ui_astroCalcAlmanacWidget> ui;
5558
};
5659

5760
#endif

0 commit comments

Comments
 (0)