Kstars

sequencejob.h
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "sequencejobstate.h"
10
11#include <QTableWidgetItem>
12
13class SkyPoint;
14
15/**
16 * @class SequenceJob
17 * @short Sequence Job is a container for the details required to capture a series of images.
18 *
19 * @author Jasem Mutlaq
20 * @version 1.0
21 */
22namespace Ekos
23{
24
25class CaptureDeviceAdaptor;
26
27class SequenceJob : public QObject
28{
30
31 public:
32 static QString const &ISOMarker;
33 static const QStringList StatusStrings();
34
35 // Core Properties
36 typedef enum
37 {
38 // Bool
39 SJ_EnforceTemperature,
40 // Bool
41 // SJ_EnforceStartGuiderDrift, // no specific option
42 // Bool
43 SJ_GuiderActive,
44 // Double
45 SJ_Exposure,
46 // QString
47 SJ_Filter,
48 // QString
49 SJ_Format,
50 // QString
51 SJ_Encoding,
52 // QPoint
53 SJ_Binning,
54 // QRect
55 SJ_ROI,
56 // QString
57 SJ_FullPrefix,
58 // Int
59 SJ_Count,
60 // Int
61 SJ_Delay,
62 // QString
63 SJ_ISO,
64 // Int
65 SJ_ISOIndex,
66 // Double
67 SJ_Gain,
68 // Double
69 SJ_Offset,
70 // QString
71 SJ_TargetName,
72 //QString
73 SJ_LocalDirectory,
74 // QString
75 SJ_PlaceholderFormat,
76 // Uint
77 SJ_PlaceholderSuffix,
78 // QString
79 SJ_RemoteDirectory,
80 // QString
81 SJ_RemoteFormatDirectory,
82 // QString
83 SJ_RemoteFormatFilename,
84 // QString
85 SJ_Filename,
86 // Double
87 SJ_TargetADU,
88 // Double
89 SJ_TargetADUTolerance,
90 // QString
91 SJ_Signature,
92 // Int
93 SJ_DitherPerJobFrequency,
94 // Bool
95 SJ_DitherPerJobEnabled,
96 // Bool
97 SJ_SkyFlat
98 } PropertyID;
99
100 typedef enum
101 {
102 JOBTYPE_BATCH, /* regular batch job */
103 JOBTYPE_PREVIEW, /* previews (single or looping) */
104 JOBTYPE_DARKFLAT /* capturing dark flats */
105 } SequenceJobType;
106
107 ////////////////////////////////////////////////////////////////////////
108 /// Constructors
109 ////////////////////////////////////////////////////////////////////////
111 const QSharedPointer<CameraState> sharedState,
112 SequenceJobType jobType, XMLEle *root = nullptr, QString targetName = "");
113 SequenceJob(XMLEle *root, QString targetName);
114 ~SequenceJob() = default;
115
116 ////////////////////////////////////////////////////////////////////////
117 /// Capture Fuctions
118 ////////////////////////////////////////////////////////////////////////
119 /**
120 * @brief startCapturing Initialize the camera and start capturing
121 *
122 * This step calls {@see SequenceJobState::initCapture()}, which triggers
123 * all actions before the camera may start to capture. If the initialization
124 * is completed, the sequence job state machine sends the signal
125 * {@see SequenceJobState::initCaptureComplete()} which will trigger the
126 * camera device to finally start capturing ({@see capture()}).
127 *
128 * @param autofocusReady was there a successful focus run previously?
129 * @param mode what is the purpose of capturing?
130 */
131 void startCapturing(bool autofocusReady, FITSMode mode);
132 /**
133 * @brief capture As soon as everything is ready for the camera to start
134 * capturing, this method triggers the camera device to start capturing.
135 * @param mode what is the purpose of capturing?
136 */
137 void capture(FITSMode mode);
138 void abort();
139 void done();
140
141 ////////////////////////////////////////////////////////////////////////
142 /// Core Properties
143 ////////////////////////////////////////////////////////////////////////
144 void setCoreProperty(PropertyID id, const QVariant &value);
145 QVariant getCoreProperty(PropertyID id) const;
146
147 ////////////////////////////////////////////////////////////////////////
148 /// Job Status Functions
149 ////////////////////////////////////////////////////////////////////////
150 const QString &getStatusString()
151 {
152 return StatusStrings()[getStatus()];
153 }
154 // Setter: Set how many captures have completed thus far
155 void setCompleted(int value)
156 {
157 m_Completed = value;
158 }
159 // Getter: How many captured have completed thus far.
160 int getCompleted() const
161 {
162 return m_Completed;
163 }
164 // Setter: Set how many more seconds to expose in this job
165 void setExposeLeft(double value);
166 // Getter: Get how many more seconds are left to expose.
167 double getExposeLeft() const;
168 // Reset: Reset the job status
169 void resetStatus(JOBStatus status = JOB_IDLE);
170 // Setter: Set how many times we re-try this job.
171 void setCaptureRetires(int value);
172 // Getter: Get many timed we retried this job already.
173 int getCaptureRetires() const;
174 // Getter: How many more seconds are remaining in this job given the
175 // estimated download time.
176 int getJobRemainingTime(double estimatedDownloadTime);
177
178 ////////////////////////////////////////////////////////////////////////
179 /// State Machine Functions
180 ////////////////////////////////////////////////////////////////////////
181 // Create all event connections between the state machine and the command processor
182 void connectDeviceAdaptor();
183 // Disconnect all event connections between the state machine and the command processor
184 void disconnectDeviceAdaptor();
185 // Setter: Set Target Filter Name
186 void setTargetFilter(int pos, const QString &name);
187 // Getter: Get Current Filter Slot
188 int getCurrentFilter() const;
189 // Retrieve the pier side from the state
190 ISD::Mount::PierSide getPierSide() const;
191
192 ////////////////////////////////////////////////////////////////////////
193 /// Job Attribute Functions
194 ////////////////////////////////////////////////////////////////////////
195 // job type
196 SequenceJobType jobType() const
197 {
198 return m_jobType;
199 }
200 void setJobType(SequenceJobType newJobType)
201 {
202 m_jobType = newJobType;
203 }
204 QString getSignature()
205 {
206 return (getCoreProperty(SJ_Signature).toString()).remove(".fits");
207 }
208 // Scripts
209 const QMap<ScriptTypes, QString> &getScripts() const
210 {
211 return m_Scripts;
212 }
213 void setScripts(const QMap<ScriptTypes, QString> &scripts)
214 {
215 m_Scripts = scripts;
216 }
217 const QString getScript(ScriptTypes type) const
218 {
219 return m_Scripts[type];
220 }
221 void setScript(ScriptTypes type, const QString &value)
222 {
223 m_Scripts[type] = value;
224 }
225
226 // helper function setting both ISO index and ISO value
227 void setISO(int index);
228
229 // Custom Properties
230 const QMap<QString, QMap<QString, QVariant> > getCustomProperties() const
231 {
232 return m_CustomProperties;
233 }
234 void setCustomProperties(const QMap<QString, QMap<QString, QVariant> > &value)
235 {
236 m_CustomProperties = value;
237 }
238
239 // Core Properties
240 const QMap<PropertyID, QVariant> &getCoreProperties() const
241 {
242 return m_CoreProperties;
243 }
244
245 /**
246 * @brief Retrieve remote directory or, if empty, use the local directory value
247 */
248 const QVariant getRemoteDirectory() const;
249
250 // Setter: Set upload mode
251 void setUploadMode(ISD::Camera::UploadMode value);
252 // Getter: get upload mode
253 ISD::Camera::UploadMode getUploadMode() const;
254
255 // Setter: Set flat field source
256 void setCalibrationPreAction(uint32_t value);
257 // Getter: Get flat field source
258 uint32_t getCalibrationPreAction() const;
259
260 // Setter: Set Wall SkyPoint Azimuth coords
261 void setWallCoord(const SkyPoint &value);
262 // Getter: Get Flat field source wall coords
263 const SkyPoint &getWallCoord() const;
264
265 // Setter: Set flat field duration
266 void setFlatFieldDuration(FlatFieldDuration value);
267 // Getter: Get flat field duration
268 FlatFieldDuration getFlatFieldDuration() const;
269
270 // Setter: Set job progress ignored flag
271 void setJobProgressIgnored(bool value);
272 bool getJobProgressIgnored() const;
273
274 /**
275 * @brief updateDeviceStates Update for all used device types whether there
276 * is one connected.
277 */
278 void updateDeviceStates();
279 /**
280 * @brief Set the light box device
281 */
282 void setLightBox(ISD::LightBox *lightBox);
283
284 /**
285 * @brief Set the dust cap device
286 */
287 void setDustCap(ISD::DustCap *dustCap);
288
289 /**
290 * @brief Set the telescope device
291 */
292 void addMount(ISD::Mount *scope);
293
294 /**
295 * @brief Set the dome device
296 */
297 void setDome(ISD::Dome *dome);
298
299
300 // ////////////////////////////////////////////////////////////////////////////
301 // Facade to state machine
302 // ////////////////////////////////////////////////////////////////////////////
303 /**
304 * @brief Retrieve the current status of the capture sequence job from the state machine
305 */
306 JOBStatus getStatus()
307 {
308 return state->getStatus();
309 }
310
311 void setFrameType(CCDFrameType value)
312 {
313 state->setFrameType(value);
314 }
315 CCDFrameType getFrameType() const
316 {
317 return state->getFrameType();
318 }
319
320 bool isVideo() const
321 {
322 return state->getFrameType() == FRAME_VIDEO;
323 }
324
325 int getTargetFilter() const
326 {
327 return state->targetFilterID;
328 }
329
330 double getTargetTemperature() const
331 {
332 return state->targetTemperature;
333 }
334 void setTargetTemperature(double value)
335 {
336 state->targetTemperature = value;
337 }
338
339 void setFocusStatus(FocusState value)
340 {
341 state->setFocusStatus(value);
342 }
343
344 double getTargetRotation() const
345 {
346 return state->targetPositionAngle;
347 }
348 void setTargetRotation(double value)
349 {
350 state->targetPositionAngle = value;
351 }
352
353 SequenceJobState::CalibrationStage getCalibrationStage() const
354 {
355 return state->calibrationStage;
356 }
357 void setCalibrationStage(SequenceJobState::CalibrationStage value)
358 {
359 state->calibrationStage = value;
360 }
361
362 SequenceJobState::PreparationState getPreparationState() const
363 {
364 return state->m_PreparationState;
365 }
366 void setPreparationState(SequenceJobState::PreparationState value)
367 {
368 state->m_PreparationState = value;
369 }
370
371 bool getAutoFocusReady() const
372 {
373 return state->autoFocusReady;
374 }
375 void setAutoFocusReady(bool value)
376 {
377 state->autoFocusReady = value;
378 }
379
380 /**
381 * @brief Central entry point to start all activities that are necessary
382 * before capturing may start. Signals {@see prepareComplete()} as soon as
383 * everything is ready.
384 */
385 void prepareCapture();
386 /**
387 * @brief processPrepareComplete All preparations necessary for capturing are completed
388 * @param success true iff preparation succeeded
389 */
390 void processPrepareComplete(bool success = true);
391 /**
392 * @brief Abort capturing
393 */
394 void processAbortCapture();
395
396 /**
397 * @brief Check if all initial tasks are completed so that capturing
398 * of flats may start.
399 * @return IPS_OK if cap is closed, IPS_BUSY if not and IPS_ALERT if the
400 * process should be aborted.
401 */
402 IPState checkFlatFramePendingTasksCompleted();
403
404 // current values
405 double currentTemperature() const;
406 double currentGain() const;
407 double currentOffset() const;
408
409 void saveTo(QTextStream &outstream, const QLocale &cLocale) const;
410 void loadFrom(XMLEle *root, const QString &targetName, SequenceJobType jobType);
411
412 signals:
413 // All preparations necessary for capturing are completed
414 void prepareComplete(bool success = true);
415 // Manage the result when capturing has been started
416 void captureStarted(CaptureResult rc);
417 // Abort capturing
418 void abortCapture();
419 // log entry
420 void newLog(QString);
421
422 void prepareState(CaptureState state);
423 // signals to be forwarded to the state machine
424 void prepareCapture(CCDFrameType frameType, bool enforceCCDTemp, bool enforceStartGuiderDrift, bool isPreview);
425 // update the current guiding deviation
426 void updateGuiderDrift(double deviation_rms);
427
428private:
429 /**
430 * @brief init Initialize the sequence job from its XML representation
431 */
432 void init(SequenceJobType jobType, XMLEle *root, QSharedPointer<CameraState> sharedState, const QString &targetName);
433
434 // job type (batch, preview, ...)
435 SequenceJobType m_jobType;
436
437 void setStatus(JOBStatus const);
438
439 //////////////////////////////////////////////////////////////
440 /// Custom Types
441 /// We save all core sequence properties in QVariant map
442 //////////////////////////////////////////////////////////////
443 QMap<PropertyID, QVariant> m_CoreProperties;
444
445 //////////////////////////////////////////////////////////////
446 /// Custom Types
447 /// We don't use Q_PROPERTY for these to simplify use
448 //////////////////////////////////////////////////////////////
449 QMap<QString, QMap<QString, QVariant>> m_CustomProperties;
450 FlatFieldDuration m_FlatFieldDuration { DURATION_MANUAL };
451 // Capture Scripts
453 // Upload Mode
454 ISD::Camera::UploadMode m_UploadMode { ISD::Camera::UPLOAD_CLIENT };
455 // Transfer Format
456 QString m_TransferFormat { "FITS" };
457
458 //////////////////////////////////////////////////////////////
459 /// Status Variables
460 //////////////////////////////////////////////////////////////
461 int m_CaptureRetires { 0 };
462 uint32_t m_Completed { 0 };
463 double m_ExposeLeft { 0 };
464 bool m_JobProgressIgnored {false};
465
466 //////////////////////////////////////////////////////////////
467 /// Device access
468 //////////////////////////////////////////////////////////////
469
470 /**
471 * @brief frameTypes Retrieve the frame types from the active camera's primary chip.
472 */
473 QStringList frameTypes() const;
474 /**
475 * @brief filterLabels list of currently available filter labels
476 */
477 QStringList filterLabels() const;
478 /**
479 * @brief setCameraProperties Set all camera device properties required for capturing
480 */
481 QString setCameraDeviceProperties();
482
483 //////////////////////////////////////////////////////////////
484 /// State machines encapsulating the state of this capture sequence job
485 //////////////////////////////////////////////////////////////
488};
489
490}
Class handles control of INDI dome devices.
Definition indidome.h:25
Handles operation of a remotely controlled dust cover cap.
Definition indidustcap.h:25
Handles operation of a remotely controlled light box.
device handle controlling Mounts.
Definition indimount.h:29
Sequence Job is a container for the details required to capture a series of images.
The sky coordinates of a point in the sky.
Definition skypoint.h:45
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
Q_OBJECTQ_OBJECT
QString & remove(QChar ch, Qt::CaseSensitivity cs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:53:01 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.