Kstars

filtermanager.h
1 /*
2  SPDX-FileCopyrightText: 2017 Jasem Mutlaq <[email protected]>
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 
12 #include <indi/indifilterwheel.h>
13 #include <indi/indifocuser.h>
14 #include <oal/filter.h>
15 
16 #include <QDialog>
17 #include <QSqlDatabase>
18 #include <QQueue>
19 #include <QPointer>
20 
21 class QSqlTableModel;
22 class LockDelegate;
23 class NotEditableDelegate;
24 class ExposureDelegate;
25 class OffsetDelegate;
26 class UseAutoFocusDelegate;
27 
28 namespace Ekos
29 {
30 
31 class FilterManager : public QDialog, public Ui::FilterSettings
32 {
33  Q_OBJECT
34  public:
35 
36  typedef enum
37  {
38  CHANGE_POLICY = 1 << 0,
39  OFFSET_POLICY = 1 << 1,
40  AUTOFOCUS_POLICY = 1 << 2,
41  ALL_POLICIES = CHANGE_POLICY | OFFSET_POLICY | AUTOFOCUS_POLICY,
42  NO_AUTOFOCUS_POLICY = CHANGE_POLICY | OFFSET_POLICY
43  } FilterPolicy;
44 
45  enum
46  {
47  FM_LABEL = 4,
48  FM_EXPOSURE,
49  FM_OFFSET,
50  FM_AUTO_FOCUS,
51  FM_LOCK_FILTER,
52  FM_FLAT_FOCUS
53  };
54 
55  FilterManager();
56 
57  QJsonObject toJSON();
58  void setFilterData(const QJsonObject &settings);
59 
60  void refreshFilterModel();
61 
62  QStringList getFilterLabels(bool forceRefresh = false);
63 
64  int getFilterPosition(bool forceRefresh = false);
65 
66  // The target position and offset
67  int getTargetFilterPosition()
68  {
69  return targetFilterPosition;
70  }
71  int getTargetFilterOffset()
72  {
73  return targetFilterOffset;
74  }
75 
76  bool setFilterAbsoluteFocusPosition(int index, int absFocusPos);
77 
78  // Set absolute focus position, if supported, to the current filter absolute focus position.
79  bool syncAbsoluteFocusPosition(int index);
80 
81  /**
82  * @brief getFilterExposure Get optimal exposure time for the specified filter
83  * @param name filter to obtain exposure time for
84  * @return exposure time in seconds.
85  */
86  double getFilterExposure(const QString &name = QString()) const;
87  bool setFilterExposure(int index, double exposure);
88 
89  /**
90  * @brief getFilterLock Return filter that should be used when running autofocus for the supplied filter
91  * For example, "Red" filter can be locked to use "Lum" when doing autofocus. "Green" filter can be locked to "--"
92  * which means that no filter change is necessary.
93  * @param name filter which we need to query its locked filter.
94  * @return locked filter. "--" indicates no locked filter and whatever current filter should be used.
95  *
96  */
97  QString getFilterLock(const QString &name) const;
98  bool setFilterLock(int index, QString name);
99 
100  /**
101  * @brief setCurrentFilterWheel Set the FilterManager active filter wheel.
102  * @param filter pointer to filter wheel device
103  */
104  void setCurrentFilterWheel(ISD::FilterWheel *filter);
105 
106  /**
107  * @brief setFocusReady Set whether a focuser device is active and in use.
108  * @param enabled true if focus is ready, false otherwise.
109  */
110  void setFocusReady(bool enabled)
111  {
112  m_FocusReady = enabled;
113  }
114 
115 
116  /**
117  * @brief applyFilterFocusPolicies Check if we need to apply any filter policies for focus operations.
118  */
119  void applyFilterFocusPolicies();
120 
121  public slots:
122  // Position. if applyPolicy is true then all filter offsets and autofocus & lock policies are applied.
123  bool setFilterPosition(uint8_t position, Ekos::FilterManager::FilterPolicy policy = ALL_POLICIES);
124  // Change filter names
125  bool setFilterNames(const QStringList &newLabels);
126  // Offset Request completed
127  void setFocusOffsetComplete();
128  // Remove Device
129  void removeDevice(ISD::GenericDevice *device);
130  // Refresh Filters after model update
131  void reloadFilters();
132  // Focus Status
133  void setFocusStatus(Ekos::FocusState focusState);
134  // Set absolute focus position
135  void setFocusAbsolutePosition(int value)
136  {
137  m_FocusAbsPosition = value;
138  }
139  // Inti filter property after connection
140  void initFilterProperties();
141 
142  signals:
143  // Emitted only when there is a change in the filter slot number
144  void positionChanged(int);
145  // Emitted when filter change operation completed successfully including any focus offsets or auto-focus operation
146  void labelsChanged(QStringList);
147  // Emitted when filter exposure duration changes
148  void exposureChanged(double);
149  // Emitted when filter change completed including all required actions
150  void ready();
151  // Emitted when operation fails
152  void failed();
153  // Status signal
154  void newStatus(Ekos::FilterState state);
155  // Check Focus
156  void checkFocus(double);
157  // New Focus offset requested
158  void newFocusOffset(int value, bool useAbsoluteOffset);
159 
160  private slots:
161  void processText(ITextVectorProperty *tvp);
162  void processNumber(INumberVectorProperty *nvp);
163  void processSwitch(ISwitchVectorProperty *svp);
164 
165  private:
166 
167  // Filter Wheel Devices
168  ISD::FilterWheel *m_FilterWheel = { nullptr };
169 
170  // Position and Labels
171  QStringList m_currentFilterLabels;
172  int m_currentFilterPosition = { -1 };
173  double m_currentFilterExposure = { -1 };
174 
175  // Filter Structure
176  QList<OAL::Filter *> m_ActiveFilters;
177  OAL::Filter *targetFilter = { nullptr };
178  OAL::Filter *currentFilter = { nullptr };
179  bool m_useTargetFilter = { false };
180 
181  // Autofocus retries
182  uint8_t retries = { 0 };
183 
184  int16_t lastFilterOffset { 0 };
185 
186  // Table model
187  QSqlTableModel *filterModel = { nullptr };
188 
189  // INDI Properties of current active filter
190  ITextVectorProperty *m_FilterNameProperty { nullptr };
191  INumberVectorProperty *m_FilterPositionProperty { nullptr };
192  ISwitchVectorProperty *m_FilterConfirmSet { nullptr };
193 
194  // Operation stack
195  void buildOperationQueue(FilterState operation);
196  bool executeOperationQueue();
197  bool executeOneOperation(FilterState operation);
198 
199  // Update model
200  void syncDBToINDI();
201 
202  // Operation Queue
203  QQueue<FilterState> operationQueue;
204 
205  FilterState state = { FILTER_IDLE };
206 
207  int targetFilterPosition { -1 };
208  int targetFilterOffset { - 1 };
209 
210 
211  bool m_FocusReady { false };
212  bool m_FocusAbsPositionPending { false};
213  int m_FocusAbsPosition { -1 };
214 
215  // Delegates
216  QPointer<LockDelegate> lockDelegate;
217  QPointer<NotEditableDelegate> noEditDelegate;
218  QPointer<ExposureDelegate> exposureDelegate;
219  QPointer<OffsetDelegate> offsetDelegate;
220  QPointer<UseAutoFocusDelegate> useAutoFocusDelegate;
221 
222  // Policies
223  FilterPolicy m_Policy = { ALL_POLICIES };
224 
225  bool m_ConfirmationPending { false };
226 };
227 
228 }
Q_OBJECTQ_OBJECT
Ekos is an advanced Astrophotography tool for Linux. It is based on a modular extensible framework to...
Definition: align.cpp:70
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.