22 #include <kfiledialog.h>
23 #include <kmessagebox.h>
43 DateTimeBox->setDateTime( dt.dateTime() );
44 DateBoxBatch->setDate( dt.date() );
45 UTBoxBatch->setTime( dt.time() );
48 LocationButton->setText( geoPlace->
fullName() );
50 RABox->setDegType(
false);
54 connect(DateTimeBox, SIGNAL(dateTimeChanged( QDateTime )),
this, SLOT(
slotComputePosition()));
55 connect(LocationButton, SIGNAL(clicked()),
this, SLOT(
slotLocation()));
74 if ( ld->exec() == QDialog::Accepted ) {
75 geoPlace = ld->selectedCity();
76 LocationButton->setText( geoPlace->
fullName() );
85 long double julianDay = dt.
djd();
90 KSPlanet Earth( I18N_NOOP(
"Earth" ));
94 if( PlanetComboBox->currentIndex() == 2 ) {
95 showCoordinates( Earth );
104 switch( PlanetComboBox->currentIndex() ) {
132 showCoordinates( *p );
137 void modCalcPlanets::showCoordinates(
const KSPlanetBase &ksp)
141 showEquatorialCoords(ksp.
ra(), ksp.
dec() );
142 showTopocentricCoords(ksp.
az(), ksp.
alt() );
145 void modCalcPlanets::showHeliocentricEclipticCoords(
const dms& hLong,
const dms& hLat,
double dist)
147 HelioLongBox->show( hLong );
148 HelioLatBox->show( hLat );
149 HelioDistBox->setText( KGlobal::locale()->formatNumber( dist,6));
152 void modCalcPlanets::showGeocentricEclipticCoords(
const dms& eLong,
const dms& eLat,
double dist)
154 GeoLongBox->show( eLong );
155 GeoLatBox->show( eLat );
156 GeoDistBox->setText( KGlobal::locale()->formatNumber( dist,6));
159 void modCalcPlanets::showEquatorialCoords(
const dms& ra,
const dms& dec)
161 RABox->show( ra,
false );
165 void modCalcPlanets::showTopocentricCoords(
const dms& az,
const dms& el)
173 PlanetComboBoxBatch->setEnabled( ! PlanetCheckBatch->isChecked() );
178 UTBoxBatch->setEnabled( ! UTCheckBatch->isChecked() );
183 DateBoxBatch->setEnabled( ! DateCheckBatch->isChecked() );
188 LongBoxBatch->setEnabled( ! LongCheckBatch->isChecked() );
193 LatBoxBatch->setEnabled( ! LatCheckBatch->isChecked() );
198 QString inputFileName;
200 inputFileName = InputFileBoxBatch->url().toLocalFile();
204 if ( QFile::exists(inputFileName) ) {
205 QFile
f( inputFileName );
206 if ( !f.open( QIODevice::ReadOnly) ) {
207 QString message = i18n(
"Could not open file %1.", f.fileName() );
208 KMessageBox::sorry( 0, message, i18n(
"Could Not Open File" ) );
209 inputFileName.clear();
217 QString message = i18n(
"Invalid file: %1", inputFileName );
218 KMessageBox::sorry( 0, message, i18n(
"Invalid file" ) );
219 inputFileName.clear();
220 InputFileBoxBatch->setUrl( inputFileName );
225 unsigned int modCalcPlanets::requiredBatchFields() {
228 if(PlanetCheckBatch->isChecked() )
230 if(UTCheckBatch->isChecked() )
232 if(DateCheckBatch->isChecked() )
234 if (LongCheckBatch->isChecked() )
236 if (LatCheckBatch->isChecked() )
246 QString outputFileName;
247 outputFileName = OutputFileBoxBatch->url().toLocalFile();
248 QFile fOut( outputFileName );
249 fOut.open(QIODevice::WriteOnly);
251 bool lineIsValid =
true;
256 unsigned int i = 0, nline = 0;
259 dms longB, latB, hlongB, hlatB, glongB, glatB, raB, decB, azmB, altB;
260 double rSunB(0.0), rEarthB(0.0);
264 QStringList pNames, pNamesi18n;
265 pNames <<
"Mercury" <<
"Venus" <<
"Earth" <<
"Mars" <<
"Jupiter"
266 <<
"Saturn" <<
"Uranus" <<
"Neptune" <<
"Pluto"
268 pNamesi18n << i18n(
"Mercury") << i18n(
"Venus") << i18n(
"Earth")
269 << i18n(
"Mars") << i18n(
"Jupiter") << i18n(
"Saturn")
270 << i18n(
"Uranus") << i18n(
"Neptune") << i18n(
"Pluto")
271 << i18n(
"Sun") << i18n(
"Moon");
274 int numberOfRequiredFields = requiredBatchFields();
275 while ( ! istream.atEnd() ) {
277 QString line = istream.readLine();
282 QStringList fields = line.split(
' ' );
284 if (fields.count() != numberOfRequiredFields ) {
286 kWarning() << i18n(
"Incorrect number of fields in line %1: " , nline)
287 << i18n(
"Present fields %1. " , fields.count())
288 << i18n(
"Required fields %1. " , numberOfRequiredFields) << endl;
294 if(PlanetCheckBatch->isChecked() ) {
296 int j = pNamesi18n.indexOf( planetB );
298 kWarning() << i18n(
"Unknown planet ")
300 << i18n(
" in line %1: ", nline) << endl;
306 planetB = PlanetComboBoxBatch->currentText( );
308 if ( AllRadioBatch->isChecked() || PlanetCheckBatch->isChecked() ) {
309 lineToWrite = planetB;
310 lineToWrite += space;
314 if(UTCheckBatch->isChecked() ) {
315 utB = QTime::fromString( fields[i] );
316 if ( !utB.isValid() ) {
317 kWarning() << i18n(
"Line %1 contains an invalid time" , nline) ;
324 utB = UTBoxBatch->time();
326 if ( AllRadioBatch->isChecked() || UTCheckBatch->isChecked() )
327 lineToWrite += KGlobal::locale()->formatTime( utB,
true ).append(space);
330 if(DateCheckBatch->isChecked() ) {
331 dtB = QDate::fromString( fields[i], Qt::ISODate );
332 if ( !dtB.isValid() ) {
333 kWarning() << i18n(
"Line %1 contains an invalid date: " , nline) <<
341 dtB = DateBoxBatch->date();
343 if ( AllRadioBatch->isChecked() || DateCheckBatch->isChecked() )
344 lineToWrite += KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
349 if (LongCheckBatch->isChecked() ) {
350 longB = dms::fromString( fields[i],
true);
353 longB = LongBoxBatch->createDms(
true);
355 if ( AllRadioBatch->isChecked() || LongCheckBatch->isChecked() )
356 lineToWrite += longB.toDMSString() + space;
359 if (LatCheckBatch->isChecked() ) {
360 latB = dms::fromString( fields[i],
true);
363 latB = LatBoxBatch->createDms(
true);
365 if ( AllRadioBatch->isChecked() || LatCheckBatch->isChecked() )
366 lineToWrite += latB.toDMSString() + space;
370 dms LST = edt.
gst() + longB;
373 KSPlanet Earth( I18N_NOOP(
"Earth" ));
374 Earth.findPosition( &num );
378 if ( pn ==
"Pluto" ) {
380 }
else if ( pn ==
"Sun" ) {
382 }
else if ( pn ==
"Moon" ) {
385 kspb =
new KSPlanet(i18n( pn.toLocal8Bit() ), QString(), Qt::white, 1.0 );
393 rSunB = kspb->
rsun();
396 glatB = kspb->
ecLat();
405 ostream << lineToWrite;
407 if ( HelioEclCheckBatch->isChecked() )
408 ostream << hlongB.toDMSString() << space << hlatB.toDMSString() << space << rSunB << space ;
409 if ( GeoEclCheckBatch->isChecked() )
410 ostream << glongB.toDMSString() << space << glatB.toDMSString() << space << rEarthB << space ;
411 if ( EquatorialCheckBatch->isChecked() )
412 ostream << raB.toHMSString() << space << decB.toDMSString() << space ;
413 if ( HorizontalCheckBatch->isChecked() )
414 ostream << azmB.toDMSString() << space << altB.toDMSString() << space ;
424 QString message = i18n(
"Errors found while parsing some lines in the input file");
425 KMessageBox::sorry( 0, message, i18n(
"Errors in lines" ) );
431 #include "modcalcplanets.moc"
void findPosition(const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth=0)
Find position, including correction for Figure-of-the-Earth.
Dialog for changing the geographic location of the observer.
modCalcPlanets(QWidget *p)
void slotDateCheckedBatch()
void processLines(QTextStream &istream)
A subclass of KSPlanetBase for seven of the major planets in the solar system (Earth and Pluto have t...
Child class of KSPlanetBase; encapsulates information about the Sun.
void slotLatCheckedBatch()
const dms & helEcLat() const
static KStarsData * Instance()
void setRsun(double r)
Set the solar distance in AU.
void slotPlanetsCheckedBatch()
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
dms GSTtoLST(const dms &gst) const
void slotComputePosition()
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
An angle, stored as degrees, but expressible in many ways.
void slotLongCheckedBatch()
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
const dms & ecLat() const
const dms & helEcLong() const
There are several time-dependent values used in position calculations, that are not specific to an ob...
const dms & ecLong() const
A subclass of SkyObject that provides information needed for the Moon.
void slotUtCheckedBatch()
A subclass of TrailObject that provides additional information needed for most solar system objects...
A subclass of KSAsteroid that represents the planet Pluto.