Kstars

modcalcaltaz.cpp
1 /*
2  SPDX-FileCopyrightText: 2002 Jason Harris <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "modcalcaltaz.h"
8 
9 #include "geolocation.h"
10 #include "kstars.h"
11 #include "kstarsdata.h"
12 #include "kstarsdatetime.h"
13 #include "dialogs/finddialog.h"
14 #include "dialogs/locationdialog.h"
15 #include "skyobjects/skypoint.h"
16 #include "widgets/dmsbox.h"
17 
18 #include <KLocalizedString>
19 #include <KMessageBox>
20 
21 #include <QTextStream>
22 #include <QFileDialog>
23 
24 modCalcAltAz::modCalcAltAz(QWidget *parentSplit) : QFrame(parentSplit)
25 {
26  setupUi(this);
27 
28  KStarsData *data = KStarsData::Instance();
29  RA->setUnits(dmsBox::HOURS);
30 
31  //Initialize Date/Time and Location data
32  geoPlace = data->geo();
33  LocationButton->setText(geoPlace->fullName());
34 
35  //Make sure slotDateTime() gets called, so that LST will be set
36  connect(DateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(slotDateTimeChanged(QDateTime)));
37  DateTime->setDateTime(data->lt());
38 
39  connect(NowButton, SIGNAL(clicked()), this, SLOT(slotNow()));
40  connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation()));
41  connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()));
42 
43  connect(RA, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
44  connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
45  connect(Az, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
46  connect(Alt, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
47 
48  show();
49 }
50 
51 void modCalcAltAz::slotNow()
52 {
53  DateTime->setDateTime(KStarsDateTime::currentDateTime());
54  slotCompute();
55 }
56 
57 void modCalcAltAz::slotLocation()
58 {
59  QPointer<LocationDialog> ld = new LocationDialog(this);
60  if (ld->exec() == QDialog::Accepted)
61  {
62  GeoLocation *newGeo = ld->selectedCity();
63  if (newGeo)
64  {
65  geoPlace = newGeo;
66  LocationButton->setText(geoPlace->fullName());
67  slotCompute();
68  }
69  }
70  delete ld;
71 }
72 
73 void modCalcAltAz::slotObject()
74 {
75  if (FindDialog::Instance()->exec() == QDialog::Accepted)
76  {
77  SkyObject *o = FindDialog::Instance()->targetObject();
78  RA->show(o->ra());
79  Dec->show(o->dec());
80  slotCompute();
81  }
82 }
83 
84 void modCalcAltAz::slotDateTimeChanged(const QDateTime &dt)
85 {
86  KStarsDateTime ut = geoPlace->LTtoUT(KStarsDateTime(dt));
87  LST = geoPlace->GSTtoLST(ut.gst());
88 }
89 
90 void modCalcAltAz::slotCompute()
91 {
92  //Determine whether we are calculating Alt/Az coordinates from RA/Dec,
93  //or vice versa. We calculate Alt/Az by default, unless the signal
94  //was sent by changing the Az or Alt value.
95  if (sender()->objectName() == "Az" || sender()->objectName() == "Alt")
96  {
97  //Validate Az and Alt coordinates
98  bool ok(false);
99  dms alt;
100  dms az = Az->createDms(&ok);
101  if (ok)
102  alt = Alt->createDms(&ok);
103  if (ok)
104  {
105  SkyPoint sp;
106  sp.setAz(az);
107  sp.setAlt(alt);
108  sp.HorizontalToEquatorial(&LST, geoPlace->lat());
109  RA->show(sp.ra());
110  Dec->show(sp.dec());
111  }
112  }
113  else
114  {
115  //Validate RA and Dec coordinates
116  bool ok(false);
117  dms ra;
118  dms dec = Dec->createDms(&ok);
119  if (ok)
120  ra = RA->createDms(&ok);
121  if (ok)
122  {
123  SkyPoint sp(ra, dec);
124  sp.EquatorialToHorizontal(&LST, geoPlace->lat());
125  Az->show(sp.az());
126  Alt->show(sp.alt());
127  }
128  }
129 }
const dms & alt() const
Definition: skypoint.h:281
static KStarsDateTime currentDateTime()
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition: skypoint.h:194
const KStarsDateTime & lt() const
Definition: kstarsdata.h:150
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
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
const CachingDms & dec() const
Definition: skypoint.h:269
GeoLocation * geo()
Definition: kstarsdata.h:229
QTextStream & dec(QTextStream &stream)
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:37
void setAz(dms az)
Sets Az, the Azimuth.
Definition: skypoint.h:230
const CachingDms & ra() const
Definition: skypoint.h:263
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
Information about an object in the sky.
Definition: skyobject.h:41
Relevant data about an observing location on Earth.
Definition: geolocation.h:27
const dms & az() const
Definition: skypoint.h:275
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.