Kstars

alignview.cpp
1/* Ekos Alignment View
2 Child of AlignView with few additions necessary for Alignment functions
3
4 SPDX-FileCopyrightText: 2017 Jasem Mutlaq <mutlaqja@ikarustech.com>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7*/
8
9#include "alignview.h"
10
11#include "ekos_align_debug.h"
12#include "kstarsdata.h"
13#include <math.h>
14#include "Options.h"
15#include "fitsviewer/fitsdata.h"
16
17#include <QPainter>
18#include <QtConcurrent>
19
20AlignView::AlignView(QWidget *parent, FITSMode mode, FITSScale filter) : FITSView(parent, mode, filter)
21{
22}
23
24void AlignView::drawOverlay(QPainter *painter, double scale)
25{
26 Q_UNUSED(scale);
27 painter->setOpacity(0.5);
28 FITSView::drawOverlay(painter, getScale());
29 painter->setOpacity(1);
30
31 // drawRaAxis/Triangle/StarCircle all make sure their points are valid.
32 drawRaAxis(painter);
33 drawTriangle(painter, correctionFrom, correctionTo, correctionAltTo);
34 drawStarCircle(painter, starCircle, 35.0, Qt::yellow);
35}
36
37bool AlignView::injectWCS(double orientation, double ra, double dec, double pixscale, bool eastToTheRight, bool block)
38{
39 m_ImageData->injectWCS(orientation, ra, dec, pixscale, eastToTheRight);
40
41 if (block)
42 {
43 if (wcsWatcher.isRunning() == false && m_ImageData->getWCSState() == FITSData::Idle)
44 {
45 // Load WCS async
46#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
47 QFuture<bool> future = QtConcurrent::run(&FITSData::loadWCS, m_ImageData.data());
48#else
49 QFuture<bool> future = QtConcurrent::run(m_ImageData.data(), &FITSData::loadWCS);
50#endif
51 wcsWatcher.setFuture(future);
52 }
53 return true;
54 }
55 // This should probably not be called in a UI thread when extras is true.
56 return m_ImageData->loadWCS();
57}
58
59void AlignView::reset()
60{
61 correctionFrom = QPointF();
62 correctionTo = QPointF();
63 correctionAltTo = QPointF();
64 markerCrosshair = QPointF();
65 celestialPolePoint = QPointF();
66 raAxis = QPointF();
67 starCircle = QPointF();
68 releaseImage();
69}
70
71void AlignView::setCorrectionParams(const QPointF &from, const QPointF &to, const QPointF &altTo)
72{
73 if (m_ImageData.isNull())
74 return;
75
76 correctionFrom = from;
77 correctionTo = to;
78 correctionAltTo = altTo;
79 markerCrosshair = to;
80
81 updateFrame(true);
82}
83
84void AlignView::setStarCircle(const QPointF &pixel)
85{
86 starCircle = pixel;
87 updateFrame(true);
88}
89
90void AlignView::drawTriangle(QPainter *painter, const QPointF &from, const QPointF &to, const QPointF &altTo)
91{
92 if (from.isNull() && to.isNull() && altTo.isNull())
93 return;
94
96 painter->setBrush(Qt::NoBrush);
97
98 const double scale = getScale();
99
100 // Some of the points may be out of the image.
101 painter->setPen(QPen(Qt::magenta, 2));
102 painter->drawLine(from.x() * scale, from.y() * scale, to.x() * scale, to.y() * scale);
103
104 painter->setPen(QPen(Qt::yellow, 3));
105 painter->drawLine(from.x() * scale, from.y() * scale, altTo.x() * scale, altTo.y() * scale);
106
107 painter->setPen(QPen(Qt::green, 3));
108 painter->drawLine(altTo.x() * scale, altTo.y() * scale, to.x() * scale, to.y() * scale);
109
110 // In limited memory mode, WCS data is not loaded so no Equatorial Gridlines are drawn
111 // so we have to at least draw the NCP/SCP locations
112 // if (Options::limitedResourcesMode() && !celestialPolePoint.isNull()
113 // && m_ImageData->contains(celestialPolePoint))
114 // {
115 // QPen pen;
116 // pen.setWidth(2);
117 // pen.setColor(Qt::darkRed);
118 // painter->setPen(pen);
119 // double x = celestialPolePoint.x() * scale;
120 // double y = celestialPolePoint.y() * scale;
121 // double sr = 3 * scale;
122
123 // if (KStarsData::Instance()->geo()->lat()->Degrees() > 0)
124 // painter->drawText(x + sr, y + sr, i18nc("North Celestial Pole", "NCP"));
125 // else
126 // painter->drawText(x + sr, y + sr, i18nc("South Celestial Pole", "SCP"));
127 // }
128}
129
130void AlignView::drawStarCircle(QPainter *painter, const QPointF &center, double radius, const QColor &color)
131{
132 if (center.isNull())
133 return;
134
136 painter->setBrush(Qt::NoBrush);
137
138 const double scale = getScale();
139 QPointF pt(center.x() * scale, center.y() * scale);
140
141 // Could get fancy and change from yellow to green when closer to the green line.
142 painter->setPen(QPen(color, 1));
143 painter->drawEllipse(pt, radius, radius);
144}
145
146void AlignView::drawRaAxis(QPainter *painter)
147{
148 if (raAxis.isNull() || !m_ImageData->contains(raAxis))
149 return;
150
151 QPen pen(Qt::green);
152 pen.setWidth(2);
153 pen.setStyle(Qt::DashLine);
154 painter->setPen(pen);
155 painter->setBrush(Qt::NoBrush);
156
157 const double scale = getScale();
158 const QPointF center(raAxis.x() * scale, raAxis.y() * scale);
159
160 // Big Radius
161 const double r = 200 * scale;
162
163 // Small radius
164 const double sr = r / 25.0;
165
166 painter->drawEllipse(center, sr, sr);
167 painter->drawEllipse(center, r, r);
168 pen.setColor(Qt::darkGreen);
169 painter->setPen(pen);
170 painter->drawText(center.x() + sr, center.y() + sr, i18n("RA Axis"));
171}
172
173void AlignView::setRaAxis(const QPointF &value)
174{
175 raAxis = value;
176 updateFrame(true);
177}
178
179void AlignView::setCelestialPole(const QPointF &value)
180{
181 celestialPolePoint = value;
182 updateFrame(true);
183}
184
185void AlignView::setRefreshEnabled(bool enable)
186{
187 if (enable)
188 setCursorMode(crosshairCursor);
189 else
190 setCursorMode(selectCursor);
191}
192
193void AlignView::processMarkerSelection(int x, int y)
194{
195 Q_UNUSED(x)
196 Q_UNUSED(y)
197}
198
199void AlignView::holdOnToImage()
200{
201 keptImagePointer = m_ImageData;
202}
203
204void AlignView::releaseImage()
205{
206 keptImagePointer.reset();
207}
QString i18n(const char *text, const TYPE &arg...)
bool isRunning() const const
void setFuture(const QFuture< T > &future)
void drawEllipse(const QPoint &center, int rx, int ry)
void drawLine(const QLine &line)
void drawText(const QPoint &position, const QString &text)
void setBrush(Qt::BrushStyle style)
void setOpacity(qreal opacity)
void setPen(Qt::PenStyle style)
void setRenderHint(RenderHint hint, bool on)
bool isNull() const const
qreal x() const const
qreal y() const const
T * data() const const
bool isNull() const const
DashLine
QTextStream & center(QTextStream &stream)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
QFuture< T > run(Function function,...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:15:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.