Kstars

mounttargetwidget.cpp
1/* Widget to slew or sync to a position.
2 SPDX-FileCopyrightText: Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "mounttargetwidget.h"
8#include "kstarsdatetime.h"
9#include "kstarsdata.h"
10#include "kstars.h"
11#include "ekos/manager.h"
12#include "dialogs/finddialog.h"
13
14#define EQ_BUTTON_ID 0
15#define HOR_BUTTON_ID 1
16#define HA_BUTTON_ID 2
17
18namespace Ekos
19{
20MountTargetWidget::MountTargetWidget(QWidget *parent)
21 : QWidget{parent}
22{
23 setupUi(this);
24
25 // Coordinate Button Group
26 targetRATextObject->setUnits(dmsBox::HOURS);
27 coordinateButtonGroup->setId(equatorialCheckObject, EQ_BUTTON_ID);
28 coordinateButtonGroup->setId(horizontalCheckObject, HOR_BUTTON_ID);
29 coordinateButtonGroup->setId(haEquatorialCheckObject, HA_BUTTON_ID);
30 connect(coordinateButtonGroup, &QButtonGroup::idPressed, [this](int id)
31 {
32 updateTargetDisplay(id);
33 });
34
35 // coordinate data changes
36 connect(targetRATextObject, &dmsBox::editingFinished, this, &MountTargetWidget::updateTarget);
37 connect(targetDETextObject, &dmsBox::editingFinished, this, &MountTargetWidget::updateTarget);
38
39 // GOTO
40 connect(gotoButtonObject, &QPushButton::clicked, this, &MountTargetWidget::processSlew);
41 // SYNC
42 connect(syncButtonObject, &QPushButton::clicked, this, &MountTargetWidget::processSync);
43 // Find
44 connect(findButtonObject, &QPushButton::clicked, this, &MountTargetWidget::findTarget);
45}
46
47bool MountTargetWidget::processCoords(dms &ra, dms &de)
48{
49 // do nothing if no target is set
50 if (currentTarget.isNull())
51 return false;
52
53 ra = currentTarget->ra();
54 de = currentTarget->dec();
55
56 return true;
57}
58
59void MountTargetWidget::setTargetPosition(SkyPoint *target)
60{
61 // we assume that JNow is set, update all other coordinates
62 updateJ2000Coordinates(target);
63 currentTarget.reset(target);
64 updateTargetDisplay();
65}
66
67void MountTargetWidget::setTargetName(const QString &name)
68{
69 targetTextObject->setText(name);
70}
71
72bool MountTargetWidget::raDecToAzAlt(QString qsRA, QString qsDec)
73{
74 dms RA, Dec;
75
76 if (!RA.setFromString(qsRA, false) || !Dec.setFromString(qsDec, true))
77 return false;
78
79 SkyPoint targetCoord(RA, Dec);
80
81 targetCoord.EquatorialToHorizontal(KStarsData::Instance()->lst(),
82 KStarsData::Instance()->geo()->lat());
83
84 targetRATextObject->setProperty("text", targetCoord.alt().toDMSString());
85 targetDETextObject->setProperty("text", targetCoord.az().toDMSString());
86
87 return true;
88}
89
90bool MountTargetWidget::raDecToHaDec(QString qsRA)
91{
92 dms RA;
93
94 if (!RA.setFromString(qsRA, false))
95 return false;
96
97 dms lst = KStarsData::Instance()->geo()->GSTtoLST(KStarsData::Instance()->clock()->utc().gst());
98
99 dms HA = (lst - RA + dms(360.0)).reduce();
100
101 QChar sgn('+');
102 if (HA.Hours() > 12.0)
103 {
104 HA.setH(24.0 - HA.Hours());
105 sgn = '-';
106 }
107
108 targetRATextObject->setProperty("text", QString("%1%2").arg(sgn).arg(HA.toHMSString()));
109
110 return true;
111}
112
113bool MountTargetWidget::azAltToRaDec(QString qsAz, QString qsAlt)
114{
115 dms Az, Alt;
116
117 if (!Az.setFromString(qsAz, true) || !Alt.setFromString(qsAlt, true))
118 return false;
119
120 SkyPoint targetCoord;
121 targetCoord.setAz(Az);
122 targetCoord.setAlt(Alt);
123
124 targetCoord.HorizontalToEquatorial(KStars::Instance()->data()->lst(),
125 KStars::Instance()->data()->geo()->lat());
126
127 targetRATextObject->setProperty("text", targetCoord.ra().toHMSString());
128 targetDETextObject->setProperty("text", targetCoord.dec().toDMSString());
129
130 return true;
131}
132
133bool MountTargetWidget::azAltToHaDec(QString qsAz, QString qsAlt)
134{
135 dms Az, Alt;
136
137 if (!Az.setFromString(qsAz, true) || !Alt.setFromString(qsAlt, true))
138 return false;
139
140 SkyPoint targetCoord;
141 targetCoord.setAz(Az);
142 targetCoord.setAlt(Alt);
143
144 dms lst = KStarsData::Instance()->geo()->GSTtoLST(KStarsData::Instance()->clock()->utc().gst());
145
146 targetCoord.HorizontalToEquatorial(&lst, KStars::Instance()->data()->geo()->lat());
147
148 dms HA = (lst - targetCoord.ra() + dms(360.0)).reduce();
149
150 QChar sgn('+');
151 if (HA.Hours() > 12.0)
152 {
153 HA.setH(24.0 - HA.Hours());
154 sgn = '-';
155 }
156
157 targetRATextObject->setProperty("text", QString("%1%2").arg(sgn).arg(HA.toHMSString()));
158 targetDETextObject->setProperty("text", targetCoord.dec().toDMSString());
159
160 return true;
161}
162
163bool MountTargetWidget::haDecToRaDec(QString qsHA)
164{
165 dms HA;
166
167 if (!HA.setFromString(qsHA, false))
168 return false;
169
170 dms lst = KStarsData::Instance()->geo()->GSTtoLST(KStarsData::Instance()->clock()->utc().gst());
171 dms RA = (lst - HA + dms(360.0)).reduce();
172
173 targetRATextObject->setProperty("text", RA.toHMSString());
174
175 return true;
176}
177
178bool MountTargetWidget::haDecToAzAlt(QString qsHA, QString qsDec)
179{
180 dms HA, Dec;
181
182 if (!HA.setFromString(qsHA, false) || !Dec.setFromString(qsDec, true))
183 return false;
184
185 dms lst = KStarsData::Instance()->geo()->GSTtoLST(KStarsData::Instance()->clock()->utc().gst());
186 dms RA = (lst - HA + dms(360.0)).reduce();
187
188 SkyPoint targetCoord;
189 targetCoord.setRA(RA);
190 targetCoord.setDec(Dec);
191
192 targetCoord.EquatorialToHorizontal(&lst, KStars::Instance()->data()->geo()->lat());
193
194 targetRATextObject->setProperty("text", targetCoord.alt().toDMSString());
195 targetDETextObject->setProperty("text", targetCoord.az().toDMSString());
196
197 return true;
198}
199
200void MountTargetWidget::setJ2000Enabled(bool enabled)
201{
202 m_isJ2000 = enabled;
203 updateTargetDisplay();
204}
205
206void MountTargetWidget::processSlew()
207{
208 dms ra, de;
209 if (processCoords(ra, de))
210 emit slew(ra.Hours(), de.Degrees());
211}
212
213void MountTargetWidget::processSync()
214{
215 dms ra, de;
216 if (processCoords(ra, de))
217 emit sync(ra.Hours(), de.Degrees());
218}
219
220void MountTargetWidget::findTarget()
221{
222 if (FindDialog::Instance()->execWithParent(Ekos::Manager::Instance()) == QDialog::Accepted)
223 {
224 auto object = FindDialog::Instance()->targetObject();
225 if (object != nullptr)
226 {
227 auto const data = KStarsData::Instance();
228 auto o = object->clone();
229 o->updateCoords(data->updateNum(), true, data->geo()->lat(), data->lst(), false);
230 o->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
231
232 equatorialCheckObject->setProperty("checked", true);
233
234 targetTextObject->setProperty("text", o->name());
235 currentTarget.reset(o);
236 updateTargetDisplay();
237 }
238 }
239
240}
241
242void MountTargetWidget::updateTargetDisplay(int id, SkyPoint *target)
243{
244 // use current target if none is set
245 if (target == nullptr)
246 target = currentTarget.get();
247 if (id < 0)
248 id = coordinateButtonGroup->checkedId();
249
250 switch (id)
251 {
252 case HOR_BUTTON_ID:
253 targetRALabel->setText("AL:");
254 targetDECLabel->setText("AZ:");
255 targetRATextObject->setUnits(dmsBox::DEGREES);
256 if (target != nullptr)
257 {
258 targetRATextObject->setText(target->alt().toDMSString());
259 targetDETextObject->setText(target->az().toDMSString());
260 }
261 break;
262 case HA_BUTTON_ID:
263 targetRALabel->setText("HA:");
264 targetDECLabel->setText("DE:");
265 targetRATextObject->setUnits(dmsBox::HOURS);
266 if (target != nullptr)
267 {
268 dms lst = KStarsData::Instance()->geo()->GSTtoLST(KStarsData::Instance()->clock()->utc().gst());
269 dms HA = (lst - target->ra() + dms(360.0)).reduce();
270
271 QChar sgn('+');
272 if (HA.Hours() > 12.0)
273 {
274 HA.setH(24.0 - HA.Hours());
275 sgn = '-';
276 }
277
278 targetRATextObject->setProperty("text", QString("%1%2").arg(sgn).arg(HA.toHMSString()));
279 targetDETextObject->setProperty("text", dms(90 - target->altRefracted().Degrees()).toDMSString());
280 }
281 break;
282 case EQ_BUTTON_ID:
283 targetRALabel->setText("RA:");
284 targetDECLabel->setText("DE:");
285 targetRATextObject->setUnits(dmsBox::HOURS);
286 if (target != nullptr)
287 {
288 if (m_isJ2000)
289 {
290 targetRATextObject->setText(target->ra0().toHMSString());
291 targetDETextObject->setText(target->dec0().toDMSString());
292 }
293 else
294 {
295 targetRATextObject->setText(target->ra().toHMSString());
296 targetDETextObject->setText(target->dec().toDMSString());
297 }
298 }
299 break;
300 default:
301 // do nothing
302 break;
303 }
304}
305
306bool MountTargetWidget::updateTarget()
307{
308 bool raOK = false, deOK = false;
309 SkyPoint *currentCoords = nullptr;
310 if (horizontalCheckObject->property("checked").toBool())
311 {
312 dms at = targetRATextObject->createDms(&raOK);
313 dms az = targetDETextObject->createDms(&deOK);
314 if (raOK == false || deOK == false)
315 return false;
316
317 currentCoords = new SkyPoint();
318 currentCoords->setAz(az);
319 currentCoords->setAlt(at);
320 currentCoords->HorizontalToEquatorial(KStars::Instance()->data()->lst(), KStars::Instance()->data()->geo()->lat());
321 // calculate J2000 coordinates
322 updateJ2000Coordinates(currentCoords, true, false);
323 }
324 else if (haEquatorialCheckObject->property("checked").toBool())
325 {
326 dms de = targetDETextObject->createDms(&deOK);
327 dms ha = targetRATextObject->createDms(&raOK);
328 if (raOK == false || deOK == false)
329 return false;
330
331 currentCoords = new SkyPoint();
332 currentCoords->setDec(de);
333 dms lst = KStarsData::Instance()->geo()->GSTtoLST(KStarsData::Instance()->clock()->utc().gst());
334 currentCoords->setRA((lst - ha + dms(360.0)).reduce());
335 // calculate J2000 coordinates
336 updateJ2000Coordinates(currentCoords);
337 }
338 else
339 {
340 dms ra = targetRATextObject->createDms(&raOK);
341 dms de = targetDETextObject->createDms(&deOK);
342 if (raOK == false || deOK == false)
343 return false;
344
345 currentCoords = new SkyPoint();
346 // set both JNow and J2000 coordinates
347 if (m_isJ2000)
348 {
349 currentCoords->setRA0(ra);
350 currentCoords->setDec0(de);
351 // update JNow coordinates
352 currentCoords->apparentCoord(static_cast<long double>(J2000), KStars::Instance()->data()->ut().djd());
353 }
354 else
355 {
356 currentCoords->setRA(ra);
357 currentCoords->setDec(de);
358 // calculate J2000 coordinates
359 updateJ2000Coordinates(currentCoords);
360 }
361 currentCoords->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
362 }
363
364 currentTarget.reset(currentCoords);
365 updateTargetDisplay();
366 return true;
367}
368
369void MountTargetWidget::updateJ2000Coordinates(SkyPoint * coords, bool updateJ2000, bool updateHorizontal)
370{
371 // do nothing for empty coordinates
372 if (coords == nullptr)
373 return;
374
375 if (updateJ2000)
376 {
377 SkyPoint J2000Coord(coords->ra(), coords->dec());
378 J2000Coord.catalogueCoord(KStars::Instance()->data()->ut().djd());
379 coords->setRA0(J2000Coord.ra());
380 coords->setDec0(J2000Coord.dec());
381 }
382
383 if (updateHorizontal)
384 coords->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
385}
386
387} // namespace
SkyObject * targetObject()
Definition finddialog.h:53
GeoLocation * geo()
Definition kstarsdata.h:232
static KStars * Instance()
Definition kstars.h:121
The sky coordinates of a point in the sky.
Definition skypoint.h:45
void apparentCoord(long double jd0, long double jdf)
Computes the apparent coordinates for this SkyPoint for any epoch, accounting for the effects of prec...
Definition skypoint.cpp:700
const CachingDms & dec() const
Definition skypoint.h:269
const CachingDms & ra0() const
Definition skypoint.h:251
void setDec(dms d)
Sets Dec, the current Declination.
Definition skypoint.h:169
void setRA(dms &r)
Sets RA, the current Right Ascension.
Definition skypoint.h:144
const CachingDms & ra() const
Definition skypoint.h:263
dms altRefracted() const
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
Definition skypoint.cpp:77
void setRA0(dms r)
Sets RA0, the catalog Right Ascension.
Definition skypoint.h:94
const dms & az() const
Definition skypoint.h:275
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition skypoint.h:194
const dms & alt() const
Definition skypoint.h:281
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates,...
Definition skypoint.cpp:143
void setAz(dms az)
Sets Az, the Azimuth.
Definition skypoint.h:230
const CachingDms & dec0() const
Definition skypoint.h:257
void setDec0(dms d)
Sets Dec0, the catalog Declination.
Definition skypoint.h:119
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
double Hours() const
Definition dms.h:168
virtual void setH(const double &x)
Sets floating-point value of angle, in hours.
Definition dms.h:210
const dms reduce() const
return the equivalent angle between 0 and 360 degrees.
Definition dms.cpp:251
virtual bool setFromString(const QString &s, bool isDeg=true)
Attempt to parse the string argument as a dms value, and set the dms object accordingly.
Definition dms.cpp:48
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
Definition dms.cpp:287
const QString toHMSString(const bool machineReadable=false, const bool highPrecision=false) const
Definition dms.cpp:378
const double & Degrees() const
Definition dms.h:141
Ekos is an advanced Astrophotography tool for Linux.
Definition align.cpp:83
GeoCoordinates geo(const QVariant &location)
void clicked(bool checked)
void idPressed(int id)
void editingFinished()
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.