From kde-commits Sat Sep 30 19:55:52 2017 From: Jasem Mutlaq Date: Sat, 30 Sep 2017 19:55:52 +0000 To: kde-commits Subject: [kstars/filtermanager] kstars/ekos/focus: Migrate focus module to Filter Manager. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=150680277926550 Git commit dc898c9a46a3a8b8ed661a12fd011d1249b5bebe by Jasem Mutlaq. Committed on 30/09/2017 at 19:53. Pushed by mutlaqja into branch 'filtermanager'. Migrate focus module to Filter Manager. M +96 -160 kstars/ekos/focus/focus.cpp M +7 -29 kstars/ekos/focus/focus.h M +17 -10 kstars/ekos/focus/focus.ui https://commits.kde.org/kstars/dc898c9a46a3a8b8ed661a12fd011d1249b5bebe diff --git a/kstars/ekos/focus/focus.cpp b/kstars/ekos/focus/focus.cpp index 43d254c5f..55a0a47ed 100644 --- a/kstars/ekos/focus/focus.cpp +++ b/kstars/ekos/focus/focus.cpp @@ -55,6 +55,8 @@ Focus::Focus() //fy=3Dfw=3Dfh=3D0; HFRFrames.clear(); = + FilterDevicesCombo->addItem("--"); + showFITSViewerB->setIcon( QIcon::fromTheme("kstars_fitsviewer", QIcon(":/icons/breeze/defaul= t/kstars_fitsviewer.svg"))); showFITSViewerB->setAttribute(Qt::WA_LayoutUsesWidgetRect); @@ -94,9 +96,8 @@ Focus::Focus() }); = connect(focuserCombo, SIGNAL(activated(int)), this, SLOT(checkFocuser(= int))); - connect(FilterCaptureCombo, SIGNAL(activated(int)), this, SLOT(checkFi= lter(int))); - connect(FilterPosCombo, SIGNAL(activated(int)), this, SLOT(updateFilte= rPos(int))); - connect(lockFilterCheck, SIGNAL(toggled(bool)), this, SLOT(filterLockT= oggled(bool))); + connect(FilterDevicesCombo, SIGNAL(activated(int)), this, SLOT(checkFi= lter(int))); + connect(FilterPosCombo, SIGNAL(activated(int)), this, SLOT(updateFilte= rPos(int))); = connect(setAbsTicksB, SIGNAL(clicked()), this, SLOT(setAbsoluteFocusTi= cks())); connect(binningCombo, SIGNAL(activated(int)), this, SLOT(setActiveBinn= ing(int))); connect(focusBoxSize, SIGNAL(valueChanged(int)), this, SLOT(updateBoxS= ize(int))); @@ -220,8 +221,7 @@ Focus::Focus() focusBoxSize->setValue(Options::focusBoxSize()); maxTravelIN->setValue(Options::focusMaxTravel()); useSubFrame->setChecked(Options::focusSubFrame()); - suspendGuideCheck->setChecked(Options::suspendGuiding()); - lockFilterCheck->setChecked(Options::lockFocusFilter()); + suspendGuideCheck->setChecked(Options::suspendGuiding()); = darkFrameCheck->setChecked(Options::useFocusDarkFrame()); thresholdSpin->setValue(Options::focusThreshold()); useFullField->setChecked(Options::focusUseFullField()); @@ -423,28 +423,25 @@ void Focus::addFilter(ISD::GDInterface *newFilter) } = FilterCaptureLabel->setEnabled(true); - FilterCaptureCombo->setEnabled(true); + FilterDevicesCombo->setEnabled(true); FilterPosLabel->setEnabled(true); - FilterPosCombo->setEnabled(true); - lockFilterCheck->setEnabled(true); + FilterPosCombo->setEnabled(true); = = - FilterCaptureCombo->addItem(newFilter->getDeviceName()); + FilterDevicesCombo->addItem(newFilter->getDeviceName()); = Filters.append(static_cast(newFilter)); = - checkFilter(0); - - FilterCaptureCombo->setCurrentIndex(0); + checkFilter(1); = - refreshFilterExposure(); + FilterDevicesCombo->setCurrentIndex(1); } = bool Focus::setFilter(QString device, int filterSlot) { bool deviceFound =3D false; = - for (int i =3D 0; i < FilterCaptureCombo->count(); i++) - if (device =3D=3D FilterCaptureCombo->itemText(i)) + for (int i =3D 0; i < FilterDevicesCombo->count(); i++) + if (device =3D=3D FilterDevicesCombo->itemText(i)) { checkFilter(i); deviceFound =3D true; @@ -454,8 +451,8 @@ bool Focus::setFilter(QString device, int filterSlot) if (deviceFound =3D=3D false) return false; = - if (filterSlot < FilterCaptureCombo->count()) - FilterCaptureCombo->setCurrentIndex(filterSlot); + if (filterSlot < FilterDevicesCombo->count()) + FilterDevicesCombo->setCurrentIndex(filterSlot); = return true; } @@ -464,102 +461,34 @@ void Focus::checkFilter(int filterNum) { if (filterNum =3D=3D -1) { - filterNum =3D FilterCaptureCombo->currentIndex(); + filterNum =3D FilterDevicesCombo->currentIndex(); if (filterNum =3D=3D -1) return; } = - QStringList filterAlias =3D Options::filterAlias(); - - bool deviceChanged =3D false; - if (filterNum <=3D Filters.count()) - { - if (currentFilter !=3D Filters.at(filterNum) || filterName =3D=3D = nullptr) - deviceChanged =3D true; - currentFilter =3D Filters.at(filterNum); - } - - FilterPosCombo->clear(); - - filterName =3D currentFilter->getBaseDevice()->getText("FILTER_NAME"); - filterSlot =3D currentFilter->getBaseDevice()->getNumber("FILTER_SLOT"= ); - - if (filterSlot =3D=3D nullptr) + // "--" is no filter + if (filterNum =3D=3D 0) { - KMessageBox::error(0, i18n("Unable to find FILTER_SLOT property in= driver %1", - currentFilter->getBaseDevice()->getDevi= ceName())); + currentFilter =3D nullptr; + currentFilterPosition=3D-1; + FilterPosCombo->clear(); return; } = - currentFilterIndex =3D filterSlot->np[0].value - 1; - - for (int i =3D 0; i < filterSlot->np[0].max; i++) - { - QString item; - - if (filterName !=3D nullptr && (i < filterName->ntp)) - item =3D filterName->tp[i].text; - else if (i < filterAlias.count() && filterAlias[i].isEmpty() =3D= =3D false) - item =3D filterAlias.at(i); - else - item =3D QString("Filter_%1").arg(i + 1); + if (filterNum <=3D Filters.count()) + currentFilter =3D Filters.at(filterNum-1); = - FilterPosCombo->addItem(item); - } + filterManager->setCurrentFilter(currentFilter); = - if (lockFilterCheck->isChecked() =3D=3D false) - FilterPosCombo->setCurrentIndex(currentFilterIndex); - else - { - if (lockedFilterIndex < 0) - { - //lockedFilterIndex =3D currentFilterIndex; - lockedFilterIndex =3D Options::lockFocusFilterIndex(); - emit filterLockUpdated(currentFilter, lockedFilterIndex); - } - FilterPosCombo->setCurrentIndex(lockedFilterIndex); - } - - // If we are waiting to change the filter wheel, let's check if the co= ndition is now met. - if (filterPositionPending) - { - if (lockedFilterIndex =3D=3D currentFilterIndex) - { - filterPositionPending =3D false; - capture(); - } - } + FilterPosCombo->clear(); = - if (deviceChanged) - refreshFilterExposure(); -} + FilterPosCombo->addItems(filterManager->getFilterLabels()); = -void Focus::filterLockToggled(bool enable) -{ - if (enable) - { - lockedFilterIndex =3D FilterPosCombo->currentIndex(); - if (lockedFilterIndex >=3D 0) - Options::setLockFocusFilterIndex(lockedFilterIndex); - emit filterLockUpdated(currentFilter, lockedFilterIndex); - } - else if (filterSlot !=3D nullptr) - { - FilterPosCombo->setCurrentIndex(filterSlot->np[0].value - 1); - emit filterLockUpdated(nullptr, 0); - } -} + currentFilterPosition =3D filterManager->getFilterPosition(); = -void Focus::updateFilterPos(int index) -{ - if (lockFilterCheck->isChecked() =3D=3D true) - { - lockedFilterIndex =3D index; - Options::setLockFocusFilterIndex(lockedFilterIndex); - emit filterLockUpdated(currentFilter, lockedFilterIndex); - } + FilterPosCombo->setCurrentIndex(currentFilterPosition-1); = - refreshFilterExposure(); + exposureIN->setValue(filterManager->getFilterExposure()); } = void Focus::addFocuser(ISD::GDInterface *newFocuser) @@ -761,8 +690,7 @@ void Focus::start() Options::setFocusBoxSize(focusBoxSize->value()); Options::setFocusSubFrame(useSubFrame->isChecked()); Options::setFocusAutoStarEnabled(useAutoStar->isChecked()); - Options::setSuspendGuiding(suspendGuideCheck->isChecked()); - Options::setLockFocusFilter(lockFilterCheck->isChecked()); + Options::setSuspendGuiding(suspendGuideCheck->isChecked()); = Options::setUseFocusDarkFrame(darkFrameCheck->isChecked()); Options::setFocusFramesCount(focusFramesSpin->value()); = @@ -887,7 +815,7 @@ void Focus::capture() currentCCD->setBLOBEnabled(true); } = - if (currentFilter !=3D nullptr && lockFilterCheck->isChecked()) + if (currentFilter !=3D nullptr) { if (currentFilter->isConnected() =3D=3D false) { @@ -895,12 +823,13 @@ void Focus::capture() return; } = - if (lockedFilterIndex !=3D currentFilterIndex) - { - int lockedFilterPosition =3D lockedFilterIndex + 1; + if (FilterPosCombo->currentIndex()+1 !=3D currentFilterPosition) + { = filterPositionPending =3D true; - appendLogText(i18n("Changing filter to %1", FilterPosCombo->cu= rrentText())); - currentFilter->runCommand(INDI_SET_FILTER, &lockedFilterPositi= on); + int targetPosition =3D FilterPosCombo->currentIndex() + 1; + // Only apply change filter and offset policies. Do not lock o= r autofocus as we are calling this from with + // focus module + filterManager->setFilterPosition(targetPosition, static_cast(FilterManager::CHANGE_POLICY|FilterManager::OFF= SET_POLICY)); return; } } @@ -1406,9 +1335,9 @@ void Focus::setCaptureComplete() starCenter.setY(subH / (2 * subBinY)); starCenter.setZ(subBinX); = - subFramed =3D true; + subFramed =3D true; = = - focusView->setFirstLoad(true); + focusView->setFirstLoad(true); = = capture(); } @@ -1454,6 +1383,7 @@ void Focus::setCaptureComplete() = if (minimumRequiredHFR >=3D 0) { + if (currentHFR =3D=3D -1) { if (noStarCount++ < MAX_RECAPTURE_RETRIES) @@ -2762,57 +2692,6 @@ bool Focus::findMinimum(double expected, double *pos= ition, double *hfr) return (status =3D=3D GSL_SUCCESS); } = -void Focus::saveFilterExposure() -{ - // Find matching filter if any and save its exposure - OAL::Filter *matchedFilter =3D nullptr; - - foreach (OAL::Filter *o, m_filterList) - { - if (o->vendor() =3D=3D FilterCaptureCombo->currentText() && o->col= or() =3D=3D FilterPosCombo->currentText()) - { - matchedFilter =3D o; - break; - } - } - -#if 0 - // If doesn't exist, create one - if (matchedFilter =3D=3D nullptr) - KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->cu= rrentText(), "", "", "0", - FilterPosCombo->curren= tText(), - QString::number(exposu= reIN->value())); - // Or update existing - else - KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->cu= rrentText(), "", "", matchedFilter->offset(), - matchedFilter->color()= , QString::number(exposureIN->value()), - matchedFilter->id()); -#endif - // Reload - KStarsData::Instance()->userdb()->GetAllFilters(m_filterList); -} - -void Focus::refreshFilterExposure() -{ - KStarsData::Instance()->userdb()->GetAllFilters(m_filterList); - OAL::Filter *matchedFilter =3D nullptr; - - foreach (OAL::Filter *o, m_filterList) - { - if (o->vendor() =3D=3D FilterCaptureCombo->currentText() && o->col= or() =3D=3D FilterPosCombo->currentText()) - { - matchedFilter =3D o; - break; - } - } - - if (matchedFilter) - exposureIN->setValue(matchedFilter->exposure().toDouble()); - else - // Default value - exposureIN->setValue(1); -} - void Focus::removeDevice(ISD::GDInterface *deviceRemoved) { // Check in Focusers @@ -2854,4 +2733,61 @@ void Focus::removeDevice(ISD::GDInterface *deviceRem= oved) } } } + +void Focus::setFilterManager(const QSharedPointer &manager) +{ + filterManager =3D manager; + connect(filterManagerB, &QPushButton::clicked, [this]() + { + filterManager->show(); + filterManager->raise(); + }); + + connect(filterManager.data(), &FilterManager::ready, [this]() + { + if (filterPositionPending) + { + filterPositionPending =3D false; + capture(); + } + } + ); + + connect(filterManager.data(), &FilterManager::failed, [this]() + { + appendLogText(i18n("Filter operation failed.")); + abort(); + } + ); + + connect(exposureIN, &QDoubleSpinBox::editingFinished, [this]() + { + filterManager->setFilterExposure(exposureIN->value()); + }); + + connect(filterManager.data(), &FilterManager::labelsChanged, this, [th= is]() + { + FilterPosCombo->clear(); + FilterPosCombo->addItems(filterManager->getFilterLabels()); + currentFilterPosition =3D filterManager->getFilterPosition(); + FilterPosCombo->setCurrentIndex(currentFilterPosition-1); + }); + connect(filterManager.data(), &FilterManager::positionChanged, this, [= this]() + { + currentFilterPosition =3D filterManager->getFilterPosition(); + FilterPosCombo->setCurrentIndex(currentFilterPosition-1); + }); + connect(filterManager.data(), &FilterManager::exposureChanged, this, [= this]() + { + exposureIN->setValue(filterManager->getFilterExposure()); + ;}); + + connect(FilterPosCombo, static_cast(&QComboBox::currentIndexChanged), + [=3D](const QString &text) + { + exposureIN->setValue(filterManager->getFilterExposure(text)); + } + ); +} + } diff --git a/kstars/ekos/focus/focus.h b/kstars/ekos/focus/focus.h index fa24e7c5c..cc32a7bf2 100644 --- a/kstars/ekos/focus/focus.h +++ b/kstars/ekos/focus/focus.h @@ -11,12 +11,12 @@ = #include "ui_focus.h" #include "ekos/ekos.h" +#include "ekos/auxiliary/filtermanager.h" #include "fitsviewer/fitsviewer.h" #include "indi/indiccd.h" #include "indi/indifocuser.h" #include "indi/indistd.h" #include "indi/inditelescope.h" -#include "oal/filter.h" = #include = @@ -27,7 +27,7 @@ namespace Ekos * @short Supports manual focusing and auto focusing using relative and ab= solute INDI focusers. * * @author Jasem Mutlaq - * @version 1.2 + * @version 1.3 */ class Focus : public QWidget, public Ui::Focus { @@ -157,6 +157,8 @@ class Focus : public QWidget, public Ui::Focus */ void removeDevice(ISD::GDInterface *deviceRemoved); = + void setFilterManager(const QSharedPointer &manager); + void clearLog(); QString getLogText() { return logText.join("\n"); } = @@ -284,17 +286,6 @@ class Focus : public QWidget, public Ui::Focus void setMountStatus(ISD::Telescope::TelescopeStatus newState); = private slots: - /** - * @brief filterLockToggled Process filter locking/unlocking. Filt= er lock causes the autofocus process to use the selected filter whenever it= runs. - */ - void filterLockToggled(bool); - - /** - * @brief updateFilterPos If filter locking is checked, set the lo= cked filter to the current filter position - * @param index current filter position - */ - void updateFilterPos(int index); - /** * @brief toggleSubframe Process enabling and disabling subfrag. * @param enable If true, subframing is enabled. If false, subfram= ing is disabled. Even if subframing is enabled, it must be supported by the= CCD driver. @@ -321,24 +312,11 @@ class Focus : public QWidget, public Ui::Focus = void toggleFocusingWidgetFullScreen(); = - /** - * @brief saveFilterExposure Save filter exposure value in database - */ - void saveFilterExposure(); - - /** - * @brief refreshFilterExposure Load filter exposure value from DB= and apply it to current exposure value - */ - void refreshFilterExposure(); - - //void registerFocusProperty(INDI::Property *prop); - signals: void newLog(); //void autoFocusFinished(bool status, double finalHFR); void suspendGuiding(); void resumeGuiding(); - void filterLockUpdated(ISD::GDInterface *filter, int lockedIndex); void newStatus(Ekos::FocusState state); void newStarPixmap(QPixmap &); void newProfilePixmap(QPixmap &); @@ -369,7 +347,7 @@ class Focus : public QWidget, public Ui::Focus /// Optional device filter ISD::GDInterface *currentFilter { nullptr }; /// Current filter position - int currentFilterIndex { -1 }; + int currentFilterPosition { -1 }; /// True if we need to change filter position and wait for result befo= re continuing capture bool filterPositionPending { false }; = @@ -529,7 +507,7 @@ class Focus : public QWidget, public Ui::Focus std::vector coeff; int polySolutionFound { 0 }; = - /// Filters from DB - QList m_filterList; + // Filter Manager + QSharedPointer filterManager; }; } diff --git a/kstars/ekos/focus/focus.ui b/kstars/ekos/focus/focus.ui index 28badbcc0..41b8edf9d 100644 --- a/kstars/ekos/focus/focus.ui +++ b/kstars/ekos/focus/focus.ui @@ -374,7 +374,7 @@ - + false @@ -409,16 +409,22 @@ - - - false + + + + 22 + 22 + - If locked, the focus process will always use the sp= ecified filter when performing autofocus. -Otherwise, the autofocus process will utilize whatever filter currently se= t by the driver. + Filter Settings - Lock + + + + + :/icons/breeze/default/view-filter.svg:/icons/breeze/default/view-filter.svg @@ -944,7 +950,7 @@ Otherwise, the autofocus process will utilize whatever = filter currently set by t - FilterCaptureCombo + FilterDevicesCombo CCDCaptureCombo binningCombo startLoopB @@ -953,7 +959,6 @@ Otherwise, the autofocus process will utilize whatever = filter currently set by t ISOCombo exposureIN FilterPosCombo - lockFilterCheck absTicksLabel filterCombo focusInB @@ -983,6 +988,8 @@ Otherwise, the autofocus process will utilize whatever = filter currently set by t relativeProfileB useFullField - + + +