Kstars

modcalcgalcoord.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 "modcalcgalcoord.h"
8
9#include "ksnotification.h"
10#include "dialogs/finddialog.h"
11#include "skyobjects/skyobject.h"
12#include "skyobjects/skypoint.h"
13
14#include <QTextStream>
15#include <QPointer>
16
17modCalcGalCoord::modCalcGalCoord(QWidget *parentSplit) : QFrame(parentSplit)
18{
19 setupUi(this);
20 RA->setUnits(dmsBox::HOURS);
21
22 connect(RA, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()));
23 connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()));
24 connect(GalLongitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()));
25 connect(GalLatitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()));
26
27 connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()));
28
29 connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()));
30 connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()));
31 connect(epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()));
32 connect(galLongCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLongCheckedBatch()));
33 connect(galLatCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLatCheckedBatch()));
34 connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()));
35
36 show();
37}
38
39void modCalcGalCoord::slotObject()
40{
41 if (FindDialog::Instance()->exec() == QDialog::Accepted)
42 {
43 SkyObject *o = FindDialog::Instance()->targetObject();
44 RA->show(o->ra());
45 Dec->show(o->dec());
46 slotComputeCoords();
47 }
48}
49
50void modCalcGalCoord::slotComputeCoords()
51{
52 if (GalLongitude->hasFocus())
53 GalLongitude->clearFocus();
54
55 //Determine whether we should compute galactic coords from
56 //equatorial, or vice versa
57 if (sender()->objectName() == "GalLongitude" || sender()->objectName() == "GalLatitude")
58 {
59 //Validate GLong and GLat
60 bool ok(false);
61 dms glat;
62 dms glong = GalLongitude->createDms(&ok);
63 if (ok)
64 glat = GalLatitude->createDms(&ok);
65 if (ok)
66 {
67 SkyPoint sp;
68 sp.GalacticToEquatorial1950(&glong, &glat);
69 sp.B1950ToJ2000();
70 RA->show(sp.ra());
71 Dec->show(sp.dec());
72 }
73 }
74 else
75 {
76 //Validate RA and Dec
77 bool ok(false);
78 dms dec;
79 dms ra = RA->createDms(&ok);
80 if (ok)
81 dec = Dec->createDms(&ok);
82 if (ok)
83 {
84 dms glong, glat;
85 SkyPoint sp(ra, dec);
86 sp.J2000ToB1950();
87 sp.Equatorial1950ToGalactic(glong, glat);
88 GalLongitude->show(glong);
89 GalLatitude->show(glat);
90 }
91 }
92}
93
94void modCalcGalCoord::galCheck()
95{
96 galLatCheckBatch->setChecked(false);
97 galLatBoxBatch->setEnabled(false);
98 galLongCheckBatch->setChecked(false);
99 galLongBoxBatch->setEnabled(false);
100 galInputCoords = false;
101}
102
103void modCalcGalCoord::equCheck()
104{
105 raCheckBatch->setChecked(false);
106 raBoxBatch->setEnabled(false);
107 decCheckBatch->setChecked(false);
108 decBoxBatch->setEnabled(false);
109 epochCheckBatch->setChecked(false);
110 galInputCoords = true;
111}
112
113void modCalcGalCoord::slotRaCheckedBatch()
114{
115 if (raCheckBatch->isChecked())
116 {
117 raBoxBatch->setEnabled(false);
118 galCheck();
119 }
120 else
121 {
122 raBoxBatch->setEnabled(true);
123 }
124}
125
126void modCalcGalCoord::slotDecCheckedBatch()
127{
128 if (decCheckBatch->isChecked())
129 {
130 decBoxBatch->setEnabled(false);
131 galCheck();
132 }
133 else
134 {
135 decBoxBatch->setEnabled(true);
136 }
137}
138
139void modCalcGalCoord::slotEpochCheckedBatch()
140{
141 epochCheckBatch->setChecked(false);
142
143 if (epochCheckBatch->isChecked())
144 {
145 epochBoxBatch->setEnabled(false);
146 galCheck();
147 }
148 else
149 {
150 epochBoxBatch->setEnabled(true);
151 }
152}
153
154void modCalcGalCoord::slotGalLatCheckedBatch()
155{
156 if (galLatCheckBatch->isChecked())
157 {
158 galLatBoxBatch->setEnabled(false);
159 equCheck();
160 }
161 else
162 {
163 galLatBoxBatch->setEnabled(true);
164 }
165}
166
167void modCalcGalCoord::slotGalLongCheckedBatch()
168{
169 if (galLongCheckBatch->isChecked())
170 {
171 galLongBoxBatch->setEnabled(false);
172 equCheck();
173 }
174 else
175 {
176 galLongBoxBatch->setEnabled(true);
177 }
178}
179
180void modCalcGalCoord::slotRunBatch()
181{
182 const QString inputFileName = InputFileBoxBatch->url().toLocalFile();
183
184 // We open the input file and read its content
185
186 if (QFile::exists(inputFileName))
187 {
188 QFile f(inputFileName);
189 if (!f.open(QIODevice::ReadOnly))
190 {
191 KSNotification::sorry(i18n("Could not open file %1.", f.fileName()), i18n("Could Not Open File"));
192 return;
193 }
194
195 // processLines(&f);
196 QTextStream istream(&f);
197 processLines(istream);
198 // readFile( istream );
199 f.close();
200 }
201 else
202 {
203 QString message = i18n("Invalid file: %1", inputFileName);
204 KSNotification::sorry(message, i18n("Invalid file"));
205 InputFileBoxBatch->setUrl(QUrl());
206 }
207}
208
209void modCalcGalCoord::processLines(QTextStream &istream)
210{
211 // we open the output file
212
213 // QTextStream istream(&fIn);
214 const QString outputFileName = OutputFileBoxBatch->url().toLocalFile();
215 QFile fOut(outputFileName);
216 fOut.open(QIODevice::WriteOnly);
217 QTextStream ostream(&fOut);
218
219 QString line;
220 QChar space = ' ';
221 int i = 0;
222 SkyPoint sp;
223 dms raB, decB, galLatB, galLongB;
224 QString epoch0B;
225
226 while (!istream.atEnd())
227 {
228 line = istream.readLine();
229 line = line.trimmed();
230
231 //Go through the line, looking for parameters
232
233 QStringList fields = line.split(' ');
234
235 i = 0;
236
237 // Input coords are galactic coordinates:
238
239 if (galInputCoords)
240 {
241 // Read Galactic Longitude and write in ostream if corresponds
242
243 if (galLongCheckBatch->isChecked())
244 {
245 galLongB = dms::fromString(fields[i], true);
246 i++;
247 }
248 else
249 galLongB = galLongBoxBatch->createDms();
250
251 if (allRadioBatch->isChecked())
252 ostream << galLongB.toDMSString() << space;
253 else if (galLongCheckBatch->isChecked())
254 ostream << galLongB.toDMSString() << space;
255
256 // Read Galactic Latitude and write in ostream if corresponds
257
258 if (galLatCheckBatch->isChecked())
259 {
260 galLatB = dms::fromString(fields[i], true);
261 i++;
262 }
263 else
264 galLatB = galLatBoxBatch->createDms();
265
266 if (allRadioBatch->isChecked())
267 ostream << galLatB.toDMSString() << space;
268 else if (galLatCheckBatch->isChecked())
269 ostream << galLatB.toDMSString() << space;
270
271 sp = SkyPoint();
272 sp.GalacticToEquatorial1950(&galLongB, &galLatB);
273 ostream << sp.ra().toHMSString() << space << sp.dec().toDMSString() << epoch0B << '\n';
274 // Input coords. are equatorial coordinates:
275 }
276 else
277 {
278 // Read RA and write in ostream if corresponds
279
280 if (raCheckBatch->isChecked())
281 {
282 raB = dms::fromString(fields[i], false);
283 i++;
284 }
285 else
286 raB = raBoxBatch->createDms();
287
288 if (allRadioBatch->isChecked())
289 ostream << raB.toHMSString() << space;
290 else if (raCheckBatch->isChecked())
291 ostream << raB.toHMSString() << space;
292
293 // Read DEC and write in ostream if corresponds
294
295 if (decCheckBatch->isChecked())
296 {
297 decB = dms::fromString(fields[i], true);
298 i++;
299 }
300 else
301 decB = decBoxBatch->createDms();
302
303 if (allRadioBatch->isChecked())
304 ostream << decB.toDMSString() << space;
305 else if (decCheckBatch->isChecked())
306 ostream << decB.toDMSString() << space;
307
308 // Read Epoch and write in ostream if corresponds
309
310 if (epochCheckBatch->isChecked())
311 {
312 epoch0B = fields[i];
313 i++;
314 }
315 else
316 epoch0B = epochBoxBatch->text();
317
318 if (allRadioBatch->isChecked())
319 ostream << epoch0B << space;
320 else if (epochCheckBatch->isChecked())
321 ostream << epoch0B << space;
322
323 sp = SkyPoint(raB, decB);
324 sp.J2000ToB1950();
325 sp.Equatorial1950ToGalactic(galLongB, galLatB);
326 ostream << galLongB.toDMSString() << space << galLatB.toDMSString() << '\n';
327 }
328 }
329
330 fOut.close();
331}
SkyObject * targetObject()
Definition finddialog.h:53
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
const CachingDms & dec() const
Definition skypoint.h:269
const CachingDms & ra() const
Definition skypoint.h:263
void B1950ToJ2000(void)
Exact precession from Besselian epoch 1950 to epoch J2000.
Definition skypoint.cpp:773
void GalacticToEquatorial1950(const dms *galLong, const dms *galLat)
Computes equatorial coordinates referred to 1950 from galactic ones referred to epoch B1950.
Definition skypoint.cpp:754
void J2000ToB1950(void)
Exact precession from epoch J2000 Besselian epoch 1950.
Definition skypoint.cpp:819
void Equatorial1950ToGalactic(dms &galLong, dms &galLat)
Computes galactic coordinates from equatorial coordinates referred to epoch 1950.
Definition skypoint.cpp:735
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
QString i18n(const char *text, const TYPE &arg...)
bool exists() const const
QObject * sender() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString trimmed() const const
QTextStream & dec(QTextStream &stream)
bool atEnd() const const
QString readLine(qint64 maxlen)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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.