7 #include "modcalcgeodcoord.h"
10 #include "geolocation.h"
12 #include "ksnotification.h"
13 #include "kstarsdata.h"
15 #include <QTextStream>
16 #include <QFileDialog>
18 modCalcGeodCoord::modCalcGeodCoord(
QWidget *parentSplit) :
QFrame(parentSplit)
22 ellipsoidList <<
"IAU76"
30 spheRadio->setChecked(
true);
31 ellipsoidBox->insertItems(5, ellipsoidList);
37 connect(Clear, SIGNAL(clicked()),
this, SLOT(slotClearGeoCoords()));
38 connect(Compute, SIGNAL(clicked()),
this, SLOT(slotComputeGeoCoords()));
41 void modCalcGeodCoord::showLongLat(
void)
45 LongGeoBox->show(data->
geo()->
lng());
46 LatGeoBox->show(data->
geo()->
lat());
47 AltGeoBox->setText(
QString(
"0.0"));
50 void modCalcGeodCoord::setEllipsoid(
int index)
52 geoPlace->changeEllipsoid(index);
55 void modCalcGeodCoord::getCartGeoCoords(
void)
57 geoPlace->setXPos(XGeoBox->text().toDouble() * 1000.);
58 geoPlace->setYPos(YGeoBox->text().toDouble() * 1000.);
59 geoPlace->setZPos(ZGeoBox->text().toDouble() * 1000.);
62 void modCalcGeodCoord::getSphGeoCoords(
void)
64 geoPlace->setLong(LongGeoBox->createDms());
65 geoPlace->setLat(LatGeoBox->createDms());
66 geoPlace->setElevation(AltGeoBox->text().toDouble());
69 void modCalcGeodCoord::slotClearGeoCoords(
void)
71 geoPlace->setLong(
dms(0.0));
72 geoPlace->setLat(
dms(0.0));
73 geoPlace->setElevation(0.0);
74 LatGeoBox->clearFields();
75 LongGeoBox->clearFields();
78 void modCalcGeodCoord::slotComputeGeoCoords(
void)
80 if (cartRadio->isChecked())
92 void modCalcGeodCoord::showSpheGeoCoords(
void)
94 LongGeoBox->show(geoPlace->lng());
95 LatGeoBox->show(geoPlace->lat());
99 void modCalcGeodCoord::showCartGeoCoords(
void)
106 void modCalcGeodCoord::geoCheck(
void)
108 XGeoBoxBatch->setEnabled(
false);
109 XGeoCheckBatch->setChecked(
false);
110 YGeoBoxBatch->setEnabled(
false);
111 YGeoCheckBatch->setChecked(
false);
112 YGeoBoxBatch->setEnabled(
false);
113 YGeoCheckBatch->setChecked(
false);
114 xyzInputCoords =
false;
117 void modCalcGeodCoord::xyzCheck(
void)
119 LongGeoBoxBatch->setEnabled(
false);
120 LongGeoCheckBatch->setChecked(
false);
121 LatGeoBoxBatch->setEnabled(
false);
122 LatGeoCheckBatch->setChecked(
false);
123 AltGeoBoxBatch->setEnabled(
false);
124 AltGeoCheckBatch->setChecked(
false);
125 xyzInputCoords =
true;
128 void modCalcGeodCoord::slotLongCheckedBatch()
130 if (LongGeoCheckBatch->isChecked())
132 LongGeoBoxBatch->setEnabled(
false);
137 LongGeoBoxBatch->setEnabled(
true);
141 void modCalcGeodCoord::slotLatCheckedBatch()
143 if (LatGeoCheckBatch->isChecked())
145 LatGeoBoxBatch->setEnabled(
false);
150 LatGeoBoxBatch->setEnabled(
true);
154 void modCalcGeodCoord::slotElevCheckedBatch()
156 if (AltGeoCheckBatch->isChecked())
158 AltGeoBoxBatch->setEnabled(
false);
163 AltGeoBoxBatch->setEnabled(
true);
167 void modCalcGeodCoord::slotXCheckedBatch()
169 if (XGeoCheckBatch->isChecked())
171 XGeoBoxBatch->setEnabled(
false);
176 XGeoBoxBatch->setEnabled(
true);
180 void modCalcGeodCoord::slotYCheckedBatch()
182 if (YGeoCheckBatch->isChecked())
184 YGeoBoxBatch->setEnabled(
false);
189 YGeoBoxBatch->setEnabled(
true);
193 void modCalcGeodCoord::slotZCheckedBatch()
195 if (ZGeoCheckBatch->isChecked())
197 ZGeoBoxBatch->setEnabled(
false);
202 ZGeoBoxBatch->setEnabled(
true);
205 void modCalcGeodCoord::slotInputFile()
212 void modCalcGeodCoord::slotOutputFile()
219 void modCalcGeodCoord::slotRunBatch(
void)
221 const QString inputFileName = InputFileBoxBatch->url().toLocalFile();
227 QFile f(inputFileName);
231 KSNotification::sorry(
message,
i18n(
"Could Not Open File"));
237 processLines(istream);
244 KSNotification::sorry(
message,
i18n(
"Invalid file"));
245 InputFileBoxBatch->setUrl(
QUrl());
249 void modCalcGeodCoord::processLines(
QTextStream &istream)
254 const QString outputFileName = OutputFileBoxBatch->url().toLocalFile();
255 QFile fOut(outputFileName);
263 geoPl.setEllipsoid(0);
265 double xB, yB, zB, hB;
268 while (!istream.
atEnd())
285 if (XGeoCheckBatch->isChecked())
287 xB = fields[i].toDouble();
291 xB = XGeoBoxBatch->text().toDouble();
293 if (AllRadioBatch->isChecked())
294 ostream << xB << space;
295 else if (XGeoCheckBatch->isChecked())
296 ostream << xB << space;
300 if (YGeoCheckBatch->isChecked())
302 yB = fields[i].toDouble();
306 yB = YGeoBoxBatch->text().toDouble();
308 if (AllRadioBatch->isChecked())
309 ostream << yB << space;
310 else if (YGeoCheckBatch->isChecked())
311 ostream << yB << space;
314 if (ZGeoCheckBatch->isChecked())
316 zB = fields[i].toDouble();
320 zB = ZGeoBoxBatch->text().toDouble();
322 if (AllRadioBatch->isChecked())
323 ostream << zB << space;
324 else if (YGeoCheckBatch->isChecked())
325 ostream << zB << space;
327 geoPl.setXPos(xB * 1000.0);
328 geoPl.setYPos(yB * 1000.0);
329 geoPl.setZPos(zB * 1000.0);
330 ostream << geoPl.lng()->toDMSString() << space << geoPl.lat()->toDMSString() << space << geoPl.elevation()
339 if (LongGeoCheckBatch->isChecked())
345 longB = LongGeoBoxBatch->createDms();
347 if (AllRadioBatch->isChecked())
349 else if (LongGeoCheckBatch->isChecked())
354 if (LatGeoCheckBatch->isChecked())
360 latB = LatGeoBoxBatch->createDms();
362 if (AllRadioBatch->isChecked())
364 else if (LatGeoCheckBatch->isChecked())
369 if (AltGeoCheckBatch->isChecked())
371 hB = fields[i].toDouble();
375 hB = AltGeoBoxBatch->text().toDouble();
377 if (AllRadioBatch->isChecked())
378 ostream << hB << space;
379 else if (AltGeoCheckBatch->isChecked())
380 ostream << hB << space;
382 geoPl.setLong(longB);
384 geoPl.setElevation(hB);
386 ostream << geoPl.xPos() / 1000.0 << space << geoPl.yPos() / 1000.0 << space << geoPl.zPos() / 1000.0