Kstars

capturecountswidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
3  SPDX-FileCopyrightText: 2021 Wolfgang Reissenberger <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "capturecountswidget.h"
9 #include "Options.h"
10 #include "ekos/ekos.h"
11 #include "ekos/manager.h"
12 
13 using Ekos::SequenceJob;
14 
15 CaptureCountsWidget::CaptureCountsWidget(QWidget *parent) : QWidget(parent)
16 {
17  setupUi(this);
18  // switch between stacked views
19  connect(switchToGraphicsButton, &QPushButton::clicked, this, [this]()
20  {
21  textView->setVisible(false);
22  graphicalView->setVisible(true);
23  Options::setUseGraphicalCountsDisplay(true);
24  });
25  connect(switchToTextButton, &QPushButton::clicked, this, [this]()
26  {
27  textView->setVisible(true);
28  graphicalView->setVisible(false);
29  Options::setUseGraphicalCountsDisplay(false);
30  });
31 
32  // start with the last used view
33  graphicalView->setVisible(Options::useGraphicalCountsDisplay());
34  textView->setVisible(!Options::useGraphicalCountsDisplay());
35 
36  // setup graphical view
37  gr_sequenceProgressBar->setDecimals(0);
38  gr_overallProgressBar->setDecimals(0);
39 
40  reset();
41 }
42 
43 void CaptureCountsWidget::updateExposureProgress(Ekos::SequenceJob *job)
44 {
45  imageCountDown.setHMS(0, 0, 0);
46  imageCountDown = imageCountDown.addSecs(int(std::round(job->getExposeLeft())));
47  if (imageCountDown.hour() == 23)
48  imageCountDown.setHMS(0, 0, 0);
49 
50  imageProgress->setRange(0, int(std::ceil(job->getCoreProperty(SequenceJob::SJ_Exposure).toDouble())));
51  imageProgress->setValue(int(std::ceil(job->getCoreProperty(SequenceJob::SJ_Exposure).toDouble() - job->getExposeLeft())));
52  gr_imageProgress->setRange(0, int(std::ceil(job->getCoreProperty(SequenceJob::SJ_Exposure).toDouble())));
53  gr_imageProgress->setValue(imageProgress->value());
54 
55  frameRemainingTime->setText(imageCountDown.toString("hh:mm:ss"));
56  gr_frameRemainingTime->setText(frameRemainingTime->text());
57 }
58 
59 void CaptureCountsWidget::updateDownloadProgress(double timeLeft)
60 {
61  imageCountDown.setHMS(0, 0, 0);
62  imageCountDown = imageCountDown.addSecs(int(std::ceil(timeLeft)));
63  frameRemainingTime->setText(imageCountDown.toString("hh:mm:ss"));
64 }
65 
66 void CaptureCountsWidget::updateCaptureCountDown(int delta)
67 {
68  overallCountDown = overallCountDown.addSecs(delta);
69  jobCountDown = jobCountDown.addSecs(delta);
70  sequenceCountDown = sequenceCountDown.addSecs(delta);
71 
72  // ensure that count downs do not overshoot
73  if (overallCountDown.hour() == 23)
74  overallCountDown.setHMS(0, 0, 0);
75  if (jobCountDown.hour() == 23)
76  jobCountDown.setHMS(0, 0, 0);
77  if (sequenceCountDown.hour() == 23)
78  sequenceCountDown.setHMS(0, 0, 0);
79 
80  // do not change overall remaining time if scheduler is in endless loop
81  if (schedulerProcess == nullptr || schedulerProcess->getCurrentJob() == nullptr ||
82  schedulerProcess->getCurrentJob()->getCompletionCondition() != SchedulerJob::FINISH_LOOP)
83  {
84  overallRemainingTime->setText(overallCountDown.toString("hh:mm:ss"));
85  gr_overallRemainingTime->setText(overallRemainingTime->text());
86  }
87  jobRemainingTime->setText(jobCountDown.toString("hh:mm:ss"));
88  sequenceRemainingTime->setText(sequenceCountDown.toString("hh:mm:ss"));
89  gr_sequenceRemainingTime->setText(sequenceRemainingTime->text());
90 }
91 
92 void CaptureCountsWidget::reset()
93 {
94  // reset graphical view
95  gr_imageProgress->setValue(0);
96  gr_frameLabel->setText("");
97  gr_frameRemainingTime->setText("--:--:--");
98  gr_frameDetailsLabel->setText("");
99  gr_sequenceLabel->setText(i18n("Sequence"));
100  gr_sequenceProgressBar->setValue(0);
101  gr_sequenceRemainingTime->setText("--:--:--");
102  gr_overallLabel->setText(i18n("Overall"));
103  gr_overallProgressBar->setValue(0);
104  gr_overallRemainingTime->setText("--:--:--");
105 
106  // reset text view
107  imageProgress->setValue(0);
108  setFrameInfo("");
109  frameRemainingTime->setText("");
110 
111  overallRemainingTime->setText("--:--:--");
112  jobRemainingTime->setText("--:--:--");
113  sequenceRemainingTime->setText("--:--:--");
114 }
115 
116 void CaptureCountsWidget::setFrameInfo(const QString frametype, const QString filter, const double exptime, const int xBin,
117  const int yBin, const double gain)
118 {
119  if (frametype == "")
120  {
121  frameInfoLabel->setText("");
122  frameDetailsLabel->setText("");
123  gr_frameRemainingTime->setText("");
124  }
125  else
126  {
127  frameInfoLabel->setText(QString("%1 %2").arg(frametype).arg(filter));
128  gr_frameLabel->setText(frameInfoLabel->text());
129  QString details = "";
130  if (exptime > 0)
131  details.append(QString("%1: %2 sec").arg(i18n("Exposure")).arg(exptime, 0, 'f', exptime < 1 ? 2 : exptime < 5 ? 1 : 0));
132  if (xBin > 0 && yBin > 0)
133  details.append(QString(", bin: %1x%2").arg(xBin).arg(yBin));
134  if (gain >= 0)
135  details.append(QString(", gain: %1").arg(gain, 0, 'f', 1));
136 
137  frameDetailsLabel->setText(details);
138  gr_frameDetailsLabel->setText(details);
139  }
140 }
141 
142 void CaptureCountsWidget::updateCaptureStatus(Ekos::CaptureState status)
143 {
144  overallCountDown.setHMS(0, 0, 0);
145  bool infinite_loop = false;
146  int total_remaining_time = 0, total_completed = 0, total_count = 0;
147  double total_percentage = 0;
148  // use this value if no scheduler is running and job name otherwise
149  QString total_label = "Total";
150 
151  // determine total number of frames and completed ones - used either for
152  // total numbers if scheduler is not used - and for job figures in the text
153  // display if the scheduler is used
154  double capture_total_percentage = captureProcess->getProgressPercentage();
155  int capture_remaining_time = captureProcess->getOverallRemainingTime();
156  int capture_total_count = 0, capture_total_completed = 0;
157  for (int i = 0; i < captureProcess->getJobCount(); i++)
158  {
159  capture_total_count += captureProcess->getJobImageCount(i);
160  capture_total_completed += captureProcess->getJobImageProgress(i);
161  }
162 
163 
164  if (schedulerProcess != nullptr && schedulerProcess->getCurrentJob() != nullptr)
165  {
166  total_label = schedulerProcess->getCurrentJobName();
167  // FIXME: accessing the completed count might be one too low due to concurrency of updating the count and this loop
168  total_completed = schedulerProcess->getCurrentJob()->getCompletedCount();
169  total_count = schedulerProcess->getCurrentJob()->getSequenceCount();
170  infinite_loop = (schedulerProcess->getCurrentJob()->getCompletionCondition() == SchedulerJob::FINISH_LOOP);
171  if (total_count > 0)
172  total_percentage = (100 * total_completed) / total_count;
173  if (schedulerProcess->getCurrentJob()->getEstimatedTime() > 0)
174  total_remaining_time = int(schedulerProcess->getCurrentJob()->getEstimatedTime());
175  }
176  else
177  {
178  total_percentage = capture_total_percentage;
179  total_remaining_time = capture_remaining_time;
180  total_count = capture_total_count;
181  total_completed = capture_total_completed;
182  }
183 
184  switch (status)
185  {
186  case Ekos::CAPTURE_IDLE:
187  // do nothing
188  break;
190  reset();
191  break;
192  default:
193  if (infinite_loop == true)
194  {
195  overallRemainingTime->setText("--:--:--");
196  gr_overallProgressBar->setValue(0);
197  gr_overallRemainingTime->setText(overallRemainingTime->text());
198  }
199  else
200  {
201  overallCountDown = overallCountDown.addSecs(total_remaining_time);
202  gr_overallProgressBar->setValue(total_percentage);
203  }
204 
205  // display overall remainings
206  overallLabel->setText(QString("%1 (%2/%3)")
207  .arg(total_label)
208  .arg(total_completed)
209  .arg(infinite_loop ? QString("-") : QString::number(total_count)));
210  gr_overallLabel->setText(overallLabel->text());
211 
212  // update job remaining time if run from the scheduler
213  bool show_job_progress = (schedulerProcess != nullptr && schedulerProcess->getCurrentJob() != nullptr);
214  jobLabel->setVisible(show_job_progress);
215  jobRemainingTime->setVisible(show_job_progress);
216  if (show_job_progress)
217  {
218  jobCountDown.setHMS(0, 0, 0);
219  jobCountDown = jobCountDown.addSecs(captureProcess->getOverallRemainingTime());
220  jobLabel->setText(QString("Job (%1/%2)")
221  .arg(capture_total_completed)
222  .arg(capture_total_count));
223  }
224 
225  // update sequence remaining time
226  sequenceCountDown.setHMS(0, 0, 0);
227  sequenceCountDown = sequenceCountDown.addSecs(captureProcess->getActiveJobRemainingTime());
228  }
229 }
230 
231 void CaptureCountsWidget::updateJobProgress(Ekos::SequenceJob *job)
232 {
233  // display informations about the current active capture
234  if (job->getCoreProperty(SequenceJob::SJ_Preview).toBool() == true)
235  setFrameInfo(i18n("Preview"), job->getCoreProperty(SequenceJob::SJ_Filter).toString(),
236  job->getCoreProperty(SequenceJob::SJ_Exposure).toDouble(), job->getCoreProperty(SequenceJob::SJ_Binning).toPoint().x(),
237  job->getCoreProperty(SequenceJob::SJ_Binning).toPoint().y(), job->getCoreProperty(SequenceJob::SJ_Gain).toDouble());
238  else
239  setFrameInfo(CCDFrameTypeNames[job->getFrameType()], job->getCoreProperty(SequenceJob::SJ_Filter).toString(),
240  job->getCoreProperty(SequenceJob::SJ_Exposure).toDouble(), job->getCoreProperty(SequenceJob::SJ_Binning).toPoint().x(),
241  job->getCoreProperty(SequenceJob::SJ_Binning).toPoint().y(), job->getCoreProperty(SequenceJob::SJ_Gain).toDouble());
242 
243  // display sequence progress in the graphical view
244  gr_sequenceProgressBar->setRange(0, job->getCoreProperty(SequenceJob::SJ_Count).toInt());
245  gr_sequenceProgressBar->setValue(job->getCompleted());
246  sequenceLabel->setText(QString("%1 %2 (%3/%4)")
247  .arg(CCDFrameTypeNames[job->getFrameType()])
248  .arg(job->getCoreProperty(SequenceJob::SJ_Filter).toString())
249  .arg(job->getCompleted()).arg(job->getCoreProperty(SequenceJob::SJ_Count).toInt()));
250  gr_sequenceLabel->setText(sequenceLabel->text());
251 }
252 
253 void CaptureCountsWidget::setEnabled(bool enabled)
254 {
255  QWidget::setEnabled(enabled);
256  overallLabel->setEnabled(enabled);
257  gr_overallLabel->setEnabled(enabled);
258 }
QString number(int n, int base)
void clicked(bool checked)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString i18n(const char *text, const TYPE &arg...)
@ CAPTURE_IDLE
Definition: ekos.h:93
CaptureState
Capture states.
Definition: ekos.h:91
void setupUi(QWidget *widget)
void setEnabled(bool)
double toDouble(bool *ok) const const
@ CAPTURE_ABORTED
Definition: ekos.h:99
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
KGuiItem reset()
QString & append(QChar ch)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.