Kstars

guidetargetplot.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3 SPDX-FileCopyrightText: 2021 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8
9#include "guidetargetplot.h"
10#include "guidegraph.h"
11#include "klocalizedstring.h"
12#include "kstarsdata.h"
13#include "Options.h"
14
15
16GuideTargetPlot::GuideTargetPlot(QWidget *parent) : QCustomPlot (parent)
17{
18 Q_UNUSED(parent);
19 //drift plot
20 double accuracyRadius = Options::guiderAccuracyThreshold();
21
22 setBackground(QBrush(Qt::black));
23 setSelectionTolerance(10);
24
25 xAxis->setBasePen(QPen(Qt::white, 1));
26 yAxis->setBasePen(QPen(Qt::white, 1));
27
28 xAxis->setTickPen(QPen(Qt::white, 1));
29 yAxis->setTickPen(QPen(Qt::white, 1));
30
31 xAxis->setSubTickPen(QPen(Qt::white, 1));
32 yAxis->setSubTickPen(QPen(Qt::white, 1));
33
34 xAxis->setTickLabelColor(Qt::white);
35 yAxis->setTickLabelColor(Qt::white);
36
37 xAxis->setLabelColor(Qt::white);
38 yAxis->setLabelColor(Qt::white);
39
40 xAxis->setLabelFont(QFont(font().family(), 9));
41 yAxis->setLabelFont(QFont(font().family(), 9));
42 xAxis->setTickLabelFont(QFont(font().family(), 9));
43 yAxis->setTickLabelFont(QFont(font().family(), 9));
44
45 xAxis->setLabelPadding(2);
46 yAxis->setLabelPadding(2);
47
48 xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
49 yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
50 xAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
51 yAxis->grid()->setSubGridPen(QPen(QColor(80, 80, 80), 1, Qt::DotLine));
52 xAxis->grid()->setZeroLinePen(QPen(Qt::gray));
53 yAxis->grid()->setZeroLinePen(QPen(Qt::gray));
54
55 xAxis->setLabel(i18n("dRA (arcsec)"));
56 yAxis->setLabel(i18n("dDE (arcsec)"));
57
58 xAxis->setRange(-accuracyRadius * 3, accuracyRadius * 3);
59 yAxis->setRange(-accuracyRadius * 3, accuracyRadius * 3);
60
61 setInteractions(QCP::iRangeZoom);
62 setInteraction(QCP::iRangeDrag, true);
63
64 addGraph();
65 graph(GuideGraph::G_RA)->setLineStyle(QCPGraph::lsNone);
66 graph(GuideGraph::G_RA)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssStar, Qt::gray, 5));
67
68 addGraph();
69 graph(GuideGraph::G_DEC)->setLineStyle(QCPGraph::lsNone);
70 graph(GuideGraph::G_DEC)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusCircle, QPen(Qt::yellow, 2), QBrush(),
71 10));
72
73 setupNSEWLabels();
74
75 // resize(190, 190);
76 replot();
77}
78
79void GuideTargetPlot::showPoint(double ra, double de)
80{
81 graph(GuideGraph::G_DEC)->data()->clear(); //Clear Guide highlighted point
82 graph(GuideGraph::G_DEC)->addData(ra, de); //Set guide highlighted point
83 replot();
84}
85
86void GuideTargetPlot::connectGuider(Ekos::GuideInterface *guider)
87{
88 connect(guider, &Ekos::GuideInterface::newAxisDelta, this, &GuideTargetPlot::setAxisDelta);
89}
90
91void GuideTargetPlot::handleHorizontalPlotSizeChange()
92{
93 resize(size().width(), size().height());
94 replot();
95}
96
97void GuideTargetPlot::handleVerticalPlotSizeChange()
98{
99 resize(size().width(), size().height());
100 replot();
101}
102
103void GuideTargetPlot::resize(int w, int h)
104{
106
107 const int accuracyRadius = Options::guiderAccuracyThreshold();
108 if (w > h)
109 {
110 yAxis->setRange(-accuracyRadius * 3, accuracyRadius * 3);
112 }
113 else
114 {
115 xAxis->setRange(-accuracyRadius * 3, accuracyRadius * 3);
117 }
118 replot();
119}
120
121void GuideTargetPlot::buildTarget(double accuracyRadius)
122{
123 if (centralTarget)
124 {
125 concentricRings->data()->clear();
126 redTarget->data()->clear();
127 yellowTarget->data()->clear();
128 centralTarget->data()->clear();
129 }
130 else
131 {
132 concentricRings = new QCPCurve(xAxis, yAxis);
133 redTarget = new QCPCurve(xAxis, yAxis);
134 yellowTarget = new QCPCurve(xAxis, yAxis);
135 centralTarget = new QCPCurve(xAxis, yAxis);
136 }
137 const int pointCount = 200;
138 QVector<QCPCurveData> circleRings(
139 pointCount * (5)); //Have to multiply by the number of rings, Rings at : 25%, 50%, 75%, 125%, 175%
140 QVector<QCPCurveData> circleCentral(pointCount);
141 QVector<QCPCurveData> circleYellow(pointCount);
142 QVector<QCPCurveData> circleRed(pointCount);
143
144 int circleRingPt = 0;
145 for (int i = 0; i < pointCount; i++)
146 {
147 double theta = i / static_cast<double>(pointCount) * 2 * M_PI;
148
149 for (double ring = 1; ring < 8; ring++)
150 {
151 if (ring != 4 && ring != 6)
152 {
153 if (i % (9 - static_cast<int>(ring)) == 0) //This causes fewer points to draw on the inner circles.
154 {
155 circleRings[circleRingPt] = QCPCurveData(circleRingPt, accuracyRadius * ring * 0.25 * qCos(theta),
156 accuracyRadius * ring * 0.25 * qSin(theta));
157 circleRingPt++;
158 }
159 }
160 }
161
162 circleCentral[i] = QCPCurveData(i, accuracyRadius * qCos(theta), accuracyRadius * qSin(theta));
163 circleYellow[i] = QCPCurveData(i, accuracyRadius * 1.5 * qCos(theta), accuracyRadius * 1.5 * qSin(theta));
164 circleRed[i] = QCPCurveData(i, accuracyRadius * 2 * qCos(theta), accuracyRadius * 2 * qSin(theta));
165 }
166
167 concentricRings->setLineStyle(QCPCurve::lsNone);
168 concentricRings->setScatterSkip(0);
169 concentricRings->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, QColor(255, 255, 255, 150), 1));
170
171 concentricRings->data()->set(circleRings, true);
172 redTarget->data()->set(circleRed, true);
173 yellowTarget->data()->set(circleYellow, true);
174 centralTarget->data()->set(circleCentral, true);
175
176 concentricRings->setPen(QPen(Qt::white));
177 redTarget->setPen(QPen(Qt::red));
178 yellowTarget->setPen(QPen(Qt::yellow));
179 centralTarget->setPen(QPen(Qt::green));
180
181 concentricRings->setBrush(Qt::NoBrush);
182 redTarget->setBrush(QBrush(QColor(255, 0, 0, 50)));
183 yellowTarget->setBrush(
184 QBrush(QColor(0, 255, 0, 50))); //Note this is actually yellow. It is green on top of red with equal opacity.
185 centralTarget->setBrush(QBrush(QColor(0, 255, 0, 50)));
186
187 if (size().width() > 0)
188 resize(size().width(), size().height());
189}
190
191void GuideTargetPlot::setupNSEWLabels()
192{
193 //Labels for N/S/E/W
194 QColor raLabelColor(KStarsData::Instance()->colorScheme()->colorNamed("RAGuideError"));
195 QColor deLabelColor(KStarsData::Instance()->colorScheme()->colorNamed("DEGuideError"));
196
197 QCPItemText *northLabel = new QCPItemText(this);
198 northLabel->setColor(deLabelColor);
199 northLabel->setFont(QFont(font().family(), 9));
200 northLabel->setText(i18nc("North", "N"));
201 northLabel->position->setType(QCPItemPosition::ptViewportRatio);
202 northLabel->position->setCoords(0.25, 0.2);
203 northLabel->setVisible(true);
204
205 QCPItemText *southLabel = new QCPItemText(this);
206 southLabel->setColor(deLabelColor);
207 southLabel->setFont(QFont(font().family(), 9));
208 southLabel->setText(i18nc("South", "S"));
209 southLabel->position->setType(QCPItemPosition::ptViewportRatio);
210 southLabel->position->setCoords(0.25, 0.7);
211 southLabel->setVisible(true);
212
213 QCPItemText *westLabel = new QCPItemText(this);
214 westLabel->setColor(raLabelColor);
215 westLabel->setFont(QFont(font().family(), 9));
216 westLabel->setText(i18nc("West", "W"));
217 westLabel->position->setType(QCPItemPosition::ptViewportRatio);
218 westLabel->position->setCoords(0.8, 0.75);
219 westLabel->setVisible(true);
220
221 QCPItemText *eastLabel = new QCPItemText(this);
222 eastLabel->setColor(raLabelColor);
223 eastLabel->setFont(QFont(font().family(), 9));
224 eastLabel->setText(i18nc("East", "E"));
225 eastLabel->position->setType(QCPItemPosition::ptViewportRatio);
226 eastLabel->position->setCoords(0.3, 0.75);
227 eastLabel->setVisible(true);
228}
229
230void GuideTargetPlot::autoScaleGraphs(double accuracyRadius)
231{
232 xAxis->setRange(-accuracyRadius * 3, accuracyRadius * 3);
233 yAxis->setRange(-accuracyRadius * 3, accuracyRadius * 3);
236 replot();
237}
238
239void GuideTargetPlot::clear()
240{
241 graph(GuideGraph::G_RA)->data()->clear(); //Guide data
242 graph(GuideGraph::G_DEC)->data()->clear(); //Guide highlighted point
243 setupNSEWLabels();
244 replot();
245}
246
247void GuideTargetPlot::setAxisDelta(double ra, double de)
248{
249 //Add to Drift Plot
250 graph(GuideGraph::G_RA)->addData(ra, de);
251 if(graphOnLatestPt)
252 {
253 graph(GuideGraph::G_DEC)->data()->clear(); //Clear highlighted point
254 graph(GuideGraph::G_DEC)->addData(ra, de); //Set highlighted point to latest point
255 }
256
257 if (xAxis->range().contains(ra) == false || yAxis->range().contains(de) == false)
258 {
260 QTimer::singleShot(300, this, [ = ]()
261 {
263 replot();
264 });
265 }
266
267 replot();
268}
Interface skeleton for implementation of different guiding applications and/or routines.
void setBrush(const QBrush &brush)
void setPen(const QPen &pen)
Q_SLOT void setRange(const QCPRange &range)
void setScaleRatio(const QCPAxis *otherAxis, double ratio=1.0)
Holds the data of one single data point for QCPCurve.
A plottable representing a parametric curve in a plot.
@ lsNone
No line is drawn between data points (e.g. only scatters)
void setLineStyle(LineStyle style)
void setScatterStyle(const QCPScatterStyle &style)
QSharedPointer< QCPCurveDataContainer > data() const
void setScatterSkip(int skip)
QSharedPointer< QCPGraphDataContainer > data() const
@ lsNone
data points are not connected with any lines (e.g.
void addData(const QVector< double > &keys, const QVector< double > &values, bool alreadySorted=false)
void setType(PositionType type)
void setCoords(double key, double value)
@ ptViewportRatio
Static positioning given by a fraction of the viewport size.
A text label.
void setText(const QString &text)
void setFont(const QFont &font)
void setColor(const QColor &color)
void setVisible(bool on)
bool contains(double value) const
Represents the visual appearance of scatter points.
@ ssDisc
\enumimage{ssDisc.png} a circle which is filled with the pen's color (not the brush as with ssCircle)
@ ssStar
\enumimage{ssStar.png} a star with eight arms, i.e. a combination of cross and plus
@ ssPlusCircle
\enumimage{ssPlusCircle.png} a circle with a plus inside
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
void setBackground(const QPixmap &pm)
QCPAxis * xAxis
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint)
QCPGraph * graph() const
QCPAxis * yAxis
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
@ iRangeDrag
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes)
@ iRangeZoom
0x002 Axis ranges are zoomable with the mouse wheel (see QCPAxisRect::setRangeZoom,...
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.