Kstars

focusdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2002 Jason Harris <kstars@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "focusdialog.h"
8
9#include "dms.h"
10#include "kstars.h"
11#include "kstarsdata.h"
12#include "ksnotification.h"
13#include "skymap.h"
14#include "skyobjects/skypoint.h"
15
16#include <KLocalizedString>
17#include <QDoubleValidator>
18#include <KMessageBox>
19#include <QPushButton>
20
21#include <QVBoxLayout>
22
23FocusDialogUI::FocusDialogUI(QWidget *parent) : QFrame(parent)
24{
25 setupUi(this);
26}
27
29{
30#ifdef Q_OS_MACOS
32#endif
33 //initialize point to the current focus position
34 Point = SkyMap::Instance()->focus();
35
36 constexpr const char* J2000EpochString = "2000.0";
37 fd = new FocusDialogUI(this);
38
39 QVBoxLayout *mainLayout = new QVBoxLayout;
40 mainLayout->addWidget(fd);
41 setLayout(mainLayout);
42
43 setWindowTitle(i18nc("@title:window", "Set Coordinates Manually"));
44
46 mainLayout->addWidget(buttonBox);
47 connect(buttonBox, SIGNAL(accepted()), this, SLOT(validatePoint()));
48 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
49
50 okB = buttonBox->button(QDialogButtonBox::Ok);
51 okB->setEnabled(false);
52
53 fd->epochBox->setText(J2000EpochString);
54 fd->epochBox->setValidator(new QDoubleValidator(fd->epochBox));
55 fd->raBox->setMinimumWidth(fd->raBox->fontMetrics().boundingRect("00h 00m 00s").width());
56 fd->azBox->setMinimumWidth(fd->raBox->fontMetrics().boundingRect("00h 00m 00s").width());
57
58 fd->raBox->setUnits(dmsBox::HOURS); //RA box should be HMS-style
59 fd->raBox->setFocus(); //set input focus
60
61 const SkyPoint *center {nullptr};
62 if (SkyMap::Instance()->focusObject())
63 center = dynamic_cast<const SkyPoint*>(SkyMap::Instance()->focusObject());
64 else
65 center = const_cast<const SkyPoint*>(SkyMap::Instance()->focusPoint());
66
67 if (center)
68 {
69 // Make a copy so as to not affect the existing center point / object
70 SkyPoint centerCopy {*center};
71 //center->deprecess(KStarsData::Instance()->updateNum());
72 centerCopy.catalogueCoord(KStarsData::Instance()->updateNum()->julianDay());
73 fd->raBox->show(centerCopy.ra());
74 fd->decBox->show(centerCopy.dec());
75
76 fd->azBox->show(centerCopy.az());
77 fd->altBox->show(centerCopy.alt());
78
80 }
81
82 connect(fd->raBox, SIGNAL(textChanged(QString)), this, SLOT(checkLineEdits()));
83 connect(fd->decBox, SIGNAL(textChanged(QString)), this, SLOT(checkLineEdits()));
84 connect(fd->azBox, SIGNAL(textChanged(QString)), this, SLOT(checkLineEdits()));
85 connect(fd->altBox, SIGNAL(textChanged(QString)), this, SLOT(checkLineEdits()));
86
87 connect(fd->J2000B, &QPushButton::clicked, this, [&]()
88 {
89 fd->epochBox->setText(J2000EpochString);
90 });
91 connect(fd->JNowB, &QPushButton::clicked, this, [&]()
92 {
93 fd->epochBox->setText(QString::number(KStarsData::Instance()->lt().epoch(), 'f', 3));
94 });
95
96}
97
99{
100 bool raOk(false), decOk(false), azOk(false), altOk(false);
101
102 fd->raBox->createDms(&raOk);
103 fd->decBox->createDms(&decOk);
104 fd->azBox->createDms(&azOk);
105 fd->altBox->createDms(&altOk);
106
107 if ((raOk && decOk) || (azOk && altOk))
108 okB->setEnabled(true);
109 else
110 okB->setEnabled(false);
111}
112
114{
115 bool raOk(false), decOk(false), azOk(false), altOk(false);
116 QString message;
117
118 if (fd->fdTab->currentWidget() == fd->rdTab)
119 {
120 //false means expressed in hours
121 dms ra(fd->raBox->createDms(&raOk));
122 dms dec(fd->decBox->createDms(&decOk));
123
124 if (raOk && decOk)
125 {
126 //make sure values are in valid range
127 if (ra.Hours() < 0.0 || ra.Hours() > 24.0)
128 message = i18n("The Right Ascension value must be between 0.0 and 24.0.");
129 if (dec.Degrees() < -90.0 || dec.Degrees() > 90.0)
130 message += '\n' + i18n("The Declination value must be between -90.0 and 90.0.");
131 if (!message.isEmpty())
132 {
133 KSNotification::sorry(message, i18n("Invalid Coordinate Data"));
134 return;
135 }
136
137 bool ok { false };
138 double epoch0 = KStarsDateTime::stringToEpoch(fd->epochBox->text(), ok);
139 if (!ok)
140 {
141 KSNotification::sorry(message, i18n("Invalid Epoch format"));
142 return;
143 }
144 long double jd0 = KStarsDateTime::epochToJd(epoch0);
145
146 // Set RA and Dec to whatever epoch we have been given (may be J2000, JNow or something completely different)
147 Point->setRA(ra);
148 Point->setDec(dec);
149
150 if (jd0 != J2000)
151 {
152 // Compute and set the J2000 coordinates of Point
153 Point->catalogueCoord(jd0);
154 }
155 else
156 {
157 Point->setRA0(ra);
158 Point->setDec0(dec);
159 }
160
161 // N.B. At this point (ra, dec) and (ra0, dec0) are both
162 // J2000.0 values Therefore, we precess again to get the
163 // values for the present draw epoch into (ra, dec)
164 Point->apparentCoord(static_cast<long double>(J2000), KStarsData::Instance()->updateNum()->julianDay());
165
166 Point->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
167 // At this point, both (RA, Dec) and (Alt, Az) should correspond to current time
168 // (RA0, Dec0) will be J2000.0 -- asimha
169
171 }
172 else
173 {
175 }
176 }
177 else // Az/Alt tab is active
178 {
179 dms az(fd->azBox->createDms(&azOk));
180 dms alt(fd->altBox->createDms(&altOk));
181
182 if (azOk && altOk)
183 {
184 //make sure values are in valid range
185 if (az.Degrees() < 0.0 || az.Degrees() > 360.0)
186 message = i18n("The Azimuth value must be between 0.0 and 360.0.");
187 if (alt.Degrees() < -90.0 || alt.Degrees() > 90.0)
188 message += '\n' + i18n("The Altitude value must be between -90.0 and 90.0.");
189 if (!message.isEmpty())
190 {
191 KSNotification::sorry(message, i18n("Invalid Coordinate Data"));
192 return;
193 }
194
195 Point->setAz(az);
196 Point->setAltRefracted(alt);
197 Point->HorizontalToEquatorial(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
198
199 UsedAltAz = true;
200
202 }
203 else
204 {
206 }
207 }
208}
209
211{
212 return QSize(350, 210);
213}
214
216{
217 fd->fdTab->setCurrentWidget(fd->aaTab);
218 fd->azBox->setFocus();
219}
void activateAzAltPage() const
Show the Az/Alt page instead of the RA/Dec page.
void checkLineEdits()
If text has been entered in both KLineEdits, enable the Ok button.
void validatePoint()
Attempt to interpret the text in the KLineEdits as Ra and Dec values.
FocusDialog()
Constructor.
QSize sizeHint() const override
static long double epochToJd(double epoch, EpochType type=JULIAN)
Takes in an epoch and returns a Julian Date.
static double stringToEpoch(const QString &eName, bool &ok)
Takes in a string and returns a Julian epoch.
This is the main window for KStars.
Definition kstars.h:89
SkyPoint * focusPoint()
retrieve the FocusPoint position.
Definition skymap.h:149
SkyPoint * focus()
Retrieve the Focus point; the position on the sky at the center of the skymap.
Definition skymap.h:123
SkyObject * focusObject() const
Retrieve the object which is centered in the sky map.
Definition skymap.h:262
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
void setAltRefracted(dms alt_apparent)
Sets the apparent altitude, checking whether refraction corrections are enabled.
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
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
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
void setDec0(dms d)
Sets Dec0, the catalog Declination.
Definition skypoint.h:119
SkyPoint catalogueCoord(long double jdf)
Computes the J2000.0 catalogue coordinates for this SkyPoint using the epoch removing aberration,...
Definition skypoint.cpp:710
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
double Hours() const
Definition dms.h:168
const double & Degrees() const
Definition dms.h:141
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void clicked(bool checked)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void accept()
void accepted()
virtual void reject()
void rejected()
QPushButton * button(StandardButton which) const const
QRect boundingRect(QChar ch) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
int width() const const
bool isEmpty() const const
void setEnabled(bool)
QFontMetrics fontMetrics() const const
void setMinimumWidth(int minw)
void setFocus()
void setLayout(QLayout *layout)
void show()
void setWindowFlags(Qt::WindowFlags type)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.