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

kstars

  • sources
  • kde-4.12
  • kdeedu
  • 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 : vicente@oan.es
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 <QTextStream>
21 
22 #include <kfiledialog.h>
23 #include <kglobal.h>
24 #include <kmessagebox.h>
25 
26 #include "dms.h"
27 #include "geolocation.h"
28 #include "kstars.h"
29 #include "kstarsdata.h"
30 #include "widgets/dmsbox.h"
31 
32 
33 modCalcGeodCoord::modCalcGeodCoord(QWidget *parentSplit)
34  : QFrame(parentSplit) {
35 
36  QStringList ellipsoidList;
37  ellipsoidList << "IAU76" << "GRS80" << "MERIT83" << "WGS84" << "IERS89";
38 
39  setupUi(this);
40 
41  spheRadio->setChecked(true);
42  ellipsoidBox->insertItems(5,ellipsoidList);
43  geoPlace = 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 
53 modCalcGeodCoord::~modCalcGeodCoord(){
54  delete geoPlace;
55 }
56 
57 void modCalcGeodCoord::showLongLat(void)
58 {
59  KStarsData* data = KStarsData::Instance();
60  LongGeoBox->show( data->geo()->lng() );
61  LatGeoBox->show( data->geo()->lat() );
62  AltGeoBox->setText( QString("0.0") );
63 }
64 
65 void modCalcGeodCoord::setEllipsoid(int index) {
66 
67  geoPlace->changeEllipsoid(index);
68 
69 }
70 
71 void modCalcGeodCoord::getCartGeoCoords (void)
72 {
73 
74  geoPlace->setXPos( KGlobal::locale()->readNumber(XGeoBox->text())*1000. );
75  geoPlace->setYPos( KGlobal::locale()->readNumber(YGeoBox->text())*1000. );
76  geoPlace->setZPos( KGlobal::locale()->readNumber(ZGeoBox->text())*1000. );
77 }
78 
79 void modCalcGeodCoord::getSphGeoCoords (void)
80 {
81  geoPlace->setLong( LongGeoBox->createDms() );
82  geoPlace->setLat( LatGeoBox->createDms() );
83  geoPlace->setHeight( AltGeoBox->text().toDouble() );
84 }
85 
86 void modCalcGeodCoord::slotClearGeoCoords (void)
87 {
88 
89  geoPlace->setLong( dms(0.0) );
90  geoPlace->setLat( dms(0.0) );
91  geoPlace->setHeight( 0.0 );
92  LatGeoBox->clearFields();
93  LongGeoBox->clearFields();
94 }
95 
96 void modCalcGeodCoord::slotComputeGeoCoords (void)
97 {
98 
99  if(cartRadio->isChecked()) {
100  getCartGeoCoords();
101  showSpheGeoCoords();
102  } else {
103  getSphGeoCoords();
104  showCartGeoCoords();
105  }
106 
107 }
108 
109 void modCalcGeodCoord::showSpheGeoCoords(void)
110 {
111  LongGeoBox->show( geoPlace->lng() );
112  LatGeoBox->show( geoPlace->lat() );
113  AltGeoBox->setText( KGlobal::locale()->formatNumber( geoPlace->height(), 3) );
114 }
115 
116 void modCalcGeodCoord::showCartGeoCoords(void)
117 {
118 
119  XGeoBox->setText( KGlobal::locale()->formatNumber( geoPlace->xPos()/1000. ,6));
120  YGeoBox->setText( KGlobal::locale()->formatNumber( geoPlace->yPos()/1000. ,6));
121  ZGeoBox->setText( KGlobal::locale()->formatNumber( geoPlace->zPos()/1000. ,6));
122 }
123 
124 void modCalcGeodCoord::geoCheck(void) {
125 
126  XGeoBoxBatch->setEnabled( false );
127  XGeoCheckBatch->setChecked( false );
128  YGeoBoxBatch->setEnabled( false );
129  YGeoCheckBatch->setChecked( false );
130  YGeoBoxBatch->setEnabled( false );
131  YGeoCheckBatch->setChecked( false );
132  xyzInputCoords = false;
133 }
134 
135 void modCalcGeodCoord::xyzCheck(void) {
136 
137  LongGeoBoxBatch->setEnabled( false );
138  LongGeoCheckBatch->setChecked( false );
139  LatGeoBoxBatch->setEnabled( false );
140  LatGeoCheckBatch->setChecked( false );
141  AltGeoBoxBatch->setEnabled( false );
142  AltGeoCheckBatch->setChecked( false );
143  xyzInputCoords = true;
144 
145 }
146 
147 void modCalcGeodCoord::slotLongCheckedBatch(){
148 
149  if ( LongGeoCheckBatch->isChecked() ) {
150  LongGeoBoxBatch->setEnabled( false );
151  geoCheck();
152  } else {
153  LongGeoBoxBatch->setEnabled( true );
154  }
155 }
156 
157 void modCalcGeodCoord::slotLatCheckedBatch(){
158 
159  if ( LatGeoCheckBatch->isChecked() ) {
160  LatGeoBoxBatch->setEnabled( false );
161  geoCheck();
162  } else {
163  LatGeoBoxBatch->setEnabled( true );
164  }
165 }
166 
167 void modCalcGeodCoord::slotElevCheckedBatch(){
168 
169  if ( AltGeoCheckBatch->isChecked() ) {
170  AltGeoBoxBatch->setEnabled( false );
171  geoCheck();
172  } else {
173  AltGeoBoxBatch->setEnabled( true );
174  }
175 }
176 
177 void modCalcGeodCoord::slotXCheckedBatch(){
178 
179  if ( XGeoCheckBatch->isChecked() ) {
180  XGeoBoxBatch->setEnabled( false );
181  xyzCheck();
182  } else {
183  XGeoBoxBatch->setEnabled( true );
184  }
185 }
186 
187 void modCalcGeodCoord::slotYCheckedBatch(){
188 
189  if ( YGeoCheckBatch->isChecked() ) {
190  YGeoBoxBatch->setEnabled( false );
191  xyzCheck();
192  } else {
193  YGeoBoxBatch->setEnabled( true );
194  }
195 }
196 
197 void modCalcGeodCoord::slotZCheckedBatch(){
198 
199  if ( ZGeoCheckBatch->isChecked() ) {
200  ZGeoBoxBatch->setEnabled( false );
201  xyzCheck();
202  } else {
203  ZGeoBoxBatch->setEnabled( true );
204  }
205 }
206 void modCalcGeodCoord::slotInputFile() {
207 
208  QString inputFileName;
209  inputFileName = KFileDialog::getOpenFileName( );
210  InputFileBoxBatch->setUrl( inputFileName );
211 }
212 
213 void modCalcGeodCoord::slotOutputFile() {
214 
215  QString outputFileName;
216  outputFileName = KFileDialog::getSaveFileName( );
217  OutputFileBoxBatch->setUrl( outputFileName );
218 }
219 
220 void modCalcGeodCoord::slotRunBatch(void) {
221 
222  QString inputFileName;
223 
224  inputFileName = InputFileBoxBatch->url().toLocalFile();
225 
226  // We open the input file and read its content
227 
228  if ( QFile::exists(inputFileName) ) {
229  QFile f( inputFileName );
230  if ( !f.open( QIODevice::ReadOnly) ) {
231  QString message = i18n( "Could not open file %1.", f.fileName() );
232  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
233  inputFileName.clear();
234  return;
235  }
236 
237  // processLines(&f);
238  QTextStream istream(&f);
239  processLines(istream);
240  // readFile( istream );
241  f.close();
242  } else {
243  QString message = i18n( "Invalid file: %1", inputFileName );
244  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
245  inputFileName.clear();
246  InputFileBoxBatch->setUrl( inputFileName );
247  return;
248  }
249 }
250 
251 void modCalcGeodCoord::processLines( QTextStream &istream ) {
252 
253  // we open the output file
254 
255  // QTextStream istream(&fIn);
256  QString outputFileName;
257  outputFileName = OutputFileBoxBatch->url().toLocalFile();
258  QFile fOut( outputFileName );
259  fOut.open(QIODevice::WriteOnly);
260  QTextStream ostream(&fOut);
261 
262  QString line;
263  QChar space = ' ';
264  int i = 0;
265  GeoLocation geoPl( dms(0), dms(0) );
266  geoPl.setEllipsoid(0);
267 
268  double xB, yB, zB, hB;
269  dms latB, longB;
270 
271 
272  while ( ! istream.atEnd() ) {
273  line = istream.readLine();
274  line.trimmed();
275 
276  //Go through the line, looking for parameters
277 
278  QStringList fields = line.split( ' ' );
279 
280  i = 0;
281 
282  // Input coords are XYZ:
283 
284  if (xyzInputCoords) {
285 
286  // Read X and write in ostream if corresponds
287 
288  if(XGeoCheckBatch->isChecked() ) {
289  xB = fields[i].toDouble();
290  i++;
291  } else
292  xB = KGlobal::locale()->readNumber(XGeoBoxBatch->text()) ;
293 
294  if ( AllRadioBatch->isChecked() )
295  ostream << xB << space;
296  else
297  if(XGeoCheckBatch->isChecked() )
298  ostream << xB << space;
299 
300  // Read Y and write in ostream if corresponds
301 
302  if(YGeoCheckBatch->isChecked() ) {
303  yB = fields[i].toDouble();
304  i++;
305  } else
306  yB = KGlobal::locale()->readNumber( YGeoBoxBatch->text()) ;
307 
308  if ( AllRadioBatch->isChecked() )
309  ostream << yB << space;
310  else
311  if(YGeoCheckBatch->isChecked() )
312  ostream << yB << space;
313  // Read Z and write in ostream if corresponds
314 
315  if(ZGeoCheckBatch->isChecked() ) {
316  zB = fields[i].toDouble();
317  i++;
318  } else
319  zB = KGlobal::locale()->readNumber( ZGeoBoxBatch->text());
320 
321  if ( AllRadioBatch->isChecked() )
322  ostream << zB << space;
323  else
324  if(YGeoCheckBatch->isChecked() )
325  ostream << zB << space;
326 
327  geoPl.setXPos( xB*1000.0 );
328  geoPl.setYPos( yB*1000.0 );
329  geoPl.setZPos( zB*1000.0 );
330  ostream << geoPl.lng()->toDMSString() << space <<
331  geoPl.lat()->toDMSString() << space <<
332  geoPl.height() << endl;
333 
334  // Input coords. are Long, Lat and Height
335 
336  } else {
337 
338  // Read Longitude and write in ostream if corresponds
339 
340  if(LongGeoCheckBatch->isChecked() ) {
341  longB = dms::fromString( fields[i],true);
342  i++;
343  } else
344  longB = LongGeoBoxBatch->createDms(true);
345 
346  if ( AllRadioBatch->isChecked() )
347  ostream << longB.toDMSString() << space;
348  else
349  if(LongGeoCheckBatch->isChecked() )
350  ostream << longB.toDMSString() << space;
351 
352  // Read Latitude and write in ostream if corresponds
353 
354  if(LatGeoCheckBatch->isChecked() ) {
355  latB = dms::fromString( fields[i], true);
356  i++;
357  } else
358  latB = LatGeoBoxBatch->createDms(true);
359 
360  if ( AllRadioBatch->isChecked() )
361  ostream << latB.toDMSString() << space;
362  else
363  if(LatGeoCheckBatch->isChecked() )
364  ostream << latB.toDMSString() << space;
365 
366  // Read Height and write in ostream if corresponds
367 
368  if(AltGeoCheckBatch->isChecked() ) {
369  hB = fields[i].toDouble();
370  i++;
371  } else
372  hB = AltGeoBoxBatch->text().toDouble() ;
373 
374  if ( AllRadioBatch->isChecked() )
375  ostream << hB << space;
376  else
377  if(AltGeoCheckBatch->isChecked() )
378  ostream << hB << space;
379 
380  geoPl.setLong( longB );
381  geoPl.setLat( latB );
382  geoPl.setHeight( hB );
383 
384  ostream << geoPl.xPos()/1000.0 << space <<
385  geoPl.yPos()/1000.0 << space <<
386  geoPl.zPos()/1000.0 << endl;
387 
388  }
389 
390  }
391 
392 
393  fOut.close();
394 }
395 
396 #include "modcalcgeodcoord.moc"
GeoLocation::xPos
double xPos() const
Definition: geolocation.h:85
modCalcGeodCoord::~modCalcGeodCoord
~modCalcGeodCoord()
Definition: modcalcgeodcoord.cpp:53
GeoLocation::setYPos
void setYPos(double y)
Set Y.
Definition: geolocation.h:159
GeoLocation::setXPos
void setXPos(double x)
Set X.
Definition: geolocation.h:152
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
modCalcGeodCoord::modCalcGeodCoord
modCalcGeodCoord(QWidget *p)
Definition: modcalcgeodcoord.cpp:33
modCalcGeodCoord::slotClearGeoCoords
void slotClearGeoCoords(void)
Definition: modcalcgeodcoord.cpp:86
GeoLocation::zPos
double zPos() const
Definition: geolocation.h:91
GeoLocation::setZPos
void setZPos(double z)
Set Z.
Definition: geolocation.h:166
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
GeoLocation::lng
const dms * lng() const
Definition: geolocation.h:76
modCalcGeodCoord::slotXCheckedBatch
void slotXCheckedBatch()
Definition: modcalcgeodcoord.cpp:177
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
GeoLocation::changeEllipsoid
void changeEllipsoid(int i)
Update Latitude, Longitude and Height according to new ellipsoid.
Definition: geolocation.cpp:73
GeoLocation::setLat
void setLat(dms l)
Set latitude according to dms argument.
Definition: geolocation.h:136
geolocation.h
dms.h
GeoLocation::setLong
void setLong(dms l)
Set longitude according to dms argument.
Definition: geolocation.h:128
GeoLocation::height
double height() const
Definition: geolocation.h:82
modCalcGeodCoord::slotYCheckedBatch
void slotYCheckedBatch()
Definition: modcalcgeodcoord.cpp:187
NaN::f
const float f
Definition: nan.h:36
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:116
modCalcGeodCoord::getSphGeoCoords
void getSphGeoCoords(void)
Definition: modcalcgeodcoord.cpp:79
modCalcGeodCoord::slotZCheckedBatch
void slotZCheckedBatch()
Definition: modcalcgeodcoord.cpp:197
GeoLocation::yPos
double yPos() const
Definition: geolocation.h:88
modCalcGeodCoord::slotLatCheckedBatch
void slotLatCheckedBatch()
Definition: modcalcgeodcoord.cpp:157
modCalcGeodCoord::slotComputeGeoCoords
void slotComputeGeoCoords(void)
Definition: modcalcgeodcoord.cpp:96
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
modCalcGeodCoord::slotElevCheckedBatch
void slotElevCheckedBatch()
Definition: modcalcgeodcoord.cpp:167
modCalcGeodCoord::slotInputFile
void slotInputFile()
Definition: modcalcgeodcoord.cpp:206
GeoLocation::setHeight
void setHeight(double hg)
Set elevation above sea level.
Definition: geolocation.h:144
QTextStream
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
modCalcGeodCoord::getCartGeoCoords
void getCartGeoCoords(void)
Definition: modcalcgeodcoord.cpp:71
kstarsdata.h
dmsbox.h
modCalcGeodCoord::slotLongCheckedBatch
void slotLongCheckedBatch()
Definition: modcalcgeodcoord.cpp:147
modCalcGeodCoord::showSpheGeoCoords
void showSpheGeoCoords(void)
Definition: modcalcgeodcoord.cpp:109
QFrame
kstars.h
modCalcGeodCoord::setEllipsoid
void setEllipsoid(int i)
Definition: modcalcgeodcoord.cpp:65
modcalcgeodcoord.h
modCalcGeodCoord::slotOutputFile
void slotOutputFile()
Definition: modcalcgeodcoord.cpp:213
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 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
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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