[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kstars/filtermanager] kstars/ekos/focus: Migrate focus module to Filter Manager.
From:       Jasem Mutlaq <null () kde ! org>
Date:       2017-09-30 19:55:52
Message-ID: E1dyNrc-0002Vj-Ie () code ! kde ! org
[Download RAW message or body]

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=fw=fh=0;
     HFRFrames.clear();
 
+    FilterDevicesCombo->addItem("--");
+
     showFITSViewerB->setIcon(
         QIcon::fromTheme("kstars_fitsviewer", \
QIcon(":/icons/breeze/default/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(checkFilter(int)));
-    connect(FilterPosCombo, SIGNAL(activated(int)), this, \
                SLOT(updateFilterPos(int)));
-    connect(lockFilterCheck, SIGNAL(toggled(bool)), this, \
SLOT(filterLockToggled(bool))); +    connect(FilterDevicesCombo, \
SIGNAL(activated(int)), this, SLOT(checkFilter(int))); +    connect(FilterPosCombo, \
                SIGNAL(activated(int)), this, SLOT(updateFilterPos(int)));    
     connect(setAbsTicksB, SIGNAL(clicked()), this, SLOT(setAbsoluteFocusTicks()));
     connect(binningCombo, SIGNAL(activated(int)), this, \
                SLOT(setActiveBinning(int)));
     connect(focusBoxSize, SIGNAL(valueChanged(int)), this, \
SLOT(updateBoxSize(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<ISD::Filter *>(newFilter));
 
-    checkFilter(0);
-
-    FilterCaptureCombo->setCurrentIndex(0);
+    checkFilter(1);
 
-    refreshFilterExposure();
+    FilterDevicesCombo->setCurrentIndex(1);
 }
 
 bool Focus::setFilter(QString device, int filterSlot)
 {
     bool deviceFound = false;
 
-    for (int i = 0; i < FilterCaptureCombo->count(); i++)
-        if (device == FilterCaptureCombo->itemText(i))
+    for (int i = 0; i < FilterDevicesCombo->count(); i++)
+        if (device == FilterDevicesCombo->itemText(i))
         {
             checkFilter(i);
             deviceFound = true;
@@ -454,8 +451,8 @@ bool Focus::setFilter(QString device, int filterSlot)
     if (deviceFound == 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 == -1)
     {
-        filterNum = FilterCaptureCombo->currentIndex();
+        filterNum = FilterDevicesCombo->currentIndex();
         if (filterNum == -1)
             return;
     }
 
-    QStringList filterAlias = Options::filterAlias();
-
-    bool deviceChanged = false;
-    if (filterNum <= Filters.count())
-    {
-        if (currentFilter != Filters.at(filterNum) || filterName == nullptr)
-            deviceChanged = true;
-        currentFilter = Filters.at(filterNum);
-    }
-
-    FilterPosCombo->clear();
-
-    filterName = currentFilter->getBaseDevice()->getText("FILTER_NAME");
-    filterSlot = currentFilter->getBaseDevice()->getNumber("FILTER_SLOT");
-
-    if (filterSlot == nullptr)
+    // "--" is no filter
+    if (filterNum == 0)
     {
-        KMessageBox::error(0, i18n("Unable to find FILTER_SLOT property in driver \
                %1",
-                                   \
currentFilter->getBaseDevice()->getDeviceName())); +        currentFilter = nullptr;
+        currentFilterPosition=-1;
+        FilterPosCombo->clear();
         return;
     }
 
-    currentFilterIndex = filterSlot->np[0].value - 1;
-
-    for (int i = 0; i < filterSlot->np[0].max; i++)
-    {
-        QString item;
-
-        if (filterName != nullptr && (i < filterName->ntp))
-            item = filterName->tp[i].text;
-        else if (i < filterAlias.count() && filterAlias[i].isEmpty() == false)
-            item = filterAlias.at(i);
-        else
-            item = QString("Filter_%1").arg(i + 1);
+    if (filterNum <= Filters.count())
+        currentFilter = Filters.at(filterNum-1);
 
-        FilterPosCombo->addItem(item);
-    }
+    filterManager->setCurrentFilter(currentFilter);
 
-    if (lockFilterCheck->isChecked() == false)
-        FilterPosCombo->setCurrentIndex(currentFilterIndex);
-    else
-    {
-        if (lockedFilterIndex < 0)
-        {
-            //lockedFilterIndex = currentFilterIndex;
-            lockedFilterIndex = Options::lockFocusFilterIndex();
-            emit filterLockUpdated(currentFilter, lockedFilterIndex);
-        }
-        FilterPosCombo->setCurrentIndex(lockedFilterIndex);
-    }
-
-    // If we are waiting to change the filter wheel, let's check if the condition is \
                now met.
-    if (filterPositionPending)
-    {
-        if (lockedFilterIndex == currentFilterIndex)
-        {
-            filterPositionPending = false;
-            capture();
-        }
-    }
+    FilterPosCombo->clear();
 
-    if (deviceChanged)
-        refreshFilterExposure();
-}
+    FilterPosCombo->addItems(filterManager->getFilterLabels());
 
-void Focus::filterLockToggled(bool enable)
-{
-    if (enable)
-    {
-        lockedFilterIndex = FilterPosCombo->currentIndex();
-        if (lockedFilterIndex >= 0)
-            Options::setLockFocusFilterIndex(lockedFilterIndex);
-        emit filterLockUpdated(currentFilter, lockedFilterIndex);
-    }
-    else if (filterSlot != nullptr)
-    {
-        FilterPosCombo->setCurrentIndex(filterSlot->np[0].value - 1);
-        emit filterLockUpdated(nullptr, 0);
-    }
-}
+    currentFilterPosition = filterManager->getFilterPosition();
 
-void Focus::updateFilterPos(int index)
-{
-    if (lockFilterCheck->isChecked() == true)
-    {
-        lockedFilterIndex = 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 != nullptr && lockFilterCheck->isChecked())
+    if (currentFilter != nullptr)
     {
         if (currentFilter->isConnected() == false)
         {
@@ -895,12 +823,13 @@ void Focus::capture()
             return;
         }
 
-        if (lockedFilterIndex != currentFilterIndex)
-        {
-            int lockedFilterPosition = lockedFilterIndex + 1;
+        if (FilterPosCombo->currentIndex()+1 != currentFilterPosition)
+        {            
             filterPositionPending    = true;
-            appendLogText(i18n("Changing filter to %1", \
                FilterPosCombo->currentText()));
-            currentFilter->runCommand(INDI_SET_FILTER, &lockedFilterPosition);
+            int targetPosition = FilterPosCombo->currentIndex() + 1;
+            // Only apply change filter and offset policies. Do not lock or \
autofocus as we are calling this from with +            // focus module
+            filterManager->setFilterPosition(targetPosition, \
static_cast<FilterManager::FilterPolicy>(FilterManager::CHANGE_POLICY|FilterManager::OFFSET_POLICY));
  return;
         }
     }
@@ -1406,9 +1335,9 @@ void Focus::setCaptureComplete()
                 starCenter.setY(subH / (2 * subBinY));
                 starCenter.setZ(subBinX);
 
-                subFramed = true;
+                subFramed = true;                
 
-                focusView->setFirstLoad(true);
+                focusView->setFirstLoad(true);                
 
                 capture();
             }
@@ -1454,6 +1383,7 @@ void Focus::setCaptureComplete()
 
     if (minimumRequiredHFR >= 0)
     {
+
         if (currentHFR == -1)
         {
             if (noStarCount++ < MAX_RECAPTURE_RETRIES)
@@ -2762,57 +2692,6 @@ bool Focus::findMinimum(double expected, double *position, \
double *hfr)  return (status == GSL_SUCCESS);
 }
 
-void Focus::saveFilterExposure()
-{
-    // Find matching filter if any and save its exposure
-    OAL::Filter *matchedFilter = nullptr;
-
-    foreach (OAL::Filter *o, m_filterList)
-    {
-        if (o->vendor() == FilterCaptureCombo->currentText() && o->color() == \
                FilterPosCombo->currentText())
-        {
-            matchedFilter = o;
-            break;
-        }
-    }
-
-#if 0
-    // If doesn't exist, create one
-    if (matchedFilter == nullptr)
-        KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), \
                "", "", "0",
-                                                    FilterPosCombo->currentText(),
-                                                    \
                QString::number(exposureIN->value()));
-    // Or update existing
-    else
-        KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), \
                "", "", 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 = nullptr;
-
-    foreach (OAL::Filter *o, m_filterList)
-    {
-        if (o->vendor() == FilterCaptureCombo->currentText() && o->color() == \
                FilterPosCombo->currentText())
-        {
-            matchedFilter = 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 *deviceRemoved)
         }
     }
 }
+
+void Focus::setFilterManager(const QSharedPointer<FilterManager> &manager)
+{
+    filterManager = manager;
+    connect(filterManagerB, &QPushButton::clicked, [this]()
+    {
+        filterManager->show();
+        filterManager->raise();
+    });
+
+    connect(filterManager.data(), &FilterManager::ready, [this]()
+    {
+        if (filterPositionPending)
+        {
+            filterPositionPending = 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, [this]()
+    {
+        FilterPosCombo->clear();
+        FilterPosCombo->addItems(filterManager->getFilterLabels());
+        currentFilterPosition = filterManager->getFilterPosition();
+        FilterPosCombo->setCurrentIndex(currentFilterPosition-1);
+    });
+    connect(filterManager.data(), &FilterManager::positionChanged, this, [this]()
+    {
+        currentFilterPosition = filterManager->getFilterPosition();
+        FilterPosCombo->setCurrentIndex(currentFilterPosition-1);
+    });
+    connect(filterManager.data(), &FilterManager::exposureChanged, this, [this]()
+    {
+        exposureIN->setValue(filterManager->getFilterExposure());
+    ;});
+
+    connect(FilterPosCombo, static_cast<void(QComboBox::*)(const QString \
&)>(&QComboBox::currentIndexChanged), +            [=](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 <QtDBus/QtDBus>
 
@@ -27,7 +27,7 @@ namespace Ekos
  * @short Supports manual focusing and auto focusing using relative and absolute \
                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<FilterManager> &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. Filter 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 locked \
                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, subframing 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 before \
continuing capture  bool filterPositionPending { false };
 
@@ -529,7 +507,7 @@ class Focus : public QWidget, public Ui::Focus
     std::vector<double> coeff;
     int polySolutionFound { 0 };
 
-    /// Filters from DB
-    QList<OAL::Filter *> m_filterList;
+    // Filter Manager
+    QSharedPointer<FilterManager> 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 @@
            </widget>
           </item>
           <item row="2" column="1">
-           <widget class="QComboBox" name="FilterCaptureCombo">
+           <widget class="QComboBox" name="FilterDevicesCombo">
             <property name="enabled">
              <bool>false</bool>
             </property>
@@ -409,16 +409,22 @@
              </widget>
             </item>
             <item>
-             <widget class="QCheckBox" name="lockFilterCheck">
-              <property name="enabled">
-               <bool>false</bool>
+             <widget class="QPushButton" name="filterManagerB">
+              <property name="maximumSize">
+               <size>
+                <width>22</width>
+                <height>22</height>
+               </size>
               </property>
               <property name="toolTip">
-               <string>If locked, the focus process will always use the specified \
                filter when performing autofocus.
-Otherwise, the autofocus process will utilize whatever filter currently set by the \
driver.</string> +               <string>Filter Settings</string>
               </property>
               <property name="text">
-               <string>Lock</string>
+               <string/>
+              </property>
+              <property name="icon">
+               <iconset resource="../../data/kstars.qrc">
+                <normaloff>:/icons/breeze/default/view-filter.svg</normaloff>:/icons/breeze/default/view-filter.svg</iconset>
  </property>
              </widget>
             </item>
@@ -944,7 +950,7 @@ Otherwise, the autofocus process will utilize whatever filter \
currently set by t  </customwidget>
  </customwidgets>
  <tabstops>
-  <tabstop>FilterCaptureCombo</tabstop>
+  <tabstop>FilterDevicesCombo</tabstop>
   <tabstop>CCDCaptureCombo</tabstop>
   <tabstop>binningCombo</tabstop>
   <tabstop>startLoopB</tabstop>
@@ -953,7 +959,6 @@ Otherwise, the autofocus process will utilize whatever filter \
currently set by t  <tabstop>ISOCombo</tabstop>
   <tabstop>exposureIN</tabstop>
   <tabstop>FilterPosCombo</tabstop>
-  <tabstop>lockFilterCheck</tabstop>
   <tabstop>absTicksLabel</tabstop>
   <tabstop>filterCombo</tabstop>
   <tabstop>focusInB</tabstop>
@@ -983,6 +988,8 @@ Otherwise, the autofocus process will utilize whatever filter \
currently set by t  <tabstop>relativeProfileB</tabstop>
   <tabstop>useFullField</tabstop>
  </tabstops>
- <resources/>
+ <resources>
+  <include location="../../data/kstars.qrc"/>
+ </resources>
  <connections/>
 </ui>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic