8#include "capturecountswidget.h"
10#include "ekos/manager.h"
11#include "ekos/scheduler/schedulerjob.h"
12#include "ekos/scheduler/schedulermodulestate.h"
13#include "ekos/capture/capture.h"
14#include "ekos/capture/sequencejob.h"
16#include <ekos_capture_debug.h>
18using Ekos::SequenceJob;
20CaptureCountsWidget::CaptureCountsWidget(
QWidget *parent) :
QWidget(parent)
26 textView->setVisible(
false);
27 graphicalView->setVisible(
true);
28 Options::setUseGraphicalCountsDisplay(
true);
32 textView->setVisible(
true);
33 graphicalView->setVisible(
false);
34 Options::setUseGraphicalCountsDisplay(
false);
38 graphicalView->setVisible(Options::useGraphicalCountsDisplay());
39 textView->setVisible(!Options::useGraphicalCountsDisplay());
42 gr_sequenceProgressBar->setDecimals(0);
43 gr_overallProgressBar->setDecimals(0);
48void CaptureCountsWidget::setCurrentTrainName(
const QString &name)
50 m_currentTrainName =
name;
51 showCurrentCameraInfo();
54void CaptureCountsWidget::updateExposureProgress(Ekos::SequenceJob *job,
const QString &devicename)
56 imageCountDown[devicename].setHMS(0, 0, 0);
57 imageCountDown[devicename] = imageCountDown[devicename].addSecs(
int(std::round(job->getExposeLeft())));
58 if (imageCountDown[devicename].hour() == 23)
59 imageCountDown[devicename].setHMS(0, 0, 0);
61 imageProgress->setRange(0,
int(std::ceil(job->getCoreProperty(SequenceJob::SJ_Exposure).
toDouble())));
62 imageProgress->setValue(
int(std::ceil(job->getCoreProperty(SequenceJob::SJ_Exposure).
toDouble() - job->getExposeLeft())));
63 gr_imageProgress->setRange(0,
int(std::ceil(job->getCoreProperty(SequenceJob::SJ_Exposure).
toDouble())));
64 gr_imageProgress->setValue(imageProgress->value());
66 frameRemainingTime->setText(imageCountDown[devicename].
toString(
"hh:mm:ss"));
67 gr_frameRemainingTime->setText(frameRemainingTime->text());
70void CaptureCountsWidget::updateDownloadProgress(
double timeLeft,
const QString &trainname)
72 imageCountDown[trainname].setHMS(0, 0, 0);
73 imageCountDown[trainname] = imageCountDown[trainname].addSecs(
int(std::ceil(timeLeft)));
74 frameRemainingTime->setText(imageCountDown[trainname].
toString(
"hh:mm:ss"));
79 m_schedulerModuleState = state;
82void CaptureCountsWidget::updateCaptureCountDown(
int delta)
85 for (
const QString &devicename : overallCountDown.
keys())
87 overallCountDown[devicename] = overallCountDown[devicename].addSecs(delta);
88 jobCountDown[devicename] = jobCountDown[devicename].addSecs(delta);
89 sequenceCountDown[devicename] = sequenceCountDown[devicename].addSecs(delta);
92 if (overallCountDown[devicename].hour() == 23)
93 overallCountDown[devicename].setHMS(0, 0, 0);
94 if (jobCountDown[devicename].hour() == 23)
95 jobCountDown[devicename].setHMS(0, 0, 0);
96 if (sequenceCountDown[devicename].hour() == 23)
97 sequenceCountDown[devicename].setHMS(0, 0, 0);
101 if (m_schedulerModuleState ==
nullptr || m_schedulerModuleState->activeJob() ==
nullptr ||
102 m_schedulerModuleState->activeJob()->getCompletionCondition() != Ekos::FINISH_LOOP)
104 overallRemainingTime->setText(overallCountDown[m_currentTrainName].
toString(
"hh:mm:ss"));
105 gr_overallRemainingTime->setText(overallRemainingTime->text());
109 jobRemainingTime->setText(jobCountDown[m_currentTrainName].
toString(
"hh:mm:ss"));
110 sequenceRemainingTime->setText(sequenceCountDown[m_currentTrainName].
toString(
"hh:mm:ss"));
111 gr_sequenceRemainingTime->setText(sequenceRemainingTime->text());
115 jobRemainingTime->setText(
"--:--:--");
116 sequenceRemainingTime->setText(
"--:--:--");
117 gr_sequenceRemainingTime->setText(
"--:--:--");
121void CaptureCountsWidget::reset()
124 gr_imageProgress->setValue(0);
125 gr_frameLabel->setText(
"");
126 gr_frameRemainingTime->setText(
"--:--:--");
127 gr_frameDetailsLabel->setText(
"");
128 gr_sequenceLabel->setText(
i18n(
"Sequence"));
129 gr_sequenceProgressBar->setValue(0);
130 gr_sequenceRemainingTime->setText(
"--:--:--");
131 gr_overallLabel->setText(
i18n(
"Overall"));
132 gr_overallProgressBar->setValue(0);
133 gr_overallRemainingTime->setText(
"--:--:--");
136 imageProgress->setValue(0);
138 frameRemainingTime->setText(
"");
140 overallRemainingTime->setText(
"--:--:--");
141 jobRemainingTime->setText(
"--:--:--");
142 sequenceRemainingTime->setText(
"--:--:--");
156 else if (type ==
"Flat")
168void CaptureCountsWidget::setFrameInfo(
const QString frametype,
const QString filter,
const double exptime,
const int xBin,
169 const int yBin,
const double gain)
173 frameInfoLabel->setText(
"");
174 frameDetailsLabel->setText(
"");
175 gr_frameRemainingTime->setText(
"");
179 frameInfoLabel->setText(
QString(
"%1").arg(frameLabel(frametype, filter)));
180 gr_frameLabel->setText(frameInfoLabel->text());
183 details.
append(
QString(
"%1: %2 sec").arg(
i18n(
"Exposure")).arg(exptime, 0,
'f', exptime < 1 ? 2 : exptime < 5 ? 1 : 0));
184 if (xBin > 0 && yBin > 0)
189 frameDetailsLabel->setText(details);
190 gr_frameDetailsLabel->setText(details);
196 overallCountDown[trainname].setHMS(0, 0, 0);
197 bool infinite_loop =
false;
198 int total_remaining_time = 0, total_completed = 0, total_count = 0;
199 double total_percentage = 0;
207 if (camera->opticalTrain() == trainname)
209 selected_cam = camera;
214 if (selected_cam.
isNull())
216 qCWarning(KSTARS_EKOS_CAPTURE) <<
"No matching camera found" << m_currentTrainName;
223 double capture_total_percentage = selected_cam->state()->progressPercentage();
224 int capture_remaining_time = selected_cam->state()->overallRemainingTime();
225 int capture_total_count = 0, capture_total_completed = 0;
226 for (
int i = 0; i < selected_cam->state()->allJobs().count(); i++)
228 capture_total_count += selected_cam->state()->jobImageCount(i);
229 capture_total_completed += selected_cam->state()->jobImageProgress(i);
233 if (m_schedulerModuleState !=
nullptr && m_schedulerModuleState->activeJob() !=
nullptr)
235 total_label = m_schedulerModuleState->activeJob()->getName();
237 total_completed = m_schedulerModuleState->activeJob()->getCompletedCount();
238 total_count = m_schedulerModuleState->activeJob()->getSequenceCount();
239 infinite_loop = (m_schedulerModuleState->activeJob()->getCompletionCondition() == Ekos::FINISH_LOOP);
241 total_percentage = (100 * total_completed) / total_count;
242 if (m_schedulerModuleState->activeJob()->getEstimatedTime() > 0)
243 total_remaining_time = int(m_schedulerModuleState->activeJob()->getEstimatedTime());
247 total_percentage = capture_total_percentage;
248 total_remaining_time = capture_remaining_time;
249 total_count = capture_total_count;
250 total_completed = capture_total_completed;
262 if (infinite_loop ==
true)
264 overallRemainingTime->setText(
"--:--:--");
265 gr_overallProgressBar->setValue(0);
266 gr_overallRemainingTime->setText(overallRemainingTime->text());
270 overallCountDown[trainname] = overallCountDown[trainname].addSecs(total_remaining_time);
271 gr_overallProgressBar->setValue(total_percentage);
276 overallLabel->setText(
QString(
"%1").arg(total_label));
278 overallLabel->setText(
QString(
"%1 (%2/%3)")
280 .arg(total_completed)
282 gr_overallLabel->setText(overallLabel->text());
285 bool show_job_progress = (m_schedulerModuleState !=
nullptr && m_schedulerModuleState->activeJob() !=
nullptr);
286 jobLabel->setVisible(show_job_progress);
287 jobRemainingTime->setVisible(show_job_progress);
288 if (show_job_progress)
290 jobCountDown[trainname].setHMS(0, 0, 0);
291 jobCountDown[trainname] = jobCountDown[trainname].addSecs(selected_cam->state()->overallRemainingTime());
292 jobLabel->setText(
QString(
"Job (%1/%2)")
293 .arg(capture_total_completed)
294 .arg(capture_total_count));
298 sequenceCountDown[trainname].setHMS(0, 0, 0);
299 sequenceCountDown[trainname] = sequenceCountDown[trainname].addSecs(selected_cam->state()->activeJobRemainingTime());
303void CaptureCountsWidget::updateJobProgress(CaptureProcessOverlay::FrameData data,
const QString &trainname)
305 m_currentFrame[trainname] = data;
308 if (trainname == m_currentTrainName)
309 showCurrentCameraInfo();
312void CaptureCountsWidget::showCurrentCameraInfo()
314 if (!m_currentFrame.
contains(m_currentTrainName))
316 qCWarning(KSTARS_EKOS_CAPTURE) <<
"No frame info available for" << m_currentTrainName;
320 auto data = m_currentFrame[m_currentTrainName];
322 if (data.jobType == SequenceJob::JOBTYPE_PREVIEW)
323 setFrameInfo(
i18n(
"Preview"), data.filterName, data.exptime, data.binning.
x(), data.binning.
y(), data.gain);
325 setFrameInfo(CCDFrameTypeNames[data.frameType], data.filterName, data.exptime, data.binning.
x(),
326 data.binning.
y(), data.gain);
329 gr_sequenceProgressBar->setRange(0, data.count);
330 gr_sequenceProgressBar->setValue(data.completed);
331 if (data.jobType == SequenceJob::JOBTYPE_PREVIEW)
332 sequenceLabel->setText(
QString(
"%1").arg(frameLabel(CCDFrameTypeNames[data.frameType], data.filterName)));
334 sequenceLabel->setText(
QString(
"%1 (%3/%4)")
335 .arg(frameLabel(CCDFrameTypeNames[data.frameType], data.filterName)).
arg(data.completed).
arg(data.count));
337 gr_sequenceLabel->setText(sequenceLabel->text());
341void CaptureCountsWidget::setEnabled(
bool enabled)
344 overallLabel->setEnabled(
enabled);
345 gr_overallLabel->setEnabled(
enabled);
Q_SCRIPTABLE bool isActiveJobPreview()
DBUS interface function.
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
CaptureState
Capture states.
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
bool contains(const Key &key) const const
QList< Key > keys() const const
bool isNull() const const
QString & append(QChar ch)
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
double toDouble(bool *ok) const const