Kstars

scheduler.h
1/*
2 SPDX-FileCopyrightText: 2015 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 DBus calls from GSoC 2015 Ekos Scheduler project:
5 SPDX-FileCopyrightText: 2015 Daniel Leu <daniel_mihai.leu@cti.pub.ro>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "ui_scheduler.h"
13#include "opsoffsetsettings.h"
14#include "opsalignmentsettings.h"
15#include "opsjobssettings.h"
16#include "opscleanupsettings.h"
17#include "schedulertypes.h"
18#include "ekos/align/align.h"
19#include "indi/indiweather.h"
20#include "schedulerjob.h"
21
22#include <lilxml.h>
23
24#include <QTime>
25#include <QTimer>
26#include <QUrl>
27#include <QtDBus/QDBusInterface>
28
29#include <cstdint>
30
32
33class GeoLocation;
34class SkyObject;
35class KConfigDialog;
36class TestSchedulerUnit;
37class SolverUtils;
38class TestEkosSchedulerOps;
39
40namespace Ekos
41{
42
43class SequenceJob;
44class GreedyScheduler;
45class SchedulerProcess;
46class SchedulerModuleState;
47class SequenceEditor;
48class SchedulerAltitudeGraph;
49
50/**
51 * @brief The Ekos scheduler is a simple scheduler class to orchestrate automated multi object observation jobs.
52 * @author Jasem Mutlaq
53 * @version 1.2
54 */
55class Scheduler : public QWidget, public Ui::Scheduler
56{
58
59 friend class FramingAssistantUI;
60
61public:
62
63 /** @brief Columns, in the same order as UI. */
64 typedef enum
65 {
66 SCHEDCOL_NAME = 0,
67 SCHEDCOL_STATUS,
68 SCHEDCOL_CAPTURES,
69 SCHEDCOL_ALTITUDE,
70 SCHEDCOL_STARTTIME,
71 SCHEDCOL_ENDTIME,
73
74 /** @brief Constructor, the starndard scheduler constructor. */
75 Scheduler();
76 /** @brief DebugConstructor, a constructor used in testing with a mock ekos. */
77 Scheduler(const QString path, const QString interface,
78 const QString &ekosPathStr, const QString &ekosInterfaceStr);
79 ~Scheduler() = default;
80
81 QString getCurrentJobName();
82
83 // shortcut
84 SchedulerJob *activeJob();
85
86 /**
87 * @brief handleConfigChanged Update UI after changes to the global configuration
88 */
90
91 void addObject(SkyObject *object);
92
93 /**
94 * @brief importMosaic Import mosaic into planner and generate jobs for the scheduler.
95 * @param payload metadata for the mosaic information.
96 * @note Only Telescopius.com mosaic format is now supported.
97 */
98 bool importMosaic(const QJsonObject &payload);
99
100 /** @defgroup SchedulerDBusInterface Ekos DBus Interface - Scheduler Module
101 * Ekos::Align interface provides primary functions to run and stop the scheduler.
102 */
103
104 /*@{*/
105
106 /**
107 * @brief Set the file URL pointing to the capture sequence file
108 * @param sequenceFileURL URL of the capture sequence file
109 */
110 void setSequence(const QString &sequenceFileURL);
111
112 /**
113 * @brief prepareGUI Perform once only GUI prep processing
114 */
115 void prepareGUI();
116
117 // Settings popup
118 OpsOffsetSettings *m_OpsOffsetSettings { nullptr };
119 OpsAlignmentSettings *m_OpsAlignmentSettings { nullptr };
120 OpsJobsSettings *m_OpsJobsSettings { nullptr };
121 OpsCleanupSettings *m_OpsCleanupSettings { nullptr };
122
123
124 /** DBUS interface function.
125 * @brief Resets all jobs to IDLE
126 */
127 Q_SCRIPTABLE void sortJobsPerAltitude();
128
129 void setProfile(const QString &profile)
130 {
131 schedulerProfileCombo->setCurrentText(profile);
132 }
133 QString profile()
134 {
135 return schedulerProfileCombo->currentText();
136 }
137
138 /**
139 * @brief retrieve the error handling strategy from the UI
140 */
142
143 /**
144 * @brief select the error handling strategy (no restart, restart after all terminated, restart immediately)
145 */
147
148 /** @}*/
149
150 // TODO: This section of static public and private methods should someday
151 // be moved from Scheduler and placed in a separate class,
152 // e.g. SchedulerPlanner or SchedulerJobEval
153 /**
154 * @brief Remove a job from current table row.
155 * @param index
156 */
157 void removeJob();
158
159 /**
160 * @brief Remove a job by selecting a table row.
161 * @param index
162 */
163 void removeOneJob(int index);
164
165 /**
166 * @brief addJob Add a new job from form values
167 */
168 Q_INVOKABLE void addJob(SchedulerJob *job = nullptr);
169 /**
170 * @brief addJob Add a new job from form values
171 */
172 Q_INVOKABLE void updateJob(int index = -1);
173
174 /**
175 * @brief createJob Create a new job from form values.
176 * @param job job to be filled from UI values
177 * @return true iff update was successful
178 */
179 bool fillJobFromUI(SchedulerJob *job);
180
181 /**
182 * @brief addToQueue Construct a SchedulerJob and add it to the queue or save job settings from current form values.
183 * jobUnderEdit determines whether to add or edit
184 */
185 void saveJob(SchedulerJob *job = nullptr);
186
187 void toggleScheduler();
188
189 QJsonObject getSchedulerSettings();
190
191 // the state machine
192 QSharedPointer<SchedulerModuleState> moduleState() const
193 {
194 return m_moduleState;
195 }
196 // the process engine
198 {
199 return m_process;
200 }
201
202 /**
203 * @brief saveFile Save scheduler jobs to disk
204 * @param path Path to esl file to save jobs to
205 * @return True if successful, false otherwise
206 */
207 bool saveFile(const QUrl &path);
208
209 /**
210 * @brief loadFile Load scheduler jobs from disk
211 * @param path Oath to esl file to load jobs from
212 * @return True if successful, false otherwise
213 */
214 bool loadFile(const QUrl &path);
215
216 // Settings
217 QVariantMap getAllSettings() const;
218 void setAllSettings(const QVariantMap &settings);
219
220private:
221
222 void setAlgorithm(int alg);
223
224 friend TestSchedulerUnit;
225
226 // TODO: See above TODO. End of static methods that might be moved to
227 // a separate Scheduler-related class.
228
229 /*@{*/
230 /** @internal Safeguard flag to avoid registering signals from widgets multiple times.
231 */
232 bool jobChangesAreWatched { false };
233
234protected:
235
236 /** @internal Enables signal watch on SchedulerJob form values in order to apply changes to current job.
237 * @param enable is the toggle flag, true to watch for changes, false to ignore them.
238 */
239 void watchJobChanges(bool enable);
240
241 /** @internal Marks the currently selected SchedulerJob as modified change.
242 *
243 * This triggers job re-evaluation.
244 * Next time save button is invoked, the complete content is written to disk.
245 */
246 void setDirty();
247 /** @} */
248
249 /**
250 * @brief updateJobTable Update the job's row in the job table. If the row does not exist, it will
251 * be created on the fly. If job is null, update the entire table
252 * @param job
253 */
254 void updateJobTable(SchedulerJob *job = nullptr);
255
256 /**
257 * @brief insertJobTableRow Insert a new row (empty) into the job table
258 * @param row row number (starting with 0)
259 * @param above insert above the given row (=true) or below (=false)
260 */
261 void insertJobTableRow(int row, bool above = true);
262
263 /**
264 * @brief Update the style of a cell, depending on the job's state
265 */
266 void updateCellStyle(SchedulerJob *job, QTableWidgetItem *cell);
267
268protected slots:
269
270 /**
271 * @brief checkInterfaceReady Sometimes syncProperties() is not sufficient since the ready signal could have fired already
272 * and cannot be relied on to know once a module interface is ready. Therefore, we explicitly check if the module interface
273 * is ready.
274 * @param iface interface to test for readiness.
275 */
276 void interfaceReady(QDBusInterface *iface);
277
278 void setWeatherStatus(ISD::Weather::Status status);
279
280 /**
281 * @brief select object from KStars's find dialog.
282 */
283 void selectObject();
284
285 /**
286 * @brief Selects FITS file for solving.
287 */
288 void selectFITS();
289
290 /**
291 * @brief Selects sequence queue.
292 */
293 void selectSequence();
294
295 /**
296 * @brief Selects sequence queue.
297 */
298 void selectStartupScript();
299
300 /**
301 * @brief Selects sequence queue.
302 */
304
305 /**
306 * @brief editJob Edit an observation job
307 * @param i index model in queue table
308 */
310
311 Q_INVOKABLE bool modifyJob(int index = -1);
312
313 /**
314 * @brief updateSchedulerURL Update scheduler URL after succesful loading a new file.
315 */
316 void updateSchedulerURL(const QString &fileURL);
317
318 /**
319 * @brief setJobAddApply Set first button state to add new job or apply changes.
320 */
321 void setJobAddApply(bool add_mode);
322
323 /**
324 * @brief setJobManipulation Enable or disable job manipulation buttons.
325 */
326 void setJobManipulation(bool can_reorder, bool can_delete, bool is_lead);
327
328 /**
329 * @brief set all GUI fields to the values of the given scheduler job
330 */
331 void syncGUIToJob(SchedulerJob *job);
332
333 /**
334 * @brief syncGUIToGeneralSettings set all UI fields that are not job specific
335 */
337
338 /**
339 * @brief jobSelectionChanged Update UI state when the job list is clicked once.
340 */
341 void clickQueueTable(QModelIndex index);
342
343 /**
344 * @brief clearJobTable delete all rows in the job table
345 */
347
348 /**
349 * @brief clearLog Clears log entry
350 */
351 Q_INVOKABLE void clearLog();
352
353 /**
354 * @brief Update scheduler parameters to the currently selected scheduler job
355 * @param selected table position
356 * @param deselected table position
357 */
358 void queueTableSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
359
360 /**
361 * @brief reorderJobs Change the order of jobs in the UI based on a subset of its jobs.
362 */
363 bool reorderJobs(QList<SchedulerJob*> reordered_sublist);
364
365 /**
366 * @brief moveJobUp Move the selected job up in the job list.
367 */
368 void moveJobUp();
369
370 /**
371 * @brief moveJobDown Move the selected job down in the list.
372 */
373 void moveJobDown();
374
375 /**
376 * @brief handleSchedulerSleeping Update UI if scheduler is set to sleep
377 * @param shutdown flag if a preemptive shutdown is executed
378 * @param sleep flag if the scheduler will sleep
379 */
380 void handleSchedulerSleeping(bool shutdown, bool sleep);
381
382 /**
383 * @brief handleSchedulerStateChanged Update UI when the scheduler state changes
384 */
386
387 /**
388 * @brief handleSetPaused Update the UI when {@see #setPaused()} is called.
389 */
390 void handleSetPaused();
391
392 void pause();
393 bool save();
394 void saveAs();
395
396 /**
397 * @brief load Open a file dialog to select an ESL file, and load its contents.
398 * @param clearQueue Clear the queue before loading, or append ESL contents to queue.
399 * @param filename If not empty, this file will be used instead of poping up a dialog.
400 */
401 Q_INVOKABLE bool load(bool clearQueue, const QString &filename = QString());
402
403 Q_INVOKABLE void resetJobEdit();
404
405 /**
406 * @brief updateNightTime update the Twilight restriction with the argument job properties.
407 * @param job SchedulerJob for which to display the next dawn and dusk, or the job currently selected if null, or today's next dawn and dusk if no job is selected.
408 */
409 void updateNightTime(SchedulerJob const * job = nullptr);
410
411 /**
412 * @brief schedulerStopped React when the process engine has stopped the scheduler
413 */
414 void schedulerStopped();
415
416 /**
417 * @brief resumeCheckStatus If the scheduler primary loop was suspended due to weather or sleep event, resume it again.
418 */
419 void resumeCheckStatus();
420
421 /**
422 * @brief checkWeather Check weather status and act accordingly depending on the current status of the scheduler and running jobs.
423 */
424 //void checkWeather();
425
426 /**
427 * @brief displayTwilightWarning Display twilight warning to user if it is unchecked.
428 */
429 void checkTwilightWarning(bool enabled);
430
431signals:
432 void newStatus(Ekos::SchedulerState state);
433 void weatherChanged(ISD::Weather::Status state);
434 void newTarget(const QString &);
435 // distance in arc-seconds measured by plate solving the a captured image and
436 // comparing that position to the target position.
437 void targetDistance(double distance);
438 // Below 2 are for the Analyze timeline.
439 void jobStarted(const QString &jobName);
440 void jobEnded(const QString &jobName, const QString &endReason);
441 void jobsUpdated(QJsonArray jobsList);
442 void settingsUpdated(const QVariantMap &settings);
443
444private:
445 /**
446 * @brief handleJobsUpdated Update UI when jobs have been updated
447 * @param jobsList
448 */
449 void handleJobsUpdated(QJsonArray jobsList);
450
451 /**
452 * @brief handleShutdownStarted Show that the shutdown has been started.
453 */
454 void handleShutdownStarted();
455
456 /**
457 * @brief processFITSSelection When a FITS file is selected, open it and try to guess
458 * the object name, and its J2000 RA/DE to fill the UI with such info automatically.
459 */
460 void processFITSSelection(const QUrl &url);
461
462 /**
463 * @brief updateProfiles React upon changed profiles and update the UI
464 */
465 void updateProfiles();
466
467 /**
468 * @brief updateStageLabel Helper function that updates the stage label.
469 */
470 void updateJobStageUI(SchedulerJobStage stage);
471
472 ////////////////////////////////////////////////////////////////////
473 /// Settings
474 ////////////////////////////////////////////////////////////////////
475
476 /**
477 * @brief Connect GUI elements to sync settings once updated.
478 */
479 void connectSettings();
480 /**
481 * @brief Stop updating settings when GUI elements are updated.
482 */
483 void disconnectSettings();
484 /**
485 * @brief loadSettings Load setting from Options and set them accordingly.
486 */
487 void loadGlobalSettings();
488
489 /**
490 * @brief syncSettings When checkboxes, comboboxes, or spin boxes are updated, save their values in the
491 * global and per-train settings.
492 */
493 void syncSettings();
494
495 /**
496 * @brief syncControl Sync setting to widget. The value depends on the widget type.
497 * @param settings Map of all settings
498 * @param key name of widget to sync
499 * @param widget pointer of widget to set
500 * @return True if sync successful, false otherwise
501 */
502 bool syncControl(const QVariantMap &settings, const QString &key, QWidget * widget);
503
504 // ////////////////////////////////////////////////////////////////////
505 // Optical Train handling
506 // ////////////////////////////////////////////////////////////////////
507 void refreshOpticalTrain();
508
509 /**
510 * @brief checkJobInputComplete Check if all inputs are filled such that a new job could be added.
511 */
512 void checkJobInputComplete();
513
514 Ekos::Scheduler *ui { nullptr };
515
516 // Interface strings for the dbus. Changeable for mocks when testing. Private so only tests can change.
517 QString schedulerPathString { "/KStars/Ekos/Scheduler" };
518 QString kstarsInterfaceString { "org.kde.kstars" };
519 // This is only used in the constructor
520 QString ekosInterfaceString { "org.kde.kstars.Ekos" };
521 QString ekosPathString { "/KStars/Ekos" };
522
523 // the state machine holding all states
525 // process engine implementing all process steps
527
528 // react upon changes of EKOS and INDI state
529 void ekosStateChanged(EkosState state);
530 void indiStateChanged(INDIState state);
531 void indiCommunicationStatusChanged(CommunicationStatus status);
532
533 // react upon state changes
534 void startupStateChanged(StartupState state);
535 void shutdownStateChanged(ShutdownState state);
536 void parkWaitStateChanged(ParkWaitState state);
537
538 /// URL to store the scheduler file
539 QUrl schedulerURL;
540 /// URL for Ekos Sequence
541 QUrl sequenceURL;
542 /// FITS URL to solve
543 QUrl fitsURL;
544 /// Busy indicator widget
545 QProgressIndicator *pi { nullptr };
546 /// Are we editing a job right now? Job row index
547 int jobUnderEdit { -1 };
548 /// Pointer to Geographic location
549 GeoLocation *geo { nullptr };
550
551 /// Call checkWeather when weatherTimer time expires. It is equal to the UpdatePeriod time in INDI::Weather device.
552 //QTimer weatherTimer;
553
554 QUrl dirPath;
555
556 // update the sleep label and its visibility
557 void changeSleepLabel(QString text, bool show = true);
558 // Used by the constructor in testing mainly so a mock ekos could be used.
559 void setupScheduler(const QString &ekosPathStr, const QString &ekosInterfaceStr);
560
561
562 /// Target coordinates for pointing check
564
565 void syncGreedyParams();
566
567 friend TestEkosSchedulerOps;
568
569 QSharedPointer<SequenceEditor> m_SequenceEditor;
570
571 QTimer m_JobUpdateDebounce;
572 QVariantMap m_Settings;
573 QVariantMap m_GlobalSettings;
574
575 // Altitude Graph
576 QPointer<SchedulerAltitudeGraph> m_altitudeGraph;
577 void handleAltitudeGraph(int index);
578};
579}
The Ekos scheduler is a simple scheduler class to orchestrate automated multi object observation jobs...
Definition scheduler.h:56
ErrorHandlingStrategy getErrorHandlingStrategy()
retrieve the error handling strategy from the UI
void moveJobUp()
moveJobUp Move the selected job up in the job list.
void watchJobChanges(bool enable)
Q_INVOKABLE void clearLog()
clearLog Clears log entry
void checkTwilightWarning(bool enabled)
checkWeather Check weather status and act accordingly depending on the current status of the schedule...
void saveJob(SchedulerJob *job=nullptr)
addToQueue Construct a SchedulerJob and add it to the queue or save job settings from current form va...
void setJobManipulation(bool can_reorder, bool can_delete, bool is_lead)
setJobManipulation Enable or disable job manipulation buttons.
void updateSchedulerURL(const QString &fileURL)
updateSchedulerURL Update scheduler URL after succesful loading a new file.
Q_INVOKABLE void addJob(SchedulerJob *job=nullptr)
addJob Add a new job from form values
void selectSequence()
Selects sequence queue.
void insertJobTableRow(int row, bool above=true)
insertJobTableRow Insert a new row (empty) into the job table
Q_INVOKABLE bool load(bool clearQueue, const QString &filename=QString())
load Open a file dialog to select an ESL file, and load its contents.
void resumeCheckStatus()
resumeCheckStatus If the scheduler primary loop was suspended due to weather or sleep event,...
void handleSchedulerSleeping(bool shutdown, bool sleep)
handleSchedulerSleeping Update UI if scheduler is set to sleep
void prepareGUI()
prepareGUI Perform once only GUI prep processing
void moveJobDown()
moveJobDown Move the selected job down in the list.
bool importMosaic(const QJsonObject &payload)
importMosaic Import mosaic into planner and generate jobs for the scheduler.
void handleSetPaused()
handleSetPaused Update the UI when {
bool reorderJobs(QList< SchedulerJob * > reordered_sublist)
reorderJobs Change the order of jobs in the UI based on a subset of its jobs.
void syncGUIToGeneralSettings()
syncGUIToGeneralSettings set all UI fields that are not job specific
void updateNightTime(SchedulerJob const *job=nullptr)
updateNightTime update the Twilight restriction with the argument job properties.
bool loadFile(const QUrl &path)
loadFile Load scheduler jobs from disk
void handleSchedulerStateChanged(SchedulerState newState)
handleSchedulerStateChanged Update UI when the scheduler state changes
bool fillJobFromUI(SchedulerJob *job)
createJob Create a new job from form values.
Q_INVOKABLE void loadJob(QModelIndex i)
editJob Edit an observation job
void setSequence(const QString &sequenceFileURL)
Set the file URL pointing to the capture sequence file.
Q_INVOKABLE void updateJob(int index=-1)
addJob Add a new job from form values
void selectStartupScript()
Selects sequence queue.
void syncGUIToJob(SchedulerJob *job)
set all GUI fields to the values of the given scheduler job
void schedulerStopped()
schedulerStopped React when the process engine has stopped the scheduler
void selectObject()
select object from KStars's find dialog.
void updateCellStyle(SchedulerJob *job, QTableWidgetItem *cell)
Update the style of a cell, depending on the job's state.
Q_INVOKABLE void clearJobTable()
clearJobTable delete all rows in the job table
void setJobAddApply(bool add_mode)
setJobAddApply Set first button state to add new job or apply changes.
void handleConfigChanged()
handleConfigChanged Update UI after changes to the global configuration
bool saveFile(const QUrl &path)
saveFile Save scheduler jobs to disk
Q_SCRIPTABLE void sortJobsPerAltitude()
DBUS interface function.
void setErrorHandlingStrategy(ErrorHandlingStrategy strategy)
select the error handling strategy (no restart, restart after all terminated, restart immediately)
void clickQueueTable(QModelIndex index)
jobSelectionChanged Update UI state when the job list is clicked once.
void updateJobTable(SchedulerJob *job=nullptr)
updateJobTable Update the job's row in the job table.
void removeJob()
Remove a job from current table row.
void removeOneJob(int index)
Remove a job by selecting a table row.
void selectFITS()
Selects FITS file for solving.
Scheduler()
Constructor, the starndard scheduler constructor.
Definition scheduler.cpp:86
void interfaceReady(QDBusInterface *iface)
checkInterfaceReady Sometimes syncProperties() is not sufficient since the ready signal could have fi...
SchedulerColumns
Columns, in the same order as UI.
Definition scheduler.h:65
void queueTableSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Update scheduler parameters to the currently selected scheduler job.
void selectShutdownScript()
Selects sequence queue.
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
Definition geolocation.h:28
The QProgressIndicator class lets an application display a progress indicator to show that a long tas...
The SchedulerState class holds all attributes defining the scheduler's state.
Sequence Job is a container for the details required to capture a series of images.
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
ErrorHandlingStrategy
options what should happen if an error or abort occurs
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.