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 <[email protected]>
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 
20 AlignView::AlignView(QWidget *parent, FITSMode mode, FITSScale filter) : FITSView(parent, mode, filter)
21 {
22 }
23 
24 void 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 
37 bool AlignView::injectWCS(double orientation, double ra, double dec, double pixscale, bool eastToTheRight, bool extras,
38  bool block)
39 {
40  m_ImageData->injectWCS(orientation, ra, dec, pixscale, eastToTheRight);
41 
42  if (block)
43  {
44  if (wcsWatcher.isRunning() == false && m_ImageData->getWCSState() == FITSData::Idle)
45  {
46  // Load WCS async
47  QFuture<bool> future = QtConcurrent::run(m_ImageData.data(), &FITSData::loadWCS, extras);
48  wcsWatcher.setFuture(future);
49  }
50  return true;
51  }
52  // This should probably not be called in a UI thread when extras is true.
53  return m_ImageData->loadWCS(extras);
54 }
55 
56 void AlignView::reset()
57 {
58  correctionFrom = QPointF();
59  correctionTo = QPointF();
60  correctionAltTo = QPointF();
61  markerCrosshair = QPointF();
62  celestialPolePoint = QPointF();
63  raAxis = QPointF();
64  starCircle = QPointF();
65  releaseImage();
66 }
67 
68 void AlignView::setCorrectionParams(const QPointF &from, const QPointF &to, const QPointF &altTo)
69 {
70  if (m_ImageData.isNull())
71  return;
72 
73  correctionFrom = from;
74  correctionTo = to;
75  correctionAltTo = altTo;
76  markerCrosshair = to;
77 
78  updateFrame(true);
79 }
80 
81 void AlignView::setStarCircle(const QPointF &pixel)
82 {
83  starCircle = pixel;
84  updateFrame(true);
85 }
86 
87 void AlignView::drawTriangle(QPainter *painter, const QPointF &from, const QPointF &to, const QPointF &altTo)
88 {
89  if (from.isNull() && to.isNull() && altTo.isNull())
90  return;
91 
93  painter->setBrush(Qt::NoBrush);
94 
95  const double scale = getScale();
96 
97  // Some of the points may be out of the image.
98  painter->setPen(QPen(Qt::magenta, 2));
99  painter->drawLine(from.x() * scale, from.y() * scale, to.x() * scale, to.y() * scale);
100 
101  painter->setPen(QPen(Qt::yellow, 3));
102  painter->drawLine(from.x() * scale, from.y() * scale, altTo.x() * scale, altTo.y() * scale);
103 
104  painter->setPen(QPen(Qt::green, 3));
105  painter->drawLine(altTo.x() * scale, altTo.y() * scale, to.x() * scale, to.y() * scale);
106 
107  // In limited memory mode, WCS data is not loaded so no Equatorial Gridlines are drawn
108  // so we have to at least draw the NCP/SCP locations
109  if (Options::limitedResourcesMode() && !celestialPolePoint.isNull()
110  && m_ImageData->contains(celestialPolePoint))
111  {
112  QPen pen;
113  pen.setWidth(2);
114  pen.setColor(Qt::darkRed);
115  painter->setPen(pen);
116  double x = celestialPolePoint.x() * scale;
117  double y = celestialPolePoint.y() * scale;
118  double sr = 3 * scale;
119 
120  if (KStarsData::Instance()->geo()->lat()->Degrees() > 0)
121  painter->drawText(x + sr, y + sr, i18nc("North Celestial Pole", "NCP"));
122  else
123  painter->drawText(x + sr, y + sr, i18nc("South Celestial Pole", "SCP"));
124  }
125 }
126 
127 void AlignView::drawStarCircle(QPainter *painter, const QPointF &center, double radius, const QColor &color)
128 {
129  if (center.isNull())
130  return;
131 
133  painter->setBrush(Qt::NoBrush);
134 
135  const double scale = getScale();
136  QPointF pt(center.x() * scale, center.y() * scale);
137 
138  // Could get fancy and change from yellow to green when closer to the green line.
139  painter->setPen(QPen(color, 1));
140  painter->drawEllipse(pt, radius, radius);
141 }
142 
143 void AlignView::drawRaAxis(QPainter *painter)
144 {
145  if (raAxis.isNull() || !m_ImageData->contains(raAxis))
146  return;
147 
148  QPen pen(Qt::green);
149  pen.setWidth(2);
150  pen.setStyle(Qt::DashLine);
151  painter->setPen(pen);
152  painter->setBrush(Qt::NoBrush);
153 
154  const double scale = getScale();
155  const QPointF center(raAxis.x() * scale, raAxis.y() * scale);
156 
157  // Big Radius
158  const double r = 200 * scale;
159 
160  // Small radius
161  const double sr = r / 25.0;
162 
163  painter->drawEllipse(center, sr, sr);
164  painter->drawEllipse(center, r, r);
165  pen.setColor(Qt::darkGreen);
166  painter->setPen(pen);
167  painter->drawText(center.x() + sr, center.y() + sr, i18n("RA Axis"));
168 }
169 
170 void AlignView::setRaAxis(const QPointF &value)
171 {
172  raAxis = value;
173  updateFrame(true);
174 }
175 
176 void AlignView::setCelestialPole(const QPointF &value)
177 {
178  celestialPolePoint = value;
179  updateFrame(true);
180 }
181 
182 void AlignView::setRefreshEnabled(bool enable)
183 {
184  if (enable)
185  setCursorMode(crosshairCursor);
186  else
187  setCursorMode(selectCursor);
188 }
189 
190 void AlignView::processMarkerSelection(int x, int y)
191 {
192  Q_UNUSED(x)
193  Q_UNUSED(y)
194 }
195 
196 void AlignView::holdOnToImage()
197 {
198  keptImagePointer = m_ImageData;
199 }
200 
201 void AlignView::releaseImage()
202 {
203  keptImagePointer.reset();
204 }
void setPen(const QColor &color)
QFuture< T > run(Function function,...)
void drawEllipse(const QRectF &rectangle)
void drawText(const QPointF &position, const QString &text)
void setColor(const QColor &color)
QString i18n(const char *text, const TYPE &arg...)
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
void setWidth(int width)
GeoCoordinates geo(const QVariant &location)
void setBrush(const QBrush &brush)
void setOpacity(qreal opacity)
qreal x() const const
qreal y() const const
void drawLine(const QLineF &line)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QTextStream & center(QTextStream &stream)
void setStyle(Qt::PenStyle style)
void setRenderHint(QPainter::RenderHint hint, bool on)
DashLine
bool isNull() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 9 2022 04:06:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.