• 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
modcalcdaylength.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalcdaylength.cpp - description
3  -------------------
4  begin : wed jun 12 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 "modcalcdaylength.h"
19 
20 #include <KGlobal>
21 #include <KLocale>
22 #include <kmessagebox.h>
23 #include <KLineEdit>
24 
25 #include "skyobjects/skyobject.h"
26 #include "geolocation.h"
27 #include "kstarsdata.h"
28 #include "skyobjects/kssun.h"
29 #include "skyobjects/ksmoon.h"
30 #include "ksnumbers.h"
31 #include "kstarsdatetime.h"
32 #include "dialogs/locationdialog.h"
33 
34 
35 modCalcDayLength::modCalcDayLength(QWidget *parentSplit) :
36  QFrame(parentSplit)
37 {
38  setupUi(this);
39 
40  showCurrentDate();
41  initGeo();
42  slotComputeAlmanac();
43 
44  connect( Date, SIGNAL(dateChanged(const QDate&)), this, SLOT(slotComputeAlmanac() ) );
45  connect( Location, SIGNAL( clicked() ), this, SLOT( slotLocation() ) );
46 
47  connect( LocationBatch, SIGNAL( clicked() ), this, SLOT( slotLocationBatch() ) );
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()) );
52 
53  RunButtonBatch->setEnabled( false );
54  ViewButtonBatch->setEnabled( false );
55 
56  show();
57 }
58 
59 modCalcDayLength::~modCalcDayLength() {}
60 
61 void modCalcDayLength::showCurrentDate (void)
62 {
63  KStarsDateTime dt( KStarsDateTime::currentDateTime() );
64  Date->setDate( dt.date() );
65 }
66 
67 void modCalcDayLength::initGeo(void)
68 {
69  KStarsData *data = KStarsData::Instance();
70  geoPlace = data->geo();
71  geoBatch = data->geo();
72  Location->setText( geoPlace->fullName() );
73  LocationBatch->setText( geoBatch->fullName() );
74 }
75 
76 QTime modCalcDayLength::lengthOfDay(QTime setQTime, QTime riseQTime){
77  QTime dL(0,0,0);
78  int dds = riseQTime.secsTo(setQTime);
79  QTime dLength = dL.addSecs( dds );
80 
81  return dLength;
82 }
83 
84 void modCalcDayLength::slotLocation() {
85  QPointer<LocationDialog> ld = new LocationDialog( this );
86  if ( ld->exec() == QDialog::Accepted ) {
87  GeoLocation *newGeo = ld->selectedCity();
88  if ( newGeo ) {
89  geoPlace = newGeo;
90  Location->setText( geoPlace->fullName() );
91  }
92  }
93  delete ld;
94 
95  slotComputeAlmanac();
96 }
97 
98 void modCalcDayLength::slotLocationBatch() {
99  QPointer<LocationDialog> ld = new LocationDialog( this );
100  if ( ld->exec() == QDialog::Accepted ) {
101  GeoLocation *newGeo = ld->selectedCity();
102  if ( newGeo ) {
103  geoBatch = newGeo;
104  LocationBatch->setText( geoBatch->fullName() );
105  }
106  }
107  delete ld;
108 }
109 
110 void modCalcDayLength::updateAlmanac( const QDate &d, GeoLocation *geo ) {
111  //Determine values needed for the Almanac
112  long double jd0 = KStarsDateTime(d, QTime(8,0,0)).djd();
113  KSNumbers num(jd0);
114 
115  //Sun
116  KSSun Sun;
117  Sun.findPosition(&num);
118 
119  QTime ssTime = Sun.riseSetTime(jd0 , geo, false );
120  QTime srTime = Sun.riseSetTime(jd0 , geo, true );
121  QTime stTime = Sun.transitTime(jd0 , geo);
122 
123  dms ssAz = Sun.riseSetTimeAz(jd0, geo, false);
124  dms srAz = Sun.riseSetTimeAz(jd0, geo, true);
125  dms stAlt = Sun.transitAltitude(jd0, geo);
126 
127  //In most cases, the Sun will rise and set:
128  if ( ssTime.isValid() ) {
129  ssAzString = ssAz.toDMSString();
130  stAltString = stAlt.toDMSString();
131  srAzString = srAz.toDMSString();
132 
133  ssTimeString = KGlobal::locale()->formatTime( ssTime );
134  srTimeString = KGlobal::locale()->formatTime( srTime );
135  stTimeString = KGlobal::locale()->formatTime( stTime );
136 
137  QTime daylength = lengthOfDay(ssTime,srTime);
138  daylengthString = KGlobal::locale()->formatTime( daylength, false, true );
139 
140  //...but not always!
141  } else if ( stAlt.Degrees() > 0. ) {
142  ssAzString = i18n("Circumpolar");
143  stAltString = stAlt.toDMSString();
144  srAzString = i18n("Circumpolar");
145 
146  ssTimeString = "--:--";
147  srTimeString = "--:--";
148  stTimeString = KGlobal::locale()->formatTime( stTime );
149  daylengthString = "24:00";
150 
151  } else if (stAlt.Degrees() < 0. ) {
152  ssAzString = i18n("Does not rise");
153  stAltString = stAlt.toDMSString();
154  srAzString = i18n("Does not set");
155 
156  ssTimeString = "--:--";
157  srTimeString = "--:--";
158  stTimeString = KGlobal::locale()->formatTime( stTime );
159  daylengthString = "00:00";
160  }
161 
162  //Moon
163  KSMoon Moon;
164  Moon.findPosition(&num);
165  Moon.findPhase();
166 
167  QTime msTime = Moon.riseSetTime( jd0 , geo, false );
168  QTime mrTime = Moon.riseSetTime( jd0 , geo, true );
169  QTime mtTime = Moon.transitTime(jd0 , geo);
170 
171  dms msAz = Moon.riseSetTimeAz(jd0, geo, false);
172  dms mrAz = Moon.riseSetTimeAz(jd0, geo, true);
173  dms mtAlt = Moon.transitAltitude(jd0, geo);
174 
175  //In most cases, the Moon will rise and set:
176  if ( msTime.isValid() ) {
177  msAzString = msAz.toDMSString();
178  mtAltString = mtAlt.toDMSString();
179  mrAzString = mrAz.toDMSString();
180 
181  msTimeString = KGlobal::locale()->formatTime( msTime );
182  mrTimeString = KGlobal::locale()->formatTime( mrTime );
183  mtTimeString = KGlobal::locale()->formatTime( mtTime );
184 
185  //...but not always!
186  } else if ( mtAlt.Degrees() > 0. ) {
187  msAzString = i18n("Circumpolar");
188  mtAltString = mtAlt.toDMSString();
189  mrAzString = i18n("Circumpolar");
190 
191  msTimeString = "--:--";
192  mrTimeString = "--:--";
193  mtTimeString = KGlobal::locale()->formatTime( mtTime );
194 
195  } else if ( mtAlt.Degrees() < 0. ) {
196  msAzString = i18n("Does not rise");
197  mtAltString = mtAlt.toDMSString();
198  mrAzString = i18n("Does not rise");
199 
200  msTimeString = "--:--";
201  mrTimeString = "--:--";
202  mtTimeString = KGlobal::locale()->formatTime( mtTime );
203  }
204 
205  lunarphaseString = Moon.phaseName()+" ("+QString::number( int( 100*Moon.illum() ) )+"%)";
206 
207  //Fix length of Az strings
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;
212 }
213 
214 void modCalcDayLength::slotComputeAlmanac() {
215  updateAlmanac( Date->date(), geoPlace );
216 
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 );
224 
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 );
232 }
233 
234 void modCalcDayLength::slotCheckFiles() {
235  bool flag = !InputFileBatch->lineEdit()->text().isEmpty() && !OutputFileBatch->lineEdit()->text().isEmpty();
236  RunButtonBatch->setEnabled( flag );
237 }
238 
239 void modCalcDayLength::slotRunBatch() {
240  QString inputFileName = InputFileBatch->url().toLocalFile();
241 
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" ) );
247  return;
248  }
249 
250  QTextStream istream(&f);
251  processLines( istream );
252  ViewButtonBatch->setEnabled( true );
253 
254  f.close();
255  } else {
256  QString message = i18n( "Invalid file: %1", inputFileName );
257  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
258  return;
259  }
260 }
261 
262 void modCalcDayLength::processLines( QTextStream &istream ) {
263  QFile fOut( OutputFileBatch->url().toLocalFile() );
264  fOut.open(QIODevice::WriteOnly);
265  QTextStream ostream(&fOut);
266 
267  //Write header
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
271  << "#" << endl
272  << "# Date SRise STran SSet SRiseAz STranAlt SSetAz DayLen MRise MTran MSet MRiseAz MTranAlt MSetAz LunarPhase" << endl
273  << "#" << endl;
274 
275  QString line;
276  QDate d;
277 
278  while ( ! istream.atEnd() ) {
279  line = istream.readLine();
280  line = line.trimmed();
281 
282  //Parse the line as a date, then compute Almanac values
283  d = QDate::fromString( line );
284  if ( d.isValid() ) {
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;
293  }
294  }
295 }
296 
297 void modCalcDayLength::slotViewBatch() {
298  QFile fOut( OutputFileBatch->url().toLocalFile() );
299  fOut.open(QIODevice::ReadOnly);
300  QTextStream istream(&fOut);
301  QStringList text;
302 
303  while ( ! istream.atEnd() )
304  text.append( istream.readLine() );
305 
306  fOut.close();
307 
308  KMessageBox::informationList( 0, i18n("Results of Almanac calculation"), text, OutputFileBatch->url().toLocalFile() );
309 }
310 
311 #include "modcalcdaylength.moc"
modCalcDayLength::~modCalcDayLength
~modCalcDayLength()
Destructor.
Definition: modcalcdaylength.cpp:59
SkyObject::riseSetTimeAz
dms riseSetTimeAz(const KStarsDateTime &dt, const GeoLocation *geo, bool rst)
Definition: skyobject.cpp:192
SkyObject::transitAltitude
dms transitAltitude(const KStarsDateTime &dt, const GeoLocation *geo)
Definition: skyobject.cpp:245
KSPlanetBase::findPosition
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.
Definition: ksplanetbase.cpp:122
KSMoon::illum
double illum() const
Definition: ksmoon.h:58
LocationDialog
Dialog for changing the geographic location of the observer.
Definition: locationdialog.h:57
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
KSSun
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition: kssun.h:31
skyobject.h
modCalcDayLength::slotComputeAlmanac
void slotComputeAlmanac()
Definition: modcalcdaylength.cpp:214
QWidget
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
SkyObject::riseSetTime
QTime riseSetTime(const KStarsDateTime &dt, const GeoLocation *geo, bool rst, bool exact=true)
Determine the time at which the point will rise or set.
Definition: skyobject.cpp:105
GeoLocation::lng
const dms * lng() const
Definition: geolocation.h:76
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
SkyObject::transitTime
QTime transitTime(const KStarsDateTime &dt, const GeoLocation *geo)
The same iteration technique described in riseSetTime() is used here.
Definition: skyobject.cpp:241
KSMoon::findPhase
virtual void findPhase(const KSSun *Sun=0)
Determine the phase angle of the moon, and assign the appropriate moon image.
Definition: ksmoon.cpp:243
geolocation.h
NaN::f
const float f
Definition: nan.h:36
locationdialog.h
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
KStarsDateTime::currentDateTime
static KStarsDateTime currentDateTime(KDateTime::Spec ts=KDateTime::Spec::ClockTime())
Definition: kstarsdatetime.cpp:67
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
i18nc
i18nc("string from libindi, used in the config dialog","100x")
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
ksnumbers.h
modCalcDayLength::slotViewBatch
void slotViewBatch()
Definition: modcalcdaylength.cpp:297
modCalcDayLength::slotLocationBatch
void slotLocationBatch()
Definition: modcalcdaylength.cpp:98
modcalcdaylength.h
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
KSMoon::phaseName
QString phaseName() const
Definition: ksmoon.cpp:256
modCalcDayLength::modCalcDayLength
modCalcDayLength(QWidget *p)
Constructor.
Definition: modcalcdaylength.cpp:35
QTextStream
KSNumbers
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition: ksnumbers.h:43
modCalcDayLength::slotCheckFiles
void slotCheckFiles()
Definition: modcalcdaylength.cpp:234
kssun.h
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
KSMoon
A subclass of SkyObject that provides information needed for the Moon.
Definition: ksmoon.h:36
NaN::d
const double d
Definition: nan.h:35
NaN::ld
const long double ld
Definition: nan.h:37
ksmoon.h
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
kstarsdatetime.h
kstarsdata.h
modCalcDayLength::slotLocation
void slotLocation()
Definition: modcalcdaylength.cpp:84
QFrame
modCalcDayLength::slotRunBatch
void slotRunBatch()
Definition: modcalcdaylength.cpp:239
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