Kstars

modcalcapcoord.cpp
1/*
2 SPDX-FileCopyrightText: 2002 Pablo de Vicente <vicente@oan.es>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "modcalcapcoord.h"
8
9#include "dms.h"
10#include "kstars.h"
11#include "ksnotification.h"
12#include "kstarsdatetime.h"
13#include "dialogs/finddialog.h"
14#include "skyobjects/skypoint.h"
15#include "skyobjects/skyobject.h"
16
17#include <QTextStream>
18#include <QFileDialog>
19#include <QPointer>
20
21modCalcApCoord::modCalcApCoord(QWidget *parentSplit) : QFrame(parentSplit)
22{
23 setupUi(this);
24 showCurrentTime();
25 RACat->setUnits(dmsBox::HOURS);
26 DecCat->setUnits(dmsBox::DEGREES);
27
28 connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()));
29 connect(NowButton, SIGNAL(clicked()), this, SLOT(showCurrentTime()));
30 connect(RACat, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
31 connect(DecCat, SIGNAL(editingFinished()), this, SLOT(slotCompute()));
32 connect(UT, SIGNAL(timeChanged(QTime)), this, SLOT(slotCompute()));
33 connect(Date, SIGNAL(dateChanged(QDate)), this, SLOT(slotCompute()));
34
35 connect(utCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtCheckedBatch()));
36 connect(dateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateCheckedBatch()));
37 connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()));
38 connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()));
39 connect(epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()));
40 connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()));
41
42 show();
43}
44
45void modCalcApCoord::showCurrentTime(void)
46{
48 Date->setDate(dt.date());
49 UT->setTime(dt.time());
50 EpochTarget->setText(QString::number(dt.epoch(), 'f', 3));
51}
52
53void modCalcApCoord::slotCompute()
54{
55 KStarsDateTime dt(Date->date(), UT->time());
56 long double jd = dt.djd();
57
58 dt.setFromEpoch(EpochCat->value());
59 long double jd0 = dt.djd();
60
61 SkyPoint sp(RACat->createDms(), DecCat->createDms());
62 sp.apparentCoord(jd0, jd);
63
64 RA->setText(sp.ra().toHMSString());
65 Dec->setText(sp.dec().toDMSString());
66}
67
68void modCalcApCoord::slotObject()
69{
70 if (FindDialog::Instance()->exec() == QDialog::Accepted)
71 {
72 SkyObject *o = FindDialog::Instance()->targetObject();
73 RACat->show(o->ra0());
74 DecCat->show(o->dec0());
75 EpochCat->setValue(2000.0);
76
77 slotCompute();
78 }
79}
80
81void modCalcApCoord::slotUtCheckedBatch()
82{
83 if (utCheckBatch->isChecked())
84 utBoxBatch->setEnabled(false);
85 else
86 {
87 utBoxBatch->setEnabled(true);
88 }
89}
90
91void modCalcApCoord::slotDateCheckedBatch()
92{
93 if (dateCheckBatch->isChecked())
94 dateBoxBatch->setEnabled(false);
95 else
96 {
97 dateBoxBatch->setEnabled(true);
98 }
99}
100
101void modCalcApCoord::slotRaCheckedBatch()
102{
103 if (raCheckBatch->isChecked())
104 raBoxBatch->setEnabled(false);
105 else
106 {
107 raBoxBatch->setEnabled(true);
108 }
109}
110
111void modCalcApCoord::slotDecCheckedBatch()
112{
113 if (decCheckBatch->isChecked())
114 decBoxBatch->setEnabled(false);
115 else
116 {
117 decBoxBatch->setEnabled(true);
118 }
119}
120
121void modCalcApCoord::slotEpochCheckedBatch()
122{
123 if (epochCheckBatch->isChecked())
124 epochBoxBatch->setEnabled(false);
125 else
126 {
127 epochBoxBatch->setEnabled(true);
128 }
129}
130
131void modCalcApCoord::slotRunBatch()
132{
133 QString inputFileName = InputLineEditBatch->url().toLocalFile();
134
135 // We open the input file and read its content
136
137 if (QFile::exists(inputFileName))
138 {
139 QFile f(inputFileName);
140 if (!f.open(QIODevice::ReadOnly))
141 {
142 KSNotification::sorry(i18n("Could not open file %1.", f.fileName()), i18n("Could Not Open File"));
143 inputFileName.clear();
144 return;
145 }
146
147 // processLines(&f);
148 QTextStream istream(&f);
149 processLines(istream);
150 // readFile( istream );
151 f.close();
152 }
153 else
154 {
155 KSNotification::sorry(i18n("Invalid file: %1", inputFileName), i18n("Invalid file"));
156 inputFileName.clear();
157 InputLineEditBatch->setText(inputFileName);
158 return;
159 }
160}
161
162//void modCalcApCoord::processLines( const QFile * fIn ) {
164{
165 // we open the output file
166
167 // QTextStream istream(&fIn);
168 QString outputFileName;
169 outputFileName = OutputLineEditBatch->text();
170 QFile fOut(outputFileName);
172 QTextStream ostream(&fOut);
173
174 QString line;
175 QChar space = ' ';
176 int i = 0;
177 long double jd, jd0;
178 SkyPoint sp;
179 QTime utB;
180 QDate dtB;
181 dms raB, decB;
182 QString epoch0B;
183
184 while (!istream.atEnd())
185 {
186 line = istream.readLine();
187 line = line.trimmed();
188
189 //Go through the line, looking for parameters
190
191 QStringList fields = line.split(' ');
192
193 i = 0;
194
195 // Read Ut and write in ostream if corresponds
196
197 if (utCheckBatch->isChecked())
198 {
199 utB = QTime::fromString(fields[i]);
200 i++;
201 }
202 else
203 utB = utBoxBatch->time();
204
205 if (allRadioBatch->isChecked())
206 ostream << QLocale().toString(utB) << space;
207 else if (utCheckBatch->isChecked())
208 ostream << QLocale().toString(utB) << space;
209
210 // Read date and write in ostream if corresponds
211
212 if (dateCheckBatch->isChecked())
213 {
214 dtB = QDate::fromString(fields[i]);
215 i++;
216 }
217 else
218 dtB = dateBoxBatch->date();
219
220 if (allRadioBatch->isChecked())
221 ostream << QLocale().toString(dtB, QLocale::LongFormat).append(space);
222 else if (dateCheckBatch->isChecked())
223 ostream << QLocale().toString(dtB, QLocale::LongFormat).append(space);
224
225 // Read RA and write in ostream if corresponds
226
227 if (raCheckBatch->isChecked())
228 {
229 raB = dms::fromString(fields[i], false);
230 i++;
231 }
232 else
233 raB = raBoxBatch->createDms();
234
235 if (allRadioBatch->isChecked())
236 ostream << raB.toHMSString() << space;
237 else if (raCheckBatch->isChecked())
238 ostream << raB.toHMSString() << space;
239
240 // Read DEC and write in ostream if corresponds
241
242 if (decCheckBatch->isChecked())
243 {
244 decB = dms::fromString(fields[i], true);
245 i++;
246 }
247 else
248 decB = decBoxBatch->createDms();
249
250 if (allRadioBatch->isChecked())
251 ostream << decB.toDMSString() << space;
252 else if (decCheckBatch->isChecked())
253 ostream << decB.toHMSString() << space;
254
255 // Read Epoch and write in ostream if corresponds
256
257 if (epochCheckBatch->isChecked())
258 {
259 epoch0B = fields[i];
260 i++;
261 }
262 else
263 epoch0B = epochBoxBatch->text();
264
265 if (allRadioBatch->isChecked())
266 ostream << epoch0B;
267 else if (decCheckBatch->isChecked())
268 ostream << epoch0B;
269
271 dt.setFromEpoch(epoch0B);
272 jd = KStarsDateTime(dtB, utB).djd();
273 jd0 = dt.djd();
274 sp = SkyPoint(raB, decB);
275 sp.apparentCoord(jd0, jd);
276
277 ostream << sp.ra().toHMSString() << sp.dec().toDMSString() << '\n';
278 }
279
280 fOut.close();
281}
SkyObject * targetObject()
Definition finddialog.h:53
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
bool setFromEpoch(double e, EpochType type)
Set the Date/Time from an epoch value, represented as a double.
static KStarsDateTime currentDateTime()
long double djd() const
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
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
const CachingDms & dec() const
Definition skypoint.h:269
const CachingDms & ra0() const
Definition skypoint.h:251
const CachingDms & ra() const
Definition skypoint.h:263
const CachingDms & dec0() const
Definition skypoint.h:257
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
static dms fromString(const QString &s, bool deg)
Static function to create a DMS object from a QString.
Definition dms.cpp:429
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
Definition dms.cpp:287
const QString toHMSString(const bool machineReadable=false, const bool highPrecision=false) const
Definition dms.cpp:378
void processLines(QTextStream &istream)
Process Lines.
modCalcApCoord(QWidget *p)
Constructor.
QString i18n(const char *text, const TYPE &arg...)
QDate fromString(QStringView string, QStringView format, QCalendar cal)
bool exists() const const
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
virtual void close() override
QString toString(QDate date, FormatType format) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString & append(QChar ch)
void clear()
QString number(double n, char format, int precision)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString trimmed() const const
bool atEnd() const const
QString readLine(qint64 maxlen)
QTime fromString(QStringView string, QStringView format)
void setupUi(QWidget *widget)
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.