7#include "sequencequeue.h"
9#include <KNotifications/KNotification>
10#include <ekos_capture_debug.h>
12#include "camerastate.h"
13#include "capturedeviceadaptor.h"
14#include "ksnotification.h"
15#include "sequencejob.h"
18constexpr double SQ_FORMAT_VERSION = 2.6;
20constexpr double SQ_COMPAT_VERSION = 2.0;
25bool SequenceQueue::load(
const QString &fileURL,
const QString &targetName,
32 QString message =
i18n(
"Unable to open file %1", fileURL);
33 KSNotification::sorry(message,
i18n(
"Could Not Open File"));
37 LilXML * xmlParser = newLilXML();
40 XMLEle * root =
nullptr;
41 XMLEle * ep =
nullptr;
47 while (sFile.getChar(&c))
49 root = readXMLEle(xmlParser, c, errmsg);
53 double sqVersion = cLocale.
toDouble(findXMLAttValu(root,
"version"));
54 if (sqVersion < SQ_COMPAT_VERSION)
56 emit newLog(
i18n(
"Deprecated sequence file format version %1. Please construct a new sequence file.",
61 for (ep = nextXMLEle(root, 1); ep !=
nullptr; ep = nextXMLEle(root, 0))
63 if (!strcmp(tagXMLEle(ep),
"Observer"))
65 state->setObserverName(
QString(pcdataXMLEle(ep)));
67 else if (!strcmp(tagXMLEle(ep),
"GuideDeviation"))
69 m_GuideDeviationSet =
true;
70 m_EnforceGuideDeviation = !strcmp(findXMLAttValu(ep,
"enabled"),
"true");
71 m_GuideDeviation = cLocale.
toDouble(pcdataXMLEle(ep));
73 else if (!strcmp(tagXMLEle(ep),
"CCD"))
77 else if (!strcmp(tagXMLEle(ep),
"FilterWheel"))
81 else if (!strcmp(tagXMLEle(ep),
"GuideStartDeviation"))
83 m_GuideStartDeviationSet =
true;
84 m_EnforceStartGuiderDrift = !strcmp(findXMLAttValu(ep,
"enabled"),
"true");
85 m_StartGuideDeviation = cLocale.
toDouble(pcdataXMLEle(ep));
87 else if (!strcmp(tagXMLEle(ep),
"Autofocus"))
91 else if (!strcmp(tagXMLEle(ep),
"HFRCheck"))
93 m_AutofocusSet =
true;
94 m_EnforceAutofocusHFR = !strcmp(findXMLAttValu(ep,
"enabled"),
"true");
99 m_HFRCheckAlgorithm = HFR_CHECK_LAST_AUTOFOCUS;
100 m_HFRCheckThresholdPercentage = HFR_CHECK_DEFAULT_THRESHOLD;
101 m_HFRCheckFrames = 1;
103 for (epHFR = nextXMLEle(ep, 1); epHFR !=
nullptr; epHFR = nextXMLEle(ep, 0))
105 if (!strcmp(tagXMLEle(epHFR),
"HFRDeviation"))
107 double const HFRValue = cLocale.
toDouble(pcdataXMLEle(epHFR));
110 m_HFRDeviation = HFRValue;
113 if (!strcmp(tagXMLEle(epHFR),
"HFRCheckAlgorithm"))
115 int HFRCheckAlgo = cLocale.
toInt(pcdataXMLEle(epHFR));
117 if (HFRCheckAlgo >= 0 && HFRCheckAlgo < HFR_CHECK_MAX_ALGO)
118 m_HFRCheckAlgorithm =
static_cast<HFRCheckAlgorithm
>(HFRCheckAlgo);
120 else if (!strcmp(tagXMLEle(epHFR),
"HFRCheckThreshold"))
122 double const hFRCheckThreshold = cLocale.
toDouble(pcdataXMLEle(epHFR));
124 if (hFRCheckThreshold >= 0.0)
125 m_HFRCheckThresholdPercentage = hFRCheckThreshold;
127 else if (!strcmp(tagXMLEle(epHFR),
"HFRCheckFrames"))
129 int const hFRCheckFrames = cLocale.
toInt(pcdataXMLEle(epHFR));
131 if (hFRCheckFrames > 1)
132 m_HFRCheckFrames = hFRCheckFrames;
136 else if (!strcmp(tagXMLEle(ep),
"RefocusOnTemperatureDelta"))
138 m_RefocusOnTemperatureDeltaSet =
true;
139 m_EnforceAutofocusOnTemperature = !strcmp(findXMLAttValu(ep,
"enabled"),
"true");
140 double const deltaValue = cLocale.
toDouble(pcdataXMLEle(ep));
141 m_MaxFocusTemperatureDelta = deltaValue;
143 else if (!strcmp(tagXMLEle(ep),
"RefocusEveryN"))
145 m_RefocusEveryNSet =
true;
146 m_EnforceRefocusEveryN = !strcmp(findXMLAttValu(ep,
"enabled"),
"true");
147 int const minutesValue = cLocale.
toInt(pcdataXMLEle(ep));
149 m_RefocusEveryN = minutesValue > 0 ? minutesValue : 0;
151 else if (!strcmp(tagXMLEle(ep),
"RefocusOnMeridianFlip"))
153 m_RefocusOnMeridianFlipSet =
true;
154 m_RefocusAfterMeridianFlip = !strcmp(findXMLAttValu(ep,
"enabled"),
"true");
156 else if (!strcmp(tagXMLEle(ep),
"MeridianFlip"))
160 if (! strcmp(findXMLAttValu(ep,
"enabled"),
"true"))
162 i18n(
"Meridian flip configuration has been shifted to the mount module. Please configure the meridian flip there."));
166 auto job =
new SequenceJob(devices, state, SequenceJob::JOBTYPE_BATCH, ep, targetName);
175 delLilXML(xmlParser);
181 state->setDirty(
false);
182 delLilXML(xmlParser);
186void SequenceQueue::setOptions()
188 if (m_GuideDeviationSet)
190 Options::setEnforceGuideDeviation(m_EnforceGuideDeviation);
191 Options::setGuideDeviation(m_GuideDeviation);
193 if (m_GuideStartDeviationSet)
195 Options::setEnforceStartGuiderDrift(m_EnforceStartGuiderDrift);
196 Options::setStartGuideDeviation(m_StartGuideDeviation);
200 Options::setEnforceAutofocusHFR(m_EnforceAutofocusHFR);
201 Options::setHFRCheckAlgorithm(m_HFRCheckAlgorithm);
202 Options::setHFRThresholdPercentage(m_HFRCheckThresholdPercentage);
203 Options::setInSequenceCheckFrames(m_HFRCheckFrames);
204 Options::setHFRDeviation(m_HFRDeviation);
206 if (m_RefocusOnTemperatureDeltaSet)
208 Options::setEnforceAutofocusOnTemperature(m_EnforceAutofocusOnTemperature);
209 Options::setMaxFocusTemperatureDelta(m_MaxFocusTemperatureDelta);
211 if (m_RefocusEveryNSet)
213 Options::setEnforceRefocusEveryN(m_EnforceRefocusEveryN);
214 Options::setRefocusEveryN(m_RefocusEveryN);
216 if (m_RefocusOnMeridianFlipSet)
218 Options::setRefocusAfterMeridianFlip(m_RefocusAfterMeridianFlip);
222void SequenceQueue::loadOptions()
224 m_GuideDeviationSet =
true;
226 m_EnforceGuideDeviation = Options::enforceGuideDeviation();
227 m_GuideDeviation = Options::guideDeviation();
229 m_GuideStartDeviationSet =
true;
230 m_EnforceStartGuiderDrift = Options::enforceStartGuiderDrift();
231 m_StartGuideDeviation = Options::startGuideDeviation();
233 m_AutofocusSet =
true;
234 m_EnforceAutofocusHFR = Options::enforceAutofocusHFR();
235 m_HFRCheckAlgorithm =
static_cast<HFRCheckAlgorithm
>(Options::hFRCheckAlgorithm());
236 m_HFRCheckThresholdPercentage = Options::hFRThresholdPercentage();
237 m_HFRCheckFrames = Options::inSequenceCheckFrames();
238 m_HFRDeviation = Options::hFRDeviation();
240 m_RefocusOnTemperatureDeltaSet =
true;
241 m_EnforceAutofocusOnTemperature = Options::enforceAutofocusOnTemperature();
242 m_MaxFocusTemperatureDelta = Options::maxFocusTemperatureDelta();
244 m_RefocusEveryNSet =
true;
245 m_EnforceRefocusEveryN = Options::enforceRefocusEveryN();
246 m_RefocusEveryN = Options::refocusEveryN();
248 m_RefocusOnMeridianFlipSet =
true;
249 m_RefocusAfterMeridianFlip = Options::refocusAfterMeridianFlip();
252bool SequenceQueue::save(
const QString &path,
const QString &observerName)
259 QString message =
i18n(
"Unable to write to file %1", path);
260 KSNotification::sorry(message,
i18n(
"Could not open file"));
269 outstream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" <<
Qt::endl;
270 outstream <<
"<SequenceQueue version='" << SQ_FORMAT_VERSION <<
"'>" <<
Qt::endl;
271 if (observerName.
isEmpty() ==
false)
272 outstream <<
"<Observer>" << observerName <<
"</Observer>" <<
Qt::endl;
273 outstream <<
"<GuideDeviation enabled='" << (m_EnforceGuideDeviation ?
"true" :
"false") <<
"'>"
275 outstream <<
"<GuideStartDeviation enabled='" << (m_EnforceStartGuiderDrift ?
"true" :
"false") <<
"'>"
276 << cLocale.
toString(m_StartGuideDeviation) <<
"</GuideStartDeviation>" <<
Qt::endl;
277 outstream <<
"<HFRCheck enabled='" << (m_EnforceAutofocusHFR ?
"true" :
"false") <<
"'>" <<
Qt::endl;
278 outstream <<
"<HFRDeviation>" << cLocale.
toString(m_HFRDeviation) <<
"</HFRDeviation>" <<
Qt::endl;
279 outstream <<
"<HFRCheckAlgorithm>" << m_HFRCheckAlgorithm <<
"</HFRCheckAlgorithm>" <<
Qt::endl;
280 outstream <<
"<HFRCheckThreshold>" << cLocale.
toString(m_HFRCheckThresholdPercentage) <<
"</HFRCheckThreshold>" <<
Qt::endl;
281 outstream <<
"<HFRCheckFrames>" << cLocale.
toString(m_HFRCheckFrames) <<
"</HFRCheckFrames>" <<
Qt::endl;
282 outstream <<
"</HFRCheck>" <<
Qt::endl;
283 outstream <<
"<RefocusOnTemperatureDelta enabled='" << (m_EnforceAutofocusOnTemperature ?
"true" :
"false") <<
285 << cLocale.
toString(m_MaxFocusTemperatureDelta) <<
"</RefocusOnTemperatureDelta>" <<
Qt::endl;
286 outstream <<
"<RefocusEveryN enabled='" << (m_EnforceRefocusEveryN ?
"true" :
"false") <<
"'>"
288 outstream <<
"<RefocusOnMeridianFlip enabled='" << (m_RefocusAfterMeridianFlip ?
"true" :
"false") <<
"'/>"
291 for (
auto &job : m_allJobs)
293 job->saveTo(outstream, cLocale);
296 outstream <<
"</SequenceQueue>" <<
Qt::endl;
298 emit newLog(
i18n(
"Sequence queue saved to %1", path));
Sequence Job is a container for the details required to capture a series of images.
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
void setFileName(const QString &name)
virtual void close() override
void append(QList< T > &&value)
double toDouble(QStringView s, bool *ok) const const
int toInt(QStringView s, bool *ok) const const
QString toString(QDate date, FormatType format) const const
bool isEmpty() const const
QTextStream & endl(QTextStream &stream)
QUrl fromLocalFile(const QString &localFile)