22 #include <KPlotWidget>
24 #include <KPlotObject>
28 #include <kmessagebox.h>
39 QFrame(parentSplit), dSpring(), dSummer(), dAutumn(), dWinter()
43 connect( Year, SIGNAL( valueChanged(
int) ),
this, SLOT( slotCompute() ) );
44 connect( InputFileBatch, SIGNAL(urlSelected(
const KUrl&)),
this, SLOT(slotCheckFiles()) );
45 connect( OutputFileBatch, SIGNAL(urlSelected(
const KUrl&)),
this, SLOT(slotCheckFiles()) );
46 connect( RunButtonBatch, SIGNAL(clicked()),
this, SLOT(slotRunBatch()));
47 connect( ViewButtonBatch, SIGNAL(clicked()),
this, SLOT(slotViewBatch()));
49 Plot->axis(KPlotWidget::LeftAxis)->setLabel( i18n(
"Sun's Declination") );
50 Plot->setTopPadding( 40 );
52 Plot->axis(KPlotWidget::BottomAxis)->setVisible(
false );
53 Plot->axis(KPlotWidget::TopAxis)->setVisible(
false );
58 RunButtonBatch->setEnabled(
false );
59 ViewButtonBatch->setEnabled(
false );
68 Q_ASSERT( i>=0 && i<12 &&
"Month must be in 0 .. 11 range");
72 void modCalcEquinox::slotCheckFiles() {
73 RunButtonBatch->setEnabled(
74 !InputFileBatch->lineEdit()->text().isEmpty() && !OutputFileBatch->lineEdit()->text().isEmpty()
78 void modCalcEquinox::slotRunBatch() {
79 QString inputFileName = InputFileBatch->url().toLocalFile();
81 if ( QFile::exists(inputFileName) ) {
82 QFile
f( inputFileName );
83 if ( !
f.open( QIODevice::ReadOnly) ) {
84 QString message = i18n(
"Could not open file %1.",
f.fileName() );
85 KMessageBox::sorry( 0, message, i18n(
"Could Not Open File" ) );
86 inputFileName.clear();
91 processLines( istream );
93 ViewButtonBatch->setEnabled(
true );
97 QString message = i18n(
"Invalid file: %1", inputFileName );
98 KMessageBox::sorry( 0, message, i18n(
"Invalid file" ) );
99 inputFileName.clear();
104 void modCalcEquinox::processLines(
QTextStream &istream ) {
105 QFile fOut( OutputFileBatch->url().toLocalFile() );
106 fOut.open(QIODevice::WriteOnly);
108 int originalYear = Year->value();
111 ostream << i18n(
"# Timing of Equinoxes and Solstices\n")
112 << i18n(
"# computed by KStars\n#\n")
113 << i18n(
"# Vernal Equinox\t\tSummer Solstice\t\t\tAutumnal Equinox\t\tWinter Solstice\n#\n");
115 while ( ! istream.atEnd() ) {
116 QString line = istream.readLine();
118 int year = line.toInt( &ok );
124 Year->setValue( year );
128 KGlobal::locale()->formatDate( dSpring.date(), KLocale::LongDate ) <<
"\t"
129 << KGlobal::locale()->formatDate( dSummer.date(), KLocale::LongDate ) <<
"\t"
130 << KGlobal::locale()->formatDate( dAutumn.date(), KLocale::LongDate ) <<
"\t"
131 << KGlobal::locale()->formatDate( dWinter.date(), KLocale::LongDate ) << endl;
135 if ( Year->value() != originalYear )
136 Year->setValue( originalYear );
139 void modCalcEquinox::slotViewBatch() {
140 QFile fOut( OutputFileBatch->url().toLocalFile() );
141 fOut.open(QIODevice::ReadOnly);
145 while ( ! istream.atEnd() )
146 text.append( istream.readLine() );
150 KMessageBox::informationList( 0, i18n(
"Results of Sidereal time calculation"), text, OutputFileBatch->url().toLocalFile() );
153 void modCalcEquinox::slotCompute()
157 int year0 = Year->value();
160 long double jd0 = dt.djd();
161 for (
int imonth=0; imonth < 12; imonth++ ) {
163 DMonth[imonth] = kdt.djd() - jd0;
166 Plot->removeAllPlotObjects();
169 KPlotObject *ce =
new KPlotObject( data->
colorScheme()->
colorNamed(
"EqColor" ), KPlotObject::Lines, 2.0 );
170 ce->addPoint( 0.0, 0.0 );
171 ce->addPoint( 366.0, 0.0 );
172 Plot->addPlotObject( ce );
177 KPlotObject *ecl =
new KPlotObject( data->
colorScheme()->
colorNamed(
"EclColor" ), KPlotObject::Lines, 2 );
178 ecl->setLinePen( QPen( ecl->pen().color(), 4 ) );
180 Plot->setLimits( 1.0,
double(dt.date().daysInYear()), -30.0, 30.0 );
185 for (
int i=1; i<=dt.date().daysInYear(); i++ ) {
188 ecl->addPoint(
double(i), Sun.
dec().
Degrees() );
190 dt = dt.addDays( 1 );
192 Plot->addPlotObject( ecl );
194 dSpring = findEquinox( Year->value(),
true, ecl );
195 dSummer = findSolstice( Year->value(), true );
196 dAutumn = findEquinox( Year->value(),
false, ecl );
197 dWinter = findSolstice( Year->value(), false );
200 VEquinox->setText( KGlobal::locale()->formatDateTime( dSpring, KLocale::LongDate ) );
201 SSolstice->setText( KGlobal::locale()->formatDateTime( dSummer, KLocale::LongDate ) );
202 AEquinox->setText( KGlobal::locale()->formatDateTime( dAutumn, KLocale::LongDate ) );
203 WSolstice->setText( KGlobal::locale()->formatDateTime( dWinter, KLocale::LongDate ) );
206 KPlotObject *poSpring =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
207 poSpring->setLinePen( QPen( Qt::white, 1.0, Qt::DotLine ) );
208 poSpring->addPoint( dSpring.djd()-jd0, Plot->dataRect().top() );
209 poSpring->addPoint( dSpring.djd()-jd0, Plot->dataRect().bottom() );
210 Plot->addPlotObject( poSpring );
211 KPlotObject *poSummer =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
212 poSummer->setLinePen( QPen( Qt::white, 1.0, Qt::DotLine ) );
213 poSummer->addPoint( dSummer.djd()-jd0, Plot->dataRect().top() );
214 poSummer->addPoint( dSummer.djd()-jd0, Plot->dataRect().bottom() );
215 Plot->addPlotObject( poSummer );
216 KPlotObject *poAutumn =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
217 poAutumn->setLinePen( QPen( Qt::white, 1.0, Qt::DotLine ) );
218 poAutumn->addPoint( dAutumn.djd()-jd0, Plot->dataRect().top() );
219 poAutumn->addPoint( dAutumn.djd()-jd0, Plot->dataRect().bottom() );
220 Plot->addPlotObject( poAutumn );
221 KPlotObject *poWinter =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
222 poWinter->setLinePen( QPen( Qt::white, 1.0, Qt::DotLine ) );
223 poWinter->addPoint( dWinter.djd()-jd0, Plot->dataRect().top() );
224 poWinter->addPoint( dWinter.djd()-jd0, Plot->dataRect().bottom() );
225 Plot->addPlotObject( poWinter );
229 void modCalcEquinox::addDateAxes() {
230 KPlotObject *poTopAxis =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
231 poTopAxis->addPoint( 0.0, Plot->dataRect().bottom() );
232 poTopAxis->addPoint( 366.0, Plot->dataRect().bottom() );
233 Plot->addPlotObject( poTopAxis );
235 KPlotObject *poBottomAxis =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
236 poBottomAxis->addPoint( 0.0, Plot->dataRect().top() + 0.02 );
237 poBottomAxis->addPoint( 366.0, Plot->dataRect().top() + 0.02 );
238 Plot->addPlotObject( poBottomAxis );
241 for (
int imonth=0; imonth<12; imonth++ ) {
242 KPlotObject *poMonth =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
243 poMonth->addPoint( dmonth(imonth), Plot->dataRect().top() );
244 poMonth->addPoint( dmonth(imonth), Plot->dataRect().top() + 1.4 );
245 Plot->addPlotObject( poMonth );
246 poMonth =
new KPlotObject( Qt::white, KPlotObject::Lines, 1 );
247 poMonth->addPoint( dmonth(imonth), Plot->dataRect().bottom() );
248 poMonth->addPoint( dmonth(imonth), Plot->dataRect().bottom() - 1.4 );
249 Plot->addPlotObject( poMonth );
253 KStarsDateTime modCalcEquinox::findEquinox(
int year,
bool Spring, KPlotObject *ecl ) {
257 const int month = Spring ? 2 : 8;
258 int i = QDate( year, month, 1 ).dayOfYear();
260 dec2 = ecl->points()[i]->y();
264 dec2 = ecl->points()[i]->y();
265 }
while ( dec1*dec2 > 0.0 );
267 double x1 = ecl->points()[i-1]->x();
268 double x2 = ecl->points()[i]->x();
269 double d = fabs(dec2 - dec1);
270 double f = 1.0 - fabs(dec2)/
d;
277 KStarsDateTime modCalcEquinox::findSolstice(
int year,
bool Summer ) {
282 long double jd1,jd2,jd3,jd4;
283 double y2(0.0),y3(0.0), y4(0.0);
285 if ( ! Summer ) month = 12;
294 if ( ! Summer ) sgn = -1;
298 num.updateValues( jd3 );
303 }
while ( y3*sgn > y2*sgn );
312 num.updateValues( jd2 );
316 while ( jd3 - jd1 > 0.0005 ) {
317 jd4 = jd1 + jd3 - jd2;
319 num.updateValues( jd4 );
323 if ( y4*sgn > y2*sgn ) {
347 #include "modcalcvizequinox.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.
modCalcEquinox(QWidget *p)
KStarsData is the backbone of KStars.
Child class of KSPlanetBase; encapsulates information about the Sun.
ColorScheme * colorScheme()
static KStarsData * Instance()
const double & Degrees() const
QColor colorNamed(const QString &name) const
Retrieve a color by name.
KStarsDateTime addSecs(double s) const
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
double dmonth(int imonth)
There are several time-dependent values used in position calculations, that are not specific to an ob...