File indexing completed on 2024-04-28 07:32:36

0001 /*
0002     SPDX-FileCopyrightText: 2002 Jason Harris <kstars@30doradus.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "modcalcaltaz.h"
0008 
0009 #include "geolocation.h"
0010 #include "kstars.h"
0011 #include "kstarsdata.h"
0012 #include "kstarsdatetime.h"
0013 #include "dialogs/finddialog.h"
0014 #include "dialogs/locationdialog.h"
0015 #include "skyobjects/skypoint.h"
0016 #include "widgets/dmsbox.h"
0017 
0018 #include <KLocalizedString>
0019 #include <KMessageBox>
0020 
0021 #include <QTextStream>
0022 #include <QFileDialog>
0023 
0024 modCalcAltAz::modCalcAltAz(QWidget *parentSplit) : QFrame(parentSplit)
0025 {
0026     setupUi(this);
0027 
0028     KStarsData *data = KStarsData::Instance();
0029     RA->setUnits(dmsBox::HOURS);
0030 
0031     //Initialize Date/Time and Location data
0032     geoPlace = data->geo();
0033     LocationButton->setText(geoPlace->fullName());
0034 
0035     //Make sure slotDateTime() gets called, so that LST will be set
0036     connect(DateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(slotDateTimeChanged(QDateTime)));
0037     DateTime->setDateTime(data->lt());
0038 
0039     connect(NowButton, SIGNAL(clicked()), this, SLOT(slotNow()));
0040     connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation()));
0041     connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()));
0042 
0043     connect(RA, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
0044     connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
0045     connect(Az, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
0046     connect(Alt, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
0047 
0048     show();
0049 }
0050 
0051 void modCalcAltAz::slotNow()
0052 {
0053     DateTime->setDateTime(KStarsDateTime::currentDateTime());
0054     slotCompute();
0055 }
0056 
0057 void modCalcAltAz::slotLocation()
0058 {
0059     QPointer<LocationDialog> ld = new LocationDialog(this);
0060     if (ld->exec() == QDialog::Accepted)
0061     {
0062         GeoLocation *newGeo = ld->selectedCity();
0063         if (newGeo)
0064         {
0065             geoPlace = newGeo;
0066             LocationButton->setText(geoPlace->fullName());
0067             slotCompute();
0068         }
0069     }
0070     delete ld;
0071 }
0072 
0073 void modCalcAltAz::slotObject()
0074 {
0075     if (FindDialog::Instance()->exec() == QDialog::Accepted)
0076     {
0077         SkyObject *o = FindDialog::Instance()->targetObject();
0078         RA->show(o->ra());
0079         Dec->show(o->dec());
0080         slotCompute();
0081     }
0082 }
0083 
0084 void modCalcAltAz::slotDateTimeChanged(const QDateTime &dt)
0085 {
0086     KStarsDateTime ut = geoPlace->LTtoUT(KStarsDateTime(dt));
0087     LST               = geoPlace->GSTtoLST(ut.gst());
0088 }
0089 
0090 void modCalcAltAz::slotCompute()
0091 {
0092     //Determine whether we are calculating Alt/Az coordinates from RA/Dec,
0093     //or vice versa.  We calculate Alt/Az by default, unless the signal
0094     //was sent by changing the Az or Alt value.
0095     if (sender()->objectName() == "Az" || sender()->objectName() == "Alt")
0096     {
0097         //Validate Az and Alt coordinates
0098         bool ok(false);
0099         dms alt;
0100         dms az = Az->createDms(&ok);
0101         if (ok)
0102             alt = Alt->createDms(&ok);
0103         if (ok)
0104         {
0105             SkyPoint sp;
0106             sp.setAz(az);
0107             sp.setAlt(alt);
0108             sp.HorizontalToEquatorial(&LST, geoPlace->lat());
0109             RA->show(sp.ra());
0110             Dec->show(sp.dec());
0111         }
0112     }
0113     else
0114     {
0115         //Validate RA and Dec coordinates
0116         bool ok(false);
0117         dms ra;
0118         dms dec = Dec->createDms(&ok);
0119         if (ok)
0120             ra = RA->createDms(&ok);
0121         if (ok)
0122         {
0123             SkyPoint sp(ra, dec);
0124             sp.EquatorialToHorizontal(&LST, geoPlace->lat());
0125             Az->show(sp.az());
0126             Alt->show(sp.alt());
0127         }
0128     }
0129 }