Kstars

equipmentwriter.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Prakash Mohan <prakash.mohan@kdemail.net>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "oal/equipmentwriter.h"
8#include "ui_equipmentwriter.h"
9
10#include <QFile>
11
12#include "kstarsdata.h"
13#include "oal/oal.h"
14#include "oal/scope.h"
15#include "oal/dslrlens.h"
16#include "oal/eyepiece.h"
17#include "oal/lens.h"
18#include "oal/filter.h"
19#include "ekos/ekos.h"
20
21#include <config-kstars.h>
22
23#ifdef HAVE_INDI
24#include "indi/drivermanager.h"
25#endif
26
27EquipmentWriter::EquipmentWriter()
28{
29 QWidget *widget = new QWidget;
30 ui.setupUi(widget);
31 ui.tabWidget->setCurrentIndex(0);
32 setWindowTitle(i18nc("@title:window", "Configure Equipment"));
33
34 QVBoxLayout *mainLayout = new QVBoxLayout;
35 mainLayout->addWidget(widget);
36 setLayout(mainLayout);
37
39 mainLayout->addWidget(buttonBox);
40
41 QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
42
43 nextScope = 0;
44 nextEyepiece = 0;
45 nextFilter = 0;
46 nextLens = 0;
47 nextDSLRLens = 0;
48 loadEquipment();
49 newScope = true;
50 newEyepiece = true;
51 newLens = true;
52 newFilter = true;
53 newDSLRLens = true;
54
55 //make connections
56 connect(ui.NewScope, SIGNAL(clicked()), this, SLOT(slotNewScope()));
57 connect(ui.NewEyepiece, SIGNAL(clicked()), this, SLOT(slotNewEyepiece()));
58 connect(ui.NewLens, SIGNAL(clicked()), this, SLOT(slotNewLens()));
59 connect(ui.NewFilter, SIGNAL(clicked()), this, SLOT(slotNewFilter()));
60 connect(ui.AddScope, SIGNAL(clicked()), this, SLOT(slotSave()));
61 connect(ui.AddEyepiece, SIGNAL(clicked()), this, SLOT(slotSave()));
62 connect(ui.AddLens, SIGNAL(clicked()), this, SLOT(slotSave()));
63 connect(ui.AddFilter, SIGNAL(clicked()), this, SLOT(slotSave()));
64 connect(ui.ScopeList, SIGNAL(currentTextChanged(QString)), this, SLOT(slotSetScope(QString)));
65 connect(ui.EyepieceList, SIGNAL(currentTextChanged(QString)), this, SLOT(slotSetEyepiece(QString)));
66 connect(ui.LensList, SIGNAL(currentTextChanged(QString)), this, SLOT(slotSetLens(QString)));
67 connect(ui.FilterList, SIGNAL(currentTextChanged(QString)), this, SLOT(slotSetFilter(QString)));
68 connect(ui.RemoveScope, SIGNAL(clicked()), this, SLOT(slotRemoveScope()));
69 connect(ui.RemoveEyepiece, SIGNAL(clicked()), this, SLOT(slotRemoveEyepiece()));
70 connect(ui.RemoveLens, SIGNAL(clicked()), this, SLOT(slotRemoveLens()));
71 connect(ui.RemoveFilter, SIGNAL(clicked()), this, SLOT(slotRemoveFilter()));
72
73 connect(ui.NewDSLRLens, &QPushButton::clicked, this, &EquipmentWriter::slotNewDSLRLens);
74 connect(ui.AddDSLRLens, &QPushButton::clicked, this, &EquipmentWriter::slotAddDSLRLens);
75 connect(ui.RemoveDSLRLens, &QPushButton::clicked, this, &EquipmentWriter::slotRemoveDSLRLens);
76 connect(ui.DSLRLensList, &QListWidget::currentTextChanged, this, &EquipmentWriter::slotSetDSLRLens);
77}
78
79void EquipmentWriter::slotAddScope()
80{
81 KStarsData::Instance()->userdb()->AddScope(ui.Model->text(),
82 ui.Vendor->text(),
83 ui.Type->currentText(),
84 ui.Aperture->value(),
85 ui.FocalLength->value());
86
87 loadEquipment();
88 ui.Model->clear();
89 ui.Vendor->clear();
90 ui.Aperture->setValue(0);
91 ui.FocalLength->setValue(0);
92}
93
94void EquipmentWriter::slotRemoveScope()
95{
96 KStarsData::Instance()->userdb()->DeleteEquipment("telescope", ui.Id->text());
97 ui.Model->clear();
98 ui.Vendor->clear();
99 ui.Aperture->setValue(0);
100 ui.FocalLength->setValue(0);
101 loadEquipment();
102}
103
104void EquipmentWriter::slotSaveScope()
105{
106 KStarsData::Instance()->userdb()->AddScope(ui.Model->text(),
107 ui.Vendor->text(),
108 ui.Type->currentText(),
109 ui.Aperture->value(),
110 ui.FocalLength->value(),
111 ui.Id->text());
112
113 loadEquipment();
114}
115
116void EquipmentWriter::slotSetScope(QString name)
117{
118 //TODO: maybe this should also use the DB? ~~spacetime
119 OAL::Scope *s = KStarsData::Instance()->logObject()->findScopeByName(name);
120 if (s)
121 {
122 ui.Id->setText(s->id());
123 ui.Model->setText(s->model());
124 ui.Vendor->setText(s->vendor());
125 ui.Type->setCurrentIndex(ui.Type->findText(s->type()));
126 ui.Aperture->setValue(s->aperture());
127 ui.FocalLength->setValue(s->focalLength());
128 newScope = false;
129 }
130}
131void EquipmentWriter::slotNewScope()
132{
133 ui.Id->clear();
134 ui.Model->clear();
135 ui.Vendor->clear();
136 ui.FocalLength->setValue(0);
137 ui.ScopeList->selectionModel()->clear();
138 newScope = true;
139}
140
141//////////////////////////////////////////////////////////////////////////////////////////
142/// DSLR lens
143//////////////////////////////////////////////////////////////////////////////////////////
144
145void EquipmentWriter::slotAddDSLRLens()
146{
147 KStarsData::Instance()->userdb()->AddDSLRLens(
148 ui.DSLR_model->text(),
149 ui.DSLR_vendor->text(),
150 ui.DSLRFocalLength->value(),
151 ui.DSLRFocalRatio->value());
152 loadEquipment();
153 ui.DSLR_model->clear();
154 ui.DSLR_vendor->clear();
155 ui.DSLRFocalLength->setValue(24);
156 ui.DSLRFocalRatio->setValue(2.8);
157}
158
159void EquipmentWriter::slotRemoveDSLRLens()
160{
161 KStarsData::Instance()->userdb()->DeleteEquipment("dslrlens", ui.DSLR_id->text());
162 ui.DSLR_model->clear();
163 ui.DSLR_vendor->clear();
164 ui.DSLRFocalLength->setValue(24);
165 ui.DSLRFocalRatio->setValue(2.8);
166 loadEquipment();
167}
168
169void EquipmentWriter::slotSaveDSLRLens()
170{
171 KStarsData::Instance()->userdb()->AddDSLRLens(
172 ui.DSLR_model->text(),
173 ui.DSLR_vendor->text(),
174 ui.DSLRFocalLength->value(),
175 ui.DSLRFocalRatio->value(),
176 ui.DSLR_id->text());
177
178 loadEquipment();
179}
180
181void EquipmentWriter::slotSetDSLRLens(QString name)
182{
183 OAL::DSLRLens *s = KStarsData::Instance()->logObject()->findDSLRLensByName(name);
184 if (s)
185 {
186 ui.DSLR_id->setText(s->id());
187 ui.DSLR_model->setText(s->model());
188 ui.DSLR_vendor->setText(s->vendor());
189 ui.DSLRFocalLength->setValue(s->focalLength());
190 ui.DSLRFocalRatio->setValue(s->focalRatio());
191 newDSLRLens = false;
192 }
193}
194
195void EquipmentWriter::slotNewDSLRLens()
196{
197 ui.DSLR_id->clear();
198 ui.DSLR_model->clear();
199 ui.DSLR_vendor->clear();
200 ui.DSLRFocalLength->setValue(24);
201 ui.DSLRFocalRatio->setValue(2.8);
202 ui.DSLRLensList->selectionModel()->clear();
203 newDSLRLens = true;
204}
205
206//////////////////////////////////////////////////////////////////////////////////////////
207/// Eyepeices
208//////////////////////////////////////////////////////////////////////////////////////////
209
210void EquipmentWriter::slotAddEyepiece()
211{
212 KStarsData::Instance()->userdb()->AddEyepiece(ui.e_Vendor->text(), ui.e_Model->text(), ui.e_focalLength->value(),
213 ui.Fov->value(), ui.FovUnit->currentText());
214 loadEquipment();
215 ui.e_Id->clear();
216 ui.e_Model->clear();
217 ui.e_Vendor->clear();
218 ui.Fov->setValue(0);
219 ui.e_focalLength->setValue(0);
220}
221
222void EquipmentWriter::slotRemoveEyepiece()
223{
224 KStarsData::Instance()->userdb()->DeleteEquipment("eyepiece", ui.e_Id->text());
225 loadEquipment();
226 ui.e_Id->clear();
227 ui.e_Model->clear();
228 ui.e_Vendor->clear();
229 ui.Fov->setValue(0);
230 ui.e_focalLength->setValue(0);
231 ui.EyepieceList->clear();
232 foreach (OAL::Eyepiece *e, *(KStarsData::Instance()->logObject()->eyepieceList()))
233 ui.EyepieceList->addItem(e->name());
234}
235void EquipmentWriter::slotSaveEyepiece()
236{
237 KStarsData::Instance()->userdb()->AddEyepiece(ui.e_Vendor->text(), ui.e_Model->text(), ui.e_focalLength->value(),
238 ui.Fov->value(), ui.FovUnit->currentText(), ui.e_Id->text());
239 loadEquipment();
240}
241
242void EquipmentWriter::slotSetEyepiece(QString name)
243{
244 //TODO: maybe this should also use the DB? ~~spacetime
245 OAL::Eyepiece *e;
246 e = KStarsData::Instance()->logObject()->findEyepieceByName(name);
247 if (e)
248 {
249 ui.e_Id->setText(e->id());
250 ui.e_Model->setText(e->model());
251 ui.e_Vendor->setText(e->vendor());
252 ui.Fov->setValue(e->appFov());
253 ui.e_focalLength->setValue(e->focalLength());
254 newEyepiece = false;
255 }
256}
257
258void EquipmentWriter::slotNewEyepiece()
259{
260 ui.e_Id->clear();
261 ui.e_Model->clear();
262 ui.e_Vendor->clear();
263 ui.Fov->setValue(0);
264 ui.e_focalLength->setValue(0);
265 ui.EyepieceList->selectionModel()->clear();
266 newEyepiece = true;
267}
268
269void EquipmentWriter::slotAddLens()
270{
271 KStarsData::Instance()->userdb()->AddLens(ui.l_Vendor->text(), ui.l_Model->text(), ui.l_Factor->value());
272 loadEquipment();
273 ui.l_Id->clear();
274 ui.l_Model->clear();
275 ui.l_Vendor->clear();
276 ui.l_Factor->setValue(0);
277}
278
279void EquipmentWriter::slotRemoveLens()
280{
281 KStarsData::Instance()->userdb()->DeleteEquipment("lens", ui.l_Id->text());
282 loadEquipment();
283 ui.l_Id->clear();
284 ui.l_Model->clear();
285 ui.l_Vendor->clear();
286 ui.l_Factor->setValue(0);
287 ui.LensList->clear();
288 foreach (OAL::Lens *l, *(KStarsData::Instance()->logObject()->lensList()))
289 ui.LensList->addItem(l->name());
290}
291void EquipmentWriter::slotSaveLens()
292{
293 KStarsData::Instance()->userdb()->AddLens(ui.l_Vendor->text(), ui.l_Model->text(), ui.l_Factor->value(),
294 ui.l_Id->text());
295 loadEquipment();
296}
297
298void EquipmentWriter::slotSetLens(QString name)
299{
300 OAL::Lens *l;
301 l = KStarsData::Instance()->logObject()->findLensByName(name);
302 if (l)
303 {
304 ui.l_Id->setText(l->id());
305 ui.l_Model->setText(l->model());
306 ui.l_Vendor->setText(l->vendor());
307 ui.l_Factor->setValue(l->factor());
308 newLens = false;
309 }
310}
311
312void EquipmentWriter::slotNewLens()
313{
314 ui.l_Id->clear();
315 ui.l_Model->clear();
316 ui.l_Vendor->clear();
317 ui.l_Factor->setValue(0);
318 ui.LensList->selectionModel()->clear();
319 newLens = true;
320}
321
322void EquipmentWriter::slotAddFilter()
323{
324 filterProperties *fp = new filterProperties(ui.f_Vendor->text(), ui.f_Model->text(), ui.f_Type->text(),
325 ui.f_Color->text(), ui.f_Offset->value(), ui.f_Exposure->value(), ui.f_UseAutoFocus->isChecked(),
326 ui.f_LockedFilter->text(), 0, Ekos::INVALID_VALUE, Ekos::INVALID_VALUE, ui.f_FocusTicksPerTemp->value(),
327 ui.f_FocusTicksPerAlt->value(), ui.f_Wavelength->value());
328 KStarsData::Instance()->userdb()->AddFilter(fp, ui.f_Vendor->text());
329
330 loadEquipment();
331 ui.f_Id->clear();
332 ui.f_Model->clear();
333 ui.f_Vendor->clear();
334 ui.f_Type->clear();
335 ui.f_Offset->setValue(0);
336 ui.f_Color->clear();
337 ui.f_Exposure->setValue(1);
338 ui.f_LockedFilter->setText(NULL_FILTER);
339 ui.f_UseAutoFocus->setChecked(false);
340 ui.f_FocusTemperature->setValue(Ekos::INVALID_VALUE);
341 ui.f_FocusAltitude->setValue(Ekos::INVALID_VALUE);
342 ui.f_FocusTicksPerTemp->setValue(0.0);
343 ui.f_FocusTicksPerAlt->setValue(0.0);
344 ui.f_Wavelength->setValue(500.0);
345
346}
347
348void EquipmentWriter::slotRemoveFilter()
349{
350 KStarsData::Instance()->userdb()->DeleteEquipment("filter", ui.f_Id->text());
351 loadEquipment();
352 ui.f_Id->clear();
353 ui.f_Model->clear();
354 ui.f_Vendor->clear();
355 ui.f_Type->clear();
356 ui.f_Offset->setValue(0);
357 ui.f_Color->clear();
358 ui.f_Exposure->setValue(0);
359 ui.f_LockedFilter->setText(NULL_FILTER);
360 ui.f_UseAutoFocus->setChecked(false);
361 ui.f_FocusTemperature->setValue(Ekos::INVALID_VALUE);
362 ui.f_FocusAltitude->setValue(Ekos::INVALID_VALUE);
363 ui.f_FocusTicksPerTemp->setValue(0.0);
364 ui.f_FocusTicksPerAlt->setValue(0.0);
365 ui.f_Wavelength->setValue(500.0);
366 ui.FilterList->clear();
367 foreach (OAL::Filter *f, *(KStarsData::Instance()->logObject()->filterList()))
368 ui.FilterList->addItem(f->name());
369}
370
371void EquipmentWriter::slotSaveFilter()
372{
373 filterProperties *fp = new filterProperties(ui.f_Vendor->text(), ui.f_Model->text(), ui.f_Type->text(),
374 ui.f_Color->text(), ui.f_Offset->value(), ui.f_Exposure->value(), ui.f_UseAutoFocus->isChecked(),
375 ui.f_LockedFilter->text(), ui.f_AbsoluteFocusPosition->value(), ui.f_FocusTemperature->value(),
376 ui.f_FocusAltitude->value(), ui.f_FocusTicksPerTemp->value(), ui.f_FocusTicksPerAlt->value(),
377 ui.f_Wavelength->value());
378 // Add
379 if (ui.f_Id->text().isEmpty())
380 KStarsData::Instance()->userdb()->AddFilter(fp);
381 // Update Existing
382 else
383 KStarsData::Instance()->userdb()->AddFilter(fp, ui.f_Id->text());
384
385 loadEquipment();
386}
387
388void EquipmentWriter::slotSetFilter(QString name)
389{
390 OAL::Filter *f;
391 f = KStarsData::Instance()->logObject()->findFilterByName(name);
392 if (f)
393 {
394 ui.f_Id->setText(f->id());
395 ui.f_Model->setText(f->model());
396 ui.f_Vendor->setText(f->vendor());
397 ui.f_Type->setText(f->type());
398 ui.f_Color->setText(f->color());
399 ui.f_Offset->setValue(f->offset());
400 ui.f_Exposure->setValue(f->exposure());
401 ui.f_LockedFilter->setText(f->lockedFilter());
402 ui.f_UseAutoFocus->setChecked(f->useAutoFocus());
403 ui.f_AbsoluteFocusPosition->setValue(f->absoluteFocusPosition());
404 ui.f_FocusTemperature->setValue(f->focusTemperature());
405 ui.f_FocusAltitude->setValue(f->focusAltitude());
406 ui.f_FocusTicksPerTemp->setValue(f->focusTicksPerTemp());
407 ui.f_FocusTicksPerAlt->setValue(f->focusTicksPerAlt());
408 ui.f_Wavelength->setValue(f->wavelength());
409 newFilter = false;
410 }
411}
412
413void EquipmentWriter::slotNewFilter()
414{
415 ui.f_Id->clear();
416 ui.f_Model->clear();
417 ui.f_Vendor->clear();
418 ui.f_Type->clear();
419 ui.f_Model->clear();
420 ui.f_Color->clear();
421 ui.f_Offset->setValue(0);
422 ui.f_Exposure->setValue(1);
423 ui.f_LockedFilter->setText(NULL_FILTER);
424 ui.f_UseAutoFocus->setChecked(false);
425 ui.f_AbsoluteFocusPosition->setValue(0);
426 ui.f_FocusTemperature->setValue(Ekos::INVALID_VALUE);
427 ui.f_FocusAltitude->setValue(Ekos::INVALID_VALUE);
428 ui.f_FocusTicksPerTemp->setValue(0.0);
429 ui.f_FocusTicksPerAlt->setValue(0.0);
430 ui.f_Wavelength->setValue(500.0);
431 ui.FilterList->selectionModel()->clear();
432 newFilter = true;
433}
434
435void EquipmentWriter::loadEquipment()
436{
437 KStarsData::Instance()->logObject()->readScopes();
438 KStarsData::Instance()->logObject()->readEyepieces();
439 KStarsData::Instance()->logObject()->readLenses();
440 KStarsData::Instance()->logObject()->readFilters();
441 KStarsData::Instance()->logObject()->readDSLRLenses();
442 ui.ScopeList->clear();
443 ui.EyepieceList->clear();
444 ui.LensList->clear();
445 ui.FilterList->clear();
446 ui.DSLRLensList->clear();
447 foreach (OAL::Scope *s, *(KStarsData::Instance()->logObject()->scopeList()))
448 ui.ScopeList->addItem(s->name());
449 foreach (OAL::Eyepiece *e, *(KStarsData::Instance()->logObject()->eyepieceList()))
450 ui.EyepieceList->addItem(e->name());
451 foreach (OAL::Lens *l, *(KStarsData::Instance()->logObject()->lensList()))
452 ui.LensList->addItem(l->name());
453 foreach (OAL::Filter *f, *(KStarsData::Instance()->logObject()->filterList()))
454 ui.FilterList->addItem(f->name());
455 foreach (OAL::DSLRLens *l, *(KStarsData::Instance()->logObject()->dslrLensList()))
456 ui.DSLRLensList->addItem(l->name());
457
458#ifdef HAVE_INDI
459 DriverManager::Instance()->updateCustomDrivers();
460#endif
461}
462
463void EquipmentWriter::slotSave()
464{
465 switch (ui.tabWidget->currentIndex())
466 {
467 case 0:
468 {
469 if (newScope)
470 slotAddScope();
471 else
472 slotSaveScope();
473 ui.ScopeList->clear();
474 foreach (OAL::Scope *s, *(KStarsData::Instance()->logObject()->scopeList()))
475 ui.ScopeList->addItem(s->name());
476 break;
477 }
478 case 1:
479 {
480 if (newEyepiece)
481 slotAddEyepiece();
482 else
483 slotSaveEyepiece();
484 ui.EyepieceList->clear();
485 foreach (OAL::Eyepiece *e, *(KStarsData::Instance()->logObject()->eyepieceList()))
486 ui.EyepieceList->addItem(e->name());
487 break;
488 }
489 case 2:
490 {
491 if (newDSLRLens)
492 slotAddDSLRLens();
493 else
494 slotSaveDSLRLens();
495 ui.DSLRLensList->clear();
496 for (const auto &l : * (KStarsData::Instance()->logObject()->dslrLensList()))
497 ui.DSLRLensList->addItem(l->name());
498 break;
499 }
500 case 3:
501 {
502 if (newLens)
503 slotAddLens();
504 else
505 slotSaveLens();
506 ui.LensList->clear();
507 foreach (OAL::Lens *l, *(KStarsData::Instance()->logObject()->lensList()))
508 ui.LensList->addItem(l->name());
509 break;
510 }
511 case 4:
512 {
513 if (newFilter)
514 slotAddFilter();
515 else
516 slotSaveFilter();
517 ui.FilterList->clear();
518 foreach (OAL::Filter *f, *(KStarsData::Instance()->logObject()->filterList()))
519 ui.FilterList->addItem(f->name());
520 break;
521 }
522 }
523}
524
525void EquipmentWriter::slotClose()
526{
527 hide();
528}
bool AddFilter(const filterProperties *fp)
Add a new filter to the database.
bool AddLens(const QString &vendor, const QString &model, const double &factor)
Add a new lens to the database.
bool AddDSLRLens(const QString &model, const QString &vendor, const double focalLength, const double focalRatio)
Appends the DSLR lens with given details in the database.
bool AddScope(const QString &model, const QString &vendor, const QString &type, const double &aperture, const double &focalLength)
Appends the scope with given details in the database.
bool DeleteEquipment(const QString &type, const QString &id)
Erase the equipment with given type and unique id Valid equipment types: "telescope",...
bool AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov, const QString &fovunit)
Add new eyepiece to database.
KSUserDB * userdb()
Definition kstarsdata.h:217
OAL::Log * logObject()
Return log object.
Definition kstarsdata.h:343
Information on DSLR lens used in astrophotography.
Definition dslrlens.h:18
Information of user filters.
Definition filter.h:48
Information of lens utilized in the observation.
Definition lens.h:18
Information on telescope used in observation.
Definition scope.h:18
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void clicked(bool checked)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void rejected()
void currentTextChanged(const QString &currentText)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QWidget(QWidget *parent, Qt::WindowFlags f)
bool close()
void hide()
void setLayout(QLayout *layout)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:57:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.