Move source files to src directory
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#include "about.h"
|
||||
#include <QTextEdit>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFile>
|
||||
#include <QLocale>
|
||||
#include "gitversion.h"
|
||||
|
||||
About::About(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setWindowTitle(tr("About Tenmon"));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
QLabel *label = new QLabel(this);
|
||||
|
||||
QFile tenmonText(":/about/tenmon");
|
||||
tenmonText.open(QIODevice::ReadOnly);
|
||||
QByteArray text = tenmonText.readAll();
|
||||
text.replace("@GITVERSION@", GITVERSION);
|
||||
label->setText(text);
|
||||
label->setOpenExternalLinks(true);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(buttonBox);
|
||||
}
|
||||
|
||||
HelpDialog::HelpDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setWindowTitle(tr("Help"));
|
||||
resize(1000, 600);
|
||||
setModal(false);
|
||||
setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
QTextEdit *helpText = new QTextEdit(this);
|
||||
helpText->setReadOnly(true);
|
||||
layout->addWidget(helpText);
|
||||
|
||||
QFile tenmonText(":/help");
|
||||
tenmonText.open(QIODevice::ReadOnly);
|
||||
helpText->setHtml(tenmonText.readAll());
|
||||
}
|
||||
|
||||
QString getVersion()
|
||||
{
|
||||
QString version = GITVERSION;
|
||||
version.truncate(8);
|
||||
return version;
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#ifndef ABOUT_H
|
||||
#define ABOUT_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class About : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
About(QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
class HelpDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HelpDialog(QWidget *parent = nullptr);
|
||||
};
|
||||
|
||||
QString getVersion();
|
||||
|
||||
#endif // ABOUT_H
|
||||
@@ -0,0 +1,335 @@
|
||||
#include "batchprocessing.h"
|
||||
#include "ui_batchprocessing.h"
|
||||
#include <functional>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QProcess>
|
||||
#include <QSettings>
|
||||
#include <QCloseEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
#include <QInputDialog>
|
||||
#include <QChart>
|
||||
#include <QChartView>
|
||||
#include <QLineSeries>
|
||||
#include "scriptengine.h"
|
||||
#include "chartgraph.h"
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
#include <QCloseEvent>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#endif
|
||||
|
||||
QList<QPair<QString, QString>> scanDirectories(const QStringList &paths)
|
||||
{
|
||||
QList<QPair<QString, QString>> files;
|
||||
QStringList scannedDirs;
|
||||
|
||||
std::function<void(const QString &root, const QString &path)> scanDirectory = [&](const QString &root, const QString &path)
|
||||
{
|
||||
QFileInfo info(path);
|
||||
if(info.isDir() && !scannedDirs.contains(info.canonicalFilePath()))
|
||||
{
|
||||
scannedDirs.append(info.canonicalFilePath());
|
||||
QDir dir(path);
|
||||
QStringList entries = dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
for(QString &entry : entries)
|
||||
scanDirectory(root, dir.absoluteFilePath(entry));
|
||||
}
|
||||
else if(info.isFile())
|
||||
{
|
||||
if(path == root)
|
||||
files.append({path, info.absolutePath()});
|
||||
else
|
||||
files.append({path, root});
|
||||
}
|
||||
};
|
||||
|
||||
for(const QString &path : paths)
|
||||
scanDirectory(path, path);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
void BatchProcessing::scanScriptDir()
|
||||
{
|
||||
QString current;
|
||||
if(_ui->scriptsList->currentItem())
|
||||
current = _ui->scriptsList->currentItem()->text();
|
||||
|
||||
_ui->scriptsList->clear();
|
||||
QDir dir(_scriptBasePath);
|
||||
QDir embededDir(":/scripts");
|
||||
QStringList scripts = dir.entryList(QDir::Files | QDir::Readable);
|
||||
scripts.append(embededDir.entryList(QDir::Files));
|
||||
scripts.removeDuplicates();
|
||||
_ui->scriptsList->addItems(scripts);
|
||||
|
||||
int idx = scripts.indexOf(current);
|
||||
if(idx>=0)_ui->scriptsList->setCurrentRow(idx);
|
||||
}
|
||||
|
||||
BatchProcessing::BatchProcessing(Database *database, QWidget *parent) : QDialog(parent)
|
||||
, _database(database)
|
||||
{
|
||||
_ui = new Ui::BatchProcessing;
|
||||
_ui->setupUi(this);
|
||||
|
||||
QStringList scriptsPath = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
|
||||
if(scriptsPath.size())
|
||||
{
|
||||
QDir dir(scriptsPath.first());
|
||||
if(!dir.exists("scripts"))
|
||||
{
|
||||
if(!dir.mkpath("scripts"))
|
||||
qWarning() << "Failed to create scripts directory";
|
||||
}
|
||||
dir.cd("scripts");
|
||||
|
||||
_scriptBasePath = dir.absolutePath() + "/";
|
||||
scanScriptDir();
|
||||
_fileWatcher.addPath(_scriptBasePath);
|
||||
connect(&_fileWatcher, &QFileSystemWatcher::directoryChanged, this, &BatchProcessing::scanScriptDir);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Failed to get app data location";
|
||||
}
|
||||
|
||||
connect(_ui->addFilesButton, &QPushButton::released, this, &BatchProcessing::addFiles);
|
||||
connect(_ui->addDirButton, &QPushButton::released, this, &BatchProcessing::addDir);
|
||||
connect(_ui->removeButton, &QPushButton::released, this, &BatchProcessing::removePath);
|
||||
connect(_ui->removeAllButton, &QPushButton::released, this, &BatchProcessing::removeAllPaths);
|
||||
connect(_ui->startButton, &QPushButton::released, this, &BatchProcessing::runScript);
|
||||
connect(_ui->stopButton, &QPushButton::released, this, &BatchProcessing::stopScript);
|
||||
connect(_ui->browseButton, &QPushButton::released, this, &BatchProcessing::browse);
|
||||
connect(_ui->openScriptsButton, &QPushButton::released, this, &BatchProcessing::openScriptDir);
|
||||
|
||||
_textColor = _ui->log->palette().text().color();
|
||||
|
||||
QSettings settings;
|
||||
_ui->outputPath->setText(settings.value("batchprocessing/outputpath", QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first()).toString());
|
||||
}
|
||||
|
||||
BatchProcessing::~BatchProcessing()
|
||||
{
|
||||
delete _engineThread;
|
||||
QSettings settings;
|
||||
settings.setValue("batchprocessing/outputpath", _ui->outputPath->text());
|
||||
delete _ui;
|
||||
}
|
||||
|
||||
void BatchProcessing::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if(_engineThread)
|
||||
{
|
||||
QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Interrupt running script?"), tr("Interrupt running script?"));
|
||||
if(ret == QMessageBox::StandardButton::Yes)
|
||||
{
|
||||
_engineThread->interrupt();
|
||||
event->accept();
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
}
|
||||
|
||||
void BatchProcessing::addFiles()
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList files = QFileDialog::getOpenFileNames(this, tr("Select files"), settings.value("batchprocessing/inputpath", QDir::homePath()).toString());
|
||||
if(!files.isEmpty())
|
||||
{
|
||||
_ui->pathsList->addItems(files);
|
||||
settings.setValue("batchprocessing/inputpath", QFileInfo(files.first()).absolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
void BatchProcessing::addDir()
|
||||
{
|
||||
QSettings settings;
|
||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Select directory"), settings.value("batchprocessing/inputpath", QDir::homePath()).toString());
|
||||
if(!dir.isEmpty())
|
||||
{
|
||||
_ui->pathsList->addItem(dir);
|
||||
settings.setValue("batchprocessing/inputpath", dir);
|
||||
}
|
||||
}
|
||||
|
||||
void BatchProcessing::removePath()
|
||||
{
|
||||
for(auto &item : _ui->pathsList->selectedItems())
|
||||
delete item;
|
||||
}
|
||||
|
||||
void BatchProcessing::removeAllPaths()
|
||||
{
|
||||
_ui->pathsList->clear();
|
||||
}
|
||||
|
||||
void BatchProcessing::browse()
|
||||
{
|
||||
QString output = QFileDialog::getExistingDirectory(this, tr("Select output directory"), _ui->outputPath->text());
|
||||
if(!output.isEmpty())
|
||||
_ui->outputPath->setText(output);
|
||||
}
|
||||
|
||||
void BatchProcessing::openScriptDir()
|
||||
{
|
||||
openDir(_scriptBasePath);
|
||||
}
|
||||
|
||||
void BatchProcessing::runScript()
|
||||
{
|
||||
_ui->log->clear();
|
||||
auto selectedItems = _ui->scriptsList->selectedItems();
|
||||
if(selectedItems.size())
|
||||
{
|
||||
_engineThread = new Script::ScriptEngineThread(_database, this);
|
||||
connect(_engineThread, &Script::ScriptEngineThread::newMessage, this, &BatchProcessing::newMessage);
|
||||
connect(_engineThread, &Script::ScriptEngineThread::finished, this, &BatchProcessing::scriptFinished);
|
||||
QStringList paths;
|
||||
for(int i=0; i<_ui->pathsList->count(); i++)
|
||||
paths.append(_ui->pathsList->item(i)->text());
|
||||
|
||||
QFileInfo outDir(_ui->outputPath->text());
|
||||
if(outDir.exists() && outDir.isWritable())
|
||||
{
|
||||
QString script = selectedItems.first()->text();
|
||||
if(QDir(_scriptBasePath).exists(script))
|
||||
script = _scriptBasePath + script;
|
||||
else
|
||||
script = ":/scripts/" + script;
|
||||
|
||||
_engineThread->setParams(script, scanDirectories(paths), _ui->outputPath->text());
|
||||
_engineThread->start();
|
||||
_ui->startButton->setEnabled(false);
|
||||
_ui->stopButton->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Invalid output directory"), tr("Output directory path doesn't exist or is not writable"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BatchProcessing::stopScript()
|
||||
{
|
||||
qDebug() << "Stop script";
|
||||
if(_engineThread)
|
||||
_engineThread->interrupt();
|
||||
}
|
||||
|
||||
void BatchProcessing::scriptFinished()
|
||||
{
|
||||
_ui->startButton->setEnabled(true);
|
||||
_ui->stopButton->setEnabled(false);
|
||||
qDebug() << "script finished";
|
||||
_engineThread->deleteLater();
|
||||
_engineThread = nullptr;
|
||||
}
|
||||
|
||||
void BatchProcessing::newMessage(const QString &message, bool error)
|
||||
{
|
||||
if(error)_ui->log->setTextColor(Qt::red);
|
||||
else _ui->log->setTextColor(_textColor);
|
||||
_ui->log->append(message);
|
||||
}
|
||||
|
||||
QJSValue BatchProcessing::getString(const QString &label, const QString &text)
|
||||
{
|
||||
bool ok = false;
|
||||
QString ret = QInputDialog::getText(this, tr("Enter text"), label, QLineEdit::Normal, text, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
}
|
||||
|
||||
QJSValue BatchProcessing::getInt(const QString &label, int value)
|
||||
{
|
||||
bool ok = false;
|
||||
int ret = QInputDialog::getInt(this, tr("Enter integer number"), label, value, INT_MIN, INT_MAX, 1, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
}
|
||||
|
||||
QJSValue BatchProcessing::getFloat(const QString &label, double value, int decimals)
|
||||
{
|
||||
bool ok = false;
|
||||
double ret = QInputDialog::getDouble(this, tr("Enter float number"), label, value, -INFINITY, INFINITY, decimals, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
}
|
||||
|
||||
QJSValue BatchProcessing::getItem(const QStringList &items, const QString &label, int current)
|
||||
{
|
||||
bool ok = false;
|
||||
QString ret = QInputDialog::getItem(this, tr("Select item"), label, items, current, false, &ok);
|
||||
return ok ? ret : QJSValue();
|
||||
}
|
||||
|
||||
QJSValue BatchProcessing::question(const QString &question, const QStringList &buttons, const QString &title)
|
||||
{
|
||||
QMessageBox::StandardButtons standardButtons = QMessageBox::NoButton;
|
||||
if(buttons.contains("ok"))standardButtons |= QMessageBox::Ok;
|
||||
if(buttons.contains("yes"))standardButtons |= QMessageBox::Yes;
|
||||
if(buttons.contains("no"))standardButtons |= QMessageBox::No;
|
||||
if(buttons.contains("yesall"))standardButtons |= QMessageBox::YesToAll;
|
||||
if(buttons.contains("noall"))standardButtons |= QMessageBox::NoToAll;
|
||||
if(buttons.contains("abort"))standardButtons |= QMessageBox::Abort;
|
||||
if(buttons.contains("retry"))standardButtons |= QMessageBox::Retry;
|
||||
if(buttons.contains("ignore"))standardButtons |= QMessageBox::Ignore;
|
||||
if(buttons.contains("cancel"))standardButtons |= QMessageBox::Cancel;
|
||||
if(buttons.contains("discard"))standardButtons |= QMessageBox::Discard;
|
||||
if(buttons.contains("apply"))standardButtons |= QMessageBox::Apply;
|
||||
if(buttons.contains("reset"))standardButtons |= QMessageBox::Reset;
|
||||
if(standardButtons == QMessageBox::NoButton)standardButtons = QMessageBox::Ok;
|
||||
|
||||
QMessageBox::StandardButton button = QMessageBox::question(this, title, question, standardButtons);
|
||||
QJSValue ret;
|
||||
switch(button)
|
||||
{
|
||||
default:
|
||||
case QMessageBox::Ok: ret = "ok"; break;
|
||||
case QMessageBox::Yes: ret = "yes"; break;
|
||||
case QMessageBox::No: ret = "no"; break;
|
||||
case QMessageBox::YesToAll: ret = "yesall"; break;
|
||||
case QMessageBox::NoToAll: ret = "noall"; break;
|
||||
case QMessageBox::Abort: ret = "abort"; break;
|
||||
case QMessageBox::Retry: ret = "retry"; break;
|
||||
case QMessageBox::Ignore: ret = "ignore"; break;
|
||||
case QMessageBox::Cancel: ret = "cancel"; break;
|
||||
case QMessageBox::Discard: ret = "discard"; break;
|
||||
case QMessageBox::Apply: ret = "apply"; break;
|
||||
case QMessageBox::Reset: ret = "reset"; break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void BatchProcessing::plot(const QVariant &graph)
|
||||
{
|
||||
ChartGraph *chart = new ChartGraph(this);
|
||||
chart->plot(graph);
|
||||
}
|
||||
|
||||
void openDir(const QString &path)
|
||||
{
|
||||
#ifdef Q_OS_LINUX
|
||||
QDBusConnection con = QDBusConnection::sessionBus();
|
||||
QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.FileManager1", "/org/freedesktop/FileManager1", "org.freedesktop.FileManager1", "ShowFolders");
|
||||
QList<QVariant> args = {QStringList(QUrl::fromLocalFile(path).toString()), QString()};
|
||||
message.setArguments(args);
|
||||
con.call(message);
|
||||
#endif
|
||||
#ifdef Q_OS_WINDOWS
|
||||
QProcess::startDetached("explorer.exe", {QDir::toNativeSeparators(path)});
|
||||
#endif
|
||||
#ifdef Q_OS_MACOS
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef BATCHPROCESSING_H
|
||||
#define BATCHPROCESSING_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QFileSystemWatcher>
|
||||
#include "scriptengine.h"
|
||||
|
||||
namespace Ui { class BatchProcessing; }
|
||||
|
||||
class Database;
|
||||
|
||||
class BatchProcessing : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Ui::BatchProcessing *_ui;
|
||||
QString _scriptBasePath;
|
||||
QFileSystemWatcher _fileWatcher;
|
||||
Script::ScriptEngineThread *_engineThread = nullptr;
|
||||
QColor _textColor;
|
||||
Database *_database;
|
||||
private slots:
|
||||
void scanScriptDir();
|
||||
public:
|
||||
explicit BatchProcessing(Database *database, QWidget *parent = nullptr);
|
||||
~BatchProcessing();
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
public slots:
|
||||
void addFiles();
|
||||
void addDir();
|
||||
void removePath();
|
||||
void removeAllPaths();
|
||||
void browse();
|
||||
void openScriptDir();
|
||||
void runScript();
|
||||
void stopScript();
|
||||
void scriptFinished();
|
||||
void newMessage(const QString &message, bool error);
|
||||
|
||||
QJSValue getString(const QString &label, const QString &text);
|
||||
QJSValue getInt(const QString &label, int value);
|
||||
QJSValue getFloat(const QString &label, double value, int decimals);
|
||||
QJSValue getItem(const QStringList &items, const QString &label, int current);
|
||||
QJSValue question(const QString &question, const QStringList &buttons, const QString &title = "");
|
||||
|
||||
void plot(const QVariant &graph);
|
||||
};
|
||||
|
||||
void openDir(const QString &path);
|
||||
|
||||
#endif // BATCHPROCESSING_H
|
||||
@@ -0,0 +1,226 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BatchProcessing</class>
|
||||
<widget class="QDialog" name="BatchProcessing">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1024</width>
|
||||
<height>768</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Batch Processing</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Input files and directories</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="pathsList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::MultiSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="addFilesButton">
|
||||
<property name="text">
|
||||
<string>Add files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addDirButton">
|
||||
<property name="text">
|
||||
<string>Add directories</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeAllButton">
|
||||
<property name="text">
|
||||
<string>Remove all</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Output directory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="outputPath">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="browseButton">
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Scripts</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openScriptsButton">
|
||||
<property name="text">
|
||||
<string>Open scripts</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="scriptsList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Log</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="log">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>4</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>FreeMono</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="startButton">
|
||||
<property name="text">
|
||||
<string>Start script</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="stopButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop script</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="closeButton">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>closeButton</sender>
|
||||
<signal>released()</signal>
|
||||
<receiver>BatchProcessing</receiver>
|
||||
<slot>close()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>973</x>
|
||||
<y>745</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>511</x>
|
||||
<y>383</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -0,0 +1,298 @@
|
||||
#include "chartgraph.h"
|
||||
#include <QChartView>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLineSeries>
|
||||
#include <QBarSeries>
|
||||
#include <QBarSet>
|
||||
#include <QBarCategoryAxis>
|
||||
#include <QScatterSeries>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QValueAxis>
|
||||
#include <QFileDialog>
|
||||
#include <QSettings>
|
||||
#include <QToolBar>
|
||||
#include <QStyle>
|
||||
|
||||
class ChartView : public QChartView
|
||||
{
|
||||
QPointF _mousePos;
|
||||
bool _scroll = false;
|
||||
public:
|
||||
ChartView(QWidget *parent) : QChartView(parent)
|
||||
{
|
||||
}
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *event) override
|
||||
{
|
||||
if(!chart()->isZoomed())chart()->zoom(0.999999);//workaround so zoomReset() reset scroll
|
||||
switch(event->key())
|
||||
{
|
||||
case Qt::Key_Plus:
|
||||
chart()->zoomIn();
|
||||
break;
|
||||
case Qt::Key_Minus:
|
||||
chart()->zoomOut();
|
||||
break;
|
||||
case Qt::Key_Left:
|
||||
chart()->scroll(-10, 0);
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
chart()->scroll(10, 0);
|
||||
break;
|
||||
case Qt::Key_Up:
|
||||
chart()->scroll(0, 10);
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
chart()->scroll(0, -10);
|
||||
break;
|
||||
default:
|
||||
QGraphicsView::keyPressEvent(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void mousePressEvent(QMouseEvent *event) override
|
||||
{
|
||||
if(event->button() == Qt::LeftButton)
|
||||
{
|
||||
_scroll = true;
|
||||
if(!chart()->isZoomed())chart()->zoom(0.999999);//workaround so zoomReset() reset scroll
|
||||
_mousePos = event->position();
|
||||
}
|
||||
|
||||
QChartView::mousePressEvent(event);
|
||||
}
|
||||
void mouseMoveEvent(QMouseEvent *event) override
|
||||
{
|
||||
if(_scroll)
|
||||
{
|
||||
QPointF pos = event->position();
|
||||
chart()->scroll(_mousePos.x() - pos.x(), pos.y() - _mousePos.y());
|
||||
_mousePos = pos;
|
||||
}
|
||||
QChartView::mouseMoveEvent(event);
|
||||
}
|
||||
void mouseReleaseEvent(QMouseEvent *event) override
|
||||
{
|
||||
_scroll = false;
|
||||
QChartView::mouseReleaseEvent(event);
|
||||
}
|
||||
void wheelEvent(QWheelEvent *event) override
|
||||
{
|
||||
if(event->angleDelta().y() > 0)
|
||||
chart()->zoomIn();
|
||||
if(event->angleDelta().y() < 0)
|
||||
chart()->zoomOut();
|
||||
}
|
||||
};
|
||||
|
||||
ChartGraph::ChartGraph(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setWindowTitle(tr("Chart"));
|
||||
|
||||
_chartView = new ChartView(this);
|
||||
setCentralWidget(_chartView);
|
||||
|
||||
_chart = new QChart;
|
||||
_chartView->setChart(_chart);
|
||||
_chartView->setRenderHint(QPainter::Antialiasing);
|
||||
resize(1024, 768);
|
||||
|
||||
menuBar()->addAction(tr("Save"), this, &ChartGraph::save);
|
||||
menuBar()->addAction(tr("Reset view"), [this](){ _chart->zoomReset(); });
|
||||
}
|
||||
|
||||
void ChartGraph::plot(const QVariant &graph)
|
||||
{
|
||||
QVariantMap map = graph.toMap();
|
||||
|
||||
_chart->setTitle(map["title"].toString());
|
||||
if(map.contains("legend"))
|
||||
{
|
||||
QVariantMap legend = map["legend"].toMap();
|
||||
if(legend.contains("visible"))
|
||||
_chart->legend()->setVisible(legend["visible"].toBool());
|
||||
|
||||
QString align = legend["align"].toString();
|
||||
if(align == "top")
|
||||
_chart->legend()->setAlignment(Qt::AlignTop);
|
||||
else if(align == "left")
|
||||
_chart->legend()->setAlignment(Qt::AlignLeft);
|
||||
else if(align == "bottom")
|
||||
_chart->legend()->setAlignment(Qt::AlignBottom);
|
||||
else if(align == "right")
|
||||
_chart->legend()->setAlignment(Qt::AlignRight);
|
||||
}
|
||||
|
||||
QBarSeries *barSeries = nullptr;
|
||||
|
||||
qreal minX = INFINITY;
|
||||
qreal maxX = -INFINITY;
|
||||
qreal minY = INFINITY;
|
||||
qreal maxY = -INFINITY;
|
||||
qreal minY2 = INFINITY;
|
||||
qreal maxY2 = -INFINITY;
|
||||
|
||||
QValueAxis *xaxis = new QValueAxis(_chart);
|
||||
QBarCategoryAxis *barxaxis = new QBarCategoryAxis(_chart);
|
||||
QValueAxis *yaxis = new QValueAxis(_chart);
|
||||
QValueAxis *y2axis = new QValueAxis(_chart);
|
||||
_chart->addAxis(xaxis, Qt::AlignBottom);
|
||||
_chart->addAxis(yaxis, Qt::AlignLeft);
|
||||
_chart->addAxis(y2axis, Qt::AlignRight);
|
||||
_chart->addAxis(barxaxis, Qt::AlignBottom);
|
||||
y2axis->setGridLinePen(Qt::DashDotLine);
|
||||
|
||||
for(auto s : map["series"].toList())
|
||||
{
|
||||
QVariantMap serie = s.toMap();
|
||||
QString type = serie["type"].toString();
|
||||
bool y2 = serie["y2"].toBool();
|
||||
|
||||
if(type == "line" || type == "points" || type == "linePoints" || type.isEmpty())
|
||||
{
|
||||
QXYSeries *series = nullptr;
|
||||
if(type == "points")
|
||||
{
|
||||
QScatterSeries *scatter = new QScatterSeries(_chart);
|
||||
series = scatter;
|
||||
QString shape = serie["shape"].toString();
|
||||
if(shape == "circle")scatter->setMarkerShape(QScatterSeries::MarkerShapeCircle);
|
||||
else if(shape == "rectangle")scatter->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
|
||||
else if(shape == "triangle")scatter->setMarkerShape(QScatterSeries::MarkerShapeTriangle);
|
||||
else if(shape == "star")scatter->setMarkerShape(QScatterSeries::MarkerShapeStar);
|
||||
else if(shape == "pentagon")scatter->setMarkerShape(QScatterSeries::MarkerShapePentagon);
|
||||
}
|
||||
else
|
||||
{
|
||||
series = new QLineSeries(_chart);
|
||||
}
|
||||
|
||||
series->setName(serie["title"].toString());
|
||||
QVariantList x = serie["x"].toList();
|
||||
QVariantList y = serie["y"].toList();
|
||||
if(x.isEmpty())
|
||||
{
|
||||
for(int i = 0; i < y.size(); i++)
|
||||
{
|
||||
qreal val = y[i].toDouble();
|
||||
if(y2)
|
||||
{
|
||||
minY2 = std::min(minY2, val);
|
||||
maxY2 = std::max(maxY2, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
minY = std::min(minY, val);
|
||||
maxY = std::max(maxY, val);
|
||||
}
|
||||
series->append(i, val);
|
||||
}
|
||||
minX = std::min(minX, 0.0);
|
||||
maxX = std::max(maxX, y.size() - 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int size = std::min(x.size(), y.size());
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
qreal val = y[i].toDouble();
|
||||
if(y2)
|
||||
{
|
||||
minY2 = std::min(minY2, val);
|
||||
maxY2 = std::max(maxY2, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
minY = std::min(minY, val);
|
||||
maxY = std::max(maxY, val);
|
||||
}
|
||||
minX = std::min(minX, x[i].toDouble());
|
||||
maxX = std::max(maxX, x[i].toDouble());
|
||||
series->append(x[i].toDouble(), val);
|
||||
}
|
||||
}
|
||||
|
||||
_chart->addSeries(series);
|
||||
series->attachAxis(xaxis);
|
||||
series->attachAxis(y2 ? y2axis : yaxis);
|
||||
|
||||
if(serie.contains("color"))
|
||||
{
|
||||
QString color = serie["color"].toString();
|
||||
if(QColor::isValidColorName(color))series->setColor(QColor::fromString(color));
|
||||
}
|
||||
|
||||
if(serie["bestFit"].toBool())
|
||||
{
|
||||
series->setBestFitLineVisible(true);
|
||||
QPen pen = series->bestFitLinePen();
|
||||
pen.setColor(series->color());
|
||||
pen.setStyle(Qt::DashLine);
|
||||
series->setBestFitLinePen(pen);
|
||||
}
|
||||
|
||||
if(type == "linePoints")
|
||||
series->setPointsVisible(true);
|
||||
|
||||
}
|
||||
else if(type == "bar")
|
||||
{
|
||||
if(!barSeries)
|
||||
{
|
||||
barSeries = new QBarSeries(_chart);
|
||||
_chart->addSeries(barSeries);
|
||||
barSeries->attachAxis(yaxis);
|
||||
barSeries->attachAxis(barxaxis);
|
||||
}
|
||||
QBarSet *set = new QBarSet(serie["title"].toString());
|
||||
QVariantList y = serie["y"].toList();
|
||||
for(int i = 0; i < y.size(); i++)
|
||||
{
|
||||
qreal val = y[i].toDouble();
|
||||
minY = std::min(minY, val);
|
||||
maxY = std::max(maxY, val);
|
||||
set->append(val);
|
||||
}
|
||||
|
||||
barSeries->append(set);
|
||||
for(int i = barxaxis->count() + 1; i <= y.size(); i++)
|
||||
barxaxis->append(QString::number(i));
|
||||
|
||||
if(serie.contains("color"))
|
||||
{
|
||||
QString color = serie["color"].toString();
|
||||
if(QColor::isValidColorName(color))set->setColor(QColor::fromString(color));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(barSeries)
|
||||
{
|
||||
xaxis->setRange(std::min(minX, -0.5), std::max(maxX, barxaxis->count() - 0.5));
|
||||
minY = std::min(minY, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
xaxis->setRange(minX, maxX);
|
||||
}
|
||||
|
||||
yaxis->setRange(minY, maxY);
|
||||
y2axis->setRange(minY2, maxY2);
|
||||
|
||||
show();
|
||||
}
|
||||
|
||||
void ChartGraph::save()
|
||||
{
|
||||
QSettings settings;
|
||||
QString dir = settings.value("mainwindow/lastdir").toString();
|
||||
QString output = QFileDialog::getSaveFileName(this, tr("Save as"), dir, "PNG (*.png)");
|
||||
|
||||
if(!output.isEmpty())
|
||||
{
|
||||
QPixmap graph = _chartView->grab();
|
||||
graph.toImage().save(output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef CHARTGRAPH_H
|
||||
#define CHARTGRAPH_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QJSValue>
|
||||
#include <QChart>
|
||||
|
||||
class ChartView;
|
||||
|
||||
class ChartGraph : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
QChart *_chart;
|
||||
ChartView *_chartView;
|
||||
public:
|
||||
explicit ChartGraph(QWidget *parent = nullptr);
|
||||
void plot(const QVariant &graph);
|
||||
public slots:
|
||||
void save();
|
||||
};
|
||||
|
||||
#endif // CHARTGRAPH_H
|
||||
@@ -0,0 +1,396 @@
|
||||
#include "database.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QDir>
|
||||
#include <QSqlError>
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
#include "loadimage.h"
|
||||
|
||||
Database::Database(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool Database::init(const QLatin1String &connectionName)
|
||||
{
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
QDir dir(path);
|
||||
|
||||
database = QSqlDatabase::addDatabase("QSQLITE", connectionName);
|
||||
ngc = QSqlDatabase::addDatabase("QSQLITE", connectionName + "ngc");
|
||||
|
||||
if(!dir.mkpath("."))
|
||||
return false;
|
||||
|
||||
if(ngc.isValid())
|
||||
{
|
||||
QString ngcDb = dir.absoluteFilePath("ngc.db");
|
||||
if(!QFile::exists(ngcDb))
|
||||
QFile::copy(":/ngc.db", ngcDb);
|
||||
|
||||
ngc.setDatabaseName(ngcDb);
|
||||
if(ngc.open())
|
||||
{
|
||||
m_getNgc = QSqlQuery(ngc);
|
||||
m_getNgc.prepare("SELECT *,IIF(V_Mag IS NULL, B_Mag, V_Mag) AS mag FROM ngc WHERE RA_deg BETWEEN ? AND ? AND DEC_deg BETWEEN ? AND ?");
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Could not open NGC database";
|
||||
}
|
||||
}
|
||||
|
||||
if(database.isValid())
|
||||
{
|
||||
database.setDatabaseName(dir.absoluteFilePath("database2.db"));
|
||||
if(database.open())
|
||||
{
|
||||
QSqlQuery query(database);
|
||||
query.exec("PRAGMA foreign_keys = ON");
|
||||
int version = checkVersion(database);
|
||||
if(version == 0)
|
||||
{
|
||||
query.exec("PRAGMA user_version = 1");
|
||||
query.exec("CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY AUTOINCREMENT, file VARCHAR(255) UNIQUE)");
|
||||
query.exec("CREATE TABLE IF NOT EXISTS fits_files (id INTEGER PRIMARY KEY AUTOINCREMENT, file VARCHAR(255) UNIQUE, mtime DATETIME,"
|
||||
" minRa REAL, maxRa REAL, minDec REAL, maxDec REAL, crVal1 REAL, crVal2 REAL)");
|
||||
query.exec("CREATE TABLE IF NOT EXISTS fits_headers (id INTEGER PRIMARY KEY AUTOINCREMENT, id_file INTEGER,"
|
||||
"key VARCHAR(81), value VARCHAR(81), comment VARCHAR(81), FOREIGN KEY(id_file) REFERENCES fits_files(id) ON DELETE CASCADE)");
|
||||
query.exec("CREATE INDEX IF NOT EXISTS key_value ON fits_headers(key, value)");
|
||||
query.exec("CREATE INDEX IF NOT EXISTS id_file ON fits_headers(id_file)");
|
||||
query.exec("CREATE INDEX IF NOT EXISTS minRa_idx ON fits_files(minRa)");
|
||||
query.exec("CREATE INDEX IF NOT EXISTS maxRa_idx ON fits_files(maxRa)");
|
||||
query.exec("CREATE INDEX IF NOT EXISTS minDec_idx ON fits_files(minDec)");
|
||||
query.exec("CREATE INDEX IF NOT EXISTS maxDec_idx ON fits_files(maxDec)");
|
||||
}
|
||||
else if(version > 1)
|
||||
{
|
||||
qDebug() << "Database version is too new";
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlError error = database.lastError();
|
||||
|
||||
if(error.type() == QSqlError::NoError)
|
||||
{
|
||||
m_markQuery = QSqlQuery(database);
|
||||
m_markQuery.prepare("INSERT INTO files (file) VALUES (?)");
|
||||
m_unmarkQuery = QSqlQuery(database);
|
||||
m_unmarkQuery.prepare("DELETE FROM files WHERE file = (?)");
|
||||
m_isMarkedQuery = QSqlQuery(database);
|
||||
m_isMarkedQuery.prepare("SELECT * FROM files WHERE file = (:name)");
|
||||
|
||||
m_insertFile = QSqlQuery(database);
|
||||
m_insertFile.prepare("INSERT INTO fits_files (file, mtime) VALUES (?, ?)");
|
||||
m_insertFileWcs = QSqlQuery(database);
|
||||
m_insertFileWcs.prepare("INSERT INTO fits_files (file, mtime, minRa, maxRa, minDec, maxDec, crVal1, crVal2) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
m_insertFitsHeader = QSqlQuery(database);
|
||||
m_insertFitsHeader.prepare("INSERT INTO fits_headers (id_file, key, value, comment) VALUES (?, ?, ?, ?)");
|
||||
m_checkFile = QSqlQuery(database);
|
||||
m_checkFile.prepare("SELECT id,mtime FROM fits_files WHERE file=?");
|
||||
m_headerKeywords = QSqlQuery(database);
|
||||
m_headerKeywords.prepare("SELECT DISTINCT key FROM fits_headers ORDER BY key");
|
||||
m_deleteFile = QSqlQuery(database);
|
||||
m_deleteFile.prepare("DELETE FROM fits_files WHERE id=?");
|
||||
return true;
|
||||
}
|
||||
qDebug() << error.text();
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed to open database" << connectionName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Database is invalid";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Database::mark(const QString &filename)
|
||||
{
|
||||
m_markQuery.bindValue(0, filename);
|
||||
m_markQuery.exec();
|
||||
return checkError(m_markQuery);
|
||||
}
|
||||
|
||||
bool Database::unmark(const QString &filename)
|
||||
{
|
||||
m_unmarkQuery.bindValue(0, filename);
|
||||
m_unmarkQuery.exec();
|
||||
return checkError(m_unmarkQuery);
|
||||
}
|
||||
|
||||
bool Database::mark(const QStringList &filenames)
|
||||
{
|
||||
m_markQuery.bindValue(0, filenames);
|
||||
m_markQuery.execBatch();
|
||||
return checkError(m_markQuery);
|
||||
}
|
||||
|
||||
bool Database::unmark(const QStringList &filenames)
|
||||
{
|
||||
m_unmarkQuery.bindValue(0, filenames);
|
||||
m_unmarkQuery.execBatch();
|
||||
return checkError(m_unmarkQuery);
|
||||
}
|
||||
|
||||
bool Database::isMarked(const QString &filename)
|
||||
{
|
||||
m_isMarkedQuery.bindValue(":name", filename);
|
||||
m_isMarkedQuery.exec();
|
||||
checkError(m_isMarkedQuery);
|
||||
return m_isMarkedQuery.next();
|
||||
}
|
||||
|
||||
QStringList Database::getMarkedFiles()
|
||||
{
|
||||
QSqlQuery markedFiles("SELECT * from files");
|
||||
|
||||
QStringList files;
|
||||
while(markedFiles.next())
|
||||
{
|
||||
files << markedFiles.value("file").toString();
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
void Database::clearMarkedFiles()
|
||||
{
|
||||
QSqlQuery query("DELETE FROM files");
|
||||
}
|
||||
|
||||
bool Database::checkError(QSqlQuery &query)
|
||||
{
|
||||
QSqlError error = query.lastError();
|
||||
if(error.type() == QSqlError::NoError)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
qDebug() << error.text();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int Database::checkVersion(QSqlDatabase &db)
|
||||
{
|
||||
QSqlQuery query("PRAGMA user_version", db);
|
||||
if(query.next())
|
||||
return query.value(0).toInt();
|
||||
return -1;
|
||||
}
|
||||
|
||||
static QStringList nameFilters = {"*.fit", "*.fits", "*.fz", "*.xisf"};
|
||||
|
||||
static int countFiles(const QDir &dir, QStringList &scannedDirs)
|
||||
{
|
||||
if(scannedDirs.contains(dir.canonicalPath()))return 0;
|
||||
scannedDirs.append(dir.canonicalPath());
|
||||
|
||||
int count = dir.entryList(nameFilters, QDir::Files).size();
|
||||
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
for(const QString &d : dirs)
|
||||
count += countFiles(dir.filePath(d), scannedDirs);
|
||||
return count;
|
||||
}
|
||||
|
||||
void Database::indexDir(const QDir &dir, QProgressDialog *progress)
|
||||
{
|
||||
m_progress = 0;
|
||||
QStringList scannedDirs;
|
||||
int count = countFiles(dir, scannedDirs);
|
||||
progress->setMaximum(count);
|
||||
database.transaction();
|
||||
|
||||
scannedDirs.clear();
|
||||
if(indexDir2(dir, progress, scannedDirs))
|
||||
{
|
||||
database.commit();
|
||||
emit databaseChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
database.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
void Database::reindex(QProgressDialog *progress)
|
||||
{
|
||||
QVariantList deleteids;
|
||||
database.transaction();
|
||||
QSqlQuery size("SELECT COUNT(*) FROM fits_files", database);
|
||||
size.next();
|
||||
progress->setMaximum(size.value(0).toInt());
|
||||
QSqlQuery files("SELECT id,file,mtime FROM fits_files", database);
|
||||
int i = 0;
|
||||
while(files.next())
|
||||
{
|
||||
QString path = files.value(1).toString();
|
||||
QFileInfo file(path);
|
||||
if(file.exists() && file.fileTime(QFileDevice::FileModificationTime).toUTC().toString(Qt::ISODate) != files.value(2).toString())
|
||||
indexFile(file);
|
||||
if(!file.exists())
|
||||
deleteids.append(files.value(0));
|
||||
progress->setValue(i++);
|
||||
if(progress->wasCanceled())
|
||||
{
|
||||
database.rollback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
QSqlQuery deleteFiles("DELETE FROM fits_files WHERE id = ?", database);
|
||||
deleteFiles.bindValue(0, deleteids);
|
||||
deleteFiles.execBatch();
|
||||
database.commit();
|
||||
}
|
||||
|
||||
QStringList Database::getFitsKeywords()
|
||||
{
|
||||
m_headerKeywords.exec();
|
||||
QStringList keywords;
|
||||
while(m_headerKeywords.next())
|
||||
{
|
||||
keywords << m_headerKeywords.value(0).toString();
|
||||
}
|
||||
return keywords;
|
||||
}
|
||||
|
||||
QVector<SkyObject> Database::getObjects(double minRa, double maxRa, double minDec, double maxDec)
|
||||
{
|
||||
QVector<SkyObject> objects;
|
||||
if(!ngc.isOpen())return objects;
|
||||
|
||||
m_getNgc.bindValue(0, minRa);
|
||||
m_getNgc.bindValue(1, maxRa);
|
||||
m_getNgc.bindValue(2, minDec);
|
||||
m_getNgc.bindValue(3, maxDec);
|
||||
|
||||
if(m_getNgc.exec())
|
||||
{
|
||||
while(m_getNgc.next())
|
||||
{
|
||||
QString name;
|
||||
QString m = m_getNgc.value("M").toString();
|
||||
QString ic = m_getNgc.value("IC").toString();
|
||||
if(!m.isEmpty())name = "M" + m + " ";
|
||||
if(!ic.isEmpty())name += "IC" + ic + " ";
|
||||
name += m_getNgc.value("Name").toString();
|
||||
|
||||
objects.append({
|
||||
name,
|
||||
m_getNgc.value("Common names").toString(),
|
||||
{m_getNgc.value("RA_deg").toDouble(), m_getNgc.value("DEC_deg").toDouble()},
|
||||
m_getNgc.value("MajAx").toDouble(),
|
||||
m_getNgc.value("MinAx").toDouble(),
|
||||
m_getNgc.value("PosAng").toDouble(),
|
||||
m_getNgc.value("mag").isNull() ? NAN : m_getNgc.value("mag").toDouble(),
|
||||
{0, 0},
|
||||
});
|
||||
}
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
bool Database::indexDir2(const QDir &dir, QProgressDialog *progress, QStringList &scannedDirs)
|
||||
{
|
||||
if(scannedDirs.contains(dir.canonicalPath()))return true;
|
||||
scannedDirs.append(dir.canonicalPath());
|
||||
|
||||
QFileInfoList files = dir.entryInfoList(nameFilters, QDir::Files);
|
||||
QStringList dirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
|
||||
for(const QString &d : dirs)
|
||||
{
|
||||
if(!indexDir2(dir.filePath(d), progress, scannedDirs))
|
||||
return false;
|
||||
}
|
||||
for(const QFileInfo &file : files)
|
||||
{
|
||||
progress->setValue(m_progress++);
|
||||
if(progress->wasCanceled())return false;
|
||||
if(!indexFile(file))return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Database::indexFile(const QFileInfo &file)
|
||||
{
|
||||
ImageInfoData info;
|
||||
QString filePath = file.absoluteFilePath();
|
||||
QString mtime = file.fileTime(QFileDevice::FileModificationTime).toUTC().toString(Qt::ISODate);
|
||||
m_checkFile.bindValue(0, filePath);
|
||||
m_checkFile.exec();
|
||||
if(m_checkFile.next())
|
||||
{
|
||||
if(m_checkFile.value(1).toString() == mtime)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
m_deleteFile.bindValue(0, m_checkFile.value(0).toLongLong());
|
||||
m_deleteFile.exec();
|
||||
}
|
||||
}
|
||||
|
||||
bool ok;
|
||||
if(filePath.endsWith(".xisf", Qt::CaseInsensitive))
|
||||
ok = readXISFHeader(filePath, info);
|
||||
else
|
||||
ok = readFITSHeader(filePath, info);
|
||||
|
||||
qlonglong last_id = -1;
|
||||
if(ok)
|
||||
{
|
||||
if(info.wcs)
|
||||
{
|
||||
double minRa, maxRa, minDec, maxDec, crVal1, crVal2;
|
||||
info.wcs->calculateBounds(minRa, maxRa, minDec, maxDec, crVal1, crVal2);
|
||||
qDebug() << "bounds" << minRa << maxRa << minDec << maxDec;
|
||||
m_insertFileWcs.bindValue(0, filePath);
|
||||
m_insertFileWcs.bindValue(1, mtime);
|
||||
m_insertFileWcs.bindValue(2, minRa);
|
||||
m_insertFileWcs.bindValue(3, maxRa);
|
||||
m_insertFileWcs.bindValue(4, minDec);
|
||||
m_insertFileWcs.bindValue(5, maxDec);
|
||||
m_insertFileWcs.bindValue(6, crVal1);
|
||||
m_insertFileWcs.bindValue(7, crVal2);
|
||||
if(!m_insertFileWcs.exec())
|
||||
{
|
||||
qDebug() << "Database error" << m_insertFileWcs.lastError();
|
||||
return false;
|
||||
}
|
||||
last_id = m_insertFileWcs.lastInsertId().toLongLong();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_insertFile.bindValue(0, filePath);
|
||||
m_insertFile.bindValue(1, mtime);
|
||||
if(!m_insertFile.exec())
|
||||
{
|
||||
qDebug() << "Database error" << m_insertFile.lastError();
|
||||
return false;
|
||||
}
|
||||
last_id = m_insertFile.lastInsertId().toLongLong();
|
||||
}
|
||||
|
||||
QVariantList file_id, keys, values, comments;
|
||||
for(const auto &record : info.fitsHeader)
|
||||
{
|
||||
file_id << last_id;
|
||||
keys << QString(record.key);
|
||||
values << record.value.toString();
|
||||
comments << QString(record.comment);
|
||||
}
|
||||
m_insertFitsHeader.bindValue(0, file_id);
|
||||
m_insertFitsHeader.bindValue(1, keys);
|
||||
m_insertFitsHeader.bindValue(2, values);
|
||||
m_insertFitsHeader.bindValue(3, comments);
|
||||
if(!m_insertFitsHeader.execBatch())
|
||||
{
|
||||
qDebug() << "Database error" << m_insertFitsHeader.lastError();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qDebug() << "Indexed" << filePath << last_id;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef DATABASE_H
|
||||
#define DATABASE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
#include <QDir>
|
||||
#include <QProgressDialog>
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class Database : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QSqlDatabase database;
|
||||
QSqlDatabase ngc;
|
||||
QSqlQuery m_markQuery;
|
||||
QSqlQuery m_unmarkQuery;
|
||||
QSqlQuery m_isMarkedQuery;
|
||||
|
||||
QSqlQuery m_insertFile;
|
||||
QSqlQuery m_insertFileWcs;
|
||||
QSqlQuery m_insertFitsHeader;
|
||||
QSqlQuery m_checkFile;
|
||||
QSqlQuery m_headerKeywords;
|
||||
QSqlQuery m_deleteFile;
|
||||
|
||||
QSqlQuery m_getNgc;
|
||||
|
||||
int m_progress;
|
||||
public:
|
||||
explicit Database(QObject *parent = 0);
|
||||
bool init(const QLatin1String &connectionName = QLatin1String(QSqlDatabase::defaultConnection));
|
||||
bool mark(const QString &filename);
|
||||
bool unmark(const QString &filename);
|
||||
bool mark(const QStringList &filenames);
|
||||
bool unmark(const QStringList &filenames);
|
||||
bool isMarked(const QString &filename);
|
||||
QStringList getMarkedFiles();
|
||||
void clearMarkedFiles();
|
||||
|
||||
void indexDir(const QDir &dir, QProgressDialog *progress);
|
||||
void reindex(QProgressDialog *progress);
|
||||
QStringList getFitsKeywords();
|
||||
QVector<SkyObject> getObjects(double minRa, double maxRa, double minDec, double maxDec);
|
||||
protected:
|
||||
bool indexDir2(const QDir &dir, QProgressDialog *progress, QStringList &scannedDirs);
|
||||
bool indexFile(const QFileInfo &file);
|
||||
bool checkError(QSqlQuery &query);
|
||||
int checkVersion(QSqlDatabase &db);
|
||||
signals:
|
||||
void databaseChanged();
|
||||
};
|
||||
|
||||
#endif // DATABASE_H
|
||||
@@ -0,0 +1,422 @@
|
||||
#include "databaseview.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QSettings>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHeaderView>
|
||||
#include <QSqlError>
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QRegularExpression>
|
||||
#include <iostream>
|
||||
#include "batchprocessing.h"
|
||||
|
||||
const QStringList DEFAULT_COLUMNS = {"EXPTIME", "OBJECT", "RA", "DEC"};
|
||||
|
||||
double RA(const QString &ra)
|
||||
{
|
||||
QRegularExpression reg("(\\d+)\\s*(\\d+)?\\s*(\\d+)?");
|
||||
QRegularExpressionMatch match = reg.match(ra);
|
||||
double h = match.captured(1).toDouble();
|
||||
double m = match.captured(2).toDouble();
|
||||
double s = match.captured(3).toDouble();
|
||||
qDebug() << "RA" << match.capturedTexts() << h << m << s;
|
||||
return h*15 + m*0.25 + s*15/3600;
|
||||
}
|
||||
|
||||
double DEC(const QString &dec)
|
||||
{
|
||||
QRegularExpression reg("([\\+\\-])?(\\d+)\\s*(\\d+)?\\s*(\\d+)?");
|
||||
QRegularExpressionMatch match = reg.match(dec);
|
||||
double sign = match.captured(1) == "-" ? -1 : 1;
|
||||
double d = match.captured(2).toDouble();
|
||||
double m = match.captured(3).toDouble();
|
||||
double s = match.captured(4).toDouble();
|
||||
qDebug() << "DEC" << match.capturedTexts() << sign << d << m << s;
|
||||
return sign * (d + m/60 + s/3600);
|
||||
}
|
||||
|
||||
SelectColumnsDialog::SelectColumnsDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
m_listWidget = new QListWidget(this);
|
||||
m_listWidget->setSelectionMode(QAbstractItemView::MultiSelection);
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
layout->addWidget(m_listWidget);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
layout->addWidget(buttonBox);
|
||||
|
||||
setWindowTitle(tr("Select columns"));
|
||||
}
|
||||
|
||||
void SelectColumnsDialog::setColumns(QStringList columns)
|
||||
{
|
||||
QSettings settings;
|
||||
m_listWidget->addItems(columns);
|
||||
QStringList selected = settings.value("databaseview/selectedColumns", DEFAULT_COLUMNS).toStringList();
|
||||
for(auto &sel : selected)
|
||||
{
|
||||
int i = columns.indexOf(sel);
|
||||
if(i>=0)
|
||||
m_listWidget->item(i)->setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList SelectColumnsDialog::selectedColumns()
|
||||
{
|
||||
QStringList ret;
|
||||
for(auto &sel : m_listWidget->selectedItems())
|
||||
ret.append(sel->text());
|
||||
return ret;
|
||||
}
|
||||
|
||||
FITSFileModel::FITSFileModel(Database *database, QObject *parent) : QSqlQueryModel(parent)
|
||||
, m_database(database)
|
||||
{
|
||||
}
|
||||
|
||||
void FITSFileModel::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
if(column < 0)
|
||||
m_sort.clear();
|
||||
else if(column <= m_columns.size())
|
||||
{
|
||||
if(column == 0)m_sort = " ORDER BY f.file ";
|
||||
else m_sort = QString(" ORDER BY \"h%1_value\" ").arg(column-1);
|
||||
m_sort += order == Qt::AscendingOrder ? "ASC" : "DESC";
|
||||
prepareQuery();
|
||||
}
|
||||
}
|
||||
|
||||
void FITSFileModel::setColumns(const QStringList &columns)
|
||||
{
|
||||
m_columns = columns;
|
||||
prepareQuery();
|
||||
}
|
||||
|
||||
void FITSFileModel::setFilter(const QStringList &key, const QStringList &value, const QStringList &limit)
|
||||
{
|
||||
if(value.isEmpty())
|
||||
{
|
||||
m_key.clear();
|
||||
m_value.clear();
|
||||
m_limit.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_key = key;
|
||||
m_value = value;
|
||||
m_limit = limit;
|
||||
}
|
||||
prepareQuery();
|
||||
}
|
||||
|
||||
QVariant FITSFileModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(role == Qt::FontRole && index.column() == 0)
|
||||
{
|
||||
QFont font;
|
||||
QString file = index.data().toString();
|
||||
font.setBold(m_markedFiles.contains(file));
|
||||
return font;
|
||||
}
|
||||
if(role == Qt::ToolTipRole && index.column() == 0)
|
||||
{
|
||||
return QSqlQueryModel::data(index, Qt::DisplayRole);
|
||||
}
|
||||
return QSqlQueryModel::data(index, role);
|
||||
}
|
||||
|
||||
void FITSFileModel::filesMarked(const QModelIndexList &indexes)
|
||||
{
|
||||
for(auto &index : indexes)
|
||||
{
|
||||
QString file = index.data().toString();
|
||||
if(!m_markedFiles.contains(file))
|
||||
{
|
||||
m_markedFiles.insert(file);
|
||||
emit dataChanged(index, index, {Qt::FontRole});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FITSFileModel::filesUnmarked(const QModelIndexList &indexes)
|
||||
{
|
||||
for(auto &index : indexes)
|
||||
{
|
||||
QString file = index.data().toString();
|
||||
if(m_markedFiles.contains(file))
|
||||
{
|
||||
m_markedFiles.remove(file);
|
||||
emit dataChanged(index, index, {Qt::FontRole});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FITSFileModel::prepareQuery()
|
||||
{
|
||||
QString cols;
|
||||
QString join;
|
||||
QStringList where;
|
||||
QString sql = m_columns.size() ? "SELECT f.file," : "SELECT f.file";
|
||||
for(int i=0; i<m_value.size(); i++)
|
||||
{
|
||||
if(m_key[i] == "file")
|
||||
where.append(QString(" f.file LIKE '%1' ").arg(m_value[i]));
|
||||
else if(m_key[i] == "RA pos")
|
||||
where.append(QString(" %1 BETWEEN f.minRa AND f.maxRa ").arg(RA(m_value[i])));
|
||||
else if(m_key[i] == "DEC pos")
|
||||
where.append(QString(" %1 BETWEEN f.minDec AND f.maxDec ").arg(DEC(m_value[i])));
|
||||
else if(m_key[i] == "RA range")
|
||||
where.append(QString(" crVal1 BETWEEN %1 AND %2 ").arg(RA(m_value[i])).arg(RA(m_limit[i])));
|
||||
else if(m_key[i] == "DEC range")
|
||||
where.append(QString(" crVal2 BETWEEN %1 AND %2 ").arg(DEC(m_value[i])).arg(DEC(m_limit[i])));
|
||||
else
|
||||
join += QString(" JOIN fits_headers AS s%1 ON f.id=s%1.id_file AND s%1.key='%2' AND s%1.value LIKE '%3'").arg(i).arg(m_key[i]).arg(m_value[i]);
|
||||
}
|
||||
int i=0;
|
||||
for(auto &column : m_columns)
|
||||
{
|
||||
cols += QString("GROUP_CONCAT(h%1.value) AS h%1_value,").arg(i);
|
||||
join += QString(" LEFT JOIN fits_headers AS h%1 ON f.id=h%1.id_file AND h%1.key='%2'").arg(i).arg(column);
|
||||
i++;
|
||||
}
|
||||
cols.chop(1);
|
||||
sql += cols;
|
||||
sql += " FROM fits_files AS f";
|
||||
sql += join;
|
||||
if(!where.isEmpty())sql += " WHERE " + where.join("AND");
|
||||
sql += " GROUP BY f.id" + m_sort;
|
||||
setQuery(sql);
|
||||
setHeaderData(0, Qt::Horizontal, tr("File name"));
|
||||
i = 1;
|
||||
for(auto &column : m_columns)
|
||||
{
|
||||
setHeaderData(i++, Qt::Horizontal, column);
|
||||
}
|
||||
std::cout << sql.toStdString() << std::endl;
|
||||
if(lastError().type() != QSqlError::NoError)
|
||||
qDebug() << "Database error" << lastError();
|
||||
|
||||
QStringList list = m_database->getMarkedFiles();
|
||||
m_markedFiles = QSet<QString>(list.begin(), list.end());
|
||||
}
|
||||
|
||||
DatabaseTableView::DatabaseTableView(QWidget *parent) : QTableView(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void DatabaseTableView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu menu;
|
||||
QAction *mark = menu.addAction(tr("Mark"));
|
||||
QAction *unmark = menu.addAction(tr("Unmark"));
|
||||
QAction *open = menu.addAction(tr("Open"));
|
||||
QAction *openDirAction = menu.addAction(tr("Open file location"));
|
||||
|
||||
QAction *a = menu.exec(event->globalPos());
|
||||
if(a == nullptr)
|
||||
return;
|
||||
|
||||
QModelIndexList indexes = selectionModel()->selectedRows();
|
||||
|
||||
if(a == mark)
|
||||
emit filesMarked(indexes);
|
||||
else if(a == unmark)
|
||||
emit filesUnmarked(indexes);
|
||||
else if(a == open)
|
||||
emit openFile(indexes);
|
||||
else if(a == openDirAction)
|
||||
emit openDir(indexes);
|
||||
}
|
||||
|
||||
DataBaseView::DataBaseView(Database *database, QWidget *parent) : QWidget(parent)
|
||||
,m_database(database)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
m_tableView = new DatabaseTableView(this);
|
||||
m_tableView->verticalHeader()->setDefaultSectionSize(1);
|
||||
m_tableView->setSortingEnabled(true);
|
||||
m_tableView->horizontalHeader()->setSortIndicatorShown(true);
|
||||
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
layout->addWidget(m_tableView);
|
||||
connect(m_tableView, &QTableView::activated, this, &DataBaseView::itemActivated);
|
||||
|
||||
m_model = new FITSFileModel(m_database, this);
|
||||
|
||||
QSettings settings;
|
||||
m_tableView->setModel(m_model);
|
||||
m_model->setColumns(settings.value("databaseview/selectedColumns", DEFAULT_COLUMNS).toStringList());
|
||||
m_tableView->horizontalHeader()->restoreState(settings.value("databaseview/header").toByteArray());
|
||||
|
||||
QHBoxLayout *hlayout = new QHBoxLayout();
|
||||
layout->addLayout(hlayout);
|
||||
|
||||
QPushButton *selectColumnsButton = new QPushButton(tr("Select columns"), this);
|
||||
hlayout->addWidget(selectColumnsButton);
|
||||
connect(selectColumnsButton, &QPushButton::pressed, this, &DataBaseView::selectColumns);
|
||||
|
||||
connect(m_tableView, &DatabaseTableView::filesMarked, [this](QModelIndexList indexes){
|
||||
QStringList files;
|
||||
for(auto &index : indexes)
|
||||
files.append(index.data().toString());
|
||||
m_database->mark(files);
|
||||
m_model->filesMarked(indexes);
|
||||
});
|
||||
connect(m_tableView, &DatabaseTableView::filesUnmarked, [this](QModelIndexList indexes){
|
||||
QStringList files;
|
||||
for(auto &index : indexes)
|
||||
files.append(index.data().toString());
|
||||
m_database->unmark(files);
|
||||
m_model->filesUnmarked(indexes);
|
||||
});
|
||||
connect(m_tableView, &DatabaseTableView::openFile, [this](QModelIndexList indexes){
|
||||
if(indexes.size())
|
||||
emit loadFile(m_model->data(indexes.front().siblingAtColumn(0)).toString());
|
||||
});
|
||||
connect(m_tableView, &DatabaseTableView::openDir, [this](QModelIndexList indexes){
|
||||
if(indexes.size())
|
||||
{
|
||||
QFileInfo info(m_model->data(indexes.front().siblingAtColumn(0)).toString());
|
||||
openDir(info.absolutePath());
|
||||
}
|
||||
});
|
||||
|
||||
auto addFilterItems = [](QComboBox *combobox, const QStringList &fitsKeywords)
|
||||
{
|
||||
combobox->clear();
|
||||
combobox->addItem("file");
|
||||
combobox->addItem("RA pos");
|
||||
combobox->addItem("DEC pos");
|
||||
combobox->addItem("RA range");
|
||||
combobox->addItem("DEC range");
|
||||
combobox->addItems(fitsKeywords);
|
||||
};
|
||||
|
||||
QStringList fitsKeywords = m_database->getFitsKeywords();
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
m_filterKeyword[i] = new QComboBox(this);
|
||||
m_filterKeyword[i]->setMaximumWidth(300);
|
||||
addFilterItems(m_filterKeyword[i], fitsKeywords);
|
||||
|
||||
|
||||
m_search[i] = new QLineEdit(this);
|
||||
m_search[i]->setPlaceholderText(tr("Text to search, you can % as wildcard"));
|
||||
|
||||
m_limit[i] = new QLineEdit(this);
|
||||
m_limit[i]->hide();
|
||||
connect(m_filterKeyword[i], static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this, i](int index){
|
||||
if(index == 3 || index == 4)m_limit[i]->show();
|
||||
else m_limit[i]->hide();
|
||||
});
|
||||
|
||||
connect(m_search[i], &QLineEdit::returnPressed, this, &DataBaseView::applyFilter);
|
||||
connect(m_limit[i], &QLineEdit::returnPressed, this, &DataBaseView::applyFilter);
|
||||
hlayout->addWidget(m_filterKeyword[i]);
|
||||
hlayout->addWidget(m_search[i]);
|
||||
hlayout->addWidget(m_limit[i]);
|
||||
}
|
||||
|
||||
QPushButton *filterButton = new QPushButton(tr("Filter"), this);
|
||||
connect(filterButton, &QPushButton::pressed, this, &DataBaseView::applyFilter);
|
||||
hlayout->addWidget(filterButton);
|
||||
|
||||
connect(m_database, &Database::databaseChanged, [this, &addFilterItems](){
|
||||
QStringList fitsKeywords = m_database->getFitsKeywords();
|
||||
for(int i=0; i<3; i++)
|
||||
addFilterItems(m_filterKeyword[i], fitsKeywords);
|
||||
|
||||
applyFilter();
|
||||
});
|
||||
}
|
||||
|
||||
DataBaseView::~DataBaseView()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("databaseview/header", m_tableView->horizontalHeader()->saveState());
|
||||
}
|
||||
|
||||
void DataBaseView::selectColumns()
|
||||
{
|
||||
SelectColumnsDialog dialog;
|
||||
QStringList columns = m_database->getFitsKeywords();
|
||||
dialog.setColumns(columns);
|
||||
if(dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList columns = dialog.selectedColumns();
|
||||
settings.setValue("databaseview/selectedColumns", columns);
|
||||
m_model->setColumns(columns);
|
||||
}
|
||||
}
|
||||
|
||||
void DataBaseView::loadDatabase()
|
||||
{
|
||||
QSettings settings;
|
||||
m_model->setColumns(settings.value("databaseview/selectedColumns", DEFAULT_COLUMNS).toStringList());
|
||||
}
|
||||
|
||||
void DataBaseView::itemActivated(const QModelIndex &index)
|
||||
{
|
||||
emit loadFile(m_model->data(index.siblingAtColumn(0)).toString());
|
||||
}
|
||||
|
||||
void DataBaseView::applyFilter()
|
||||
{
|
||||
QStringList keys;
|
||||
QStringList values;
|
||||
QStringList limits;
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
QString key = m_filterKeyword[i]->currentText();
|
||||
if(!m_search[i]->text().isEmpty() && !keys.contains(key))
|
||||
{
|
||||
keys.append(key);
|
||||
values.append(m_search[i]->text());
|
||||
limits.append(m_limit[i]->text());
|
||||
}
|
||||
}
|
||||
m_model->setFilter(keys, values, limits);
|
||||
}
|
||||
|
||||
bool DataBaseView::exportCSV(const QString &path)
|
||||
{
|
||||
QFile csv(path);
|
||||
if(!csv.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return false;
|
||||
|
||||
QSqlQuery sql(m_model->query().lastQuery());
|
||||
int colCount = m_model->columnCount();
|
||||
QStringList header;
|
||||
for(int i=0; i<colCount; i++)
|
||||
header.append(m_model->headerData(i, Qt::Horizontal).toString());
|
||||
|
||||
csv.write(header.join(",").toUtf8());
|
||||
csv.write("\n");
|
||||
|
||||
while(sql.next())
|
||||
{
|
||||
QStringList columns;
|
||||
for(int i=0; i<colCount; i++)
|
||||
{
|
||||
QString val = sql.value(i).toString();
|
||||
val.replace("\"", "\"\"");
|
||||
if(val.contains('"') || val.contains(','))
|
||||
{
|
||||
val.prepend('"');
|
||||
val.append('"');
|
||||
}
|
||||
columns.append(val);
|
||||
}
|
||||
csv.write(columns.join(",").toUtf8());
|
||||
csv.write("\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#ifndef DATABASEVIEW_H
|
||||
#define DATABASEVIEW_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
#include <QSqlQueryModel>
|
||||
#include <QTableView>
|
||||
#include <QListWidget>
|
||||
#include <QComboBox>
|
||||
#include <QLineEdit>
|
||||
#include "database.h"
|
||||
|
||||
class SelectColumnsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
QListWidget *m_listWidget;
|
||||
public:
|
||||
explicit SelectColumnsDialog(QWidget *parent = nullptr);
|
||||
void setColumns(QStringList columns);
|
||||
QStringList selectedColumns();
|
||||
};
|
||||
|
||||
class FITSFileModel : public QSqlQueryModel
|
||||
{
|
||||
Q_OBJECT
|
||||
QStringList m_columns;
|
||||
QString m_sort;
|
||||
QStringList m_key;
|
||||
QStringList m_value;
|
||||
QStringList m_limit;
|
||||
QSet<QString> m_markedFiles;
|
||||
Database *m_database;
|
||||
public:
|
||||
explicit FITSFileModel(Database *database, QObject *parent = nullptr);
|
||||
void sort(int column, Qt::SortOrder order) override;
|
||||
void setColumns(const QStringList &columns);
|
||||
void setFilter(const QStringList &key, const QStringList &value, const QStringList &limit);
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
void filesMarked(const QModelIndexList &indexes);
|
||||
void filesUnmarked(const QModelIndexList &indexes);
|
||||
protected:
|
||||
void prepareQuery();
|
||||
};
|
||||
|
||||
class DatabaseTableView : public QTableView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DatabaseTableView(QWidget *parent = nullptr);
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
signals:
|
||||
void filesMarked(QModelIndexList indexes);
|
||||
void filesUnmarked(QModelIndexList indexes);
|
||||
void openFile(QModelIndexList indexes);
|
||||
void openDir(QModelIndexList indexes);
|
||||
};
|
||||
|
||||
class DataBaseView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Database *m_database;
|
||||
DatabaseTableView *m_tableView;
|
||||
FITSFileModel *m_model;
|
||||
QComboBox *m_filterKeyword[3];
|
||||
QLineEdit *m_search[3];
|
||||
QLineEdit *m_limit[3];
|
||||
public:
|
||||
explicit DataBaseView(Database *database, QWidget *parent = nullptr);
|
||||
~DataBaseView() override;
|
||||
public slots:
|
||||
void selectColumns();
|
||||
void loadDatabase();
|
||||
void itemActivated(const QModelIndex &index);
|
||||
void applyFilter();
|
||||
bool exportCSV(const QString &path);
|
||||
signals:
|
||||
void loadFile(QString file);
|
||||
};
|
||||
|
||||
#endif // DATABASEVIEW_H
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifdef FLATPAK
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusUnixFileDescriptor>
|
||||
#include <QString>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
//flatpak bug prevent to use QFile::moveToTrash
|
||||
bool moveToTrash(const QString &path)
|
||||
{
|
||||
QDBusConnection con = QDBusConnection::sessionBus();
|
||||
QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop", "org.freedesktop.portal.Trash", "TrashFile");
|
||||
int fd = ::open(path.toLocal8Bit().data(), O_RDWR);
|
||||
if(fd >= 0)
|
||||
{
|
||||
QList<QVariant> args = {QVariant::fromValue(QDBusUnixFileDescriptor(fd))};
|
||||
message.setArguments(args);
|
||||
QDBusMessage reply = con.call(message);
|
||||
::close(fd);
|
||||
if(reply.type() == QDBusMessage::ReplyMessage && reply.arguments().size() && reply.arguments().first().toInt())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
|
||||
bool moveToTrash(const QString &path)
|
||||
{
|
||||
return QFile::moveToTrash(path);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,160 @@
|
||||
#include "filesystemwidget.h"
|
||||
#include <QSettings>
|
||||
#include <QVBoxLayout>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
#include <QSettings>
|
||||
#include <QHeaderView>
|
||||
|
||||
FilesystemWidget::FilesystemWidget(QAbstractItemModel *model, QWidget *parent) : QWidget(parent)
|
||||
, m_model(model)
|
||||
{
|
||||
m_listView = new QListView(this);
|
||||
m_listView->setModel(model);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->addWidget(m_listView);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
connect(m_listView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FilesystemWidget::fileClicked);
|
||||
}
|
||||
|
||||
void FilesystemWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu menu;
|
||||
menu.addAction(tr("Sort by filename"), [this](){ emit sortChanged(QDir::Name); });
|
||||
menu.addAction(tr("Sort by time"), [this](){ emit sortChanged(QDir::Time); });
|
||||
menu.addAction(tr("Sort by size"), [this](){ emit sortChanged(QDir::Size); });
|
||||
menu.addAction(tr("Sort by type"), [this](){ emit sortChanged(QDir::Type); });
|
||||
menu.addAction(tr("Reverse"), [this](){ emit reverseSort(); });
|
||||
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
|
||||
void FilesystemWidget::selectFile(int row)
|
||||
{
|
||||
QModelIndex index = m_model->index(row, 0);
|
||||
m_listView->selectionModel()->select(index, QItemSelectionModel::SelectCurrent);
|
||||
m_listView->scrollTo(index);
|
||||
}
|
||||
|
||||
void FilesystemWidget::fileClicked(const QModelIndex &index, const QModelIndex &)
|
||||
{
|
||||
if(index.isValid())
|
||||
emit fileSelected(index.row());
|
||||
}
|
||||
|
||||
QVariant FileSystemModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(role == Qt::ToolTipRole && index.column() == 0)role = Qt::DisplayRole;
|
||||
return QFileSystemModel::data(index, role);
|
||||
}
|
||||
|
||||
Filetree::Filetree(QWidget *parent) : QTreeView(parent)
|
||||
{
|
||||
QSettings settings;
|
||||
m_rootDir = settings.value("filetree/rootDir", QDir::homePath()).toString();
|
||||
m_fileSystemModel = new FileSystemModel(this);
|
||||
m_fileSystemModel->setRootPath(m_rootDir);
|
||||
m_fileSystemModel->setNameFilters({"*.fits", "*.fit", "*.fz", "*.xisf", "*.jpg", "*.jpeg", "*.png", "*.cr2", "*.nef", "*.dng"});
|
||||
m_fileSystemModel->setNameFilterDisables(false);
|
||||
if(settings.value("filetree/showHidden", false).toBool())
|
||||
m_fileSystemModel->setFilter(m_fileSystemModel->filter() | QDir::Hidden);
|
||||
|
||||
setModel(m_fileSystemModel);
|
||||
setRootIndex(m_fileSystemModel->index(m_rootDir));
|
||||
header()->restoreState(settings.value("filetree/header").toByteArray());
|
||||
}
|
||||
|
||||
Filetree::~Filetree()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("filetree/rootDir", m_rootDir);
|
||||
settings.setValue("filetree/header", header()->saveState());
|
||||
settings.setValue("filetree/showHidden", (bool)(m_fileSystemModel->filter() & QDir::Hidden));
|
||||
}
|
||||
|
||||
void Filetree::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QModelIndex index = indexAt(event->pos());
|
||||
QFileInfo info = m_fileSystemModel->fileInfo(index);
|
||||
QMenu menu;
|
||||
QAction *open = nullptr;
|
||||
QAction *setRoot = nullptr;
|
||||
QAction *copy = nullptr;
|
||||
QAction *move = nullptr;
|
||||
QAction *indexDir = nullptr;
|
||||
|
||||
if(info.isFile())
|
||||
open = menu.addAction(tr("Open"));
|
||||
|
||||
if(info.isDir())
|
||||
{
|
||||
open = menu.addAction(tr("Open"));
|
||||
setRoot = menu.addAction(tr("Set as root"));
|
||||
copy = menu.addAction(tr("Copy marked files"));
|
||||
move = menu.addAction(tr("Move marked files"));
|
||||
indexDir = menu.addAction(tr("Index directory"));
|
||||
}
|
||||
menu.addSeparator();
|
||||
|
||||
QAction *resetRoot = menu.addAction(tr("Reset root"));
|
||||
QAction *goUp = menu.addAction(tr("Go up"));
|
||||
QAction *showHidden = menu.addAction(tr("Show hidden files"));
|
||||
showHidden->setCheckable(true);
|
||||
showHidden->setChecked(m_fileSystemModel->filter() & QDir::Hidden);
|
||||
|
||||
QAction *a = menu.exec(event->globalPos());
|
||||
if(a == nullptr)
|
||||
return;
|
||||
|
||||
if(a == open)
|
||||
{
|
||||
emit fileSelected(m_fileSystemModel->filePath(index));
|
||||
}
|
||||
else if(a == setRoot && index.isValid())
|
||||
{
|
||||
setRootIndex(index);
|
||||
m_rootDir = m_fileSystemModel->filePath(index);
|
||||
}
|
||||
else if(a == resetRoot)
|
||||
{
|
||||
setRootIndex(QModelIndex());
|
||||
m_rootDir = QDir::rootPath();
|
||||
}
|
||||
else if(a == goUp)
|
||||
{
|
||||
setRootIndex(rootIndex().parent());
|
||||
m_rootDir = m_fileSystemModel->filePath(rootIndex().parent());
|
||||
}
|
||||
else if(a == copy)
|
||||
{
|
||||
emit copyFiles(m_fileSystemModel->filePath(index));
|
||||
}
|
||||
else if(a == move)
|
||||
{
|
||||
emit moveFiles(m_fileSystemModel->filePath(index));
|
||||
}
|
||||
else if(a == indexDir)
|
||||
{
|
||||
emit indexDirectory(m_fileSystemModel->filePath(index));
|
||||
}
|
||||
else if(a == showHidden)
|
||||
{
|
||||
auto filter = m_fileSystemModel->filter();
|
||||
filter ^= QDir::Hidden;
|
||||
m_fileSystemModel->setFilter(filter);
|
||||
m_fileSystemModel->setRootPath(m_rootDir);
|
||||
}
|
||||
}
|
||||
|
||||
void Filetree::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
QModelIndex index = indexAt(event->pos());
|
||||
QFileInfo info = m_fileSystemModel->fileInfo(index);
|
||||
if(info.isFile())
|
||||
emit fileSelected(info.filePath());
|
||||
else
|
||||
QTreeView::mouseDoubleClickEvent(event);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef FILESYSTEMWIDGET_H
|
||||
#define FILESYSTEMWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QFileSystemModel>
|
||||
#include <QListView>
|
||||
#include <QTreeView>
|
||||
|
||||
class FilesystemWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
QListView *m_listView;
|
||||
QAbstractItemModel *m_model;
|
||||
public:
|
||||
explicit FilesystemWidget(QAbstractItemModel *model, QWidget *parent = nullptr);
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
public slots:
|
||||
void selectFile(int row);
|
||||
protected slots:
|
||||
void fileClicked(const QModelIndex &index, const QModelIndex &);
|
||||
signals:
|
||||
void fileSelected(int row);
|
||||
void sortChanged(QDir::SortFlag sort);
|
||||
void reverseSort();
|
||||
};
|
||||
|
||||
class FileSystemModel : public QFileSystemModel
|
||||
{
|
||||
public:
|
||||
explicit FileSystemModel(QObject *parent) : QFileSystemModel(parent){}
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
};
|
||||
|
||||
class Filetree : public QTreeView
|
||||
{
|
||||
Q_OBJECT
|
||||
FileSystemModel *m_fileSystemModel;
|
||||
QString m_rootDir;
|
||||
public:
|
||||
explicit Filetree(QWidget *parent = nullptr);
|
||||
~Filetree() override;
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
signals:
|
||||
void fileSelected(const QString &path);
|
||||
void copyFiles(const QString &path);
|
||||
void moveFiles(const QString &path);
|
||||
void indexDirectory(const QString &path);
|
||||
};
|
||||
|
||||
#endif // FILESYSTEMWIDGET_H
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "histogram.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QStyleOption>
|
||||
|
||||
Histogram::Histogram(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setStyleSheet("QWidget { background: white; color: black; } ");
|
||||
}
|
||||
|
||||
void Histogram::imageLoaded(Image *img)
|
||||
{
|
||||
if(img && img->rawImage())
|
||||
{
|
||||
m_histogram = img->rawImage()->imageStats().m_histogram;
|
||||
m_points.clear();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void Histogram::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), Qt::black);
|
||||
|
||||
uint h = height();
|
||||
uint w = width();
|
||||
|
||||
if(m_histogram.size())
|
||||
{
|
||||
if(m_points.size() != w)
|
||||
{
|
||||
m_points.clear();
|
||||
for(uint64_t i = 0; i < w; i++)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
uint64_t start = i * m_histogram.size() / w;
|
||||
uint64_t end =(i+1) * m_histogram.size() / w;
|
||||
for(uint64_t o = start; o < end; o++)
|
||||
sum += m_histogram[o];
|
||||
if(start != end)
|
||||
m_points.push_back(sum);
|
||||
}
|
||||
float scale = *std::max_element(m_points.begin(), m_points.end());
|
||||
if(m_log)
|
||||
{
|
||||
scale = std::log(scale);
|
||||
std::for_each(m_points.begin(), m_points.end(), [scale](float &x){ x = (x > 0 ? std::log(x) : 0.0f) / scale; });
|
||||
}
|
||||
else
|
||||
{
|
||||
std::for_each(m_points.begin(), m_points.end(), [scale](float &x){ x /= scale; });
|
||||
}
|
||||
}
|
||||
std::vector<QPointF> points;
|
||||
points.push_back(QPointF(0, h));
|
||||
for(size_t i = 0; i < m_points.size(); i++)
|
||||
{
|
||||
points.push_back(QPointF((float)i * w / m_points.size(), h - m_points[i] * h));
|
||||
}
|
||||
points.push_back(QPoint(w, h));
|
||||
painter.setBrush(Qt::gray);
|
||||
painter.setPen(Qt::white);
|
||||
|
||||
painter.drawPolygon(&points[0], points.size());
|
||||
}
|
||||
|
||||
QStyleOptionButton button;
|
||||
button.initFrom(this);
|
||||
button.state = m_log ? QStyle::State_On : QStyle::State_Off;
|
||||
button.text = tr("Logarithmic scale");
|
||||
button.rect = style()->subElementRect(QStyle::SE_CheckBoxClickRect, &button, this);
|
||||
button.rect.moveTop(0);
|
||||
button.rect.moveRight(w);
|
||||
style()->drawControl(QStyle::CE_CheckBox, &button, &painter, this);
|
||||
}
|
||||
|
||||
void Histogram::mouseReleaseEvent(QMouseEvent *)
|
||||
{
|
||||
m_log = !m_log;
|
||||
m_points.clear();
|
||||
update();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef HISTOGRAM_H
|
||||
#define HISTOGRAM_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "imageringlist.h"
|
||||
|
||||
class Histogram : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
std::vector<uint32_t> m_histogram;
|
||||
std::vector<float> m_points;
|
||||
bool m_log = false;
|
||||
public:
|
||||
explicit Histogram(QWidget *parent = nullptr);
|
||||
public slots:
|
||||
void imageLoaded(Image *img);
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void mouseReleaseEvent(QMouseEvent *) override;
|
||||
};
|
||||
|
||||
#endif // HISTOGRAM_H
|
||||
@@ -0,0 +1,527 @@
|
||||
#include "httpdownloader.h"
|
||||
#include <QNetworkReply>
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
#include <QFileInfo>
|
||||
|
||||
#ifdef PLATESOLVER
|
||||
#include "solver.h"
|
||||
#endif
|
||||
|
||||
// filename arcseconds range
|
||||
// index-4119.fits 1400–2000
|
||||
// index-4118.fits 1000–1400
|
||||
// index-4117.fits 680–1000
|
||||
// index-4116.fits 480–680
|
||||
// index-4115.fits 340–480
|
||||
// index-4114.fits 240–340
|
||||
// index-4113.fits 170–240
|
||||
// index-4112.fits 120–170
|
||||
// index-4111.fits 85–120
|
||||
// index-4110.fits 60—85
|
||||
// index-4109.fits 42–60
|
||||
// index-4108.fits 30–42
|
||||
// index-4107.fits 22–30
|
||||
// index-5206-*.fits 16–22
|
||||
// index-5205-*.fits 11–16
|
||||
// index-5204-*.fits 8–11
|
||||
// index-5203-*.fits 5.6–8.0
|
||||
// index-5202-*.fits 4.0–5.6
|
||||
// index-5201-*.fits 2.8–4.0
|
||||
|
||||
static const QMap<QString, QByteArray> md5 = {
|
||||
{"index-4107.fits.zst", "b4c3bc2b162fcb6417b2c3358dbf0543"},
|
||||
{"index-4108.fits.zst", "14a54b8e0abcb58efb7a828fc8f00267"},
|
||||
{"index-4109.fits.zst", "d6bce03dfbb527cc807ec360a8b4afa6"},
|
||||
{"index-4110.fits.zst", "da0aded630ee4650850f5828b4289746"},
|
||||
{"index-4111.fits.zst", "c11547481f97727e546b3b7c776f6394"},
|
||||
{"index-4112.fits.zst", "fd3f5ad964d69c66555b2c5b6d65d426"},
|
||||
{"index-4113.fits.zst", "4546e33817a161b8011e5f1321d39445"},
|
||||
{"index-4114.fits.zst", "ebc815fa4d9a3fd259fe22b84796fbc4"},
|
||||
{"index-4115.fits.zst", "5395b7b225ffe5329867354bc653887f"},
|
||||
{"index-4116.fits.zst", "341cebc6b962cede0f27d08c3b3a4f23"},
|
||||
{"index-4117.fits.zst", "e362a868ae0751d1a1e7f6b9e48a2f79"},
|
||||
{"index-4118.fits.zst", "a7d38ec4b1d69c859e875c8d6ba1679b"},
|
||||
{"index-4119.fits.zst", "9e07b46f4c4ca9ba536383d201e70c35"},
|
||||
{"index-5201-00.fits.zst", "87255d073576674ec50959522cbbc9eb"},
|
||||
{"index-5201-01.fits.zst", "b5154f26c8b2a6e143bdc11a062213ab"},
|
||||
{"index-5201-02.fits.zst", "cf0b08e586fe2ce306adb370c9f113e8"},
|
||||
{"index-5201-03.fits.zst", "eda457e3b3b419156b0cbdbe6c262fb7"},
|
||||
{"index-5201-04.fits.zst", "e1344126047714aac771d37861da4698"},
|
||||
{"index-5201-05.fits.zst", "1b2bf2fe61e883db7e65628761a934e8"},
|
||||
{"index-5201-06.fits.zst", "e4338de4ae486cedd31ec24b2677fe1d"},
|
||||
{"index-5201-07.fits.zst", "14665b88b4ab179d1bedd46acdc0d9bd"},
|
||||
{"index-5201-08.fits.zst", "636f411a83dfcf0c02e13ad4c0fed948"},
|
||||
{"index-5201-09.fits.zst", "8afe4edf38794225c1c3b23d72671d96"},
|
||||
{"index-5201-10.fits.zst", "742db3b858e160f69f2d189961fdfcad"},
|
||||
{"index-5201-11.fits.zst", "0ffb50923c71d269acc9c3c661d5429a"},
|
||||
{"index-5201-12.fits.zst", "535eefd763e08593e775e0f4e19c69e3"},
|
||||
{"index-5201-13.fits.zst", "e94426ba2275e76b11495105d780890d"},
|
||||
{"index-5201-14.fits.zst", "754a22f37153773662acaea5ea34a417"},
|
||||
{"index-5201-15.fits.zst", "7e399e94b7a15c2b97e14f49b3999070"},
|
||||
{"index-5201-16.fits.zst", "7441074047de8bccd1c09570b122466d"},
|
||||
{"index-5201-17.fits.zst", "bb7f5979b0d7963420dabfc5dd58407c"},
|
||||
{"index-5201-18.fits.zst", "ca950e0190d849d709357bacce6fc1d0"},
|
||||
{"index-5201-19.fits.zst", "36b84a8ac921064ad1a89f1155af7b31"},
|
||||
{"index-5201-20.fits.zst", "25eeda073f427462e0064acf23a38498"},
|
||||
{"index-5201-21.fits.zst", "0bd79e677363442dc7e994b2f088cd27"},
|
||||
{"index-5201-22.fits.zst", "071abfb9131ca5a6cda792870f97bd8d"},
|
||||
{"index-5201-23.fits.zst", "56721c1918e7ac114d43602ec6b17402"},
|
||||
{"index-5201-24.fits.zst", "4409be2965dacf376b0124d8f7342c3c"},
|
||||
{"index-5201-25.fits.zst", "e784c443787e6c3b3b51e7c82701b3b6"},
|
||||
{"index-5201-26.fits.zst", "02e58904a47e3305dd2a2c1e754c2b56"},
|
||||
{"index-5201-27.fits.zst", "f4f37044f787349dfda36e9aab07c348"},
|
||||
{"index-5201-28.fits.zst", "69893cbd149173c98d496b3d62d23526"},
|
||||
{"index-5201-29.fits.zst", "d55efc9ffca98742f7575c0fa7cd9420"},
|
||||
{"index-5201-30.fits.zst", "014c94da04a6e94897af09001e08bad8"},
|
||||
{"index-5201-31.fits.zst", "376319584d0b6a66bcaced5b31f705d4"},
|
||||
{"index-5201-32.fits.zst", "00f2873b2468d103661e6938fed2d905"},
|
||||
{"index-5201-33.fits.zst", "fa1ce3020ec8511885472c0eda777cd7"},
|
||||
{"index-5201-34.fits.zst", "7c66e555866806d61f90769bc626ef32"},
|
||||
{"index-5201-35.fits.zst", "f1767cf0b802a97b939711f3ecd788c8"},
|
||||
{"index-5201-36.fits.zst", "76825b18fef6546bbbeef3f8538a06cb"},
|
||||
{"index-5201-37.fits.zst", "af507a214fc69c7daa0688fce2924c7e"},
|
||||
{"index-5201-38.fits.zst", "05fc75e562c612c51bf7bacb3907aa02"},
|
||||
{"index-5201-39.fits.zst", "3eeaabf9b945d71fafff7c282f9a3add"},
|
||||
{"index-5201-40.fits.zst", "f891a7def591965ad4aa4ddc9cfb7718"},
|
||||
{"index-5201-41.fits.zst", "48ef1d61841567de4d94d3dc366df643"},
|
||||
{"index-5201-42.fits.zst", "d2c8041bbada7df9dcc5614c35edd7f1"},
|
||||
{"index-5201-43.fits.zst", "24fc923bdc21f696b1da418a131dc2bc"},
|
||||
{"index-5201-44.fits.zst", "690eb483b2d60e1e31ff0e71e1c19167"},
|
||||
{"index-5201-45.fits.zst", "7b7972184b9bd5d485680cb10ad7f566"},
|
||||
{"index-5201-46.fits.zst", "e09515bdd779241b6871eb9130980924"},
|
||||
{"index-5201-47.fits.zst", "95583b10a270336b4cfb31153305b666"},
|
||||
{"index-5202-00.fits.zst", "c877e6a6790d62a77753bc0b5c1c471f"},
|
||||
{"index-5202-01.fits.zst", "2069168ce477a4b9c0659eb97d9d3f3e"},
|
||||
{"index-5202-02.fits.zst", "80b53bdc44addc02c5a9a47183ae405e"},
|
||||
{"index-5202-03.fits.zst", "fcef358afae1ac87e1072bf94c33919f"},
|
||||
{"index-5202-04.fits.zst", "fb6e067de3d8f59868fc5daad9e45ac1"},
|
||||
{"index-5202-05.fits.zst", "168861bd176f0c9283ef091b855cefe8"},
|
||||
{"index-5202-06.fits.zst", "c88d93502450e872004d952f5cc970c6"},
|
||||
{"index-5202-07.fits.zst", "0eb1b5b3b15212f734f150087872a84c"},
|
||||
{"index-5202-08.fits.zst", "03a110b7092787f0da40117d3daf4ee8"},
|
||||
{"index-5202-09.fits.zst", "10b89b70f19e0042c1a832dfbb0f157c"},
|
||||
{"index-5202-10.fits.zst", "6d55a5356f820b437137586037049392"},
|
||||
{"index-5202-11.fits.zst", "ee561de1f6ad229b1aec1d2d576cf2d6"},
|
||||
{"index-5202-12.fits.zst", "16bb2e40a0a71a91b4304c0e030d9f14"},
|
||||
{"index-5202-13.fits.zst", "d6259841cb5209f1fe2262a94ebba80e"},
|
||||
{"index-5202-14.fits.zst", "7fcabd9e89f560dae0ea9032817ffc95"},
|
||||
{"index-5202-15.fits.zst", "42c4006c6482e6a46ed81191d03a6e54"},
|
||||
{"index-5202-16.fits.zst", "a726672e54dd30367664781f533a5f48"},
|
||||
{"index-5202-17.fits.zst", "67fc64ba28344d9fd31143fc5123acb3"},
|
||||
{"index-5202-18.fits.zst", "97ca32bc2a0ab5313547bd01485902e1"},
|
||||
{"index-5202-19.fits.zst", "d261fb13fac3aa19e930d48c6cf13929"},
|
||||
{"index-5202-20.fits.zst", "7a67bc4e1d1dd003280f48815d244b52"},
|
||||
{"index-5202-21.fits.zst", "bbc66dabd84be8fbb47452807aa6cbd5"},
|
||||
{"index-5202-22.fits.zst", "264b65ac94678334ea5dfbc4b329f2ca"},
|
||||
{"index-5202-23.fits.zst", "657492ac072d1679d77abc8f532aa2c9"},
|
||||
{"index-5202-24.fits.zst", "7cbd56e15c84d8b0ad605983aa0eabcb"},
|
||||
{"index-5202-25.fits.zst", "5cd3457ec29821bfca8da6da1ef76684"},
|
||||
{"index-5202-26.fits.zst", "253639c9680bafbbfa465d5de51de235"},
|
||||
{"index-5202-27.fits.zst", "a891918b3c22f7b1e2876358a6e971e2"},
|
||||
{"index-5202-28.fits.zst", "69ee777be98231c104a2e28d2c349111"},
|
||||
{"index-5202-29.fits.zst", "5b9985f33d66e4da27d4c618565f35f4"},
|
||||
{"index-5202-30.fits.zst", "04d6b9acb868242cf3615ca9bef4c1d8"},
|
||||
{"index-5202-31.fits.zst", "24e98426ed5a60b12a6b5652b8f68ce6"},
|
||||
{"index-5202-32.fits.zst", "502ca42a47d5234aab0829a387242dfc"},
|
||||
{"index-5202-33.fits.zst", "253c838df836f569afe854cf598f0c79"},
|
||||
{"index-5202-34.fits.zst", "8dd8e8289e9925058c9cc11e7e76c3e3"},
|
||||
{"index-5202-35.fits.zst", "5b1bb19b81633bb3c2c8d1dff4bb8507"},
|
||||
{"index-5202-36.fits.zst", "7990d2b9a7f120df9095d5a93d3c94f2"},
|
||||
{"index-5202-37.fits.zst", "9e5f0ff891ff1b726df0001547ffd322"},
|
||||
{"index-5202-38.fits.zst", "f06244e6825e4ddb101482295b5294cb"},
|
||||
{"index-5202-39.fits.zst", "390f90dae3a4124cc4c7aa157e8c8597"},
|
||||
{"index-5202-40.fits.zst", "b2d380ef7974fc55f0bf31ebb62ee019"},
|
||||
{"index-5202-41.fits.zst", "ae8058e144898d1b786202345b6581cf"},
|
||||
{"index-5202-42.fits.zst", "1247b8a91c3a9d6b10a324247c9e02c6"},
|
||||
{"index-5202-43.fits.zst", "e01049718b0c6f4eb8884c647c2cdf17"},
|
||||
{"index-5202-44.fits.zst", "802f0e2d56c0e4ec3d8c6d69832102d7"},
|
||||
{"index-5202-45.fits.zst", "83fe2cff3cf65317f5c1bf7b953519e9"},
|
||||
{"index-5202-46.fits.zst", "f12f308a3b53d95ffd7bc420700e4f44"},
|
||||
{"index-5202-47.fits.zst", "608a14303810c9762b25fc68896d2a26"},
|
||||
{"index-5203-00.fits.zst", "2862efb33765b7bbefb635dcad970298"},
|
||||
{"index-5203-01.fits.zst", "2cd34cef4b44ad1e770396baccb2a46c"},
|
||||
{"index-5203-02.fits.zst", "40c9f67282210cc374281cde023c4e71"},
|
||||
{"index-5203-03.fits.zst", "c8f40e164ec3ce1df92e3a121a127716"},
|
||||
{"index-5203-04.fits.zst", "cb40c64cad1d99b55dcb0b645ae388aa"},
|
||||
{"index-5203-05.fits.zst", "fe1900531baaa1bb3c513b356befd522"},
|
||||
{"index-5203-06.fits.zst", "8d4b7d902bacbd478b3a372338887097"},
|
||||
{"index-5203-07.fits.zst", "0f18e0822ea6b67a8e5536680df16218"},
|
||||
{"index-5203-08.fits.zst", "4cd0aa9bf00f903f3c71b37e047dfd2d"},
|
||||
{"index-5203-09.fits.zst", "c34aeb0674c2cbd3de31e2d9b20708f0"},
|
||||
{"index-5203-10.fits.zst", "64c3f710c11b5e18743d93a1e9e204f2"},
|
||||
{"index-5203-11.fits.zst", "518ee18fae552e2fd83f664028219f28"},
|
||||
{"index-5203-12.fits.zst", "712d6cddc97f8c183c4d9a130ba87ca4"},
|
||||
{"index-5203-13.fits.zst", "185a056e25091c23bbfa425026b9897b"},
|
||||
{"index-5203-14.fits.zst", "e85ade3d5b7d1c98b5d9174fb520c154"},
|
||||
{"index-5203-15.fits.zst", "182d21f53ddbec1f3585936e6463b9e8"},
|
||||
{"index-5203-16.fits.zst", "c2cf948d5714d61ecb6a5e235885c5ea"},
|
||||
{"index-5203-17.fits.zst", "748862d448c996eda58ede16ea37b5a3"},
|
||||
{"index-5203-18.fits.zst", "d145bd1cba6ccc3948fca16fd04e7efe"},
|
||||
{"index-5203-19.fits.zst", "6a031fee285d47357c3cd98148c416c7"},
|
||||
{"index-5203-20.fits.zst", "d08f64480576cbcb3ce1f5625e82bc87"},
|
||||
{"index-5203-21.fits.zst", "5dcec75f91802cb05c36b185ea5b26de"},
|
||||
{"index-5203-22.fits.zst", "c76d7ad199114e77f4e05a290eff1de8"},
|
||||
{"index-5203-23.fits.zst", "3d8909cb4322a7b7baa3cd2e464269c8"},
|
||||
{"index-5203-24.fits.zst", "dd5a0ce7d08940fba606546140ccd38d"},
|
||||
{"index-5203-25.fits.zst", "bd27d2e07a96d7eceb26bbfff4eaf4f4"},
|
||||
{"index-5203-26.fits.zst", "8d82ba9557c9b4fea8ee1a16d1cc4bb9"},
|
||||
{"index-5203-27.fits.zst", "9f7e923674521562dd54903d8102bd0c"},
|
||||
{"index-5203-28.fits.zst", "3064ae36821a24d67b8c53000a6b67bc"},
|
||||
{"index-5203-29.fits.zst", "4eb82a64d7c9d8f7314cfda94e160e43"},
|
||||
{"index-5203-30.fits.zst", "e8cf8a17c62cf0ef09b61065d1bba527"},
|
||||
{"index-5203-31.fits.zst", "488fec71fc896c780aa970228d65f749"},
|
||||
{"index-5203-32.fits.zst", "8d09558d167283cf5bff4feca9202421"},
|
||||
{"index-5203-33.fits.zst", "c1f61ffaaee068d0a1d1829b71f46a30"},
|
||||
{"index-5203-34.fits.zst", "e2567ca06041ee6995f2cb9e282fe12b"},
|
||||
{"index-5203-35.fits.zst", "1c61653eb8851385a70adb15bbb8c836"},
|
||||
{"index-5203-36.fits.zst", "4d5360eea4e466121f3ffc0ad2574152"},
|
||||
{"index-5203-37.fits.zst", "95b713845864aa8418af634f16a0cb84"},
|
||||
{"index-5203-38.fits.zst", "7ccf07966a95072e621672dfc588d127"},
|
||||
{"index-5203-39.fits.zst", "0bf97501842e571c84a90d30c4b62c45"},
|
||||
{"index-5203-40.fits.zst", "f0ec8a7f888c225c749dd0ca6bb946be"},
|
||||
{"index-5203-41.fits.zst", "bd6fca77c9c0aae43de799b7ad823ab5"},
|
||||
{"index-5203-42.fits.zst", "71ffbc8755c943c67f8b67deda4a9d44"},
|
||||
{"index-5203-43.fits.zst", "4a48b878fd510a9bde3101acd7210cdb"},
|
||||
{"index-5203-44.fits.zst", "1ed3d2e05dd619d145d0aac46dd69320"},
|
||||
{"index-5203-45.fits.zst", "70e4d9fb4b5d66fc24990310cfc913d4"},
|
||||
{"index-5203-46.fits.zst", "ecd1d7b1cb94ba52031314d189bd2390"},
|
||||
{"index-5203-47.fits.zst", "894ae74eb43a8f34ad06edea62bd4337"},
|
||||
{"index-5204-00.fits.zst", "6bdb9974308249e68f1ed707d6951848"},
|
||||
{"index-5204-01.fits.zst", "c10ce6a6d2375bcf3e3babced3722ecd"},
|
||||
{"index-5204-02.fits.zst", "9e7ed423196691e4c9f38449957860bd"},
|
||||
{"index-5204-03.fits.zst", "60ccf82d3d7443423c84c789ad5d5604"},
|
||||
{"index-5204-04.fits.zst", "e8ba7567c5bda04c4fb58bb93454b8ed"},
|
||||
{"index-5204-05.fits.zst", "1f36a1432c055fc96582642ea5c853b2"},
|
||||
{"index-5204-06.fits.zst", "bb8a67b877eeccdfef5668796a677f4f"},
|
||||
{"index-5204-07.fits.zst", "2c547a8abd2410530a7547db80c40eaa"},
|
||||
{"index-5204-08.fits.zst", "5be1251fcc27f3f95c38a87ba6e0335d"},
|
||||
{"index-5204-09.fits.zst", "291cbc557df140dc3caccad105f9d515"},
|
||||
{"index-5204-10.fits.zst", "b155a2c52e3b5a3d99d0fa5b112cd1e4"},
|
||||
{"index-5204-11.fits.zst", "0a21c7bff80b6225f00e9c2213282003"},
|
||||
{"index-5204-12.fits.zst", "2ca005ea103d668ebdd2f07d215dc824"},
|
||||
{"index-5204-13.fits.zst", "6a3677a3e55af336dbbaa7db29492c1d"},
|
||||
{"index-5204-14.fits.zst", "00c4922987950b875ddb6d68cf22dbf2"},
|
||||
{"index-5204-15.fits.zst", "4faec4fdaae6ab10d91e42f77a8786b2"},
|
||||
{"index-5204-16.fits.zst", "211cb590033d680cabfa3559243bbe0f"},
|
||||
{"index-5204-17.fits.zst", "f8c27d1b6448ca442b5ec13d09d161ca"},
|
||||
{"index-5204-18.fits.zst", "6a264515e128f61b89a5ec94d649aa05"},
|
||||
{"index-5204-19.fits.zst", "d24b3fd902dbea191953d173bf85627a"},
|
||||
{"index-5204-20.fits.zst", "a240cf519935d77ebda8a1ba89629b19"},
|
||||
{"index-5204-21.fits.zst", "8633a5f455a70b089916bb952649abc5"},
|
||||
{"index-5204-22.fits.zst", "a64cc9fc8dc5d38d530d161dde40adb0"},
|
||||
{"index-5204-23.fits.zst", "639bf9f5433a272b9208094435dfacf0"},
|
||||
{"index-5204-24.fits.zst", "20eece3a49f82fe2ae575bce9bc57dc9"},
|
||||
{"index-5204-25.fits.zst", "6895bc172752aa20a9975e9123d6867b"},
|
||||
{"index-5204-26.fits.zst", "9cb92cd20d8060dcf8c694b670800a19"},
|
||||
{"index-5204-27.fits.zst", "09894bc3185f68b49cf2eb0cc7eacebe"},
|
||||
{"index-5204-28.fits.zst", "bb5a2a09b531d2ca13f341cb0b00041b"},
|
||||
{"index-5204-29.fits.zst", "f2d5f146ff97b86dfb4b59c8636c69d8"},
|
||||
{"index-5204-30.fits.zst", "cb8bec9885e23cce0d86a94a886858ff"},
|
||||
{"index-5204-31.fits.zst", "ff92d11ee8aebd9e4cd7c63006e2ba0f"},
|
||||
{"index-5204-32.fits.zst", "5bc007791035420ab06a8a8dee13f50b"},
|
||||
{"index-5204-33.fits.zst", "98305f6ec87af98d0a7fb82f6cb38397"},
|
||||
{"index-5204-34.fits.zst", "5af466f48514b9bec75e877e3aa348e7"},
|
||||
{"index-5204-35.fits.zst", "f84d32ef9278e2fa0aa013334ebddedc"},
|
||||
{"index-5204-36.fits.zst", "5e7afe529e949d83812c15ca66e5fbe4"},
|
||||
{"index-5204-37.fits.zst", "091d775d07623d86adf0c6f0d61da00f"},
|
||||
{"index-5204-38.fits.zst", "61c3b59cd6614357da8427887fa1d7be"},
|
||||
{"index-5204-39.fits.zst", "ad5687f7e7e6d65c25f52696a5be73fb"},
|
||||
{"index-5204-40.fits.zst", "d95ca1f3d0abe527518ad3c4797e3b69"},
|
||||
{"index-5204-41.fits.zst", "4d49cd25ea1cf1c348916b39f026a6e1"},
|
||||
{"index-5204-42.fits.zst", "7f517937c94d9db3d7515cadb5cd3b10"},
|
||||
{"index-5204-43.fits.zst", "f3d336795a32af76d61742c9a29bfb14"},
|
||||
{"index-5204-44.fits.zst", "3372d5b85a802f891acdadfc65e05893"},
|
||||
{"index-5204-45.fits.zst", "7e6c52552bf25c63af732ec7243d8766"},
|
||||
{"index-5204-46.fits.zst", "5ce56079d24213af35d9ec730e12121f"},
|
||||
{"index-5204-47.fits.zst", "d33d355ad900766c8fcdd53522124d01"},
|
||||
{"index-5205-00.fits.zst", "d95511d75f6915caed5a4cf010e51056"},
|
||||
{"index-5205-01.fits.zst", "53857e19e4ff54360ed9335c35d20ac8"},
|
||||
{"index-5205-02.fits.zst", "f8bdcd851d44da92a4a90bc71deb0782"},
|
||||
{"index-5205-03.fits.zst", "4782fc867bd02c58140daecc7a4f9cab"},
|
||||
{"index-5205-04.fits.zst", "b63b9bfdda4a85e9377b512038aa9627"},
|
||||
{"index-5205-05.fits.zst", "ffb688a56d6dc70842765a7e1fdc9ca7"},
|
||||
{"index-5205-06.fits.zst", "8d906365279b2f41baa7fedd76683619"},
|
||||
{"index-5205-07.fits.zst", "82ec7cc676c9ef825f218fceb236d216"},
|
||||
{"index-5205-08.fits.zst", "29171a06fd40f5c5df6e637550bc7626"},
|
||||
{"index-5205-09.fits.zst", "dca0e789c482eef07bee53100e10f73a"},
|
||||
{"index-5205-10.fits.zst", "7d66c8c27198481c587c1432275feced"},
|
||||
{"index-5205-11.fits.zst", "ce66e30646b02e7128a004cda4240b6d"},
|
||||
{"index-5205-12.fits.zst", "6a42dcd534efb467a0a53c69a6047866"},
|
||||
{"index-5205-13.fits.zst", "950331af7d668da1006c1b6902fd6439"},
|
||||
{"index-5205-14.fits.zst", "ac6c30027cd93e91b5baf6e344032254"},
|
||||
{"index-5205-15.fits.zst", "3c8d77076a49d3dc051089df8025308b"},
|
||||
{"index-5205-16.fits.zst", "5c7a0c57f7bf6fcc886c7518adc2b882"},
|
||||
{"index-5205-17.fits.zst", "6daa68b68104426b3e92a433107e565e"},
|
||||
{"index-5205-18.fits.zst", "74b94ab3f7ee6a260560b5d78614df30"},
|
||||
{"index-5205-19.fits.zst", "01597167da7a9e6fde3ace7d6e9c6788"},
|
||||
{"index-5205-20.fits.zst", "3dffc55b7ab5c15e1c689c0d73f880f6"},
|
||||
{"index-5205-21.fits.zst", "bfa484d631819e2a2b7a8d3dec337a9b"},
|
||||
{"index-5205-22.fits.zst", "de2a3ebbf56bb640411e0a50ed0653eb"},
|
||||
{"index-5205-23.fits.zst", "5498579da779e625617140b04a88659c"},
|
||||
{"index-5205-24.fits.zst", "41589963565a4d1d056ac2551c94bc5b"},
|
||||
{"index-5205-25.fits.zst", "88dac5e97a8e3cccd4962ee9d1f062fb"},
|
||||
{"index-5205-26.fits.zst", "528044ec968e08a1347f97d2d58bc9f8"},
|
||||
{"index-5205-27.fits.zst", "50890dbe9394c9101138f781394a62da"},
|
||||
{"index-5205-28.fits.zst", "da541fb011826588a7ff682d3fc1065f"},
|
||||
{"index-5205-29.fits.zst", "96873ae405bd9ac727656d4fbf3c508c"},
|
||||
{"index-5205-30.fits.zst", "e320dad418e7e64bbd4700e074af97b6"},
|
||||
{"index-5205-31.fits.zst", "5cb52c69ad1a9b780dddd82da4295f01"},
|
||||
{"index-5205-32.fits.zst", "af2f00cbfc50a82138f01ee26b9e9d91"},
|
||||
{"index-5205-33.fits.zst", "0e3abcccf8295f99b846e69e0a82ee55"},
|
||||
{"index-5205-34.fits.zst", "02220a844210cbab3dbf32f15f25d6ff"},
|
||||
{"index-5205-35.fits.zst", "21380e2a86b908f5cef98cd5b2ba5fc5"},
|
||||
{"index-5205-36.fits.zst", "5898e4e3b3f4961420124fe23c106e7e"},
|
||||
{"index-5205-37.fits.zst", "12a7eebcfcb9871366f27bab7bd7c02b"},
|
||||
{"index-5205-38.fits.zst", "ad7ae57547afae6d7e7b5bfde0f2dd4e"},
|
||||
{"index-5205-39.fits.zst", "ce92be215ddb055395db6ff1469a13c5"},
|
||||
{"index-5205-40.fits.zst", "21f0f02bf765bea7577e9c379cc32aaf"},
|
||||
{"index-5205-41.fits.zst", "d7bb45a9cc162262cf860554cb577cb3"},
|
||||
{"index-5205-42.fits.zst", "923d46b2900879a7deb9c07a71a5a604"},
|
||||
{"index-5205-43.fits.zst", "12036538e03f7e87e7e5197a176bfbeb"},
|
||||
{"index-5205-44.fits.zst", "763625ff1a99a09010b4d29ee26c45f5"},
|
||||
{"index-5205-45.fits.zst", "515b596b4ccb4684d84ac5bae00c3ec7"},
|
||||
{"index-5205-46.fits.zst", "69c36255820c21846ce066ef9727ad9c"},
|
||||
{"index-5205-47.fits.zst", "7208bf7057c156f68f8797055279c396"},
|
||||
{"index-5206-00.fits.zst", "ec763f6717dc23aa74f0c37d37bbc79d"},
|
||||
{"index-5206-01.fits.zst", "77c60eb07dca413177f265fd3a7358d1"},
|
||||
{"index-5206-02.fits.zst", "7b04e7e1bdd5d10a7ecd8784458dfe3a"},
|
||||
{"index-5206-03.fits.zst", "ff096041f96c1a928583277d53b70754"},
|
||||
{"index-5206-04.fits.zst", "edfab290c5d79b16142e8e29b930276e"},
|
||||
{"index-5206-05.fits.zst", "01842535f9cd6cabebdbc99eba0c2469"},
|
||||
{"index-5206-06.fits.zst", "8c191abe714e0e2c709bf1b3f1e46534"},
|
||||
{"index-5206-07.fits.zst", "221bc2471617105004d213b44238fa41"},
|
||||
{"index-5206-08.fits.zst", "c04330df6a106b55618cc0d0467c349d"},
|
||||
{"index-5206-09.fits.zst", "ac6d28cad4716da936f5f9878ecab761"},
|
||||
{"index-5206-10.fits.zst", "bd79f130d1931d167a2a9cf801b05cfd"},
|
||||
{"index-5206-11.fits.zst", "2e50c634e80b32ca13d643e0535a37c1"},
|
||||
{"index-5206-12.fits.zst", "c132774b1cb656056d04e8175948559f"},
|
||||
{"index-5206-13.fits.zst", "bc491d7a0a773f9e499b9f18f4cc2d26"},
|
||||
{"index-5206-14.fits.zst", "9209a393a7341d08982925936d587178"},
|
||||
{"index-5206-15.fits.zst", "416f3f4c655fdc56504030442d52f21b"},
|
||||
{"index-5206-16.fits.zst", "9e6f16e687376c17c15d3f2bb7621b8f"},
|
||||
{"index-5206-17.fits.zst", "4f131eff7aa8eee019dd081a250f15bd"},
|
||||
{"index-5206-18.fits.zst", "7535d000a0d9ef54c1e50202319f2a4d"},
|
||||
{"index-5206-19.fits.zst", "2a20fb3cf2f2bd39c9d8f0efa376e5ea"},
|
||||
{"index-5206-20.fits.zst", "0e08f721f97341a0f737b4d9ffc1bafc"},
|
||||
{"index-5206-21.fits.zst", "aa2b2719031262219b9e105853655d84"},
|
||||
{"index-5206-22.fits.zst", "c4966b370e8e0abe7c0827712419b63f"},
|
||||
{"index-5206-23.fits.zst", "baff2c6b458965754a33c2b8e4ddae30"},
|
||||
{"index-5206-24.fits.zst", "f9c37d9dadf7b5c10e417909b89dd0f6"},
|
||||
{"index-5206-25.fits.zst", "c420b02c3f701459762ffd24d3ee0b7f"},
|
||||
{"index-5206-26.fits.zst", "f8c296fe490a6449233787f7b2275f7d"},
|
||||
{"index-5206-27.fits.zst", "b63de1ef274c7b3482ec49b038c95e4a"},
|
||||
{"index-5206-28.fits.zst", "0e91227a868e4d626d05f8556fd385db"},
|
||||
{"index-5206-29.fits.zst", "010af2760055eb0b0f139f26808d3d0a"},
|
||||
{"index-5206-30.fits.zst", "bb75c13afb642f8d1039627885591adf"},
|
||||
{"index-5206-31.fits.zst", "9cbec1344ba47dd477d6d8a1f680527e"},
|
||||
{"index-5206-32.fits.zst", "74e832eb93be5e6d58793418253c1b1c"},
|
||||
{"index-5206-33.fits.zst", "303d2fecce3f69914d2aec9b137cd65b"},
|
||||
{"index-5206-34.fits.zst", "b2fa4d6404f11552dd0ae3212a893813"},
|
||||
{"index-5206-35.fits.zst", "18533d28093a1b01ba0a17811237c9c2"},
|
||||
{"index-5206-36.fits.zst", "7f8a6ce0c1e0fe7998a047172bee9390"},
|
||||
{"index-5206-37.fits.zst", "eef8a7d8de31e0865de6a2563cd54602"},
|
||||
{"index-5206-38.fits.zst", "27d0395d69aa600d2c334664ee88191d"},
|
||||
{"index-5206-39.fits.zst", "455e2ee060c16a560e62df0bf6790027"},
|
||||
{"index-5206-40.fits.zst", "9d7f12a0adfb97d7d3b904bf6f8788c4"},
|
||||
{"index-5206-41.fits.zst", "d05556c1d3c15f0cdb72363a82ab6d7c"},
|
||||
{"index-5206-42.fits.zst", "99268fca7e2a9161f4f1c144b13dea3a"},
|
||||
{"index-5206-43.fits.zst", "e3b6becbf0949d9c40dac1d366805493"},
|
||||
{"index-5206-44.fits.zst", "eb6802ea492c8ab920699a47cd8e5ccf"},
|
||||
{"index-5206-45.fits.zst", "d3f692ee8ee9d6c9d3483818f2b81584"},
|
||||
{"index-5206-46.fits.zst", "aff3a7ba7140e5e850c1395fba6402c0"},
|
||||
{"index-5206-47.fits.zst", "27b479b738a7cd3379e105638b1fc43e"}
|
||||
};
|
||||
|
||||
Download::Download(QNetworkReply *reply, const QString indexPath, QObject *parent) : QObject(parent)
|
||||
,_reply(reply)
|
||||
,_hash(QCryptographicHash::Md5)
|
||||
{
|
||||
connect(_reply, &QNetworkReply::finished, this, &Download::finished);
|
||||
connect(_reply, &QNetworkReply::readyRead, this, &Download::readData);
|
||||
connect(_reply, &QNetworkReply::downloadProgress, this, &Download::progress);
|
||||
|
||||
QString filename = _reply->url().fileName();
|
||||
filename.remove(QRegularExpression("\\.zst$"));
|
||||
|
||||
_fw.setFileName(indexPath + "/" + filename);
|
||||
_fw.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
if(_fw.isOpen())
|
||||
{
|
||||
qDebug() << "open file" << _fw.fileName();
|
||||
}
|
||||
|
||||
_dstream = ZSTD_createDStream();
|
||||
}
|
||||
|
||||
Download::~Download()
|
||||
{
|
||||
ZSTD_freeDStream(_dstream);
|
||||
}
|
||||
|
||||
void Download::abort()
|
||||
{
|
||||
_reply->abort();
|
||||
}
|
||||
|
||||
void Download::readData()
|
||||
{
|
||||
QByteArray data = _reply->readAll();
|
||||
decompress(data);
|
||||
}
|
||||
|
||||
void Download::finished()
|
||||
{
|
||||
if(_reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
QByteArray data = _reply->readAll();
|
||||
qDebug() << "finished" << data.size();
|
||||
decompress(data);
|
||||
|
||||
if(md5.contains(_reply->url().fileName()))
|
||||
{
|
||||
if(_hash.result().toHex() == md5[_reply->url().fileName()])
|
||||
qDebug() << "DOWNLOAD OK";
|
||||
else
|
||||
{
|
||||
qDebug() << "DOWNLOAD BAD";
|
||||
_fw.remove();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_fw.flush();
|
||||
_fw.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed to perform http request" << _reply->url();
|
||||
_fw.remove();
|
||||
}
|
||||
}
|
||||
|
||||
void Download::decompress(QByteArray &data)
|
||||
{
|
||||
if(data.isEmpty())return;
|
||||
|
||||
_hash.addData(data);
|
||||
|
||||
ZSTD_inBuffer inBuffer = {data.constData(), static_cast<size_t>(data.size()), 0};
|
||||
QByteArray outData(ZSTD_DStreamOutSize(), '\0');
|
||||
while(inBuffer.pos < inBuffer.size)
|
||||
{
|
||||
ZSTD_outBuffer outBuffer = {outData.data(), static_cast<size_t>(outData.size()), 0};
|
||||
size_t ret = ZSTD_decompressStream(_dstream, &outBuffer, &inBuffer);
|
||||
if(ZSTD_isError(ret))
|
||||
{
|
||||
qDebug() << "decompress error" << ZSTD_getErrorName(ret);
|
||||
_fw.remove();
|
||||
_reply->abort();
|
||||
break;
|
||||
}
|
||||
else if(outBuffer.pos)
|
||||
{
|
||||
_fw.write(static_cast<char*>(outBuffer.dst), outBuffer.pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HttpDownloader::HttpDownloader(QObject *parent) : QObject(parent)
|
||||
,_manager(new QNetworkAccessManager(this))
|
||||
{
|
||||
_manager->setAutoDeleteReplies(true);
|
||||
connect(_manager, &QNetworkAccessManager::finished, this, &HttpDownloader::finished);
|
||||
#ifdef PLATESOLVER
|
||||
QDir dir(Solver::getTenmonIndexPath());
|
||||
if(!dir.exists())
|
||||
{
|
||||
if(dir.mkpath("."))
|
||||
qDebug() << "Failed to create astrometry directory";
|
||||
}
|
||||
|
||||
_indexPath = dir.absolutePath();
|
||||
#endif
|
||||
}
|
||||
|
||||
void HttpDownloader::download(const QUrl &url)
|
||||
{
|
||||
if(!_queue.contains(url))
|
||||
_queue.enqueue(url);
|
||||
|
||||
if(!_download)
|
||||
finished();
|
||||
}
|
||||
|
||||
bool HttpDownloader::downloadIndex(int scale)
|
||||
{
|
||||
if(scale > 19 || scale < 1)
|
||||
return false;
|
||||
|
||||
QUrl url("https://tenmon.nouspiro.space/");
|
||||
QStringList files = indexFileNames(scale);
|
||||
|
||||
for(auto &file : files)
|
||||
{
|
||||
if(QFile::exists(_indexPath + "/" + file))
|
||||
{
|
||||
qDebug() << "File already exists, skipping" << file;
|
||||
}
|
||||
else
|
||||
{
|
||||
url.setPath("/astrometry/" + file + ".zst");
|
||||
download(url);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HttpDownloader::abort()
|
||||
{
|
||||
if(_download)
|
||||
_download->abort();
|
||||
}
|
||||
|
||||
QStringList HttpDownloader::indexFileNames(int scale)
|
||||
{
|
||||
QStringList ret;
|
||||
|
||||
if(scale >= 7)
|
||||
{
|
||||
ret.append(QString("index-%1.fits").arg(4100 + scale));
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i=0; i<48; i++)
|
||||
ret.append(QString("index-%1-%2.fits").arg(5200 + scale).arg(i, 2, 10, QChar('0')));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void HttpDownloader::finished()
|
||||
{
|
||||
if(_queue.isEmpty())
|
||||
{
|
||||
_download = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
QUrl url = _queue.dequeue();
|
||||
QString filename = url.fileName();
|
||||
filename.remove(QRegularExpression("\\.zst$"));
|
||||
QFileInfo info(_indexPath + "/" + filename);
|
||||
if(info.exists())
|
||||
{
|
||||
finished();
|
||||
return;
|
||||
}
|
||||
QNetworkRequest request(url);
|
||||
_download = new Download(_manager->get(request), _indexPath, this);
|
||||
connect(_download, &Download::progress, this, &HttpDownloader::updateProgress);
|
||||
}
|
||||
}
|
||||
|
||||
void HttpDownloader::updateProgress(qint64 received, qint64 total)
|
||||
{
|
||||
emit progress((float)received / total * 100.0f, _queue.size());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef HTTPDOWNLOADER_H
|
||||
#define HTTPDOWNLOADER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QFile>
|
||||
#include <QQueue>
|
||||
#include <QCryptographicHash>
|
||||
#include <zstd.h>
|
||||
|
||||
class Download : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QNetworkReply *_reply;
|
||||
ZSTD_DStream *_dstream;
|
||||
QFile _fw;
|
||||
QCryptographicHash _hash;
|
||||
public:
|
||||
Download(QNetworkReply *reply, const QString indexPath, QObject *parent);
|
||||
~Download();
|
||||
void abort();
|
||||
public slots:
|
||||
void readData();
|
||||
void finished();
|
||||
signals:
|
||||
void progress(qint64 received, qint64 total);
|
||||
protected:
|
||||
void decompress(QByteArray &data);
|
||||
};
|
||||
|
||||
class HttpDownloader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QNetworkAccessManager *_manager;
|
||||
Download *_download = nullptr;
|
||||
QQueue<QUrl> _queue;
|
||||
QString _indexPath;
|
||||
public:
|
||||
explicit HttpDownloader(QObject *parent = nullptr);
|
||||
void download(const QUrl &url);
|
||||
// scale in range 19-1
|
||||
bool downloadIndex(int scale);
|
||||
void abort();
|
||||
static QStringList indexFileNames(int scale);
|
||||
signals:
|
||||
void progress(int percent, int files);
|
||||
protected slots:
|
||||
void finished();
|
||||
void updateProgress(qint64 received, qint64 total);
|
||||
};
|
||||
|
||||
#endif // HTTPDOWNLOADER_H
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "imageinfo.h"
|
||||
#include <QSettings>
|
||||
#include <QHeaderView>
|
||||
|
||||
QMap<QString, QColor> headerHighlight;
|
||||
|
||||
ImageInfo::ImageInfo(QWidget *parent) : QTreeWidget(parent)
|
||||
{
|
||||
setColumnCount(3);
|
||||
setHeaderLabels({tr("Property"), tr("Value"), tr("Comment")});
|
||||
setIndentation(5);
|
||||
QSettings settings;
|
||||
header()->restoreState(settings.value("imageinfo/headerstate").toByteArray());
|
||||
}
|
||||
|
||||
ImageInfo::~ImageInfo()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("imageinfo/headerstate", header()->saveState());
|
||||
}
|
||||
|
||||
void ImageInfo::setInfo(const ImageInfoData &info)
|
||||
{
|
||||
clear();
|
||||
if(info.fitsHeader.size())
|
||||
{
|
||||
QTreeWidgetItem *fitsHeader = new QTreeWidgetItem({tr("FITS Header")});
|
||||
for(const FITSRecord &record : info.fitsHeader)
|
||||
{
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem(fitsHeader, {record.key, record.value.toString().left(1024), record.comment});
|
||||
if(headerHighlight.contains(record.key))
|
||||
{
|
||||
QColor color = headerHighlight[record.key];
|
||||
item->setBackground(0, color);
|
||||
item->setBackground(1, color);
|
||||
item->setBackground(2, color);
|
||||
}
|
||||
}
|
||||
addTopLevelItem(fitsHeader);
|
||||
}
|
||||
if(info.info.size())
|
||||
{
|
||||
QTreeWidgetItem *infoHeader = new QTreeWidgetItem({tr("Image info")});
|
||||
for(auto &item : info.info)
|
||||
{
|
||||
new QTreeWidgetItem(infoHeader, {item.first, item.second});
|
||||
}
|
||||
addTopLevelItem(infoHeader);
|
||||
}
|
||||
expandAll();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef IMAGEINFO_H
|
||||
#define IMAGEINFO_H
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class ImageInfo : public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImageInfo(QWidget *parent);
|
||||
~ImageInfo() override;
|
||||
public slots:
|
||||
void setInfo(const ImageInfoData &info);
|
||||
};
|
||||
|
||||
#endif // IMAGEINFO_H
|
||||
@@ -0,0 +1,572 @@
|
||||
#include "imageinfodata.h"
|
||||
#include <QTime>
|
||||
#include <QRectF>
|
||||
#include <QRegularExpression>
|
||||
#include <wcslib/wcshdr.h>
|
||||
#include <wcslib/wcsfix.h>
|
||||
#include "database.h"
|
||||
#include "libxisf.h"
|
||||
|
||||
static const QVector<QByteArray> noEditableKey = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"};
|
||||
|
||||
bool FITSRecord::editable() const
|
||||
{
|
||||
return noEditableKey.count(key);
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment) :
|
||||
key(key), value(value), comment(comment)
|
||||
{
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const LibXISF::FITSKeyword &record)
|
||||
{
|
||||
key = record.name.c_str();
|
||||
comment = record.comment.c_str();
|
||||
|
||||
QString string = record.value.c_str();
|
||||
if(string.startsWith('\'') && string.endsWith('\''))
|
||||
{
|
||||
string.chop(1);
|
||||
string.remove(0, 1);
|
||||
}
|
||||
bool isint;
|
||||
bool isdouble;
|
||||
double vald = string.toDouble(&isdouble);
|
||||
long long vall = string.toLongLong(&isint);
|
||||
if(isint)
|
||||
value = vall;
|
||||
else if(isdouble)
|
||||
value = vald;
|
||||
else if(string == "T" || string == "F")
|
||||
value = string == "T";
|
||||
else
|
||||
value = string;
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const LibXISF::Property &property)
|
||||
{
|
||||
key = property.id.c_str();
|
||||
value = QString::fromStdString(property.value.toString());
|
||||
comment = property.comment.c_str();
|
||||
xisf = true;
|
||||
}
|
||||
|
||||
void WCSDataT::freeWCS()
|
||||
{
|
||||
wcsvfree(&nwcs, &wcs);
|
||||
nwcs = 0;
|
||||
wcs = nullptr;
|
||||
}
|
||||
|
||||
WCSDataT::WCSDataT(int width, int height, char *header, int nrec) :
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
int nreject = 0;
|
||||
int status = wcspih(header, nrec, 1, 0, &nreject, &nwcs, &wcs);
|
||||
if(status != 0)
|
||||
{
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
WCSDataT::WCSDataT(int width, int height, const QVector<FITSRecord> &header) :
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
QByteArray str;
|
||||
int nrec = 1;
|
||||
for(const FITSRecord &record : header)
|
||||
{
|
||||
if(record.key.startsWith("PV"))continue;
|
||||
|
||||
QByteArray rec;
|
||||
rec.append(record.key.leftJustified(8, ' '));
|
||||
rec.append("= ");
|
||||
rec.append(record.value.toString().toLatin1());
|
||||
rec.append(" / ");
|
||||
rec.append(record.comment);
|
||||
str.append(rec.leftJustified(80, ' ', true));
|
||||
nrec++;
|
||||
}
|
||||
str.append(QByteArray("END").leftJustified(80));
|
||||
|
||||
int nreject = 0;
|
||||
status = wcspih(str.data(), nrec, 1, 0, &nreject, &nwcs, &wcs);
|
||||
if(status != 0)
|
||||
{
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
WCSDataT::~WCSDataT()
|
||||
{
|
||||
if(wcs)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
bool WCSDataT::pixelToWorld(const QPointF &pixel, SkyPoint &point) const
|
||||
{
|
||||
if(!valid())return false;
|
||||
|
||||
double pixcrd[2] = {pixel.x(), pixel.y()};
|
||||
double imgcrd[8] = {0};
|
||||
double phi = 0;
|
||||
double theta = 0;
|
||||
double world[8] = {0};
|
||||
int stat[NWCSFIX] = {0};
|
||||
int status = wcsp2s(wcs, 1, 2, pixcrd, imgcrd, &phi, &theta, world, stat);
|
||||
if(status == 0)
|
||||
{
|
||||
point = SkyPoint(world[0], world[1]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WCSDataT::worldToPixel(const SkyPoint &point, QPointF &pixel) const
|
||||
{
|
||||
if(!valid())return false;
|
||||
|
||||
double world[2] = {point.RA(), point.DEC()};
|
||||
double phi = 0;
|
||||
double theta = 0;
|
||||
double imgcrd[8] = {0};
|
||||
double pixcrd[8] = {0};
|
||||
int stat[NWCSFIX] = {0};
|
||||
int status = wcss2p(wcs, 1, 2, world, &phi, &theta, imgcrd, pixcrd, stat);
|
||||
if(status == 0)
|
||||
{
|
||||
pixel = QPointF(pixcrd[0], pixcrd[1]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WCSDataT::calculateBounds(double &minRa, double &maxRa, double &minDec, double &maxDec, double &crVal1, double &crVal2) const
|
||||
{
|
||||
if(wcs == nullptr)return false;
|
||||
|
||||
minRa = 1000;
|
||||
maxRa = -1000;
|
||||
minDec = 1000;
|
||||
maxDec = -1000;
|
||||
|
||||
if(wcs->crval)
|
||||
{
|
||||
crVal1 = wcs->crval[0];
|
||||
crVal2 = wcs->crval[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
crVal1 = crVal2 = NAN;
|
||||
}
|
||||
|
||||
auto update = [&](const QPointF &pixel)
|
||||
{
|
||||
SkyPoint point;
|
||||
pixelToWorld(pixel, point);
|
||||
minRa = std::min(minRa, point.RA());
|
||||
maxRa = std::max(maxRa, point.RA());
|
||||
minDec = std::min(minDec, point.DEC());
|
||||
maxDec = std::max(maxDec, point.DEC());
|
||||
};
|
||||
|
||||
for(int x=0; x<width; x++)
|
||||
{
|
||||
update(QPointF(x, 0));
|
||||
update(QPointF(x, height - 1));
|
||||
}
|
||||
|
||||
for(int y=0; y<height; y++)
|
||||
{
|
||||
update(QPointF(0, y));
|
||||
update(QPointF(width - 1, y));
|
||||
}
|
||||
|
||||
QPointF ncp;
|
||||
QPointF scp;
|
||||
QRectF s(0, 0, width - 1, height - 1);
|
||||
if(worldToPixel(SkyPoint(0, 90), ncp))
|
||||
{
|
||||
if(s.contains(ncp))
|
||||
maxDec = 90;
|
||||
}
|
||||
|
||||
if(worldToPixel(SkyPoint(0, -90), scp))
|
||||
{
|
||||
if(s.contains(scp))
|
||||
minDec = -90;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
double hav(double x)
|
||||
{
|
||||
return (1.0 - std::cos(x)) * 0.5;
|
||||
}
|
||||
|
||||
double haverSine(const SkyPoint &a, SkyPoint &b)
|
||||
{
|
||||
const double ToRAD = M_PI / 180.0;
|
||||
double d = hav((a.DEC() - b.DEC()) * ToRAD) + std::cos(a.DEC() * ToRAD) * std::cos(b.DEC() * ToRAD) * hav((a.RA() - b.RA()) * ToRAD);
|
||||
return std::acos(1.0 - 2.0 * d) * (180.0 / M_PI);
|
||||
}
|
||||
|
||||
SkyPointScale WCSDataT::getRaDecScale() const
|
||||
{
|
||||
SkyPointScale ret;
|
||||
pixelToWorld(QPointF(width/2.0, height/2.0), ret.point);
|
||||
SkyPoint pointX;
|
||||
SkyPoint pointY;
|
||||
pixelToWorld(QPointF(width/2.0+1, height/2.0), pointX);
|
||||
pixelToWorld(QPointF(width/2.0, height/2.0+1), pointY);
|
||||
double scaleX = haverSine(ret.point, pointX) * 3600.0;
|
||||
double scaleY = haverSine(ret.point, pointY) * 3600.0;
|
||||
ret.scaleLow = std::min(scaleX, scaleY);
|
||||
ret.scaleHigh = std::max(scaleX, scaleY);
|
||||
ret.scaleValid = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint() : ra(NAN), dec(NAN)
|
||||
{
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint(double ra, double dec) : ra(ra), dec(dec)
|
||||
{
|
||||
}
|
||||
|
||||
void SkyPoint::set(double ra, double dec)
|
||||
{
|
||||
this->ra = ra;
|
||||
this->dec = dec;
|
||||
}
|
||||
|
||||
QString SkyPoint::toString() const
|
||||
{
|
||||
if(std::isnan(ra) || std::isnan(dec))
|
||||
return QString();
|
||||
|
||||
QTime t(0, 0);
|
||||
t = t.addSecs(ra * 240);
|
||||
|
||||
double deg, min, sec;
|
||||
min = std::abs(std::modf(dec, °) * 60);
|
||||
sec = std::modf(min, &min) * 60;
|
||||
return QString("RA: %1 DEC: %2° %3' %4\"").arg(t.toString("HH'h' mm'm' ss's'")).arg(deg, 2, 'f', 0, '0').arg(min, 2, 'f', 0, '0').arg(sec, 2, 'f', 0, '0');
|
||||
}
|
||||
|
||||
QString SkyPoint::RAString() const
|
||||
{
|
||||
return toHMS(ra / 15);
|
||||
}
|
||||
|
||||
QString SkyPoint::DECString() const
|
||||
{
|
||||
return toDMS(dec);
|
||||
}
|
||||
|
||||
double SkyPoint::fromHMS(const QString &hms)
|
||||
{
|
||||
double deg = fromDMS(hms);
|
||||
if(std::isnan(deg))return deg;
|
||||
return deg * 15.0;
|
||||
}
|
||||
|
||||
double SkyPoint::fromDMS(const QString &dms)
|
||||
{
|
||||
double deg = 0.0;
|
||||
QString str = dms.trimmed();
|
||||
str.remove(QRegularExpression("[hdms°'\"]"));
|
||||
str.replace(':', ' ');
|
||||
str.replace(QRegularExpression("\\s+"), " ");
|
||||
QStringList fields = str.split(' ');
|
||||
double sign = 1.0;
|
||||
|
||||
bool ok = false;
|
||||
if(fields.size() >= 1)
|
||||
deg = fields.at(0).toDouble(&ok);
|
||||
if(!ok)return NAN;
|
||||
if(deg < 0.0)
|
||||
sign = -1.0;
|
||||
if(fields.size() >= 2)
|
||||
deg += sign * fields.at(1).toDouble() / 60.0;
|
||||
if(fields.size() >= 3)
|
||||
deg += sign * fields.at(2).toDouble() / 3600.0;
|
||||
|
||||
return deg;
|
||||
}
|
||||
|
||||
QString SkyPoint::toHMS(double decHour)
|
||||
{
|
||||
double h,m,s,md;
|
||||
md = std::modf(decHour, &h) * 60.0;
|
||||
s = std::modf(md, &m) * 60.0;
|
||||
|
||||
return QString("%1h %2m %3s").arg((int)h, 2, 10, QChar('0')).arg((int)m, 2, 10, QChar('0')).arg((int)s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
QString SkyPoint::toDMS(double deg)
|
||||
{
|
||||
int sign = deg < 0.0 ? -1 : 1;
|
||||
deg *= sign;
|
||||
double d,m,s,md;
|
||||
md = std::modf(deg, &d) * 60.0;
|
||||
s = std::modf(md, &m) * 60.0;
|
||||
|
||||
return QString("%1˚ %2' %3\"").arg((int)d * sign, 2, 10, QChar('0')).arg((int)m, 2, 10, QChar('0')).arg((int)s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
SkyPoint SkyPoint::operator+(const SkyPoint &p)
|
||||
{
|
||||
SkyPoint ret;
|
||||
ret.ra = ra + p.ra;
|
||||
ret.dec = dec + p.dec;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SkyPointScale ImageInfoData::getCenterRaDec() const
|
||||
{
|
||||
SkyPointScale ret;
|
||||
if(wcs && wcs->valid())
|
||||
{
|
||||
ret = wcs->getRaDecScale();
|
||||
}
|
||||
else
|
||||
{
|
||||
double ra,dec,focalLen,scale,pixSizeX,pixSizeY;
|
||||
int binX = 1;
|
||||
int binY = 1;
|
||||
ra = dec = focalLen = scale = pixSizeX = pixSizeY = NAN;
|
||||
bool ok;
|
||||
for(const FITSRecord &header : fitsHeader)
|
||||
{
|
||||
if(header.key == "OBJCTRA")
|
||||
{
|
||||
double tmp = SkyPoint::fromHMS(header.value.toString());
|
||||
if(!std::isnan(tmp))ra = tmp;
|
||||
}
|
||||
else if(header.key == "RA" && std::isnan(ra))
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)ra = tmp;
|
||||
}
|
||||
else if(header.key == "OBJCTDEC")
|
||||
{
|
||||
double tmp = SkyPoint::fromDMS(header.value.toString());
|
||||
if(!std::isnan(tmp))dec = tmp;
|
||||
}
|
||||
else if(header.key == "DEC" && std::isnan(dec))
|
||||
{
|
||||
double tmp = SkyPoint::fromDMS(header.value.toString());
|
||||
if(!std::isnan(tmp))dec = tmp;
|
||||
}
|
||||
else if(header.key == "SCALE")
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)scale = tmp;
|
||||
}
|
||||
else if(header.key == "FOCALLEN")
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)focalLen = tmp;
|
||||
}
|
||||
else if(header.key == "PIXSIZE1" || header.key == "XPIXSZ")
|
||||
{
|
||||
pixSizeX = header.value.toDouble();
|
||||
}
|
||||
else if(header.key == "PIXSIZE2" || header.key == "YPIXSZ")
|
||||
{
|
||||
pixSizeY = header.value.toDouble();
|
||||
}
|
||||
else if(header.key == "XBINNING")
|
||||
{
|
||||
int tmp = header.value.toInt(&ok);
|
||||
if(ok)binX = tmp;
|
||||
}
|
||||
else if(header.key == "YBINNING")
|
||||
{
|
||||
int tmp = header.value.toInt(&ok);
|
||||
if(ok)binY = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
ret.point.set(ra, dec);
|
||||
if(!std::isnan(scale))
|
||||
{
|
||||
ret.scaleLow = ret.scaleHigh = scale;
|
||||
ret.scaleValid = true;
|
||||
}
|
||||
else if(!(std::isnan(focalLen) || std::isnan(pixSizeX) || std::isnan(pixSizeY)))
|
||||
{
|
||||
const double r = 206.2648097656; // (180 * 3600) / (1000 * pi) magic number to convert pixel size to focal length ratio to arcsec.
|
||||
ret.scaleLow = std::min(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r);
|
||||
ret.scaleHigh = std::max(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r);
|
||||
ret.scaleValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(ret.scaleValid)
|
||||
{
|
||||
ret.scaleLow *= 0.8;
|
||||
ret.scaleHigh *= 1.2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SkyPoint greatCircle(SkyPoint &p, double dist, double azm)
|
||||
{
|
||||
dist = dist * M_PI / 180;
|
||||
azm = azm * M_PI / 180;
|
||||
double dec0 = p.DEC() * M_PI / 180;
|
||||
double ra0 = p.RA() * M_PI / 180;
|
||||
double dec1 = std::asin(std::sin(dec0) * std::cos(dist) + std::cos(dec0) * std::sin(dist) * std::cos(azm));
|
||||
double ra1 = ra0 + std::atan2(std::sin(azm) * std::sin(dist) * std::cos(dec0), std::cos(dist) - std::sin(dec0) * std::sin(dec1));
|
||||
return SkyPoint(ra1 * 180 / M_PI, dec1 * 180 / M_PI);
|
||||
}
|
||||
|
||||
SkyGrid WCSDataT::prepareGrid(uint32_t w, uint32_t h, Database *database)
|
||||
{
|
||||
SkyGrid skyGrid;
|
||||
if(!wcs)return skyGrid;
|
||||
|
||||
double minRa, maxRa, minDec, maxDec, crVal1, crVal2;
|
||||
calculateBounds(minRa, maxRa, minDec, maxDec, crVal1, crVal2);
|
||||
|
||||
QPointF a,b;
|
||||
worldToPixel(SkyPoint(crVal1, crVal2), a);
|
||||
worldToPixel(SkyPoint(crVal1 + 0.01, crVal2), b);
|
||||
skyGrid.rot_ang = std::atan2(b.y() - a.y(), b.x() - a.x()) / M_PI * -180.0;
|
||||
|
||||
if(database)
|
||||
{
|
||||
skyGrid.objects = database->getObjects(minRa, maxRa, minDec, maxDec);
|
||||
for(auto &object : skyGrid.objects)
|
||||
{
|
||||
QPointF p;
|
||||
if(worldToPixel(object.skyPoint, p))
|
||||
object.pixel = p;
|
||||
|
||||
QPointF majax;
|
||||
worldToPixel(greatCircle(object.skyPoint, (object.min_ax + object.maj_ax) / 120.0, object.pos_ang), majax);
|
||||
majax -= p;
|
||||
object.maj_ax = std::sqrt(QPointF::dotProduct(majax, majax));
|
||||
}
|
||||
}
|
||||
|
||||
double raStep = 15;
|
||||
double decStep = 15;
|
||||
double raRange = maxRa - minRa;
|
||||
double decRange = maxDec - minDec;
|
||||
const QVector<double> raSteps = {15, 5, 2.5, 1.25, 0.25, 20/240.0, 10/240.0, 5/240.0, 1/240.0};
|
||||
const QVector<double> decSteps = {20, 10, 5, 2, 1, 20/60.0, 10/60.0, 5/60.0, 2/60.0, 1/60.0, 20/3600.0, 10/3600.0, 5/3600.0, 2/3600.0, 1/3600.0};
|
||||
|
||||
for(double ra : raSteps)
|
||||
{
|
||||
if(ra * 5 <= raRange)
|
||||
{
|
||||
raStep = ra;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(double dec : decSteps)
|
||||
{
|
||||
if(dec * 5 <= decRange)
|
||||
{
|
||||
decStep = dec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
minRa -= std::fmod(minRa, raStep);
|
||||
minDec -= std::fmod(minDec, decStep);
|
||||
if(minRa < 0)minRa -= raStep;
|
||||
if(minDec < 0)minDec -= decStep;
|
||||
|
||||
QRectF clip(0, 0, w, h);
|
||||
const double step = 0.2;
|
||||
|
||||
maxRa += raStep;
|
||||
maxDec += decStep;
|
||||
for(double ra = minRa; ra <= maxRa; ra += raStep)
|
||||
{
|
||||
QPointF p;
|
||||
worldToPixel(SkyPoint(ra, minDec), p);
|
||||
skyGrid.grid.moveTo(p);
|
||||
for(double dec = minDec + decStep * step; dec <= maxDec; dec += decStep * step)
|
||||
{
|
||||
worldToPixel(SkyPoint(ra, dec), p);
|
||||
skyGrid.grid.lineTo(p);
|
||||
}
|
||||
}
|
||||
|
||||
for(double dec = minDec; dec <= maxDec; dec += decStep)
|
||||
{
|
||||
QPointF p;
|
||||
worldToPixel(SkyPoint(minRa, dec), p);
|
||||
skyGrid.grid.moveTo(p);
|
||||
for(double ra = minRa + raStep * step; ra <= maxRa; ra += raStep * step)
|
||||
{
|
||||
worldToPixel(SkyPoint(ra, dec), p);
|
||||
skyGrid.grid.lineTo(p);
|
||||
}
|
||||
}
|
||||
|
||||
SkyPoint sp1, sp2,orig;
|
||||
pixelToWorld(QPointF(-1, -1), orig);
|
||||
sp1 = orig;
|
||||
for(uint32_t x = 0; x < w; x++)
|
||||
{
|
||||
QPointF p(x, 0);
|
||||
if(!pixelToWorld(p, sp2))
|
||||
break;
|
||||
|
||||
if(static_cast<int>(sp1.RA() / raStep) != static_cast<int>(sp2.RA() / raStep))
|
||||
skyGrid.text.append({p, std::abs(sp1.RA()) > std::abs(sp2.RA()) ? sp1.RAString() : sp2.RAString()});
|
||||
|
||||
if(static_cast<int>(sp1.DEC() / decStep) != static_cast<int>(sp2.DEC() / decStep))
|
||||
skyGrid.text.append({p, std::abs(sp1.DEC()) > std::abs(sp2.DEC()) ? sp1.DECString() : sp2.DECString()});
|
||||
|
||||
sp1 = sp2;
|
||||
}
|
||||
|
||||
sp1 = orig;
|
||||
for(uint32_t y = 0; y < h; y++)
|
||||
{
|
||||
QPointF p(0, y);
|
||||
if(!pixelToWorld(p, sp2))
|
||||
break;
|
||||
|
||||
if(static_cast<int>(sp1.RA() / raStep) != static_cast<int>(sp2.RA() / raStep))
|
||||
skyGrid.text.append({p, std::abs(sp1.RA()) > std::abs(sp2.RA()) ? sp1.RAString() : sp2.RAString()});
|
||||
|
||||
if(static_cast<int>(sp1.DEC() / decStep) != static_cast<int>(sp2.DEC() / decStep))
|
||||
skyGrid.text.append({p, std::abs(sp1.DEC()) > std::abs(sp2.DEC()) ? sp1.DECString() : sp2.DECString()});
|
||||
|
||||
sp1 = sp2;
|
||||
}
|
||||
|
||||
skyGrid.empty = false;
|
||||
return skyGrid;
|
||||
}
|
||||
|
||||
void SkyGrid::clear()
|
||||
{
|
||||
empty = true;
|
||||
grid.clear();
|
||||
text.clear();
|
||||
objects.clear();
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
#ifndef IMAGEINFODATA_H
|
||||
#define IMAGEINFODATA_H
|
||||
|
||||
#include <QString>
|
||||
#include <QPointF>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
#include <QPainterPath>
|
||||
#include <wcslib/wcs.h>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
namespace LibXISF { struct FITSKeyword; struct Property; }
|
||||
|
||||
class Database;
|
||||
|
||||
struct FITSRecord
|
||||
{
|
||||
QByteArray key;
|
||||
QVariant value;
|
||||
QByteArray comment;
|
||||
bool xisf = false;
|
||||
bool editable() const;
|
||||
FITSRecord(){}
|
||||
FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment);
|
||||
FITSRecord(const LibXISF::FITSKeyword &record);
|
||||
FITSRecord(const LibXISF::Property &property);
|
||||
};
|
||||
|
||||
class SkyPoint
|
||||
{
|
||||
double ra = NAN;
|
||||
double dec = NAN;
|
||||
public:
|
||||
SkyPoint();
|
||||
SkyPoint(double ra, double dec);
|
||||
void set(double ra, double dec);
|
||||
double RA() const { return ra; }
|
||||
double RAHour() const { return ra / 15.0; }
|
||||
double DEC() const { return dec; }
|
||||
QString toString() const;
|
||||
QString RAString() const;
|
||||
QString DECString() const;
|
||||
static double fromHMS(const QString &hms);
|
||||
static double fromDMS(const QString &dms);
|
||||
static QString toHMS(double decHour);
|
||||
static QString toDMS(double deg);
|
||||
SkyPoint operator+(const SkyPoint &p);
|
||||
};
|
||||
|
||||
struct SkyPointScale
|
||||
{
|
||||
SkyPoint point;
|
||||
//arcsec per pixel
|
||||
bool scaleValid = false;
|
||||
double scaleLow = 0.0;
|
||||
double scaleHigh = 10000.0;
|
||||
};
|
||||
|
||||
struct SkyObject
|
||||
{
|
||||
QString name;
|
||||
QString name2;
|
||||
SkyPoint skyPoint;
|
||||
double maj_ax;
|
||||
double min_ax;
|
||||
double pos_ang;
|
||||
double mag;
|
||||
QPointF pixel;
|
||||
};
|
||||
|
||||
struct SkyGrid
|
||||
{
|
||||
bool empty = true;
|
||||
QPainterPath grid;
|
||||
QVector<QPair<QPointF, QString>> text;
|
||||
QVector<SkyObject> objects;
|
||||
double rot_ang = 0;
|
||||
void clear();
|
||||
};
|
||||
|
||||
class WCSDataT
|
||||
{
|
||||
int nwcs = 0;
|
||||
struct wcsprm *wcs = nullptr;
|
||||
int width;
|
||||
int height;
|
||||
void freeWCS();
|
||||
public:
|
||||
WCSDataT(int width, int height, char *header, int nrec);
|
||||
WCSDataT(int width, int height, const QVector<FITSRecord> &header);
|
||||
WCSDataT(const WCSDataT &) = delete;
|
||||
~WCSDataT();
|
||||
bool pixelToWorld(const QPointF &pixel, SkyPoint &point) const;
|
||||
bool worldToPixel(const SkyPoint &point, QPointF &pixel) const;
|
||||
bool calculateBounds(double &minRa, double &maxRa, double &minDec, double &maxDec, double &crVal1, double &crVal2) const;
|
||||
bool valid() const { return wcs; };
|
||||
SkyPointScale getRaDecScale() const;
|
||||
SkyGrid prepareGrid(uint32_t w, uint32_t h, Database *database);
|
||||
};
|
||||
|
||||
struct ImageInfoData
|
||||
{
|
||||
QVector<FITSRecord> fitsHeader;
|
||||
QVector<QPair<QString, QString>> info;
|
||||
std::shared_ptr<WCSDataT> wcs;
|
||||
SkyPointScale getCenterRaDec() const;
|
||||
int index = 0;
|
||||
int num = 1;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
None,
|
||||
Statistics,
|
||||
Peaks,
|
||||
Stars,
|
||||
}AnalyzeLevel;
|
||||
|
||||
Q_DECLARE_METATYPE(ImageInfoData);
|
||||
|
||||
#endif // IMAGEINFODATA_H
|
||||
@@ -0,0 +1,607 @@
|
||||
#include "imageringlist.h"
|
||||
#include <functional>
|
||||
#include <QThreadPool>
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QTimer>
|
||||
#include <QRegularExpression>
|
||||
#include "loadrunable.h"
|
||||
#include "rawimage.h"
|
||||
#include "database.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int DEFAULT_WIDTH = 2;
|
||||
|
||||
Image::Image(const QString name, int number, ImageRingList *ringList) :
|
||||
m_loading(false),
|
||||
m_released(true),
|
||||
m_current(false),
|
||||
m_number(number),
|
||||
m_name(name),
|
||||
m_ringList(ringList)
|
||||
{
|
||||
}
|
||||
|
||||
void Image::load(int index, QThreadPool *pool)
|
||||
{
|
||||
if(index != m_info.index && !m_loading)
|
||||
m_rawImage.reset();
|
||||
|
||||
if(!m_rawImage && !m_loading)
|
||||
{
|
||||
m_loading = true;
|
||||
m_released = false;
|
||||
pool->start(new LoadRunable(m_name, this, m_ringList->analyzeLevel(), index));
|
||||
}
|
||||
if(!m_loading && m_rawImage)
|
||||
emit pixmapLoaded(this);
|
||||
}
|
||||
|
||||
void Image::loadThumbnail(QThreadPool *pool)
|
||||
{
|
||||
if(!m_thumbnail)
|
||||
pool->start(new LoadRunable(m_name, this, AnalyzeLevel::None, 0, true));
|
||||
else
|
||||
emit thumbnailLoaded(this);
|
||||
}
|
||||
|
||||
void Image::release()
|
||||
{
|
||||
m_rawImage.reset();
|
||||
m_released = true;
|
||||
m_loading = false;
|
||||
}
|
||||
|
||||
QString Image::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
std::shared_ptr<RawImage> Image::rawImage()
|
||||
{
|
||||
return m_rawImage;
|
||||
}
|
||||
|
||||
const RawImage *Image::thumbnail() const
|
||||
{
|
||||
return m_thumbnail.get();
|
||||
}
|
||||
|
||||
ImageInfoData Image::info() const
|
||||
{
|
||||
return m_info;
|
||||
}
|
||||
|
||||
bool Image::isCurrent() const
|
||||
{
|
||||
return !m_released;
|
||||
}
|
||||
|
||||
int Image::number() const
|
||||
{
|
||||
return m_number;
|
||||
}
|
||||
|
||||
void Image::clearThumbnail()
|
||||
{
|
||||
m_thumbnail.reset();
|
||||
}
|
||||
|
||||
bool Image::isLoading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void Image::imageLoaded(std::shared_ptr<RawImage> rawImage, ImageInfoData info)
|
||||
{
|
||||
m_loading = false;
|
||||
if(!m_released)
|
||||
{
|
||||
m_rawImage = rawImage;
|
||||
m_info = info;
|
||||
emit pixmapLoaded(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Image::thumbnailLoadFinish(std::shared_ptr<RawImage> rawImage)
|
||||
{
|
||||
m_thumbnail = rawImage;
|
||||
if(m_thumbnail)
|
||||
emit thumbnailLoaded(this);
|
||||
}
|
||||
|
||||
ImageRingList::ImageRingList(Database *database, const QStringList &nameFilter, QObject *parent) : QAbstractItemModel(parent)
|
||||
, m_liveMode(false)
|
||||
, m_analyzeLevel(None)
|
||||
, m_database(database)
|
||||
, m_nameFilter(nameFilter)
|
||||
, m_fileSuffix(nameFilter)
|
||||
{
|
||||
connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &ImageRingList::dirChanged);
|
||||
m_nameFilter.replaceInStrings(QRegularExpression("^"), "*.");
|
||||
m_loadPool = new QThreadPool(this);
|
||||
m_loadPool->setThreadPriority(QThread::LowPriority);
|
||||
m_thumbPool = new QThreadPool(this);
|
||||
m_thumbPool->setThreadPriority(QThread::LowPriority);
|
||||
|
||||
m_slideShowTimer = new QTimer(this);
|
||||
connect(m_slideShowTimer, &QTimer::timeout, this, static_cast<void (ImageRingList::*)()>(&ImageRingList::increment));
|
||||
|
||||
m_dirChangeDelay = new QTimer(this);
|
||||
m_dirChangeDelay->setInterval(3000);
|
||||
m_dirChangeDelay->setSingleShot(true);
|
||||
connect(m_dirChangeDelay, &QTimer::timeout, this, &ImageRingList::reloadDir);
|
||||
}
|
||||
|
||||
ImageRingList::~ImageRingList()
|
||||
{
|
||||
m_loadPool->clear();
|
||||
m_thumbPool->clear();
|
||||
|
||||
m_loadPool->waitForDone();
|
||||
m_thumbPool->waitForDone();
|
||||
}
|
||||
|
||||
bool ImageRingList::setDir(const QString path, const QString ¤tFile, bool recursive)
|
||||
{
|
||||
QDir dir(path);
|
||||
|
||||
if(dir.exists())
|
||||
{
|
||||
m_currentDir = path;
|
||||
QStringList scannedDirs;
|
||||
QStringList absolutePaths;
|
||||
std::function<void(const QString&)> scanDir = [&](const QString &path)
|
||||
{
|
||||
QDir dir(path);
|
||||
if(scannedDirs.contains(dir.canonicalPath()))return;
|
||||
scannedDirs.append(dir.canonicalPath());
|
||||
QDir::SortFlags sortFlags = m_liveMode ? QDir::Time : m_sort | QDir::IgnoreCase;
|
||||
if(m_reversed)sortFlags |= QDir::Reversed;
|
||||
|
||||
if(recursive)
|
||||
{
|
||||
QStringList dirs = dir.entryList(QDir::Readable | QDir::Dirs | QDir::NoDotAndDotDot, sortFlags);
|
||||
for(const QString &subdir : dirs)
|
||||
scanDir(dir.absoluteFilePath(subdir));
|
||||
}
|
||||
|
||||
QStringList list = dir.entryList(m_nameFilter, QDir::Files | QDir::Readable, sortFlags);
|
||||
for(const QString &file : list)
|
||||
{
|
||||
absolutePaths.append(dir.absoluteFilePath(file));
|
||||
}
|
||||
};
|
||||
|
||||
scanDir(path);
|
||||
//qDebug() << absolutePaths.size();
|
||||
setFilesPrivate(absolutePaths, m_liveMode ? absolutePaths.first() : currentFile);
|
||||
|
||||
if(m_fileSystemWatcher.directories().size())
|
||||
m_fileSystemWatcher.removePaths(m_fileSystemWatcher.directories());
|
||||
m_fileSystemWatcher.addPath(path);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ImageRingList::setFile(const QString &file)
|
||||
{
|
||||
if(!file.isEmpty())
|
||||
{
|
||||
QFileInfo info(file);
|
||||
if(info.isDir())
|
||||
setDir(file, QString(), true);
|
||||
else
|
||||
setDir(info.absolutePath(), file);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setFiles(QStringList files)
|
||||
{
|
||||
QRegularExpression reg("(" + m_fileSuffix.join("|") + ")");
|
||||
files.removeIf([®](const QString &file){
|
||||
QFileInfo info(file);
|
||||
auto match = reg.match(info.suffix());
|
||||
return !match.hasMatch() || !info.exists() || !info.isReadable() || !info.isFile();
|
||||
});
|
||||
setFilesPrivate(files);
|
||||
}
|
||||
|
||||
ImagePtr ImageRingList::currentImage()
|
||||
{
|
||||
if(m_images.size())
|
||||
return *m_currImage;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
QString ImageRingList::currentDir() const
|
||||
{
|
||||
return m_currentDir;
|
||||
}
|
||||
|
||||
void ImageRingList::increment()
|
||||
{
|
||||
if(m_images.size())
|
||||
{
|
||||
//don't increment if current image was not loaded yet
|
||||
if((*m_currImage)->isLoading())
|
||||
return;
|
||||
|
||||
(*m_firstImage)->release();
|
||||
m_firstImage = increment(m_firstImage);
|
||||
m_currImage = increment(m_currImage);
|
||||
(*m_currImage)->load(0, m_loadPool);
|
||||
m_lastImage = increment(m_lastImage);
|
||||
(*m_lastImage)->load(0, m_loadPool);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::decrement()
|
||||
{
|
||||
if(m_images.size())
|
||||
{
|
||||
//don't decrement if current image was not loaded yet
|
||||
if((*m_currImage)->isLoading())
|
||||
return;
|
||||
|
||||
(*m_lastImage)->release();
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
m_currImage = decrement(m_currImage);
|
||||
(*m_currImage)->load(0, m_loadPool);
|
||||
m_lastImage = decrement(m_lastImage);
|
||||
(*m_firstImage)->load(0, m_loadPool);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::prevSubImage()
|
||||
{
|
||||
if(m_images.size())
|
||||
{
|
||||
if((*m_currImage)->isLoading())
|
||||
return;
|
||||
|
||||
int index = (*m_currImage)->info().index;
|
||||
int num = (*m_currImage)->info().num;
|
||||
if(num > 1)
|
||||
(*m_currImage)->load(index == 0 ? num - 1 : index - 1, m_loadPool);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::nextSubImage()
|
||||
{
|
||||
if(m_images.size())
|
||||
{
|
||||
if((*m_currImage)->isLoading())
|
||||
return;
|
||||
|
||||
int index = (*m_currImage)->info().index;
|
||||
int num = (*m_currImage)->info().num;
|
||||
if(num > 1)
|
||||
(*m_currImage)->load((index + 1) % num, m_loadPool);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setMarked()
|
||||
{
|
||||
QStringList files = m_database->getMarkedFiles();
|
||||
files.removeIf([](const QString &file){
|
||||
QFileInfo info(file);
|
||||
return !info.exists() || !info.isReadable();
|
||||
});
|
||||
setFilesPrivate(files);
|
||||
}
|
||||
|
||||
void ImageRingList::reloadImage()
|
||||
{
|
||||
if(*m_currImage)
|
||||
{
|
||||
int index = (*m_currImage)->info().index;
|
||||
(*m_currImage)->release();
|
||||
(*m_currImage)->load(index, m_loadPool);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setLiveMode(bool live)
|
||||
{
|
||||
m_liveMode = live;
|
||||
}
|
||||
|
||||
void ImageRingList::setCalculateStats(bool stats)
|
||||
{
|
||||
m_analyzeLevel = stats ? Statistics : None;
|
||||
}
|
||||
|
||||
void ImageRingList::setFindPeaks(bool findPeaks)
|
||||
{
|
||||
m_analyzeLevel = findPeaks ? Peaks : None;
|
||||
}
|
||||
|
||||
void ImageRingList::setFindStars(bool findStars)
|
||||
{
|
||||
m_analyzeLevel = findStars ? Stars : None;
|
||||
}
|
||||
|
||||
AnalyzeLevel ImageRingList::analyzeLevel() const
|
||||
{
|
||||
return m_analyzeLevel;
|
||||
}
|
||||
|
||||
void ImageRingList::loadFile(int row)
|
||||
{
|
||||
if(row < m_images.size())
|
||||
{
|
||||
int diff = m_currImage != m_images.end() ? row - (m_currImage - m_images.begin()) : -100;
|
||||
if(diff == 1)
|
||||
increment();
|
||||
else if(diff == -1)
|
||||
decrement();
|
||||
else
|
||||
{
|
||||
m_firstImage = m_currImage = m_lastImage = m_images.begin()+row;
|
||||
if(m_images.empty())
|
||||
return;
|
||||
|
||||
(*m_currImage)->load(0, m_loadPool);
|
||||
|
||||
m_width = DEFAULT_WIDTH<m_images.size()/2 ? DEFAULT_WIDTH : m_images.size()/2;
|
||||
if(m_liveMode)
|
||||
m_width = 0;
|
||||
|
||||
for(int i=0; i<m_width; i++)
|
||||
{
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
(*m_firstImage)->load(0, m_loadPool);
|
||||
m_lastImage = increment(m_lastImage);
|
||||
(*m_lastImage)->load(0, m_loadPool);
|
||||
}
|
||||
if(m_lastImage != m_firstImage)
|
||||
{
|
||||
QList<ImagePtr>::iterator iter = increment(m_lastImage);
|
||||
while(m_firstImage != iter)
|
||||
{
|
||||
(*iter)->release();
|
||||
iter = increment(iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::loadThumbnails()
|
||||
{
|
||||
for(auto &img : m_images)
|
||||
{
|
||||
img->loadThumbnail(m_thumbPool);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::stopLoading()
|
||||
{
|
||||
m_thumbPool->clear();
|
||||
m_thumbPool->waitForDone();
|
||||
}
|
||||
|
||||
int ImageRingList::imageCount() const
|
||||
{
|
||||
return m_images.size();
|
||||
}
|
||||
|
||||
QStringList ImageRingList::imageNames() const
|
||||
{
|
||||
QStringList ret;
|
||||
for(auto &img : m_images)
|
||||
ret.push_back(img->name());
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ImageRingList::updateMark()
|
||||
{
|
||||
if(m_images.size())
|
||||
{
|
||||
QModelIndex idx = index(m_currImage - m_images.begin(), 0);
|
||||
emit dataChanged(idx, idx, {Qt::FontRole});
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::clearThumbnails()
|
||||
{
|
||||
for(auto &img : m_images)
|
||||
img->clearThumbnail();
|
||||
}
|
||||
|
||||
QModelIndex ImageRingList::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return createIndex(row, column, m_images.at(row).get());
|
||||
}
|
||||
|
||||
QModelIndex ImageRingList::parent(const QModelIndex &child) const
|
||||
{
|
||||
Q_UNUSED(child);
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
int ImageRingList::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
if(parent == QModelIndex())
|
||||
return m_images.size();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ImageRingList::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant ImageRingList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
switch(role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
{
|
||||
QFileInfo info(m_images.at(index.row())->name());
|
||||
return info.fileName();
|
||||
}
|
||||
case Qt::FontRole:
|
||||
{
|
||||
bool marked = m_database->isMarked(m_images.at(index.row())->name());
|
||||
QFont font;
|
||||
font.setBold(marked);
|
||||
return font;
|
||||
}
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant ImageRingList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if(section==0 && orientation==Qt::Horizontal && role==Qt::DisplayRole)
|
||||
{
|
||||
return tr("Name");
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ImageRingList::setPreload(int width)
|
||||
{
|
||||
DEFAULT_WIDTH = width;
|
||||
if(m_images.size() == 0)return;
|
||||
|
||||
int newWidth = DEFAULT_WIDTH<m_images.size()/2 ? DEFAULT_WIDTH : m_images.size()/2;
|
||||
if(newWidth > m_width)
|
||||
{
|
||||
for(int i = newWidth - m_width; i>0; i--)
|
||||
{
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
(*m_firstImage)->load(0, m_loadPool);
|
||||
m_lastImage = increment(m_lastImage);
|
||||
(*m_lastImage)->load(0, m_loadPool);
|
||||
}
|
||||
}
|
||||
if(newWidth < m_width)
|
||||
{
|
||||
for(int i = m_width - newWidth; i>0; i--)
|
||||
{
|
||||
(*m_firstImage)->release();
|
||||
m_firstImage = increment(m_firstImage);
|
||||
(*m_lastImage)->release();
|
||||
m_lastImage = decrement(m_lastImage);
|
||||
}
|
||||
}
|
||||
m_width = newWidth;
|
||||
}
|
||||
|
||||
void ImageRingList::setSort(QDir::SortFlag sort)
|
||||
{
|
||||
if(m_sort != sort)
|
||||
{
|
||||
m_sort = sort;
|
||||
if(m_images.size())
|
||||
{
|
||||
QString path = (*m_currImage)->name();
|
||||
setFile(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::reverseSort()
|
||||
{
|
||||
m_reversed = !m_reversed;
|
||||
if(m_images.size())
|
||||
{
|
||||
QString path = (*m_currImage)->name();
|
||||
setFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::toggleSlideshow(bool start)
|
||||
{
|
||||
if(start)
|
||||
{
|
||||
QSettings settings;
|
||||
int time = settings.value("settings/slideshowtime", 1.0).toDouble() * 1000;
|
||||
m_slideShowTimer->start(time);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_slideShowTimer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setFilesPrivate(const QStringList files, const QString ¤tFile)
|
||||
{
|
||||
m_loadPool->clear();
|
||||
m_thumbPool->clear();
|
||||
m_loadPool->waitForDone();
|
||||
m_thumbPool->waitForDone();
|
||||
beginResetModel();
|
||||
m_images.clear();
|
||||
int i = 0;
|
||||
for(const QString &file : files)
|
||||
{
|
||||
ImagePtr ptr = make_shared<Image>(file, i++, this);
|
||||
connect(ptr.get(), &Image::pixmapLoaded, this, &ImageRingList::imageLoaded);
|
||||
connect(ptr.get(), &Image::thumbnailLoaded, this, &ImageRingList::thumbnailLoaded);
|
||||
m_images.append(ptr);
|
||||
}
|
||||
|
||||
int index = files.indexOf(currentFile);
|
||||
if(index < 0)
|
||||
index = 0;
|
||||
|
||||
endResetModel();
|
||||
m_currImage = m_images.end();
|
||||
loadFile(index);
|
||||
}
|
||||
|
||||
QList<ImagePtr>::iterator ImageRingList::increment(QList<ImagePtr>::iterator iter)
|
||||
{
|
||||
iter++;
|
||||
if(iter == m_images.end())
|
||||
iter = m_images.begin();
|
||||
return iter;
|
||||
}
|
||||
|
||||
QList<ImagePtr>::iterator ImageRingList::decrement(QList<ImagePtr>::iterator iter)
|
||||
{
|
||||
if(iter == m_images.begin())
|
||||
iter = m_images.end();
|
||||
iter--;
|
||||
return iter;
|
||||
}
|
||||
|
||||
void ImageRingList::imageLoaded(Image *image)
|
||||
{
|
||||
if(image->name() == (*m_currImage)->name())
|
||||
{
|
||||
emit pixmapLoaded(image);
|
||||
emit infoLoaded(image->info());
|
||||
emit currentImageChanged(m_currImage-m_images.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::dirChanged(QString)
|
||||
{
|
||||
if(m_liveMode)
|
||||
reloadDir();
|
||||
else
|
||||
m_dirChangeDelay->start();
|
||||
}
|
||||
|
||||
void ImageRingList::reloadDir()
|
||||
{
|
||||
QString currentFile;
|
||||
|
||||
if(m_images.size())
|
||||
currentFile = (*m_currImage)->name();
|
||||
|
||||
setDir(m_currentDir, currentFile);
|
||||
if(m_images.size())
|
||||
emit currentImageChanged(m_currImage-m_images.begin());
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#ifndef IMAGERINGLIST_H
|
||||
#define IMAGERINGLIST_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QList>
|
||||
#include <QPixmap>
|
||||
#include <QDir>
|
||||
#include <memory>
|
||||
#include "imageinfodata.h"
|
||||
#include "rawimage.h"
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class ImageRingList;
|
||||
class QThreadPool;
|
||||
|
||||
class Image : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
bool m_loading;
|
||||
bool m_released;
|
||||
bool m_current;
|
||||
int m_number;
|
||||
std::shared_ptr<RawImage> m_rawImage;
|
||||
std::shared_ptr<RawImage> m_thumbnail;
|
||||
QString m_name;
|
||||
ImageInfoData m_info;
|
||||
ImageRingList *m_ringList;
|
||||
public:
|
||||
explicit Image(const QString name, int number, ImageRingList *ringList);
|
||||
void load(int index, QThreadPool *pool);
|
||||
void loadThumbnail(QThreadPool *pool);
|
||||
void release();
|
||||
QString name() const;
|
||||
std::shared_ptr<RawImage> rawImage();
|
||||
const RawImage* thumbnail() const;
|
||||
ImageInfoData info() const;
|
||||
bool isCurrent() const;
|
||||
int number() const;
|
||||
void clearThumbnail();
|
||||
bool isLoading() const;
|
||||
signals:
|
||||
void pixmapLoaded(Image *ptr);
|
||||
void thumbnailLoaded(Image *ptr);
|
||||
protected slots:
|
||||
void imageLoaded(std::shared_ptr<RawImage> rawImage, ImageInfoData info);
|
||||
void thumbnailLoadFinish(std::shared_ptr<RawImage> rawImage);
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<Image> ImagePtr;
|
||||
|
||||
class Database;
|
||||
|
||||
class ImageRingList : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
int m_width;
|
||||
QList<ImagePtr> m_images;
|
||||
QList<ImagePtr>::iterator m_firstImage;
|
||||
QList<ImagePtr>::iterator m_currImage;
|
||||
QList<ImagePtr>::iterator m_lastImage;
|
||||
QFileSystemWatcher m_fileSystemWatcher;
|
||||
bool m_liveMode;
|
||||
QDir::SortFlag m_sort = QDir::Name;
|
||||
bool m_reversed = false;
|
||||
AnalyzeLevel m_analyzeLevel;
|
||||
QThreadPool *m_loadPool;
|
||||
QThreadPool *m_thumbPool;
|
||||
Database *m_database;
|
||||
QStringList m_nameFilter;
|
||||
QStringList m_fileSuffix;
|
||||
QTimer *m_slideShowTimer;
|
||||
QTimer *m_dirChangeDelay;
|
||||
QString m_currentDir;
|
||||
public:
|
||||
explicit ImageRingList(Database *database, const QStringList &nameFilter, QObject *parent = 0);
|
||||
~ImageRingList() override;
|
||||
bool setDir(const QString path, const QString ¤tFile = QString(), bool recursive = false);
|
||||
void setFile(const QString &file);
|
||||
void setFiles(QStringList files);
|
||||
ImagePtr currentImage();
|
||||
QString currentDir() const;
|
||||
void setLiveMode(bool live);
|
||||
void setCalculateStats(bool stats);
|
||||
void setFindPeaks(bool findPeaks);
|
||||
void setFindStars(bool findStars);
|
||||
AnalyzeLevel analyzeLevel() const;
|
||||
void loadFile(int row);
|
||||
void loadThumbnails();
|
||||
void stopLoading();
|
||||
int imageCount() const;
|
||||
QStringList imageNames() const;
|
||||
void updateMark();
|
||||
void clearThumbnails();
|
||||
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||
QModelIndex parent(const QModelIndex &child) const override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||
public slots:
|
||||
void setPreload(int width);
|
||||
void setSort(QDir::SortFlag sort);
|
||||
void reverseSort();
|
||||
void toggleSlideshow(bool start);
|
||||
void increment();
|
||||
void decrement();
|
||||
void prevSubImage();
|
||||
void nextSubImage();
|
||||
void setMarked();
|
||||
void reloadImage();
|
||||
protected:
|
||||
void setFilesPrivate(const QStringList files, const QString ¤tFile = QString());
|
||||
QList<ImagePtr>::iterator increment(QList<ImagePtr>::iterator iter);
|
||||
QList<ImagePtr>::iterator decrement(QList<ImagePtr>::iterator iter);
|
||||
signals:
|
||||
void pixmapLoaded(Image *image);
|
||||
void thumbnailLoaded(Image *image);
|
||||
void infoLoaded(ImageInfoData info);
|
||||
void currentImageChanged(int index);
|
||||
protected slots:
|
||||
void imageLoaded(Image *image);
|
||||
void dirChanged(QString);
|
||||
void reloadDir();
|
||||
};
|
||||
|
||||
#endif // IMAGERINGLIST_H
|
||||
@@ -0,0 +1,153 @@
|
||||
#include "imagescrollarea.h"
|
||||
#include "imageringlist.h"
|
||||
#include <QDebug>
|
||||
#include <QKeyEvent>
|
||||
#include <QGridLayout>
|
||||
#include <QMimeData>
|
||||
#include <QMessageBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include <QScrollBar>
|
||||
#include <cmath>
|
||||
|
||||
ImageScrollArea::ImageScrollArea(Database *database, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
QGridLayout *layout = new QGridLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
ImageWidgetGL *imageWidgetGL = new ImageWidgetGL(database, this);
|
||||
m_imageWidget = imageWidgetGL;
|
||||
|
||||
m_verticalScrollBar = new QScrollBar(Qt::Vertical, this);
|
||||
m_horizontalScrollBar = new QScrollBar(Qt::Horizontal, this);
|
||||
|
||||
layout->setSpacing(0);
|
||||
layout->addWidget(dynamic_cast<ImageWidgetGL*>(m_imageWidget), 0, 0);
|
||||
layout->addWidget(m_verticalScrollBar, 0, 1);
|
||||
layout->addWidget(m_horizontalScrollBar, 1, 0);
|
||||
|
||||
connect(m_verticalScrollBar, &QScrollBar::valueChanged, this, &ImageScrollArea::scrollEvent);
|
||||
connect(m_horizontalScrollBar, &QScrollBar::valueChanged, this, &ImageScrollArea::scrollEvent);
|
||||
|
||||
if(imageWidgetGL)
|
||||
{
|
||||
connect(imageWidgetGL, &ImageWidgetGL::fileDropped, this, &ImageScrollArea::fileDropped);
|
||||
connect(imageWidgetGL, &ImageWidgetGL::status, this, &ImageScrollArea::status);
|
||||
connect(imageWidgetGL, &ImageWidgetGL::scrollBarsUpdate, this, &ImageScrollArea::updateScrollbars);
|
||||
}
|
||||
}
|
||||
|
||||
ImageScrollArea::~ImageScrollArea()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ImageScrollArea::allocateThumbnails(const QStringList &paths)
|
||||
{
|
||||
m_imageWidget->allocateThumbnails(paths);
|
||||
}
|
||||
|
||||
void ImageScrollArea::showThumbnail(bool enable)
|
||||
{
|
||||
m_imageWidget->showThumbnail(enable);
|
||||
}
|
||||
|
||||
void ImageScrollArea::setBayerMask(int mask)
|
||||
{
|
||||
m_imageWidget->setBayerMask(mask);
|
||||
}
|
||||
|
||||
void ImageScrollArea::setColormap(int colormap)
|
||||
{
|
||||
m_imageWidget->setColormap(colormap);
|
||||
}
|
||||
|
||||
void ImageScrollArea::updateScrollbars(int valueH, int stepH, int maxH, int valueV, int stepV, int maxV)
|
||||
{
|
||||
if(maxH > 0)
|
||||
{
|
||||
m_horizontalScrollBar->show();
|
||||
m_horizontalScrollBar->setRange(0, maxH);
|
||||
m_horizontalScrollBar->setPageStep(stepH);
|
||||
m_horizontalScrollBar->setValue(valueH);
|
||||
}
|
||||
else
|
||||
m_horizontalScrollBar->hide();
|
||||
|
||||
if(maxV > 0)
|
||||
{
|
||||
m_verticalScrollBar->show();
|
||||
m_verticalScrollBar->setRange(0, maxV);
|
||||
m_verticalScrollBar->setPageStep(stepV);
|
||||
m_verticalScrollBar->setValue(valueV);
|
||||
}
|
||||
else
|
||||
m_verticalScrollBar->hide();
|
||||
}
|
||||
|
||||
void ImageScrollArea::zoomIn()
|
||||
{
|
||||
m_imageWidget->zoom(1);
|
||||
}
|
||||
|
||||
void ImageScrollArea::zoomOut()
|
||||
{
|
||||
m_imageWidget->zoom(-1);
|
||||
}
|
||||
|
||||
void ImageScrollArea::bestFit()
|
||||
{
|
||||
m_horizontalScrollBar->hide();
|
||||
m_verticalScrollBar->hide();
|
||||
m_imageWidget->bestFit();
|
||||
}
|
||||
|
||||
void ImageScrollArea::oneToOne()
|
||||
{
|
||||
m_imageWidget->zoom(0);
|
||||
}
|
||||
|
||||
void ImageScrollArea::imageLoaded(Image *image)
|
||||
{
|
||||
if(image)
|
||||
{
|
||||
m_imageWidget->setImage(image->rawImage(), image->number());
|
||||
m_imageWidget->setWCS(image->info().wcs);
|
||||
}
|
||||
}
|
||||
|
||||
void ImageScrollArea::thumbnailLoaded(const Image *image)
|
||||
{
|
||||
m_imageWidget->thumbnailLoaded(image);
|
||||
}
|
||||
|
||||
void ImageScrollArea::setMTFParams(const MTFParam ¶ms)
|
||||
{
|
||||
m_imageWidget->setMTFParams(params);
|
||||
}
|
||||
|
||||
void ImageScrollArea::invert(bool enable)
|
||||
{
|
||||
m_imageWidget->invert(enable);
|
||||
}
|
||||
|
||||
void ImageScrollArea::superPixel(bool enable)
|
||||
{
|
||||
m_imageWidget->superPixel(enable);
|
||||
}
|
||||
|
||||
void ImageScrollArea::falseColor(bool enable)
|
||||
{
|
||||
m_imageWidget->falseColor(enable);
|
||||
}
|
||||
|
||||
QImage ImageScrollArea::renderToImage()
|
||||
{
|
||||
return m_imageWidget->renderToImage();
|
||||
}
|
||||
|
||||
void ImageScrollArea::scrollEvent()
|
||||
{
|
||||
m_imageWidget->setOffset(m_horizontalScrollBar->value(), m_verticalScrollBar->value());
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef IMAGESCROLLAREA_H
|
||||
#define IMAGESCROLLAREA_H
|
||||
|
||||
#include "imagewidget.h"
|
||||
#include <QScrollBar>
|
||||
|
||||
class ImageScrollArea : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
QScrollBar *m_verticalScrollBar;
|
||||
QScrollBar *m_horizontalScrollBar;
|
||||
ImageWidget *m_imageWidget;
|
||||
public:
|
||||
explicit ImageScrollArea(Database *database, QWidget *parent = nullptr);
|
||||
~ImageScrollArea();
|
||||
|
||||
void allocateThumbnails(const QStringList &paths);
|
||||
void showThumbnail(bool enable);
|
||||
void setBayerMask(int mask);
|
||||
void setColormap(int colormap);
|
||||
protected:
|
||||
void updateScrollbars(int valueH, int stepH, int maxH, int valueV, int stepV, int maxV);
|
||||
public slots:
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void bestFit();
|
||||
void oneToOne();
|
||||
void imageLoaded(Image *image);
|
||||
void thumbnailLoaded(const Image *image);
|
||||
void setMTFParams(const MTFParam ¶ms);
|
||||
void invert(bool enable);
|
||||
void superPixel(bool enable);
|
||||
void falseColor(bool enable);
|
||||
QImage renderToImage();
|
||||
protected slots:
|
||||
void scrollEvent();
|
||||
signals:
|
||||
void fileDropped(const QString &path);
|
||||
void status(const QString &value, const QString &pixelCoords, const QString &celestialCoords);
|
||||
void scrollBarsUpdate(int valueH, int stepH, int maxH, int valueV, int stepV, int maxV);
|
||||
};
|
||||
|
||||
#endif // IMAGESCROLLAREA_H
|
||||
+1042
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,143 @@
|
||||
#ifndef IMAGEWIDGET_H
|
||||
#define IMAGEWIDGET_H
|
||||
|
||||
#include <memory>
|
||||
#include <QOpenGLWidget>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QOpenGLBuffer>
|
||||
#include <QOpenGLTexture>
|
||||
#include <QOpenGLVertexArrayObject>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QPainterPath>
|
||||
#include "database.h"
|
||||
#include "rawimage.h"
|
||||
#include "imageinfodata.h"
|
||||
#include "stretchtoolbar.h"
|
||||
|
||||
class ImageWidget
|
||||
{
|
||||
public:
|
||||
ImageWidget(){}
|
||||
virtual ~ImageWidget(){}
|
||||
|
||||
virtual void setImage(std::shared_ptr<RawImage> image, int index) = 0;
|
||||
virtual void setWCS(std::shared_ptr<WCSDataT> wcs) = 0;
|
||||
|
||||
virtual void zoom(int zoom, const QPointF &mousePos = QPointF()) = 0;
|
||||
virtual void bestFit() = 0;
|
||||
|
||||
virtual void setBayerMask(int mask) = 0;
|
||||
virtual void setColormap(int colormap) = 0;
|
||||
virtual void setOffset(float dx, float dy) = 0;
|
||||
virtual void allocateThumbnails(const QStringList &paths) = 0;
|
||||
|
||||
virtual void setMTFParams(const MTFParam ¶ms) = 0;
|
||||
virtual void superPixel(bool enable) = 0;
|
||||
virtual void invert(bool enable) = 0;
|
||||
virtual void falseColor(bool enable) = 0;
|
||||
virtual QImage renderToImage() = 0;
|
||||
virtual void thumbnailLoaded(const Image *image) = 0;
|
||||
virtual void showThumbnail(bool enable) = 0;
|
||||
virtual void drawGrid(bool enable) = 0;
|
||||
|
||||
static QImage loadColormap();
|
||||
};
|
||||
|
||||
struct ImageThumb
|
||||
{
|
||||
QString name;
|
||||
QString path;
|
||||
QSize size;
|
||||
bool selected;
|
||||
bool dirty;
|
||||
};
|
||||
|
||||
class ImageWidgetGL : public QOpenGLWidget, public ImageWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
QOpenGLFunctions *f = nullptr;
|
||||
QOpenGLExtraFunctions *fx = nullptr;
|
||||
QTimer *m_updateTimer = nullptr;
|
||||
std::unique_ptr<QOpenGLShaderProgram> m_program;
|
||||
std::unique_ptr<QOpenGLShaderProgram> m_thumbnailProgram;
|
||||
std::unique_ptr<QOpenGLShaderProgram> m_debayerProgram;
|
||||
std::unique_ptr<QOpenGLBuffer> m_buffer;
|
||||
std::unique_ptr<QOpenGLBuffer> m_bufferSizes;
|
||||
std::unique_ptr<QOpenGLTexture> m_image;
|
||||
std::unique_ptr<QOpenGLVertexArrayObject> m_vao;
|
||||
std::unique_ptr<QOpenGLVertexArrayObject> m_vaoThumb;
|
||||
std::unique_ptr<QOpenGLTexture> m_thumbnailTexture;
|
||||
std::unique_ptr<QOpenGLTexture> m_lut;
|
||||
std::unique_ptr<QOpenGLTexture> m_colormap;
|
||||
GLuint m_debayerTex = 0;
|
||||
std::shared_ptr<RawImage> m_rawImage;
|
||||
std::shared_ptr<WCSDataT> m_wcs;
|
||||
SkyGrid m_grid;
|
||||
int m_width, m_height;
|
||||
int m_imgWidth = -1, m_imgHeight = -1;
|
||||
int m_currentImg = 0;
|
||||
MTFParam m_mtfParams;
|
||||
float m_unit_scale[2] = {1.0f, 0.0f}; // scale and offset
|
||||
float m_dx = 0, m_dy = 0;
|
||||
float m_scale = 1.0f;
|
||||
int m_scaleStop = 0;
|
||||
bool m_bestFit = false;
|
||||
bool m_bwImg = false;
|
||||
bool m_falseColor = false;
|
||||
bool m_invert = false;
|
||||
bool m_superpixel = false;
|
||||
bool m_showThumbnails = false;
|
||||
bool m_selecting = false;
|
||||
bool m_sizesDirty = false;
|
||||
bool m_srgb = false;
|
||||
bool m_drawGrid = false;
|
||||
int m_thumbnailCount = 0;
|
||||
int m_maxTextureSize = 0;
|
||||
int m_maxArrayLayers = 0;
|
||||
int m_firstRed[2] = {0, 0};
|
||||
int m_colormapIdx = 0;
|
||||
QVector<ImageThumb> m_thumnails;
|
||||
Database *m_database = nullptr;
|
||||
QPointF m_lastPos;
|
||||
QString m_error;
|
||||
bool m_swPaint = false;
|
||||
public:
|
||||
explicit ImageWidgetGL(Database *database, QWidget *parent = nullptr);
|
||||
~ImageWidgetGL() override;
|
||||
void setImage(std::shared_ptr<RawImage> image, int index) override;
|
||||
void setWCS(std::shared_ptr<WCSDataT> wcs) override;
|
||||
void zoom(int zoom, const QPointF &mousePos = QPointF()) override;
|
||||
void bestFit() override;
|
||||
void allocateThumbnails(const QStringList &paths) override;
|
||||
QVector2D getImagePixelCoord(const QVector2D &pos);
|
||||
void setBayerMask(int mask) override;
|
||||
void setColormap(int colormap) override;
|
||||
void setOffset(float dx, float dy) override;
|
||||
void setMTFParams(const MTFParam ¶ms) override;
|
||||
void superPixel(bool enable) override;
|
||||
void invert(bool enable) override;
|
||||
void falseColor(bool enable) override;
|
||||
QImage renderToImage() override;
|
||||
void thumbnailLoaded(const Image *image) override;
|
||||
void showThumbnail(bool enable) override;
|
||||
void drawGrid(bool enable) override;
|
||||
protected:
|
||||
void paintGL() override;
|
||||
void resizeGL(int w, int h) override;
|
||||
void initializeGL() override;
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
void thumbSelect(QMouseEvent *event);
|
||||
void debayer();
|
||||
void updateScrollBars();
|
||||
signals:
|
||||
void fileDropped(const QString &path);
|
||||
void status(const QString &value, const QString &pixelCoords, const QString &celestialCoords);
|
||||
void scrollBarsUpdate(int valueH, int stepH, int maxH, int valueV, int stepV, int maxV);
|
||||
};
|
||||
|
||||
#endif // IMAGEWIDGET_H
|
||||
@@ -0,0 +1,446 @@
|
||||
#include "loadimage.h"
|
||||
#include <QElapsedTimer>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <libraw/libraw.h>
|
||||
#include <fitsio2.h>
|
||||
#include "libxisf.h"
|
||||
#include <libexif/exif-data.h>
|
||||
#include "rawimage.h"
|
||||
|
||||
QString makeUNCPath(const QString &path)
|
||||
{
|
||||
#ifdef Q_OS_WIN64
|
||||
if(!path.startsWith("\\\\") && !path.startsWith("//"))
|
||||
{
|
||||
QString tmp;
|
||||
QFileInfo info(path);
|
||||
tmp = info.absoluteFilePath();
|
||||
tmp = QDir::toNativeSeparators(tmp);
|
||||
tmp.prepend("\\\\?\\");
|
||||
qDebug() << "makeMaxPath" << path << tmp;
|
||||
return tmp;
|
||||
}
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
int loadFITSHeader(fitsfile *file, ImageInfoData &info)
|
||||
{
|
||||
int imgtype;
|
||||
int naxis;
|
||||
long naxes[3] = {0};
|
||||
int nexist;
|
||||
int status = 0;
|
||||
char key[FLEN_KEYWORD];
|
||||
char val[FLEN_VALUE];
|
||||
char comm[FLEN_COMMENT];
|
||||
char strval[FLEN_VALUE];
|
||||
QVariant var;
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
||||
fits_get_hdrspace(file, &nexist, nullptr, &status);
|
||||
for(int i=1; i<=nexist; i++)
|
||||
{
|
||||
fits_read_keyn(file, i, key, val, comm, &status);
|
||||
fits_read_key(file, TSTRING, key, strval, nullptr, &status);
|
||||
if(status == 0 || status == VALUE_UNDEFINED)
|
||||
{
|
||||
QString string(strval);
|
||||
bool isint;
|
||||
bool isdouble;
|
||||
double vald = string.toDouble(&isdouble);
|
||||
long long vall = string.toLongLong(&isint);
|
||||
if(isint)
|
||||
var = vall;
|
||||
else if(isdouble)
|
||||
var = vald;
|
||||
else if(status == VALUE_UNDEFINED)
|
||||
var = QVariant();
|
||||
else if(string == "T" || string == "F")
|
||||
var = string == "T";
|
||||
else
|
||||
var = string;
|
||||
status = 0;
|
||||
info.fitsHeader.append(FITSRecord(key, var, comm));
|
||||
}
|
||||
else
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
char *header = nullptr;
|
||||
int nrec = 0;
|
||||
const char *exclist[] = {"PV1_1", "PV1_2"};
|
||||
fits_hdr2str(file, TRUE, (char**)exclist, 2, &header, &nrec, &status);
|
||||
if(status == 0)
|
||||
{
|
||||
info.wcs = std::make_shared<WCSDataT>(naxes[0], naxes[1], header, nrec);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
}
|
||||
fits_free_memory(header, &status);
|
||||
return status;
|
||||
}
|
||||
|
||||
bool loadFITS(const QString path, ImageInfoData &info, std::shared_ptr<RawImage> &image, bool planar, uint32_t index)
|
||||
{
|
||||
fitsfile *file;
|
||||
int status = 0;
|
||||
int num = 0;
|
||||
long naxes[3] = {0};
|
||||
|
||||
auto checkError = [&info, &status]()
|
||||
{
|
||||
char err[100];
|
||||
fits_get_errstatus(status, err);
|
||||
info.info.append({QObject::tr("Error"), QString(err)});
|
||||
qDebug() << "Failed to load FITS file" << err;
|
||||
return false;
|
||||
};
|
||||
|
||||
fits_open_diskfile(&file, path.toLocal8Bit().data(), READONLY, &status);
|
||||
if(status)return checkError();
|
||||
fits_get_num_hdus(file, &num, &status);
|
||||
if(status)return checkError();
|
||||
|
||||
int hdutype;
|
||||
int imgtype;
|
||||
int naxis;
|
||||
std::vector<int> imageIdxs;
|
||||
for(int i = 1; i <= num; i++)
|
||||
{
|
||||
fits_movabs_hdu(file, i, &hdutype, &status);if(status)return checkError();
|
||||
if(hdutype == IMAGE_HDU)
|
||||
{
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);if(status)return checkError();
|
||||
if(naxis >= 2 && naxis <= 3)imageIdxs.push_back(i);
|
||||
}
|
||||
}
|
||||
info.num = imageIdxs.size();
|
||||
info.index = index;
|
||||
|
||||
if(index >= imageIdxs.size())return false;
|
||||
|
||||
fits_movabs_hdu(file, imageIdxs[index], &hdutype, &status);if(status)return checkError();
|
||||
if(hdutype == IMAGE_HDU)
|
||||
{
|
||||
naxes[0] = naxes[1] = naxes[2] = 0;
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);if(status)return checkError();
|
||||
fits_get_img_equivtype(file, &imgtype, &status);if(status)return checkError();
|
||||
|
||||
if(hdutype == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
||||
{
|
||||
RawImage::DataType type;
|
||||
int fitstype;
|
||||
long fpixel[3] = {1,1,1};
|
||||
switch(imgtype)
|
||||
{
|
||||
case BYTE_IMG:
|
||||
type = RawImage::UINT8;
|
||||
fitstype = TBYTE;
|
||||
break;
|
||||
case SHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TSHORT;
|
||||
break;
|
||||
case USHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TUSHORT;
|
||||
break;
|
||||
case LONG_IMG:
|
||||
type = RawImage::UINT32;
|
||||
fitstype = TINT;
|
||||
break;
|
||||
case ULONG_IMG:
|
||||
type = RawImage::UINT32;
|
||||
fitstype = TUINT;
|
||||
break;
|
||||
case FLOAT_IMG:
|
||||
type = RawImage::FLOAT32;
|
||||
fitstype = TFLOAT;
|
||||
break;
|
||||
case DOUBLE_IMG:
|
||||
type = RawImage::FLOAT64;
|
||||
fitstype = TDOUBLE;
|
||||
break;
|
||||
default:
|
||||
info.info.append({QObject::tr("Error"), QObject::tr("Unsupported sample format")});
|
||||
goto noload;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t size = naxes[0]*naxes[1];
|
||||
size_t w = naxes[0];
|
||||
size_t h = naxes[1];
|
||||
|
||||
info.info.append({QObject::tr("Width"), QString::number(naxes[0])});
|
||||
info.info.append({QObject::tr("Height"), QString::number(naxes[1])});
|
||||
|
||||
RawImage img(w, h, naxis == 2 ? 1 : naxes[2], type);
|
||||
uint8_t *data = static_cast<uint8_t*>(img.data());
|
||||
for (int i=1; i==1 || i<=naxes[2]; i++)
|
||||
{
|
||||
fpixel[2] = i;
|
||||
fits_read_pix(file, fitstype, fpixel, size, NULL, data + img.size() * RawImage::typeSize(type) * (i-1), NULL, &status);
|
||||
if(status)return checkError();
|
||||
}
|
||||
if(fitstype == TSHORT)
|
||||
{
|
||||
uint16_t *s = static_cast<uint16_t*>(img.data());
|
||||
size_t size = img.size() * img.channels();
|
||||
for(size_t i=0; i<size; i++)
|
||||
s[i] -= INT16_MIN;
|
||||
}
|
||||
else if(fitstype == TINT)
|
||||
{
|
||||
uint32_t *s = static_cast<uint32_t*>(img.data());
|
||||
size_t size = img.size() * img.channels();
|
||||
for(size_t i=0; i<size; i++)
|
||||
s[i] -= INT32_MIN;
|
||||
}
|
||||
|
||||
if(img.channels() == 1 || planar)
|
||||
image = std::make_shared<RawImage>(std::move(img));
|
||||
else
|
||||
image = RawImage::fromPlanar(img);
|
||||
}
|
||||
}
|
||||
noload:
|
||||
if(file)
|
||||
{
|
||||
status = loadFITSHeader(file, info);
|
||||
if(status)return checkError();
|
||||
}
|
||||
|
||||
if(image)
|
||||
{
|
||||
for(auto fits : info.fitsHeader)
|
||||
{
|
||||
if(fits.key == "ROWORDER" && fits.value == "BOTTOM-UP")
|
||||
image->flip();
|
||||
}
|
||||
}
|
||||
|
||||
fits_close_file(file, &status);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadXISF(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &image, bool planar, uint32_t index)
|
||||
{
|
||||
try
|
||||
{
|
||||
LibXISF::XISFReader xisf;
|
||||
xisf.open(path.toLocal8Bit().data());
|
||||
|
||||
if(index >= (uint32_t)xisf.imagesCount())return false;
|
||||
const LibXISF::Image &xisfImage = xisf.getImage(index);
|
||||
|
||||
auto fitskeywords = xisfImage.fitsKeywords();
|
||||
for(auto fits : fitskeywords)
|
||||
{
|
||||
info.fitsHeader.append(fits);
|
||||
}
|
||||
auto imageproperties = xisfImage.imageProperties();
|
||||
for(auto prop : imageproperties)
|
||||
{
|
||||
info.fitsHeader.append(prop);
|
||||
}
|
||||
|
||||
info.num = xisf.imagesCount();
|
||||
info.index = index;
|
||||
info.wcs = std::make_shared<WCSDataT>(xisfImage.width(), xisfImage.height(), info.fitsHeader);
|
||||
info.info.append({QObject::tr("Width"), QString::number(xisfImage.width())});
|
||||
info.info.append({QObject::tr("Height"), QString::number(xisfImage.height())});
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
|
||||
RawImage::DataType type;
|
||||
switch(xisfImage.sampleFormat())
|
||||
{
|
||||
case LibXISF::Image::UInt8: type = RawImage::UINT8; break;
|
||||
case LibXISF::Image::UInt16: type = RawImage::UINT16; break;
|
||||
case LibXISF::Image::UInt32: type = RawImage::UINT32; break;
|
||||
case LibXISF::Image::Float32: type = RawImage::FLOAT32; break;
|
||||
case LibXISF::Image::Float64: type = RawImage::FLOAT64; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
LibXISF::Image tmpImage = xisfImage;
|
||||
tmpImage.convertPixelStorageTo(LibXISF::Image::Planar);
|
||||
if(tmpImage.colorSpace() == LibXISF::Image::ColorSpace::Gray)
|
||||
{
|
||||
image = std::make_shared<RawImage>(tmpImage.width(), tmpImage.height(), 1, type);
|
||||
std::memcpy(image->data(), tmpImage.imageData(), tmpImage.imageDataSize() / tmpImage.channelCount());
|
||||
image->setICCProfile(tmpImage.iccProfile());
|
||||
return true;
|
||||
}
|
||||
else if(tmpImage.channelCount() == 3 || tmpImage.channelCount() == 4)
|
||||
{
|
||||
if(planar)
|
||||
{
|
||||
image = std::make_shared<RawImage>(tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type);
|
||||
std::memcpy(image->data(), tmpImage.imageData(), tmpImage.imageDataSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
image = RawImage::fromPlanar(tmpImage.imageData(), tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type);
|
||||
}
|
||||
|
||||
image->setICCProfile(tmpImage.iccProfile());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (LibXISF::Error &err)
|
||||
{
|
||||
info.info.append(QPair<QString, QString>("Error", err.what()));
|
||||
qDebug() << "Failed to load XISF" << err.what();
|
||||
return false;
|
||||
}
|
||||
info.info.append({QObject::tr("Error"), QObject::tr("Unsupported sample format")});
|
||||
return false;
|
||||
}
|
||||
|
||||
bool readFITSHeader(const QString &path, ImageInfoData &info)
|
||||
{
|
||||
fitsfile *fr;
|
||||
int status = 0;
|
||||
QString path2 = makeUNCPath(path);
|
||||
fits_open_diskfile(&fr, path2.toLocal8Bit().data(), READONLY, &status);
|
||||
|
||||
if(fr && status == 0)
|
||||
{
|
||||
status = loadFITSHeader(fr, info);
|
||||
fits_close_file(fr, &status);
|
||||
}
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
bool readXISFHeader(const QString &path, ImageInfoData &info)
|
||||
{
|
||||
QString path2 = makeUNCPath(path);
|
||||
try
|
||||
{
|
||||
LibXISF::XISFReader xisf;
|
||||
xisf.open(path2.toLocal8Bit().data());
|
||||
const LibXISF::Image &image = xisf.getImage(0, false);
|
||||
|
||||
auto fitskeywords = image.fitsKeywords();
|
||||
for(auto fits : fitskeywords)
|
||||
{
|
||||
info.fitsHeader.append(fits);
|
||||
}
|
||||
|
||||
auto imageproperties = image.imageProperties();
|
||||
for(auto prop : imageproperties)
|
||||
{
|
||||
info.fitsHeader.append(prop);
|
||||
}
|
||||
info.wcs = std::make_shared<WCSDataT>(image.width(), image.height(), info.fitsHeader);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
}
|
||||
catch (LibXISF::Error &err)
|
||||
{
|
||||
qDebug() << err.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void loadExifEntry(ImageInfoData &info, ExifContent *content, ExifTag tag)
|
||||
{
|
||||
char val[1024];
|
||||
ExifEntry *entry = exif_content_get_entry(content, tag);
|
||||
if(entry)
|
||||
{
|
||||
exif_entry_get_value(entry, val, sizeof(val));
|
||||
info.info.append({exif_tag_get_title(tag), val});
|
||||
}
|
||||
}
|
||||
|
||||
bool loadRAW(const QString path, ImageInfoData &info, std::shared_ptr<RawImage> &image)
|
||||
{
|
||||
std::unique_ptr<LibRaw> raw = std::make_unique<LibRaw>();
|
||||
raw->open_file(path.toLocal8Bit().data());
|
||||
raw->imgdata.params.half_size = true;
|
||||
raw->imgdata.params.use_camera_wb = true;
|
||||
raw->imgdata.params.user_flip = 0;
|
||||
if(raw->unpack())
|
||||
return false;
|
||||
|
||||
|
||||
libraw_rawdata_t rawdata = raw->imgdata.rawdata;
|
||||
size_t size = rawdata.sizes.width*rawdata.sizes.height;
|
||||
|
||||
std::vector<uint16_t> out;
|
||||
out.resize(size);
|
||||
size_t d = 0;
|
||||
uint h=rawdata.sizes.top_margin+rawdata.sizes.height;
|
||||
uint w=rawdata.sizes.left_margin+rawdata.sizes.width;
|
||||
size_t pitch = rawdata.sizes.raw_pitch/sizeof(uint16_t);
|
||||
|
||||
for(size_t i=rawdata.sizes.top_margin;i<h;i++)
|
||||
{
|
||||
for(size_t o=rawdata.sizes.left_margin;o<w;o++)
|
||||
{
|
||||
uint16_t p = rawdata.raw_image[i*pitch+o];
|
||||
out[d++] = p;
|
||||
}
|
||||
}
|
||||
image = std::make_shared<RawImage>(rawdata.sizes.width, rawdata.sizes.height, 1, RawImage::UINT16);
|
||||
memcpy(image->data(), &out[0], sizeof(uint16_t)*d);
|
||||
|
||||
QString shutterSpeed = QString::number(raw->imgdata.other.shutter);
|
||||
if(raw->imgdata.other.shutter < 1)
|
||||
{
|
||||
shutterSpeed = QString("1/%1s").arg(1.0f/raw->imgdata.other.shutter);
|
||||
}
|
||||
info.info.append({QObject::tr("Width"), QString::number(raw->imgdata.sizes.width)});
|
||||
info.info.append({QObject::tr("Height"), QString::number(raw->imgdata.sizes.height)});
|
||||
info.info.append({QObject::tr("ISO"), QString::number(raw->imgdata.other.iso_speed)});
|
||||
info.info.append({QObject::tr("Shutter speed"), shutterSpeed});
|
||||
#if LIBRAW_MINOR_VERSION>=19
|
||||
// info.append(StringPair(QObject::tr("Camera temperature"), QString::number(raw.imgdata.other.CameraTemperature)));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &rawImage, int index, bool planar)
|
||||
{
|
||||
bool ret = false;
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
if(path.endsWith(".CR2", Qt::CaseInsensitive) || path.endsWith(".CR3", Qt::CaseInsensitive) || path.endsWith(".NEF", Qt::CaseInsensitive) || path.endsWith(".DNG", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadRAW(path, info, rawImage);
|
||||
qDebug() << "LoadRAW" << timer.elapsed();
|
||||
}
|
||||
else if(path.endsWith(".FIT", Qt::CaseInsensitive) || path.endsWith(".FITS", Qt::CaseInsensitive) || path.endsWith(".FZ", Qt::CaseInsensitive) || path.endsWith(".FTS", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadFITS(path, info, rawImage, planar, index);
|
||||
qDebug() << "LoadFITS" << timer.elapsed();
|
||||
}
|
||||
else if(path.endsWith(".XISF", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadXISF(path, info, rawImage, planar, index);
|
||||
qDebug() << "LoadXISF" << timer.elapsed();
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage img(path);
|
||||
|
||||
ExifData *exif = exif_data_new_from_file(path.toLocal8Bit().constData());
|
||||
info.info.append({QObject::tr("Width"), QString::number(img.width())});
|
||||
info.info.append({QObject::tr("Height"), QString::number(img.height())});
|
||||
if(exif)
|
||||
{
|
||||
loadExifEntry(info, exif->ifd[EXIF_IFD_EXIF], EXIF_TAG_ISO_SPEED_RATINGS);
|
||||
loadExifEntry(info, exif->ifd[EXIF_IFD_EXIF], EXIF_TAG_SHUTTER_SPEED_VALUE);
|
||||
exif_data_free(exif);
|
||||
}
|
||||
rawImage = std::make_shared<RawImage>(img);
|
||||
qDebug() << "LoadQImage" << timer.elapsed();
|
||||
ret = !img.isNull();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef LOADIMAGE_H
|
||||
#define LOADIMAGE_H
|
||||
|
||||
#include <QString>
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class RawImage;
|
||||
|
||||
QString makeUNCPath(const QString &path);
|
||||
bool readFITSHeader(const QString &path, ImageInfoData &info);
|
||||
bool readXISFHeader(const QString &path, ImageInfoData &info);
|
||||
bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &rawImage, int index, bool planar = false);
|
||||
|
||||
#endif // LOADIMAGE_H
|
||||
@@ -0,0 +1,370 @@
|
||||
#include "loadrunable.h"
|
||||
#include "imageringlist.h"
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QElapsedTimer>
|
||||
#include <QDebug>
|
||||
#include <algorithm>
|
||||
#include <fitsio2.h>
|
||||
#include "rawimage.h"
|
||||
#include "loadimage.h"
|
||||
#include <lcms2.h>
|
||||
|
||||
LoadRunable::LoadRunable(const QString &file, Image *receiver, AnalyzeLevel level, int index, bool thumbnail) :
|
||||
m_file(makeUNCPath(file)),
|
||||
m_receiver(receiver),
|
||||
m_analyzeLevel(level),
|
||||
m_thumbnail(thumbnail),
|
||||
m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
void LoadRunable::run()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!m_thumbnail && !m_receiver->isCurrent())
|
||||
{
|
||||
return;
|
||||
}
|
||||
QElapsedTimer timer;
|
||||
ImageInfoData info;
|
||||
QFileInfo finfo(m_file);
|
||||
info.info.append({QObject::tr("Filename"), finfo.fileName()});
|
||||
|
||||
std::shared_ptr<RawImage> rawImage;
|
||||
if(!loadImage(m_file, info, rawImage, m_index))
|
||||
info.info.append({QObject::tr("Error"), QObject::tr("Failed to load image")});
|
||||
|
||||
|
||||
if(rawImage && !m_thumbnail)
|
||||
{
|
||||
rawImage->convertToGLFormat();
|
||||
timer.start();
|
||||
rawImage->generateLUT();
|
||||
qDebug() << "generate LUT" << timer.restart();
|
||||
//rawImage->convertTosRGB();
|
||||
//qDebug() << "convert" << timer.restart();
|
||||
rawImage->calcStats();
|
||||
const RawImage::Stats &stats = rawImage->imageStats();
|
||||
qDebug() << "image stats" << timer.restart();
|
||||
if(rawImage->channels() == 1)
|
||||
{
|
||||
info.info.append({QObject::tr("Mean"), QString::number(stats.m_mean[0])});
|
||||
info.info.append({QObject::tr("Standart deviation"), QString::number(stats.m_stdDev[0])});
|
||||
info.info.append({QObject::tr("Median"), QString::number(stats.m_median[0])});
|
||||
info.info.append({QObject::tr("Minimum"), QString::number(stats.m_min[0])});
|
||||
info.info.append({QObject::tr("Maximum"), QString::number(stats.m_max[0])});
|
||||
info.info.append({QObject::tr("MAD"), QString::number(stats.m_mad[0])});
|
||||
info.info.append({QObject::tr("Saturated"), QString::number(100.0 * stats.m_saturated[0] / rawImage->size()) + "%"});
|
||||
}
|
||||
else
|
||||
{
|
||||
info.info.append({QObject::tr("Mean"), QString("%1 %2 %3").arg(stats.m_mean[0]).arg(stats.m_mean[1]).arg(stats.m_mean[2])});
|
||||
info.info.append({QObject::tr("Standart deviation"), QString("%1 %2 %3").arg(stats.m_stdDev[0]).arg(stats.m_stdDev[1]).arg(stats.m_stdDev[2])});
|
||||
info.info.append({QObject::tr("Median"), QString("%1 %2 %3").arg(stats.m_median[0]).arg(stats.m_median[1]).arg(stats.m_median[2])});
|
||||
info.info.append({QObject::tr("Minimum"), QString("%1 %2 %3").arg(stats.m_min[0]).arg(stats.m_min[1]).arg(stats.m_min[2])});
|
||||
info.info.append({QObject::tr("Maximum"), QString("%1 %2 %3").arg(stats.m_max[0]).arg(stats.m_max[1]).arg(stats.m_max[2])});
|
||||
info.info.append({QObject::tr("MAD"), QString("%1 %2 %3").arg(stats.m_mad[0]).arg(stats.m_mad[1]).arg(stats.m_mad[2])});
|
||||
info.info.append({QObject::tr("Saturated"), QString("%1 %2 %3%").arg(100.0 * stats.m_saturated[0] / rawImage->size())
|
||||
.arg(100.0 * stats.m_saturated[1] / rawImage->size())
|
||||
.arg(100.0 * stats.m_saturated[2] / rawImage->size())});
|
||||
}
|
||||
}
|
||||
|
||||
if(m_thumbnail)
|
||||
{
|
||||
if(rawImage && rawImage->valid())
|
||||
{
|
||||
if(QUALITY_RESIZE)
|
||||
rawImage->resize(THUMB_SIZE, THUMB_SIZE);
|
||||
|
||||
rawImage->convertToGLFormat();
|
||||
rawImage->convertToThumbnail();
|
||||
}
|
||||
QMetaObject::invokeMethod(m_receiver, "thumbnailLoadFinish", Qt::QueuedConnection, Q_ARG(std::shared_ptr<RawImage>, rawImage));
|
||||
}
|
||||
else
|
||||
{
|
||||
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(std::shared_ptr<RawImage>, rawImage), Q_ARG(ImageInfoData, info));
|
||||
}
|
||||
}
|
||||
catch(std::exception e)
|
||||
{
|
||||
qDebug() << m_file << e.what();
|
||||
std::shared_ptr<RawImage> rawImage;
|
||||
if(m_thumbnail)
|
||||
QMetaObject::invokeMethod(m_receiver, "thumbnailLoadFinish", Qt::QueuedConnection, Q_ARG(std::shared_ptr<RawImage>, rawImage));
|
||||
else
|
||||
QMetaObject::invokeMethod(m_receiver, "imageLoaded", Qt::QueuedConnection, Q_ARG(std::shared_ptr<RawImage>, rawImage), Q_ARG(ImageInfoData, ImageInfoData()));
|
||||
}
|
||||
}
|
||||
|
||||
ConvertRunable::ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms, QSemaphore *semaphore) :
|
||||
m_infile(makeUNCPath(in)),
|
||||
m_outfile(makeUNCPath(out)),
|
||||
m_format(format),
|
||||
m_params(params),
|
||||
m_semaphore(semaphore)
|
||||
{
|
||||
}
|
||||
|
||||
void writeFITSImage(fitsfile *fw, std::shared_ptr<RawImage> rawimage, ImageInfoData &imageinfo)
|
||||
{
|
||||
static QStringList skipKeys = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "BZERO", "BSCALE", "EXTEND"};
|
||||
|
||||
int status = 0;
|
||||
long firstpix[3] = {1,1,1};
|
||||
|
||||
int channels = rawimage->channels();
|
||||
int naxis = channels == 1 ? 2 : 3;
|
||||
long naxes[3] = {(int)rawimage->width(), (int)rawimage->height(), rawimage->channels()};
|
||||
|
||||
std::vector<RawImage> planes;
|
||||
if(channels == 1)
|
||||
planes.push_back(*rawimage);
|
||||
else
|
||||
planes = rawimage->split();
|
||||
|
||||
switch(rawimage->type())
|
||||
{
|
||||
case RawImage::UINT8:
|
||||
fits_create_img(fw, BYTE_IMG, naxis, naxes, &status);
|
||||
for(int i=0; i<channels; i++)
|
||||
{
|
||||
firstpix[2] = i+1;
|
||||
fits_write_pix(fw, TBYTE, firstpix, rawimage->size(), planes[i].data(), &status);
|
||||
}
|
||||
break;
|
||||
case RawImage::UINT16:
|
||||
fits_create_img(fw, USHORT_IMG, naxis, naxes, &status);
|
||||
for(int i=0; i<channels; i++)
|
||||
{
|
||||
firstpix[2] = i+1;
|
||||
fits_write_pix(fw, TUSHORT, firstpix, rawimage->size(), planes[i].data(), &status);
|
||||
}
|
||||
break;
|
||||
case RawImage::FLOAT32:
|
||||
fits_create_img(fw, FLOAT_IMG, naxis, naxes, &status);
|
||||
for(int i=0; i<channels; i++)
|
||||
{
|
||||
firstpix[2] = i+1;
|
||||
fits_write_pix(fw, TFLOAT, firstpix, rawimage->size(), planes[i].data(), &status);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
for(const FITSRecord &record : imageinfo.fitsHeader)
|
||||
{
|
||||
if(skipKeys.contains(record.key) || record.xisf)continue;
|
||||
|
||||
bool isdouble;
|
||||
bool isint;
|
||||
bool isbool = record.value.toString() == "T" || record.value.toString() == "F";
|
||||
double vald = record.value.toDouble(&isdouble);
|
||||
int valb = record.value.toString() == "T";
|
||||
long long vall = record.value.toLongLong(&isint);
|
||||
if(isint)isint = vall == vald;
|
||||
QByteArray str = record.value.toString().toLatin1();
|
||||
if(isint)
|
||||
fits_write_key(fw, TLONGLONG, record.key.data(), &vall, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
else if(isdouble)
|
||||
fits_write_key(fw, TDOUBLE, record.key.data(), &vald, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
else if(isbool)
|
||||
fits_write_key(fw, TLOGICAL, record.key.data(), &valb, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
else if(record.key == "COMMENT")
|
||||
fits_write_comment(fw, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
else if(record.key == "HISTORY")
|
||||
fits_write_history(fw, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
else
|
||||
fits_write_key(fw, TSTRING, record.key.data(), str.isEmpty() ? nullptr : str.data(), record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertRunable::run()
|
||||
{
|
||||
QSemaphoreReleaser release;
|
||||
if(m_semaphore)release = QSemaphoreReleaser(m_semaphore);
|
||||
|
||||
ImageInfoData imageinfo;
|
||||
std::shared_ptr<RawImage> rawimage;
|
||||
loadImage(m_infile, imageinfo, rawimage, 0);
|
||||
QFileInfo info(m_outfile);
|
||||
info.dir().mkpath(".");
|
||||
|
||||
if(m_params.autostretch)
|
||||
{
|
||||
rawimage->calcStats();
|
||||
MTFParam mtfParam = rawimage->calcMTFParams();
|
||||
rawimage->applySTF(mtfParam);
|
||||
}
|
||||
if(m_params.binning > 1)
|
||||
{
|
||||
rawimage->resizeInt(m_params.binning, m_params.average);
|
||||
}
|
||||
if(m_params.resize.isValid() && !m_params.resize.isEmpty())
|
||||
{
|
||||
QSize imgSize(rawimage->width(), rawimage->height());
|
||||
imgSize = imgSize.scaled(m_params.resize, m_params.aspect);
|
||||
rawimage->resize(imgSize.width(), imgSize.height());
|
||||
}
|
||||
|
||||
if(rawimage)
|
||||
{
|
||||
if(m_format == "xisf")
|
||||
{
|
||||
try
|
||||
{
|
||||
LibXISF::XISFWriter xisf;
|
||||
int channelCount = rawimage->channels();
|
||||
LibXISF::Image::SampleFormat sampleFormat;
|
||||
switch(rawimage->type())
|
||||
{
|
||||
case RawImage::UINT8: sampleFormat = LibXISF::Image::UInt8; break;
|
||||
case RawImage::UINT16: sampleFormat = LibXISF::Image::UInt16; break;
|
||||
case RawImage::FLOAT32: sampleFormat = LibXISF::Image::Float32; break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
LibXISF::Image image(rawimage->width(), rawimage->height(), channelCount, sampleFormat, channelCount == 1 ? LibXISF::Image::Gray : LibXISF::Image::RGB, LibXISF::Image::Planar);
|
||||
if(channelCount == 1)
|
||||
{
|
||||
std::memcpy(image.imageData(), rawimage->data(), image.imageDataSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t off = 0;
|
||||
std::vector<RawImage> planes = rawimage->split();
|
||||
for(const auto &plane : planes)
|
||||
{
|
||||
std::memcpy(image.imageData<uint8_t>() + off, plane.data(), plane.size() * RawImage::typeSize(plane.type()));
|
||||
off += plane.size() * RawImage::typeSize(plane.type());
|
||||
}
|
||||
}
|
||||
for(auto &record : imageinfo.fitsHeader)
|
||||
{
|
||||
if(record.xisf)continue;
|
||||
|
||||
if(record.value.typeId() == QMetaType::Bool)
|
||||
image.addFITSKeyword({record.key.toStdString(), record.value.toBool() ? "T" : "F", record.comment.toStdString()});
|
||||
else
|
||||
image.addFITSKeyword({record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()});
|
||||
}
|
||||
|
||||
if(m_params.compressionType.startsWith("zstd") && LibXISF::DataBlock::CompressionCodecSupported(LibXISF::DataBlock::ZSTD))
|
||||
image.setCompression(LibXISF::DataBlock::ZSTD, m_params.compressionLevel);
|
||||
else if(m_params.compressionType.startsWith("lz4hc"))
|
||||
image.setCompression(LibXISF::DataBlock::LZ4HC, m_params.compressionLevel);
|
||||
else if(m_params.compressionType.startsWith("lz4"))
|
||||
image.setCompression(LibXISF::DataBlock::LZ4, m_params.compressionLevel);
|
||||
else if(m_params.compressionType.startsWith("zlib"))
|
||||
image.setCompression(LibXISF::DataBlock::Zlib, m_params.compressionLevel);
|
||||
|
||||
if(m_params.compressionType.endsWith("+sh"))
|
||||
image.setByteshuffling(true);
|
||||
|
||||
xisf.writeImage(image);
|
||||
xisf.save(m_outfile.toLocal8Bit().data());
|
||||
}
|
||||
catch(LibXISF::Error &err)
|
||||
{
|
||||
qDebug() << "Failed to save XISF image" << err.what();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_format == "fits")
|
||||
{
|
||||
int status = 0;
|
||||
fitsfile *fw;
|
||||
if(QFileInfo(m_outfile).exists())QFile::remove(m_outfile);
|
||||
fits_create_diskfile(&fw, m_outfile.toLocal8Bit().data(), &status);
|
||||
if(!m_params.compressionType.isEmpty())
|
||||
{
|
||||
if(m_params.compressionType == "gzip")
|
||||
fits_set_compression_type(fw, GZIP_1, &status);
|
||||
else if(m_params.compressionType == "rice")
|
||||
fits_set_compression_type(fw, RICE_1, &status);
|
||||
}
|
||||
writeFITSImage(fw, rawimage, imageinfo);
|
||||
fits_close_file(fw, &status);
|
||||
return;
|
||||
}
|
||||
|
||||
// if nothing else try QImage
|
||||
{
|
||||
QImage::Format format = QImage::Format_Invalid;
|
||||
|
||||
switch(rawimage->type())
|
||||
{
|
||||
case RawImage::UINT8:
|
||||
if(rawimage->channels() == 1)format = QImage::Format_Grayscale8;
|
||||
else if(rawimage->channels() == 3)format = QImage::Format_RGBX8888;
|
||||
else if(rawimage->channels() == 4)format = QImage::Format_RGBA8888;
|
||||
break;
|
||||
case RawImage::UINT16:
|
||||
if(rawimage->channels() == 1)format = QImage::Format_Grayscale16;
|
||||
else if(rawimage->channels() == 3)format = QImage::Format_RGBX64;
|
||||
else if(rawimage->channels() == 4)format = QImage::Format_RGBA64;
|
||||
break;
|
||||
case RawImage::FLOAT16:
|
||||
case RawImage::FLOAT32:
|
||||
case RawImage::FLOAT64:
|
||||
case RawImage::UINT32:
|
||||
rawimage->convertToType(RawImage::UINT16);
|
||||
if(rawimage->channels() == 1)format = QImage::Format_Grayscale16;
|
||||
else if(rawimage->channels() == 3)format = QImage::Format_RGBX64;
|
||||
else if(rawimage->channels() == 4)format = QImage::Format_RGBA64;
|
||||
break;
|
||||
}
|
||||
|
||||
if(format == QImage::Format_Invalid)return;
|
||||
|
||||
QImage qimage((const uchar*)rawimage->data(), rawimage->width(), rawimage->height(), rawimage->widthBytes(), format);
|
||||
qimage.save(m_outfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConvertRunable::ConvertParams::ConvertParams(const QVariantMap &map)
|
||||
{
|
||||
bool ok = false;
|
||||
if(map.contains("compressionLevel"))
|
||||
compressionLevel = std::clamp(map["compressionLevel"].toInt(&ok), -1, 100);
|
||||
|
||||
if(!ok)compressionLevel = -1;
|
||||
|
||||
if(map.contains("compressionType"))
|
||||
compressionType = map["compressionType"].toString();
|
||||
|
||||
if(map.contains("binning"))
|
||||
binning = map["binning"].toInt();
|
||||
|
||||
if(map.contains("average"))
|
||||
average = map["average"].toBool();
|
||||
|
||||
if(map.contains("resize"))
|
||||
{
|
||||
QVariantMap size = map["resize"].toMap();
|
||||
if(size.contains("width") && size.contains("height"))
|
||||
{
|
||||
int w = size["width"].toInt();
|
||||
int h = size["height"].toInt();
|
||||
resize = QSize(w, h);
|
||||
}
|
||||
if(size.contains("aspect"))
|
||||
{
|
||||
QString aspectStr = map["aspect"].toString();
|
||||
if(aspectStr == "keep")
|
||||
aspect = Qt::KeepAspectRatio;
|
||||
else if(aspectStr == "expand")
|
||||
aspect = Qt::KeepAspectRatioByExpanding;
|
||||
else if(aspectStr == "ignore")
|
||||
aspect = Qt::IgnoreAspectRatio;
|
||||
}
|
||||
}
|
||||
|
||||
if(map.contains("autostretch"))
|
||||
autostretch = map["autostretch"].toBool();
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef LOADRUNABLE_H
|
||||
#define LOADRUNABLE_H
|
||||
|
||||
#include <QRunnable>
|
||||
#include <QString>
|
||||
#include <QSemaphore>
|
||||
#include <QSize>
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class Image;
|
||||
|
||||
class LoadRunable : public QRunnable
|
||||
{
|
||||
QString m_file;
|
||||
Image *m_receiver;
|
||||
AnalyzeLevel m_analyzeLevel;
|
||||
bool m_thumbnail;
|
||||
int m_index = 0;
|
||||
public:
|
||||
LoadRunable(const QString &file, Image *receiver, AnalyzeLevel level, int index, bool thumbnail = false);
|
||||
void run() override;
|
||||
};
|
||||
|
||||
class ConvertRunable : public QRunnable
|
||||
{
|
||||
public:
|
||||
struct ConvertParams
|
||||
{
|
||||
int compressionLevel = -1;
|
||||
QString compressionType;
|
||||
int binning = 0;
|
||||
bool average = true;
|
||||
QSize resize;
|
||||
Qt::AspectRatioMode aspect = Qt::KeepAspectRatio;
|
||||
bool autostretch = false;
|
||||
ConvertParams(){}
|
||||
ConvertParams(const QVariantMap &map);
|
||||
};
|
||||
ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms = ConvertParams(), QSemaphore *semaphore = nullptr);
|
||||
void run() override;
|
||||
private:
|
||||
QString m_infile;
|
||||
QString m_outfile;
|
||||
QString m_format;
|
||||
ConvertParams m_params;
|
||||
QSemaphore *m_semaphore;
|
||||
};
|
||||
|
||||
#endif // LOADRUNABLE_H
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QSurfaceFormat>
|
||||
#include <QTranslator>
|
||||
#include <QCommandLineParser>
|
||||
#include <stdlib.h>
|
||||
#include "../thumbnailer/genthumbnail.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef __linux__
|
||||
setenv("LC_NUMERIC", "C", 1);
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__APPLE__)
|
||||
bool useGLES = false;
|
||||
#else
|
||||
bool useGLES = true;
|
||||
#endif
|
||||
|
||||
QCommandLineParser cmd;
|
||||
cmd.addOption({"gl", "Use desktop OpenGL. This is default on x86 and MacOS platform."});
|
||||
cmd.addOption({"gles", "Use OpenGL ES. This is default on ARM platform."});
|
||||
cmd.addOption({{"thumb", "thumbnail"}, "Generate thumbnail and save it to path.", "path"});
|
||||
cmd.addOption({{"s", "size"}, "Size of the thumbnails in pixels (default: 128)", "size", "128"});
|
||||
cmd.addPositionalArgument("file", "File to open");
|
||||
cmd.addHelpOption();
|
||||
QStringList cmdArgs;
|
||||
for(int i = 0; i < argc; i++)
|
||||
cmdArgs.append(argv[i]);
|
||||
|
||||
cmd.process(cmdArgs);
|
||||
if(cmd.isSet("gl"))
|
||||
useGLES = false;
|
||||
if(cmd.isSet("gles"))
|
||||
useGLES = true;
|
||||
|
||||
if(cmd.isSet("thumb"))
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
QStringList files = cmd.positionalArguments();
|
||||
if(files.size() == 0)
|
||||
return 1;
|
||||
|
||||
QString thumb = cmd.value("thumb");
|
||||
int size = 128;
|
||||
bool ok;
|
||||
int size2 = cmd.value("s").toInt(&ok);
|
||||
if(ok)
|
||||
size = size2;
|
||||
|
||||
return generateThumbnail(files.front(), thumb, size);
|
||||
}
|
||||
|
||||
QSurfaceFormat format;
|
||||
if(useGLES)
|
||||
{
|
||||
format.setMajorVersion(3);
|
||||
format.setMinorVersion(0);
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
}
|
||||
else
|
||||
{
|
||||
format.setMajorVersion(3);
|
||||
format.setMinorVersion(3);
|
||||
//format.setOption(QSurfaceFormat::DebugContext);
|
||||
format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile);
|
||||
}
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
|
||||
QApplication a(argc, argv);
|
||||
a.setOrganizationName("nou");
|
||||
a.setApplicationName("Tenmon");
|
||||
a.setWindowIcon(QIcon(":/space.nouspiro.tenmon.png"));
|
||||
|
||||
QTranslator translator;
|
||||
QTranslator translator2;
|
||||
if(translator.load(QLocale(), "tenmon", "_", ":/translations"))
|
||||
a.installTranslator(&translator);
|
||||
if(translator2.load(QLocale(), "tenmon", "_", a.applicationDirPath()))
|
||||
a.installTranslator(&translator2);
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
if(!cmd.positionalArguments().isEmpty())
|
||||
{
|
||||
QStringList files = cmd.positionalArguments();
|
||||
QStringList paths;
|
||||
for(auto &arg : files)
|
||||
{
|
||||
QUrl url(arg);
|
||||
QFileInfo info(url.isLocalFile() ? url.toLocalFile() : arg);
|
||||
if(info.exists())
|
||||
paths.append(info.canonicalFilePath());
|
||||
}
|
||||
if(paths.size() == 1)
|
||||
w.loadFile(paths.front());
|
||||
else if(paths.size() > 1)
|
||||
w.loadFiles(paths);
|
||||
}
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
@@ -0,0 +1,823 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QScrollArea>
|
||||
#include <QDir>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
#include <QDebug>
|
||||
#include <QDockWidget>
|
||||
#include <QActionGroup>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <QSettings>
|
||||
#include <QGuiApplication>
|
||||
#include <QThreadPool>
|
||||
#include <QStatusBar>
|
||||
#include <QImageReader>
|
||||
#include <QMimeDatabase>
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkReply>
|
||||
#include "loadrunable.h"
|
||||
#include "markedfiles.h"
|
||||
#include "about.h"
|
||||
#include "statusbar.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "histogram.h"
|
||||
#include "batchprocessing.h"
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/btrfs.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
bool moveToTrash(const QString &path);
|
||||
|
||||
int MainWindow::socketPair[2] = {0, 0};
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
{
|
||||
qRegisterMetaType<ImageInfoData>("ImageInfoData");
|
||||
qRegisterMetaType<std::shared_ptr<RawImage>>("std::shared_ptr<RawImage>");
|
||||
|
||||
SettingsDialog::loadSettings();
|
||||
|
||||
QStringList nameFilter;
|
||||
_saveFilter = tr("FITS (*.fits *.fit);;XISF (*.xisf);;");
|
||||
_openFilter = tr("Images (");
|
||||
QMimeDatabase db;
|
||||
auto supportedFormats = QImageReader::supportedMimeTypes();
|
||||
QStringList filters;
|
||||
for(auto format : supportedFormats)
|
||||
{
|
||||
QMimeType mimeType = db.mimeTypeForName(format);
|
||||
_saveFilter.append(mimeType.filterString() + ";;");
|
||||
_openFilter.append("*.");
|
||||
_openFilter.append(mimeType.suffixes().join(" *."));
|
||||
_openFilter.append(" ");
|
||||
nameFilter.append(mimeType.suffixes());
|
||||
}
|
||||
_openFilter.append("*.fit *.fits *.fts *.fz *.xisf *.cr2 *.cr3 *.nef *.dng)");
|
||||
_openFilter.append(tr(";;All files (*)"));
|
||||
nameFilter.append({"fit", "fits", "fts", "fz", "xisf", "cr2", "cr3", "nef", "dng"});
|
||||
QImageReader::setAllocationLimit(0);
|
||||
|
||||
m_info = new ImageInfo(this);
|
||||
QDockWidget *infoDock = new QDockWidget(tr("Image info"), this);
|
||||
infoDock->setWidget(m_info);
|
||||
infoDock->setObjectName("infoDock");
|
||||
addDockWidget(Qt::LeftDockWidgetArea, infoDock);
|
||||
resize(1024, 600);
|
||||
setStatusBar(new QStatusBar(this));
|
||||
|
||||
m_database = new Database(this);
|
||||
if(!m_database->init())
|
||||
QMessageBox::critical(this, tr("Can't open DB"), tr("Can't open SQLITE database"));
|
||||
|
||||
m_image = new ImageScrollArea(m_database, this);
|
||||
setCentralWidget(m_image);
|
||||
|
||||
StatusBar *statusBar = new StatusBar(this);
|
||||
setStatusBar(statusBar);
|
||||
connect(m_image, &ImageScrollArea::status, statusBar, &StatusBar::newStatus);
|
||||
|
||||
m_stretchPanel = new StretchToolbar(this);
|
||||
connect(m_stretchPanel, &StretchToolbar::paramChanged, m_image, &ImageScrollArea::setMTFParams);
|
||||
connect(m_stretchPanel, &StretchToolbar::autoStretch, [&](){ m_stretchPanel->stretchImage(m_ringList->currentImage().get()); });
|
||||
connect(m_stretchPanel, &StretchToolbar::invert, m_image, &ImageScrollArea::invert);
|
||||
connect(m_stretchPanel, &StretchToolbar::superPixel, m_image, &ImageScrollArea::superPixel);
|
||||
connect(m_stretchPanel, &StretchToolbar::falseColor, m_image, &ImageScrollArea::falseColor);
|
||||
|
||||
m_ringList = new ImageRingList(m_database, nameFilter, this);
|
||||
m_filesystem = new FilesystemWidget(m_ringList, this);
|
||||
connect(m_filesystem, &FilesystemWidget::fileSelected, this, static_cast<void (MainWindow::*)(int)>(&MainWindow::loadFile));
|
||||
connect(m_filesystem, &FilesystemWidget::sortChanged, m_ringList, &ImageRingList::setSort);
|
||||
connect(m_filesystem, &FilesystemWidget::reverseSort, m_ringList, &ImageRingList::reverseSort);
|
||||
|
||||
m_filetree = new Filetree(this);
|
||||
connect(m_filetree, &Filetree::fileSelected, this, static_cast<void (MainWindow::*)(const QString &)>(&MainWindow::loadFile));
|
||||
connect(m_filetree, &Filetree::copyFiles, [this](const QString &path){ copyOrMove(true, path); });
|
||||
connect(m_filetree, &Filetree::moveFiles, [this](const QString &path){ copyOrMove(false, path); });
|
||||
connect(m_filetree, &Filetree::indexDirectory, this, static_cast<void (MainWindow::*)(const QString &)>(&MainWindow::indexDir));
|
||||
|
||||
m_databaseView = new DataBaseView(m_database, this);
|
||||
connect(m_databaseView, &DataBaseView::loadFile, this, static_cast<void (MainWindow::*)(const QString &)>(&MainWindow::loadFile));
|
||||
|
||||
#ifdef PLATESOLVER
|
||||
_plateSolving = new PlateSolving(this);
|
||||
addDockWidget(Qt::RightDockWidgetArea, _plateSolving);
|
||||
_plateSolving->hide();
|
||||
#endif
|
||||
|
||||
QToolBar *navigationToolbar = new QToolBar(tr("Navigation toolbar"), this);
|
||||
navigationToolbar->setObjectName("navigationtoolbar");
|
||||
navigationToolbar->hide();
|
||||
QAction *prevAction = navigationToolbar->addAction(style()->standardIcon(QStyle::SP_ArrowLeft), tr("Previous image"));
|
||||
prevAction->setShortcuts({Qt::Key_Left, Qt::Key_Up});
|
||||
QAction *nextAction = navigationToolbar->addAction(style()->standardIcon(QStyle::SP_ArrowRight), tr("Next image"));
|
||||
nextAction->setShortcuts({Qt::Key_Right, Qt::Key_Down});
|
||||
QAction *prevSubAction = navigationToolbar->addAction(style()->standardIcon(QStyle::SP_ArrowUp), tr("Prev sub image"), Qt::Key_PageUp);
|
||||
QAction *nextSubAction = navigationToolbar->addAction(style()->standardIcon(QStyle::SP_ArrowDown), tr("Next sub image"), Qt::Key_PageDown);
|
||||
connect(prevAction, &QAction::triggered, m_ringList, static_cast<void (ImageRingList::*)()>(&ImageRingList::decrement));
|
||||
connect(nextAction, &QAction::triggered, m_ringList, static_cast<void (ImageRingList::*)()>(&ImageRingList::increment));
|
||||
connect(prevSubAction, &QAction::triggered, m_ringList, static_cast<void (ImageRingList::*)()>(&ImageRingList::prevSubImage));
|
||||
connect(nextSubAction, &QAction::triggered, m_ringList, static_cast<void (ImageRingList::*)()>(&ImageRingList::nextSubImage));
|
||||
|
||||
addToolBar(Qt::TopToolBarArea, navigationToolbar);
|
||||
addToolBar(Qt::TopToolBarArea, m_stretchPanel);
|
||||
|
||||
QDockWidget *filesystemDock = new QDockWidget(tr("Filesystem"), this);
|
||||
filesystemDock->setWidget(m_filesystem);
|
||||
filesystemDock->setObjectName("filesystemDock");
|
||||
addDockWidget(Qt::LeftDockWidgetArea, filesystemDock);
|
||||
|
||||
QDockWidget *databaseViewDock = new QDockWidget(tr("FITS/XISF files database"), this);
|
||||
databaseViewDock->setWidget(m_databaseView);
|
||||
databaseViewDock->setObjectName("databaseViewDock");
|
||||
databaseViewDock->hide();
|
||||
addDockWidget(Qt::BottomDockWidgetArea, databaseViewDock);
|
||||
|
||||
QDockWidget *filetreeDock = new QDockWidget(tr("File tree"), this);
|
||||
filetreeDock->setWidget(m_filetree);
|
||||
filetreeDock->setObjectName("filetreeDock");
|
||||
databaseViewDock->hide();
|
||||
addDockWidget(Qt::LeftDockWidgetArea, filetreeDock);
|
||||
|
||||
Histogram *histogram = new Histogram(this);
|
||||
QDockWidget *histogramDock = new QDockWidget(tr("Histogram"), this);
|
||||
histogramDock->setWidget(histogram);
|
||||
histogramDock->setObjectName("histogramDock");
|
||||
histogramDock->hide();
|
||||
addDockWidget(Qt::LeftDockWidgetArea, histogramDock);
|
||||
|
||||
setWindowTitle(tr("Tenmon"));
|
||||
|
||||
connect(m_ringList, &ImageRingList::pixmapLoaded, m_image, &ImageScrollArea::imageLoaded);
|
||||
connect(m_ringList, &ImageRingList::currentImageChanged, this, &MainWindow::updateWindowTitle);
|
||||
connect(m_ringList, &ImageRingList::infoLoaded, m_info, &ImageInfo::setInfo);
|
||||
connect(m_ringList, &ImageRingList::currentImageChanged, m_filesystem, &FilesystemWidget::selectFile);
|
||||
connect(m_ringList, &ImageRingList::thumbnailLoaded, m_image, &ImageScrollArea::thumbnailLoaded);
|
||||
connect(m_ringList, &ImageRingList::pixmapLoaded, m_stretchPanel, &StretchToolbar::imageLoaded);
|
||||
connect(m_ringList, &ImageRingList::pixmapLoaded, histogram, &Histogram::imageLoaded);
|
||||
#ifdef PLATESOLVER
|
||||
connect(m_ringList, &ImageRingList::pixmapLoaded, _plateSolving, &PlateSolving::imageLoaded);
|
||||
connect(_plateSolving, &PlateSolving::headerUpdated, m_ringList, &ImageRingList::reloadImage);
|
||||
#endif
|
||||
connect(m_image, &ImageScrollArea::fileDropped, this, static_cast<void (MainWindow::*)(const QString &)>(&MainWindow::loadFile));
|
||||
|
||||
QMenu *fileMenu = new QMenu(tr("File"), this);
|
||||
fileMenu->addAction(tr("Open"), QKeySequence::Open, this, static_cast<void (MainWindow::*)()>(&MainWindow::loadFile));
|
||||
fileMenu->addAction(tr("Open directory recursively"), this, &MainWindow::loadDir);
|
||||
QAction *saveAs = fileMenu->addAction(tr("Save as"), QKeySequence::Save, this, &MainWindow::saveAs);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(tr("Copy marked files"), Qt::Key_F5, this, &MainWindow::copyMarked);
|
||||
fileMenu->addAction(tr("Move marked files"), Qt::Key_F6, this, &MainWindow::moveMarked);
|
||||
fileMenu->addAction(tr("Move marked files to trash"), QKeySequence::Delete, this, &MainWindow::deleteMarked);
|
||||
fileMenu->addSeparator();
|
||||
fileMenu->addAction(tr("Index directory"), this, static_cast<void (MainWindow::*)()>(&MainWindow::indexDir));
|
||||
fileMenu->addAction(tr("Reindex files"), this, &MainWindow::reindex);
|
||||
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
||||
fileMenu->addAction(tr("Batch processing"), Qt::Key_B | Qt::CTRL, [this](){
|
||||
BatchProcessing *batchProcessing = new BatchProcessing(m_database, this);
|
||||
batchProcessing->exec();
|
||||
delete batchProcessing;
|
||||
});
|
||||
fileMenu->addSeparator();
|
||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, &MainWindow::liveMode);
|
||||
liveModeAction->setCheckable(true);
|
||||
QAction *exitAction = fileMenu->addAction(tr("Exit"), this, &MainWindow::close);
|
||||
exitAction->setShortcut(QKeySequence::Quit);
|
||||
menuBar()->addMenu(fileMenu);
|
||||
|
||||
QMenu *editMenu = new QMenu(tr("Edit"), this);
|
||||
editMenu->addAction(tr("Settings"), this, &MainWindow::showSettingsDialog);
|
||||
menuBar()->addMenu(editMenu);
|
||||
|
||||
QMenu *navigationMenu = new QMenu(tr("Navigation"), this);
|
||||
navigationMenu->addAction(prevAction);
|
||||
navigationMenu->addAction(nextAction);
|
||||
navigationMenu->addAction(prevSubAction);
|
||||
navigationMenu->addAction(nextSubAction);
|
||||
menuBar()->addMenu(navigationMenu);
|
||||
|
||||
QMenu *viewMenu = new QMenu(tr("View"), this);
|
||||
viewMenu->addAction(tr("Zoom In"), QKeySequence::ZoomIn, m_image, &ImageScrollArea::zoomIn);
|
||||
viewMenu->addAction(tr("Zoom Out"), QKeySequence::ZoomOut, m_image, &ImageScrollArea::zoomOut);
|
||||
viewMenu->addAction(tr("Best Fit"), QKeySequence("Ctrl+1"), m_image, &ImageScrollArea::bestFit);
|
||||
viewMenu->addAction(tr("100%"), QKeySequence("Ctrl+0"), m_image, &ImageScrollArea::oneToOne);
|
||||
viewMenu->addSeparator();
|
||||
QMenu *bayerMenu = viewMenu->addMenu(tr("Bayer mask"));
|
||||
QActionGroup *bayerActionGroup = new QActionGroup(this);
|
||||
QAction *rggbAction = bayerActionGroup->addAction(tr("RGGB"));//0 0
|
||||
QAction *grbgAction = bayerActionGroup->addAction(tr("GRBG"));//1 0
|
||||
QAction *gbrgAction = bayerActionGroup->addAction(tr("GBRG"));//0 1
|
||||
QAction *bggrAction = bayerActionGroup->addAction(tr("BGGR"));//1 1
|
||||
rggbAction->setCheckable(true); rggbAction->setData(0); rggbAction->setIcon(QIcon(":/bayer.png"));
|
||||
grbgAction->setCheckable(true); grbgAction->setData(1); grbgAction->setIcon(QIcon(":/grbg.png"));
|
||||
gbrgAction->setCheckable(true); gbrgAction->setData(2); gbrgAction->setIcon(QIcon(":/gbrg.png"));
|
||||
bggrAction->setCheckable(true); bggrAction->setData(3); bggrAction->setIcon(QIcon(":/bggr.png"));
|
||||
bayerMenu->addActions({rggbAction, grbgAction, gbrgAction, bggrAction});
|
||||
viewMenu->addMenu(bayerMenu);
|
||||
connect(bayerActionGroup, &QActionGroup::triggered, [this](QAction *action){
|
||||
int data = action->data().toInt();
|
||||
m_image->setBayerMask(data);
|
||||
QSettings settings;
|
||||
settings.setValue("mainwindow/bayermask", data);
|
||||
});
|
||||
|
||||
QStringList colormaps = {"Autumn", "Bone", "Jet", "Winter", "Rainbow", "Ocean", "Summer", "Spring", "Cool", "HSV", "Pink", "Hot", "Parula", "Magma",
|
||||
"Inferno", "Plasma", "Viridis", "Cividis", "Twilight", "Twilight shifted", "Turbo", "Deepgreen"};
|
||||
QMenu *colormapMenu = viewMenu->addMenu(tr("Colormap"));
|
||||
QActionGroup *colormapActionGroup = new QActionGroup(this);
|
||||
|
||||
QImage cmImg = ImageWidget::loadColormap();
|
||||
for(int i=0; i<cmImg.height(); i++)
|
||||
{
|
||||
QImage icon = cmImg.copy(0, i, cmImg.width(), 1).scaled(32, 32);
|
||||
QAction *action = colormapActionGroup->addAction(i < colormaps.size() ? colormaps[i] : tr("User %1").arg(i - colormaps.size() + 1));
|
||||
action->setIcon(QPixmap::fromImage(icon));
|
||||
action->setCheckable(true); action->setData(i);
|
||||
colormapMenu->addAction(action);
|
||||
}
|
||||
viewMenu->addMenu(colormapMenu);
|
||||
connect(colormapActionGroup, &QActionGroup::triggered, [this](QAction *action){
|
||||
int data = action->data().toInt();
|
||||
m_image->setColormap(data);
|
||||
QSettings settings;
|
||||
settings.setValue("mainwindow/colormap", data);
|
||||
});
|
||||
|
||||
QAction *thumbnailsAction = viewMenu->addAction(tr("Thumbnails"), Qt::Key_F2, [this](bool checked){
|
||||
if(SettingsDialog::loadThumbsizes())m_ringList->clearThumbnails();
|
||||
m_image->allocateThumbnails(m_ringList->imageNames());
|
||||
m_image->showThumbnail(checked);
|
||||
if(checked)m_ringList->loadThumbnails();
|
||||
else m_ringList->stopLoading();
|
||||
});
|
||||
thumbnailsAction->setCheckable(true);
|
||||
QAction *slideshowAction = viewMenu->addAction(tr("Slideshow"), Qt::Key_F3, m_ringList, &ImageRingList::toggleSlideshow);
|
||||
slideshowAction->setCheckable(true);
|
||||
viewMenu->addSeparator();
|
||||
auto actionList = m_stretchPanel->actions();
|
||||
actionList.removeFirst();
|
||||
viewMenu->addActions(actionList);
|
||||
menuBar()->addMenu(viewMenu);
|
||||
|
||||
QMenu *selectMenu = new QMenu(tr("Select"), this);
|
||||
selectMenu->addAction(tr("Mark"), Qt::Key_F7, this, &MainWindow::markImage);
|
||||
selectMenu->addAction(tr("Unmark"), Qt::Key_F8, this, &MainWindow::unmarkImage);
|
||||
selectMenu->addSeparator();
|
||||
selectMenu->addAction(tr("Mark and next"), Qt::Key_M, this, &MainWindow::markAndNext);
|
||||
selectMenu->addAction(tr("Unmark and next"), Qt::Key_X, this, &MainWindow::unmarkAndNext);
|
||||
selectMenu->addSeparator();
|
||||
selectMenu->addAction(tr("Show marked list"), this, &MainWindow::showMarkFilesDialog);
|
||||
QAction *openMarked = selectMenu->addAction(tr("Open marked"), m_ringList, &ImageRingList::setMarked);
|
||||
menuBar()->addMenu(selectMenu);
|
||||
fileMenu->insertAction(saveAs, openMarked);
|
||||
|
||||
/*QMenu *analyzeMenu = new QMenu(tr("Analyze"), this);
|
||||
QActionGroup *analyzeGroup = new QActionGroup(this);
|
||||
connect(analyzeGroup, &QActionGroup::triggered, [](QAction* action) {
|
||||
static QAction* lastAction = nullptr;
|
||||
if(action == lastAction)
|
||||
{
|
||||
action->setChecked(false);
|
||||
lastAction = nullptr;
|
||||
}
|
||||
else
|
||||
lastAction = action;
|
||||
});
|
||||
|
||||
QAction *statsAction = analyzeGroup->addAction(tr("Image statistics"));
|
||||
QAction *peakAction = analyzeGroup->addAction(tr("Peak finder"));
|
||||
QAction *starAction = analyzeGroup->addAction(tr("Star finder"));
|
||||
statsAction->setCheckable(true);
|
||||
peakAction->setCheckable(true);
|
||||
starAction->setCheckable(true);
|
||||
connect(statsAction, SIGNAL(toggled(bool)), this, SLOT(imageStats(bool)));
|
||||
connect(peakAction, SIGNAL(toggled(bool)), this, SLOT(peakFinder(bool)));
|
||||
connect(starAction, SIGNAL(toggled(bool)), this, SLOT(starFinder(bool)));
|
||||
analyzeMenu->addActions({statsAction, peakAction, starAction});
|
||||
menuBar()->addMenu(analyzeMenu);*/
|
||||
|
||||
QMenu *dockMenu = new QMenu(tr("Docks"), this);
|
||||
dockMenu->addAction(infoDock->toggleViewAction());
|
||||
dockMenu->addAction(m_stretchPanel->toggleViewAction());
|
||||
dockMenu->addAction(navigationToolbar->toggleViewAction());
|
||||
dockMenu->addAction(filesystemDock->toggleViewAction());
|
||||
dockMenu->addAction(databaseViewDock->toggleViewAction());
|
||||
dockMenu->addAction(filetreeDock->toggleViewAction());
|
||||
dockMenu->addAction(histogramDock->toggleViewAction());
|
||||
#ifdef PLATESOLVER
|
||||
dockMenu->addAction(_plateSolving->toggleViewAction());
|
||||
#endif
|
||||
menuBar()->addMenu(dockMenu);
|
||||
|
||||
QMenu *helpMenu = menuBar()->addMenu(tr("Help"));
|
||||
helpMenu->addAction(tr("Help"), QKeySequence::HelpContents, [this]{ HelpDialog *help = new HelpDialog(this); help->show(); });
|
||||
helpMenu->addAction(tr("About Tenmon"), [this]{ About about(this); about.exec(); });
|
||||
helpMenu->addAction(tr("About Qt"), [this](){ QMessageBox::aboutQt(this); });
|
||||
helpMenu->addAction(tr("Check for update"), this, &MainWindow::checkNewVersion);
|
||||
|
||||
setupSigterm();
|
||||
QSettings settings;
|
||||
restoreGeometry(settings.value("mainwindow/geometry").toByteArray());
|
||||
restoreState(settings.value("mainwindow/state").toByteArray());
|
||||
int bayermask = settings.value("mainwindow/bayermask", 0).toInt();
|
||||
switch(bayermask)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
rggbAction->setChecked(true); break;
|
||||
case 1:
|
||||
grbgAction->setChecked(true); break;
|
||||
case 2:
|
||||
gbrgAction->setChecked(true); break;
|
||||
case 3:
|
||||
bggrAction->setChecked(true); break;
|
||||
}
|
||||
int colormap = settings.value("mainwindow/colormap", 4).toInt();
|
||||
if(colormap >= 0 && colormap < colormapActionGroup->actions().size())
|
||||
colormapActionGroup->actions().at(colormap)->setChecked(true);
|
||||
|
||||
m_image->setBayerMask(bayermask);
|
||||
m_image->setColormap(colormap);
|
||||
|
||||
QStringList standardLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
|
||||
if(standardLocations.size())
|
||||
_lastDir = standardLocations.first();
|
||||
|
||||
_lastDir = settings.value("mainwindow/lastdir", _lastDir).toString();
|
||||
|
||||
m_image->setFocus();
|
||||
|
||||
// workaround for nasty wayland backend bug https://bugreports.qt.io/browse/QTBUG-87332
|
||||
if(static_cast<QGuiApplication*>(QCoreApplication::instance())->platformName() == "wayland")
|
||||
{
|
||||
infoDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);
|
||||
filesystemDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);
|
||||
databaseViewDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);
|
||||
filetreeDock->setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable);
|
||||
m_stretchPanel->setFloatable(false);
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete m_database;
|
||||
}
|
||||
|
||||
void MainWindow::setupSigterm()
|
||||
{
|
||||
#ifdef __linux__
|
||||
struct sigaction signal;
|
||||
|
||||
signal.sa_handler = MainWindow::signalHandler;
|
||||
sigemptyset(&signal.sa_mask);
|
||||
signal.sa_flags = 0;
|
||||
signal.sa_flags |= SA_RESTART;
|
||||
|
||||
sigaction(SIGHUP, &signal, 0);
|
||||
sigaction(SIGTERM, &signal, 0);
|
||||
sigaction(SIGINT, &signal, 0);
|
||||
|
||||
::socketpair(AF_UNIX, SOCK_STREAM, 0, socketPair);
|
||||
socketNotifier = new QSocketNotifier(socketPair[1], QSocketNotifier::Read, this);
|
||||
connect(socketNotifier, &QSocketNotifier::activated, this, &MainWindow::socketNotify);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::signalHandler(int)
|
||||
{
|
||||
char a = 1;
|
||||
::write(socketPair[0], &a, sizeof(a));
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("mainwindow/geometry", saveGeometry());
|
||||
settings.setValue("mainwindow/state", saveState());
|
||||
QMainWindow::closeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::copyOrMove(bool copy)
|
||||
{
|
||||
QString dest = QFileDialog::getExistingDirectory(this,
|
||||
tr("Select destination"),
|
||||
_lastDir,
|
||||
QFileDialog::ShowDirsOnly);
|
||||
copyOrMove(copy, dest);
|
||||
}
|
||||
|
||||
void MainWindow::copyOrMove(bool copy, const QString &dest)
|
||||
{
|
||||
QDir dir(dest);
|
||||
if(!dest.isEmpty() && dir.exists())
|
||||
{
|
||||
int i = 0;
|
||||
int missing = 0;
|
||||
bool overwriteAll = false;
|
||||
bool skipAll = false;
|
||||
QStringList files = m_database->getMarkedFiles();
|
||||
QProgressDialog progress(copy ? tr("Copying") : tr("Moving"), tr("Cancel"), 0, files.size(), this);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
progress.show();
|
||||
for(const QString &file : files)
|
||||
{
|
||||
bool result = false;
|
||||
QFileInfo info(file);
|
||||
QFile srcFile(file);
|
||||
QFile dstFile(dir.absoluteFilePath(info.fileName()));
|
||||
|
||||
if(!srcFile.exists())
|
||||
{
|
||||
missing++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(dstFile.exists())
|
||||
{
|
||||
if(skipAll)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if(overwriteAll)
|
||||
{
|
||||
dstFile.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::StandardButton button = QMessageBox::question(this, tr("Overwrite file?"), tr("Destination file %1 already exists. Overwrite?").arg(dstFile.fileName()),
|
||||
QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll);
|
||||
switch (button)
|
||||
{
|
||||
case QMessageBox::YesToAll:
|
||||
overwriteAll = true;
|
||||
case QMessageBox::Yes:
|
||||
dstFile.remove();
|
||||
break;
|
||||
case QMessageBox::NoToAll:
|
||||
skipAll = true;
|
||||
case QMessageBox::No:
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(progress.wasCanceled())
|
||||
return;
|
||||
#ifdef __linux__
|
||||
if(copy)
|
||||
{
|
||||
srcFile.open(QIODevice::ReadOnly);
|
||||
dstFile.open(QIODevice::WriteOnly);
|
||||
if(ioctl(dstFile.handle(), BTRFS_IOC_CLONE, srcFile.handle()) < 0)
|
||||
{
|
||||
dstFile.remove();
|
||||
dstFile.close();
|
||||
result = srcFile.copy(dstFile.fileName());
|
||||
}
|
||||
else result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = srcFile.rename(dstFile.fileName());
|
||||
}
|
||||
#else
|
||||
if(copy)
|
||||
result = srcFile.copy(dstFile.fileName());
|
||||
else
|
||||
result = srcFile.rename(dstFile.fileName());
|
||||
#endif
|
||||
if(!result)
|
||||
{
|
||||
QString t = copy ? tr("Failed to copy") : tr("Failed to move");
|
||||
QString m = copy ? tr("Failed to copy from %1 to %2") : tr("Failed to move from %1 to %2");
|
||||
QMessageBox::StandardButton button = QMessageBox::warning(this, t,
|
||||
m.arg(srcFile.fileName()).arg(dir.absolutePath()),
|
||||
QMessageBox::Ignore | QMessageBox::Abort);
|
||||
if(button == QMessageBox::Abort)return;
|
||||
}
|
||||
progress.setValue(i++);
|
||||
}
|
||||
m_database->clearMarkedFiles();
|
||||
if(missing)
|
||||
QMessageBox::information(this, tr("Missing marked files"), tr("%1 marked files were missing. They were skipped.").arg(missing));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::socketNotify()
|
||||
{
|
||||
socketNotifier->setEnabled(false);
|
||||
char tmp;
|
||||
read(socketPair[1], &tmp, sizeof(tmp));
|
||||
close();
|
||||
socketNotifier->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::loadFile()
|
||||
{
|
||||
QString file = QFileDialog::getOpenFileName(this,
|
||||
tr("Open file"),
|
||||
_lastDir,
|
||||
_openFilter);
|
||||
loadFile(file);
|
||||
}
|
||||
|
||||
void MainWindow::loadFile(const QString &path)
|
||||
{
|
||||
if(!path.isEmpty())
|
||||
{
|
||||
QFileInfo info(path);
|
||||
m_ringList->setFile(info.canonicalFilePath());
|
||||
updateWindowTitle();
|
||||
if(info.isDir())
|
||||
_lastDir = info.absolutePath();
|
||||
else
|
||||
_lastDir = info.canonicalPath();
|
||||
QSettings settings;
|
||||
settings.setValue("mainwindow/lastdir", _lastDir);
|
||||
if(settings.value("settings/bestfit", false).toBool())
|
||||
m_image->bestFit();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadFiles(const QStringList &paths)
|
||||
{
|
||||
m_ringList->setFiles(paths);
|
||||
}
|
||||
|
||||
void MainWindow::loadFile(int row)
|
||||
{
|
||||
m_ringList->loadFile(row);
|
||||
}
|
||||
|
||||
void MainWindow::loadDir()
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(this,
|
||||
tr("Open directory recursively"),
|
||||
_lastDir);
|
||||
if(!dir.isEmpty())
|
||||
{
|
||||
_lastDir = dir;
|
||||
m_ringList->setDir(dir, QString(), true);
|
||||
QSettings settings;
|
||||
settings.setValue("mainwindow/lastdir", _lastDir);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::indexDir()
|
||||
{
|
||||
QString dir = QFileDialog::getExistingDirectory(this, tr("Index directory"), _lastDir, QFileDialog::ShowDirsOnly);
|
||||
indexDir(dir);
|
||||
}
|
||||
|
||||
void MainWindow::indexDir(const QString &dir)
|
||||
{
|
||||
if(!dir.isEmpty())
|
||||
{
|
||||
QProgressDialog progressDialog(tr("Indexing FITS files"), tr("Cancel"), 0, 1, this);
|
||||
progressDialog.setModal(true);
|
||||
m_database->indexDir(dir, &progressDialog);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::reindex()
|
||||
{
|
||||
QProgressDialog progressDialog(tr("Indexing FITS files"), tr("Cancel"), 0, 1, this);
|
||||
progressDialog.setModal(true);
|
||||
m_database->reindex(&progressDialog);
|
||||
}
|
||||
|
||||
void MainWindow::saveAs()
|
||||
{
|
||||
QString selectedFilter;
|
||||
QString file = QFileDialog::getSaveFileName(this,
|
||||
tr("Save as"),
|
||||
_lastDir,
|
||||
_saveFilter,
|
||||
&selectedFilter);
|
||||
auto filterToFormat = [](const QString &file, const QString &filter) -> const char*
|
||||
{
|
||||
QString suffix = QFileInfo(file).suffix();
|
||||
if(!suffix.compare("jpg", Qt::CaseInsensitive) || !suffix.compare("jpeg", Qt::CaseInsensitive))return "jpeg";
|
||||
if(!suffix.compare("png", Qt::CaseInsensitive))return "png";
|
||||
if(!suffix.compare("fits", Qt::CaseInsensitive) || !suffix.compare("fit", Qt::CaseInsensitive))return "fits";
|
||||
if(!suffix.compare("xisf", Qt::CaseInsensitive))return "xisf";
|
||||
if(filter.contains("png"))return "png";
|
||||
if(filter.contains("fits"))return "fits";
|
||||
if(filter.contains("xisf"))return "xisf";
|
||||
return "jpeg";
|
||||
};
|
||||
|
||||
if(!file.isEmpty())
|
||||
{
|
||||
QString format = filterToFormat(file, selectedFilter);
|
||||
|
||||
if(format == "fits" || format == "xisf")
|
||||
{
|
||||
convert(file, format);
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage img = m_image->renderToImage();
|
||||
if(!img.isNull())
|
||||
img.save(file, filterToFormat(file, selectedFilter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::convert(const QString &outfile, const QString &format)
|
||||
{
|
||||
QString file = m_ringList->currentImage()->name();
|
||||
QThreadPool::globalInstance()->start(new ConvertRunable(file, outfile, format));
|
||||
}
|
||||
|
||||
void MainWindow::markImage()
|
||||
{
|
||||
ImagePtr ptr = m_ringList->currentImage();
|
||||
if(ptr)
|
||||
{
|
||||
QString file = ptr->name();
|
||||
if(!file.isEmpty())
|
||||
{
|
||||
m_database->mark(file);
|
||||
m_ringList->updateMark();
|
||||
}
|
||||
|
||||
updateWindowTitle();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::unmarkImage()
|
||||
{
|
||||
ImagePtr ptr = m_ringList->currentImage();
|
||||
if(ptr)
|
||||
{
|
||||
QString file = ptr->name();
|
||||
if(!file.isEmpty())
|
||||
{
|
||||
m_database->unmark(file);
|
||||
m_ringList->updateMark();
|
||||
}
|
||||
|
||||
updateWindowTitle();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::markAndNext()
|
||||
{
|
||||
markImage();
|
||||
m_ringList->increment();
|
||||
updateWindowTitle();
|
||||
}
|
||||
|
||||
void MainWindow::unmarkAndNext()
|
||||
{
|
||||
unmarkImage();
|
||||
m_ringList->increment();
|
||||
updateWindowTitle();
|
||||
}
|
||||
|
||||
void MainWindow::copyMarked()
|
||||
{
|
||||
copyOrMove(true);
|
||||
}
|
||||
|
||||
void MainWindow::moveMarked()
|
||||
{
|
||||
copyOrMove(false);
|
||||
}
|
||||
|
||||
void MainWindow::deleteMarked()
|
||||
{
|
||||
QStringList files = m_database->getMarkedFiles();
|
||||
if(QMessageBox::question(this, tr("Move files to trash?"), tr("Do you want to move %1 files to trash?").arg(files.size())) != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
QProgressDialog progress(tr("Moving marked files to trash"), tr("Cancel"), 0, files.size(), this);
|
||||
progress.setWindowModality(Qt::WindowModal);
|
||||
progress.show();
|
||||
int i = 0;
|
||||
for(const QString &file : files)
|
||||
{
|
||||
if(!QFile::exists(file))
|
||||
continue;
|
||||
|
||||
if(progress.wasCanceled())
|
||||
return;
|
||||
|
||||
if(!moveToTrash(file))
|
||||
{
|
||||
QMessageBox::warning(this, tr("Failed to move file to trash"), tr("Failed to move file to trash %1").arg(file));
|
||||
return;
|
||||
}
|
||||
progress.setValue(i++);
|
||||
}
|
||||
m_database->clearMarkedFiles();
|
||||
}
|
||||
|
||||
void MainWindow::liveMode(bool active)
|
||||
{
|
||||
m_ringList->setLiveMode(active);
|
||||
}
|
||||
|
||||
void MainWindow::imageStats(bool imageStats)
|
||||
{
|
||||
m_ringList->setCalculateStats(imageStats);
|
||||
}
|
||||
|
||||
void MainWindow::peakFinder(bool findPeaks)
|
||||
{
|
||||
m_ringList->setFindPeaks(findPeaks);
|
||||
}
|
||||
|
||||
void MainWindow::starFinder(bool findStars)
|
||||
{
|
||||
m_ringList->setFindStars(findStars);
|
||||
}
|
||||
|
||||
void MainWindow::showMarkFilesDialog()
|
||||
{
|
||||
MarkedFiles markedFiles(this);
|
||||
markedFiles.exec();
|
||||
}
|
||||
|
||||
void MainWindow::showSettingsDialog()
|
||||
{
|
||||
SettingsDialog settingsDialog(this);
|
||||
connect(&settingsDialog, &SettingsDialog::preloadChanged, m_ringList, &ImageRingList::setPreload);
|
||||
settingsDialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::exportCSV()
|
||||
{
|
||||
QStringList documentDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
||||
if(documentDir.empty())documentDir.append("");
|
||||
QString file = QFileDialog::getSaveFileName(this,
|
||||
tr("Save as"),
|
||||
documentDir.first(),
|
||||
tr("CSV file (*.csv)"));
|
||||
|
||||
if(!file.isEmpty())
|
||||
m_databaseView->exportCSV(file);
|
||||
}
|
||||
|
||||
void MainWindow::checkNewVersion()
|
||||
{
|
||||
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
|
||||
QNetworkRequest request(QUrl("https://gitea.nouspiro.space/api/v1/repos/nou/tenmon/releases/latest"));
|
||||
request.setRawHeader("accept", "application/json");
|
||||
QNetworkReply *reply = manager->get(request);
|
||||
connect(reply, &QNetworkReply::finished, [this, manager, reply](){
|
||||
QJsonParseError error;
|
||||
QJsonDocument json = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||
if(json.isObject() && json.object().contains("tag_name"))
|
||||
{
|
||||
QString tag = json.object().value("tag_name").toString();
|
||||
QString version = getVersion();
|
||||
if(version >= tag)
|
||||
QMessageBox::information(this, tr("Update check"), tr("You have newest version"));
|
||||
else
|
||||
{
|
||||
if(QMessageBox::question(this, tr("Update check"), tr("New version %1 is available. Do you want to download it now?").arg(tag)) == QMessageBox::Yes)
|
||||
{
|
||||
QUrl url(json.object().value("html_url").toString());
|
||||
qDebug() << url;
|
||||
if(url.host() == "gitea.nouspiro.space")
|
||||
QDesktopServices::openUrl(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, tr("Update check"), tr("Failed to check version"));
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
manager->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::updateWindowTitle()
|
||||
{
|
||||
ImagePtr ptr = m_ringList->currentImage();
|
||||
if(ptr)
|
||||
{
|
||||
QDir dir(m_ringList->currentDir());
|
||||
QString title = dir.relativeFilePath(ptr->name());
|
||||
if(ptr->info().num > 1)
|
||||
title += QString(" [%1/%2]").arg(ptr->info().index + 1).arg(ptr->info().num);
|
||||
if(m_database->isMarked(ptr->name()))
|
||||
title += " *";
|
||||
setWindowTitle(title);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSocketNotifier>
|
||||
#include "imageringlist.h"
|
||||
#include "database.h"
|
||||
#include "imageinfo.h"
|
||||
#include "imagescrollarea.h"
|
||||
#include "filesystemwidget.h"
|
||||
#include "stretchtoolbar.h"
|
||||
#include "databaseview.h"
|
||||
#include "platesolving.h"
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
ImageScrollArea *m_image;
|
||||
ImageRingList *m_ringList;
|
||||
StretchToolbar *m_stretchPanel;
|
||||
Database *m_database;
|
||||
ImageInfo *m_info;
|
||||
FilesystemWidget *m_filesystem;
|
||||
Filetree *m_filetree;
|
||||
DataBaseView *m_databaseView;
|
||||
PlateSolving *_plateSolving;
|
||||
static int socketPair[2];
|
||||
QSocketNotifier *socketNotifier;
|
||||
QString _lastDir;
|
||||
bool _maximized;
|
||||
QString _openFilter;
|
||||
QString _saveFilter;
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
~MainWindow() override;
|
||||
protected:
|
||||
void setupSigterm();
|
||||
static void signalHandler(int);
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void copyOrMove(bool copy);
|
||||
void copyOrMove(bool copy, const QString &dest);
|
||||
public slots:
|
||||
void socketNotify();
|
||||
void updateWindowTitle();
|
||||
void loadFile();
|
||||
void loadFile(const QString &path);
|
||||
void loadFiles(const QStringList &paths);
|
||||
void loadFile(int row);
|
||||
void loadDir();
|
||||
void indexDir();
|
||||
void indexDir(const QString &dir);
|
||||
void reindex();
|
||||
void saveAs();
|
||||
void convert(const QString &outfile, const QString &format);
|
||||
void markImage();
|
||||
void unmarkImage();
|
||||
void markAndNext();
|
||||
void unmarkAndNext();
|
||||
void copyMarked();
|
||||
void moveMarked();
|
||||
void deleteMarked();
|
||||
void liveMode(bool active);
|
||||
void imageStats(bool imageStats);
|
||||
void peakFinder(bool findPeaks);
|
||||
void starFinder(bool findStars);
|
||||
void showMarkFilesDialog();
|
||||
void showSettingsDialog();
|
||||
void exportCSV();
|
||||
void checkNewVersion();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "markedfiles.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QTableView>
|
||||
#include <QSqlTableModel>
|
||||
#include <QPushButton>
|
||||
#include <QHeaderView>
|
||||
#include <QSqlQuery>
|
||||
|
||||
MarkedFiles::MarkedFiles(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setWindowTitle(tr("Marked files"));
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
m_tableView = new QTableView(this);
|
||||
m_tableView->verticalHeader()->setDefaultSectionSize(1);
|
||||
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
m_model = new QSqlTableModel(this, db);
|
||||
|
||||
m_model->setTable("files");
|
||||
m_model->removeColumn(0);
|
||||
m_model->setHeaderData(0, Qt::Horizontal, tr("Filename"));
|
||||
m_model->select();
|
||||
|
||||
m_tableView->setModel(m_model);
|
||||
m_tableView->resizeColumnsToContents();
|
||||
m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
QPushButton *clearSelectedButton = new QPushButton(tr("Clear selected"), this);
|
||||
QPushButton *clearAllButton = new QPushButton(tr("Clear all"), this);
|
||||
|
||||
connect(clearSelectedButton, &QPushButton::pressed, this, &MarkedFiles::clearSelected);
|
||||
connect(clearAllButton, &QPushButton::pressed, this, &MarkedFiles::clearAll);
|
||||
|
||||
layout->addWidget(m_tableView);
|
||||
layout->addLayout(hlayout);
|
||||
hlayout->addWidget(clearSelectedButton);
|
||||
hlayout->addWidget(clearAllButton);
|
||||
|
||||
resize(800, 600);
|
||||
}
|
||||
|
||||
void MarkedFiles::clearSelected()
|
||||
{
|
||||
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
QSqlQuery query("DELETE FROM files where file = ?", db);
|
||||
QModelIndexList rows = m_tableView->selectionModel()->selectedRows();
|
||||
QStringList files;
|
||||
for(const QModelIndex &row : rows)
|
||||
{
|
||||
files.append(row.data().toString());
|
||||
}
|
||||
query.bindValue(0, files);
|
||||
query.execBatch();
|
||||
m_model->select();
|
||||
}
|
||||
|
||||
void MarkedFiles::clearAll()
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
QSqlQuery("DELETE FROM files", db);
|
||||
m_model->select();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef MARKEDFILES_H
|
||||
#define MARKEDFILES_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTableView>
|
||||
#include <QSqlTableModel>
|
||||
|
||||
class MarkedFiles : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
QTableView *m_tableView;
|
||||
QSqlTableModel *m_model;
|
||||
public:
|
||||
MarkedFiles(QWidget *parent = nullptr);
|
||||
protected slots:
|
||||
void clearSelected();
|
||||
void clearAll();
|
||||
};
|
||||
|
||||
#endif // MARKEDFILES_H
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef MTFPARAM_H
|
||||
#define MTFPARAM_H
|
||||
|
||||
struct MTFParam
|
||||
{
|
||||
float blackPoint[3] = {0.0f, 0.0f, 0.0f};
|
||||
float midPoint[3] = {0.5f, 0.5f, 0.5f};
|
||||
float whitePoint[3] = {1.0f, 1.0f, 1.0f};
|
||||
};
|
||||
|
||||
#endif // MTFPARAM_H
|
||||
@@ -0,0 +1,203 @@
|
||||
#include "platesolving.h"
|
||||
#include <QSettings>
|
||||
#include <QMessageBox>
|
||||
#include "ui_platesolving.h"
|
||||
#include "solver.h"
|
||||
#include "imageringlist.h"
|
||||
#include "platesolvingsettings.h"
|
||||
|
||||
PlateSolving::PlateSolving(QWidget *parent)
|
||||
: QDockWidget(parent)
|
||||
, _ui(new Ui::PlateSolving)
|
||||
{
|
||||
_ui->setupUi(this);
|
||||
|
||||
_solver = new Solver(this);
|
||||
QSettings settings;
|
||||
_solver->setIndexFolder(settings.value("platesolving/indexPath", Solver::getTenmonIndexPath()).toString());
|
||||
auto profiles = StellarSolver::getBuiltInProfiles();
|
||||
int profileIdx = settings.value("platesolving/profile", 0).toInt();
|
||||
_solver->setParameters(profiles[profileIdx]);
|
||||
|
||||
for(auto &profile : profiles)
|
||||
{
|
||||
_ui->profileComboBox->addItem(profile.listName);
|
||||
}
|
||||
_ui->profileComboBox->setCurrentIndex(profileIdx);
|
||||
_ui->profileComboBox->setToolTip(profiles[profileIdx].description);
|
||||
_ui->scaleUnit->setCurrentIndex(settings.value("platesolving/scaleUnit", 1).toInt());
|
||||
|
||||
connect(_ui->profileComboBox, &QComboBox::currentIndexChanged, [this](int index){
|
||||
auto profiles = StellarSolver::getBuiltInProfiles();
|
||||
_solver->setParameters(profiles[index]);
|
||||
_ui->profileComboBox->setToolTip(profiles[index].description);
|
||||
QSettings settings;
|
||||
settings.setValue("platesolving/profile", index);
|
||||
});
|
||||
|
||||
connect(_ui->extractButton, &QPushButton::clicked, this, &PlateSolving::extract);
|
||||
connect(_ui->solveButton, &QPushButton::clicked, this, &PlateSolving::solve);
|
||||
connect(_ui->settingsButton, &QPushButton::clicked, this, &PlateSolving::settings);
|
||||
connect(_ui->abortButton, &QPushButton::clicked, this, &PlateSolving::abort);
|
||||
connect(_ui->updateButton, &QPushButton::clicked, this, &PlateSolving::updateHeader);
|
||||
connect(_ui->raStart, &QDoubleSpinBox::valueChanged, [this](double val){ _ui->raLabel->setText("RA " + SkyPoint::toHMS(val)); });
|
||||
connect(_solver, &Solver::solvingDone, this, &PlateSolving::solvingDone);
|
||||
connect(_solver, &Solver::extractionDone, this, &PlateSolving::extractionDone);
|
||||
connect(_solver, &Solver::logOutput, [this](const QString &log){ _ui->log->appendPlainText(log); });
|
||||
connect(_solver, &Solver::headerUpdated, this, &PlateSolving::headerUpdated);
|
||||
}
|
||||
|
||||
PlateSolving::~PlateSolving()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("platesolving/profile", _ui->profileComboBox->currentIndex());
|
||||
settings.setValue("platesolving/scaleUnit", _ui->scaleUnit->currentIndex());
|
||||
delete _ui;
|
||||
}
|
||||
|
||||
void PlateSolving::extract()
|
||||
{
|
||||
if(!_rawImage)return;
|
||||
_ui->solveButton->setDisabled(true);
|
||||
_ui->extractButton->setDisabled(true);
|
||||
_ui->log->clear();
|
||||
|
||||
_solver->loadImage(_rawImage, _path);
|
||||
_solvingTime.start();
|
||||
_solver->extractSources(_ui->withHFR->isChecked());
|
||||
}
|
||||
|
||||
void PlateSolving::extractionDone()
|
||||
{
|
||||
auto stars = _solver->getStars();
|
||||
float a = 0;
|
||||
float b = 0;
|
||||
float hfr = 0;
|
||||
for(auto &star : stars)
|
||||
{
|
||||
a += star.a;
|
||||
b += star.b;
|
||||
hfr += star.HFR;
|
||||
}
|
||||
if(size_t size = stars.size())
|
||||
{
|
||||
a /= size;
|
||||
b /= size;
|
||||
hfr /= size;
|
||||
}
|
||||
|
||||
_ui->stars->setText(QString::number(stars.size()));
|
||||
_ui->hfr->setText(QString("%1pix Ecc:%2").arg(hfr).arg(std::sqrt(1 - (b*b)/(a*a))));
|
||||
_ui->log->appendPlainText(QString("Extraction finished in %1 ms").arg(_solvingTime.elapsed()));
|
||||
|
||||
_ui->solveButton->setDisabled(false);
|
||||
_ui->extractButton->setDisabled(false);
|
||||
}
|
||||
|
||||
void PlateSolving::solve()
|
||||
{
|
||||
if(!_rawImage)return;
|
||||
_ui->solveButton->setDisabled(true);
|
||||
_ui->extractButton->setDisabled(true);
|
||||
_ui->log->clear();
|
||||
|
||||
_solver->loadImage(_rawImage, _path);
|
||||
if(_ui->usePosition->isChecked())
|
||||
_solver->setSearchPosition(_ui->raStart->value(), _ui->decStart->value());
|
||||
|
||||
if(_ui->useScale->isChecked())
|
||||
{
|
||||
SSolver::ScaleUnits scaleUnit;
|
||||
switch(_ui->scaleUnit->currentIndex())
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
scaleUnit = SSolver::ScaleUnits::DEG_WIDTH; break;
|
||||
case 1:
|
||||
scaleUnit = SSolver::ScaleUnits::ARCMIN_WIDTH; break;
|
||||
case 2:
|
||||
scaleUnit = SSolver::ScaleUnits::ARCSEC_PER_PIX; break;
|
||||
case 3:
|
||||
scaleUnit = SSolver::ScaleUnits::FOCAL_MM; break;
|
||||
}
|
||||
_solver->setSearchScale(_ui->fovLow->value(), _ui->fovHigh->value(), scaleUnit);
|
||||
}
|
||||
_solvingTime.start();
|
||||
_solver->solveImage();
|
||||
}
|
||||
|
||||
void PlateSolving::solvingDone()
|
||||
{
|
||||
_ui->solveButton->setDisabled(false);
|
||||
_ui->extractButton->setDisabled(false);
|
||||
|
||||
auto solution = _solver->getSolution();
|
||||
_ui->ra->setText(SkyPoint::toHMS(solution.ra / 15.0));
|
||||
_ui->dec->setText(SkyPoint::toDMS(solution.dec));
|
||||
_ui->orientation->setText(QString::number(solution.orientation) + "°");
|
||||
_ui->fieldWidth->setText(QString::number(solution.fieldWidth) + "'");
|
||||
_ui->fieldHeight->setText(QString::number(solution.fieldHeight) + "\"");
|
||||
_ui->pixelScale->setText(QString::number(solution.pixscale) + "\"/pix");
|
||||
_ui->log->appendPlainText(QString("Solving finished in %1 ms").arg(_solvingTime.elapsed()));
|
||||
}
|
||||
|
||||
void PlateSolving::abort()
|
||||
{
|
||||
_solver->abort();
|
||||
}
|
||||
|
||||
void PlateSolving::updateHeader()
|
||||
{
|
||||
QString error;
|
||||
if(!_solver->updateHeader(error))
|
||||
QMessageBox::warning(this, tr("Header update failed"), error);
|
||||
}
|
||||
|
||||
void PlateSolving::imageLoaded(Image *image)
|
||||
{
|
||||
if(image && image->rawImage())
|
||||
{
|
||||
_rawImage = image->rawImage();
|
||||
_path = image->name();
|
||||
_ui->ra->clear();
|
||||
_ui->dec->clear();
|
||||
_ui->orientation->clear();
|
||||
_ui->fieldWidth->clear();
|
||||
_ui->fieldHeight->clear();
|
||||
_ui->pixelScale->clear();
|
||||
_ui->hfr->clear();
|
||||
_ui->stars->clear();
|
||||
|
||||
const ImageInfoData &info = image->info();
|
||||
SkyPointScale pointScale = info.getCenterRaDec();
|
||||
if(!std::isnan(pointScale.point.RA()) && !std::isnan(pointScale.point.DEC()))
|
||||
{
|
||||
_ui->raStart->setValue(pointScale.point.RAHour());
|
||||
_ui->decStart->setValue(pointScale.point.DEC());
|
||||
_ui->usePosition->setChecked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ui->usePosition->setChecked(false);
|
||||
}
|
||||
|
||||
if(pointScale.scaleValid)
|
||||
{
|
||||
_ui->scaleUnit->setCurrentIndex(2);
|
||||
_ui->fovLow->setValue(pointScale.scaleLow);
|
||||
_ui->fovHigh->setValue(pointScale.scaleHigh);
|
||||
_ui->useScale->setChecked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ui->useScale->setChecked(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlateSolving::settings()
|
||||
{
|
||||
PlateSolvingSettings settings(this);
|
||||
settings.exec();
|
||||
_solver->setIndexFolder(settings.indexDirectory());
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef PLATESOLVING_H
|
||||
#define PLATESOLVING_H
|
||||
|
||||
#include "qelapsedtimer.h"
|
||||
#include <QDockWidget>
|
||||
|
||||
class Solver;
|
||||
class RawImage;
|
||||
class Image;
|
||||
|
||||
namespace Ui {
|
||||
class PlateSolving;
|
||||
}
|
||||
|
||||
class PlateSolving : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Solver *_solver;
|
||||
std::shared_ptr<RawImage> _rawImage;
|
||||
QString _path;
|
||||
QElapsedTimer _solvingTime;
|
||||
public:
|
||||
explicit PlateSolving(QWidget *parent = nullptr);
|
||||
~PlateSolving();
|
||||
|
||||
public slots:
|
||||
void extract();
|
||||
void extractionDone();
|
||||
void solve();
|
||||
void solvingDone();
|
||||
void abort();
|
||||
void updateHeader();
|
||||
void imageLoaded(Image *image);
|
||||
void settings();
|
||||
signals:
|
||||
void headerUpdated(const QString &path);
|
||||
private:
|
||||
Ui::PlateSolving *_ui;
|
||||
};
|
||||
|
||||
#endif // PLATESOLVING_H
|
||||
@@ -0,0 +1,364 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PlateSolving</class>
|
||||
<widget class="QDockWidget" name="PlateSolving">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>860</width>
|
||||
<height>700</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Plate Solving</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Profile</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="profileComboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
<string>Start point</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="3" column="3">
|
||||
<widget class="QComboBox" name="scaleUnit">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Degree width</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Arcmin width</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Arcsec per pixel</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>35 mm equivalent focal length</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="usePosition">
|
||||
<property name="text">
|
||||
<string>Use position</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="QDoubleSpinBox" name="fovHigh">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>100000.000000000000000</double>
|
||||
</property>
|
||||
<property name="stepType">
|
||||
<enum>QAbstractSpinBox::AdaptiveDecimalStepType</enum>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="text">
|
||||
<string>DEC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="raStart">
|
||||
<property name="suffix">
|
||||
<string> h</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>24.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QLabel" name="label_13">
|
||||
<property name="text">
|
||||
<string>High</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QDoubleSpinBox" name="fovLow">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10000.000000000000000</double>
|
||||
</property>
|
||||
<property name="stepType">
|
||||
<enum>QAbstractSpinBox::AdaptiveDecimalStepType</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="useScale">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Use scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QDoubleSpinBox" name="decStart">
|
||||
<property name="suffix">
|
||||
<string> deg</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-90.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>90.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="text">
|
||||
<string>Low </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="raLabel">
|
||||
<property name="text">
|
||||
<string>RA</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="text">
|
||||
<string>Unit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Solution</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>RA</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="ra">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>DEC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLineEdit" name="dec">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Field width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="fieldWidth">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Field height</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="fieldHeight">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Orientation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="orientation">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Pixel scale</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QLineEdit" name="pixelScale">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Stars</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="stars">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="text">
|
||||
<string>HFR</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QLineEdit" name="hfr">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="log">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="settingsButton">
|
||||
<property name="text">
|
||||
<string>Settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QPushButton" name="extractButton">
|
||||
<property name="text">
|
||||
<string>Extract</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QPushButton" name="solveButton">
|
||||
<property name="text">
|
||||
<string>Solve</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="withHFR">
|
||||
<property name="text">
|
||||
<string>Extract with HFR</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QPushButton" name="abortButton">
|
||||
<property name="text">
|
||||
<string>Abort</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="updateButton">
|
||||
<property name="text">
|
||||
<string>Update FITS header</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,135 @@
|
||||
#include "platesolvingsettings.h"
|
||||
#include "ui_platesolvingsettings.h"
|
||||
#include <QSettings>
|
||||
#include <QFileDialog>
|
||||
#include "solver.h"
|
||||
|
||||
PlateSolvingSettings::PlateSolvingSettings(QWidget *parent) : QDialog(parent)
|
||||
, _ui(new Ui::PlateSolvingSettings)
|
||||
{
|
||||
_ui->setupUi(this);
|
||||
|
||||
_download = new HttpDownloader(this);
|
||||
connect(_download, &HttpDownloader::progress, this, &PlateSolvingSettings::progress);
|
||||
connect(_ui->stopDownloadButton, &QPushButton::clicked, _download, &HttpDownloader::abort);
|
||||
|
||||
connect(_ui->scale01, &QCheckBox::clicked, [this](){ if(_ui->scale01->isChecked())_download->downloadIndex(1); });
|
||||
connect(_ui->scale02, &QCheckBox::clicked, [this](){ if(_ui->scale02->isChecked())_download->downloadIndex(2); });
|
||||
connect(_ui->scale03, &QCheckBox::clicked, [this](){ if(_ui->scale03->isChecked())_download->downloadIndex(3); });
|
||||
connect(_ui->scale04, &QCheckBox::clicked, [this](){ if(_ui->scale04->isChecked())_download->downloadIndex(4); });
|
||||
connect(_ui->scale05, &QCheckBox::clicked, [this](){ if(_ui->scale05->isChecked())_download->downloadIndex(5); });
|
||||
connect(_ui->scale06, &QCheckBox::clicked, [this](){ if(_ui->scale06->isChecked())_download->downloadIndex(6); });
|
||||
connect(_ui->scale07, &QCheckBox::clicked, [this](){ if(_ui->scale07->isChecked())_download->downloadIndex(7); });
|
||||
connect(_ui->scale08, &QCheckBox::clicked, [this](){ if(_ui->scale08->isChecked())_download->downloadIndex(8); });
|
||||
connect(_ui->scale09, &QCheckBox::clicked, [this](){ if(_ui->scale09->isChecked())_download->downloadIndex(9); });
|
||||
connect(_ui->scale10, &QCheckBox::clicked, [this](){ if(_ui->scale10->isChecked())_download->downloadIndex(10); });
|
||||
connect(_ui->scale11, &QCheckBox::clicked, [this](){ if(_ui->scale11->isChecked())_download->downloadIndex(11); });
|
||||
connect(_ui->scale12, &QCheckBox::clicked, [this](){ if(_ui->scale12->isChecked())_download->downloadIndex(12); });
|
||||
connect(_ui->scale13, &QCheckBox::clicked, [this](){ if(_ui->scale13->isChecked())_download->downloadIndex(13); });
|
||||
connect(_ui->scale14, &QCheckBox::clicked, [this](){ if(_ui->scale14->isChecked())_download->downloadIndex(14); });
|
||||
connect(_ui->scale15, &QCheckBox::clicked, [this](){ if(_ui->scale15->isChecked())_download->downloadIndex(15); });
|
||||
connect(_ui->scale16, &QCheckBox::clicked, [this](){ if(_ui->scale16->isChecked())_download->downloadIndex(16); });
|
||||
connect(_ui->scale17, &QCheckBox::clicked, [this](){ if(_ui->scale17->isChecked())_download->downloadIndex(17); });
|
||||
connect(_ui->scale18, &QCheckBox::clicked, [this](){ if(_ui->scale18->isChecked())_download->downloadIndex(18); });
|
||||
connect(_ui->scale19, &QCheckBox::clicked, [this](){ if(_ui->scale19->isChecked())_download->downloadIndex(19); });
|
||||
|
||||
QSettings settings;
|
||||
_ui->indexPaths->addItems(settings.value("platesolving/indexPaths", Solver::getIndexPaths()).toStringList());
|
||||
_ui->indexPaths->setCurrentText(settings.value("platesolving/indexPath", Solver::getTenmonIndexPath()).toString());
|
||||
connect(_ui->addButton, &QPushButton::clicked, [this](){
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Index files directory"), Solver::getTenmonIndexPath());
|
||||
if(!path.isEmpty())
|
||||
{
|
||||
bool contain = false;
|
||||
for(int i=0; i<_ui->indexPaths->count(); i++)
|
||||
{
|
||||
if(path == _ui->indexPaths->itemText(i))
|
||||
{
|
||||
contain = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!contain)_ui->indexPaths->addItem(path);
|
||||
}
|
||||
});
|
||||
connect(_ui->removeButton, &QPushButton::clicked, [this](){
|
||||
int current = _ui->indexPaths->currentIndex();
|
||||
if(current > 0)_ui->indexPaths->removeItem(current);
|
||||
});
|
||||
|
||||
_watcher = new QFileSystemWatcher(this);
|
||||
_watcher->addPath(Solver::getTenmonIndexPath());
|
||||
connect(_watcher, &QFileSystemWatcher::directoryChanged, this, &PlateSolvingSettings::checkIndexFiles);
|
||||
connect(_ui->indexPaths, &QComboBox::currentTextChanged, [this](const QString &text){
|
||||
_watcher->removePaths(_watcher->directories());
|
||||
_watcher->addPath(text);
|
||||
});
|
||||
connect(_ui->indexPaths, &QComboBox::currentIndexChanged, [this](int index){
|
||||
_ui->indexFilesGroup->setEnabled(index == 0);
|
||||
});
|
||||
checkIndexFiles();
|
||||
}
|
||||
|
||||
PlateSolvingSettings::~PlateSolvingSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("platesolving/indexPath", _ui->indexPaths->currentText());
|
||||
QStringList paths;
|
||||
for(int i=0; i<_ui->indexPaths->count(); i++)
|
||||
paths.append(_ui->indexPaths->itemText(i));
|
||||
|
||||
settings.setValue("platesolving/indexPaths", paths);
|
||||
delete _ui;
|
||||
}
|
||||
|
||||
void PlateSolvingSettings::checkIndexFiles()
|
||||
{
|
||||
QString indexDir = Solver::getTenmonIndexPath() + "/";
|
||||
auto checkScale = [indexDir](QCheckBox *box, int scale)
|
||||
{
|
||||
bool all = true;
|
||||
QStringList files = HttpDownloader::indexFileNames(scale);
|
||||
for(auto &file : files)
|
||||
if(!QFile::exists(indexDir + file))
|
||||
{
|
||||
all = false;
|
||||
break;
|
||||
}
|
||||
|
||||
box->setChecked(all);
|
||||
if(all)box->setStyleSheet("color: green; font: bold;");
|
||||
else box->setStyleSheet("");
|
||||
};
|
||||
|
||||
checkScale(_ui->scale01, 1);
|
||||
checkScale(_ui->scale02, 2);
|
||||
checkScale(_ui->scale03, 3);
|
||||
checkScale(_ui->scale04, 4);
|
||||
checkScale(_ui->scale05, 5);
|
||||
checkScale(_ui->scale06, 6);
|
||||
checkScale(_ui->scale07, 7);
|
||||
checkScale(_ui->scale08, 8);
|
||||
checkScale(_ui->scale09, 9);
|
||||
checkScale(_ui->scale10, 10);
|
||||
checkScale(_ui->scale11, 11);
|
||||
checkScale(_ui->scale12, 12);
|
||||
checkScale(_ui->scale13, 13);
|
||||
checkScale(_ui->scale14, 14);
|
||||
checkScale(_ui->scale15, 15);
|
||||
checkScale(_ui->scale16, 16);
|
||||
checkScale(_ui->scale17, 17);
|
||||
checkScale(_ui->scale18, 18);
|
||||
checkScale(_ui->scale19, 19);
|
||||
}
|
||||
|
||||
QString PlateSolvingSettings::indexDirectory() const
|
||||
{
|
||||
return _ui->indexPaths->currentText();
|
||||
}
|
||||
|
||||
void PlateSolvingSettings::progress(int percent, int files)
|
||||
{
|
||||
_ui->filesRemaining->setText(tr("%1 files").arg(files));
|
||||
_ui->downloadProgressbar->setValue(percent);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef PLATESOLVINGSETTINGS_H
|
||||
#define PLATESOLVINGSETTINGS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QFileSystemWatcher>
|
||||
#include "httpdownloader.h"
|
||||
|
||||
namespace Ui {
|
||||
class PlateSolvingSettings;
|
||||
}
|
||||
|
||||
class PlateSolvingSettings : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
HttpDownloader *_download;
|
||||
QFileSystemWatcher *_watcher;
|
||||
public:
|
||||
explicit PlateSolvingSettings(QWidget *parent = nullptr);
|
||||
~PlateSolvingSettings();
|
||||
void checkIndexFiles();
|
||||
QString indexDirectory() const;
|
||||
protected slots:
|
||||
void progress(int percent, int files);
|
||||
private:
|
||||
Ui::PlateSolvingSettings *_ui;
|
||||
};
|
||||
|
||||
#endif // PLATESOLVINGSETTINGS_H
|
||||
@@ -0,0 +1,229 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>PlateSolvingSettings</class>
|
||||
<widget class="QDialog" name="PlateSolvingSettings">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>787</width>
|
||||
<height>479</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="indexPaths">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Plate solving need index files in order to solve an image. You can download them here by clicking on check box. It will download them into default location. Or you can reuse <span style=" font-weight:700;">any</span> index files (not only listed bellow) from astrometry.net by adding path pointing to them. <a href="https://astrometrynet.readthedocs.io/en/latest/readme.html#getting-index-files"><span style=" text-decoration: underline; color:#0000ff;">More details about index files.</span></a></p><p>It is required to download index files that cover 100%-50% field of view and recomended 100%-10%. So for images with 70' field of view it is required to download index files in 30'-85' and recomended 4'-85'.</p></body></html></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="indexFilesGroup">
|
||||
<property name="title">
|
||||
<string>Index files</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="scale14">
|
||||
<property name="text">
|
||||
<string>240' - 340'index-4114.fits (1.4 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="scale17">
|
||||
<property name="text">
|
||||
<string>680' - 1000' index-4117.fits (242 kiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="scale16">
|
||||
<property name="text">
|
||||
<string>480' - 680' index-4116.fits (400 kiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="scale18">
|
||||
<property name="text">
|
||||
<string>1000' - 1400' index-4118.fits (183 kiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="scale15">
|
||||
<property name="text">
|
||||
<string>340' - 480' index-4115.fits (723 kiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="scale19">
|
||||
<property name="text">
|
||||
<string>1400' - 2000' index-4119.fits (141 kiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QCheckBox" name="scale12">
|
||||
<property name="text">
|
||||
<string>120' - 170' index-4112.fits (5.1MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QCheckBox" name="scale13">
|
||||
<property name="text">
|
||||
<string>170' - 240' index-4113.fits (2.7MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="0">
|
||||
<widget class="QCheckBox" name="scale11">
|
||||
<property name="text">
|
||||
<string>85' - 120' index-4111.fits (9.8 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="18" column="0">
|
||||
<widget class="QCheckBox" name="scale10">
|
||||
<property name="text">
|
||||
<string>60' - 85' index-4110.fits (24 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="scale09">
|
||||
<property name="text">
|
||||
<string>42' - 60' index-4109.fits (48 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="scale08">
|
||||
<property name="text">
|
||||
<string>30' - 42' index-4108.fits (91 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="scale07">
|
||||
<property name="text">
|
||||
<string>22' - 30' index-4107.fits (158 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="scale06">
|
||||
<property name="text">
|
||||
<string>16' - 22' index-5206-*.fits (294 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="scale05">
|
||||
<property name="text">
|
||||
<string>11' - 16' index-5205-*.fits (587 MiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QCheckBox" name="scale04">
|
||||
<property name="text">
|
||||
<string>8' - 11' index-5204-*.fits (1.2 GiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QCheckBox" name="scale03">
|
||||
<property name="text">
|
||||
<string>4.0' - 5.6' index-5203-*.fits (2.3 GiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QCheckBox" name="scale02">
|
||||
<property name="text">
|
||||
<string>5.6' - 8.0' index-5202-*.fits (4.6 GiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="17" column="1">
|
||||
<widget class="QCheckBox" name="scale01">
|
||||
<property name="text">
|
||||
<string>2.0' - 2.8' index-5201-*.fits (8.9 GiB)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="filesRemaining">
|
||||
<property name="text">
|
||||
<string>0 files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="downloadProgressbar">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="stopDownloadButton">
|
||||
<property name="text">
|
||||
<string>Stop download</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+1296
File diff suppressed because it is too large
Load Diff
+141
@@ -0,0 +1,141 @@
|
||||
#ifndef RAWIMAGE_H
|
||||
#define RAWIMAGE_H
|
||||
|
||||
#include "libxisf.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#ifndef NO_QT
|
||||
#include <QImage>
|
||||
#endif
|
||||
#include "mtfparam.h"
|
||||
|
||||
extern int THUMB_SIZE;
|
||||
extern int THUMB_SIZE_BORDER;
|
||||
extern int THUMB_SIZE_BORDER_Y;
|
||||
extern bool QUALITY_RESIZE;
|
||||
|
||||
class Peak
|
||||
{
|
||||
uint32_t m_v;
|
||||
uint32_t m_x,m_y;
|
||||
public:
|
||||
Peak() : m_v(0), m_x(0), m_y(0) {}
|
||||
Peak(uint32_t v, uint32_t x, uint32_t y) : m_v(v), m_x(x), m_y(y) {}
|
||||
uint32_t v() const { return m_v; }
|
||||
uint32_t x() const { return m_x; }
|
||||
uint32_t y() const { return m_y; }
|
||||
double distance(const Peak &d) const
|
||||
{
|
||||
uint32_t dx = m_x-d.m_x;
|
||||
uint32_t dy = m_y-d.m_y;
|
||||
return dx*dx + dy*dy;
|
||||
}
|
||||
bool operator <(const Peak &d) const
|
||||
{
|
||||
return m_v > d.m_v;
|
||||
}
|
||||
};
|
||||
|
||||
class RawImage
|
||||
{
|
||||
using PixelType = uint8_t;
|
||||
public:
|
||||
enum DataType
|
||||
{
|
||||
UINT8,
|
||||
UINT16,
|
||||
UINT32,
|
||||
FLOAT16,
|
||||
FLOAT32,
|
||||
FLOAT64,
|
||||
};
|
||||
struct Stats
|
||||
{
|
||||
bool m_stats = false;
|
||||
double m_mean[4] = {0.0};
|
||||
double m_stdDev[4] = {0.0};
|
||||
double m_median[4] = {0.0};
|
||||
double m_min[4] = {0.0};
|
||||
double m_max[4] = {0.0};
|
||||
double m_mad[4] = {0.0};
|
||||
uint32_t m_saturated[4] = {0};
|
||||
std::vector<uint32_t> m_histogram;
|
||||
};
|
||||
protected:
|
||||
std::unique_ptr<PixelType[]> m_pixels;
|
||||
std::unique_ptr<PixelType[]> m_original;
|
||||
uint32_t m_width = 0;
|
||||
uint32_t m_height = 0;
|
||||
uint32_t m_origWidth = 0;
|
||||
uint32_t m_origHeight = 0;
|
||||
uint32_t m_channels = 0;
|
||||
uint32_t m_ch = 0;
|
||||
DataType m_type = UINT8;
|
||||
DataType m_origType = UINT8;
|
||||
float m_thumbAspect = 0.0;
|
||||
Stats m_stats;
|
||||
bool m_planar = false;
|
||||
std::vector<uint8_t> m_iccProfile;
|
||||
std::vector<uint16_t> m_lut;// actually qfloat16
|
||||
void allocate(uint32_t w, uint32_t h, uint32_t ch, DataType type);
|
||||
public:
|
||||
RawImage();
|
||||
RawImage(uint32_t w, uint32_t h, uint32_t ch, DataType type);
|
||||
RawImage(const RawImage &d);
|
||||
RawImage(RawImage &&d);
|
||||
#ifndef NO_QT
|
||||
RawImage(const QImage &img);
|
||||
#endif
|
||||
const RawImage::Stats& imageStats() const;
|
||||
void calcStats();
|
||||
uint32_t width() const;
|
||||
uint32_t height() const;
|
||||
uint32_t channels() const;
|
||||
uint64_t size() const;
|
||||
DataType type() const;
|
||||
uint32_t norm() const;
|
||||
uint32_t widthBytes() const;
|
||||
uint32_t widthSamples() const;
|
||||
void* data();
|
||||
const void* data() const;
|
||||
void* data(uint32_t row, uint32_t col = 0);
|
||||
const void* data(uint32_t row, uint32_t col = 0) const;
|
||||
const void *origData() const;
|
||||
const void *origData(uint32_t row, uint32_t col = 0) const;
|
||||
bool planar() const;
|
||||
void setPlanar();
|
||||
void convertToThumbnail();
|
||||
void convertToGLFormat();
|
||||
void convertToType(RawImage::DataType type);
|
||||
float thumbAspect() const;
|
||||
bool pixel(int x, int y, double &r, double &g, double &b) const;
|
||||
void resize(uint32_t w, uint32_t h);
|
||||
void resizeInt(int downsample, bool avg);
|
||||
std::pair<float, float> unitScale() const;
|
||||
void flip();
|
||||
|
||||
static std::shared_ptr<RawImage> fromPlanar(const RawImage &img);
|
||||
static std::shared_ptr<RawImage> fromPlanar(const void *pixels, uint32_t w, uint32_t h, uint32_t ch, DataType type);
|
||||
std::shared_ptr<RawImage> toPlanar();
|
||||
static size_t typeSize(DataType type);
|
||||
std::vector<RawImage> split() const;
|
||||
bool valid() const;
|
||||
#ifndef NO_QT
|
||||
void setICCProfile(const QByteArray &icc);
|
||||
void setICCProfile(const LibXISF::ByteArray &icc);
|
||||
void convertTosRGB();
|
||||
void generateLUT();
|
||||
#endif
|
||||
void applySTF(const MTFParam &mtfParams);
|
||||
MTFParam calcMTFParams(bool linked = false, bool debayer = false) const;
|
||||
const std::vector<uint16_t>& getLUT() const;
|
||||
|
||||
};
|
||||
|
||||
//Q_DECLARE_SMART_POINTER_METATYPE(std::shared_ptr);
|
||||
//Q_DECLARE_METATYPE(std::shared_ptr<RawImage>);
|
||||
|
||||
#endif // RAWIMAGE_H
|
||||
@@ -0,0 +1,115 @@
|
||||
#ifdef __SSE2__
|
||||
#include <x86intrin.h>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
template<typename T, int ch>
|
||||
void fromPlanarSSE(const void *in, void *out, size_t count)
|
||||
{
|
||||
const __m128i *_in[4] = {(const __m128i*) static_cast<const T*>(in),
|
||||
(const __m128i*)(static_cast<const T*>(in) + count),
|
||||
(const __m128i*)(static_cast<const T*>(in) + count*2),
|
||||
(const __m128i*)(static_cast<const T*>(in) + count*3)};
|
||||
__m128i *_out = (__m128i*)out;
|
||||
size_t s2 = count;
|
||||
if constexpr(sizeof(T) == 1)
|
||||
{
|
||||
count /= 16;
|
||||
__m128i a = _mm_set1_epi8(-1);
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
__m128i r = _mm_loadu_si128(_in[0] + i);
|
||||
__m128i g = _mm_loadu_si128(_in[1] + i);
|
||||
__m128i b = _mm_loadu_si128(_in[2] + i);
|
||||
if constexpr(ch==4)a = _mm_loadu_si128(_in[3] + i);
|
||||
|
||||
__m128i d1 = _mm_unpacklo_epi8(r, b);
|
||||
__m128i d2 = _mm_unpacklo_epi8(g, a);
|
||||
_mm_storeu_si128(_out + i*4, _mm_unpacklo_epi8(d1, d2));
|
||||
_mm_storeu_si128(_out + i*4 + 1, _mm_unpackhi_epi8(d1, d2));
|
||||
d1 = _mm_unpackhi_epi8(r, b);
|
||||
d2 = _mm_unpackhi_epi8(g, a);
|
||||
_mm_storeu_si128(_out + i*4 + 2, _mm_unpacklo_epi8(d1, d2));
|
||||
_mm_storeu_si128(_out + i*4 + 3, _mm_unpackhi_epi8(d1, d2));
|
||||
}
|
||||
count *= 16;
|
||||
}
|
||||
if constexpr(sizeof(T) == 2)
|
||||
{
|
||||
count /= 8;
|
||||
__m128i a = _mm_set1_epi16(-1);
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
__m128i r = _mm_loadu_si128(_in[0] + i);
|
||||
__m128i g = _mm_loadu_si128(_in[1] + i);
|
||||
__m128i b = _mm_loadu_si128(_in[2] + i);
|
||||
if constexpr(ch==4)a = _mm_loadu_si128(_in[3] + i);
|
||||
|
||||
__m128i d1 = _mm_unpacklo_epi16(r, b);
|
||||
__m128i d2 = _mm_unpacklo_epi16(g, a);
|
||||
_mm_storeu_si128(_out + i*4, _mm_unpacklo_epi16(d1, d2));
|
||||
_mm_storeu_si128(_out + i*4 + 1, _mm_unpackhi_epi16(d1, d2));
|
||||
d1 = _mm_unpackhi_epi16(r, b);
|
||||
d2 = _mm_unpackhi_epi16(g, a);
|
||||
_mm_storeu_si128(_out + i*4 + 2, _mm_unpacklo_epi16(d1, d2));
|
||||
_mm_storeu_si128(_out + i*4 + 3, _mm_unpackhi_epi16(d1, d2));
|
||||
}
|
||||
count *= 8;
|
||||
}
|
||||
if constexpr(sizeof(T) == 4)
|
||||
{
|
||||
count /= 4;
|
||||
__m128i a = _mm_set1_epi32(-1);
|
||||
if constexpr(!std::numeric_limits<T>::is_integer)a = _mm_castps_si128(_mm_set1_ps(1.0));
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
__m128i r = _mm_loadu_si128(_in[0] + i);
|
||||
__m128i g = _mm_loadu_si128(_in[1] + i);
|
||||
__m128i b = _mm_loadu_si128(_in[2] + i);
|
||||
if constexpr(ch==4)a = _mm_loadu_si128(_in[3] + i);
|
||||
|
||||
__m128i d1 = _mm_unpacklo_epi32(r, b);
|
||||
__m128i d2 = _mm_unpacklo_epi32(g, a);
|
||||
_mm_storeu_si128(_out + i*4, _mm_unpacklo_epi32(d1, d2));
|
||||
_mm_storeu_si128(_out + i*4 + 1, _mm_unpackhi_epi32(d1, d2));
|
||||
d1 = _mm_unpackhi_epi32(r, b);
|
||||
d2 = _mm_unpackhi_epi32(g, a);
|
||||
_mm_storeu_si128(_out + i*4 + 2, _mm_unpacklo_epi32(d1, d2));
|
||||
_mm_storeu_si128(_out + i*4 + 3, _mm_unpackhi_epi32(d1, d2));
|
||||
}
|
||||
count *= 4;
|
||||
}
|
||||
for(size_t i = count; i < s2; i++)
|
||||
{
|
||||
switch(sizeof(T))
|
||||
{
|
||||
case 1:
|
||||
for(uint32_t o=0; o<ch; o++)static_cast<uint8_t*>(out)[i*4 + o] = static_cast<const uint8_t*>(in)[i + o*s2];
|
||||
if(ch==3)static_cast<uint8_t*>(out)[i*4 + 3] = 0xff;
|
||||
break;
|
||||
case 2:
|
||||
for(uint32_t o=0; o<ch; o++)static_cast<uint16_t*>(out)[i*4 + o] = static_cast<const uint16_t*>(in)[i + o*s2];
|
||||
if(ch==3)static_cast<uint16_t*>(out)[i*4 + 3] = 0xffff;
|
||||
break;
|
||||
case 4:
|
||||
for(uint32_t o=0; o<ch; o++)static_cast<uint32_t*>(out)[i*4 + o] = static_cast<const uint32_t*>(in)[i + o*s2];
|
||||
if(ch==3)
|
||||
{
|
||||
if(!std::numeric_limits<T>::is_integer)static_cast<float*>(out)[i*4 + 3] = 1.0;
|
||||
else static_cast<uint32_t*>(out)[i*4 + 3] = 0xffffffff;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template void fromPlanarSSE<uint8_t, 3>(const void *in, void *out, size_t count);
|
||||
template void fromPlanarSSE<uint8_t, 4>(const void *in, void *out, size_t count);
|
||||
template void fromPlanarSSE<uint16_t, 3>(const void *in, void *out, size_t count);
|
||||
template void fromPlanarSSE<uint16_t, 4>(const void *in, void *out, size_t count);
|
||||
template void fromPlanarSSE<uint32_t, 3>(const void *in, void *out, size_t count);
|
||||
template void fromPlanarSSE<uint32_t, 4>(const void *in, void *out, size_t count);
|
||||
template void fromPlanarSSE<float, 3>(const void *in, void *out, size_t count);
|
||||
template void fromPlanarSSE<float, 4>(const void *in, void *out, size_t count);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,985 @@
|
||||
#include "scriptengine.h"
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
#include <QInputDialog>
|
||||
#include <QJsonValue>
|
||||
#include "loadrunable.h"
|
||||
#include "rawimage.h"
|
||||
#include "loadimage.h"
|
||||
#include "batchprocessing.h"
|
||||
#include <fitsio2.h>
|
||||
#include "libxisf.h"
|
||||
#ifdef PLATESOLVER
|
||||
#include "solver.h"
|
||||
#endif // PLATESOLVER
|
||||
|
||||
namespace Script
|
||||
{
|
||||
|
||||
ScriptEngine::ScriptEngine(Database *database, BatchProcessing *parent)
|
||||
: _jsEngine(new QJSEngine(this))
|
||||
, _database(database)
|
||||
, _parent(parent)
|
||||
, _pool(new QThreadPool(this))
|
||||
{
|
||||
QJSValue core = _jsEngine->newQObject(this);
|
||||
_jsEngine->globalObject().setProperty("core", core);
|
||||
QJSValue fitsRecordObject = _jsEngine->newQMetaObject(&FITSRecordModify::staticMetaObject);
|
||||
QJSValue textFile = _jsEngine->newQMetaObject(&TextFile::staticMetaObject);
|
||||
_jsEngine->globalObject().setProperty("FITSRecordModify", fitsRecordObject);
|
||||
_jsEngine->globalObject().setProperty("TextFile", textFile);
|
||||
_semaphore.release(_pool->maxThreadCount());
|
||||
_pool->setThreadPriority(QThread::LowPriority);
|
||||
|
||||
#ifdef PLATESOLVER
|
||||
_solver = new Solver(this);
|
||||
#endif // PLATESOLVER
|
||||
}
|
||||
|
||||
void ScriptEngine::setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir)
|
||||
{
|
||||
_scriptPath = scriptPath;
|
||||
_paths = paths;
|
||||
_outputDir = outputDir + "/";
|
||||
}
|
||||
|
||||
void ScriptEngine::reportError(const QString &message)
|
||||
{
|
||||
_jsEngine->throwError(message);
|
||||
}
|
||||
|
||||
const QString &ScriptEngine::outputDir() const
|
||||
{
|
||||
return _outputDir;
|
||||
}
|
||||
|
||||
void ScriptEngine::interrupt()
|
||||
{
|
||||
#ifdef PLATESOLVER
|
||||
if(_solver)_solver->abort();
|
||||
#endif
|
||||
_jsEngine->setInterrupted(true);
|
||||
}
|
||||
|
||||
void ScriptEngine::logError(const QString &message)
|
||||
{
|
||||
emit newMessage(message, true);
|
||||
}
|
||||
|
||||
void ScriptEngine::log(const QString &message)
|
||||
{
|
||||
emit newMessage(message, false);
|
||||
}
|
||||
|
||||
void ScriptEngine::mark(File *file)
|
||||
{
|
||||
QString path = file->absoluteFilePath();
|
||||
QMetaObject::invokeMethod(_database, [this, path](){ _database->mark(path); }, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void ScriptEngine::unmark(File *file)
|
||||
{
|
||||
QString path = file->absoluteFilePath();
|
||||
QMetaObject::invokeMethod(_database, [this, path](){ _database->unmark(path); }, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
bool ScriptEngine::isMarked(const File *file)
|
||||
{
|
||||
bool ret;
|
||||
QString path = file->absoluteFilePath();
|
||||
QMetaObject::invokeMethod(_database, [this, path](){ return _database->isMarked(path); }, Qt::BlockingQueuedConnection, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getObjects(double ra, double dec, double distance)
|
||||
{
|
||||
QVector<SkyObject> objects;
|
||||
QMetaObject::invokeMethod(_database, [this, ra, dec, distance](){
|
||||
return _database->getObjects(ra - distance, ra + distance, dec - distance, dec + distance); }, Qt::BlockingQueuedConnection, &objects);
|
||||
|
||||
QJSValue ret = newArray(objects.size());
|
||||
qint32 i = 0;
|
||||
for(auto &object : objects)
|
||||
{
|
||||
QJSValue jsObj = newObject();
|
||||
jsObj.setProperty("name", object.name);
|
||||
jsObj.setProperty("name2", object.name2);
|
||||
jsObj.setProperty("ra", object.skyPoint.RA());
|
||||
jsObj.setProperty("dec", object.skyPoint.DEC());
|
||||
jsObj.setProperty("mag", object.mag);
|
||||
ret.setProperty(i++, jsObj);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getObjects(const QJSValue &bounds)
|
||||
{
|
||||
QVector<SkyObject> objects;
|
||||
double minRa = bounds.property("minRA").toNumber();
|
||||
double maxRa = bounds.property("maxRA").toNumber();
|
||||
double minDec = bounds.property("minDEC").toNumber();
|
||||
double maxDec = bounds.property("maxDEC").toNumber();
|
||||
|
||||
QMetaObject::invokeMethod(_database, [this, minRa, maxRa, minDec, maxDec](){
|
||||
return _database->getObjects(minRa, maxRa, minDec, maxDec); }, Qt::BlockingQueuedConnection, &objects);
|
||||
|
||||
QJSValue ret = newArray(objects.size());
|
||||
qint32 i = 0;
|
||||
for(auto &object : objects)
|
||||
{
|
||||
QJSValue jsObj = newObject();
|
||||
jsObj.setProperty("name", object.name);
|
||||
jsObj.setProperty("name2", object.name2);
|
||||
jsObj.setProperty("ra", object.skyPoint.RA());
|
||||
jsObj.setProperty("dec", object.skyPoint.DEC());
|
||||
jsObj.setProperty("mag", object.mag);
|
||||
ret.setProperty(i++, jsObj);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ScriptEngine::setMaxThread(int maxthread)
|
||||
{
|
||||
int newval = std::max(std::min(QThread::idealThreadCount(), maxthread), 1);
|
||||
int oldval = _pool->maxThreadCount();
|
||||
if(newval > oldval)
|
||||
_semaphore.release(newval - oldval);
|
||||
else if(newval < oldval)
|
||||
_semaphore.acquire(oldval - newval);
|
||||
_pool->setMaxThreadCount(newval);
|
||||
}
|
||||
|
||||
void ScriptEngine::sync()
|
||||
{
|
||||
_pool->waitForDone();
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getString(const QString &label, const QString &text) const
|
||||
{
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getString", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(QString, text));
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getInt(const QString &label, int value)
|
||||
{
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getInt", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(int, value));
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getFloat(const QString &label, double value, int decimals) const
|
||||
{
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getFloat", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, label), Q_ARG(double, value), Q_ARG(int, decimals));
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getItem(const QStringList &items, const QString &label, int current) const
|
||||
{
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "getItem", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QStringList, items), Q_ARG(QString, label), Q_ARG(int, current));
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::question(const QString &question, const QStringList &buttons, const QString &title) const
|
||||
{
|
||||
QJSValue ret;
|
||||
QMetaObject::invokeMethod(_parent, "question", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QJSValue, ret), Q_ARG(QString, question), Q_ARG(QStringList, buttons), Q_ARG(QString, title));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ScriptEngine::plot(const QJSValue &graph)
|
||||
{
|
||||
QVariant graphV = graph.toVariant(QJSValue::ConvertJSObjects);
|
||||
if(graphV.isValid())
|
||||
QMetaObject::invokeMethod(_parent, "plot", Qt::QueuedConnection, Q_ARG(QVariant, graphV));
|
||||
else
|
||||
logError("Invalid value to be plotted");
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::openFile(const QString &fileName, const QString &mode)
|
||||
{
|
||||
QFileInfo info(fileName);
|
||||
if(!info.isAbsolute())
|
||||
info = QFileInfo(outputDir() + fileName);
|
||||
|
||||
TextFile *textFile = new TextFile;
|
||||
if(textFile->open(info.absoluteFilePath(), mode))
|
||||
{
|
||||
return _jsEngine->newQObject(textFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to open file " + fileName);
|
||||
delete textFile;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptEngine::convert(File *file, QString &outpath, const QString &format, const QVariantMap ¶ms, bool async)
|
||||
{
|
||||
QString path;
|
||||
QDir dir(_outputDir);
|
||||
QFileInfo info(outpath);
|
||||
QString suffix = info.suffix();
|
||||
if(info.isAbsolute())
|
||||
path = info.absolutePath();
|
||||
else
|
||||
path = dir.absoluteFilePath(outpath);
|
||||
|
||||
QString f = format.toLower();
|
||||
if(f != "xisf" && f != "fits" && f != "png" && f != "bmp" && f != "jpg" && f != "tiff")
|
||||
{
|
||||
logError("Output format must be one of xisf fits jpg png bmp tiff");
|
||||
return false;
|
||||
}
|
||||
|
||||
info.setFile(path);
|
||||
outpath = info.absolutePath() + "/" + info.completeBaseName() + "." + f;
|
||||
if(async)
|
||||
{
|
||||
_semaphore.acquire();
|
||||
_pool->start(new ConvertRunable(file->absoluteFilePath(), outpath, f, params, &_semaphore));
|
||||
}
|
||||
else
|
||||
{
|
||||
ConvertRunable crun(file->absoluteFilePath(), outpath, f, params, nullptr);
|
||||
crun.run();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef PLATESOLVER
|
||||
void ScriptEngine::setSolverProfile(int index)
|
||||
{
|
||||
index -= 1;
|
||||
if(_solver && index >= SSolver::Parameters::DEFAULT && index < SSolver::Parameters::BIG_STARS)
|
||||
{
|
||||
_solver->setParameters((SSolver::Parameters::ParametersProfile)index);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::setSolverProfile(const QVariantMap &profile)
|
||||
{
|
||||
if(_solver)
|
||||
{
|
||||
SSolver::Parameters params = SSolver::Parameters::convertFromMap(profile);
|
||||
_solver->setParameters(params);
|
||||
}
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::getSolverProfile() const
|
||||
{
|
||||
if(_solver)
|
||||
{
|
||||
QMap<QString, QVariant> params = SSolver::Parameters::convertToMap(_solver->getProfile());
|
||||
QJSValue ret = _jsEngine->newObject();
|
||||
for(auto i = params.begin(); i != params.end(); i++)
|
||||
{
|
||||
switch(i.value().metaType().id())
|
||||
{
|
||||
case QMetaType::Int:
|
||||
ret.setProperty(i.key(), i.value().toInt());
|
||||
break;
|
||||
case QMetaType::Double:
|
||||
ret.setProperty(i.key(), i.value().toDouble());
|
||||
break;
|
||||
case QMetaType::Bool:
|
||||
ret.setProperty(i.key(), i.value().toBool());
|
||||
break;
|
||||
case QMetaType::QString:
|
||||
ret.setProperty(i.key(), i.value().toString());
|
||||
break;
|
||||
default:
|
||||
qWarning() << "unhandled metatype" << i.key() << i.value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QJSValue();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::setStartingSolution(const QJSValue &solution)
|
||||
{
|
||||
if(solution.isObject())
|
||||
{
|
||||
if(solution.hasProperty("ra") && solution.hasProperty("dec") && solution.property("ra").isNumber() && solution.property("dec").isNumber())
|
||||
_solver->setSearchPosition(solution.property("ra").toNumber() / 15.0, solution.property("dec").toNumber());
|
||||
|
||||
if(solution.hasProperty("pixscale") && solution.property("pixscale").isNumber())
|
||||
{
|
||||
double scale = solution.property("pixscale").toNumber();
|
||||
_solver->setSearchScale(scale * 0.8, scale * 1.2, SSolver::ScaleUnits::ARCSEC_PER_PIX);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_solver->clearStartingPositionAndScale();
|
||||
}
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::solveImage(File *file, bool updateHeader)
|
||||
{
|
||||
QString path = file->absoluteFilePath();
|
||||
QJSValue ret = newObject();
|
||||
|
||||
if(_solver->loadImage(path))
|
||||
{
|
||||
if(_solver->solveImage(true))
|
||||
{
|
||||
auto solution = _solver->getSolution();
|
||||
ret.setProperty("fieldWidth", solution.fieldWidth);
|
||||
ret.setProperty("fieldHeight", solution.fieldHeight);
|
||||
ret.setProperty("ra", solution.ra);
|
||||
ret.setProperty("dec", solution.dec);
|
||||
ret.setProperty("orientation", solution.orientation);
|
||||
ret.setProperty("pixscale", solution.pixscale);
|
||||
ret.setProperty("parity", solution.parity == FITSImage::Parity::POSITIVE);
|
||||
ret.setProperty("raError", solution.raError);
|
||||
ret.setProperty("decError", solution.decError);
|
||||
if(updateHeader)
|
||||
{
|
||||
QString error;
|
||||
if(!_solver->updateHeader(error))
|
||||
logError(error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to plate solve image " + path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to load image " + path);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::extractStars(File *file, bool hfr)
|
||||
{
|
||||
QJSValue ret;
|
||||
QString path = file->absoluteFilePath();
|
||||
if(_solver->loadImage(path))
|
||||
{
|
||||
if(_solver->extractSources(hfr, true))
|
||||
{
|
||||
auto stars = _solver->getStars();
|
||||
ret = newArray(stars.size());
|
||||
int i = 0;
|
||||
for(auto &star : stars)
|
||||
{
|
||||
QJSValue starj = newObject();
|
||||
starj.setProperty("x", star.x);
|
||||
starj.setProperty("y", star.y);
|
||||
starj.setProperty("mag", star.mag);
|
||||
starj.setProperty("flux", star.flux);
|
||||
starj.setProperty("peak", star.peak);
|
||||
starj.setProperty("HFR", star.HFR);
|
||||
starj.setProperty("a", star.a);
|
||||
starj.setProperty("b", star.b);
|
||||
starj.setProperty("theta", star.theta);
|
||||
starj.setProperty("ra", star.ra);
|
||||
starj.setProperty("dec", star.dec);
|
||||
starj.setProperty("numPixels", star.numPixels);
|
||||
ret.setProperty(i++, starj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to extract sources from " + path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("Failed to load image " + path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif // PLATESOLVER
|
||||
|
||||
QJSValue ScriptEngine::newObject()
|
||||
{
|
||||
return _jsEngine->newObject();
|
||||
}
|
||||
|
||||
QJSValue ScriptEngine::newArray(uint size)
|
||||
{
|
||||
return _jsEngine->newArray(size);
|
||||
}
|
||||
|
||||
void ScriptEngine::run()
|
||||
{
|
||||
QJSValue jsPaths = _jsEngine->newArray(_paths.size());
|
||||
for(qsizetype i=0; i<_paths.size(); i++)
|
||||
jsPaths.setProperty(i, _jsEngine->newQObject(new File(_paths[i].first, _paths[i].second, this)));
|
||||
|
||||
_jsEngine->globalObject().setProperty("files", jsPaths);
|
||||
|
||||
QFile scriptFile(_scriptPath);
|
||||
if(!scriptFile.open(QIODevice::ReadOnly))
|
||||
{
|
||||
emit newMessage("Failed to open " + _scriptPath, true);
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream stream(&scriptFile);
|
||||
QString contents = stream.readAll();
|
||||
scriptFile.close();
|
||||
QJSValue result = _jsEngine->evaluate(contents, _scriptPath);
|
||||
qDebug() << result.isError() << result.toString();
|
||||
_pool->waitForDone();
|
||||
if(result.isError())
|
||||
{
|
||||
QString error = result.property("name").toString() + " on line " + result.property("lineNumber").toString() + " : " + result.toString();
|
||||
error += "\n" + result.property("stack").toString();
|
||||
emit newMessage(error, true);
|
||||
}
|
||||
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void File::loadFitsKeywords()
|
||||
{
|
||||
if(!_fitsKeywordsLoaded)
|
||||
{
|
||||
_fitsKeywordsLoaded = true;
|
||||
ImageInfoData info;
|
||||
if(suffix().toLower() == "xisf")
|
||||
{
|
||||
readXISFHeader(_path, info);
|
||||
}
|
||||
else if(suffix().toLower() == "fits" || suffix().toLower() == "fit" || suffix().toLower() == "fz")
|
||||
{
|
||||
readFITSHeader(_path, info);
|
||||
}
|
||||
else return;
|
||||
|
||||
_wcs = info.wcs;
|
||||
|
||||
for(auto &record : info.fitsHeader)
|
||||
{
|
||||
_fitsKeywords.append(record.key);
|
||||
_fitsRecords.insert(record.key, record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool File::mkpath(const QString &path) const
|
||||
{
|
||||
QFileInfo info(path);
|
||||
if(!info.isRelative())
|
||||
{
|
||||
_engine->logError("Destination path is not relative");
|
||||
return false;
|
||||
}
|
||||
QDir dir(_engine->outputDir());
|
||||
if(dir.mkpath(info.path()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_engine->logError("Failed to create dir " + info.path());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
File::File(const QString &path, Script::ScriptEngine *engine) : File(path, QString(), engine)
|
||||
{
|
||||
}
|
||||
|
||||
File::File(const QString &path, const QString &root, ScriptEngine *engine) :
|
||||
_engine(engine),
|
||||
_path(path),
|
||||
_root(root),
|
||||
_info(path)
|
||||
{
|
||||
}
|
||||
|
||||
QString File::fileName() const
|
||||
{
|
||||
return _info.fileName();
|
||||
}
|
||||
|
||||
QString File::absoluteFilePath() const
|
||||
{
|
||||
return _info.absoluteFilePath();
|
||||
}
|
||||
|
||||
QString File::absolutePath() const
|
||||
{
|
||||
return _info.absolutePath();
|
||||
}
|
||||
|
||||
QString File::relativeFilePath() const
|
||||
{
|
||||
QDir dir(_root);
|
||||
return dir.relativeFilePath(_info.absoluteFilePath());
|
||||
}
|
||||
|
||||
QString File::relativePath() const
|
||||
{
|
||||
QDir dir(_root);
|
||||
return dir.relativeFilePath(_info.absolutePath());
|
||||
}
|
||||
|
||||
QString File::baseName() const
|
||||
{
|
||||
return _info.baseName();
|
||||
}
|
||||
|
||||
QString File::completeBaseName() const
|
||||
{
|
||||
return _info.completeBaseName();
|
||||
}
|
||||
|
||||
QString File::suffix() const
|
||||
{
|
||||
return _info.suffix();
|
||||
}
|
||||
|
||||
qint64 File::size() const
|
||||
{
|
||||
return _info.size();
|
||||
}
|
||||
|
||||
QStringList File::fitsKeywords()
|
||||
{
|
||||
loadFitsKeywords();
|
||||
return _fitsKeywords;
|
||||
}
|
||||
|
||||
QString File::fitsValue(const QString &key)
|
||||
{
|
||||
loadFitsKeywords();
|
||||
if(_fitsRecords.contains(key))
|
||||
return _fitsRecords[key].value.toString();
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
QJSValue File::fitsValues(const QString &key)
|
||||
{
|
||||
loadFitsKeywords();
|
||||
if(_fitsRecords.contains(key))
|
||||
{
|
||||
QList<FITSRecord> values = _fitsRecords.values(key);
|
||||
QJSValue array = _engine->newArray(values.size());
|
||||
for(qsizetype i=0; i<values.size(); i++)
|
||||
array.setProperty(i, values[i].value.toString());
|
||||
return array;
|
||||
}
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
QJSValue File::fitsRecords()
|
||||
{
|
||||
loadFitsKeywords();
|
||||
|
||||
QJSValue array = _engine->newArray(_fitsRecords.size());
|
||||
uint i = 0;
|
||||
for(auto &record : _fitsRecords)
|
||||
{
|
||||
QJSValue item = _engine->newObject();
|
||||
item.setProperty("key", QString::fromUtf8(record.key));
|
||||
item.setProperty("value", record.value.toString());
|
||||
item.setProperty("comment", QString::fromUtf8(record.comment));
|
||||
item.setProperty("xisf", record.xisf);
|
||||
array.setProperty(i++, item);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
||||
{
|
||||
_fitsKeywordsLoaded = false;
|
||||
_fitsKeywords.clear();
|
||||
|
||||
if(QRegularExpression("(fits?|fz|fts)", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch())
|
||||
{
|
||||
fitsfile *file;
|
||||
int status = 0;
|
||||
QString path = makeUNCPath(_path);
|
||||
fits_open_diskfile(&file, path.toLocal8Bit().data(), READWRITE, &status);
|
||||
int num = 0;
|
||||
fits_get_num_hdus(file, &num, &status);
|
||||
if(status)
|
||||
{
|
||||
if(_engine)_engine->newMessage("Failed to open FITS file", true);
|
||||
return false;
|
||||
}
|
||||
int imgtype;
|
||||
int naxis;
|
||||
long naxes[3] = {0};
|
||||
int type = -1;
|
||||
for(int i=1; i <= num; i++)
|
||||
{
|
||||
fits_movabs_hdu(file, i, IMAGE_HDU, &status);
|
||||
fits_get_hdu_type(file, &type, &status);
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
||||
if(type == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
||||
break;
|
||||
if(i == num)return false;
|
||||
}
|
||||
|
||||
for(auto &remove : modify->_remove)
|
||||
{
|
||||
int status = 0;//we ignore errors from here
|
||||
fits_delete_key(file, remove.toLatin1().data(), &status);
|
||||
}
|
||||
for(auto &record : modify->_update)
|
||||
{
|
||||
switch(record.value.typeId())
|
||||
{
|
||||
case QMetaType::Bool:
|
||||
{
|
||||
int val = record.value.toBool();
|
||||
fits_update_key(file, TLOGICAL, record.key.data(), &val, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
case QMetaType::Int:
|
||||
case QMetaType::UInt:
|
||||
{
|
||||
long long val = record.value.toLongLong();
|
||||
fits_update_key(file, TLONGLONG, record.key.data(), &val, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
case QMetaType::QString:
|
||||
{
|
||||
QByteArray val = record.value.toString().toLatin1();
|
||||
fits_update_key(file, TSTRING, record.key.data(), val.isEmpty() ? nullptr : val.data(), record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
case QMetaType::Float:
|
||||
case QMetaType::Double:
|
||||
{
|
||||
double val = record.value.toDouble();
|
||||
fits_update_key(file, TDOUBLE, record.key.data(), &val, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if(_engine)_engine->newMessage("Unknown type for KEY " + record.key, true);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
if(status)
|
||||
{
|
||||
char error[100];
|
||||
fits_get_errstatus(status, error);
|
||||
if(_engine)_engine->newMessage(QString("Error when updating KEY %1 %2").arg(record.key).arg(error), true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for(auto &record : modify->_add)
|
||||
{
|
||||
switch(record.value.typeId())
|
||||
{
|
||||
case QMetaType::Bool:
|
||||
{
|
||||
int val = record.value.toBool();
|
||||
fits_write_key(file, TLOGICAL, record.key.data(), &val, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
case QMetaType::Int:
|
||||
case QMetaType::UInt:
|
||||
{
|
||||
long long val = record.value.toLongLong();
|
||||
fits_write_key(file, TLONGLONG, record.key.data(), &val, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
case QMetaType::QString:
|
||||
{
|
||||
QByteArray val = record.value.toString().toLatin1();
|
||||
fits_write_key(file, TSTRING, record.key.data(), val.isEmpty() ? nullptr : val.data(), record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
case QMetaType::Float:
|
||||
case QMetaType::Double:
|
||||
{
|
||||
double val = record.value.toDouble();
|
||||
fits_write_key(file, TDOUBLE, record.key.data(), &val, record.comment.isEmpty() ? nullptr : record.comment.data(), &status);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
if(_engine)_engine->newMessage("Unknown type for KEY " + record.key, true);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
if(status)
|
||||
{
|
||||
char error[100];
|
||||
fits_get_errstatus(status, error);
|
||||
if(_engine)_engine->newMessage(QString("Error when adding KEY {} {}").arg(record.key).arg(error), true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
fits_close_file(file, &status);
|
||||
|
||||
return status == 0;
|
||||
}
|
||||
else if(suffix().toLower() == "xisf")
|
||||
{
|
||||
try
|
||||
{
|
||||
LibXISF::XISFModify modifyXISF;
|
||||
QString in = makeUNCPath(absoluteFilePath());
|
||||
QString out = in + "~";
|
||||
modifyXISF.open(in.toLocal8Bit().data());
|
||||
qDebug() << "modify" << in << out;
|
||||
|
||||
for(auto &remove : modify->_remove)
|
||||
modifyXISF.removeFITSKeyword(0, remove.toStdString());
|
||||
|
||||
for(auto &record : modify->_update)
|
||||
modifyXISF.updateFITSKeyword(0, {record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()}, true);
|
||||
|
||||
for(auto &record : modify->_add)
|
||||
modifyXISF.addFITSKeyword(0, {record.key.toStdString(), record.value.toString().toStdString(), record.comment.toStdString()});
|
||||
|
||||
modifyXISF.save(out.toLocal8Bit().toStdString());
|
||||
modifyXISF.close();
|
||||
std::filesystem::rename(out.toLocal8Bit().toStdString(), in.toLocal8Bit().toStdString());
|
||||
return true;
|
||||
}
|
||||
catch(std::filesystem::filesystem_error &err)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch(LibXISF::Error &err)
|
||||
{
|
||||
if(_engine)_engine->newMessage("Failed to modify file " + _path + " " + err.what(), true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool File::isMarked() const
|
||||
{
|
||||
return _engine->isMarked(this);
|
||||
}
|
||||
|
||||
File* File::copy(const QString &newpath) const
|
||||
{
|
||||
if(mkpath(newpath))
|
||||
{
|
||||
if(QFile::copy(_path, _engine->outputDir() + newpath))
|
||||
return new File(_engine->outputDir() + newpath, _engine);
|
||||
_engine->logError("Failed copy to " + newpath);
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool File::move(const QString &newpath)
|
||||
{
|
||||
if(mkpath(newpath))
|
||||
{
|
||||
if(QFile::rename(_path, _engine->outputDir() + newpath))
|
||||
{
|
||||
_path = _engine->outputDir() + newpath;
|
||||
return true;
|
||||
}
|
||||
_engine->logError("Failed move to " + newpath);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
File* File::convert(const QString &outpath, const QString &format, const QVariantMap ¶ms)
|
||||
{
|
||||
QString path = outpath;
|
||||
if(_engine->convert(this, path, format, params, false))
|
||||
return new File(path, _engine);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
File* File::convertAsync(const QString &outpath, const QString &format, const QVariantMap ¶ms)
|
||||
{
|
||||
QString path = outpath;
|
||||
if(_engine->convert(this, path, format, params, true))
|
||||
return new File(path, _engine);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QJSValue File::stats()
|
||||
{
|
||||
if(_stats.isUndefined())
|
||||
{
|
||||
ImageInfoData info;
|
||||
std::shared_ptr<RawImage> rawImage;
|
||||
loadImage(_path, info, rawImage, 0);
|
||||
rawImage->calcStats();
|
||||
RawImage::Stats stats = rawImage->imageStats();
|
||||
_stats = _engine->newObject();
|
||||
_stats.setProperty("mean", stats.m_mean[0]);
|
||||
_stats.setProperty("stddev", stats.m_stdDev[0]);
|
||||
_stats.setProperty("median", stats.m_median[0]);
|
||||
_stats.setProperty("min", stats.m_min[0]);
|
||||
_stats.setProperty("max", stats.m_max[0]);
|
||||
_stats.setProperty("mad", stats.m_mean[0]);
|
||||
}
|
||||
return _stats;
|
||||
}
|
||||
|
||||
QJSValue File::calculatedBounds()
|
||||
{
|
||||
QJSValue ret = _engine->newObject();
|
||||
loadFitsKeywords();
|
||||
if(_wcs)
|
||||
{
|
||||
double minRa, maxRa, minDec, maxDec, crVal1, crVal2;
|
||||
_wcs->calculateBounds(minRa, maxRa, minDec, maxDec, crVal1, crVal2);
|
||||
ret.setProperty("minRA", minRa);
|
||||
ret.setProperty("maxRA", maxRa);
|
||||
ret.setProperty("minDEC", minDec);
|
||||
ret.setProperty("maxDEC", maxDec);
|
||||
ret.setProperty("crVal1", crVal1);
|
||||
ret.setProperty("crVal2", crVal2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef PLATESOLVER
|
||||
QJSValue File::solve(bool updateHeader)
|
||||
{
|
||||
if(_solution.isUndefined() || updateHeader)
|
||||
_solution = _engine->solveImage(this, updateHeader);
|
||||
|
||||
return _solution;
|
||||
}
|
||||
|
||||
QJSValue File::extractStars(bool hfr)
|
||||
{
|
||||
if(_stars.isUndefined())
|
||||
_stars = _engine->extractStars(this, hfr);
|
||||
|
||||
return _stars;
|
||||
}
|
||||
#endif // PLATESOLVER
|
||||
|
||||
ScriptEngineThread::ScriptEngineThread(Database *database, BatchProcessing *parent) : QObject(parent)
|
||||
{
|
||||
_thread = new QThread();
|
||||
_thread->setObjectName("ScriptEngine");
|
||||
_engine = new ScriptEngine(database, parent);
|
||||
_engine->moveToThread(_thread);
|
||||
connect(_engine, &ScriptEngine::finished, _thread, &QThread::quit);
|
||||
connect(_engine, &ScriptEngine::newMessage, this, &ScriptEngineThread::newMessage);
|
||||
connect(_thread, &QThread::started, _engine, &ScriptEngine::run);
|
||||
connect(_thread, &QThread::finished, _engine, &ScriptEngine::deleteLater);
|
||||
connect(_engine, &ScriptEngine::destroyed, [this](){ _engine = nullptr; });
|
||||
connect(_thread, &QThread::finished, _thread, &QThread::deleteLater);
|
||||
connect(_thread, &QThread::finished, this, &ScriptEngineThread::finished);
|
||||
}
|
||||
|
||||
ScriptEngineThread::~ScriptEngineThread()
|
||||
{
|
||||
if(_engine)_engine->interrupt();
|
||||
}
|
||||
|
||||
void ScriptEngineThread::setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir)
|
||||
{
|
||||
_engine->setParams(scriptPath, paths, outputDir);
|
||||
}
|
||||
|
||||
void ScriptEngineThread::start()
|
||||
{
|
||||
_thread->start();
|
||||
}
|
||||
|
||||
void ScriptEngineThread::interrupt()
|
||||
{
|
||||
if(_engine)_engine->interrupt();
|
||||
}
|
||||
|
||||
void FITSRecordModify::removeKeyword(const QString &key)
|
||||
{
|
||||
if(!_remove.contains(key))
|
||||
_remove.append(key);
|
||||
}
|
||||
|
||||
void FITSRecordModify::updateKeyword(const QString &key, const QVariant &value, const QString &comment)
|
||||
{
|
||||
_update.append({key.toLatin1(), value, comment.toLatin1()});
|
||||
}
|
||||
|
||||
void FITSRecordModify::addKeyword(const QString &key, const QVariant &value, const QString &comment)
|
||||
{
|
||||
_update.append({key.toLatin1(), value, comment.toLatin1()});
|
||||
}
|
||||
|
||||
bool TextFile::open(const QString &path, const QString &mode)
|
||||
{
|
||||
_fr.setFileName(path);
|
||||
QIODevice::OpenMode openMode;
|
||||
if(mode == "r")
|
||||
openMode = QIODevice::ReadOnly;
|
||||
else if(mode == "w")
|
||||
openMode = QIODevice::WriteOnly;
|
||||
else if(mode == "a")
|
||||
openMode = QIODevice::WriteOnly | QIODevice::Append;
|
||||
else if(mode == "r+")
|
||||
openMode = QIODevice::ReadWrite | QIODevice::ExistingOnly;
|
||||
else if(mode == "w+")
|
||||
openMode = QIODevice::ReadWrite;
|
||||
else if(mode == "a+")
|
||||
openMode = QIODevice::ReadWrite | QIODevice::Append;
|
||||
else
|
||||
return false;
|
||||
|
||||
openMode |= QIODevice::Text;//always open as text
|
||||
return _fr.open(openMode);
|
||||
}
|
||||
|
||||
void TextFile::write(const QString &data)
|
||||
{
|
||||
_fr.write(data.toUtf8());
|
||||
}
|
||||
|
||||
QString TextFile::read(int maxlen)
|
||||
{
|
||||
QByteArray data = _fr.read(maxlen);
|
||||
return data;
|
||||
}
|
||||
|
||||
QString TextFile::readLine()
|
||||
{
|
||||
QByteArray data = _fr.readLine();
|
||||
return QString::fromUtf8(data);
|
||||
}
|
||||
|
||||
QString TextFile::readAll()
|
||||
{
|
||||
QByteArray data = _fr.readAll();
|
||||
return QString::fromUtf8(data);
|
||||
}
|
||||
|
||||
bool TextFile::seek(qint64 offset)
|
||||
{
|
||||
return _fr.seek(offset);
|
||||
}
|
||||
|
||||
qint64 TextFile::pos()
|
||||
{
|
||||
return _fr.pos();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
#ifndef SCRIPTENGINE_H
|
||||
#define SCRIPTENGINE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QJSEngine>
|
||||
#include <QFileInfo>
|
||||
#include <QThread>
|
||||
#include <QThreadPool>
|
||||
#include <QSemaphore>
|
||||
#include "database.h"
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class BatchProcessing;
|
||||
class Solver;
|
||||
|
||||
namespace Script
|
||||
{
|
||||
|
||||
class File;
|
||||
|
||||
class ScriptEngine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QJSEngine *_jsEngine;
|
||||
Database *_database;
|
||||
BatchProcessing *_parent;
|
||||
QThreadPool *_pool;
|
||||
QSemaphore _semaphore;
|
||||
QString _scriptPath;
|
||||
QString _outputDir;
|
||||
QList<QPair<QString, QString>> _paths;
|
||||
Solver *_solver = nullptr;
|
||||
public:
|
||||
explicit ScriptEngine(Database *database, BatchProcessing *parent = nullptr);
|
||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
||||
void reportError(const QString &message);
|
||||
const QString& outputDir() const;
|
||||
void interrupt();
|
||||
void logError(const QString &message);
|
||||
Q_INVOKABLE void log(const QString &message);
|
||||
Q_INVOKABLE void mark(File *file);
|
||||
Q_INVOKABLE void unmark(File *file);
|
||||
Q_INVOKABLE bool isMarked(const File *file);
|
||||
Q_INVOKABLE QJSValue getObjects(double ra, double dec, double distance);
|
||||
Q_INVOKABLE QJSValue getObjects(const QJSValue &bounds);
|
||||
Q_INVOKABLE void setMaxThread(int maxthread);
|
||||
Q_INVOKABLE void sync();
|
||||
Q_INVOKABLE QJSValue getString(const QString &label = QString(), const QString &text = QString()) const;
|
||||
Q_INVOKABLE QJSValue getInt(const QString &label = QString(), int value = 0);
|
||||
Q_INVOKABLE QJSValue getFloat(const QString &label = QString(), double value = 0, int decimals = 3) const;
|
||||
Q_INVOKABLE QJSValue getItem(const QStringList &items, const QString &label = "", int current = 0) const;
|
||||
Q_INVOKABLE QJSValue question(const QString &question, const QStringList &buttons = {"ok"}, const QString &title = "") const;
|
||||
Q_INVOKABLE void plot(const QJSValue &pointsArray);
|
||||
Q_INVOKABLE QJSValue openFile(const QString &fileName, const QString &mode = "r");
|
||||
bool convert(File *file, QString &outpath, const QString &format, const QVariantMap ¶ms, bool async);
|
||||
#ifdef PLATESOLVER
|
||||
Q_INVOKABLE void setSolverProfile(int index);
|
||||
Q_INVOKABLE void setSolverProfile(const QVariantMap &profile);
|
||||
Q_INVOKABLE QJSValue getSolverProfile() const;
|
||||
Q_INVOKABLE void setStartingSolution(const QJSValue &solution = QJSValue());
|
||||
QJSValue solveImage(File *file, bool updateHeader);
|
||||
QJSValue extractStars(File *file, bool hfr);
|
||||
#endif // PLATESOLVER
|
||||
QJSValue newObject();
|
||||
QJSValue newArray(uint size);
|
||||
public slots:
|
||||
void run();
|
||||
signals:
|
||||
void newMessage(const QString &message, bool error);
|
||||
void finished();
|
||||
};
|
||||
|
||||
class ScriptEngineThread : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QThread *_thread;
|
||||
ScriptEngine *_engine;
|
||||
public:
|
||||
ScriptEngineThread(Database *database, BatchProcessing *parent = nullptr);
|
||||
~ScriptEngineThread();
|
||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
||||
void start();
|
||||
void interrupt();
|
||||
signals:
|
||||
void newMessage(const QString &message, bool error);
|
||||
void finished();
|
||||
};
|
||||
|
||||
class FITSRecordModify;
|
||||
|
||||
class File : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
ScriptEngine *_engine = nullptr;
|
||||
QString _path;
|
||||
QString _root;
|
||||
QFileInfo _info;
|
||||
bool _fitsKeywordsLoaded = false;
|
||||
QStringList _fitsKeywords;
|
||||
QMultiHash<QString, FITSRecord> _fitsRecords;
|
||||
std::shared_ptr<WCSDataT> _wcs;
|
||||
void loadFitsKeywords();
|
||||
bool mkpath(const QString &path) const;
|
||||
QJSValue _stats;
|
||||
QJSValue _solution;
|
||||
QJSValue _stars;
|
||||
public:
|
||||
explicit File(const QString &path, ScriptEngine *engine);
|
||||
explicit File(const QString &path, const QString &root, ScriptEngine *engine);
|
||||
Q_INVOKABLE QString fileName() const;
|
||||
Q_INVOKABLE QString absoluteFilePath() const;
|
||||
Q_INVOKABLE QString absolutePath() const;
|
||||
Q_INVOKABLE QString relativeFilePath() const;
|
||||
Q_INVOKABLE QString relativePath() const;
|
||||
Q_INVOKABLE QString baseName() const;
|
||||
Q_INVOKABLE QString completeBaseName() const;
|
||||
Q_INVOKABLE QString suffix() const;
|
||||
Q_INVOKABLE qint64 size() const;
|
||||
Q_INVOKABLE QStringList fitsKeywords();
|
||||
Q_INVOKABLE QString fitsValue(const QString &key);
|
||||
Q_INVOKABLE QJSValue fitsValues(const QString &key);
|
||||
Q_INVOKABLE QJSValue fitsRecords();
|
||||
Q_INVOKABLE bool modifyFITSRecords(const FITSRecordModify *modify);
|
||||
Q_INVOKABLE bool isMarked() const;
|
||||
Q_INVOKABLE File* copy(const QString &newpath) const;
|
||||
Q_INVOKABLE bool move(const QString &newpath);
|
||||
Q_INVOKABLE File* convert(const QString &outpath, const QString &format, const QVariantMap ¶ms = QVariantMap());
|
||||
Q_INVOKABLE File* convertAsync(const QString &outpath, const QString &format, const QVariantMap ¶ms = QVariantMap());
|
||||
Q_INVOKABLE QJSValue stats();
|
||||
Q_INVOKABLE QJSValue calculatedBounds();
|
||||
#ifdef PLATESOLVER
|
||||
Q_INVOKABLE QJSValue solve(bool updateHeader = false);
|
||||
Q_INVOKABLE QJSValue extractStars(bool hfr);
|
||||
#endif // PLATESOLVER
|
||||
};
|
||||
|
||||
class FITSRecordModify : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QStringList _remove;
|
||||
QVector<FITSRecord> _update;
|
||||
QVector<FITSRecord> _add;
|
||||
|
||||
friend class File;
|
||||
public:
|
||||
Q_INVOKABLE FITSRecordModify(){};
|
||||
Q_INVOKABLE void removeKeyword(const QString &key);
|
||||
Q_INVOKABLE void updateKeyword(const QString &key, const QVariant &value, const QString &comment = QString());
|
||||
Q_INVOKABLE void addKeyword(const QString &key, const QVariant &value, const QString &comment = QString());
|
||||
};
|
||||
|
||||
class TextFile : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QFile _fr;
|
||||
public:
|
||||
bool open(const QString &path, const QString &mode);
|
||||
Q_INVOKABLE void write(const QString &data);
|
||||
Q_INVOKABLE QString read(int maxlen);
|
||||
Q_INVOKABLE QString readLine();
|
||||
Q_INVOKABLE QString readAll();
|
||||
Q_INVOKABLE bool seek(qint64 offset);
|
||||
Q_INVOKABLE qint64 pos();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // SCRIPTENGINE_H
|
||||
@@ -0,0 +1,240 @@
|
||||
#include "settingsdialog.h"
|
||||
#include <QFormLayout>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QSettings>
|
||||
#include <QApplication>
|
||||
#include <QProcess>
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
#include <QPushButton>
|
||||
#include <QLineEdit>
|
||||
#include <QColorDialog>
|
||||
#include "rawimage.h"
|
||||
|
||||
extern int DEFAULT_WIDTH;
|
||||
extern double SATURATION;
|
||||
extern int FILTERING;
|
||||
extern bool BESTFIT;
|
||||
extern QMap<QString, QColor> headerHighlight;
|
||||
|
||||
class EvenNumber : public QSpinBox
|
||||
{
|
||||
public:
|
||||
explicit EvenNumber(QWidget *parent) : QSpinBox(parent){}
|
||||
protected:
|
||||
QValidator::State validate(QString &text, int &) const
|
||||
{
|
||||
bool ok;
|
||||
int val = text.toInt(&ok);
|
||||
if(ok && (val & 1) == 0)return QValidator::Acceptable;
|
||||
if(ok)return QValidator::Intermediate;
|
||||
return QValidator::Invalid;
|
||||
}
|
||||
void fixup(QString &input) const
|
||||
{
|
||||
bool ok;
|
||||
int val = input.toInt(&ok);
|
||||
val -= val & 1;
|
||||
input = QString::number(val);
|
||||
}
|
||||
};
|
||||
|
||||
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
QFormLayout *layout = new QFormLayout(this);
|
||||
setWindowTitle(tr("Settings"));
|
||||
|
||||
QSettings settings;
|
||||
|
||||
m_preloadImages = new QSpinBox(this);
|
||||
m_preloadImages->setRange(0, 32);
|
||||
m_preloadImages->setValue(settings.value("settings/preloadimagecount", DEFAULT_WIDTH).toInt());
|
||||
m_preloadImages->setToolTip(tr("How many images are preloaded before and after current image."));
|
||||
|
||||
m_thumSize = new EvenNumber(this);
|
||||
m_thumSize->setRange(64, 512);
|
||||
m_thumSize->setSingleStep(2);
|
||||
m_thumSize->setValue(settings.value("settings/thumnailsize", THUMB_SIZE).toInt());
|
||||
m_thumSize->setToolTip(tr("Thumbnail size in pixels"));
|
||||
|
||||
m_saturation = new QDoubleSpinBox(this);
|
||||
m_saturation->setMinimum(0);
|
||||
m_saturation->setMaximum(100);
|
||||
m_saturation->setSuffix(" %");
|
||||
m_saturation->setValue(settings.value("settings/saturation", SATURATION * 100.0).toDouble());
|
||||
m_saturation->setToolTip(tr("Set threshold value that is considered saturated when showing statistics.\nFor RAW files you may set 22%"));
|
||||
|
||||
m_slideShowTime = new QDoubleSpinBox(this);
|
||||
m_slideShowTime->setMinimum(0.01);
|
||||
m_slideShowTime->setMaximum(10);
|
||||
m_slideShowTime->setSuffix(" s");
|
||||
m_slideShowTime->setValue(settings.value("settings/slideshowtime", 1.0).toDouble());
|
||||
m_slideShowTime->setSingleStep(0.1);
|
||||
|
||||
m_useNativeDialog = new QCheckBox(tr("Don't use native file dialog"), this);
|
||||
m_useNativeDialog->setChecked(QApplication::testAttribute(Qt::AA_DontUseNativeDialogs));
|
||||
|
||||
m_filtering = new QComboBox(this);
|
||||
m_filtering->addItems({tr("Nearest"), tr("Linear"), tr("Cubic")});
|
||||
m_filtering->setCurrentIndex(FILTERING);
|
||||
|
||||
m_qualityThumbnail = new QCheckBox(tr("Smooth thumbnails"), this);
|
||||
m_qualityThumbnail->setChecked(QUALITY_RESIZE);
|
||||
m_qualityThumbnail->setToolTip(tr("Use box filter when downsampling thumbnails instead of nearest. Slightly slower."));
|
||||
|
||||
m_bestFit = new QCheckBox(tr("Best Fit on image load"));
|
||||
m_bestFit->setToolTip(tr("Set Best Fit zoom level when opening new image."));
|
||||
m_bestFit->setChecked(BESTFIT);
|
||||
|
||||
m_headerHighlight = new QListWidget(this);
|
||||
m_headerHighlight->setToolTip(tr("List of FITS keywords that will be highlighted in Image info"));
|
||||
for(auto i = headerHighlight.begin(); i != headerHighlight.end(); i++)
|
||||
{
|
||||
QListWidgetItem *item = new QListWidgetItem(m_headerHighlight);
|
||||
item->setText(i.key());
|
||||
item->setBackground(i.value());
|
||||
}
|
||||
m_keyword = new QLineEdit(this);
|
||||
m_keyword->setPlaceholderText(tr("FITS keyword"));
|
||||
QPushButton *color = new QPushButton(this);
|
||||
QPixmap pix(16, 16);
|
||||
pix.fill(m_color);
|
||||
color->setIcon(pix);
|
||||
connect(color, &QPushButton::clicked, [this, color](){
|
||||
QColor rgb = QColorDialog::getColor(m_color, this);
|
||||
if(rgb.isValid())
|
||||
{
|
||||
QPixmap pix(16, 16);
|
||||
pix.fill(rgb);
|
||||
color->setIcon(pix);
|
||||
m_color = rgb;
|
||||
}
|
||||
});
|
||||
|
||||
QPushButton *add = new QPushButton(tr("Add keyword highlight"), this);
|
||||
connect(add, &QPushButton::clicked, [this](){
|
||||
auto list = m_headerHighlight->findItems(m_keyword->text(), Qt::MatchFixedString | Qt::MatchCaseSensitive);
|
||||
if(list.size())return;
|
||||
QListWidgetItem *item = new QListWidgetItem(m_headerHighlight);
|
||||
item->setText(m_keyword->text());
|
||||
item->setBackground(m_color);
|
||||
});
|
||||
QPushButton *remove = new QPushButton(tr("Remove keyword highlight"), this);
|
||||
connect(remove, &QPushButton::clicked, [this](){
|
||||
auto list = m_headerHighlight->selectedItems();
|
||||
for(auto item : list)
|
||||
delete item;
|
||||
});
|
||||
|
||||
layout->addRow(tr("Image preload count"), m_preloadImages);
|
||||
layout->addRow(tr("Thumbnails size"), m_thumSize);
|
||||
layout->addRow(tr("Saturation"), m_saturation);
|
||||
layout->addRow(tr("Slideshow interval"), m_slideShowTime);
|
||||
layout->addRow(tr("Image interpolation"), m_filtering);
|
||||
layout->addRow(m_qualityThumbnail);
|
||||
layout->addRow(m_useNativeDialog);
|
||||
layout->addRow(m_bestFit);
|
||||
layout->addRow(new QLabel(tr("FITS header highlight"), this));
|
||||
layout->addRow(m_headerHighlight);
|
||||
layout->addRow(m_keyword, color);
|
||||
layout->addRow(add, remove);
|
||||
|
||||
#ifdef Q_OS_WIN64
|
||||
QPushButton *installThumbnailer = new QPushButton(tr("Install"), this);
|
||||
installThumbnailer->setToolTip(tr("This will install thumnail generation for FITS and XISF files in File Explorer"));
|
||||
connect(installThumbnailer, &QPushButton::clicked, this, &SettingsDialog::installThumbnailer);
|
||||
layout->addRow(tr("Install thumbnailer"), installThumbnailer);
|
||||
#endif
|
||||
//layout->addRow(new QLabel(tr("Changes in settings will take effect after program restart.")));
|
||||
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
connect(this, &QDialog::accepted, this, &SettingsDialog::saveSettings);
|
||||
|
||||
layout->addRow(buttonBox);
|
||||
}
|
||||
|
||||
void SettingsDialog::loadSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
THUMB_SIZE = settings.value("settings/thumbnailsize", THUMB_SIZE).toInt();
|
||||
THUMB_SIZE_BORDER = THUMB_SIZE + 10;
|
||||
THUMB_SIZE_BORDER_Y = THUMB_SIZE + 30;
|
||||
DEFAULT_WIDTH = settings.value("settings/preloadimagecount", DEFAULT_WIDTH).toInt();
|
||||
SATURATION = settings.value("settings/saturation", 95.0).toDouble() / 100.0;
|
||||
FILTERING = settings.value("settings/filtering", FILTERING).toInt();
|
||||
QUALITY_RESIZE = settings.value("settings/qualitythumbnail", QUALITY_RESIZE).toBool();
|
||||
BESTFIT = settings.value("settings/bestfit", BESTFIT).toBool();
|
||||
QStringList keywords = settings.value("settings/headerhighlightkeywords").toStringList();
|
||||
QStringList colors = settings.value("settings/headerhighlightcolors").toStringList();
|
||||
for(int i = 0; i < std::min(keywords.size(), colors.size()); i++)
|
||||
headerHighlight.insert(keywords[i], QColor::fromString(colors[i]));
|
||||
|
||||
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, settings.value("settings/dontusenativedialogs", false).toBool());
|
||||
}
|
||||
|
||||
bool SettingsDialog::loadThumbsizes()
|
||||
{
|
||||
QSettings settings;
|
||||
int OLD_THUMB_SIZE = THUMB_SIZE;
|
||||
THUMB_SIZE = settings.value("settings/thumbnailsize", THUMB_SIZE).toInt();
|
||||
THUMB_SIZE_BORDER = THUMB_SIZE + 10;
|
||||
THUMB_SIZE_BORDER_Y = THUMB_SIZE + 30;
|
||||
return OLD_THUMB_SIZE != THUMB_SIZE;
|
||||
}
|
||||
|
||||
void SettingsDialog::installThumbnailer()
|
||||
{
|
||||
#ifdef Q_OS_WIN64
|
||||
QString path = QCoreApplication::instance()->applicationDirPath() + "/tenmonthumbnailer.dll";
|
||||
if(!QFileInfo::exists(path))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Missing dll"), tr("Can't find ") + path);
|
||||
return;
|
||||
}
|
||||
|
||||
QProcess regsvr;
|
||||
int ret = regsvr.execute("regsvr32.exe", {"/s", path});
|
||||
if(ret == 0)
|
||||
QMessageBox::information(this, tr("Thumbnail support"), tr("Thumbnail generation support sucessufully installed."));
|
||||
else
|
||||
QMessageBox::critical(this, tr("Error"), tr("Failed to register thumbnailer. %1").arg(ret));
|
||||
#endif
|
||||
}
|
||||
|
||||
void SettingsDialog::saveSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("settings/thumbnailsize", m_thumSize->value());
|
||||
settings.setValue("settings/preloadimagecount", m_preloadImages->value());
|
||||
settings.setValue("settings/dontusenativedialogs", m_useNativeDialog->isChecked());
|
||||
settings.setValue("settings/saturation", m_saturation->value());
|
||||
settings.setValue("settings/slideshowtime", m_slideShowTime->value());
|
||||
settings.setValue("settings/qualitythumbnail", m_qualityThumbnail->isChecked());
|
||||
QUALITY_RESIZE = m_qualityThumbnail->isChecked();
|
||||
FILTERING = m_filtering->currentIndex();
|
||||
BESTFIT = m_bestFit->isChecked();
|
||||
settings.setValue("settings/filtering", FILTERING);
|
||||
settings.setValue("settings/bestfit", BESTFIT);
|
||||
SATURATION = m_saturation->value() / 100.0;
|
||||
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, m_useNativeDialog->isChecked());
|
||||
if(DEFAULT_WIDTH != m_preloadImages->value())
|
||||
emit preloadChanged(m_preloadImages->value());
|
||||
|
||||
headerHighlight.clear();
|
||||
QStringList colors;
|
||||
for(int i = 0; i < m_headerHighlight->count(); i++)
|
||||
{
|
||||
auto item = m_headerHighlight->item(i);
|
||||
colors.push_back(item->background().color().name());
|
||||
headerHighlight[item->text()] = item->background().color();
|
||||
}
|
||||
settings.setValue("settings/headerhighlightkeywords", headerHighlight.keys());
|
||||
settings.setValue("settings/headerhighlightcolors", colors);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef SETTINGSDIALOG_H
|
||||
#define SETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QListWidget>
|
||||
|
||||
class SettingsDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SettingsDialog(QWidget *parent = nullptr);
|
||||
static void loadSettings();
|
||||
static bool loadThumbsizes();
|
||||
public slots:
|
||||
void installThumbnailer();
|
||||
signals:
|
||||
void preloadChanged(int witdth);
|
||||
private:
|
||||
void saveSettings();
|
||||
|
||||
QSpinBox *m_preloadImages;
|
||||
QSpinBox *m_thumSize;
|
||||
QDoubleSpinBox *m_slideShowTime;
|
||||
QDoubleSpinBox *m_saturation;
|
||||
QCheckBox *m_useNativeDialog;
|
||||
QCheckBox *m_qualityThumbnail;
|
||||
QComboBox *m_filtering;
|
||||
QCheckBox *m_bestFit;
|
||||
QListWidget *m_headerHighlight;
|
||||
QColor m_color = Qt::yellow;
|
||||
QLineEdit *m_keyword;
|
||||
};
|
||||
|
||||
#endif // SETTINGSDIALOG_H
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
#include "solver.h"
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <fitsio.h>
|
||||
#include <QStandardPaths>
|
||||
#include <QSettings>
|
||||
#include <wcslib/wcshdr.h>
|
||||
#include <wcslib/wcsutil.h>
|
||||
#include "rawimage.h"
|
||||
#include "loadimage.h"
|
||||
#include "scriptengine.h"
|
||||
|
||||
Solver::Solver(QObject *parent) : QObject(parent)
|
||||
{
|
||||
_solver = new StellarSolver(this);
|
||||
connect(_solver, &StellarSolver::logOutput, this, &Solver::logOutput);
|
||||
|
||||
_solver->setProperty("ProcessType", SSolver::SOLVE);
|
||||
QSettings settings;
|
||||
setIndexFolder(settings.value("platesolving/indexPath", Solver::getTenmonIndexPath()).toString());
|
||||
int profileIdx = settings.value("platesolving/profile", 0).toInt();
|
||||
auto profiles = _solver->getBuiltInProfiles();
|
||||
_solver->setParameters(profiles[profileIdx]);
|
||||
|
||||
connect(_solver, &StellarSolver::finished, this, &Solver::finished);
|
||||
}
|
||||
|
||||
Solver::~Solver()
|
||||
{
|
||||
}
|
||||
|
||||
void Solver::setIndexFolder(const QString &indexPath)
|
||||
{
|
||||
_solver->setIndexFolderPaths(QStringList(indexPath));
|
||||
}
|
||||
|
||||
bool Solver::loadImage(const QString &path)
|
||||
{
|
||||
if(path == _path)return true;
|
||||
|
||||
_loaded = false;
|
||||
std::shared_ptr<RawImage> image;
|
||||
ImageInfoData info;
|
||||
if(::loadImage(path, info, image, 0, true))
|
||||
{
|
||||
return loadImage(image, path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Solver::loadImage(std::shared_ptr<RawImage> &image, const QString &path)
|
||||
{
|
||||
_rawImage = image;
|
||||
if(_rawImage->channels() > 1)
|
||||
_rawImagePlanar = _rawImage->toPlanar();
|
||||
else
|
||||
_rawImagePlanar = _rawImage;
|
||||
|
||||
switch(_rawImage->type())
|
||||
{
|
||||
case RawImage::UINT8:
|
||||
_stats.dataType = TBYTE;
|
||||
break;
|
||||
case RawImage::UINT16:
|
||||
_stats.dataType = TUSHORT;
|
||||
break;
|
||||
case RawImage::UINT32:
|
||||
_stats.dataType = TUINT;
|
||||
break;
|
||||
case RawImage::FLOAT32:
|
||||
_stats.dataType = TFLOAT;
|
||||
break;
|
||||
case RawImage::FLOAT64:
|
||||
_stats.dataType = TDOUBLE;
|
||||
break;
|
||||
default:
|
||||
_error = tr("Unsupported image data type");
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
_stats.bytesPerPixel = _rawImage->typeSize(_rawImagePlanar->type());
|
||||
_stats.channels = _rawImagePlanar->channels();
|
||||
_stats.width = _rawImagePlanar->width();
|
||||
_stats.height = _rawImagePlanar->height();
|
||||
_stats.samples_per_channel = _stats.width * _stats.height;
|
||||
|
||||
_solver->clearSearchPosition();
|
||||
_solver->clearSearchScale();
|
||||
_loaded = _solver->loadNewImageBuffer(_stats, (const uint8_t*)_rawImagePlanar->data());
|
||||
_path = path;
|
||||
return _loaded;
|
||||
}
|
||||
|
||||
bool Solver::solveImage(bool sync)
|
||||
{
|
||||
if(_loaded && !_solver->isRunning())
|
||||
{
|
||||
_process = SSolver::ProcessType::SOLVE;
|
||||
_solver->setProperty("ProcessType", _process);
|
||||
if(sync)return _solver->solve();
|
||||
else _solver->start();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Solver::extractSources(bool hfr, bool sync)
|
||||
{
|
||||
if(_loaded && !_solver->isRunning())
|
||||
{
|
||||
_process = hfr ? SSolver::ProcessType::EXTRACT_WITH_HFR : SSolver::ProcessType::EXTRACT;
|
||||
_solver->setProperty("ProcessType", _process);
|
||||
if(sync)return _solver->extract(hfr);
|
||||
else _solver->start();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Solver::abort()
|
||||
{
|
||||
_solver->abort();
|
||||
}
|
||||
|
||||
const FITSImage::Solution& Solver::getSolution() const
|
||||
{
|
||||
return _solver->getSolution();
|
||||
}
|
||||
|
||||
const QList<FITSImage::Star>& Solver::getStars() const
|
||||
{
|
||||
return _solver->getStarList();
|
||||
}
|
||||
|
||||
double Solver::getHFR() const
|
||||
{
|
||||
double hfr = 0.0;
|
||||
auto stars = getStars();
|
||||
if(stars.empty())return -1.0;
|
||||
|
||||
for(auto &star : stars)
|
||||
{
|
||||
hfr += star.HFR;
|
||||
}
|
||||
return hfr / stars.size();
|
||||
}
|
||||
|
||||
QString Solver::errorMessage() const
|
||||
{
|
||||
return _error;
|
||||
}
|
||||
|
||||
bool Solver::updateHeader(QString &error)
|
||||
{
|
||||
if(!_solver->solvingDone())
|
||||
{
|
||||
error = tr("Solving is not finished");
|
||||
return false;
|
||||
}
|
||||
|
||||
FITSImage::Solution solution = getSolution();
|
||||
|
||||
double rotationDeg = 360.0 - solution.orientation;
|
||||
if(rotationDeg > 360)rotationDeg -= 360;
|
||||
double rotationRad = rotationDeg / 180.0 * M_PI;
|
||||
|
||||
double cdeltx = (solution.parity == FITSImage::NEGATIVE ? solution.pixscale : -solution.pixscale) / 3600.0;
|
||||
double cdelty = solution.pixscale / 3600.0;
|
||||
|
||||
Script::File file(_path, nullptr);
|
||||
Script::FITSRecordModify modify;
|
||||
modify.removeKeyword("RADECSYS");
|
||||
modify.updateKeyword("CRPIX1", _stats.width / 2.0, QByteArray("x pixel coordinate of the reference point"));
|
||||
modify.updateKeyword("CRPIX2", _stats.height / 2.0, QByteArray("y pixel coordinate of the reference point"));
|
||||
modify.updateKeyword("CDELT1", cdeltx, QByteArray("X pixel size (deg)"));
|
||||
modify.updateKeyword("CDELT2", cdelty, QByteArray("Y pixel size (deg)"));
|
||||
modify.updateKeyword("CRVAL1", solution.ra, QByteArray("RA of reference pixel (deg)"));
|
||||
modify.updateKeyword("CRVAL2", solution.dec, QByteArray("DEC of reference pixel (deg)"));
|
||||
modify.updateKeyword("CD1_1", std::cos(rotationRad) * cdeltx, QByteArray("CD matrix to convert (x,y) to (RA, DEC)"));
|
||||
modify.updateKeyword("CD1_2",-std::sin(rotationRad) * cdelty, QByteArray("CD matrix to convert (x,y) to (RA, DEC)"));
|
||||
modify.updateKeyword("CD2_1", std::sin(rotationRad) * cdeltx, QByteArray("CD matrix to convert (x,y) to (RA, DEC)"));
|
||||
modify.updateKeyword("CD2_2", std::cos(rotationRad) * cdelty, QByteArray("CD matrix to convert (x,y) to (RA, DEC)"));
|
||||
modify.updateKeyword("CROTA1", rotationDeg, QByteArray("Image twist X axis (deg)"));
|
||||
modify.updateKeyword("CROTA2", rotationDeg, QByteArray("Image twist Y axis (deg)"));
|
||||
modify.updateKeyword("CTYPE1", "RA---TAN", QByteArray("first parameter RA, projection TANgential"));
|
||||
modify.updateKeyword("CTYPE2", "DEC--TAN", QByteArray("first parameter DEC, projection TANgential"));
|
||||
modify.updateKeyword("RADESYS", "ICRS", QByteArray("International Celestial Reference System"));
|
||||
modify.updateKeyword("EQUINOX", 2000, QByteArray("Equinox of coordinates"));
|
||||
bool ret = file.modifyFITSRecords(&modify);
|
||||
if(!ret)error = tr("Failed to update file header");
|
||||
else emit headerUpdated(_path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Solver::setParameters(Parameters::ParametersProfile profile)
|
||||
{
|
||||
auto profileParam = _solver->getBuiltInProfiles().at(profile);
|
||||
profileParam.partition = false;
|
||||
_solver->setParameters(profileParam);
|
||||
}
|
||||
|
||||
void Solver::setParameters(const Parameters ¶meters)
|
||||
{
|
||||
auto profile = parameters;
|
||||
profile.partition = false;
|
||||
_solver->setParameters(profile);
|
||||
}
|
||||
|
||||
Parameters Solver::getProfile() const
|
||||
{
|
||||
return _solver->getCurrentParameters();
|
||||
}
|
||||
|
||||
void Solver::setSearchScale(double fovLow, double fowHigh, SSolver::ScaleUnits units)
|
||||
{
|
||||
_solver->setSearchScale(fovLow, fowHigh, units);
|
||||
}
|
||||
|
||||
void Solver::setSearchPosition(double ra, double dec)
|
||||
{
|
||||
_solver->setSearchPositionRaDec(ra, dec);
|
||||
}
|
||||
|
||||
void Solver::clearStartingPositionAndScale()
|
||||
{
|
||||
_solver->clearSearchPosition();
|
||||
_solver->clearSearchScale();
|
||||
}
|
||||
|
||||
QStringList Solver::getIndexPaths()
|
||||
{
|
||||
QStringList paths = StellarSolver::getDefaultIndexFolderPaths();
|
||||
paths.prepend(getTenmonIndexPath());
|
||||
return paths;
|
||||
}
|
||||
|
||||
QString Solver::getTenmonIndexPath()
|
||||
{
|
||||
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/astrometry";
|
||||
}
|
||||
|
||||
void Solver::finished()
|
||||
{
|
||||
switch(_process)
|
||||
{
|
||||
case SSolver::ProcessType::SOLVE:
|
||||
emit solvingDone();
|
||||
break;
|
||||
case SSolver::ProcessType::EXTRACT_WITH_HFR:
|
||||
case SSolver::ProcessType::EXTRACT:
|
||||
emit extractionDone();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef SOLVER_H
|
||||
#define SOLVER_H
|
||||
|
||||
#include <stellarsolver.h>
|
||||
|
||||
class RawImage;
|
||||
|
||||
class Solver : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
StellarSolver *_solver;
|
||||
FITSImage::Statistic _stats;
|
||||
SSolver::ProcessType _process = SSolver::SOLVE;
|
||||
bool _loaded = false;
|
||||
QString _path;
|
||||
QString _error;
|
||||
std::shared_ptr<RawImage> _rawImage;
|
||||
std::shared_ptr<RawImage> _rawImagePlanar;
|
||||
public:
|
||||
explicit Solver(QObject *parent = nullptr);
|
||||
~Solver();
|
||||
void setIndexFolder(const QString &indexPath);
|
||||
|
||||
bool loadImage(const QString &path);
|
||||
bool loadImage(std::shared_ptr<RawImage> &image, const QString &path);
|
||||
bool solveImage(bool sync = false);
|
||||
bool extractSources(bool hfr, bool sync = false);
|
||||
void abort();
|
||||
const FITSImage::Solution& getSolution() const;
|
||||
const QList<FITSImage::Star>& getStars() const;
|
||||
double getHFR() const;
|
||||
|
||||
QString errorMessage() const;
|
||||
bool updateHeader(QString &error);
|
||||
void setParameters(SSolver::Parameters::ParametersProfile profile);
|
||||
void setParameters(const SSolver::Parameters ¶meters);
|
||||
SSolver::Parameters getProfile() const;
|
||||
void setSearchScale(double fovLow, double fowHigh, ScaleUnits units);
|
||||
void setSearchPosition(double ra, double dec);
|
||||
void clearStartingPositionAndScale();
|
||||
|
||||
static QStringList getIndexPaths();
|
||||
static QString getTenmonIndexPath();
|
||||
public slots:
|
||||
void finished();
|
||||
signals:
|
||||
void solvingDone();
|
||||
void extractionDone();
|
||||
void headerUpdated(const QString &path);
|
||||
void logOutput(const QString &log);
|
||||
};
|
||||
|
||||
#endif // SOLVER_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "statusbar.h"
|
||||
#include <QFontMetrics>
|
||||
|
||||
StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent)
|
||||
{
|
||||
m_value = new QLabel(this);
|
||||
m_pixelCoords = new QLabel(this);
|
||||
m_celestianCoords = new QLabel(this);
|
||||
|
||||
m_value->setMinimumWidth(m_value->fontMetrics().horizontalAdvance("R:65536 G:65536 B:65536 "));
|
||||
m_pixelCoords->setMinimumWidth(m_pixelCoords->fontMetrics().horizontalAdvance("X:65536 Y:65536 "));
|
||||
m_celestianCoords->setMinimumWidth(m_celestianCoords->fontMetrics().horizontalAdvance("RA: 00h00m00s DEC: 00° 00' 00\" "));
|
||||
addPermanentWidget(m_value);
|
||||
addPermanentWidget(m_pixelCoords);
|
||||
addPermanentWidget(m_celestianCoords);
|
||||
}
|
||||
|
||||
void StatusBar::newStatus(const QString &value, const QString &pixelCoords, const QString &celestialCoords)
|
||||
{
|
||||
m_value->setText(value);
|
||||
m_pixelCoords->setText(pixelCoords);
|
||||
m_celestianCoords->setText(celestialCoords);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef STATUSBAR_H
|
||||
#define STATUSBAR_H
|
||||
|
||||
#include <QStatusBar>
|
||||
#include <QLabel>
|
||||
|
||||
class StatusBar : public QStatusBar
|
||||
{
|
||||
Q_OBJECT
|
||||
QLabel *m_value;
|
||||
QLabel *m_pixelCoords;
|
||||
QLabel *m_celestianCoords;
|
||||
public:
|
||||
explicit StatusBar(QWidget *parent = nullptr);
|
||||
public slots:
|
||||
void newStatus(const QString &value, const QString &pixelCoords, const QString &celestialCoords);
|
||||
};
|
||||
|
||||
#endif // STATUSBAR_H
|
||||
@@ -0,0 +1,245 @@
|
||||
#include "stfslider.h"
|
||||
#include <cmath>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QPainterPath>
|
||||
#include <QToolTip>
|
||||
|
||||
static float clamp(float x)
|
||||
{
|
||||
return std::min(std::max(x, 0.0f), 1.0f);
|
||||
}
|
||||
|
||||
STFSlider::STFSlider(const QColor &color, QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
setMinimumWidth(100);
|
||||
setMouseTracking(true);
|
||||
|
||||
if(color == Qt::white)
|
||||
{
|
||||
setMaximumHeight(16);
|
||||
setMinimumHeight(16);
|
||||
}
|
||||
else
|
||||
{
|
||||
setMaximumHeight(10);
|
||||
setMinimumHeight(10);
|
||||
}
|
||||
m_blackPoint = 0;
|
||||
m_midPoint = 0.5;
|
||||
m_whitePoint = 1;
|
||||
m_grabbed = -1;
|
||||
m_fineTune = false;
|
||||
m_color = color;
|
||||
if(color == Qt::blue || color == Qt::red)
|
||||
m_threshold = 1.1f;
|
||||
else if(color == Qt::green)
|
||||
m_threshold = 0.8f;
|
||||
else
|
||||
m_threshold = 0.4f;
|
||||
setToolTip(tr("Press Shift for fine tuning"));
|
||||
}
|
||||
|
||||
float STFSlider::blackPoint() const
|
||||
{
|
||||
return m_blackPoint;
|
||||
}
|
||||
|
||||
float STFSlider::midPoint() const
|
||||
{
|
||||
return m_midPoint;
|
||||
}
|
||||
|
||||
float STFSlider::whitePoint() const
|
||||
{
|
||||
return m_whitePoint;
|
||||
}
|
||||
|
||||
void STFSlider::setMTFParams(float low, float mid, float high)
|
||||
{
|
||||
m_blackPoint = clamp(low);
|
||||
m_midPoint = clamp(mid);
|
||||
m_whitePoint = clamp(high);
|
||||
update();
|
||||
}
|
||||
|
||||
void STFSlider::orientationChanged(Qt::Orientations orientation)
|
||||
{
|
||||
m_orientation = orientation;
|
||||
if(m_orientation == Qt::Horizontal)
|
||||
{
|
||||
if(m_color == Qt::white)
|
||||
{
|
||||
setMaximumSize(QWIDGETSIZE_MAX, 16);
|
||||
setMinimumSize(16, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
setMaximumSize(QWIDGETSIZE_MAX, 10);
|
||||
setMinimumSize(10, 10);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_color == Qt::white)
|
||||
{
|
||||
setMaximumSize(16, QWIDGETSIZE_MAX);
|
||||
setMinimumSize(16, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
setMaximumSize(10, QWIDGETSIZE_MAX);
|
||||
setMinimumSize(10, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void STFSlider::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
QRect rect = event->rect();
|
||||
qreal w = rect.width() - 1;
|
||||
qreal h = rect.height();
|
||||
if(m_orientation == Qt::Vertical)
|
||||
{
|
||||
rect = rect.transposed();
|
||||
painter.rotate(90);
|
||||
w = rect.width() - 1;
|
||||
h = rect.height();
|
||||
painter.translate(0, -h);
|
||||
}
|
||||
QLinearGradient gradient(rect.topLeft(), rect.topRight());
|
||||
gradient.setColorAt(0, Qt::black);
|
||||
for(int i=1; i<=32; i++)
|
||||
{
|
||||
qreal p = i/32.0f;
|
||||
qreal c = std::pow(p, 1.0/2.2)*255;
|
||||
gradient.setColorAt(p, QColor(m_color.redF()*c, m_color.greenF()*c, m_color.blueF()*c));
|
||||
}
|
||||
|
||||
QPainterPath tick(QPointF(0, 0));
|
||||
tick.lineTo(0, h - 5);
|
||||
tick.lineTo(-5, h);
|
||||
tick.lineTo(5, h);
|
||||
tick.lineTo(0, h - 5);
|
||||
|
||||
painter.setBrush(gradient);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.drawRect(rect);
|
||||
|
||||
auto drawTick = [&](qreal p)
|
||||
{
|
||||
painter.setPen(p < m_threshold ? Qt::white : Qt::black);
|
||||
painter.resetTransform();
|
||||
if(m_orientation == Qt::Vertical)
|
||||
{
|
||||
painter.rotate(90);
|
||||
painter.translate(0, -h);
|
||||
}
|
||||
painter.translate(w*p, 0);
|
||||
painter.drawPath(tick);
|
||||
};
|
||||
|
||||
painter.setBrush(Qt::NoBrush);
|
||||
drawTick(m_blackPoint);
|
||||
drawTick(m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint);
|
||||
drawTick(m_whitePoint);
|
||||
}
|
||||
|
||||
void STFSlider::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
qreal x,w;
|
||||
if(m_orientation == Qt::Horizontal)
|
||||
{
|
||||
x = event->position().x();
|
||||
w = width();
|
||||
}
|
||||
else
|
||||
{
|
||||
x = event->position().y();
|
||||
w = height();
|
||||
}
|
||||
|
||||
if(std::abs(m_blackPoint*w - x) < 5 ||
|
||||
std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*w - x) < 5 ||
|
||||
std::abs(m_whitePoint*w - x) < 5)
|
||||
setCursor(m_orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor);
|
||||
else
|
||||
unsetCursor();
|
||||
|
||||
qreal xw = x/w;
|
||||
if(event->modifiers() & Qt::ShiftModifier && !m_fineTune)
|
||||
{
|
||||
m_fineTune = true;
|
||||
m_fineTuneX = xw;
|
||||
}
|
||||
if(!(event->modifiers() & Qt::ShiftModifier) && m_fineTune)
|
||||
m_fineTune = false;
|
||||
|
||||
if(m_fineTune)
|
||||
{
|
||||
xw = m_fineTuneX + (xw - m_fineTuneX) * 0.2;
|
||||
}
|
||||
|
||||
switch(m_grabbed)
|
||||
{
|
||||
case 0:
|
||||
m_blackPoint = clamp(xw);
|
||||
m_whitePoint = std::max(m_whitePoint, m_blackPoint);
|
||||
QToolTip::showText(event->globalPosition().toPoint(), QString::number(m_blackPoint), this);
|
||||
break;
|
||||
case 1:
|
||||
m_midPoint = (xw - m_blackPoint) / (m_whitePoint - m_blackPoint);
|
||||
m_midPoint = clamp(m_midPoint);
|
||||
QToolTip::showText(event->globalPosition().toPoint(), QString::number(m_midPoint), this);
|
||||
break;
|
||||
case 2:
|
||||
m_whitePoint = clamp(xw);
|
||||
m_blackPoint = std::min(m_blackPoint, m_whitePoint);
|
||||
QToolTip::showText(event->globalPosition().toPoint(), QString::number(m_whitePoint), this);
|
||||
break;
|
||||
}
|
||||
if(m_grabbed >= 0)
|
||||
{
|
||||
emit paramChanged(m_blackPoint, midPoint(), m_whitePoint);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void STFSlider::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
qreal x,w;
|
||||
if(m_orientation == Qt::Horizontal)
|
||||
{
|
||||
x = event->position().x();
|
||||
w = width();
|
||||
}
|
||||
else
|
||||
{
|
||||
x = event->position().y();
|
||||
w = height();
|
||||
}
|
||||
|
||||
if(event->modifiers() & Qt::ShiftModifier)
|
||||
{
|
||||
m_fineTune = true;
|
||||
m_fineTuneX = x/w;
|
||||
}
|
||||
|
||||
if(std::abs((m_blackPoint + (m_whitePoint - m_blackPoint) * m_midPoint)*w - x) < 5)
|
||||
m_grabbed = 1;
|
||||
else if(std::abs(m_blackPoint*w - x) < 5)
|
||||
m_grabbed = 0;
|
||||
else if(std::abs(m_whitePoint*w - x) < 5)
|
||||
m_grabbed = 2;
|
||||
else
|
||||
m_grabbed = -1;
|
||||
}
|
||||
|
||||
void STFSlider::mouseReleaseEvent(QMouseEvent *)
|
||||
{
|
||||
m_grabbed = -1;
|
||||
m_fineTune = false;
|
||||
emit paramChanged(m_blackPoint, midPoint(), m_whitePoint);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef STFSLIDER_H
|
||||
#define STFSLIDER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
|
||||
class STFSlider : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
float m_blackPoint;
|
||||
float m_midPoint;
|
||||
float m_whitePoint;
|
||||
int m_grabbed;
|
||||
bool m_fineTune;
|
||||
float m_fineTuneX;
|
||||
QColor m_color;
|
||||
float m_threshold;
|
||||
Qt::Orientations m_orientation = Qt::Horizontal;
|
||||
public:
|
||||
explicit STFSlider(const QColor &color = Qt::white, QWidget *parent = nullptr);
|
||||
float blackPoint() const;
|
||||
float midPoint() const;
|
||||
float whitePoint() const;
|
||||
void setMTFParams(float low, float mid, float high);
|
||||
public slots:
|
||||
void orientationChanged(Qt::Orientations orientation);
|
||||
signals:
|
||||
void paramChanged(float blackPoint, float midPoint, float whitePoint);
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *) override;
|
||||
};
|
||||
|
||||
#endif // STFSLIDER_H
|
||||
@@ -0,0 +1,163 @@
|
||||
#include "stretchtoolbar.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QToolButton>
|
||||
#include <QSettings>
|
||||
#include <QStyle>
|
||||
#include "imageringlist.h"
|
||||
|
||||
StretchToolbar::StretchToolbar(QWidget *parent) : QToolBar(tr("Stretch toolbar"), parent)
|
||||
{
|
||||
setObjectName("stretchtoolbar");
|
||||
QWidget *lum = new QWidget(this);
|
||||
QVBoxLayout *vbox1 = new QVBoxLayout(lum);
|
||||
m_stfSlider = new STFSlider(Qt::white, this);
|
||||
vbox1->addWidget(m_stfSlider);
|
||||
connect(this, &StretchToolbar::orientationChanged, m_stfSlider, &STFSlider::orientationChanged);
|
||||
|
||||
m_stfSliderR = new STFSlider(Qt::red, this);
|
||||
m_stfSliderG = new STFSlider(Qt::green, this);
|
||||
m_stfSliderB = new STFSlider(Qt::blue, this);
|
||||
QWidget *rgb = new QWidget(this);
|
||||
QBoxLayout *box2 = new QBoxLayout(orientation() == Qt::Horizontal ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight, rgb);
|
||||
box2->setSpacing(0);
|
||||
box2->addWidget(m_stfSliderR);
|
||||
box2->addWidget(m_stfSliderG);
|
||||
box2->addWidget(m_stfSliderB);
|
||||
connect(this, &StretchToolbar::orientationChanged, m_stfSliderR, &STFSlider::orientationChanged);
|
||||
connect(this, &StretchToolbar::orientationChanged, m_stfSliderG, &STFSlider::orientationChanged);
|
||||
connect(this, &StretchToolbar::orientationChanged, m_stfSliderB, &STFSlider::orientationChanged);
|
||||
connect(this, &StretchToolbar::orientationChanged, [box2](Qt::Orientations orientation){
|
||||
box2->setDirection(orientation == Qt::Horizontal ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
|
||||
});
|
||||
|
||||
m_stack = new QStackedWidget(this);
|
||||
m_stack->addWidget(lum);
|
||||
m_stack->addWidget(rgb);
|
||||
m_stack->setCurrentIndex(0);
|
||||
addWidget(m_stack);
|
||||
|
||||
connect(m_stfSlider, &STFSlider::paramChanged, [this](float blackPoint, float midPoint, float whitePoint){
|
||||
m_mtfParam.blackPoint[0] = m_mtfParam.blackPoint[1] = m_mtfParam.blackPoint[2] = blackPoint;
|
||||
m_mtfParam.midPoint[0] = m_mtfParam.midPoint[1] = m_mtfParam.midPoint[2] = midPoint;
|
||||
m_mtfParam.whitePoint[0] = m_mtfParam.whitePoint[1] = m_mtfParam.whitePoint[2] = whitePoint;
|
||||
emit paramChanged(m_mtfParam);
|
||||
});
|
||||
connect(m_stfSliderR, &STFSlider::paramChanged, [this](float blackPoint, float midPoint, float whitePoint){
|
||||
m_mtfParam.blackPoint[0] = blackPoint;
|
||||
m_mtfParam.midPoint[0] = midPoint;
|
||||
m_mtfParam.whitePoint[0] = whitePoint;
|
||||
emit paramChanged(m_mtfParam);
|
||||
});
|
||||
connect(m_stfSliderG, &STFSlider::paramChanged, [this](float blackPoint, float midPoint, float whitePoint){
|
||||
m_mtfParam.blackPoint[1] = blackPoint;
|
||||
m_mtfParam.midPoint[1] = midPoint;
|
||||
m_mtfParam.whitePoint[1] = whitePoint;
|
||||
emit paramChanged(m_mtfParam);
|
||||
});
|
||||
connect(m_stfSliderB, &STFSlider::paramChanged, [this](float blackPoint, float midPoint, float whitePoint){
|
||||
m_mtfParam.blackPoint[2] = blackPoint;
|
||||
m_mtfParam.midPoint[2] = midPoint;
|
||||
m_mtfParam.whitePoint[2] = whitePoint;
|
||||
emit paramChanged(m_mtfParam);
|
||||
});
|
||||
|
||||
QAction *rgbStretch = addAction(QIcon(":/link.png"), tr("Linked channels"));
|
||||
rgbStretch->setCheckable(true);
|
||||
rgbStretch->setChecked(true);
|
||||
connect(rgbStretch, &QAction::toggled, this, &StretchToolbar::unlinkStretch);
|
||||
|
||||
QAction *autoStretchButton = addAction(QIcon(":/nuke.png"), tr("Auto Stretch F12"));
|
||||
autoStretchButton->setShortcut(Qt::Key_F12);
|
||||
connect(autoStretchButton, &QAction::triggered, this, &StretchToolbar::autoStretch);
|
||||
|
||||
QAction *resetButton = addAction(style()->standardIcon(QStyle::SP_DialogResetButton), tr("Reset Screen Transfer Function F11"));
|
||||
resetButton->setShortcut(Qt::Key_F11);
|
||||
connect(resetButton, &QAction::triggered, this, &StretchToolbar::resetMTF);
|
||||
|
||||
QAction *invertButton = addAction(QIcon(":/invert.png"), tr("Invert colors"));
|
||||
invertButton->setCheckable(true);
|
||||
connect(invertButton, &QAction::toggled, this, &StretchToolbar::invert);
|
||||
|
||||
QAction *falseColorButton = addAction(QIcon(":/falsecolor.png"), tr("False colors"));
|
||||
falseColorButton->setCheckable(true);
|
||||
connect(falseColorButton, &QAction::toggled, this, &StretchToolbar::falseColor);
|
||||
|
||||
m_debayer = addAction(QIcon(":/bayer.png"), tr("Debayer CFA"));
|
||||
m_debayer->setCheckable(true);
|
||||
connect(m_debayer, &QAction::toggled, this, &StretchToolbar::superPixel);
|
||||
|
||||
m_autoStretchOnLoad = addAction(QIcon(":/nuke_a.png"), tr("Apply auto stretch on load"));
|
||||
m_autoStretchOnLoad->setCheckable(true);
|
||||
QSettings settings;
|
||||
m_autoStretchOnLoad->setChecked(settings.value("stretchtoolbar/autostretch", false).toBool());
|
||||
}
|
||||
|
||||
StretchToolbar::~StretchToolbar()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("stretchtoolbar/autostretch", m_autoStretchOnLoad->isChecked());
|
||||
}
|
||||
|
||||
void StretchToolbar::stretchImage(Image *img)
|
||||
{
|
||||
if(img && img->rawImage())
|
||||
{
|
||||
m_mtfParam = img->rawImage()->calcMTFParams(m_stack->currentIndex() == 0,
|
||||
m_stack->currentIndex() == 1 && img->rawImage()->channels() == 1 && m_debayer->isChecked());
|
||||
|
||||
if(m_stack->currentIndex() == 0)
|
||||
{
|
||||
m_stfSlider->setMTFParams(m_mtfParam.blackPoint[0], m_mtfParam.midPoint[0], m_mtfParam.whitePoint[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_stfSliderR->setMTFParams(m_mtfParam.blackPoint[0], m_mtfParam.midPoint[0], m_mtfParam.whitePoint[0]);
|
||||
m_stfSliderG->setMTFParams(m_mtfParam.blackPoint[1], m_mtfParam.midPoint[1], m_mtfParam.whitePoint[1]);
|
||||
m_stfSliderB->setMTFParams(m_mtfParam.blackPoint[2], m_mtfParam.midPoint[2], m_mtfParam.whitePoint[2]);
|
||||
}
|
||||
emit paramChanged(m_mtfParam);
|
||||
}
|
||||
}
|
||||
|
||||
void StretchToolbar::resetMTF()
|
||||
{
|
||||
MTFParam params;
|
||||
m_mtfParam = params;
|
||||
if(m_stack->currentIndex() == 0)
|
||||
{
|
||||
m_stfSlider->setMTFParams(0, 0.5, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_stfSliderR->setMTFParams(0, 0.5, 1);
|
||||
m_stfSliderG->setMTFParams(0, 0.5, 1);
|
||||
m_stfSliderB->setMTFParams(0, 0.5, 1);
|
||||
}
|
||||
emit paramChanged(params);
|
||||
}
|
||||
|
||||
void StretchToolbar::imageLoaded(Image *img)
|
||||
{
|
||||
if(m_autoStretchOnLoad->isChecked())
|
||||
stretchImage(img);
|
||||
}
|
||||
|
||||
void StretchToolbar::unlinkStretch(bool enable)
|
||||
{
|
||||
if(!enable)
|
||||
{
|
||||
m_stack->setCurrentIndex(1);
|
||||
m_mtfParam.blackPoint[0] = m_stfSliderR->blackPoint(); m_mtfParam.midPoint[0] = m_stfSliderR->midPoint(); m_mtfParam.whitePoint[0] = m_stfSliderR->whitePoint();
|
||||
m_mtfParam.blackPoint[1] = m_stfSliderG->blackPoint(); m_mtfParam.midPoint[1] = m_stfSliderG->midPoint(); m_mtfParam.whitePoint[1] = m_stfSliderG->whitePoint();
|
||||
m_mtfParam.blackPoint[2] = m_stfSliderB->blackPoint(); m_mtfParam.midPoint[2] = m_stfSliderB->midPoint(); m_mtfParam.whitePoint[2] = m_stfSliderB->whitePoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_stack->setCurrentIndex(0);
|
||||
m_mtfParam.blackPoint[0] = m_mtfParam.blackPoint[1] = m_mtfParam.blackPoint[2] = m_stfSlider->blackPoint();
|
||||
m_mtfParam.midPoint[0] = m_mtfParam.midPoint[1] = m_mtfParam.midPoint[2] = m_stfSlider->midPoint();
|
||||
m_mtfParam.whitePoint[0] = m_mtfParam.whitePoint[1] = m_mtfParam.whitePoint[2] = m_mtfParam.whitePoint[2] = m_stfSlider->whitePoint();
|
||||
}
|
||||
emit paramChanged(m_mtfParam);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef STRETCHTOOLBAR_H
|
||||
#define STRETCHTOOLBAR_H
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QStackedWidget>
|
||||
#include "stfslider.h"
|
||||
#include "mtfparam.h"
|
||||
|
||||
class Image;
|
||||
|
||||
class StretchToolbar : public QToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
STFSlider *m_stfSlider;
|
||||
STFSlider *m_stfSliderR;
|
||||
STFSlider *m_stfSliderG;
|
||||
STFSlider *m_stfSliderB;
|
||||
QAction *m_autoStretchOnLoad;
|
||||
QAction *m_debayer;
|
||||
QStackedWidget *m_stack;
|
||||
MTFParam m_mtfParam;
|
||||
public:
|
||||
explicit StretchToolbar(QWidget *parent = nullptr);
|
||||
~StretchToolbar();
|
||||
public slots:
|
||||
void stretchImage(Image *img);
|
||||
void resetMTF();
|
||||
void imageLoaded(Image *img);
|
||||
void unlinkStretch(bool enable);
|
||||
signals:
|
||||
void paramChanged(const MTFParam ¶ms);
|
||||
void autoStretch();
|
||||
void invert(bool enable);
|
||||
void superPixel(bool enable);
|
||||
void falseColor(bool enable);
|
||||
};
|
||||
|
||||
#endif // STRETCHTOOLBAR_H
|
||||
@@ -0,0 +1,68 @@
|
||||
#ifndef TFLOAT16_H
|
||||
#define TFLOAT16_H
|
||||
|
||||
// crude implementation of float16 for platforms that do not support _Float16
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class TFloat16
|
||||
{
|
||||
uint16_t b16;
|
||||
public:
|
||||
TFloat16(){ b16 = 0; }
|
||||
explicit inline TFloat16(float f)
|
||||
{
|
||||
uint32_t i = *reinterpret_cast<uint32_t*>(&f);
|
||||
uint32_t sign = (i >> 16) & 0x8000;
|
||||
uint32_t exp = (i >> 23) & 0xff;
|
||||
uint32_t mantisa = (i & 0x7fffff) >> 13;
|
||||
|
||||
b16 = 0;
|
||||
if(exp < 111)
|
||||
{
|
||||
// do nothing it map to 0
|
||||
}
|
||||
else if(exp == 111)
|
||||
{
|
||||
b16 |= sign;
|
||||
b16 |= mantisa;
|
||||
}
|
||||
else if(exp == 255)//inf or nan
|
||||
{
|
||||
b16 = 0x7c00;
|
||||
b16 |= sign;
|
||||
b16 |= mantisa;
|
||||
}
|
||||
else if(exp > 142)
|
||||
{
|
||||
b16 = 0x7c00;// inf
|
||||
b16 |= sign;
|
||||
}
|
||||
else
|
||||
{
|
||||
b16 |= sign;
|
||||
b16 |= (exp - 112) << 10;
|
||||
b16 |= mantisa;
|
||||
}
|
||||
}
|
||||
friend TFloat16 operator*(TFloat16 a, TFloat16 b)
|
||||
{
|
||||
return TFloat16(static_cast<float>(a) * static_cast<float>(b));
|
||||
}
|
||||
operator float() const
|
||||
{
|
||||
uint32_t i = 0;
|
||||
uint32_t sign = b16 & 0x8000;
|
||||
uint32_t exp = (b16 & 0x7c00) >> 10;
|
||||
if(b16)
|
||||
{
|
||||
i |= sign << 16;
|
||||
if(exp==31)i |= 0x7f800000;
|
||||
else i |= (exp + 112) << 23;
|
||||
i |= (b16 & 0x3ff) << 13;
|
||||
}
|
||||
return *reinterpret_cast<float*>(&i);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TFLOAT16_H
|
||||
Reference in New Issue
Block a user