kstars
modcalcgeodcoord.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "modcalcgeodcoord.h"
00019 #include "modcalcgeodcoord.moc"
00020 #include "dms.h"
00021 #include "dmsbox.h"
00022 #include "geolocation.h"
00023 #include "kstars.h"
00024
00025 #include <qradiobutton.h>
00026 #include <qstring.h>
00027 #include <qcheckbox.h>
00028 #include <qtextstream.h>
00029
00030 #include <kcombobox.h>
00031 #include <klineedit.h>
00032 #include <kapplication.h>
00033 #include <knumvalidator.h>
00034 #include <klocale.h>
00035 #include <klineedit.h>
00036 #include <kfiledialog.h>
00037 #include <kmessagebox.h>
00038
00039
00040 modCalcGeodCoord::modCalcGeodCoord(QWidget *parentSplit, const char *name) : modCalcGeodCoordDlg(parentSplit,name) {
00041
00042 static const char *ellipsoidList[] = {
00043 "IAU76", "GRS80", "MERIT83", "WGS84", "IERS89"};
00044
00045 spheRadio->setChecked(TRUE);
00046 ellipsoidBox->insertStrList (ellipsoidList,5);
00047 geoPlace = new GeoLocation();
00048 showLongLat();
00049 setEllipsoid(0);
00050 show();
00051
00052 }
00053
00054 modCalcGeodCoord::~modCalcGeodCoord(){
00055 delete geoPlace;
00056 }
00057
00058 void modCalcGeodCoord::showLongLat(void)
00059 {
00060
00061 KStars *ks = (KStars*) parent()->parent()->parent();
00062 lonGeoBox->show( ks->geo()->lng() );
00063 latGeoBox->show( ks->geo()->lat() );
00064 altGeoBox->setText( QString("0.0") );
00065 }
00066
00067 void modCalcGeodCoord::setEllipsoid(int index) {
00068
00069 geoPlace->changeEllipsoid(index);
00070
00071 }
00072
00073 void modCalcGeodCoord::getCartGeoCoords (void)
00074 {
00075
00076 geoPlace->setXPos( KGlobal::locale()->readNumber(xGeoName->text())*1000. );
00077 geoPlace->setYPos( KGlobal::locale()->readNumber(yGeoName->text())*1000. );
00078 geoPlace->setZPos( KGlobal::locale()->readNumber(zGeoName->text())*1000. );
00079
00080
00081
00082 }
00083
00084 void modCalcGeodCoord::getSphGeoCoords (void)
00085 {
00086 geoPlace->setLong( lonGeoBox->createDms() );
00087 geoPlace->setLat( latGeoBox->createDms() );
00088 geoPlace->setHeight( altGeoBox->text().toDouble() );
00089 }
00090
00091 void modCalcGeodCoord::slotClearGeoCoords (void)
00092 {
00093
00094 geoPlace->setLong( 0.0 );
00095 geoPlace->setLat( 0.0 );
00096 geoPlace->setHeight( 0.0 );
00097 latGeoBox->clearFields();
00098 lonGeoBox->clearFields();
00099
00100
00101
00102 }
00103
00104 void modCalcGeodCoord::slotComputeGeoCoords (void)
00105 {
00106
00107 if(cartRadio->isChecked()) {
00108 getCartGeoCoords();
00109 showSpheGeoCoords();
00110 } else {
00111 getSphGeoCoords();
00112 showCartGeoCoords();
00113 }
00114
00115 }
00116
00117 void modCalcGeodCoord::showSpheGeoCoords(void)
00118 {
00119 lonGeoBox->show( geoPlace->lng() );
00120 latGeoBox->show( geoPlace->lat() );
00121 altGeoBox->setText( KGlobal::locale()->formatNumber( geoPlace->height(), 3) );
00122 }
00123
00124 void modCalcGeodCoord::showCartGeoCoords(void)
00125 {
00126
00127 xGeoName->setText( KGlobal::locale()->formatNumber( geoPlace->xPos()/1000. ,6));
00128 yGeoName->setText( KGlobal::locale()->formatNumber( geoPlace->yPos()/1000. ,6));
00129 zGeoName->setText( KGlobal::locale()->formatNumber( geoPlace->zPos()/1000. ,6));
00130 }
00131
00132 void modCalcGeodCoord::geoCheck(void) {
00133
00134 xBoxBatch->setEnabled( false );
00135 xCheckBatch->setChecked( false );
00136 yBoxBatch->setEnabled( false );
00137 yCheckBatch->setChecked( false );
00138 zBoxBatch->setEnabled( false );
00139 zCheckBatch->setChecked( false );
00140 xyzInputCoords = FALSE;
00141 }
00142
00143 void modCalcGeodCoord::xyzCheck(void) {
00144
00145 longBoxBatch->setEnabled( false );
00146 longCheckBatch->setChecked( false );
00147 latBoxBatch->setEnabled( false );
00148 latCheckBatch->setChecked( false );
00149 elevBoxBatch->setEnabled( false );
00150 elevCheckBatch->setChecked( false );
00151 xyzInputCoords = TRUE;
00152
00153 }
00154
00155 void modCalcGeodCoord::slotLongCheckedBatch(){
00156
00157 if ( longCheckBatch->isChecked() ) {
00158 longBoxBatch->setEnabled( false );
00159 geoCheck();
00160 } else {
00161 longBoxBatch->setEnabled( true );
00162 }
00163 }
00164
00165 void modCalcGeodCoord::slotLatCheckedBatch(){
00166
00167 if ( latCheckBatch->isChecked() ) {
00168 latBoxBatch->setEnabled( false );
00169 geoCheck();
00170 } else {
00171 latBoxBatch->setEnabled( true );
00172 }
00173 }
00174
00175 void modCalcGeodCoord::slotElevCheckedBatch(){
00176
00177 if ( elevCheckBatch->isChecked() ) {
00178 elevBoxBatch->setEnabled( false );
00179 geoCheck();
00180 } else {
00181 elevBoxBatch->setEnabled( true );
00182 }
00183 }
00184
00185 void modCalcGeodCoord::slotXCheckedBatch(){
00186
00187 if ( xCheckBatch->isChecked() ) {
00188 xBoxBatch->setEnabled( false );
00189 xyzCheck();
00190 } else {
00191 xBoxBatch->setEnabled( true );
00192 }
00193 }
00194
00195 void modCalcGeodCoord::slotYCheckedBatch(){
00196
00197 if ( yCheckBatch->isChecked() ) {
00198 yBoxBatch->setEnabled( false );
00199 xyzCheck();
00200 } else {
00201 yBoxBatch->setEnabled( true );
00202 }
00203 }
00204
00205 void modCalcGeodCoord::slotZCheckedBatch(){
00206
00207 if ( zCheckBatch->isChecked() ) {
00208 zBoxBatch->setEnabled( false );
00209 xyzCheck();
00210 } else {
00211 zBoxBatch->setEnabled( true );
00212 }
00213 }
00214 void modCalcGeodCoord::slotInputFile() {
00215
00216 QString inputFileName;
00217 inputFileName = KFileDialog::getOpenFileName( );
00218 InputLineEditBatch->setText( inputFileName );
00219 }
00220
00221 void modCalcGeodCoord::slotOutputFile() {
00222
00223 QString outputFileName;
00224 outputFileName = KFileDialog::getSaveFileName( );
00225 OutputLineEditBatch->setText( outputFileName );
00226 }
00227
00228 void modCalcGeodCoord::slotRunBatch(void) {
00229
00230 QString inputFileName;
00231
00232 inputFileName = InputLineEditBatch->text();
00233
00234
00235
00236 if ( QFile::exists(inputFileName) ) {
00237 QFile f( inputFileName );
00238 if ( !f.open( IO_ReadOnly) ) {
00239 QString message = i18n( "Could not open file %1.").arg( f.name() );
00240 KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00241 inputFileName = "";
00242 return;
00243 }
00244
00245
00246 QTextStream istream(&f);
00247 processLines(istream);
00248
00249 f.close();
00250 } else {
00251 QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00252 KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00253 inputFileName = "";
00254 InputLineEditBatch->setText( inputFileName );
00255 return;
00256 }
00257 }
00258
00259 void modCalcGeodCoord::processLines( QTextStream &istream ) {
00260
00261
00262
00263
00264 QString outputFileName;
00265 outputFileName = OutputLineEditBatch->text();
00266 QFile fOut( outputFileName );
00267 fOut.open(IO_WriteOnly);
00268 QTextStream ostream(&fOut);
00269
00270 QString line;
00271 QString space = " ";
00272 int i = 0;
00273 GeoLocation *geoPl = new GeoLocation();
00274 geoPl->setEllipsoid(0);
00275
00276 double xB, yB, zB, hB;
00277 dms latB, longB;
00278
00279
00280 while ( ! istream.eof() ) {
00281 line = istream.readLine();
00282 line.stripWhiteSpace();
00283
00284
00285
00286 QStringList fields = QStringList::split( " ", line );
00287
00288 i = 0;
00289
00290
00291
00292 if (xyzInputCoords) {
00293
00294
00295
00296 if(xCheckBatch->isChecked() ) {
00297 xB = fields[i].toDouble();
00298 i++;
00299 } else
00300 xB = KGlobal::locale()->readNumber(xBoxBatch->text()) ;
00301
00302 if ( allRadioBatch->isChecked() )
00303 ostream << xB << space;
00304 else
00305 if(xCheckBatch->isChecked() )
00306 ostream << xB << space;
00307
00308
00309
00310 if(yCheckBatch->isChecked() ) {
00311 yB = fields[i].toDouble();
00312 i++;
00313 } else
00314 yB = KGlobal::locale()->readNumber( yBoxBatch->text()) ;
00315
00316 if ( allRadioBatch->isChecked() )
00317 ostream << yB << space;
00318 else
00319 if(yCheckBatch->isChecked() )
00320 ostream << yB << space;
00321
00322
00323 if(zCheckBatch->isChecked() ) {
00324 zB = fields[i].toDouble();
00325 i++;
00326 } else
00327 zB = KGlobal::locale()->readNumber( zBoxBatch->text());
00328
00329 if ( allRadioBatch->isChecked() )
00330 ostream << zB << space;
00331 else
00332 if(yCheckBatch->isChecked() )
00333 ostream << zB << space;
00334
00335 geoPl->setXPos( xB*1000.0 );
00336 geoPl->setYPos( yB*1000.0 );
00337 geoPl->setZPos( zB*1000.0 );
00338 ostream << geoPl->lng()->toDMSString() << space <<
00339 geoPl->lat()->toDMSString() << space <<
00340 geoPl->height() << endl;
00341
00342
00343
00344 } else {
00345
00346
00347
00348 if(longCheckBatch->isChecked() ) {
00349 longB = dms::fromString( fields[i],TRUE);
00350 i++;
00351 } else
00352 longB = longBoxBatch->createDms(TRUE);
00353
00354 if ( allRadioBatch->isChecked() )
00355 ostream << longB.toDMSString() << space;
00356 else
00357 if(longCheckBatch->isChecked() )
00358 ostream << longB.toDMSString() << space;
00359
00360
00361
00362 if(latCheckBatch->isChecked() ) {
00363 latB = dms::fromString( fields[i], TRUE);
00364 i++;
00365 } else
00366 latB = latBoxBatch->createDms(TRUE);
00367
00368 if ( allRadioBatch->isChecked() )
00369 ostream << latB.toDMSString() << space;
00370 else
00371 if(latCheckBatch->isChecked() )
00372 ostream << latB.toDMSString() << space;
00373
00374
00375
00376 if(elevCheckBatch->isChecked() ) {
00377 hB = fields[i].toDouble();
00378 i++;
00379 } else
00380 hB = elevBoxBatch->text().toDouble() ;
00381
00382 if ( allRadioBatch->isChecked() )
00383 ostream << hB << space;
00384 else
00385 if(elevCheckBatch->isChecked() )
00386 ostream << hB << space;
00387
00388 geoPl->setLong( longB );
00389 geoPl->setLat( latB );
00390 geoPl->setHeight( hB );
00391
00392 ostream << geoPl->xPos()/1000.0 << space <<
00393 geoPl->yPos()/1000.0 << space <<
00394 geoPl->zPos()/1000.0 << endl;
00395
00396 }
00397
00398 }
00399
00400
00401 fOut.close();
00402 }