7#include "opticaltrainmanager.h"
8#include <kstars_debug.h>
10#include "ksnotification.h"
11#include "kstarsdata.h"
14#include "indi/indilistener.h"
15#include "ekos/auxiliary/profilesettings.h"
16#include "oal/equipmentwriter.h"
19#include <QSqlTableModel>
20#include <QSqlDatabase>
23#include <basedevice.h>
30OpticalTrainManager *OpticalTrainManager::m_Instance =
nullptr;
35OpticalTrainManager *OpticalTrainManager::Instance()
37 if (m_Instance ==
nullptr)
38 m_Instance =
new OpticalTrainManager();
46void OpticalTrainManager::release()
55OpticalTrainManager::OpticalTrainManager() :
QDialog(
KStars::Instance())
65 emit configurationRequested(
false);
72 updateOpticalTrainValue(mountComboBox,
"mount");
79 updateOpticalTrainValue(dustCapComboBox,
"dustcap");
86 updateOpticalTrainValue(lightBoxComboBox,
"lightbox");
93 updateOpticalTrainValue(scopeComboBox,
"scope");
100 updateOpticalTrainValue(value,
"reducer");
107 updateOpticalTrainValue(rotatorComboBox,
"rotator");
114 updateOpticalTrainValue(focusComboBox,
"focuser");
121 updateOpticalTrainValue(filterComboBox,
"filterwheel");
128 updateOpticalTrainValue(cameraComboBox,
"camera");
135 updateOpticalTrainValue(guiderComboBox,
"guider");
140 addOpticalTrain(m_TrainNames.count(),
i18n(
"New Train"));
141 m_OpticalTrainsModel->select();
143 trainNamesList->setCurrentRow(trainNamesList->count() - 1);
144 selectOpticalTrain(trainNamesList->currentItem());
149 if (trainNamesList->currentItem() !=
nullptr)
151 removeOpticalTrain(trainNamesList->currentItem()->text());
152 removeB->setEnabled(
false);
161 writer->loadEquipment();
163 refreshOpticalElements();
168 selectOpticalTrain(item);
172 renameCurrentOpticalTrain(item->
text());
177 selectOpticalTrain(trainNamesList->currentItem());
180 m_CheckMissingDevicesTimer.setInterval(5000);
181 m_CheckMissingDevicesTimer.setSingleShot(
true);
184 m_DelegateTimer.setInterval(1000);
185 m_DelegateTimer.setSingleShot(
true);
189 setProfile(m_Profile);
198void OpticalTrainManager::initModel()
204 m_OpticalTrains.clear();
205 for (
int i = 0; i < m_OpticalTrainsModel->rowCount(); ++i)
207 QVariantMap recordMap;
208 QSqlRecord record = m_OpticalTrainsModel->record(i);
209 for (
int j = 0; j < record.
count(); j++)
212 m_OpticalTrains.append(recordMap);
215 m_TrainNames.clear();
216 for (
auto &oneTrain : m_OpticalTrains)
217 m_TrainNames << oneTrain[
"name"].toString();
219 trainNamesList->clear();
220 trainNamesList->addItems(m_TrainNames);
226void OpticalTrainManager::syncDevices()
228 syncDelegatesToDevices();
239void OpticalTrainManager::refreshModel()
242 m_TrainNames.clear();
243 for (
auto &oneTrain : m_OpticalTrains)
244 m_TrainNames << oneTrain[
"name"].toString();
246 trainNamesList->clear();
247 trainNamesList->addItems(m_TrainNames);
253void OpticalTrainManager::syncActiveDevices()
255 for (
auto &oneTrain : m_OpticalTrains)
257 auto train = oneTrain[
"name"].toString();
260 if (getGenericDevice(train, Mount, device))
261 syncActiveProperties(oneTrain, device);
262 if (getGenericDevice(train, Camera, device))
263 syncActiveProperties(oneTrain, device);
264 if (getGenericDevice(train, GuideVia, device))
265 syncActiveProperties(oneTrain, device);
266 if (getGenericDevice(train, Focuser, device))
267 syncActiveProperties(oneTrain, device);
268 if (getGenericDevice(train, FilterWheel, device))
269 syncActiveProperties(oneTrain, device);
270 if (getGenericDevice(train, Rotator, device))
271 syncActiveProperties(oneTrain, device);
272 if (getGenericDevice(train, DustCap, device))
273 syncActiveProperties(oneTrain, device);
274 if (getGenericDevice(train, LightBox, device))
275 syncActiveProperties(oneTrain, device);
280 if (!m_OpticalTrains.isEmpty())
282 auto name = m_OpticalTrains[0][
"name"].toString();
283 if (getGenericDevice(name, Dome, device))
284 syncActiveProperties(m_OpticalTrains[0], device);
285 if (getGenericDevice(name, Weather, device))
286 syncActiveProperties(m_OpticalTrains[0], device);
287 if (getGenericDevice(name, GPS, device))
288 syncActiveProperties(m_OpticalTrains[0], device);
297 auto tvp = device->getProperty(
"ACTIVE_DEVICES");
301 auto name = train[
"name"].toString();
303 for (
auto &it : *tvp.getText())
306 QString elementText = it.getText();
307 if (it.isNameMatch(
"ACTIVE_TELESCOPE"))
309 auto activeDevice = train[
"mount"].toString();
310 if (activeDevice ==
"--")
312 else if (activeDevice != elementText)
315 if (getGenericDevice(name, Mount, genericDevice))
316 devs.
append(genericDevice);
319 else if (it.isNameMatch(
"ACTIVE_DOME"))
321 devs = INDIListener::devicesByInterface(INDI::BaseDevice::DOME_INTERFACE);
323 else if (it.isNameMatch(
"ACTIVE_GPS"))
325 devs = INDIListener::devicesByInterface(INDI::BaseDevice::GPS_INTERFACE);
329 devs.
erase(std::remove_if(devs.
begin(), devs.
end(), [](
const auto & oneDevice)
331 return oneDevice->getDeviceName() != Options::locationSource() && oneDevice->getDeviceName() != Options::timeSource();
337 else if (it.isNameMatch(
"ACTIVE_ROTATOR"))
339 auto activeDevice = train[
"rotator"].toString();
340 if (activeDevice ==
"--")
342 else if (activeDevice != elementText)
345 if (getGenericDevice(name, Rotator, genericDevice))
346 devs.
append(genericDevice);
349 else if (it.isNameMatch(
"ACTIVE_FOCUSER"))
351 auto activeDevice = train[
"focuser"].toString();
352 if (activeDevice ==
"--")
354 else if (activeDevice != elementText)
357 if (getGenericDevice(name, Focuser, genericDevice))
358 devs.
append(genericDevice);
361 else if (it.isNameMatch(
"ACTIVE_FILTER"))
363 auto activeDevice = train[
"filterwheel"].toString();
364 if (activeDevice ==
"--")
366 else if (activeDevice != elementText)
369 if (getGenericDevice(name, FilterWheel, genericDevice))
370 devs.
append(genericDevice);
376 if (it.getText() != devs.
first()->getDeviceName())
378 it.setText(devs.
first()->getDeviceName().toLatin1().constData());
379 device->sendNewProperty(tvp.getText());
386 device->sendNewProperty(tvp.getText());
397 m_DelegateTimer.stop();
400 if (m_Profile != profile)
407 if (syncDelegatesToDevices())
409 m_CheckMissingDevicesTimer.start();
412 m_DelegateTimer.start();
418 checkOpticalTrains();
425void OpticalTrainManager::checkOpticalTrains()
427 if (m_OpticalTrains.empty())
429 generateOpticalTrains();
431 if (!m_OpticalTrains.empty())
433 auto primaryTrainID = m_OpticalTrains[0][
"id"].toUInt();
434 ProfileSettings::Instance()->setOneSetting(ProfileSettings::PrimaryOpticalTrain, primaryTrainID);
435 ProfileSettings::Instance()->setOneSetting(ProfileSettings::CaptureOpticalTrain, primaryTrainID);
436 ProfileSettings::Instance()->setOneSetting(ProfileSettings::FocusOpticalTrain, primaryTrainID);
437 ProfileSettings::Instance()->setOneSetting(ProfileSettings::MountOpticalTrain, primaryTrainID);
438 ProfileSettings::Instance()->setOneSetting(ProfileSettings::AlignOpticalTrain, primaryTrainID);
439 ProfileSettings::Instance()->setOneSetting(ProfileSettings::DarkLibraryOpticalTrain, primaryTrainID);
440 if (m_OpticalTrains.count() > 1)
441 ProfileSettings::Instance()->setOneSetting(ProfileSettings::GuideOpticalTrain, m_OpticalTrains[1][
"id"].toInt());
443 ProfileSettings::Instance()->setOneSetting(ProfileSettings::GuideOpticalTrain, primaryTrainID);
449 emit configurationRequested(
true);
453 m_CheckMissingDevicesTimer.start();
460void OpticalTrainManager::generateOpticalTrains()
463 addOpticalTrain(0,
i18n(
"Primary"));
465 if (cameraComboBox->count() > 2)
466 addOpticalTrain(1,
i18n(
"Secondary"));
468 if (cameraComboBox->count() > 3)
469 addOpticalTrain(2,
i18n(
"Tertiary"));
475QString OpticalTrainManager::addOpticalTrain(uint8_t index,
const QString &name)
478 train[
"profile"] = m_Profile->id;
479 train[
"name"] = uniqueTrainName(name);
481 train[
"mount"] = mountComboBox->itemText(mountComboBox->count() - 1);
482 train[
"dustcap"] = dustCapComboBox->itemText(dustCapComboBox->count() - 1);
483 train[
"lightbox"] = lightBoxComboBox->itemText(lightBoxComboBox->count() - 1);
484 train[
"reducer"] = 1.0;
485 train[
"rotator"] = rotatorComboBox->itemText(rotatorComboBox->count() - 1);
486 train[
"focuser"] = focusComboBox->itemText(focusComboBox->count() - 1);
487 train[
"filterwheel"] = filterComboBox->itemText(filterComboBox->count() - 1);
488 train[
"guider"] = guiderComboBox->itemText(guiderComboBox->count() - 1);
491 if (
KStars::Instance()->data()->userdb()->getLastOpticalElement(opticalElement))
492 train[
"scope"] = opticalElement[
"name"].toString();
494 train[
"camera"] =
"--";
496 if (index == 0 && cameraComboBox->count() > 1)
497 train[
"camera"] = cameraComboBox->itemText(1);
503 auto cameraIndex = index + 1;
504 if (cameraComboBox->count() >= cameraIndex)
505 train[
"camera"] = cameraComboBox->itemText(cameraIndex);
509 return train[
"name"].toString();
515void OpticalTrainManager::addOpticalTrain(
const QJsonObject &value)
518 newTrain[
"profile"] = m_Profile->id;
527bool OpticalTrainManager::setOpticalTrainValue(
const QString &name,
const QString &field,
const QVariant &value)
529 for (
auto &oneTrain : m_OpticalTrains)
531 if (oneTrain[
"name"].
toString() == name)
534 if (oneTrain[field] == value)
538 oneTrain[field] = value;
551void OpticalTrainManager::renameCurrentOpticalTrain(
const QString &name)
553 if (m_CurrentOpticalTrain !=
nullptr && (*m_CurrentOpticalTrain)[
"name"] != name)
555 auto pos = trainNamesList->currentRow();
557 auto unique = uniqueTrainName(name);
559 setOpticalTrainValue((*m_CurrentOpticalTrain)[
"name"].
toString(),
"name", unique);
561 trainNamesList->currentItem()->setText(unique);
565 selectOpticalTrain(unique);
566 trainNamesList->setCurrentRow(pos);
573bool OpticalTrainManager::setOpticalTrain(
const QJsonObject &train)
575 auto oneOpticalTrain = getOpticalTrain(train[
"id"].toInt());
576 if (!oneOpticalTrain.empty())
588bool OpticalTrainManager::removeOpticalTrain(
const QString &name)
590 for (
auto &oneTrain : m_OpticalTrains)
592 if (oneTrain[
"name"].
toString() == name)
594 auto id = oneTrain[
"id"].toInt();
595 KStarsData::Instance()->
userdb()->DeleteOpticalTrain(
id);
596 KStarsData::Instance()->
userdb()->DeleteOpticalTrainSettings(
id);
598 selectOpticalTrain(
nullptr);
609bool OpticalTrainManager::syncDelegatesToDevices()
611 auto changed =
false;
614 auto mounts = INDIListener::devicesByInterface(INDI::BaseDevice::TELESCOPE_INTERFACE);
616 for (
auto &oneMount : mounts)
617 values << oneMount->getDeviceName();
618 changed |= !values.
empty() && values != m_MountNames;
619 m_MountNames = values;
620 auto currentMount = mountComboBox->currentText();
621 mountComboBox->
clear();
622 mountComboBox->addItems(
QStringList() <<
"--" << values);
623 mountComboBox->setCurrentText(currentMount);
627 auto dustcaps = INDIListener::devicesByInterface(INDI::BaseDevice::DUSTCAP_INTERFACE);
628 for (
auto &oneCap : dustcaps)
629 values << oneCap->getDeviceName();
630 changed |= !values.
empty() && values != m_DustCapNames;
631 m_DustCapNames = values;
632 auto currentCap = dustCapComboBox->currentText();
633 dustCapComboBox->
clear();
634 dustCapComboBox->addItems(
QStringList() <<
"--" << values);
635 dustCapComboBox->setCurrentText(currentCap);
639 auto lightboxes = INDIListener::devicesByInterface(INDI::BaseDevice::LIGHTBOX_INTERFACE);
640 for (
auto &oneBox : lightboxes)
641 values << oneBox->getDeviceName();
642 changed |= !values.
empty() && values != m_LightBoxNames;
643 auto currentLightBox = lightBoxComboBox->currentText();
644 m_LightBoxNames = values;
645 lightBoxComboBox->
clear();
646 lightBoxComboBox->addItems(
QStringList() <<
"--" << values);
647 lightBoxComboBox->setCurrentText(currentLightBox);
651 changed |= !values.
empty() && values != m_ScopeNames;
652 m_ScopeNames = values;
653 auto currentScope = scopeComboBox->currentText();
654 scopeComboBox->
clear();
655 scopeComboBox->addItems(
QStringList() <<
"--" << values);
656 scopeComboBox->setCurrentText(currentScope);
660 auto rotators = INDIListener::devicesByInterface(INDI::BaseDevice::ROTATOR_INTERFACE);
661 for (
auto &oneRotator : rotators)
662 values << oneRotator->getDeviceName();
663 changed |= !values.
empty() && values != m_RotatorNames;
664 m_RotatorNames = values;
665 auto currentRotator = rotatorComboBox->currentText();
666 rotatorComboBox->
clear();
667 rotatorComboBox->addItems(
QStringList() <<
"--" << values);
668 rotatorComboBox->setCurrentText(currentRotator);
672 auto focusers = INDIListener::devicesByInterface(INDI::BaseDevice::FOCUSER_INTERFACE);
673 for (
auto &oneFocuser : focusers)
674 values << oneFocuser->getDeviceName();
675 changed |= !values.
empty() && values != m_FocuserNames;
676 m_FocuserNames = values;
677 auto currentFocuser = focusComboBox->currentText();
678 focusComboBox->
clear();
679 focusComboBox->addItems(
QStringList() <<
"--" << values);
680 focusComboBox->setCurrentText(currentFocuser);
684 auto filterwheels = INDIListener::devicesByInterface(INDI::BaseDevice::FILTER_INTERFACE);
685 for (
auto &oneFilterWheel : filterwheels)
686 values << oneFilterWheel->getDeviceName();
687 changed |= !values.
empty() && values != m_FilterWheelNames;
688 m_FilterWheelNames = values;
689 auto currentFilter = filterComboBox->currentText();
690 filterComboBox->
clear();
691 filterComboBox->addItems(
QStringList() <<
"--" << values);
692 filterComboBox->setCurrentText(currentFilter);
696 auto cameras = INDIListener::devicesByInterface(INDI::BaseDevice::CCD_INTERFACE);
697 for (
auto &oneCamera : cameras)
698 values << oneCamera->getDeviceName();
699 changed |= !values.
empty() && values != m_CameraNames;
700 m_CameraNames = values;
701 auto currentCamera = cameraComboBox->currentText();
702 cameraComboBox->
clear();
703 cameraComboBox->addItems(
QStringList() <<
"--" << values);
704 cameraComboBox->setCurrentText(currentCamera);
708 auto guiders = INDIListener::devicesByInterface(INDI::BaseDevice::GUIDER_INTERFACE);
709 for (
auto &oneGuider : guiders)
710 values << oneGuider->getDeviceName();
711 changed |= !values.
empty() && values != m_GuiderNames;
712 m_GuiderNames = values;
713 auto currentGuider = guiderComboBox->currentText();
714 guiderComboBox->
clear();
715 guiderComboBox->addItems(
QStringList() <<
"--" << values);
716 guiderComboBox->setCurrentText(currentGuider);
728 while (m_TrainNames.contains(result))
739 if (item !=
nullptr && selectOpticalTrain(item->
text()))
750QString OpticalTrainManager::findTrainContainingDevice(
const QString &name, Role role)
752 for (
auto &oneTrain : m_OpticalTrains)
754 auto train = oneTrain[
"name"].toString();
759 if (oneTrain[
"mount"].
toString() == name)
763 if (oneTrain[
"camera"].
toString() == name)
767 if (oneTrain[
"rotator"].
toString() == name)
771 if (oneTrain[
"guider"].
toString() == name)
775 if (oneTrain[
"dustcap"].
toString() == name)
779 if (oneTrain[
"scope"].
toString() == name)
783 if (oneTrain[
"filterwheel"].
toString() == name)
787 if (oneTrain[
"focuser"].
toString() == name)
791 if (oneTrain[
"reducer"].
toString() == name)
795 if (oneTrain[
"lightbox"].
toString() == name)
813bool OpticalTrainManager::selectOpticalTrain(
const QString &name)
815 for (
auto &oneTrain : m_OpticalTrains)
817 if (oneTrain[
"name"].
toString() == name)
819 m_Persistent =
false;
820 m_CurrentOpticalTrain = &oneTrain;
821 mountComboBox->setCurrentText(oneTrain[
"mount"].
toString());
822 dustCapComboBox->setCurrentText(oneTrain[
"dustcap"].
toString());
823 lightBoxComboBox->setCurrentText(oneTrain[
"lightbox"].
toString());
824 scopeComboBox->setCurrentText(oneTrain[
"scope"].
toString());
825 reducerSpinBox->setValue(oneTrain[
"reducer"].toDouble());
826 rotatorComboBox->setCurrentText(oneTrain[
"rotator"].
toString());
827 focusComboBox->setCurrentText(oneTrain[
"focuser"].
toString());
828 filterComboBox->setCurrentText(oneTrain[
"filterwheel"].
toString());
829 cameraComboBox->setCurrentText(oneTrain[
"camera"].
toString());
830 guiderComboBox->setCurrentText(oneTrain[
"guider"].
toString());
831 removeB->setEnabled(m_OpticalTrains.length() > 1);
832 trainConfigBox->setEnabled(
true);
839 m_Persistent =
false;
840 m_CurrentOpticalTrain =
nullptr;
841 mountComboBox->setCurrentText(
"--");
842 dustCapComboBox->setCurrentText(
"--");
843 lightBoxComboBox->setCurrentText(
"--");
844 scopeComboBox->setCurrentText(
"--");
845 reducerSpinBox->setValue(1.0);
846 rotatorComboBox->setCurrentText(
"--");
847 focusComboBox->setCurrentText(
"--");
848 filterComboBox->setCurrentText(
"--");
849 cameraComboBox->setCurrentText(
"--");
850 guiderComboBox->setCurrentText(
"--");
851 removeB->setEnabled(
false);
852 trainConfigBox->setEnabled(
false);
860void OpticalTrainManager::openEditor(
const QString &name)
862 selectOpticalTrain(name);
864 if (matches.
count() > 0)
865 trainNamesList->setCurrentItem(matches.
first());
866 emit configurationRequested(
true);
875 for (
auto &oneTrain : m_OpticalTrains)
877 if (oneTrain[
"name"].
toString() == train)
882 return INDIListener::findDevice(oneTrain[
"mount"].
toString(), generic);
884 return INDIListener::findDevice(oneTrain[
"camera"].
toString(), generic);
886 return INDIListener::findDevice(oneTrain[
"rotator"].
toString(), generic);
888 return INDIListener::findDevice(oneTrain[
"guider"].
toString(), generic);
890 return INDIListener::findDevice(oneTrain[
"dustcap"].
toString(), generic);
892 return INDIListener::findDevice(oneTrain[
"filterwheel"].
toString(), generic);
894 return INDIListener::findDevice(oneTrain[
"focuser"].
toString(), generic);
896 return INDIListener::findDevice(oneTrain[
"lightbox"].
toString(), generic);
899 auto devices = INDIListener::devicesByInterface(INDI::BaseDevice::DOME_INTERFACE);
900 if (!devices.empty())
902 generic = devices[0];
911 auto devices = INDIListener::devicesByInterface(INDI::BaseDevice::WEATHER_INTERFACE);
912 if (!devices.empty())
914 generic = devices[0];
923 auto devices = INDIListener::devicesByInterface(INDI::BaseDevice::GPS_INTERFACE);
924 if (!devices.empty())
926 generic = devices[0];
946 for (
auto &oneTrain : m_OpticalTrains)
948 if (oneTrain[
"name"].
toString() == name)
951 if (INDIListener::findDevice(oneTrain[
"mount"].
toString(), generic))
952 return generic->getMount();
964 for (
auto &oneTrain : m_OpticalTrains)
966 if (oneTrain[
"name"].
toString() == name)
969 if (INDIListener::findDevice(oneTrain[
"dustcap"].
toString(), generic))
970 return generic->getDustCap();
982 for (
auto &oneTrain : m_OpticalTrains)
984 if (oneTrain[
"name"].
toString() == name)
987 if (INDIListener::findDevice(oneTrain[
"lightbox"].
toString(), generic))
988 return generic->getLightBox();
1001 for (
auto &oneTrain : m_OpticalTrains)
1003 if (oneTrain[
"name"].
toString() == name)
1005 if (
KStars::Instance()->data()->userdb()->getOpticalElementByName(oneTrain[
"scope"].
toString(), oneOpticalElement))
1006 return oneOpticalElement;
1010 return oneOpticalElement;
1016double OpticalTrainManager::getReducer(
const QString &name)
1018 for (
auto &oneTrain : m_OpticalTrains)
1020 if (oneTrain[
"name"].
toString() == name)
1021 return oneTrain[
"reducer"].toDouble();
1032 for (
auto &oneTrain : m_OpticalTrains)
1034 if (oneTrain[
"name"].
toString() == name)
1037 if (INDIListener::findDevice(oneTrain[
"rotator"].
toString(), generic))
1038 return generic->getRotator();
1050 for (
auto &oneTrain : m_OpticalTrains)
1052 if (oneTrain[
"name"].
toString() == name)
1055 if (INDIListener::findDevice(oneTrain[
"focuser"].
toString(), generic))
1056 return generic->getFocuser();
1066ISD::FilterWheel *OpticalTrainManager::getFilterWheel(
const QString &name)
1068 for (
auto &oneTrain : m_OpticalTrains)
1070 if (oneTrain[
"name"].
toString() == name)
1073 if (INDIListener::findDevice(oneTrain[
"filterwheel"].
toString(), generic))
1074 return generic->getFilterWheel();
1086 for (
auto &oneTrain : m_OpticalTrains)
1088 if (oneTrain[
"name"].
toString() == name)
1091 if (INDIListener::findDevice(oneTrain[
"camera"].
toString(), generic))
1092 return generic->getCamera();
1102ISD::Guider *OpticalTrainManager::getGuider(
const QString &name)
1104 for (
auto &oneTrain : m_OpticalTrains)
1106 if (oneTrain[
"name"].
toString() == name)
1109 if (INDIListener::findDevice(oneTrain[
"guider"].
toString(), generic))
1110 return generic->getGuider();
1124 for (
auto &oneTrain : m_OpticalTrains)
1126 if (oneTrain[
"name"].
toString() == name)
1129 if (INDIListener::findDevice(oneTrain[
"adaptiveoptics"].
toString(), generic))
1130 return generic->getAdaptiveOptics();
1140const QVariantMap OpticalTrainManager::getOpticalTrain(uint8_t
id)
const
1142 for (
auto &oneTrain : m_OpticalTrains)
1144 if (oneTrain[
"id"].toInt() ==
id)
1148 return QVariantMap();
1154bool OpticalTrainManager::exists(uint8_t
id)
const
1156 for (
auto &oneTrain : m_OpticalTrains)
1158 if (oneTrain[
"id"].toInt() ==
id)
1168const QVariantMap OpticalTrainManager::getOpticalTrain(
const QString &name)
const
1170 for (
auto &oneTrain : m_OpticalTrains)
1172 if (oneTrain[
"name"].
toString() == name)
1176 return QVariantMap();
1182void OpticalTrainManager::refreshTrains()
1191void OpticalTrainManager::refreshOpticalElements()
1194 syncDelegatesToDevices();
1200int OpticalTrainManager::id(
const QString &name)
const
1202 for (
auto &oneTrain : m_OpticalTrains)
1204 if (oneTrain[
"name"].
toString() == name)
1205 return oneTrain[
"id"].toUInt();
1214QString OpticalTrainManager::name(
int id)
const
1216 for (
auto &oneTrain : m_OpticalTrains)
1218 if (oneTrain[
"id"].toInt() ==
id)
1219 return oneTrain[
"name"].toString();
1228void OpticalTrainManager::checkMissingDevices()
1231 auto devices = getMissingDevices();
1232 if (!devices.empty())
1234 if (devices.count() == 1)
1237 i18n(
"Missing device detected (%1). Please reconfigure the optical trains before proceeding any further.",
1239 KSNotification::General, KSNotification::Warn);
1244 i18n(
"Missing devices detected (%1). Please reconfigure the optical trains before proceeding any further.",
1245 devices.join(
", ")),
1246 KSNotification::General, KSNotification::Warn);
1250 emit configurationRequested(
true);
1257QStringList OpticalTrainManager::getMissingDevices()
const
1260 for (
auto &oneTrain : m_OpticalTrains)
1262 auto mount = oneTrain[
"mount"].toString();
1263 if (mount !=
"--" && m_MountNames.contains(mount) ==
false)
1266 auto camera = oneTrain[
"camera"].toString();
1267 if (camera !=
"--" && m_CameraNames.contains(camera) ==
false)
1270 auto dustcap = oneTrain[
"dustcap"].toString();
1271 if (dustcap !=
"--" && m_DustCapNames.contains(dustcap) ==
false)
1274 auto lightbox = oneTrain[
"lightbox"].toString();
1275 if (lightbox !=
"--" && m_LightBoxNames.contains(lightbox) ==
false)
1276 missing << lightbox;
1278 auto focuser = oneTrain[
"focuser"].toString();
1279 if (focuser !=
"--" && m_FocuserNames.contains(focuser) ==
false)
1282 auto filterwheel = oneTrain[
"filterwheel"].toString();
1283 if (filterwheel !=
"--" && m_FilterWheelNames.contains(filterwheel) ==
false)
1284 missing << filterwheel;
1286 auto guider = oneTrain[
"guider"].toString();
1287 if (guider !=
"--" && m_GuiderNames.contains(guider) ==
false)
1298void Ekos::OpticalTrainManager::updateOpticalTrainValue(
QComboBox *cb,
const QString &element)
1300 if (trainNamesList->currentItem() !=
nullptr && m_Persistent ==
true)
1301 setOpticalTrainValue(trainNamesList->currentItem()->text(), element, cb->
currentText());
1307void OpticalTrainManager::updateOpticalTrainValue(
double value,
const QString &element)
1309 if (trainNamesList->currentItem() !=
nullptr && m_Persistent ==
true)
1310 setOpticalTrainValue(trainNamesList->currentItem()->text(), element, value);
1317void OpticalTrainManager::reset()
1319 if (m_CurrentOpticalTrain !=
nullptr)
1321 auto id = m_CurrentOpticalTrain->value(
"id");
1322 auto name = m_CurrentOpticalTrain->value(
"name");
1323 int row = trainNamesList->currentRow();
1324 m_CurrentOpticalTrain->clear();
1326 m_CurrentOpticalTrain->insert(
"id",
id);
1327 m_CurrentOpticalTrain->insert(
"name", name);
1328 m_CurrentOpticalTrain->insert(
"mount",
"--");
1329 m_CurrentOpticalTrain->insert(
"camera",
"--");
1330 m_CurrentOpticalTrain->insert(
"rotator",
"--");
1331 m_CurrentOpticalTrain->insert(
"guider",
"--");
1332 m_CurrentOpticalTrain->insert(
"dustcap",
"--");
1333 m_CurrentOpticalTrain->insert(
"scope",
"--");
1334 m_CurrentOpticalTrain->insert(
"filterwheel",
"--");
1335 m_CurrentOpticalTrain->insert(
"focuser",
"--");
1336 m_CurrentOpticalTrain->insert(
"reducer", 1);
1337 m_CurrentOpticalTrain->insert(
"lightbox",
"--");
1341 selectOpticalTrain(
name.toString());
1342 trainNamesList->setCurrentRow(row);
AdaptiveOptics class handles control of INDI AdaptiveOptics devices.
Camera class controls an INDI Camera device.
Handles operation of a remotely controlled dust cover cap.
Focuser class handles control of INDI focuser devices.
Handles operation of a remotely controlled light box.
device handle controlling Mounts.
Rotator class handles control of INDI Rotator devices.
bool AddOpticalTrain(const QVariantMap &oneTrain)
Add a new optical train to the database.
bool GetOpticalTrains(uint32_t profileID, QList< QVariantMap > &opticalTrains)
Populate the reference passed with all optical trains.
bool UpdateOpticalTrain(const QVariantMap &oneTrain, int id)
Update an existing optical train.
This is the main window for KStars.
static KStars * Instance()
KStarsData * data() const
Information on telescope used in observation.
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
Ekos is an advanced Astrophotography tool for Linux.
QString name(GameStandardAction id)
KIOCORE_EXPORT SimpleJob * mount(bool ro, const QByteArray &fstype, const QString &dev, const QString &point, JobFlags flags=DefaultFlags)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
void currentIndexChanged(int index)
void finished(int result)
void valueChanged(double d)
QVariantMap toVariantMap() const const
void append(QList< T > &&value)
qsizetype count() const const
iterator erase(const_iterator begin, const_iterator end)
bool isEmpty() const const
QString text() const const
QSqlDatabase database(const QString &connectionName, bool open)
QString fieldName(int index) const const
QVariant value(const QString &name) const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)