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

KDE's Doxygen guidelines are available online.