Kstars

guideview.cpp
1 /* Ekos GuideView
2  Child of FITSView with few additions necessary for Internal Guider
3 
4  SPDX-FileCopyrightText: 2020 Hy Murveit <[email protected]>
5 
6  SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 
9 #include "guideview.h"
10 
11 #include <QPainter>
12 #include <math.h>
13 
14 GuideView::GuideView(QWidget *parent, FITSMode mode, FITSScale filter) : FITSView(parent, mode, filter)
15 {
16 }
17 
18 void GuideView::updateNeighbors()
19 {
20  if (newNeighbors)
21  updateFrame(true);
22 }
23 
24 void GuideView::drawOverlay(QPainter *painter, double scale)
25 {
26  Q_UNUSED(scale);
27 
28  FITSView::drawOverlay(painter, getScale());
29 
30  for (const auto &neighbor : neighbors)
31  drawNeighbor(painter, neighbor);
32  newNeighbors = false;
33 
34 }
35 
36 void GuideView::addGuideStarNeighbor(double targetX, double targetY, bool found,
37  double detectedX, double detectedY, bool isGuideStar)
38 {
39  Neighbor n;
40  n.targetX = targetX;
41  n.targetY = targetY;
42  n.found = found;
43  n.detectedX = detectedX;
44  n.detectedY = detectedY;
45  n.isGuideStar = isGuideStar;
46  neighbors.append(n);
47  newNeighbors = true;
48 }
49 
50 void GuideView::clearNeighbors()
51 {
52  neighbors.clear();
53 }
54 
55 // We draw a circle around each "neighbor" star and draw a line from the guide star to the neighbor
56 // Which starts at the reticle around the guide star and ends at the circle around the neighbor.
57 void GuideView::drawNeighbor(QPainter *painter, const Neighbor &neighbor)
58 {
59  double origOpacity = painter->opacity();
60  QPen pen(neighbor.found ? Qt::green : Qt::red);
61  pen.setWidth(2);
62  pen.setStyle(Qt::SolidLine);
63  painter->setPen(pen);
64  painter->setBrush(Qt::NoBrush);
65  const double scale = getScale();
66 
67  if (!neighbor.isGuideStar)
68  {
69  const QPointF center(neighbor.targetX * scale, neighbor.targetY * scale);
70  const double r = 10.0 * scale;
71  painter->drawEllipse(center, r, r);
72 
73  const QRect &box = getTrackingBox();
74  const int x1 = (box.x() + box.width() / 2.0) * scale;
75  const int y1 = (box.y() + box.height() / 2.0) * scale;
76  painter->setOpacity(0.25);
77  const double dx = neighbor.targetX * scale - x1;
78  const double dy = neighbor.targetY * scale - y1;
79 
80  const double lineLength = std::hypotf(fabs(dx), fabs(dy));
81 
82  // f1 indicates the place along line between the guide star and the neighbor star
83  // where the line should start because it intersects the reticle box around the guide star.
84  double f1;
85  if (std::fabs(dx) > std::fabs(dy))
86  {
87  const double rBox = scale * box.width() / 2.0;
88  f1 = std::hypot(rBox, std::fabs(dy) * rBox / std::fabs(dx)) / lineLength;
89  }
90  else
91  {
92  const double rBox = scale * box.height() / 2.0;
93  f1 = std::hypotf(rBox, std::fabs(dx) * rBox / std::fabs(dy)) / lineLength;
94  }
95  // f2 indicates the place along line between the guide star and the neighbor star
96  // where the line should stop because it intersects the circle around the neighbor.
97  const double f2 = 1.0 - (r / lineLength);
98 
99  if (f1 < 1 && lineLength > r)
100  painter->drawLine(x1 + dx * f1, y1 + dy * f1, x1 + dx * f2, y1 + dy * f2);
101  }
102  painter->setOpacity(origOpacity);
103 }
void append(const T &value)
void setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
int width() const const
int x() const const
int y() const const
qreal opacity() const const
QFuture< void > filter(Sequence &sequence, KeepFunctor filterFunction)
void setBrush(const QBrush &brush)
void setOpacity(qreal opacity)
int height() const const
void drawLine(const QLineF &line)
void clear()
QTextStream & center(QTextStream &stream)
SolidLine
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 8 2022 04:13:21 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.