summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-09-05 03:12:45 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-09-05 03:12:45 (GMT)
commit7f7d2d208a038ec0bef9828bbe485dd557bd43d0 (patch)
tree6074b2e579b42300d58bbf18af02b58be02f6abb
parent0acf553c250d3498be85bed26746369aacaf684b (diff)
Initial work for dark library
-rw-r--r--kstars/CMakeLists.txt1
-rw-r--r--kstars/auxiliary/ksuserdb.cpp83
-rw-r--r--kstars/auxiliary/ksuserdb.h12
-rw-r--r--kstars/ekos/capture.cpp58
-rw-r--r--kstars/ekos/capture.h2
-rw-r--r--kstars/ekos/darklibrary.cpp54
-rw-r--r--kstars/ekos/darklibrary.h45
-rw-r--r--kstars/ekos/ekosmanager.cpp1
-rw-r--r--kstars/ekos/focus.cpp6
-rw-r--r--kstars/ekos/sequencejob.cpp9
-rw-r--r--kstars/ekos/sequencejob.h2
-rw-r--r--kstars/indi/indiccd.cpp14
-rw-r--r--kstars/indi/indiccd.h8
13 files changed, 256 insertions, 39 deletions
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index aad4fe3..e3ee4ce 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -117,6 +117,7 @@ if(INDI_FOUND)
ekos/dome.cpp
ekos/weather.cpp
ekos/dustcap.cpp
+ ekos/darklibrary.cpp
ekos/astrometryparser.cpp
ekos/offlineastrometryparser.cpp
ekos/onlineastrometryparser.cpp
diff --git a/kstars/auxiliary/ksuserdb.cpp b/kstars/auxiliary/ksuserdb.cpp
index 384dee9..54666b0 100644
--- a/kstars/auxiliary/ksuserdb.cpp
+++ b/kstars/auxiliary/ksuserdb.cpp
@@ -115,6 +115,20 @@ bool KSUserDB::Initialize() {
if (!query.exec("INSERT INTO driver (label, role, profile) VALUES ('Focuser Simulator', 'Focuser', 1)"))
qDebug() << query.lastError();
}
+
+ // If prior to 2.6.1 upgrade database for dark library tables
+ if (record.value("Version").toString() < "2.6.1")
+ {
+ QSqlQuery query(userdb_);
+ QString versionQuery = QString("UPDATE Version SET Version='%1'").arg(KSTARS_VERSION);
+
+ if (!query.exec(versionQuery))
+ qDebug() << query.lastError();
+
+ // Dark Frame
+ if (!query.exec("CREATE TABLE IF NOT EXISTS darkframe (id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, ccd TEXT NOT NULL, chip INTEGER DEFAULT 0, binX INTEGER, binY INTEGER, temperature REAL, duration REAL, filename TEXT NOT NULL, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)"))
+ qDebug() << query.lastError();
+ }
}
}
userdb_.close();
@@ -240,6 +254,8 @@ bool KSUserDB::RebuildDB() {
tables.append("INSERT INTO driver (label, role, profile) VALUES ('CCD Simulator', 'CCD', 1)");
tables.append("INSERT INTO driver (label, role, profile) VALUES ('Focuser Simulator', 'Focuser', 1)");
+ tables.append("CREATE TABLE IF NOT EXISTS darkframe (id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, ccd TEXT NOT NULL, chip INTEGER DEFAULT 0, binX INTEGER, binY INTEGER, temperature REAL, duration REAL, filename TEXT NOT NULL, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)");
+
for (int i = 0; i < tables.count(); ++i) {
QSqlQuery query(userdb_);
if (!query.exec(tables[i])) {
@@ -280,7 +296,7 @@ void KSUserDB::AddObserver(const QString& name, const QString& surname,
userdb_.close();
}
-int KSUserDB::FindObserver(const QString &name, const QString &surname) {
+bool KSUserDB::FindObserver(const QString &name, const QString &surname) {
userdb_.open();
QSqlTableModel users(0, userdb_);
users.setTable("user");
@@ -339,6 +355,71 @@ void KSUserDB::GetAllObservers(QList<Observer *> &observer_list) {
userdb_.close();
}
+/* Dark Library Section */
+
+void KSUserDB::AddDarkFrame(const QVariantMap &oneFrame)
+{
+ userdb_.open();
+ QSqlTableModel darkframe(0, userdb_);
+ darkframe.setTable("darkframe");
+ darkframe.select();
+
+ QSqlRecord record = darkframe.record();
+
+ // Remove PK so that it gets auto-incremented later
+ record.remove(0);
+ // Remove timestamp so that it gets auto-generated
+ record.remove(7);
+
+ for(QVariantMap::const_iterator iter = oneFrame.begin(); iter != oneFrame.end(); ++iter)
+ record.setValue(iter.key(), iter.value());
+
+ darkframe.insertRecord(-1, record);
+
+ darkframe.submitAll();
+
+ userdb_.close();
+}
+
+bool KSUserDB::DeleteDarkFrame(const QString &filename)
+{
+ userdb_.open();
+ QSqlTableModel darkframe(0, userdb_);
+ darkframe.setTable("darkframe");
+ darkframe.setFilter("filename = \'"+filename+"\'");
+
+ darkframe.select();
+
+ darkframe.removeRows(0, 1);
+ darkframe.submitAll();
+
+ userdb_.close();
+
+ return true;
+}
+
+void KSUserDB::GetAllDarkFrames(QList<QVariantMap> &darkFrames)
+{
+ darkFrames.clear();
+
+ userdb_.open();
+ QSqlTableModel darkframe(0, userdb_);
+ darkframe.setTable("darkframe");
+ darkframe.select();
+
+ for (int i =0; i < darkframe.rowCount(); ++i)
+ {
+ QVariantMap recordMap;
+ QSqlRecord record = darkframe.record(i);
+ for (int j=1; j < record.count(); j++)
+ recordMap[record.fieldName(j)] = record.value(j);
+
+ darkFrames.append(recordMap);
+ }
+
+ userdb_.close();
+}
+
/*
* Flag Section
*/
diff --git a/kstars/auxiliary/ksuserdb.h b/kstars/auxiliary/ksuserdb.h
index 674146f..e7e8a77 100644
--- a/kstars/auxiliary/ksuserdb.h
+++ b/kstars/auxiliary/ksuserdb.h
@@ -76,6 +76,14 @@ class KSUserDB {
void GetAllProfiles(QList<ProfileInfo *> &profiles);
/************************************************************************
+ ******************************* Dark Library****************************
+ ************************************************************************/
+
+ void AddDarkFrame(const QVariantMap &oneFrame);
+ bool DeleteDarkFrame(const QString &filename);
+ void GetAllDarkFrames(QList<QVariantMap> &darkFrames);
+
+ /************************************************************************
******************************* Observers ******************************
************************************************************************/
@@ -86,9 +94,9 @@ class KSUserDB {
/* @brief Returns the unique id of the user with given name & surname
*
- * @return int
+ * @return true if found, false otherwise
**/
- int FindObserver(const QString &name, const QString &surname);
+ bool FindObserver(const QString &name, const QString &surname);
/**
* @brief Removes the user with unique id as given by FindObserver
* Returns false if the user is not found
diff --git a/kstars/ekos/capture.cpp b/kstars/ekos/capture.cpp
index 2ec6846..cd885c5 100644
--- a/kstars/ekos/capture.cpp
+++ b/kstars/ekos/capture.cpp
@@ -34,6 +34,7 @@
#include "fitsviewer/fitsviewer.h"
#include "fitsviewer/fitsview.h"
+#include "darklibrary.h"
#include "ekosmanager.h"
#include "captureadaptor.h"
#include "ui_calibrationoptions.h"
@@ -97,7 +98,7 @@ Capture::Capture()
jobUnderEdit = false;
currentFilterPosition = -1;
- calibrationState = CALIBRATE_NONE;
+ //calibrationState = CALIBRATE_NONE;
meridianFlipStage = MF_NONE;
resumeGuidingAfterFlip = false;
@@ -844,9 +845,26 @@ void Capture::newFITS(IBLOB *bp)
return;
disconnect(currentCCD, SIGNAL(BLOBUpdated(IBLOB*)), this, SLOT(newFITS(IBLOB*)));
- disconnect(currentCCD, SIGNAL(newImage(QImage*, ISD::CCDChip*)), this, SLOT(sendNewImage(QImage*, ISD::CCDChip*)));
+ disconnect(currentCCD, SIGNAL(newImage(QImage*, ISD::CCDChip*)), this, SLOT(sendNewImage(QImage*, ISD::CCDChip*)));
- if (calibrationState == CALIBRATE_START)
+ // TODO implement this tomorrow
+ /*
+ if (useGuideHead == false && darkSubCheck->isChecked() && activeJob->isPreview())
+ {
+ FITSView *currentImage = targetChip->getImage(FITS_NORMAL);
+
+ if (DarkLibrary::Instance()->hasDarkFrame(targetChip))
+ DarkLibrary::Instance()->subtract(targetChip, currentImage);
+ else
+ {
+
+ connect(DarkLibrary::Instance(), SIGNAL(darkFrameSubtracted()), this, SLOT(setCaptureComplete()));
+ DarkLibrary::Instance()->captureAndSubtract(targetChip, currentImage);
+ }
+
+ }*/
+
+ /*if (calibrationState == CALIBRATE_START)
{
calibrationState = CALIBRATE_DONE;
startNextExposure();
@@ -867,12 +885,13 @@ void Capture::newFITS(IBLOB *bp)
if (image_data && calibrateImage && currentImage)
image_data->subtract(calibrateImage->getImageData()->getImageBuffer());
- }
+ }*/
}
- secondsLabel->setText(i18n("Complete."));
+ //TODO Move this to setCaptureComplete() function
- disconnect(currentCCD, SIGNAL(newExposureValue(ISD::CCDChip*,double,IPState)), this, SLOT(updateCaptureProgress(ISD::CCDChip*,double,IPState)));
+ disconnect(currentCCD, SIGNAL(newExposureValue(ISD::CCDChip*,double,IPState)), this, SLOT(updateCaptureProgress(ISD::CCDChip*,double,IPState)));
+ secondsLabel->setText(i18n("Complete."));
// If it was initially set as preview job
if (seqTotalCount <= 0)
@@ -1043,7 +1062,7 @@ void Capture::captureOne()
void Capture::captureImage()
{
seqTimer->stop();
- bool isDark=false;
+ //bool isDark=false;
SequenceJob::CAPTUREResult rc=SequenceJob::CAPTURE_OK;
if (isFocusBusy)
@@ -1053,9 +1072,8 @@ void Capture::captureImage()
return;
}
- if (useGuideHead == false && darkSubCheck->isChecked() && calibrationState == CALIBRATE_NONE)
- isDark = true;
-
+ //if (useGuideHead == false && darkSubCheck->isChecked() && calibrationState == CALIBRATE_NONE)
+ //isDark = true;
if (filterSlot != NULL)
{
@@ -1102,18 +1120,18 @@ void Capture::captureImage()
frameSettings[activeJob->getActiveChip()] = settings;
}
- rc = activeJob->capture(isDark);
+ rc = activeJob->capture();
switch (rc)
{
case SequenceJob::CAPTURE_OK:
connect(currentCCD, SIGNAL(newExposureValue(ISD::CCDChip*,double,IPState)), this, SLOT(updateCaptureProgress(ISD::CCDChip*,double,IPState)), Qt::UniqueConnection);
- if (isDark)
+ /*if (isDark)
{
calibrationState = CALIBRATE_START;
appendLogText(i18n("Capturing dark frame..."));
}
- else
+ else*/
appendLogText(i18n("Capturing image..."));
break;
@@ -1389,22 +1407,22 @@ void Capture::addJob(bool preview)
job->setFrame(frameXIN->value(), frameYIN->value(), frameWIN->value(), frameHIN->value());
+ job->setRootFITSDir(fitsDir->text());
+
if (jobUnderEdit == false)
{
jobs.append(job);
- job->setRootFITSDir(fitsDir->text());
-
// Nothing more to do if preview
if (preview)
return;
+ }
- QString finalFITSDir = fitsDir->text() + QLatin1Literal("/") + frameTypeCombo->currentText();
- if ( (job->getFrameType() == FRAME_LIGHT || job->getFrameType() == FRAME_FLAT) && job->getFilterName().isEmpty() == false)
- finalFITSDir += QLatin1Literal("/") + job->getFilterName();
+ QString finalFITSDir = fitsDir->text() + QLatin1Literal("/") + frameTypeCombo->currentText();
+ if ( (job->getFrameType() == FRAME_LIGHT || job->getFrameType() == FRAME_FLAT) && job->getFilterName().isEmpty() == false)
+ finalFITSDir += QLatin1Literal("/") + job->getFilterName();
- job->setFITSDir(finalFITSDir);
- }
+ job->setFITSDir(finalFITSDir);
int currentRow = 0;
if (jobUnderEdit == false)
diff --git a/kstars/ekos/capture.h b/kstars/ekos/capture.h
index 79e0d1d..34718a4 100644
--- a/kstars/ekos/capture.h
+++ b/kstars/ekos/capture.h
@@ -475,7 +475,7 @@ private:
int seqFileCount;
bool isBusy;
- int calibrationState;
+ //int calibrationState;
bool useGuideHead;
SequenceJob *activeJob;
diff --git a/kstars/ekos/darklibrary.cpp b/kstars/ekos/darklibrary.cpp
new file mode 100644
index 0000000..df5ad43
--- /dev/null
+++ b/kstars/ekos/darklibrary.cpp
@@ -0,0 +1,54 @@
+/* Ekos Dark Library Handler
+ Copyright (C) 2016 Jasem Mutlaq <mutlaqja@ikarustech.com>
+
+ This application is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+ */
+
+#include "darklibrary.h"
+#include "Options.h"
+
+#include "kstars.h"
+#include "kstarsdata.h"
+#include "auxiliary/ksuserdb.h"
+
+namespace Ekos
+{
+
+DarkLibrary * DarkLibrary::_DarkLibrary = NULL;
+
+DarkLibrary * DarkLibrary::Instance()
+{
+ if (_DarkLibrary == NULL)
+ _DarkLibrary = new DarkLibrary(KStars::Instance());
+
+ return _DarkLibrary;
+}
+
+DarkLibrary::DarkLibrary(QObject *parent) : QObject(parent)
+{
+ //if ccd TEXT NOT NULL, chip INTEGER DEFAULT 0, binX INTEGER, binY INTEGER, temperature REAL, duration REAL, filename TEXT NOT NULL, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)"))
+
+ //KStarsData::Instance()->userdb()->AddDarkFrame(test);
+
+ /*KStarsData::Instance()->userdb()->DeleteDarkFrame("/home/jasem/foo.fits");
+
+ KStarsData::Instance()->userdb()->GetAllDarkFrames(darkFrames);
+
+ foreach(QVariantMap map, darkFrames)
+ {
+ for(QVariantMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
+ qDebug() << iter.key() << " --> " << iter.value();
+ }*/
+
+
+}
+
+DarkLibrary::~DarkLibrary()
+{
+}
+}
+
+
diff --git a/kstars/ekos/darklibrary.h b/kstars/ekos/darklibrary.h
new file mode 100644
index 0000000..67504a9
--- /dev/null
+++ b/kstars/ekos/darklibrary.h
@@ -0,0 +1,45 @@
+/* Ekos Dark Library Handler
+ Copyright (C) 2016 Jasem Mutlaq <mutlaqja@ikarustech.com>
+
+ This application is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+ */
+
+#ifndef DARKLIBRARY_H
+#define DARKLIBRARY_H
+
+#include <QObject>
+
+namespace Ekos
+{
+
+/**
+ *@class DarkLibrary
+ *@short Handles aquisition & loading of dark frames for cameras. If a suitable dark frame exists, it is loaded from disk, otherwise it gets captured and saved
+ * for later use.
+ *@author Jasem Mutlaq
+ *@version 1.0
+ */
+class DarkLibrary : public QObject
+{
+
+ Q_OBJECT
+
+public:
+
+ static DarkLibrary *Instance();
+
+private:
+ DarkLibrary(QObject *parent);
+ ~DarkLibrary();
+ static DarkLibrary * _DarkLibrary;
+
+ QList<QVariantMap> darkFrames;
+
+};
+
+}
+
+#endif // DARKLIBRARY_H
diff --git a/kstars/ekos/ekosmanager.cpp b/kstars/ekos/ekosmanager.cpp
index 1daeb79..7bed361 100644
--- a/kstars/ekos/ekosmanager.cpp
+++ b/kstars/ekos/ekosmanager.cpp
@@ -27,6 +27,7 @@
#include "skymap.h"
#include "sequencejob.h"
+#include "darklibrary.h"
#include "profileeditor.h"
#include "profileinfo.h"
diff --git a/kstars/ekos/focus.cpp b/kstars/ekos/focus.cpp
index 854acf6..df95efa 100644
--- a/kstars/ekos/focus.cpp
+++ b/kstars/ekos/focus.cpp
@@ -228,7 +228,7 @@ Focus::~Focus()
//qDeleteAll(HFRAbsolutePoints);
// HFRAbsolutePoints.clear();
- delete (darkBuffer);
+ delete [] darkBuffer;
}
void Focus::toggleAutofocus(bool enable)
@@ -294,6 +294,8 @@ void Focus::resetFrame()
starCoords = QVector3D();
subFramed = false;
+ haveDarkFrame=false;
+
FITSView *targetImage = targetChip->getImage(FITS_FOCUS);
if (targetImage)
targetImage->setTrackingBox(QRect());
@@ -999,7 +1001,7 @@ void Focus::newFITS(IBLOB *bp)
{
calibrationState = CALIBRATE_NONE;
- delete (darkBuffer);
+ delete [] darkBuffer;
FITSView *calibrateImage = targetChip->getImage(FITS_CALIBRATE);
Q_ASSERT(calibrateImage != NULL);
diff --git a/kstars/ekos/sequencejob.cpp b/kstars/ekos/sequencejob.cpp
index 02ec1b4..e5bd67f 100644
--- a/kstars/ekos/sequencejob.cpp
+++ b/kstars/ekos/sequencejob.cpp
@@ -144,7 +144,8 @@ void SequenceJob::prepareCapture()
}
-SequenceJob::CAPTUREResult SequenceJob::capture(bool isDark)
+//SequenceJob::CAPTUREResult SequenceJob::capture(bool isDark)
+SequenceJob::CAPTUREResult SequenceJob::capture()
{
// If focusing is busy, return error
//if (activeChip->getCaptureMode() == FITS_FOCUS)
@@ -188,17 +189,17 @@ SequenceJob::CAPTUREResult SequenceJob::capture(bool isDark)
return CAPTURE_BIN_ERROR;
}
- if (isDark)
+ /*if (isDark)
{
activeChip->setFrameType(FRAME_DARK);
activeChip->setCaptureMode(FITS_CALIBRATE);
}
else
- {
+ {*/
activeChip->setFrameType(frameTypeName);
activeChip->setCaptureMode(FITS_NORMAL);
activeChip->setCaptureFilter(captureFilter);
- }
+ //}
// If filter is different that CCD, send the filter info
if (activeFilter && activeFilter != activeCCD)
diff --git a/kstars/ekos/sequencejob.h b/kstars/ekos/sequencejob.h
index c87438e..9e8d44e 100644
--- a/kstars/ekos/sequencejob.h
+++ b/kstars/ekos/sequencejob.h
@@ -36,7 +36,7 @@ class SequenceJob : public QObject
SequenceJob();
~SequenceJob() {}
- CAPTUREResult capture(bool isDark=false);
+ CAPTUREResult capture();
void reset();
void abort();
void done();
diff --git a/kstars/indi/indiccd.cpp b/kstars/indi/indiccd.cpp
index f062d9f..06a844f 100644
--- a/kstars/indi/indiccd.cpp
+++ b/kstars/indi/indiccd.cpp
@@ -25,6 +25,7 @@
#include "fitsviewer/fitsdata.h"
#endif
+#include "driverinfo.h"
#include "clientmanager.h"
#include "streamwg.h"
#include "indiccd.h"
@@ -42,11 +43,12 @@ const int MAX_FILENAME_LEN = 1024;
namespace ISD
{
-CCDChip::CCDChip(INDI::BaseDevice *bDevice, ClientManager *cManager, ChipType cType)
+CCDChip::CCDChip(ISD::CCD *ccd, ChipType cType)
{
- baseDevice = bDevice;
- clientManager = cManager;
- type = cType;
+ baseDevice = ccd->getBaseDevice();
+ clientManager = ccd->getDriverInfo()->getClientManager();
+ parentCCD = ccd;
+ type = cType;
batchMode = false;
displayFITS = true;
CanBin = false;
@@ -782,7 +784,7 @@ CCD::CCD(GDInterface *iPtr) : DeviceDecorator(iPtr)
ST4Driver = NULL;
nextSequenceID = 0 ;
- primaryChip = new CCDChip(baseDevice, clientManager, CCDChip::PRIMARY_CCD);
+ primaryChip = new CCDChip(this, CCDChip::PRIMARY_CCD);
normalTabID = calibrationTabID = focusTabID = guideTabID = -1;
guideChip = NULL;
@@ -804,7 +806,7 @@ void CCD::registerProperty(INDI::Property *prop)
if (!strcmp(prop->getName(), "GUIDER_EXPOSURE"))
{
HasGuideHead = true;
- guideChip = new CCDChip(baseDevice, clientManager, CCDChip::GUIDE_CCD);
+ guideChip = new CCDChip(this, CCDChip::GUIDE_CCD);
}
else if (!strcmp(prop->getName(), "CCD_FRAME_TYPE"))
{
diff --git a/kstars/indi/indiccd.h b/kstars/indi/indiccd.h
index 2c390ca..470b236 100644
--- a/kstars/indi/indiccd.h
+++ b/kstars/indi/indiccd.h
@@ -34,6 +34,8 @@ class StreamWG;
namespace ISD
{
+class CCD;
+
/**
* @class CCDChip
* CCDChip class controls a particular chip in CCD device. While most amateur CCDs only have a single chip on the CCD, some
@@ -44,7 +46,7 @@ class CCDChip
public:
typedef enum { PRIMARY_CCD, GUIDE_CCD } ChipType;
- CCDChip(INDI::BaseDevice *bDevice, ClientManager *cManager, ChipType cType);
+ CCDChip(ISD::CCD *ccd, ChipType cType);
FITSView * getImage(FITSMode imageType);
void setImage(FITSView *image, FITSMode imageType);
@@ -68,6 +70,7 @@ public:
bool getBinning(int *bin_x, int *bin_y);
bool getMaxBin(int *max_xbin, int *max_ybin);
ChipType getType() const { return type; }
+ ISD::CCD *getParentCCD() { return parentCCD;}
bool isCapturing();
bool abortExposure();
@@ -110,7 +113,8 @@ private:
QStringList frameTypes;
bool CanBin;
bool CanSubframe;
- bool CanAbort;
+ bool CanAbort;
+ ISD::CCD *parentCCD;
//int fx,fy,fw,fh;
};