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 QFuture<bool> future = QtConcurrent::run(m_ImageData.data(), &FITSData::loadWCS);
47 wcsWatcher.setFuture(future);
48 }
49 return true;
50 }
51 // This should probably not be called in a UI thread when extras is true.
52 return m_ImageData->loadWCS();
53}
54
55void AlignView::reset()
56{
57 correctionFrom = QPointF();
58 correctionTo = QPointF();
59 correctionAltTo = QPointF();
60 markerCrosshair = QPointF();
61 celestialPolePoint = QPointF();
62 raAxis = QPointF();
63 starCircle = QPointF();
64 releaseImage();
65}
66
67void AlignView::setCorrectionParams(const QPointF &from, const QPointF &to, const QPointF &altTo)
68{
69 if (m_ImageData.isNull())
70 return;
71
72 correctionFrom = from;
73 correctionTo = to;
74 correctionAltTo = altTo;
75 markerCrosshair = to;
76
77 updateFrame(true);
78}
79
80void AlignView::setStarCircle(const QPointF &pixel)
81{
82 starCircle = pixel;
83 updateFrame(true);
84}
85
86void AlignView::drawTriangle(QPainter *painter, const QPointF &from, const QPointF &to, const QPointF &altTo)
87{
88 if (from.isNull() && to.isNull() && altTo.isNull())
89 return;
90
92 painter->setBrush(Qt::NoBrush);
93
94 const double scale = getScale();
95
96 // Some of the points may be out of the image.
97 painter->setPen(QPen(Qt::magenta, 2));
98 painter->drawLine(from.x() * scale, from.y() * scale, to.x() * scale, to.y() * scale);
99
100 painter->setPen(QPen(Qt::yellow, 3));
101 painter->drawLine(from.x() * scale, from.y() * scale, altTo.x() * scale, altTo.y() * scale);
102
103 painter->setPen(QPen(Qt::green, 3));
104 painter->drawLine(altTo.x() * scale, altTo.y() * scale, to.x() * scale, to.y() * scale);
105
106 // In limited memory mode, WCS data is not loaded so no Equatorial Gridlines are drawn
107 // so we have to at least draw the NCP/SCP locations
108 // if (Options::limitedResourcesMode() && !celestialPolePoint.isNull()
109 // && m_ImageData->contains(celestialPolePoint))
110 // {
111 // QPen pen;
112 // pen.setWidth(2);
113 // pen.setColor(Qt::darkRed);
114 // painter->setPen(pen);
115 // double x = celestialPolePoint.x() * scale;
116 // double y = celestialPolePoint.y() * scale;
117 // double sr = 3 * scale;
118
119 // if (KStarsData::Instance()->geo()->lat()->Degrees() > 0)
120 // painter->drawText(x + sr, y + sr, i18nc("North Celestial Pole", "NCP"));
121 // else
122 // painter->drawText(x + sr, y + sr, i18nc("South Celestial Pole", "SCP"));
123 // }
124}
125
126void AlignView::drawStarCircle(QPainter *painter, const QPointF &center, double radius, const QColor &color)
127{
128 if (center.isNull())
129 return;
130
132 painter->setBrush(Qt::NoBrush);
133
134 const double scale = getScale();
135 QPointF pt(center.x() * scale, center.y() * scale);
136
137 // Could get fancy and change from yellow to green when closer to the green line.
138 painter->setPen(QPen(color, 1));
139 painter->drawEllipse(pt, radius, radius);
140}
141
142void AlignView::drawRaAxis(QPainter *painter)
143{
144 if (raAxis.isNull() || !m_ImageData->contains(raAxis))
145 return;
146
147 QPen pen(Qt::green);
148 pen.setWidth(2);
149 pen.setStyle(Qt::DashLine);
150 painter->setPen(pen);
151 painter->setBrush(Qt::NoBrush);
152
153 const double scale = getScale();
154 const QPointF center(raAxis.x() * scale, raAxis.y() * scale);
155
156 // Big Radius
157 const double r = 200 * scale;
158
159 // Small radius
160 const double sr = r / 25.0;
161
162 painter->drawEllipse(center, sr, sr);
163 painter->drawEllipse(center, r, r);
164 pen.setColor(Qt::darkGreen);
165 painter->setPen(pen);
166 painter->drawText(center.x() + sr, center.y() + sr, i18n("RA Axis"));
167}
168
169void AlignView::setRaAxis(const QPointF &value)
170{
171 raAxis = value;
172 updateFrame(true);
173}
174
175void AlignView::setCelestialPole(const QPointF &value)
176{
177 celestialPolePoint = value;
178 updateFrame(true);
179}
180
181void AlignView::setRefreshEnabled(bool enable)
182{
183 if (enable)
184 setCursorMode(crosshairCursor);
185 else
186 setCursorMode(selectCursor);
187}
188
189void AlignView::processMarkerSelection(int x, int y)
190{
191 Q_UNUSED(x)
192 Q_UNUSED(y)
193}
194
195void AlignView::holdOnToImage()
196{
197 keptImagePointer = m_ImageData;
198}
199
200void AlignView::releaseImage()
201{
202 keptImagePointer.reset();
203}
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 May 24 2024 11:49:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.