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

KDE's Doxygen guidelines are available online.