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 altGraphLabel->setText(
"");
94 altMoveLeftB->setEnabled(
false);
95 altMoveLeftB->setIcon(
QIcon());
96 altMoveRightB->setEnabled(
false);
97 altMoveRightB->setIcon(
QIcon());
99 else if (m_AltGraphDay == 1)
101 altGraphLabel->setText(
"Tomorrow");
102 altMoveLeftB->setEnabled(
true);
103 altMoveRightB->setEnabled(
true);
107 else if (m_AltGraphDay == 2)
109 altGraphLabel->setText(
"Day After Tomorrow");
110 altMoveLeftB->setEnabled(
true);
112 altMoveRightB->setEnabled(
false);
113 altMoveRightB->setIcon(
QIcon());
118 altGraphLabel->setText(
"");
119 altMoveLeftB->setEnabled(
false);
120 altMoveLeftB->setIcon(
QIcon());
121 altMoveRightB->setEnabled(
true);
126void SchedulerAltitudeGraph::plot()
128 if (m_State->jobs().size() == 0)
130 altGraph->removeAllPlotObjects();
136 m_AltitudeGraphUpdateTime = SchedulerModuleState::getLocalTime();
137 const QDateTime now = SchedulerModuleState::getLocalTime().
addDays(m_AltGraphDay), start,
end;
139 SchedulerModuleState::calculateDawnDusk(now, nextDawn, nextDusk);
140 QDateTime plotStart = (nextDusk < nextDawn) ? nextDusk : nextDusk.addDays(-1);
148 KSAlmanac ksal(ut, SchedulerModuleState::getGeo());
151 plotStart = plotStart.
addSecs(-1 * 3600);
152 auto plotEnd = nextDawn.
addSecs(1 * 3600);
156 const int currentPosition = m_State->currentPosition();
158 for (
int index = 0; index < m_State->jobs().size(); index++)
162 auto job = m_State->jobs().
at(index);
163 while (t.secsTo(plotEnd) > 0)
165 double alt = SchedulerUtils::findAltitude(job->getTargetCoords(), t);
167 double hour = midnight.
secsTo(t) / 3600.0;
169 t = t.addSecs(60 * 10);
172 const int lineWidth = (index == currentPosition) ? 2 : 1;
174 altGraph->plot(SchedulerModuleState::getGeo(), &ksal, times, alts, lineWidth,
Qt::white);
176 altGraph->plotOverlay(times, alts, lineWidth,
Qt::white);
179 altGraph->setCurrentLine(currentPosition);
186 for (
int index = 0; index < m_State->jobs().size(); index++)
188 auto job = m_State->jobs().at(index);
189 for (
const auto &jobSchedule : job->getSimulatedSchedule())
191 auto startTime = jobSchedule.startTime;
192 auto stopTime = jobSchedule.stopTime;
193 if (startTime.isValid() && startTime < plotEnd && stopTime.isValid() && stopTime > plotStart)
195 if (startTime < plotStart) startTime = plotStart;
196 if (stopTime > plotEnd)
201 while (t.secsTo(stopTime) >= 0)
203 double alt = SchedulerUtils::findAltitude(job->getTargetCoords(), t);
205 double hour = midnight.
secsTo(t) / 3600.0;
207 int secsToStop = t.secsTo(stopTime);
208 if (secsToStop <= 0)
break;
209 t = t.addSecs(std::min(60 * 1, secsToStop));
212 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,...
Ekos is an advanced Astrophotography tool for Linux.
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
QDate addDays(qint64 ndays) 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)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)