Kstars

focusdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2002 Jason Harris <[email protected]>
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 
23 FocusDialogUI::FocusDialogUI(QWidget *parent) : QFrame(parent)
24 {
25  setupUi(this);
26 }
27 
29 {
30 #ifdef Q_OS_OSX
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 
117  //false means expressed in hours
118  dms ra(fd->raBox->createDms(&raOk));
119  dms dec(fd->decBox->createDms(&decOk));
120 
122 
123  if (raOk && decOk)
124  {
125  //make sure values are in valid range
126  if (ra.Hours() < 0.0 || ra.Hours() > 24.0)
127  message = i18n("The Right Ascension value must be between 0.0 and 24.0.");
128  if (dec.Degrees() < -90.0 || dec.Degrees() > 90.0)
129  message += '\n' + i18n("The Declination value must be between -90.0 and 90.0.");
130  if (!message.isEmpty())
131  {
132  KSNotification::sorry(message, i18n("Invalid Coordinate Data"));
133  return;
134  }
135 
136  bool ok { false };
137  double epoch0 = KStarsDateTime::stringToEpoch(fd->epochBox->text(), ok);
138  if (!ok)
139  {
140  KSNotification::sorry(message, i18n("Invalid Epoch format"));
141  return;
142  }
143  long double jd0 = KStarsDateTime::epochToJd(epoch0);
144 
145  // Set RA and Dec to whatever epoch we have been given (may be J2000, JNow or something completely different)
146  Point->setRA(ra);
147  Point->setDec(dec);
148 
149  if (jd0 != J2000)
150  {
151  // Compute and set the J2000 coordinates of Point
152  Point->catalogueCoord(jd0);
153  }
154  else
155  {
156  Point->setRA0(ra);
157  Point->setDec0(dec);
158  }
159 
160  // N.B. At this point (ra, dec) and (ra0, dec0) are both
161  // J2000.0 values Therefore, we precess again to get the
162  // values for the present draw epoch into (ra, dec)
163  Point->apparentCoord(static_cast<long double>(J2000), KStarsData::Instance()->updateNum()->julianDay());
164 
165  Point->EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
166  // At this point, both (RA, Dec) and (Alt, Az) should correspond to current time
167  // (RA0, Dec0) will be J2000.0 -- asimha
168 
169  QDialog::accept();
170  }
171  else
172  {
173  dms az(fd->azBox->createDms(&azOk));
174  dms alt(fd->altBox->createDms(&altOk));
175 
176  if (azOk && altOk)
177  {
178  //make sure values are in valid range
179  if (az.Degrees() < 0.0 || az.Degrees() > 360.0)
180  message = i18n("The Azimuth value must be between 0.0 and 360.0.");
181  if (alt.Degrees() < -90.0 || alt.Degrees() > 90.0)
182  message += '\n' + i18n("The Altitude value must be between -90.0 and 90.0.");
183  if (!message.isEmpty())
184  {
185  KSNotification::sorry(message, i18n("Invalid Coordinate Data"));
186  return;
187  }
188 
189  Point->setAz(az);
190  Point->setAltRefracted(alt);
191  Point->HorizontalToEquatorial(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
192 
193  UsedAltAz = true;
194 
195  QDialog::accept();
196  }
197  else
198  {
199  QDialog::reject();
200  }
201  }
202 }
203 
205 {
206  return QSize(350, 210);
207 }
208 
210 {
211  fd->fdTab->setCurrentWidget(fd->aaTab);
212  fd->azBox->setFocus();
213 }
virtual void reject()
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
void clicked(bool checked)
void validatePoint()
Attempt to interpret the text in the KLineEdits as Ra and Dec values.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void activateAzAltPage() const
Show the Az/Alt page instead of the RA/Dec page.
void rejected()
QString i18n(const char *text, const TYPE &arg...)
void setWindowFlags(Qt::WindowFlags type)
SkyPoint * focus()
Retrieve the Focus point; the position on the sky at the center of the skymap.
Definition: skymap.h:122
static double stringToEpoch(const QString &eName, bool &ok)
Takes in a string and returns a Julian epoch.
bool isEmpty() const const
long double julianDay() const
Definition: ksnumbers.h:91
void setWindowTitle(const QString &)
virtual void accept()
static long double epochToJd(double epoch, EpochType type=JULIAN)
Takes in an epoch and returns a Julian Date.
This is the main window for KStars. In addition to the GUI elements, the class contains the program c...
Definition: kstars.h:92
QSize sizeHint() const override
void setEnabled(bool)
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
SkyObject * focusObject() const
Retrieve the object which is centered in the sky map.
Definition: skymap.h:261
QPushButton * button(QDialogButtonBox::StandardButton which) const const
const double & Degrees() const
Definition: dms.h:141
QString i18nc(const char *context, const char *text, const TYPE &arg...)
SkyPoint * focusPoint()
retrieve the FocusPoint position.
Definition: skymap.h:148
void setLayout(QLayout *layout)
FocusDialog()
Constructor.
Definition: focusdialog.cpp:28
void checkLineEdits()
If text has been entered in both KLineEdits, enable the Ok button.
Definition: focusdialog.cpp:98
QString message
double Hours() const
Definition: dms.h:168
void accepted()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 03:59:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.