Kstars

filtermanager.h
1/*
2 SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "ui_filtersettings.h"
10#include "ekos/ekos.h"
11#include "ekos/focus/focusutils.h"
12
13#include <indi/indifilterwheel.h>
14#include <indi/indifocuser.h>
15#include <oal/filter.h>
16
17#include <QQueue>
18#include <QPointer>
19#include <QStandardItemModel>
20
21class QSqlTableModel;
22class ComboDelegate;
23class NotEditableDelegate;
24class NotEditableDelegate2dp;
25class DoubleDelegate;
26class IntegerDelegate;
27class ToggleDelegate;
28class DatetimeDelegate;
29
30namespace Ekos
31{
32
33class FilterManager : public QDialog, public Ui::FilterSettings
34{
36
37 // BuildFilterOffsets is a friend class so it can access methods in FilterManager
38 friend class BuildFilterOffsets;
39
40 public:
41
42 typedef enum
43 {
44 CHANGE_POLICY = 1 << 0,
45 OFFSET_POLICY = 1 << 1,
46 AUTOFOCUS_POLICY = 1 << 2,
47 ALL_POLICIES = CHANGE_POLICY | OFFSET_POLICY | AUTOFOCUS_POLICY,
48 NO_AUTOFOCUS_POLICY = CHANGE_POLICY | OFFSET_POLICY
49 } FilterPolicy;
50
51 enum
52 {
53 FM_LABEL = 4,
54 FM_EXPOSURE,
55 FM_OFFSET,
56 FM_AUTO_FOCUS,
57 FM_LOCK_FILTER,
58 FM_LAST_AF_SOLUTION,
59 FM_LAST_AF_TEMP,
60 FM_LAST_AF_ALT,
61 FM_LAST_AF_DATETIME,
62 FM_TICKS_PER_TEMP,
63 FM_TICKS_PER_ALT,
64 FM_WAVELENGTH
65 };
66
67 FilterManager(QWidget *parent = nullptr);
68
69 QJsonObject toJSON();
70 void setFilterData(const QJsonObject &settings);
71
72 void createFilterModel();
73 void refreshFilterModel();
74
75 QStringList getFilterLabels(bool forceRefresh = false);
76 int getFilterPosition(bool forceRefresh = false);
77 /**
78 * @brief refreshFilterLabels Update the filter labels from the device and signal changes.
79 */
80 void refreshFilterLabels();
81 /**
82 * @brief refreshFilterPos Update the filter wheel position and signal changes.
83 */
84 void refreshFilterPosition();
85
86 // The target position and offset
87 int getTargetFilterPosition()
88 {
89 return targetFilterPosition;
90 }
91 int getTargetFilterOffset()
92 {
93 return targetFilterOffset;
94 }
95
96 /**
97 * @brief setFilterAbsoluteFocusDetails set params from successful autofocus run
98 * @param index filter index
99 * @param focusPos the position of the focus solution
100 * @param focusTemp the temperature at the time of the focus run
101 * @param focusAlt the altitude at the time of the focus run
102 * @return whether function worked or not
103 */
104 bool setFilterAbsoluteFocusDetails(int index, int focusPos, double focusTemp, double focusAlt);
105
106 /**
107 * @brief getFilterAbsoluteFocusDetails get params from the last successful autofocus run
108 * @param name filter name
109 * @param focusPos the position of the focus solution
110 * @param focusTemp the temperature at the time of the focus run
111 * @param focusAlt the altitude at the time of the focus run
112 * @return whether function worked or not
113 */
114 bool getFilterAbsoluteFocusDetails(const QString &name, int &focusPos, double &focusTemp, double &focusAlt) const;
115
116 /**
117 * @brief getAFDatetime get timestamp of the last successful autofocus run
118 * @param name filter name
119 * @param datetime
120 * @return whether function worked or not
121 */
122 bool getAFDatetime(const QString &name, QDateTime &datetime) const;
123
124 // Set absolute focus position, if supported, to the current filter absolute focus position.
125 bool syncAbsoluteFocusPosition(int index);
126
127 /**
128 * @brief getFilterExposure Get optimal exposure time for the specified filter
129 * @param name filter to obtain exposure time for
130 * @return exposure time in seconds.
131 */
132 double getFilterExposure(const QString &name = QString()) const;
133 bool setFilterExposure(int index, double exposure);
134
135 /**
136 * @brief getFilterOffset returns the offset for the specified filter
137 * @param name of the filter
138 * @return filter offset (INVALID_VALUE in the case of a problem)
139 */
140 int getFilterOffset(const QString &name) const;
141
142 /**
143 * @brief setFilterOffset set the offset for the specified filter
144 * @param color of the filter
145 * @param the new filter offset
146 * @return whether or not the operation was successful
147 */
148 bool setFilterOffset(QString color, int offset);
149
150 /**
151 * @brief getFilterWavelength Get mid-point wavelength for the specified filter
152 * @param name filter to obtain exposure time for
153 * @return wavelength in nm.
154 */
155 int getFilterWavelength(const QString &name = QString()) const;
156
157 /**
158 * @brief getFilterTicksPerTemp gets the ticks per degree C
159 * @param name filter to obtain exposure time for
160 * @return ticks / degree C
161 */
162 double getFilterTicksPerTemp(const QString &name = QString()) const;
163
164 /**
165 * @brief getFilterTicksPerAlt gets the ticks per degree of altitude
166 * @param name filter to obtain exposure time for
167 * @return ticks / degree Alt
168 */
169 double getFilterTicksPerAlt(const QString &name = QString()) const;
170
171 /**
172 * @brief getFilterLock Return filter that should be used when running autofocus for the supplied filter
173 * For example, "Red" filter can be locked to use "Lum" when doing autofocus. "Green" filter can be locked to "--"
174 * which means that no filter change is necessary.
175 * @param name filter which we need to query its locked filter.
176 * @return locked filter. "--" indicates no locked filter and whatever current filter should be used.
177 *
178 */
179 QString getFilterLock(const QString &name) const;
180 bool setFilterLock(int index, QString name);
181
182 /**
183 * @brief setCurrentFilterWheel Set the FilterManager active filter wheel.
184 * @param filter pointer to filter wheel device
185 */
186 void setFilterWheel(ISD::FilterWheel *filter);
187 ISD::FilterWheel *filterWheel() const
188 {
189 return m_FilterWheel;
190 }
191
192 /**
193 * @brief setFocusReady Set whether a focuser device is active and in use.
194 * @param enabled true if focus is ready, false otherwise.
195 */
196 void setFocusReady(bool enabled)
197 {
198 m_FocusReady = enabled;
199 }
200
201
202 /**
203 * @brief applyFilterFocusPolicies Check if we need to apply any filter policies for focus operations.
204 */
205 void applyFilterFocusPolicies();
206
207 /**
208 * @brief buildFilterOffsets Launch the Build Filter Offsets utility
209 * @param FM pointer to the FilterManager
210 */
211 void buildFilterOffsets();
212
213 public slots:
214 // Position. if applyPolicy is true then all filter offsets and autofocus & lock policies are applied.
215 bool setFilterPosition(uint8_t position, Ekos::FilterManager::FilterPolicy policy = ALL_POLICIES);
216 // Change filter names
217 bool setFilterNames(const QStringList &newLabels);
218 // Offset Request completed
219 void setFocusOffsetComplete();
220 // Remove Device
221 void removeDevice(const QSharedPointer<ISD::GenericDevice> &device);
222 // Refresh Filters after model update
223 void reloadFilters();
224 // Resize the dialog to the contents
225 void resizeDialog();
226 // Focus Status
227 void setFocusStatus(Ekos::FocusState focusState);
228 // Set absolute focus position
229 void setFocusAbsolutePosition(int value)
230 {
231 m_FocusAbsPosition = value;
232 }
233 // Inti filter property after connection
234 void refreshFilterProperties();
235 // Signal from BuildFilterOffsets to run Autofocus. Pass onto Focus
236 void signalRunAutoFocus(AutofocusReason autofocusReason, const QString &reasonInfo);
237 // Signal from BuildFilterOffsets to abort AF run. Pass onto Focus
238 void signalAbortAutoFocus();
239 // Signal from Focus that Autofocus has completed - used by BuildFilterOffsets utility
240 void autoFocusComplete(FocusState completionState, int currentPosition, double currentTemperature, double currentAlt);
241
242 signals:
243 // Emitted only when there is a change in the filter slot number
244 void positionChanged(int);
245 // Emitted when filter change operation completed successfully including any focus offsets or auto-focus operation
246 void labelsChanged(QStringList);
247 // Emitted when filter exposure duration changes
248 void exposureChanged(double);
249 // Emitted when filter change completed including all required actions
250 void ready();
251 // Emitted when operation fails
252 void failed();
253 // Status signal
254 void newStatus(Ekos::FilterState state);
255 // Run AutoFocus
256 void runAutoFocus(AutofocusReason autofocusReason, const QString &reasonInfo);
257 // Abort AutoFocus
258 void abortAutoFocus();
259 // New Focus offset requested
260 void newFocusOffset(int value, bool useAbsoluteOffset);
261 // database was updated
262 void updated();
263 // Filter ticks per degree of temperature changed
264 void ticksPerTempChanged();
265 // Filter ticks per degree of altitude changed
266 void ticksPerAltChanged();
267 // Filter wavelength changed
268 void wavelengthChanged();
269 // Pass on Autofocus completed signal to Build Filter Offsets
270 void autoFocusDone(FocusState completionState, int currentPosition, double currentTemperature, double currentAlt);
271
272 private slots:
273 void updateProperty(INDI::Property prop);
274 void processDisconnect();
275
276 private:
277
278 // Filter Wheel Devices
279 ISD::FilterWheel *m_FilterWheel = { nullptr };
280
281 // Position and Labels
282 QStringList m_currentFilterLabels;
283 int m_currentFilterPosition = { -1 };
284 double m_currentFilterExposure = { -1 };
285
286 // Filter Structure
287 QList<OAL::Filter *> m_ActiveFilters;
288 OAL::Filter *targetFilter = { nullptr };
289 OAL::Filter *currentFilter = { nullptr };
290 bool m_useTargetFilter = { false };
291
292 // Autofocus retries
293 uint8_t retries = { 0 };
294
295 int16_t lastFilterOffset { 0 };
296
297 // Table model
298 QSqlTableModel *m_FilterModel = { nullptr };
299
300 // INDI Properties of current active filter
301 ITextVectorProperty *m_FilterNameProperty { nullptr };
302 INumberVectorProperty *m_FilterPositionProperty { nullptr };
303 ISwitchVectorProperty *m_FilterConfirmSet { nullptr };
304
305 // Accessor function to return filter pointer for the passed in name.
306 // nullptr is returned if there isn't a match
307 OAL::Filter * getFilterByName(const QString &name) const;
308
309 // Operation stack
310 void buildOperationQueue(FilterState operation);
311 bool executeOperationQueue();
312 bool executeOneOperation(FilterState operation);
313
314 // Check Filter Change timeout
315 void checkFilterChangeTimeout();
316
317 // Update model
318 void syncDBToINDI();
319
320 // Get the list of possible lock filters to set in the combo box.
321 // The list excludes filters already setup with a lock to prevent nested dependencies
322 QStringList getLockDelegates();
323
324 // Operation Queue
325 QQueue<FilterState> operationQueue;
326
327 FilterState state = { FILTER_IDLE };
328
329 int targetFilterPosition { -1 };
330 int targetFilterOffset { - 1 };
331 QTimer m_FilterChangeTimeout;
332
333 bool m_FocusReady { false };
334 bool m_FocusAbsPositionPending { false};
335 int m_FocusAbsPosition { -1 };
336
337 // Delegates
338 QPointer<ComboDelegate> lockDelegate;
339 QPointer<NotEditableDelegate> noEditDelegate;
340 QPointer<DoubleDelegate> exposureDelegate;
341 QPointer<IntegerDelegate> offsetDelegate;
342 QPointer<ToggleDelegate> useAutoFocusDelegate;
343 QPointer<IntegerDelegate> lastAFSolutionDelegate;
344 QPointer<DoubleDelegate> lastAFTempDelegate;
345 QPointer<DoubleDelegate> lastAFAltDelegate;
346 QPointer<DatetimeDelegate> lastAFDTDelegate;
347 QPointer<DoubleDelegate> ticksPerTempDelegate;
348 QPointer<DoubleDelegate> ticksPerAltDelegate;
349 QPointer<IntegerDelegate> wavelengthDelegate;
350
351 // Policies
352 FilterPolicy m_Policy = { ALL_POLICIES };
353
354 bool m_ConfirmationPending { false };
355};
356
357}
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
Q_OBJECTQ_OBJECT
QObject * parent() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 28 2025 11:55:59 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.