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);
122void SchedulerAltitudeGraph::plot()
124 if (m_State->jobs().size() == 0)
126 altGraph->removeAllPlotObjects();
129 altGraphLabel->setText(
"");
133 m_AltitudeGraphUpdateTime = SchedulerModuleState::getLocalTime();
134 const QDateTime now = SchedulerModuleState::getLocalTime().
addDays(m_AltGraphDay), start,
end;
136 SchedulerModuleState::calculateDawnDusk(now, nextDawn, nextDusk);
137 QDateTime plotStart = (nextDusk < nextDawn) ? nextDusk : nextDusk.addDays(-1);
145 const QString dayName = m_AltGraphDay == 1 ?
i18n(
"Tomorrow") : (m_AltGraphDay == 2 ?
i18n(
"Day After Tomorrow") :
151 altGraphLabel->setText(plotTitle);
154 KSAlmanac ksal(ut, SchedulerModuleState::getGeo());
157 plotStart = plotStart.
addSecs(-1 * 3600);
158 auto plotEnd = nextDawn.
addSecs(1 * 3600);
160 handleButtons(
false);
162 const int currentPosition = m_State->currentPosition();
164 for (
int index = 0; index < m_State->jobs().size(); index++)
168 auto job = m_State->jobs().
at(index);
169 while (t.secsTo(plotEnd) > 0)
171 double alt = SchedulerUtils::findAltitude(job->getTargetCoords(), t);
173 double hour = midnight.
secsTo(t) / 3600.0;
175 t = t.addSecs(60 * 10);
178 const int lineWidth = (index == currentPosition) ? 2 : 1;
180 altGraph->plot(SchedulerModuleState::getGeo(), &ksal, times, alts, lineWidth,
Qt::white, job->getName());
182 altGraph->plotOverlay(times, alts, lineWidth,
Qt::white, job->getName());
185 altGraph->setCurrentLine(currentPosition);
192 for (
int index = 0; index < m_State->jobs().size(); index++)
194 auto job = m_State->jobs().at(index);
195 for (
const auto &jobSchedule : job->getSimulatedSchedule())
197 auto startTime = jobSchedule.startTime;
198 auto stopTime = jobSchedule.stopTime;
199 if (!startTime.isValid())
201 if (startTime < plotStart)
202 startTime = plotStart;
203 if (!stopTime.isValid() || stopTime > plotEnd)
205 if (startTime.isValid() && startTime < plotEnd && stopTime.isValid() && stopTime > plotStart)
209 while (t.secsTo(stopTime) >= 0)
211 double alt = SchedulerUtils::findAltitude(job->getTargetCoords(), t);
213 double hour = midnight.
secsTo(t) / 3600.0;
215 int secsToStop = t.secsTo(stopTime);
216 if (secsToStop <= 0)
break;
217 t = t.addSecs(std::min(60 * 1, secsToStop));
220 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
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)
QString arg(Args &&... args) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)