Kstars

astapastrometryparser.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "astapastrometryparser.h"
8
9#include "align.h"
10#include "ekos_align_debug.h"
11#include "Options.h"
12#include "indi/clientmanager.h"
13#include "indi/driverinfo.h"
14#include "indi/guimanager.h"
15#include "indi/indidevice.h"
16
17#include <indicom.h>
18
19#include <KMessageBox>
20
21namespace Ekos
22{
23ASTAPAstrometryParser::ASTAPAstrometryParser() : AstrometryParser()
24{
25}
26
27bool ASTAPAstrometryParser::init()
28{
29 return QFile::exists(Options::aSTAPExecutable());
30}
31
32void ASTAPAstrometryParser::verifyIndexFiles(double, double)
33{
34}
35
36bool ASTAPAstrometryParser::startSolver(const QString &filename, const QStringList &args, bool generated)
37{
38 INDI_UNUSED(generated);
39
40 QStringList solverArgs = args;
41
42 solverArgs << "-f" << filename;
43
44 QString solutionFile = QDir::tempPath() + "/solution";
45 solverArgs << "-o" << solutionFile;
46
47 solver.clear();
48 solver = new QProcess(this);
49
50 connect(solver, static_cast<void (QProcess::*)(int exitCode, QProcess::ExitStatus exitStatus)>(&QProcess::finished),
51 this, &ASTAPAstrometryParser::solverComplete);
52 // solver->setProcessChannelMode(QProcess::MergedChannels);
53 // connect(solver, SIGNAL(readyReadStandardOutput()), this, SLOT(logSolver()));
54#if QT_VERSION > QT_VERSION_CHECK(5, 6, 0)
55 connect(solver.data(), &QProcess::errorOccurred, this, [&]()
56 {
57 align->appendLogText(i18n("Error starting solver: %1", solver->errorString()));
58 emit solverFailed();
59 });
60#else
61 connect(solver, SIGNAL(error(QProcess::ProcessError)), this, SIGNAL(solverFailed()));
62#endif
63
64 solverTimer.start();
65
66 QString solverPath = Options::aSTAPExecutable();
67
68 solver->start(solverPath, solverArgs);
69
70 align->appendLogText(i18n("Starting solver..."));
71
72 if (Options::alignmentLogging())
73 {
74 QString command = solverPath + ' ' + solverArgs.join(' ');
75 align->appendLogText(command);
76 }
77
78 return true;
79}
80
81void ASTAPAstrometryParser::solverComplete(int exitCode, QProcess::ExitStatus exitStatus)
82{
83 Q_UNUSED(exitCode)
84 Q_UNUSED(exitStatus)
85
86 QFile solution(QDir::tempPath() + "/solution.ini");
87
88 if (!solution.open(QIODevice::ReadOnly))
89 {
90 qCritical(KSTARS_EKOS_ALIGN) << "Failed to open solution file" << QDir::tempPath() + "/solution.ini";
91 emit solverFailed();
92 return;
93 }
94
95 QTextStream in(&solution);
96 QString line = in.readLine();
97
98 QStringList ini = line.split("=");
99 if (ini.count() <= 1 || ini[1] == "F")
100 {
101 align->appendLogText(i18n("Solver failed. Try again."));
102 emit solverFailed();
103 return;
104 }
105
106 double ra = 0, dec = 0, orientation = 0, pixscale = 0;
107 double cd11 = 0;
108 double cd22 = 0;
109 double cd12 = 0;
110 double cd21 = 0;
111 bool ok[8] = {false};
112
113 line = in.readLine();
114 while (!line.isNull())
115 {
116 QStringList ini = line.split("=");
117 if (ini[0] == "CRVAL1")
118 ra = ini[1].trimmed().toDouble(&ok[0]);
119 else if (ini[0] == "CRVAL2")
120 dec = ini[1].trimmed().toDouble(&ok[1]);
121 else if (ini[0] == "CDELT1")
122 pixscale = ini[1].trimmed().toDouble(&ok[2]) * 3600.0;
123 else if (ini[0] == "CROTA1")
124 orientation = ini[1].trimmed().toDouble(&ok[3]);
125 else if (ini[0] == "CD1_1")
126 cd11 = ini[1].trimmed().toDouble(&ok[4]);
127 else if (ini[0] == "CD1_2")
128 cd12 = ini[1].trimmed().toDouble(&ok[5]);
129 else if (ini[0] == "CD2_1")
130 cd21 = ini[1].trimmed().toDouble(&ok[6]);
131 else if (ini[0] == "CD2_2")
132 cd22 = ini[1].trimmed().toDouble(&ok[7]);
133
134 line = in.readLine();
135 }
136
137 if ( ok[0] && ok[1] && ok[2] && ok[3] )
138 {
139 Bool eastToTheRight = true;
140 if ( ok[4] && ok[5] && ok[6] && ok[7] )
141 {
142 // Negative determinant = positive parity (i.e. east on the left).
143 double det = cd11 * cd22 - cd12 * cd21;
144 if(det < 0)
145 eastToTheRight = false;
146 }
147 int elapsed = static_cast<int>(round(solverTimer.elapsed() / 1000.0));
148 align->appendLogText(i18np("Solver completed in %1 second.", "Solver completed in %1 seconds.", elapsed));
149 emit solverFinished(orientation, ra, dec, pixscale, eastToTheRight);
150 }
151 else
152 {
153 align->appendLogText(i18n("Solver failed. Try again."));
154 emit solverFailed();
155 }
156}
157
158bool ASTAPAstrometryParser::stopSolver()
159{
160 if (solver.isNull() == false)
161 {
162 solver->terminate();
163 solver->disconnect();
164 }
165
166 return true;
167}
168}
QString i18np(const char *singular, const char *plural, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QString tempPath()
bool exists() const const
qsizetype count() const const
void errorOccurred(QProcess::ProcessError error)
void finished(int exitCode, QProcess::ExitStatus exitStatus)
void clear()
bool isNull() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
QTextStream & dec(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.