22 #include <kmessagebox.h>
45 connect( Location, SIGNAL( clicked() ),
this, SLOT(
slotLocation() ) );
48 connect( InputFileBatch, SIGNAL(urlSelected(
const KUrl&)),
this, SLOT(
slotCheckFiles()) );
49 connect( OutputFileBatch, SIGNAL(urlSelected(
const KUrl&)),
this, SLOT(
slotCheckFiles()) );
50 connect( RunButtonBatch, SIGNAL(clicked()),
this, SLOT(
slotRunBatch()) );
51 connect( ViewButtonBatch, SIGNAL(clicked()),
this, SLOT(
slotViewBatch()) );
53 RunButtonBatch->setEnabled(
false );
54 ViewButtonBatch->setEnabled(
false );
61 void modCalcDayLength::showCurrentDate (
void)
64 Date->setDate( dt.date() );
67 void modCalcDayLength::initGeo(
void)
70 geoPlace = data->
geo();
71 geoBatch = data->
geo();
72 Location->setText( geoPlace->
fullName() );
73 LocationBatch->setText( geoBatch->
fullName() );
76 QTime modCalcDayLength::lengthOfDay(QTime setQTime, QTime riseQTime){
78 int dds = riseQTime.secsTo(setQTime);
79 QTime dLength = dL.addSecs( dds );
86 if ( ld->exec() == QDialog::Accepted ) {
90 Location->setText( geoPlace->
fullName() );
100 if ( ld->exec() == QDialog::Accepted ) {
104 LocationBatch->setText( geoBatch->
fullName() );
110 void modCalcDayLength::updateAlmanac(
const QDate &
d,
GeoLocation *geo ) {
128 if ( ssTime.isValid() ) {
129 ssAzString = ssAz.toDMSString();
130 stAltString = stAlt.toDMSString();
131 srAzString = srAz.toDMSString();
133 ssTimeString = KGlobal::locale()->formatTime( ssTime );
134 srTimeString = KGlobal::locale()->formatTime( srTime );
135 stTimeString = KGlobal::locale()->formatTime( stTime );
137 QTime daylength = lengthOfDay(ssTime,srTime);
138 daylengthString = KGlobal::locale()->formatTime( daylength,
false,
true );
141 }
else if ( stAlt.
Degrees() > 0. ) {
142 ssAzString = i18n(
"Circumpolar");
143 stAltString = stAlt.toDMSString();
144 srAzString = i18n(
"Circumpolar");
146 ssTimeString =
"--:--";
147 srTimeString =
"--:--";
148 stTimeString = KGlobal::locale()->formatTime( stTime );
149 daylengthString =
"24:00";
151 }
else if (stAlt.
Degrees() < 0. ) {
152 ssAzString = i18n(
"Does not rise");
153 stAltString = stAlt.toDMSString();
154 srAzString = i18n(
"Does not set");
156 ssTimeString =
"--:--";
157 srTimeString =
"--:--";
158 stTimeString = KGlobal::locale()->formatTime( stTime );
159 daylengthString =
"00:00";
167 QTime msTime = Moon.
riseSetTime( jd0 , geo,
false );
168 QTime mrTime = Moon.
riseSetTime( jd0 , geo,
true );
176 if ( msTime.isValid() ) {
177 msAzString = msAz.toDMSString();
178 mtAltString = mtAlt.toDMSString();
179 mrAzString = mrAz.toDMSString();
181 msTimeString = KGlobal::locale()->formatTime( msTime );
182 mrTimeString = KGlobal::locale()->formatTime( mrTime );
183 mtTimeString = KGlobal::locale()->formatTime( mtTime );
186 }
else if ( mtAlt.
Degrees() > 0. ) {
187 msAzString = i18n(
"Circumpolar");
188 mtAltString = mtAlt.toDMSString();
189 mrAzString = i18n(
"Circumpolar");
191 msTimeString =
"--:--";
192 mrTimeString =
"--:--";
193 mtTimeString = KGlobal::locale()->formatTime( mtTime );
195 }
else if ( mtAlt.
Degrees() < 0. ) {
196 msAzString = i18n(
"Does not rise");
197 mtAltString = mtAlt.toDMSString();
198 mrAzString = i18n(
"Does not rise");
200 msTimeString =
"--:--";
201 mrTimeString =
"--:--";
202 mtTimeString = KGlobal::locale()->formatTime( mtTime );
205 lunarphaseString = Moon.
phaseName()+
" ("+QString::number(
int( 100*Moon.
illum() ) )+
"%)";
208 if ( srAz.
Degrees() < 100.0 ) srAzString =
' '+srAzString;
209 if ( ssAz.
Degrees() < 100.0 ) ssAzString =
' '+ssAzString;
210 if ( mrAz.
Degrees() < 100.0 ) mrAzString =
' '+mrAzString;
211 if ( msAz.
Degrees() < 100.0 ) msAzString =
' '+msAzString;
215 updateAlmanac( Date->date(), geoPlace );
217 SunSet->setText( ssTimeString );
218 SunRise->setText( srTimeString );
219 SunTransit->setText( stTimeString );
220 SunSetAz->setText( ssAzString );
221 SunRiseAz->setText( srAzString );
222 SunTransitAlt->setText( stAltString );
223 DayLength->setText( daylengthString );
225 MoonSet->setText( msTimeString );
226 MoonRise->setText( mrTimeString );
227 MoonTransit->setText( mtTimeString );
228 MoonSetAz->setText( msAzString );
229 MoonRiseAz->setText( mrAzString );
230 MoonTransitAlt->setText( mtAltString );
231 LunarPhase->setText( lunarphaseString );
235 bool flag = !InputFileBatch->lineEdit()->text().isEmpty() && !OutputFileBatch->lineEdit()->text().isEmpty();
236 RunButtonBatch->setEnabled( flag );
240 QString inputFileName = InputFileBatch->url().toLocalFile();
242 if ( QFile::exists(inputFileName) ) {
243 QFile
f( inputFileName );
244 if ( !f.open( QIODevice::ReadOnly) ) {
245 QString message = i18n(
"Could not open file %1.", f.fileName() );
246 KMessageBox::sorry( 0, message, i18n(
"Could Not Open File" ) );
251 processLines( istream );
252 ViewButtonBatch->setEnabled(
true );
256 QString message = i18n(
"Invalid file: %1", inputFileName );
257 KMessageBox::sorry( 0, message, i18n(
"Invalid file" ) );
262 void modCalcDayLength::processLines(
QTextStream &istream ) {
263 QFile fOut( OutputFileBatch->url().toLocalFile() );
264 fOut.open(QIODevice::WriteOnly);
268 ostream <<
"# " <<
i18nc(
"%1 is a location on earth",
"Almanac for %1", geoBatch->
fullName())
269 << QString(
" [%1, %2]").arg(geoBatch->
lng()->toDMSString()).arg(geoBatch->
lat()->toDMSString()) << endl
270 <<
"# " << i18n(
"computed by KStars") << endl
272 <<
"# Date SRise STran SSet SRiseAz STranAlt SSetAz DayLen MRise MTran MSet MRiseAz MTranAlt MSetAz LunarPhase" << endl
278 while ( ! istream.atEnd() ) {
279 line = istream.readLine();
280 line = line.trimmed();
283 d = QDate::fromString( line );
285 updateAlmanac( d, geoBatch );
286 ostream << d.toString( Qt::ISODate ) <<
" "
287 << srTimeString <<
" " << stTimeString <<
" " << ssTimeString <<
" "
288 << srAzString <<
" " << stAltString <<
" " << ssAzString <<
" "
289 << daylengthString <<
" "
290 << mrTimeString <<
" " << mtTimeString <<
" " << msTimeString <<
" "
291 << mrAzString <<
" " << mtAltString <<
" " << msAzString <<
" "
292 << lunarphaseString << endl;
298 QFile fOut( OutputFileBatch->url().toLocalFile() );
299 fOut.open(QIODevice::ReadOnly);
303 while ( ! istream.atEnd() )
304 text.append( istream.readLine() );
308 KMessageBox::informationList( 0, i18n(
"Results of Almanac calculation"), text, OutputFileBatch->url().toLocalFile() );
311 #include "modcalcdaylength.moc"
~modCalcDayLength()
Destructor.
dms riseSetTimeAz(const KStarsDateTime &dt, const GeoLocation *geo, bool rst)
dms transitAltitude(const KStarsDateTime &dt, const GeoLocation *geo)
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.
KStarsData is the backbone of KStars.
Child class of KSPlanetBase; encapsulates information about the Sun.
void slotComputeAlmanac()
static KStarsData * Instance()
const double & Degrees() const
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true)
Determine the time at which the point will rise or set.
QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo)
The same iteration technique described in riseSetTime() is used here.
virtual void findPhase(const KSSun *Sun=0)
Determine the phase angle of the moon, and assign the appropriate moon image.
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
i18nc("string from libindi, used in the config dialog","100x")
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.
QString phaseName() const
modCalcDayLength(QWidget *p)
Constructor.
There are several time-dependent values used in position calculations, that are not specific to an ob...
A subclass of SkyObject that provides information needed for the Moon.