Commit 7f7d2d20 authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

Initial work for dark library

parent 0acf553c
......@@ -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
......
......@@ -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
*/
......
......@@ -75,6 +75,14 @@ class KSUserDB {
//QMap<int, QStringList> GetAllProfiles();
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
......
......@@ -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)
......
......@@ -475,7 +475,7 @@ private:
int seqFileCount;
bool isBusy;
int calibrationState;
//int calibrationState;
bool useGuideHead;
SequenceJob *activeJob;
......
/* 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()
{
}
}
/* 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
......@@ -27,6 +27,7 @@
#include "skymap.h"
#include "sequencejob.h"
#include "darklibrary.h"
#include "profileeditor.h"
#include "profileinfo.h"
......
......@@ -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);
......
......@@ -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)
......
......@@ -36,7 +36,7 @@ class SequenceJob : public QObject
SequenceJob();
~SequenceJob() {}
CAPTUREResult capture(bool isDark=false);
CAPTUREResult capture();
void reset();
void abort();
void done();
......
......@@ -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"))
{
......
......@@ -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;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment