7#include "scheduleraltitudegraph.h"
8#include "ui_scheduleraltitudegraph.h"
9#include "kplotwidget.h"
10#include "kplotobject.h"
13#include "schedulerjob.h"
14#include "schedulerutils.h"
17#include "schedulermodulestate.h"
23SchedulerAltitudeGraph::SchedulerAltitudeGraph(QWidget * parent) : QFrame(parent)
36void SchedulerAltitudeGraph::tickle()
38 if (m_State->jobs().isEmpty() ||
39 !m_AltitudeGraphUpdateTime.isValid() ||
40 m_AltitudeGraphUpdateTime.secsTo(SchedulerModuleState::getLocalTime()) > 120)
47void SchedulerAltitudeGraph::next()
50 if (m_AltGraphDay > 2)
54void SchedulerAltitudeGraph::prev()
57 if (m_AltGraphDay < 0)
62void SchedulerAltitudeGraph::setup()
65 altMoveLeftB->setStyleSheet(
"background-color: black;");
66 altMoveRightB->setStyleSheet(
"background-color: black;");
67 altMoveLeftB->setIcon(
QIcon());
68 altMoveRightB->setIcon(
QIcon());
69 altMoveLeftB->setEnabled(
false);
70 altMoveRightB->setEnabled(
false);
71 altMoveLeftB->setFixedWidth(16);
72 altMoveRightB->setFixedWidth(16);
73 altMoveLeftB->setFixedHeight(16);
74 altMoveRightB->setFixedHeight(16);
76 altGraph->setAltitudeAxis(-20.0, 90.0);
77 altGraph->setTopPadding(0);
78 altGraph->setBottomPadding(25);
79 altGraph->setLeftPadding(25);
80 altGraph->setRightPadding(10);
87void SchedulerAltitudeGraph::handleButtons(
bool disable)
93 altMoveLeftB->setEnabled(
false);
94 altMoveLeftB->setIcon(
QIcon());
95 altMoveRightB->setEnabled(
false);
96 altMoveRightB->setIcon(
QIcon());
98 else if (m_AltGraphDay == 1)
100 altMoveLeftB->setEnabled(
true);
101 altMoveRightB->setEnabled(
true);
105 else if (m_AltGraphDay == 2)
107 altMoveLeftB->setEnabled(
true);
109 altMoveRightB->setEnabled(
false);
110 altMoveRightB->setIcon(
QIcon());
115 altMoveLeftB->setEnabled(
false);
116 altMoveLeftB->setIcon(
QIcon());
117 altMoveRightB->setEnabled(
true);
128 for (
int index = 0; index < jobs.
size(); index++)
130 const auto job = jobs.
at(index);
131 for (
const auto &jobSchedule : job->getSimulatedSchedule())
133 const auto startTime = jobSchedule.startTime;
134 const auto stopTime = jobSchedule.stopTime;
135 if (!startTime.isValid())
138 if (startTime >= now && startTime < normalStart)
140 if (!newStartTime.
isValid() || newStartTime > startTime)
141 newStartTime = startTime.
addSecs(-1800);
143 else if (startTime < now && (!stopTime.isValid() || (stopTime > now)))
145 if (!newStartTime.
isValid() || newStartTime > now)
146 newStartTime = now.
addSecs(-1800);
151 return static_cast<int>(0.99 + newStartTime.
secsTo(normalStart) / 3600.0);
156void SchedulerAltitudeGraph::plot()
158 if (m_State->jobs().size() == 0)
160 altGraph->removeAllPlotObjects();
163 altGraphLabel->setText(
"");
167 m_AltitudeGraphUpdateTime = SchedulerModuleState::getLocalTime();
168 const QDateTime now = SchedulerModuleState::getLocalTime().
addDays(m_AltGraphDay), start,
end;
170 SchedulerModuleState::calculateDawnDusk(now, nextDawn, nextDusk);
171 QDateTime plotStart = (nextDusk < nextDawn) ? nextDusk : nextDusk.addDays(-1);
181 else if (now < nextDusk.
addSecs(-startOffset * 3600))
185 startOffset += additionalOffset(m_State->jobs(), now,
186 plotStart.
addSecs(-startOffset * 3600));
189 plotStart = plotStart.
addSecs(-startOffset * 3600);
190 auto plotEnd = nextDawn.
addSecs(startOffset * 3600);
192 const QString dayName = m_AltGraphDay == 1 ?
i18n(
"Tomorrow") : (m_AltGraphDay == 2 ?
i18n(
"Day After Tomorrow") :
198 altGraphLabel->setText(plotTitle);
201 KSAlmanac ksal(ut, SchedulerModuleState::getGeo());
203 handleButtons(
false);
205 const int currentPosition = m_State->currentPosition();
207 for (
int index = 0; index < m_State->jobs().size(); index++)
211 auto job = m_State->jobs().
at(index);
212 while (t.secsTo(plotEnd) > 0)
214 double alt = SchedulerUtils::findAltitude(job->getTargetCoords(), t);
216 double hour = midnight.
secsTo(t) / 3600.0;
218 t = t.addSecs(60 * 10);
221 const int lineWidth = (index == currentPosition) ? 2 : 1;
223 altGraph->plot(SchedulerModuleState::getGeo(), &ksal, times, alts, lineWidth,
Qt::white, job->getName());
225 altGraph->plotOverlay(times, alts, lineWidth,
Qt::white, job->getName());
228 altGraph->setCurrentLine(currentPosition);
235 for (
int index = 0; index < m_State->jobs().size(); index++)
237 auto job = m_State->jobs().at(index);
238 for (
const auto &jobSchedule : job->getSimulatedSchedule())
240 auto startTime = jobSchedule.startTime;
241 auto stopTime = jobSchedule.stopTime;
242 if (!startTime.isValid())
244 if (startTime < plotStart)
245 startTime = plotStart;
246 if (!stopTime.isValid() || stopTime > plotEnd)
248 if (startTime.isValid() && startTime < plotEnd && stopTime.isValid() && stopTime > plotStart)
252 while (t.secsTo(stopTime) >= 0)
254 double alt = SchedulerUtils::findAltitude(job->getTargetCoords(), t);
256 double hour = midnight.
secsTo(t) / 3600.0;
258 int secsToStop = t.secsTo(stopTime);
259 if (secsToStop <= 0)
break;
260 t = t.addSecs(std::min(60 * 1, secsToStop));
263 altGraph->plotOverlay(runTimes, runAlts, 4,
Qt::green);
A class that implements methods to find sun rise, sun set, twilight begin / end times,...
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
KStarsDateTime addSecs(double s) const
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
const QList< QKeySequence > & end()
QDate addDays(qint64 ndays) const const
QString toString(QStringView format, QCalendar cal) const const
QDateTime addDays(qint64 ndays) const const
QDateTime addSecs(qint64 s) const const
bool isValid() const const
qint64 secsTo(const QDateTime &other) const const
QIcon fromTheme(const QString &name)
const_reference at(qsizetype i) const const
void push_back(parameter_type value)
qsizetype size() const const
QString arg(Args &&... args) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)