diff --git a/kstars/tools/modcalcangdist.cpp b/kstars/tools/modcalcangdist.cpp index b7d978aeb..ec806a2f4 100644 --- a/kstars/tools/modcalcangdist.cpp +++ b/kstars/tools/modcalcangdist.cpp @@ -1,268 +1,268 @@ /*************************************************************************** modcalcapcoord.cpp - description ------------------- begin : Sun May 30 2004 copyright : (C) 2004 by Pablo de Vicente email : vicente@oan.es ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "modcalcangdist.h" #include #include #include #include #include "dms.h" #include "widgets/dmsbox.h" #include "skyobjects/skypoint.h" #include "skyobjects/skyobject.h" #include "dialogs/finddialog.h" #include "kstars.h" modCalcAngDist::modCalcAngDist(QWidget *parentSplit) : QFrame(parentSplit) { setupUi(this); FirstRA->setDegType(false); SecondRA->setDegType(false); connect(FirstRA, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions())); connect(FirstDec, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions())); connect(SecondRA, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions())); connect(SecondDec, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions())); connect(FirstRA, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle())); connect(FirstDec, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle())); connect(SecondRA, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle())); connect(SecondDec, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle())); connect(FirstObjectButton, SIGNAL(clicked()), this, SLOT(slotObjectButton())); connect(SecondObjectButton, SIGNAL(clicked()), this, SLOT(slotObjectButton())); connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch())); show(); slotValidatePositions(); } modCalcAngDist::~modCalcAngDist() { } SkyPoint modCalcAngDist::getCoords(dmsBox *rBox, dmsBox *dBox, bool *ok) { dms raCoord, decCoord; bool ok2 = false; raCoord = rBox->createDms(false, &ok2); if (ok2) decCoord = dBox->createDms(true, &ok2); if (ok2) { if (ok) *ok = ok2; return SkyPoint(raCoord, decCoord); } else { if (ok) *ok = ok2; return SkyPoint(); } } void modCalcAngDist::slotValidatePositions() { SkyPoint sp0, sp1; bool ok; sp0 = getCoords(FirstRA, FirstDec, &ok); if (ok) sp1 = getCoords(SecondRA, SecondDec, &ok); if (ok) { double PA = 0; AngDist->setText(sp0.angularDistanceTo(&sp1, &PA).toDMSString()); PositionAngle->setText(QString::number(PA, 'f', 3)); } else { AngDist->setText(" .... "); PositionAngle->setText(" .... "); } } void modCalcAngDist::slotObjectButton() { QPointer fd = new FindDialog(this); if (fd->exec() == QDialog::Accepted) { SkyObject *o = fd->targetObject(); if (sender()->objectName() == QString("FirstObjectButton")) { FirstRA->showInHours(o->ra()); FirstDec->showInDegrees(o->dec()); FirstPositionBox->setTitle(i18n("First position: %1", o->name())); } else { SecondRA->showInHours(o->ra()); SecondDec->showInDegrees(o->dec()); SecondPositionBox->setTitle(i18n("Second position: %1", o->name())); } slotValidatePositions(); } delete fd; } void modCalcAngDist::slotResetTitle() { QString name = sender()->objectName(); if (name.contains("First")) FirstPositionBox->setTitle(i18n("First position")); else SecondPositionBox->setTitle(i18n("Second position")); } void modCalcAngDist::slotRunBatch() { QString inputFileName = InputLineEditBatch->url().toLocalFile(); // We open the input file and read its content if (QFile::exists(inputFileName)) { QFile f(inputFileName); if (!f.open(QIODevice::ReadOnly)) { QString message = i18n("Could not open file %1.", f.fileName()); KMessageBox::sorry(nullptr, message, i18n("Could Not Open File")); inputFileName.clear(); return; } // processLines(&f); QTextStream istream(&f); processLines(istream); // readFile( istream ); f.close(); } else { QString message = i18n("Invalid file: %1", inputFileName); KMessageBox::sorry(nullptr, message, i18n("Invalid file")); inputFileName.clear(); InputLineEditBatch->setText(inputFileName); return; } } //void modCalcAngDist::processLines( const QFile * fIn ) { void modCalcAngDist::processLines(QTextStream &istream) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputLineEditBatch->text(); QFile fOut(outputFileName); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); QString line; QChar space = ' '; int i = 0; SkyPoint sp0, sp1; double PA = 0; dms ra0B, dec0B, ra1B, dec1B, dist; while (!istream.atEnd()) { line = istream.readLine(); - line.trimmed(); + line = line.trimmed(); //Go through the line, looking for parameters QStringList fields = line.split(' '); i = 0; // Read RA and write in ostream if corresponds if (ra0CheckBatch->isChecked()) { ra0B = dms::fromString(fields[i], false); i++; } else ra0B = ra0BoxBatch->createDms(false); if (allRadioBatch->isChecked()) ostream << ra0B.toHMSString() << space; else if (ra0CheckBatch->isChecked()) ostream << ra0B.toHMSString() << space; // Read DEC and write in ostream if corresponds if (dec0CheckBatch->isChecked()) { dec0B = dms::fromString(fields[i], true); i++; } else dec0B = dec0BoxBatch->createDms(); if (allRadioBatch->isChecked()) ostream << dec0B.toDMSString() << space; else if (dec0CheckBatch->isChecked()) ostream << dec0B.toDMSString() << space; // Read RA and write in ostream if corresponds if (ra1CheckBatch->isChecked()) { ra1B = dms::fromString(fields[i], false); i++; } else ra1B = ra1BoxBatch->createDms(false); if (allRadioBatch->isChecked()) ostream << ra1B.toHMSString() << space; else if (ra1CheckBatch->isChecked()) ostream << ra1B.toHMSString() << space; // Read DEC and write in ostream if corresponds if (dec1CheckBatch->isChecked()) { dec1B = dms::fromString(fields[i], true); i++; } else dec1B = dec1BoxBatch->createDms(); if (allRadioBatch->isChecked()) ostream << dec1B.toDMSString() << space; else if (dec1CheckBatch->isChecked()) ostream << dec1B.toDMSString() << space; sp0 = SkyPoint(ra0B, dec0B); sp1 = SkyPoint(ra1B, dec1B); dist = sp0.angularDistanceTo(&sp1, &PA); ostream << dist.toDMSString() << QString::number(PA, 'f', 3) << endl; } fOut.close(); } diff --git a/kstars/tools/modcalcapcoord.cpp b/kstars/tools/modcalcapcoord.cpp index 166dd0b14..45811d663 100644 --- a/kstars/tools/modcalcapcoord.cpp +++ b/kstars/tools/modcalcapcoord.cpp @@ -1,297 +1,297 @@ /*************************************************************************** modcalcapcoord.cpp - description ------------------- begin : Wed Apr 10 2002 copyright : (C) 2002 by Pablo de Vicente email : vicente@oan.es ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "modcalcapcoord.h" #include "dms.h" #include "kstars.h" #include "kstarsdatetime.h" #include "dialogs/finddialog.h" #include "skyobjects/skypoint.h" #include "skyobjects/skyobject.h" #include #include #include #include modCalcApCoord::modCalcApCoord(QWidget *parentSplit) : QFrame(parentSplit) { setupUi(this); showCurrentTime(); RACat->setDegType(false); DecCat->setDegType(true); connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject())); connect(NowButton, SIGNAL(clicked()), this, SLOT(showCurrentTime())); connect(RACat, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(DecCat, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(UT, SIGNAL(timeChanged(QTime)), this, SLOT(slotCompute())); connect(Date, SIGNAL(dateChanged(QDate)), this, SLOT(slotCompute())); connect(utCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtCheckedBatch())); connect(dateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateCheckedBatch())); connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch())); connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch())); connect(epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch())); connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch())); show(); } void modCalcApCoord::showCurrentTime(void) { KStarsDateTime dt(KStarsDateTime::currentDateTime()); Date->setDate(dt.date()); UT->setTime(dt.time()); EpochTarget->setText(QString::number(dt.epoch(), 'f', 3)); } void modCalcApCoord::slotCompute() { KStarsDateTime dt(Date->date(), UT->time()); long double jd = dt.djd(); dt.setFromEpoch(EpochCat->value()); long double jd0 = dt.djd(); SkyPoint sp(RACat->createDms(false), DecCat->createDms()); sp.apparentCoord(jd0, jd); RA->setText(sp.ra().toHMSString()); Dec->setText(sp.dec().toDMSString()); } void modCalcApCoord::slotObject() { QPointer fd = new FindDialog(this); if (fd->exec() == QDialog::Accepted) { SkyObject *o = fd->targetObject(); RACat->showInHours(o->ra0()); DecCat->showInDegrees(o->dec0()); EpochCat->setValue(2000.0); slotCompute(); } delete fd; } void modCalcApCoord::slotUtCheckedBatch() { if (utCheckBatch->isChecked()) utBoxBatch->setEnabled(false); else { utBoxBatch->setEnabled(true); } } void modCalcApCoord::slotDateCheckedBatch() { if (dateCheckBatch->isChecked()) dateBoxBatch->setEnabled(false); else { dateBoxBatch->setEnabled(true); } } void modCalcApCoord::slotRaCheckedBatch() { if (raCheckBatch->isChecked()) raBoxBatch->setEnabled(false); else { raBoxBatch->setEnabled(true); } } void modCalcApCoord::slotDecCheckedBatch() { if (decCheckBatch->isChecked()) decBoxBatch->setEnabled(false); else { decBoxBatch->setEnabled(true); } } void modCalcApCoord::slotEpochCheckedBatch() { if (epochCheckBatch->isChecked()) epochBoxBatch->setEnabled(false); else { epochBoxBatch->setEnabled(true); } } void modCalcApCoord::slotRunBatch() { QString inputFileName = InputLineEditBatch->url().toLocalFile(); // We open the input file and read its content if (QFile::exists(inputFileName)) { QFile f(inputFileName); if (!f.open(QIODevice::ReadOnly)) { QString message = i18n("Could not open file %1.", f.fileName()); KMessageBox::sorry(nullptr, message, i18n("Could Not Open File")); inputFileName.clear(); return; } // processLines(&f); QTextStream istream(&f); processLines(istream); // readFile( istream ); f.close(); } else { QString message = i18n("Invalid file: %1", inputFileName); KMessageBox::sorry(nullptr, message, i18n("Invalid file")); inputFileName.clear(); InputLineEditBatch->setText(inputFileName); return; } } //void modCalcApCoord::processLines( const QFile * fIn ) { void modCalcApCoord::processLines(QTextStream &istream) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputLineEditBatch->text(); QFile fOut(outputFileName); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); QString line; QChar space = ' '; int i = 0; long double jd, jd0; SkyPoint sp; QTime utB; QDate dtB; dms raB, decB; QString epoch0B; while (!istream.atEnd()) { line = istream.readLine(); - line.trimmed(); + line = line.trimmed(); //Go through the line, looking for parameters QStringList fields = line.split(' '); i = 0; // Read Ut and write in ostream if corresponds if (utCheckBatch->isChecked()) { utB = QTime::fromString(fields[i]); i++; } else utB = utBoxBatch->time(); if (allRadioBatch->isChecked()) ostream << QLocale().toString(utB) << space; else if (utCheckBatch->isChecked()) ostream << QLocale().toString(utB) << space; // Read date and write in ostream if corresponds if (dateCheckBatch->isChecked()) { dtB = QDate::fromString(fields[i]); i++; } else dtB = dateBoxBatch->date(); if (allRadioBatch->isChecked()) ostream << QLocale().toString(dtB, QLocale::LongFormat).append(space); else if (dateCheckBatch->isChecked()) ostream << QLocale().toString(dtB, QLocale::LongFormat).append(space); // Read RA and write in ostream if corresponds if (raCheckBatch->isChecked()) { raB = dms::fromString(fields[i], false); i++; } else raB = raBoxBatch->createDms(false); if (allRadioBatch->isChecked()) ostream << raB.toHMSString() << space; else if (raCheckBatch->isChecked()) ostream << raB.toHMSString() << space; // Read DEC and write in ostream if corresponds if (decCheckBatch->isChecked()) { decB = dms::fromString(fields[i], true); i++; } else decB = decBoxBatch->createDms(); if (allRadioBatch->isChecked()) ostream << decB.toDMSString() << space; else if (decCheckBatch->isChecked()) ostream << decB.toHMSString() << space; // Read Epoch and write in ostream if corresponds if (epochCheckBatch->isChecked()) { epoch0B = fields[i]; i++; } else epoch0B = epochBoxBatch->text(); if (allRadioBatch->isChecked()) ostream << epoch0B; else if (decCheckBatch->isChecked()) ostream << epoch0B; KStarsDateTime dt; dt.setFromEpoch(epoch0B); jd = KStarsDateTime(dtB, utB).djd(); jd0 = dt.djd(); sp = SkyPoint(raB, decB); sp.apparentCoord(jd0, jd); ostream << sp.ra().toHMSString() << sp.dec().toDMSString() << endl; } fOut.close(); } diff --git a/kstars/tools/modcalcgalcoord.cpp b/kstars/tools/modcalcgalcoord.cpp index 98a69dd9a..7fef760d2 100644 --- a/kstars/tools/modcalcgalcoord.cpp +++ b/kstars/tools/modcalcgalcoord.cpp @@ -1,350 +1,350 @@ /*************************************************************************** modcalcgal.cpp - description ------------------- begin : Thu Jan 17 2002 copyright : (C) 2002 by Pablo de Vicente email : vicente@oan.es ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "modcalcgalcoord.h" #include "dialogs/finddialog.h" #include "skyobjects/skyobject.h" #include "skyobjects/skypoint.h" #include #include #include modCalcGalCoord::modCalcGalCoord(QWidget *parentSplit) : QFrame(parentSplit) { setupUi(this); RA->setDegType(false); connect(RA, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords())); connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords())); connect(GalLongitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords())); connect(GalLatitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords())); connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject())); connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch())); connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch())); connect(epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch())); connect(galLongCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLongCheckedBatch())); connect(galLatCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLatCheckedBatch())); connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch())); show(); } modCalcGalCoord::~modCalcGalCoord() { } void modCalcGalCoord::slotObject() { QPointer fd = new FindDialog(this); if (fd->exec() == QDialog::Accepted) { SkyObject *o = fd->targetObject(); RA->showInHours(o->ra()); Dec->showInDegrees(o->dec()); slotComputeCoords(); } delete fd; } void modCalcGalCoord::slotComputeCoords() { if (GalLongitude->hasFocus()) GalLongitude->clearFocus(); //Determine whether we should compute galactic coords from //equatorial, or vice versa if (sender()->objectName() == "GalLongitude" || sender()->objectName() == "GalLatitude") { //Validate GLong and GLat bool ok(false); dms glat; dms glong = GalLongitude->createDms(true, &ok); if (ok) glat = GalLatitude->createDms(true, &ok); if (ok) { SkyPoint sp; sp.GalacticToEquatorial1950(&glong, &glat); sp.B1950ToJ2000(); RA->showInHours(sp.ra()); Dec->showInDegrees(sp.dec()); } } else { //Validate RA and Dec bool ok(false); dms dec; dms ra = RA->createDms(false, &ok); if (ok) dec = Dec->createDms(true, &ok); if (ok) { dms glong, glat; SkyPoint sp(ra, dec); sp.J2000ToB1950(); sp.Equatorial1950ToGalactic(glong, glat); GalLongitude->showInDegrees(glong); GalLatitude->showInDegrees(glat); } } } void modCalcGalCoord::galCheck() { galLatCheckBatch->setChecked(false); galLatBoxBatch->setEnabled(false); galLongCheckBatch->setChecked(false); galLongBoxBatch->setEnabled(false); galInputCoords = false; } void modCalcGalCoord::equCheck() { raCheckBatch->setChecked(false); raBoxBatch->setEnabled(false); decCheckBatch->setChecked(false); decBoxBatch->setEnabled(false); epochCheckBatch->setChecked(false); galInputCoords = true; } void modCalcGalCoord::slotRaCheckedBatch() { if (raCheckBatch->isChecked()) { raBoxBatch->setEnabled(false); galCheck(); } else { raBoxBatch->setEnabled(true); } } void modCalcGalCoord::slotDecCheckedBatch() { if (decCheckBatch->isChecked()) { decBoxBatch->setEnabled(false); galCheck(); } else { decBoxBatch->setEnabled(true); } } void modCalcGalCoord::slotEpochCheckedBatch() { epochCheckBatch->setChecked(false); if (epochCheckBatch->isChecked()) { epochBoxBatch->setEnabled(false); galCheck(); } else { epochBoxBatch->setEnabled(true); } } void modCalcGalCoord::slotGalLatCheckedBatch() { if (galLatCheckBatch->isChecked()) { galLatBoxBatch->setEnabled(false); equCheck(); } else { galLatBoxBatch->setEnabled(true); } } void modCalcGalCoord::slotGalLongCheckedBatch() { if (galLongCheckBatch->isChecked()) { galLongBoxBatch->setEnabled(false); equCheck(); } else { galLongBoxBatch->setEnabled(true); } } void modCalcGalCoord::slotRunBatch() { const QString inputFileName = InputFileBoxBatch->url().toLocalFile(); // We open the input file and read its content if (QFile::exists(inputFileName)) { QFile f(inputFileName); if (!f.open(QIODevice::ReadOnly)) { QString message = i18n("Could not open file %1.", f.fileName()); KMessageBox::sorry(nullptr, message, i18n("Could Not Open File")); return; } // processLines(&f); QTextStream istream(&f); processLines(istream); // readFile( istream ); f.close(); } else { QString message = i18n("Invalid file: %1", inputFileName); KMessageBox::sorry(nullptr, message, i18n("Invalid file")); InputFileBoxBatch->setUrl(QUrl()); } } void modCalcGalCoord::processLines(QTextStream &istream) { // we open the output file // QTextStream istream(&fIn); const QString outputFileName = OutputFileBoxBatch->url().toLocalFile(); QFile fOut(outputFileName); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); QString line; QChar space = ' '; int i = 0; SkyPoint sp; dms raB, decB, galLatB, galLongB; QString epoch0B; while (!istream.atEnd()) { line = istream.readLine(); - line.trimmed(); + line = line.trimmed(); //Go through the line, looking for parameters QStringList fields = line.split(' '); i = 0; // Input coords are galactic coordinates: if (galInputCoords) { // Read Galactic Longitude and write in ostream if corresponds if (galLongCheckBatch->isChecked()) { galLongB = dms::fromString(fields[i], true); i++; } else galLongB = galLongBoxBatch->createDms(true); if (allRadioBatch->isChecked()) ostream << galLongB.toDMSString() << space; else if (galLongCheckBatch->isChecked()) ostream << galLongB.toDMSString() << space; // Read Galactic Latitude and write in ostream if corresponds if (galLatCheckBatch->isChecked()) { galLatB = dms::fromString(fields[i], true); i++; } else galLatB = galLatBoxBatch->createDms(true); if (allRadioBatch->isChecked()) ostream << galLatB.toDMSString() << space; else if (galLatCheckBatch->isChecked()) ostream << galLatB.toDMSString() << space; sp = SkyPoint(); sp.GalacticToEquatorial1950(&galLongB, &galLatB); ostream << sp.ra().toHMSString() << space << sp.dec().toDMSString() << epoch0B << endl; // Input coords. are equatorial coordinates: } else { // Read RA and write in ostream if corresponds if (raCheckBatch->isChecked()) { raB = dms::fromString(fields[i], false); i++; } else raB = raBoxBatch->createDms(false); if (allRadioBatch->isChecked()) ostream << raB.toHMSString() << space; else if (raCheckBatch->isChecked()) ostream << raB.toHMSString() << space; // Read DEC and write in ostream if corresponds if (decCheckBatch->isChecked()) { decB = dms::fromString(fields[i], true); i++; } else decB = decBoxBatch->createDms(); if (allRadioBatch->isChecked()) ostream << decB.toDMSString() << space; else if (decCheckBatch->isChecked()) ostream << decB.toDMSString() << space; // Read Epoch and write in ostream if corresponds if (epochCheckBatch->isChecked()) { epoch0B = fields[i]; i++; } else epoch0B = epochBoxBatch->text(); if (allRadioBatch->isChecked()) ostream << epoch0B << space; else if (epochCheckBatch->isChecked()) ostream << epoch0B << space; sp = SkyPoint(raB, decB); sp.J2000ToB1950(); sp.Equatorial1950ToGalactic(galLongB, galLatB); ostream << galLongB.toDMSString() << space << galLatB.toDMSString() << endl; } } fOut.close(); } diff --git a/kstars/tools/modcalcgeodcoord.cpp b/kstars/tools/modcalcgeodcoord.cpp index 1b4ceb892..4c17e0858 100644 --- a/kstars/tools/modcalcgeodcoord.cpp +++ b/kstars/tools/modcalcgeodcoord.cpp @@ -1,404 +1,404 @@ /*************************************************************************** modcalcgeodcoord.cpp - description ------------------- begin : Tue Jan 15 2002 copyright : (C) 2002 by Pablo de Vicente email : vicente@oan.es ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "modcalcgeodcoord.h" #include "dms.h" #include "geolocation.h" #include "kstars.h" #include "kstarsdata.h" #include #include #include modCalcGeodCoord::modCalcGeodCoord(QWidget *parentSplit) : QFrame(parentSplit) { QStringList ellipsoidList; ellipsoidList << "IAU76" << "GRS80" << "MERIT83" << "WGS84" << "IERS89"; setupUi(this); spheRadio->setChecked(true); ellipsoidBox->insertItems(5, ellipsoidList); geoPlace.reset(new GeoLocation(dms(0), dms(0))); showLongLat(); setEllipsoid(0); show(); connect(Clear, SIGNAL(clicked()), this, SLOT(slotClearGeoCoords())); connect(Compute, SIGNAL(clicked()), this, SLOT(slotComputeGeoCoords())); } void modCalcGeodCoord::showLongLat(void) { KStarsData *data = KStarsData::Instance(); LongGeoBox->show(data->geo()->lng()); LatGeoBox->show(data->geo()->lat()); AltGeoBox->setText(QString("0.0")); } void modCalcGeodCoord::setEllipsoid(int index) { geoPlace->changeEllipsoid(index); } void modCalcGeodCoord::getCartGeoCoords(void) { geoPlace->setXPos(XGeoBox->text().toDouble() * 1000.); geoPlace->setYPos(YGeoBox->text().toDouble() * 1000.); geoPlace->setZPos(ZGeoBox->text().toDouble() * 1000.); } void modCalcGeodCoord::getSphGeoCoords(void) { geoPlace->setLong(LongGeoBox->createDms()); geoPlace->setLat(LatGeoBox->createDms()); geoPlace->setElevation(AltGeoBox->text().toDouble()); } void modCalcGeodCoord::slotClearGeoCoords(void) { geoPlace->setLong(dms(0.0)); geoPlace->setLat(dms(0.0)); geoPlace->setElevation(0.0); LatGeoBox->clearFields(); LongGeoBox->clearFields(); } void modCalcGeodCoord::slotComputeGeoCoords(void) { if (cartRadio->isChecked()) { getCartGeoCoords(); showSpheGeoCoords(); } else { getSphGeoCoords(); showCartGeoCoords(); } } void modCalcGeodCoord::showSpheGeoCoords(void) { LongGeoBox->show(geoPlace->lng()); LatGeoBox->show(geoPlace->lat()); AltGeoBox->setText(QLocale().toString(geoPlace->elevation(), 3)); } void modCalcGeodCoord::showCartGeoCoords(void) { XGeoBox->setText(QLocale().toString(geoPlace->xPos() / 1000., 6)); YGeoBox->setText(QLocale().toString(geoPlace->yPos() / 1000., 6)); ZGeoBox->setText(QLocale().toString(geoPlace->zPos() / 1000., 6)); } void modCalcGeodCoord::geoCheck(void) { XGeoBoxBatch->setEnabled(false); XGeoCheckBatch->setChecked(false); YGeoBoxBatch->setEnabled(false); YGeoCheckBatch->setChecked(false); YGeoBoxBatch->setEnabled(false); YGeoCheckBatch->setChecked(false); xyzInputCoords = false; } void modCalcGeodCoord::xyzCheck(void) { LongGeoBoxBatch->setEnabled(false); LongGeoCheckBatch->setChecked(false); LatGeoBoxBatch->setEnabled(false); LatGeoCheckBatch->setChecked(false); AltGeoBoxBatch->setEnabled(false); AltGeoCheckBatch->setChecked(false); xyzInputCoords = true; } void modCalcGeodCoord::slotLongCheckedBatch() { if (LongGeoCheckBatch->isChecked()) { LongGeoBoxBatch->setEnabled(false); geoCheck(); } else { LongGeoBoxBatch->setEnabled(true); } } void modCalcGeodCoord::slotLatCheckedBatch() { if (LatGeoCheckBatch->isChecked()) { LatGeoBoxBatch->setEnabled(false); geoCheck(); } else { LatGeoBoxBatch->setEnabled(true); } } void modCalcGeodCoord::slotElevCheckedBatch() { if (AltGeoCheckBatch->isChecked()) { AltGeoBoxBatch->setEnabled(false); geoCheck(); } else { AltGeoBoxBatch->setEnabled(true); } } void modCalcGeodCoord::slotXCheckedBatch() { if (XGeoCheckBatch->isChecked()) { XGeoBoxBatch->setEnabled(false); xyzCheck(); } else { XGeoBoxBatch->setEnabled(true); } } void modCalcGeodCoord::slotYCheckedBatch() { if (YGeoCheckBatch->isChecked()) { YGeoBoxBatch->setEnabled(false); xyzCheck(); } else { YGeoBoxBatch->setEnabled(true); } } void modCalcGeodCoord::slotZCheckedBatch() { if (ZGeoCheckBatch->isChecked()) { ZGeoBoxBatch->setEnabled(false); xyzCheck(); } else { ZGeoBoxBatch->setEnabled(true); } } void modCalcGeodCoord::slotInputFile() { const QString inputFileName = QFileDialog::getOpenFileName(KStars::Instance(), QString(), QString()); if (!inputFileName.isEmpty()) InputFileBoxBatch->setUrl(QUrl::fromLocalFile(inputFileName)); } void modCalcGeodCoord::slotOutputFile() { const QString outputFileName = QFileDialog::getSaveFileName(); if (!outputFileName.isEmpty()) OutputFileBoxBatch->setUrl(QUrl::fromLocalFile(outputFileName)); } void modCalcGeodCoord::slotRunBatch(void) { const QString inputFileName = InputFileBoxBatch->url().toLocalFile(); // We open the input file and read its content if (QFile::exists(inputFileName)) { QFile f(inputFileName); if (!f.open(QIODevice::ReadOnly)) { QString message = i18n("Could not open file %1.", f.fileName()); KMessageBox::sorry(nullptr, message, i18n("Could Not Open File")); return; } // processLines(&f); QTextStream istream(&f); processLines(istream); // readFile( istream ); f.close(); } else { QString message = i18n("Invalid file: %1", inputFileName); KMessageBox::sorry(nullptr, message, i18n("Invalid file")); InputFileBoxBatch->setUrl(QUrl()); } } void modCalcGeodCoord::processLines(QTextStream &istream) { // we open the output file // QTextStream istream(&fIn); const QString outputFileName = OutputFileBoxBatch->url().toLocalFile(); QFile fOut(outputFileName); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); QString line; QChar space = ' '; int i = 0; GeoLocation geoPl(dms(0), dms(0)); geoPl.setEllipsoid(0); double xB, yB, zB, hB; dms latB, longB; while (!istream.atEnd()) { line = istream.readLine(); - line.trimmed(); + line = line.trimmed(); //Go through the line, looking for parameters QStringList fields = line.split(' '); i = 0; // Input coords are XYZ: if (xyzInputCoords) { // Read X and write in ostream if corresponds if (XGeoCheckBatch->isChecked()) { xB = fields[i].toDouble(); i++; } else xB = XGeoBoxBatch->text().toDouble(); if (AllRadioBatch->isChecked()) ostream << xB << space; else if (XGeoCheckBatch->isChecked()) ostream << xB << space; // Read Y and write in ostream if corresponds if (YGeoCheckBatch->isChecked()) { yB = fields[i].toDouble(); i++; } else yB = YGeoBoxBatch->text().toDouble(); if (AllRadioBatch->isChecked()) ostream << yB << space; else if (YGeoCheckBatch->isChecked()) ostream << yB << space; // Read Z and write in ostream if corresponds if (ZGeoCheckBatch->isChecked()) { zB = fields[i].toDouble(); i++; } else zB = ZGeoBoxBatch->text().toDouble(); if (AllRadioBatch->isChecked()) ostream << zB << space; else if (YGeoCheckBatch->isChecked()) ostream << zB << space; geoPl.setXPos(xB * 1000.0); geoPl.setYPos(yB * 1000.0); geoPl.setZPos(zB * 1000.0); ostream << geoPl.lng()->toDMSString() << space << geoPl.lat()->toDMSString() << space << geoPl.elevation() << endl; // Input coords. are Long, Lat and Height } else { // Read Longitude and write in ostream if corresponds if (LongGeoCheckBatch->isChecked()) { longB = dms::fromString(fields[i], true); i++; } else longB = LongGeoBoxBatch->createDms(true); if (AllRadioBatch->isChecked()) ostream << longB.toDMSString() << space; else if (LongGeoCheckBatch->isChecked()) ostream << longB.toDMSString() << space; // Read Latitude and write in ostream if corresponds if (LatGeoCheckBatch->isChecked()) { latB = dms::fromString(fields[i], true); i++; } else latB = LatGeoBoxBatch->createDms(true); if (AllRadioBatch->isChecked()) ostream << latB.toDMSString() << space; else if (LatGeoCheckBatch->isChecked()) ostream << latB.toDMSString() << space; // Read Height and write in ostream if corresponds if (AltGeoCheckBatch->isChecked()) { hB = fields[i].toDouble(); i++; } else hB = AltGeoBoxBatch->text().toDouble(); if (AllRadioBatch->isChecked()) ostream << hB << space; else if (AltGeoCheckBatch->isChecked()) ostream << hB << space; geoPl.setLong(longB); geoPl.setLat(latB); geoPl.setElevation(hB); ostream << geoPl.xPos() / 1000.0 << space << geoPl.yPos() / 1000.0 << space << geoPl.zPos() / 1000.0 << endl; } } fOut.close(); } diff --git a/kstars/tools/modcalcplanets.cpp b/kstars/tools/modcalcplanets.cpp index 9c4934610..1d0cf9883 100644 --- a/kstars/tools/modcalcplanets.cpp +++ b/kstars/tools/modcalcplanets.cpp @@ -1,457 +1,457 @@ /*************************************************************************** modcalcequinox.cpp - description ------------------- begin : dom may 2 2004 copyright : (C) 2004-2005 by Pablo de Vicente email : p.devicentea@wanadoo.es ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "modcalcplanets.h" #include "geolocation.h" #include "kstarsdata.h" #include "dialogs/locationdialog.h" #include "skyobjects/ksmoon.h" #include "skyobjects/kssun.h" modCalcPlanets::modCalcPlanets(QWidget *parentSplit) : QFrame(parentSplit) { setupUi(this); KStarsDateTime dt(KStarsDateTime::currentDateTime()); DateTimeBox->setDateTime(dt); DateBoxBatch->setDate(dt.date()); UTBoxBatch->setTime(dt.time()); geoPlace = KStarsData::Instance()->geo(); LocationButton->setText(geoPlace->fullName()); RABox->setDegType(false); // signals and slots connections connect(PlanetComboBox, SIGNAL(activated(int)), this, SLOT(slotComputePosition())); connect(DateTimeBox, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(slotComputePosition())); connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation())); connect(UTCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtCheckedBatch())); connect(DateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateCheckedBatch())); connect(LatCheckBatch, SIGNAL(clicked()), this, SLOT(slotLatCheckedBatch())); connect(LongCheckBatch, SIGNAL(clicked()), this, SLOT(slotLongCheckedBatch())); connect(PlanetCheckBatch, SIGNAL(clicked()), this, SLOT(slotPlanetsCheckedBatch())); slotComputePosition(); show(); } modCalcPlanets::~modCalcPlanets() { } void modCalcPlanets::slotLocation() { QPointer ld = new LocationDialog(this); if (ld->exec() == QDialog::Accepted) { geoPlace = ld->selectedCity(); LocationButton->setText(geoPlace->fullName()); slotComputePosition(); } delete ld; } void modCalcPlanets::slotComputePosition() { KStarsDateTime dt(DateTimeBox->dateTime()); long double julianDay = dt.djd(); KSNumbers num(julianDay); CachingDms LST(geoPlace->GSTtoLST(dt.gst())); // Earth KSPlanet Earth(I18N_NOOP("Earth")); Earth.findPosition(&num); // Earth is special case! if (PlanetComboBox->currentIndex() == 2) { showCoordinates(Earth); return; } // Pointer to hold planet data. Pointer is used since it has to // hold objects of different type. It's safe to use new/delete // because exceptions are disallowed. std::unique_ptr p; switch (PlanetComboBox->currentIndex()) { case 0: p.reset(new KSPlanet(KSPlanetBase::MERCURY)); break; case 1: p.reset(new KSPlanet(KSPlanetBase::VENUS)); break; case 3: p.reset(new KSPlanet(KSPlanetBase::MARS)); break; case 4: p.reset(new KSPlanet(KSPlanetBase::JUPITER)); break; case 5: p.reset(new KSPlanet(KSPlanetBase::SATURN)); break; case 6: p.reset(new KSPlanet(KSPlanetBase::URANUS)); break; case 7: p.reset(new KSPlanet(KSPlanetBase::NEPTUNE)); break; /*case 8: p.reset(new KSPluto(); break;*/ case 8: p.reset(new KSMoon()); break; case 9: p.reset(new KSSun()); p->setRsun(0.0); break; } if (p.get() == nullptr) return; // Show data. p->findPosition(&num, geoPlace->lat(), &LST, &Earth); p->EquatorialToHorizontal(&LST, geoPlace->lat()); showCoordinates(*p); } void modCalcPlanets::showCoordinates(const KSPlanetBase &ksp) { showHeliocentricEclipticCoords(ksp.helEcLong(), ksp.helEcLat(), ksp.rsun()); showGeocentricEclipticCoords(ksp.ecLong(), ksp.ecLat(), ksp.rearth()); showEquatorialCoords(ksp.ra(), ksp.dec()); showTopocentricCoords(ksp.az(), ksp.alt()); } void modCalcPlanets::showHeliocentricEclipticCoords(const dms &hLong, const dms &hLat, double dist) { HelioLongBox->show(hLong); HelioLatBox->show(hLat); HelioDistBox->setText(QLocale().toString(dist, 6)); } void modCalcPlanets::showGeocentricEclipticCoords(const dms &eLong, const dms &eLat, double dist) { GeoLongBox->show(eLong); GeoLatBox->show(eLat); GeoDistBox->setText(QLocale().toString(dist, 6)); } void modCalcPlanets::showEquatorialCoords(const dms &ra, const dms &dec) { RABox->show(ra, false); DecBox->show(dec); } void modCalcPlanets::showTopocentricCoords(const dms &az, const dms &el) { AzBox->show(az); AltBox->show(el); } void modCalcPlanets::slotPlanetsCheckedBatch() { PlanetComboBoxBatch->setEnabled(!PlanetCheckBatch->isChecked()); } void modCalcPlanets::slotUtCheckedBatch() { UTBoxBatch->setEnabled(!UTCheckBatch->isChecked()); } void modCalcPlanets::slotDateCheckedBatch() { DateBoxBatch->setEnabled(!DateCheckBatch->isChecked()); } void modCalcPlanets::slotLongCheckedBatch() { LongBoxBatch->setEnabled(!LongCheckBatch->isChecked()); } void modCalcPlanets::slotLatCheckedBatch() { LatBoxBatch->setEnabled(!LatCheckBatch->isChecked()); } void modCalcPlanets::slotRunBatch() { const QString inputFileName = InputFileBoxBatch->url().toLocalFile(); // We open the input file and read its content if (QFile::exists(inputFileName)) { QFile f(inputFileName); if (!f.open(QIODevice::ReadOnly)) { QString message = i18n("Could not open file %1.", f.fileName()); KMessageBox::sorry(nullptr, message, i18n("Could Not Open File")); return; } QTextStream istream(&f); processLines(istream); f.close(); } else { QString message = i18n("Invalid file: %1", inputFileName); KMessageBox::sorry(nullptr, message, i18n("Invalid file")); InputFileBoxBatch->setUrl(QUrl()); } } unsigned int modCalcPlanets::requiredBatchFields() { unsigned int i = 0; if (PlanetCheckBatch->isChecked()) i++; if (UTCheckBatch->isChecked()) i++; if (DateCheckBatch->isChecked()) i++; if (LongCheckBatch->isChecked()) i++; if (LatCheckBatch->isChecked()) i++; return i; } void modCalcPlanets::processLines(QTextStream &istream) { // we open the output file const QString outputFileName = OutputFileBoxBatch->url().toLocalFile(); QFile fOut(outputFileName); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); bool lineIsValid = true; QChar space = ' '; QString planetB; unsigned int i = 0, nline = 0; QTime utB; QDate dtB; CachingDms longB, latB, hlongB, hlatB, glongB, glatB, raB, decB, azmB, altB; double rSunB(0.0), rEarthB(0.0); //Initialize planet names QString pn; QStringList pNames, pNamesi18n; pNames << "Mercury" << "Venus" << "Earth" << "Mars" << "Jupiter" << "Saturn" << "Uranus" << "Neptune" /* << "Pluto" */ << "Sun" << "Moon"; pNamesi18n << i18n("Mercury") << i18n("Venus") << i18n("Earth") << i18n("Mars") << i18n("Jupiter") << i18n("Saturn") << i18n("Uranus") << i18n("Neptune") /* << i18nc("Asteroid name (optional)", "Pluto") */ << i18n("Sun") << i18n("Moon"); ///Parse the input file int numberOfRequiredFields = requiredBatchFields(); while (!istream.atEnd()) { QString lineToWrite; QString line = istream.readLine(); - line.trimmed(); + line = line.trimmed(); //Go through the line, looking for parameters QStringList fields = line.split(' '); if (fields.count() != numberOfRequiredFields) { lineIsValid = false; qWarning() << i18n("Incorrect number of fields in line %1: ", nline) << i18n("Present fields %1. ", fields.count()) << i18n("Required fields %1. ", numberOfRequiredFields) << endl; nline++; continue; } i = 0; if (PlanetCheckBatch->isChecked()) { planetB = fields[i]; int j = pNamesi18n.indexOf(planetB); if (j == -1) { qWarning() << i18n("Unknown planet ") << fields[i] << i18n(" in line %1: ", nline) << endl; continue; } pn = pNames.at(j); //untranslated planet name i++; } else { planetB = PlanetComboBoxBatch->currentText(); } if (AllRadioBatch->isChecked() || PlanetCheckBatch->isChecked()) { lineToWrite = planetB; lineToWrite += space; } // Read Ut and write in ostream if corresponds if (UTCheckBatch->isChecked()) { utB = QTime::fromString(fields[i]); if (!utB.isValid()) { qWarning() << i18n("Line %1 contains an invalid time", nline); lineIsValid = false; nline++; continue; } i++; } else { utB = UTBoxBatch->time(); } if (AllRadioBatch->isChecked() || UTCheckBatch->isChecked()) lineToWrite += QLocale().toString(utB).append(space); // Read date and write in ostream if corresponds if (DateCheckBatch->isChecked()) { dtB = QDate::fromString(fields[i], Qt::ISODate); if (!dtB.isValid()) { qWarning() << i18n("Line %1 contains an invalid date: ", nline) << fields[i] << endl; lineIsValid = false; nline++; continue; } i++; } else { dtB = DateBoxBatch->date(); } if (AllRadioBatch->isChecked() || DateCheckBatch->isChecked()) lineToWrite += QLocale().toString(dtB, QLocale::LongFormat).append(space); // Read Longitude and write in ostream if corresponds if (LongCheckBatch->isChecked()) { longB = CachingDms::fromString(fields[i], true); i++; } else { longB = LongBoxBatch->createDms(true); } if (AllRadioBatch->isChecked() || LongCheckBatch->isChecked()) lineToWrite += longB.toDMSString() + space; // Read Latitude if (LatCheckBatch->isChecked()) { latB = CachingDms::fromString(fields[i], true); i++; } else { latB = LatBoxBatch->createDms(true); } if (AllRadioBatch->isChecked() || LatCheckBatch->isChecked()) lineToWrite += latB.toDMSString() + space; KStarsDateTime edt(dtB, utB); CachingDms LST = edt.gst() + longB; KSNumbers num(edt.djd()); KSPlanet Earth(I18N_NOOP("Earth")); Earth.findPosition(&num); // FIXME: allocate new object for every iteration is probably not wisest idea. KSPlanetBase *kspb = nullptr; /*if ( pn == "Pluto" ) { kspb = new KSPluto(); } else*/ if (pn == "Sun") { kspb = new KSSun(); } else if (pn == "Moon") { kspb = new KSMoon(); } else { kspb = new KSPlanet(i18n(pn.toLocal8Bit()), QString(), Qt::white, 1.0); } kspb->findPosition(&num, &latB, &LST, &Earth); kspb->EquatorialToHorizontal(&LST, &latB); // Heliocentric Ecl. coords. hlongB = kspb->helEcLong(); hlatB = kspb->helEcLat(); rSunB = kspb->rsun(); // Geocentric Ecl. coords. glongB = kspb->ecLong(); glatB = kspb->ecLat(); rEarthB = kspb->rearth(); // Equatorial coords. decB = kspb->dec(); raB = kspb->ra(); // Topocentric Coords. azmB = kspb->az(); altB = kspb->alt(); ostream << lineToWrite; if (HelioEclCheckBatch->isChecked()) ostream << hlongB.toDMSString() << space << hlatB.toDMSString() << space << rSunB << space; if (GeoEclCheckBatch->isChecked()) ostream << glongB.toDMSString() << space << glatB.toDMSString() << space << rEarthB << space; if (EquatorialCheckBatch->isChecked()) ostream << raB.toHMSString() << space << decB.toDMSString() << space; if (HorizontalCheckBatch->isChecked()) ostream << azmB.toDMSString() << space << altB.toDMSString() << space; ostream << endl; // Delete object delete kspb; nline++; } if (!lineIsValid) { QString message = i18n("Errors found while parsing some lines in the input file"); KMessageBox::sorry(nullptr, message, i18n("Errors in lines")); } fOut.close(); } diff --git a/kstars/tools/modcalcvlsr.cpp b/kstars/tools/modcalcvlsr.cpp index c6542fa63..6c3666976 100644 --- a/kstars/tools/modcalcvlsr.cpp +++ b/kstars/tools/modcalcvlsr.cpp @@ -1,514 +1,514 @@ /*************************************************************************** modcalcvlsr.cpp - description ------------------- begin : sun mar 13 2005 copyright : (C) 2005 by Pablo de Vicente email : p.devicente@wanadoo.es ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "modcalcvlsr.h" #include #include #include #include #include "ksnumbers.h" #include "dms.h" #include "skyobjects/skypoint.h" #include "geolocation.h" #include "kstars.h" #include "kstarsdata.h" #include "kstarsdatetime.h" #include "widgets/dmsbox.h" #include "dialogs/locationdialog.h" #include "dialogs/finddialog.h" modCalcVlsr::modCalcVlsr(QWidget *parentSplit) : QFrame(parentSplit), velocityFlag(0) { setupUi(this); RA->setDegType(false); Date->setDateTime(KStarsDateTime::currentDateTime()); initGeo(); VLSR->setValidator(new QDoubleValidator(VLSR)); VHelio->setValidator(new QDoubleValidator(VHelio)); VGeo->setValidator(new QDoubleValidator(VGeo)); VTopo->setValidator(new QDoubleValidator(VTopo)); // signals and slots connections connect(Date, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(slotCompute())); connect(NowButton, SIGNAL(clicked()), this, SLOT(slotNow())); connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation())); connect(ObjectButton, SIGNAL(clicked()), this, SLOT(slotFindObject())); connect(RA, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(Dec, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(VLSR, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(VHelio, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(VGeo, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(VTopo, SIGNAL(editingFinished()), this, SLOT(slotCompute())); connect(RunButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch())); show(); } modCalcVlsr::~modCalcVlsr() { } void modCalcVlsr::initGeo(void) { geoPlace = KStarsData::Instance()->geo(); LocationButton->setText(geoPlace->fullName()); } void modCalcVlsr::slotNow() { Date->setDateTime(KStarsDateTime::currentDateTime()); slotCompute(); } void modCalcVlsr::slotFindObject() { QPointer fd = new FindDialog(KStars::Instance()); if (fd->exec() == QDialog::Accepted) { SkyObject *o = fd->targetObject(); RA->showInHours(o->ra0()); Dec->showInDegrees(o->dec0()); } delete fd; } void modCalcVlsr::slotLocation() { QPointer ld(new LocationDialog(this)); if (ld->exec() == QDialog::Accepted && ld) { GeoLocation *newGeo = ld->selectedCity(); if (newGeo) { geoPlace = newGeo; LocationButton->setText(geoPlace->fullName()); } } delete ld; slotCompute(); } void modCalcVlsr::slotCompute() { bool ok1(false), ok2(false); SkyPoint sp(RA->createDms(false, &ok1), Dec->createDms(true, &ok2)); if (!ok1 || !ok2) return; KStarsDateTime dt(Date->dateTime()); double vst[3]; geoPlace->TopocentricVelocity(vst, dt.gst()); if (sender()->objectName() == "VLSR") velocityFlag = 0; if (sender()->objectName() == "VHelio") velocityFlag = 1; if (sender()->objectName() == "VGeo") velocityFlag = 2; if (sender()->objectName() == "VTopo") velocityFlag = 3; switch (velocityFlag) { case 0: //Hold VLSR constant, compute the others { double vlsr = VLSR->text().toDouble(); double vhelio = sp.vHeliocentric(vlsr, dt.djd()); double vgeo = sp.vGeocentric(vhelio, dt.djd()); VHelio->setText(QString::number(vhelio)); VGeo->setText(QString::number(vgeo)); VTopo->setText(QString::number(sp.vTopocentric(vgeo, vst))); break; } case 1: //Hold VHelio constant, compute the others { double vhelio = VHelio->text().toDouble(); double vlsr = sp.vHelioToVlsr(vhelio, dt.djd()); double vgeo = sp.vGeocentric(vhelio, dt.djd()); VLSR->setText(QString::number(vlsr)); VGeo->setText(QString::number(vgeo)); VTopo->setText(QString::number(sp.vTopocentric(vgeo, vst))); break; } case 2: //Hold VGeo constant, compute the others { double vgeo = VGeo->text().toDouble(); double vhelio = sp.vGeoToVHelio(vgeo, dt.djd()); double vlsr = sp.vHelioToVlsr(vhelio, dt.djd()); VLSR->setText(QString::number(vlsr)); VHelio->setText(QString::number(vhelio)); VTopo->setText(QString::number(sp.vTopocentric(vgeo, vst))); break; } case 3: //Hold VTopo constant, compute the others { double vtopo = VTopo->text().toDouble(); double vgeo = sp.vTopoToVGeo(vtopo, vst); double vhelio = sp.vGeoToVHelio(vgeo, dt.djd()); double vlsr = sp.vHelioToVlsr(vhelio, dt.djd()); VLSR->setText(QString::number(vlsr)); VHelio->setText(QString::number(vhelio)); VGeo->setText(QString::number(vgeo)); break; } default: //oops qDebug() << "Error: do not know which velocity to use for input."; break; } } void modCalcVlsr::slotUtChecked() { if (UTCheckBatch->isChecked()) UTBoxBatch->setEnabled(false); else { UTBoxBatch->setEnabled(true); } } void modCalcVlsr::slotDateChecked() { if (DateCheckBatch->isChecked()) DateBoxBatch->setEnabled(false); else { DateBoxBatch->setEnabled(true); } } void modCalcVlsr::slotRaChecked() { if (RACheckBatch->isChecked()) { RABoxBatch->setEnabled(false); } else { RABoxBatch->setEnabled(true); } } void modCalcVlsr::slotDecChecked() { if (DecCheckBatch->isChecked()) { DecBoxBatch->setEnabled(false); } else { DecBoxBatch->setEnabled(true); } } void modCalcVlsr::slotEpochChecked() { if (EpochCheckBatch->isChecked()) EpochBoxBatch->setEnabled(false); else EpochBoxBatch->setEnabled(true); } void modCalcVlsr::slotLongChecked() { if (LongCheckBatch->isChecked()) LongitudeBoxBatch->setEnabled(false); else LongitudeBoxBatch->setEnabled(true); } void modCalcVlsr::slotLatChecked() { if (LatCheckBatch->isChecked()) LatitudeBoxBatch->setEnabled(false); else { LatitudeBoxBatch->setEnabled(true); } } void modCalcVlsr::slotHeightChecked() { if (ElevationCheckBatch->isChecked()) ElevationBoxBatch->setEnabled(false); else { ElevationBoxBatch->setEnabled(true); } } void modCalcVlsr::slotVlsrChecked() { if (InputVelocityCheckBatch->isChecked()) InputVelocityBoxBatch->setEnabled(false); else { InputVelocityBoxBatch->setEnabled(true); } } void modCalcVlsr::slotInputFile() { const QString inputFileName = QFileDialog::getOpenFileName(KStars::Instance(), QString(), QString()); if (!inputFileName.isEmpty()) InputFileBoxBatch->setUrl(QUrl::fromLocalFile(inputFileName)); } void modCalcVlsr::slotOutputFile() { const QString outputFileName = QFileDialog::getSaveFileName(); if (!outputFileName.isEmpty()) OutputFileBoxBatch->setUrl(QUrl::fromLocalFile(outputFileName)); } void modCalcVlsr::slotRunBatch() { const QString inputFileName = InputFileBoxBatch->url().toLocalFile(); // We open the input file and read its content if (QFile::exists(inputFileName)) { QFile f(inputFileName); if (!f.open(QIODevice::ReadOnly)) { QString message = i18n("Could not open file %1.", f.fileName()); KMessageBox::sorry(nullptr, message, i18n("Could Not Open File")); return; } // processLines(&f); QTextStream istream(&f); processLines(istream); // readFile( istream ); f.close(); } else { QString message = i18n("Invalid file: %1", inputFileName); KMessageBox::sorry(nullptr, message, i18n("Invalid file")); InputFileBoxBatch->setUrl(QUrl()); } } void modCalcVlsr::processLines(QTextStream &istream) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputFileBoxBatch->url().toLocalFile(); QFile fOut(outputFileName); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); QString line; QChar space = ' '; int i = 0; long double jd0; SkyPoint spB; double sra, cra, sdc, cdc; dms raB, decB, latB, longB; QString epoch0B; double vhB, vgB, vtB, vlsrB, heightB; double vtopo[3]; QTime utB; QDate dtB; KStarsDateTime dt0B; while (!istream.atEnd()) { line = istream.readLine(); - line.trimmed(); + line = line.trimmed(); //Go through the line, looking for parameters QStringList fields = line.split(' '); i = 0; // Read Ut and write in ostream if corresponds if (UTCheckBatch->isChecked()) { utB = QTime::fromString(fields[i]); i++; } else utB = UTBoxBatch->time(); if (AllRadioBatch->isChecked()) ostream << QLocale().toString(utB) << space; else if (UTCheckBatch->isChecked()) ostream << QLocale().toString(utB) << space; // Read date and write in ostream if corresponds if (DateCheckBatch->isChecked()) { dtB = QDate::fromString(fields[i]); i++; } else dtB = DateBoxBatch->date(); if (AllRadioBatch->isChecked()) ostream << QLocale().toString(dtB, QLocale::LongFormat).append(space); else if (DateCheckBatch->isChecked()) ostream << QLocale().toString(dtB, QLocale::LongFormat).append(space); // Read RA and write in ostream if corresponds if (RACheckBatch->isChecked()) { raB = dms::fromString(fields[i], false); i++; } else raB = RABoxBatch->createDms(false); if (AllRadioBatch->isChecked()) ostream << raB.toHMSString() << space; else if (RACheckBatch->isChecked()) ostream << raB.toHMSString() << space; // Read DEC and write in ostream if corresponds if (DecCheckBatch->isChecked()) { decB = dms::fromString(fields[i], true); i++; } else decB = DecBoxBatch->createDms(); if (AllRadioBatch->isChecked()) ostream << decB.toDMSString() << space; else if (DecCheckBatch->isChecked()) ostream << decB.toDMSString() << space; // Read Epoch and write in ostream if corresponds if (EpochCheckBatch->isChecked()) { epoch0B = fields[i]; i++; } else epoch0B = EpochBoxBatch->text(); if (AllRadioBatch->isChecked()) ostream << epoch0B << space; else if (EpochCheckBatch->isChecked()) ostream << epoch0B << space; // Read vlsr and write in ostream if corresponds if (InputVelocityCheckBatch->isChecked()) { vlsrB = fields[i].toDouble(); i++; } else vlsrB = InputVelocityComboBatch->currentText().toDouble(); if (AllRadioBatch->isChecked()) ostream << vlsrB << space; else if (InputVelocityCheckBatch->isChecked()) ostream << vlsrB << space; // Read Longitude and write in ostream if corresponds if (LongCheckBatch->isChecked()) { longB = dms::fromString(fields[i], true); i++; } else longB = LongitudeBoxBatch->createDms(true); if (AllRadioBatch->isChecked()) ostream << longB.toDMSString() << space; else if (LongCheckBatch->isChecked()) ostream << longB.toDMSString() << space; // Read Latitude if (LatCheckBatch->isChecked()) { latB = dms::fromString(fields[i], true); i++; } else latB = LatitudeBoxBatch->createDms(true); if (AllRadioBatch->isChecked()) ostream << latB.toDMSString() << space; else if (LatCheckBatch->isChecked()) ostream << latB.toDMSString() << space; // Read height and write in ostream if corresponds if (ElevationCheckBatch->isChecked()) { heightB = fields[i].toDouble(); i++; } else heightB = ElevationBoxBatch->text().toDouble(); if (AllRadioBatch->isChecked()) ostream << heightB << space; else if (ElevationCheckBatch->isChecked()) ostream << heightB << space; // We make the first calculations spB = SkyPoint(raB, decB); dt0B.setFromEpoch(epoch0B); vhB = spB.vHeliocentric(vlsrB, dt0B.djd()); jd0 = KStarsDateTime(dtB, utB).djd(); vgB = spB.vGeocentric(vlsrB, jd0); geoPlace->setLong(longB); geoPlace->setLat(latB); geoPlace->setElevation(heightB); dms gsidt = KStarsDateTime(dtB, utB).gst(); geoPlace->TopocentricVelocity(vtopo, gsidt); spB.ra().SinCos(sra, cra); spB.dec().SinCos(sdc, cdc); vtB = vgB - (vtopo[0] * cdc * cra + vtopo[1] * cdc * sra + vtopo[2] * sdc); ostream << vhB << space << vgB << space << vtB << endl; } fOut.close(); }