File indexing completed on 2024-03-24 15:18:06
0001 /* 0002 SPDX-FileCopyrightText: 2004 Pablo de Vicente <vicente@oan.es> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "modcalceclipticcoords.h" 0008 0009 #include "dms.h" 0010 #include "ksnumbers.h" 0011 #include "kstars.h" 0012 #include "kstarsdata.h" 0013 #include "dialogs/finddialog.h" 0014 #include "skyobjects/skypoint.h" 0015 #include "widgets/dmsbox.h" 0016 0017 #include <KLocalizedString> 0018 #include <KMessageBox> 0019 #include <KUrlRequester> 0020 0021 #include <QTextStream> 0022 #include <QFileDialog> 0023 0024 modCalcEclCoords::modCalcEclCoords(QWidget *parentSplit) : QFrame(parentSplit) 0025 { 0026 setupUi(this); 0027 RA->setUnits(dmsBox::HOURS); 0028 0029 //Initialize Date/Time and Location data 0030 DateTime->setDateTime(KStarsData::Instance()->lt()); 0031 kdt = KStarsDateTime(DateTime->dateTime()); 0032 0033 connect(NowButton, SIGNAL(clicked()), this, SLOT(slotNow())); 0034 connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject())); 0035 connect(DateTime, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(slotDateTimeChanged(QDateTime))); 0036 0037 connect(RA, SIGNAL(editingFinished()), this, SLOT(slotCompute())); 0038 connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotCompute())); 0039 connect(EcLong, SIGNAL(editingFinished()), this, SLOT(slotCompute())); 0040 connect(EcLat, SIGNAL(editingFinished()), this, SLOT(slotCompute())); 0041 0042 this->show(); 0043 } 0044 0045 void modCalcEclCoords::slotNow() 0046 { 0047 DateTime->setDateTime(KStarsDateTime::currentDateTime()); 0048 slotCompute(); 0049 } 0050 0051 void modCalcEclCoords::slotObject() 0052 { 0053 if (FindDialog::Instance()->exec() == QDialog::Accepted) 0054 { 0055 SkyObject *o = FindDialog::Instance()->targetObject(); 0056 RA->show(o->ra()); 0057 Dec->show(o->dec()); 0058 slotCompute(); 0059 } 0060 } 0061 0062 void modCalcEclCoords::slotDateTimeChanged(const QDateTime &edt) 0063 { 0064 kdt = ((KStarsDateTime)edt); 0065 } 0066 0067 void modCalcEclCoords::slotCompute(void) 0068 { 0069 KSNumbers num(kdt.djd()); 0070 0071 //Determine whether we are calculating ecliptic coordinates from equatorial, 0072 //or vice versa. We calculate ecliptic by default, unless the signal 0073 //was sent by changing the EcLong or EcLat value. 0074 if (sender()->objectName() == "EcLong" || sender()->objectName() == "EcLat") 0075 { 0076 //Validate ecliptic coordinates 0077 bool ok(false); 0078 dms elat; 0079 dms elong = EcLong->createDms(&ok); 0080 if (ok) 0081 elat = EcLat->createDms(&ok); 0082 if (ok) 0083 { 0084 SkyPoint sp; 0085 sp.setFromEcliptic(num.obliquity(), elong, elat); 0086 RA->show(sp.ra()); 0087 Dec->show(sp.dec()); 0088 } 0089 } 0090 else 0091 { 0092 //Validate RA and Dec coordinates 0093 bool ok(false); 0094 dms ra; 0095 dms dec = Dec->createDms(&ok); 0096 if (ok) 0097 ra = RA->createDms(&ok); 0098 if (ok) 0099 { 0100 SkyPoint sp(ra, dec); 0101 dms elong, elat; 0102 sp.findEcliptic(num.obliquity(), elong, elat); 0103 EcLong->show(elong); 0104 EcLat->show(elat); 0105 } 0106 } 0107 }