Kstars

opticaltrainmanager.h
1/*
2 SPDX-FileCopyrightText: 2022 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "ui_opticaltrains.h"
10
11#include <indi/indifilterwheel.h>
12#include <indi/indifocuser.h>
13
14#include <QDialog>
15#include <QSqlDatabase>
16#include <QQueue>
17#include <QPointer>
18
19class QSqlTableModel;
20class ComboDelegate;
21class NotEditableDelegate;
22class DoubleDelegate;
23class IntegerDelegate;
24class ToggleDelegate;
25class ProfileInfo;
26
27namespace Ekos
28{
29
30class OpticalTrainManager : public QDialog, public Ui::OpticalTrain
31{
33 Q_PROPERTY(QStringList trainNames READ getTrainNames)
34
35 public:
36
37 static OpticalTrainManager *Instance();
38 static void release();
39
40 typedef enum
41 {
42 Mount,
43 Camera,
44 Rotator,
45 GuideVia,
46 DustCap,
47 Scope,
48 FilterWheel,
49 Focuser,
50 Reducer,
51 LightBox,
52 // Non-train specific
53 Dome,
54 Weather,
55 GPS
56 } Role;
57
58 void setProfile(const QSharedPointer<ProfileInfo> &profile);
59 void checkOpticalTrains();
60
61 bool exists(uint8_t id) const;
62 const QVariantMap getOpticalTrain(uint8_t id) const;
63 const QVariantMap getOpticalTrain(const QString &name) const;
64 const QList<QVariantMap> &getOpticalTrains() const
65 {
66 return m_OpticalTrains;
67 }
68 const QStringList &getTrainNames() const
69 {
70 return m_TrainNames;
71 }
72
73 void addOpticalTrain(const QJsonObject &value);
74
75 /**
76 * @brief Select an optical train and fill the field values in the train editor with the
77 * appropriate values of the selected optical train.
78 * @param item optical train list item
79 * @return true if optical train found
80 */
81 bool selectOpticalTrain(QListWidgetItem *item);
82
83 /**
84 * @brief findTrainContainingDevice Search optical trains for device match a specific role.
85 * @param name Device Name
86 * @param role Device Role
87 * @return Train containing device name matching the specified role
88 */
89 QString findTrainContainingDevice(const QString &name, Role role);
90
91 /**
92 * @brief Select an optical train and fill the field values in the train editor with the
93 * appropriate values of the selected optical train.
94 * @param name optical train name
95 * @return true if optical train found
96 */
97 bool selectOpticalTrain(const QString &name);
98
99 /**
100 * @brief Show the dialog and select an optical train for editing.
101 * @param name optical train name
102 */
103 void openEditor(const QString &name);
104
105 /**
106 * @brief setOpticalTrainValue Set specific field of optical train
107 * @param name Name of optical field
108 * @param field Name of field
109 * @param value Value of field
110 * @return True if set is successful, false otherwise.
111 */
112 bool setOpticalTrainValue(const QString &name, const QString &field, const QVariant &value);
113
114 /**
115 * @brief Change the name of the currently selected optical train to a new value
116 * @param name new train name
117 */
118 void renameCurrentOpticalTrain(const QString &name);
119
120 /**
121 * @brief setOpticalTrain Replaces optical train matching the name of the passed train.
122 * @param train Train information, including name and database id
123 * @return True if train is successfully updated in the database.
124 */
125 bool setOpticalTrain(const QJsonObject &train);
126
127 /**
128 * @brief removeOpticalTrain Remove optical train from database and all associated settings
129 * @param name name if the optical train to remove
130 * @return True if successful, false if id is not found.
131 */
132 bool removeOpticalTrain(const QString &name);
133
134 void refreshModel();
135 void refreshTrains();
136 void refreshOpticalElements();
137 void reset();
138 /**
139 * @brief syncDevices Sync delegates and then update model accordingly.
140 */
141 void syncDevices();
142
143 /**
144 * @brief syncActiveDevices Syncs ACTIVE_DEVICES in INDI as per the optical train settings.
145 */
146 void syncActiveDevices();
147
148 /**
149 * @brief getGenericDevice Find Generic Device matching given Role in the given train
150 * @param train Train Name
151 * @param role Device Role
152 * @param generic Generic Device. If found, the pointer is pointing to GenericDevice
153 * @return True if found, false if not found.
154 */
155 bool getGenericDevice(const QString &train, Role role, QSharedPointer<ISD::GenericDevice> &generic);
156
157 /**
158 * @brief syncActiveProperties Since ACTIVE_DEVICE properties
159 * @param train Train map
160 * @param device Generic device
161 */
162 void syncActiveProperties(const QVariantMap &train, const QSharedPointer<ISD::GenericDevice> &device);
163
164 /**
165 * @brief id Get database ID for a given train
166 * @param name Name of train
167 * @return ID if exists, or -1 if not found.
168 */
169 int id(const QString &name) const;
170
171 /**
172 * @brief name Get database name for a given name
173 * @param id database ID for the train to get
174 * @return Train name, or empty string if not found.
175 */
176 QString name(int id) const;
177
178 ISD::Mount *getMount(const QString &name);
179 ISD::DustCap *getDustCap(const QString &name);
180 ISD::LightBox *getLightBox(const QString &name);
181 QJsonObject getScope(const QString &name);
182 double getReducer(const QString &name);
183 ISD::Rotator *getRotator(const QString &name);
184 ISD::Focuser *getFocuser(const QString &name);
185 ISD::FilterWheel *getFilterWheel(const QString &name);
186 ISD::Camera *getCamera(const QString &name);
187 ISD::Guider *getGuider(const QString &name);
188 ISD::AdaptiveOptics *getAdaptiveOptics(const QString &name);
189
190 signals:
191 void updated();
192 void configurationRequested(bool show);
193
194 protected:
195 void initModel();
196 QStringList getMissingDevices() const;
197
198 private slots:
199 /**
200 * @brief Update an element value in the currently selected optical train
201 * @param cb combo box holding the new value
202 * @param element element name
203 */
204 void updateOpticalTrainValue(QComboBox *cb, const QString &element);
205 /**
206 * @brief Update an element value in the currently selected optical train
207 * @param value the new value
208 * @param element element name
209 */
210 void updateOpticalTrainValue(double value, const QString &element);
211
212 private:
213
214 OpticalTrainManager();
215 static OpticalTrainManager *m_Instance;
216
217 /**
218 * @brief generateOpticalTrains Automatically generate optical trains based on the current profile information.
219 * This happens when users use the tool for the first time.
220 */
221 void generateOpticalTrains();
222
223 /**
224 * @brief Add a new optical train with the given name
225 * @param index train index (0, 1, 2..etc)
226 * @param name train name
227 * @return unique train name
228 */
229 QString addOpticalTrain(uint8_t index, const QString &name);
230
231 void checkMissingDevices();
232
233 /**
234 * @brief syncDelegatesToDevices Parses INDI devices and updates delegates accordingly.
235 * @return True if all devices synced. False if no new devices synced.
236 */
237 bool syncDelegatesToDevices();
238
239 /**
240 * @brief Create a unique train name
241 * @param name original train name
242 * @return name, eventually added (i) to make the train name unique
243 */
244 QString uniqueTrainName(QString name);
245
247 QList<QVariantMap> m_OpticalTrains;
248 QTimer m_CheckMissingDevicesTimer;
249 QTimer m_DelegateTimer;
250 QVariantMap *m_CurrentOpticalTrain = nullptr;
251
252 // make changes persistent
253 bool m_Persistent = false;
254
255 // Table model
256 QSqlTableModel *m_OpticalTrainsModel = { nullptr };
257
258 QStringList m_TrainNames;
259 // Device names
260 QStringList m_MountNames;
261 QStringList m_DustCapNames;
262 QStringList m_LightBoxNames;
263 QStringList m_ScopeNames;
264 QStringList m_ReducerNames;
265 QStringList m_RotatorNames;
266 QStringList m_FocuserNames;
267 QStringList m_FilterWheelNames;
268 QStringList m_CameraNames;
269 QStringList m_GuiderNames;
270};
271
272}
AdaptiveOptics class handles control of INDI AdaptiveOptics devices.
Camera class controls an INDI Camera device.
Definition indicamera.h:45
Handles operation of a remotely controlled dust cover cap.
Definition indidustcap.h:25
Focuser class handles control of INDI focuser devices.
Definition indifocuser.h:21
Handles operation of a remotely controlled light box.
device handle controlling Mounts.
Definition indimount.h:29
Rotator class handles control of INDI Rotator devices.
Definition indirotator.h:20
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.