• 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
modcalcapcoord.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalcapcoord.cpp - description
3  -------------------
4  begin : Wed Apr 10 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 "modcalcapcoord.h"
19 
20 #include <QTextStream>
21 
22 #include <KGlobal>
23 #include <KLocale>
24 #include <kfiledialog.h>
25 #include <kmessagebox.h>
26 
27 #include "kstars.h"
28 #include "dms.h"
29 #include "skyobjects/skypoint.h"
30 #include "kstarsdatetime.h"
31 #include "dialogs/finddialog.h"
32 #include "widgets/dmsbox.h"
33 
34 modCalcApCoord::modCalcApCoord(QWidget *parentSplit)
35  : QFrame(parentSplit) {
36 
37  setupUi(this);
38  showCurrentTime();
39  RACat->setDegType(false);
40  DecCat->setDegType(true);
41 
42  connect( ObjectButton, SIGNAL( clicked() ), this, SLOT( slotObject() ) );
43  connect( NowButton, SIGNAL( clicked() ), this, SLOT( showCurrentTime() ) );
44  connect( RACat, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
45  connect( DecCat, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
46  connect( UT, SIGNAL( timeChanged( const QTime & ) ), this, SLOT( slotCompute() ) );
47  connect( Date, SIGNAL( dateChanged( const QDate & ) ), this, SLOT( slotCompute() ) );
48 
49  connect( utCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtCheckedBatch()) );
50  connect( dateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateCheckedBatch()) );
51  connect( raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()) );
52  connect( decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()) );
53  connect( epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()) );
54  connect( runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()) );
55 
56  show();
57 }
58 
59 modCalcApCoord::~modCalcApCoord(){
60 }
61 
62 void modCalcApCoord::showCurrentTime (void)
63 {
64  KStarsDateTime dt( KStarsDateTime::currentDateTime() );
65  Date->setDate( dt.date() );
66  UT->setTime( dt.time() );
67  EpochTarget->setText( QString::number( dt.epoch(), 'f', 3 ) );
68 }
69 
70 void modCalcApCoord::slotCompute(){
71  KStarsDateTime dt( Date->date(), UT->time() );
72  long double jd = dt.djd();
73 
74  dt.setFromEpoch( EpochCat->value() );
75  long double jd0 = dt.djd();
76 
77  SkyPoint sp( RACat->createDms(false), DecCat->createDms() );
78  sp.apparentCoord(jd0, jd);
79 
80  RA->setText( sp.ra().toHMSString() );
81  Dec->setText( sp.dec().toDMSString() );
82 }
83 
84 void modCalcApCoord::slotObject() {
85  QPointer<FindDialog> fd = new FindDialog( this );
86  if ( fd->exec() == QDialog::Accepted ) {
87  SkyObject *o = fd->selectedObject();
88  RACat->showInHours( o->ra0() );
89  DecCat->showInDegrees( o->dec0() );
90  EpochCat->setValue( 2000.0 );
91 
92  slotCompute();
93  }
94  delete fd;
95 }
96 
97 void modCalcApCoord::slotUtCheckedBatch(){
98  if ( utCheckBatch->isChecked() )
99  utBoxBatch->setEnabled( false );
100  else {
101  utBoxBatch->setEnabled( true );
102  }
103 }
104 
105 void modCalcApCoord::slotDateCheckedBatch(){
106 
107  if ( dateCheckBatch->isChecked() )
108  dateBoxBatch->setEnabled( false );
109  else {
110  dateBoxBatch->setEnabled( true );
111  }
112 }
113 
114 void modCalcApCoord::slotRaCheckedBatch(){
115 
116  if ( raCheckBatch->isChecked() )
117  raBoxBatch->setEnabled( false );
118  else {
119  raBoxBatch->setEnabled( true );
120  }
121 }
122 
123 void modCalcApCoord::slotDecCheckedBatch(){
124 
125  if ( decCheckBatch->isChecked() )
126  decBoxBatch->setEnabled( false );
127  else {
128  decBoxBatch->setEnabled( true );
129  }
130 }
131 
132 void modCalcApCoord::slotEpochCheckedBatch(){
133 
134  if ( epochCheckBatch->isChecked() )
135  epochBoxBatch->setEnabled( false );
136  else {
137  epochBoxBatch->setEnabled( true );
138  }
139 }
140 
141 void modCalcApCoord::slotRunBatch() {
142 
143  QString inputFileName = InputLineEditBatch->url().toLocalFile();
144 
145  // We open the input file and read its content
146 
147  if ( QFile::exists(inputFileName) ) {
148  QFile f( inputFileName );
149  if ( !f.open( QIODevice::ReadOnly) ) {
150  QString message = i18n( "Could not open file %1.", f.fileName() );
151  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
152  inputFileName.clear();
153  return;
154  }
155 
156  // processLines(&f);
157  QTextStream istream(&f);
158  processLines(istream);
159  // readFile( istream );
160  f.close();
161  } else {
162  QString message = i18n( "Invalid file: %1", inputFileName );
163  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
164  inputFileName.clear();
165  InputLineEditBatch->setText( inputFileName );
166  return;
167  }
168 }
169 
170 //void modCalcApCoord::processLines( const QFile * fIn ) {
171 void modCalcApCoord::processLines( QTextStream &istream ) {
172 
173  // we open the output file
174 
175  // QTextStream istream(&fIn);
176  QString outputFileName;
177  outputFileName = OutputLineEditBatch->text();
178  QFile fOut( outputFileName );
179  fOut.open(QIODevice::WriteOnly);
180  QTextStream ostream(&fOut);
181 
182  QString line;
183  QChar space = ' ';
184  int i = 0;
185  long double jd, jd0;
186  SkyPoint sp;
187  QTime utB;
188  QDate dtB;
189  dms raB, decB;
190  QString epoch0B;
191 
192  while ( ! istream.atEnd() ) {
193  line = istream.readLine();
194  line.trimmed();
195 
196  //Go through the line, looking for parameters
197 
198  QStringList fields = line.split( ' ' );
199 
200  i = 0;
201 
202  // Read Ut and write in ostream if corresponds
203 
204  if(utCheckBatch->isChecked() ) {
205  utB = QTime::fromString( fields[i] );
206  i++;
207  } else
208  utB = utBoxBatch->time();
209 
210  if ( allRadioBatch->isChecked() )
211  ostream << KGlobal::locale()->formatTime( utB ) << space;
212  else
213  if(utCheckBatch->isChecked() )
214  ostream << KGlobal::locale()->formatTime( utB ) << space;
215 
216  // Read date and write in ostream if corresponds
217 
218  if(dateCheckBatch->isChecked() ) {
219  dtB = QDate::fromString( fields[i] );
220  i++;
221  } else
222  dtB = dateBoxBatch->date();
223 
224  if ( allRadioBatch->isChecked() )
225  ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
226  else
227  if(dateCheckBatch->isChecked() )
228  ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space);
229 
230  // Read RA and write in ostream if corresponds
231 
232  if(raCheckBatch->isChecked() ) {
233  raB = dms::fromString( fields[i],false);
234  i++;
235  } else
236  raB = raBoxBatch->createDms(false);
237 
238  if ( allRadioBatch->isChecked() )
239  ostream << raB.toHMSString() << space;
240  else
241  if(raCheckBatch->isChecked() )
242  ostream << raB.toHMSString() << space;
243 
244  // Read DEC and write in ostream if corresponds
245 
246  if(decCheckBatch->isChecked() ) {
247  decB = dms::fromString( fields[i], true);
248  i++;
249  } else
250  decB = decBoxBatch->createDms();
251 
252  if ( allRadioBatch->isChecked() )
253  ostream << decB.toDMSString() << space;
254  else
255  if(decCheckBatch->isChecked() )
256  ostream << decB.toHMSString() << space;
257 
258  // Read Epoch and write in ostream if corresponds
259 
260  if(epochCheckBatch->isChecked() ) {
261  epoch0B = fields[i];
262  i++;
263  } else
264  epoch0B = epochBoxBatch->text();
265 
266  if ( allRadioBatch->isChecked() )
267  ostream << epoch0B;
268  else
269  if(decCheckBatch->isChecked() )
270  ostream << epoch0B;
271 
272  KStarsDateTime dt;
273  dt.setFromEpoch( epoch0B );
274  jd = KStarsDateTime(dtB,utB).djd();
275  jd0 = dt.djd();
276  sp = SkyPoint (raB, decB);
277  sp.apparentCoord(jd0, jd);
278 
279  ostream << sp.ra().toHMSString() << sp.dec().toDMSString() << endl;
280  }
281 
282  fOut.close();
283 }
284 
285 #include "modcalcapcoord.moc"
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
SkyPoint::dec0
const dms & dec0() const
Definition: skypoint.h:168
SkyPoint::apparentCoord
void apparentCoord(long double jd0, long double jdf)
Computes the apparent coordinates for this SkyPoint for any epoch, accounting for the effects of prec...
Definition: skypoint.cpp:433
modCalcApCoord::~modCalcApCoord
~modCalcApCoord()
Destructor.
Definition: modcalcapcoord.cpp:59
modCalcApCoord::processLines
void processLines(QTextStream &istream)
Process Lines.
Definition: modcalcapcoord.cpp:171
modcalcapcoord.h
QWidget
SkyPoint::ra0
const dms & ra0() const
Definition: skypoint.h:165
KStarsDateTime::setFromEpoch
bool setFromEpoch(double e)
Set the Date/Time from an epoch value, represented as a double.
Definition: kstarsdatetime.cpp:195
dms.h
NaN::f
const float f
Definition: nan.h:36
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
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
KStarsDateTime
Extension of KDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day...
Definition: kstarsdatetime.h:45
FindDialog
Dialog window for finding SkyObjects by name.
Definition: finddialog.h:47
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
skypoint.h
QTextStream
modCalcApCoord::modCalcApCoord
modCalcApCoord(QWidget *p)
Constructor.
Definition: modcalcapcoord.cpp:34
finddialog.h
kstarsdatetime.h
dmsbox.h
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
QFrame
kstars.h
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