• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • edu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • extragear
  • edu
  • kstars
  • kstars
  • tools
modcalcgeodcoord.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalcgeodcoord.cpp - description
3  -------------------
4  begin : Tue Jan 15 2002
5  copyright : (C) 2002 by Pablo de Vicente
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "modcalcgeodcoord.h"
19 
20 #include "dms.h"
21 #include "geolocation.h"
22 #include "kstars.h"
23 #include "ksnotification.h"
24 #include "kstarsdata.h"
25 
26 #include <QTextStream>
27 #include <QFileDialog>
28 
29 modCalcGeodCoord::modCalcGeodCoord(QWidget *parentSplit) : QFrame(parentSplit)
30 {
31  QStringList ellipsoidList;
32 
33  ellipsoidList << "IAU76"
34  << "GRS80"
35  << "MERIT83"
36  << "WGS84"
37  << "IERS89";
38 
39  setupUi(this);
40 
41  spheRadio->setChecked(true);
42  ellipsoidBox->insertItems(5, ellipsoidList);
43  geoPlace.reset(new GeoLocation(dms(0), dms(0)));
44  showLongLat();
45  setEllipsoid(0);
46  show();
47 
48  connect(Clear, SIGNAL(clicked()), this, SLOT(slotClearGeoCoords()));
49  connect(Compute, SIGNAL(clicked()), this, SLOT(slotComputeGeoCoords()));
50 }
51 
52 void modCalcGeodCoord::showLongLat(void)
53 {
54  KStarsData *data = KStarsData::Instance();
55 
56  LongGeoBox->show(data->geo()->lng());
57  LatGeoBox->show(data->geo()->lat());
58  AltGeoBox->setText(QString("0.0"));
59 }
60 
61 void modCalcGeodCoord::setEllipsoid(int index)
62 {
63  geoPlace->changeEllipsoid(index);
64 }
65 
66 void modCalcGeodCoord::getCartGeoCoords(void)
67 {
68  geoPlace->setXPos(XGeoBox->text().toDouble() * 1000.);
69  geoPlace->setYPos(YGeoBox->text().toDouble() * 1000.);
70  geoPlace->setZPos(ZGeoBox->text().toDouble() * 1000.);
71 }
72 
73 void modCalcGeodCoord::getSphGeoCoords(void)
74 {
75  geoPlace->setLong(LongGeoBox->createDms());
76  geoPlace->setLat(LatGeoBox->createDms());
77  geoPlace->setElevation(AltGeoBox->text().toDouble());
78 }
79 
80 void modCalcGeodCoord::slotClearGeoCoords(void)
81 {
82  geoPlace->setLong(dms(0.0));
83  geoPlace->setLat(dms(0.0));
84  geoPlace->setElevation(0.0);
85  LatGeoBox->clearFields();
86  LongGeoBox->clearFields();
87 }
88 
89 void modCalcGeodCoord::slotComputeGeoCoords(void)
90 {
91  if (cartRadio->isChecked())
92  {
93  getCartGeoCoords();
94  showSpheGeoCoords();
95  }
96  else
97  {
98  getSphGeoCoords();
99  showCartGeoCoords();
100  }
101 }
102 
103 void modCalcGeodCoord::showSpheGeoCoords(void)
104 {
105  LongGeoBox->show(geoPlace->lng());
106  LatGeoBox->show(geoPlace->lat());
107  AltGeoBox->setText(QLocale().toString(geoPlace->elevation(), 3));
108 }
109 
110 void modCalcGeodCoord::showCartGeoCoords(void)
111 {
112  XGeoBox->setText(QLocale().toString(geoPlace->xPos() / 1000., 6));
113  YGeoBox->setText(QLocale().toString(geoPlace->yPos() / 1000., 6));
114  ZGeoBox->setText(QLocale().toString(geoPlace->zPos() / 1000., 6));
115 }
116 
117 void modCalcGeodCoord::geoCheck(void)
118 {
119  XGeoBoxBatch->setEnabled(false);
120  XGeoCheckBatch->setChecked(false);
121  YGeoBoxBatch->setEnabled(false);
122  YGeoCheckBatch->setChecked(false);
123  YGeoBoxBatch->setEnabled(false);
124  YGeoCheckBatch->setChecked(false);
125  xyzInputCoords = false;
126 }
127 
128 void modCalcGeodCoord::xyzCheck(void)
129 {
130  LongGeoBoxBatch->setEnabled(false);
131  LongGeoCheckBatch->setChecked(false);
132  LatGeoBoxBatch->setEnabled(false);
133  LatGeoCheckBatch->setChecked(false);
134  AltGeoBoxBatch->setEnabled(false);
135  AltGeoCheckBatch->setChecked(false);
136  xyzInputCoords = true;
137 }
138 
139 void modCalcGeodCoord::slotLongCheckedBatch()
140 {
141  if (LongGeoCheckBatch->isChecked())
142  {
143  LongGeoBoxBatch->setEnabled(false);
144  geoCheck();
145  }
146  else
147  {
148  LongGeoBoxBatch->setEnabled(true);
149  }
150 }
151 
152 void modCalcGeodCoord::slotLatCheckedBatch()
153 {
154  if (LatGeoCheckBatch->isChecked())
155  {
156  LatGeoBoxBatch->setEnabled(false);
157  geoCheck();
158  }
159  else
160  {
161  LatGeoBoxBatch->setEnabled(true);
162  }
163 }
164 
165 void modCalcGeodCoord::slotElevCheckedBatch()
166 {
167  if (AltGeoCheckBatch->isChecked())
168  {
169  AltGeoBoxBatch->setEnabled(false);
170  geoCheck();
171  }
172  else
173  {
174  AltGeoBoxBatch->setEnabled(true);
175  }
176 }
177 
178 void modCalcGeodCoord::slotXCheckedBatch()
179 {
180  if (XGeoCheckBatch->isChecked())
181  {
182  XGeoBoxBatch->setEnabled(false);
183  xyzCheck();
184  }
185  else
186  {
187  XGeoBoxBatch->setEnabled(true);
188  }
189 }
190 
191 void modCalcGeodCoord::slotYCheckedBatch()
192 {
193  if (YGeoCheckBatch->isChecked())
194  {
195  YGeoBoxBatch->setEnabled(false);
196  xyzCheck();
197  }
198  else
199  {
200  YGeoBoxBatch->setEnabled(true);
201  }
202 }
203 
204 void modCalcGeodCoord::slotZCheckedBatch()
205 {
206  if (ZGeoCheckBatch->isChecked())
207  {
208  ZGeoBoxBatch->setEnabled(false);
209  xyzCheck();
210  }
211  else
212  {
213  ZGeoBoxBatch->setEnabled(true);
214  }
215 }
216 void modCalcGeodCoord::slotInputFile()
217 {
218  const QString inputFileName = QFileDialog::getOpenFileName(KStars::Instance(), QString(), QString());
219  if (!inputFileName.isEmpty())
220  InputFileBoxBatch->setUrl(QUrl::fromLocalFile(inputFileName));
221 }
222 
223 void modCalcGeodCoord::slotOutputFile()
224 {
225  const QString outputFileName = QFileDialog::getSaveFileName();
226  if (!outputFileName.isEmpty())
227  OutputFileBoxBatch->setUrl(QUrl::fromLocalFile(outputFileName));
228 }
229 
230 void modCalcGeodCoord::slotRunBatch(void)
231 {
232  const QString inputFileName = InputFileBoxBatch->url().toLocalFile();
233 
234  // We open the input file and read its content
235 
236  if (QFile::exists(inputFileName))
237  {
238  QFile f(inputFileName);
239  if (!f.open(QIODevice::ReadOnly))
240  {
241  QString message = i18n("Could not open file %1.", f.fileName());
242  KSNotification::sorry(message, i18n("Could Not Open File"));
243  return;
244  }
245 
246  // processLines(&f);
247  QTextStream istream(&f);
248  processLines(istream);
249  // readFile( istream );
250  f.close();
251  }
252  else
253  {
254  QString message = i18n("Invalid file: %1", inputFileName);
255  KSNotification::sorry(message, i18n("Invalid file"));
256  InputFileBoxBatch->setUrl(QUrl());
257  }
258 }
259 
260 void modCalcGeodCoord::processLines(QTextStream &istream)
261 {
262  // we open the output file
263 
264  // QTextStream istream(&fIn);
265  const QString outputFileName = OutputFileBoxBatch->url().toLocalFile();
266  QFile fOut(outputFileName);
267  fOut.open(QIODevice::WriteOnly);
268  QTextStream ostream(&fOut);
269 
270  QString line;
271  QChar space = ' ';
272  int i = 0;
273  GeoLocation geoPl(dms(0), dms(0));
274  geoPl.setEllipsoid(0);
275 
276  double xB, yB, zB, hB;
277  dms latB, longB;
278 
279  while (!istream.atEnd())
280  {
281  line = istream.readLine();
282  line = line.trimmed();
283 
284  //Go through the line, looking for parameters
285 
286  QStringList fields = line.split(' ');
287 
288  i = 0;
289 
290  // Input coords are XYZ:
291 
292  if (xyzInputCoords)
293  {
294  // Read X and write in ostream if corresponds
295 
296  if (XGeoCheckBatch->isChecked())
297  {
298  xB = fields[i].toDouble();
299  i++;
300  }
301  else
302  xB = XGeoBoxBatch->text().toDouble();
303 
304  if (AllRadioBatch->isChecked())
305  ostream << xB << space;
306  else if (XGeoCheckBatch->isChecked())
307  ostream << xB << space;
308 
309  // Read Y and write in ostream if corresponds
310 
311  if (YGeoCheckBatch->isChecked())
312  {
313  yB = fields[i].toDouble();
314  i++;
315  }
316  else
317  yB = YGeoBoxBatch->text().toDouble();
318 
319  if (AllRadioBatch->isChecked())
320  ostream << yB << space;
321  else if (YGeoCheckBatch->isChecked())
322  ostream << yB << space;
323  // Read Z and write in ostream if corresponds
324 
325  if (ZGeoCheckBatch->isChecked())
326  {
327  zB = fields[i].toDouble();
328  i++;
329  }
330  else
331  zB = ZGeoBoxBatch->text().toDouble();
332 
333  if (AllRadioBatch->isChecked())
334  ostream << zB << space;
335  else if (YGeoCheckBatch->isChecked())
336  ostream << zB << space;
337 
338  geoPl.setXPos(xB * 1000.0);
339  geoPl.setYPos(yB * 1000.0);
340  geoPl.setZPos(zB * 1000.0);
341  ostream << geoPl.lng()->toDMSString() << space << geoPl.lat()->toDMSString() << space << geoPl.elevation()
342  << endl;
343 
344  // Input coords. are Long, Lat and Height
345  }
346  else
347  {
348  // Read Longitude and write in ostream if corresponds
349 
350  if (LongGeoCheckBatch->isChecked())
351  {
352  longB = dms::fromString(fields[i], true);
353  i++;
354  }
355  else
356  longB = LongGeoBoxBatch->createDms(true);
357 
358  if (AllRadioBatch->isChecked())
359  ostream << longB.toDMSString() << space;
360  else if (LongGeoCheckBatch->isChecked())
361  ostream << longB.toDMSString() << space;
362 
363  // Read Latitude and write in ostream if corresponds
364 
365  if (LatGeoCheckBatch->isChecked())
366  {
367  latB = dms::fromString(fields[i], true);
368  i++;
369  }
370  else
371  latB = LatGeoBoxBatch->createDms(true);
372 
373  if (AllRadioBatch->isChecked())
374  ostream << latB.toDMSString() << space;
375  else if (LatGeoCheckBatch->isChecked())
376  ostream << latB.toDMSString() << space;
377 
378  // Read Height and write in ostream if corresponds
379 
380  if (AltGeoCheckBatch->isChecked())
381  {
382  hB = fields[i].toDouble();
383  i++;
384  }
385  else
386  hB = AltGeoBoxBatch->text().toDouble();
387 
388  if (AllRadioBatch->isChecked())
389  ostream << hB << space;
390  else if (AltGeoCheckBatch->isChecked())
391  ostream << hB << space;
392 
393  geoPl.setLong(longB);
394  geoPl.setLat(latB);
395  geoPl.setElevation(hB);
396 
397  ostream << geoPl.xPos() / 1000.0 << space << geoPl.yPos() / 1000.0 << space << geoPl.zPos() / 1000.0
398  << endl;
399  }
400  }
401 
402  fOut.close();
403 }
QWidget
QWidget::setupUi
void setupUi(QWidget *widget)
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:78
dms::fromString
static dms fromString(const QString &s, bool deg)
Static function to create a DMS object from a QString.
Definition: dms.cpp:398
QTextStream::readLine
QString readLine(qint64 maxlen)
modCalcGeodCoord::modCalcGeodCoord
modCalcGeodCoord(QWidget *p)
Definition: modcalcgeodcoord.cpp:29
GeoLocation::lng
const CachingDms * lng() const
Definition: geolocation.h:76
QChar
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
modCalcGeodCoord::slotClearGeoCoords
void slotClearGeoCoords(void)
Definition: modcalcgeodcoord.cpp:80
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:98
modCalcGeodCoord::slotXCheckedBatch
void slotXCheckedBatch()
Definition: modcalcgeodcoord.cpp:178
KSNotification::sorry
void sorry(const QString &message, const QString &title)
Definition: ksnotification.cpp:42
KStars::Instance
static KStars * Instance()
Definition: kstars.h:130
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:215
QFile::exists
bool exists() const
QFile
QTextStream
GeoLocation::lat
const CachingDms * lat() const
Definition: geolocation.h:82
geolocation.h
dms.h
modCalcGeodCoord::slotYCheckedBatch
void slotYCheckedBatch()
Definition: modcalcgeodcoord.cpp:191
NaN::f
const float f
Definition: nan.h:35
QTextStream::atEnd
bool atEnd() const
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
modCalcGeodCoord::showCartGeoCoords
void showCartGeoCoords(void)
Definition: modcalcgeodcoord.cpp:110
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
modCalcGeodCoord::getSphGeoCoords
void getSphGeoCoords(void)
Definition: modcalcgeodcoord.cpp:73
modCalcGeodCoord::slotZCheckedBatch
void slotZCheckedBatch()
Definition: modcalcgeodcoord.cpp:204
modCalcGeodCoord::slotLatCheckedBatch
void slotLatCheckedBatch()
Definition: modcalcgeodcoord.cpp:152
QString
modCalcGeodCoord::slotComputeGeoCoords
void slotComputeGeoCoords(void)
Definition: modcalcgeodcoord.cpp:89
QStringList
QLocale
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:48
modCalcGeodCoord::slotElevCheckedBatch
void slotElevCheckedBatch()
Definition: modcalcgeodcoord.cpp:165
QUrl
QFrame
modCalcGeodCoord::slotInputFile
void slotInputFile()
Definition: modcalcgeodcoord.cpp:216
ksnotification.h
modCalcGeodCoord::getCartGeoCoords
void getCartGeoCoords(void)
Definition: modcalcgeodcoord.cpp:66
QFileDialog::getSaveFileName
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
dms::toDMSString
const QString toDMSString(const bool forceSign=false, const bool machineReadable=false, const bool highPrecision=false) const
Definition: dms.cpp:287
QWidget::show
void show()
kstarsdata.h
QFileDialog::getOpenFileName
QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, QString *selectedFilter, QFlags< QFileDialog::Option > options)
modCalcGeodCoord::slotLongCheckedBatch
void slotLongCheckedBatch()
Definition: modcalcgeodcoord.cpp:139
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
modCalcGeodCoord::showSpheGeoCoords
void showSpheGeoCoords(void)
Definition: modcalcgeodcoord.cpp:103
kstars.h
QUrl::fromLocalFile
QUrl fromLocalFile(const QString &localFile)
modCalcGeodCoord::setEllipsoid
void setEllipsoid(int i)
Definition: modcalcgeodcoord.cpp:61
modcalcgeodcoord.h
modCalcGeodCoord::slotOutputFile
void slotOutputFile()
Definition: modcalcgeodcoord.cpp:223
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Fri Dec 13 2019 02:57:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

edu API Reference

Skip menu "edu API Reference"
  •     core
  • kstars

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal