PageRenderTime 51ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/kstars/tools/modcalcapcoord.cpp

https://gitlab.com/g10h4ck/kstars
C++ | 283 lines | 197 code | 59 blank | 27 comment | 31 complexity | 6f93d92345983e5acf2f2bc9faf90f9d MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0
  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. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "modcalcapcoord.h"
  17. #include <QTextStream>
  18. #include <QFileDialog>
  19. #include <KLocalizedString>
  20. #include <KMessageBox>
  21. #include "kstars.h"
  22. #include "dms.h"
  23. #include "skyobjects/skypoint.h"
  24. #include "kstarsdatetime.h"
  25. #include "dialogs/finddialog.h"
  26. #include "widgets/dmsbox.h"
  27. modCalcApCoord::modCalcApCoord(QWidget *parentSplit)
  28. : QFrame(parentSplit) {
  29. setupUi(this);
  30. showCurrentTime();
  31. RACat->setDegType(false);
  32. DecCat->setDegType(true);
  33. connect( ObjectButton, SIGNAL( clicked() ), this, SLOT( slotObject() ) );
  34. connect( NowButton, SIGNAL( clicked() ), this, SLOT( showCurrentTime() ) );
  35. connect( RACat, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
  36. connect( DecCat, SIGNAL( editingFinished() ), this, SLOT( slotCompute() ) );
  37. connect( UT, SIGNAL( timeChanged( const QTime & ) ), this, SLOT( slotCompute() ) );
  38. connect( Date, SIGNAL( dateChanged( const QDate & ) ), this, SLOT( slotCompute() ) );
  39. connect( utCheckBatch, SIGNAL(clicked()), this, SLOT(slotUtCheckedBatch()) );
  40. connect( dateCheckBatch, SIGNAL(clicked()), this, SLOT(slotDateCheckedBatch()) );
  41. connect( raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()) );
  42. connect( decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()) );
  43. connect( epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()) );
  44. connect( runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()) );
  45. show();
  46. }
  47. modCalcApCoord::~modCalcApCoord(){
  48. }
  49. void modCalcApCoord::showCurrentTime (void)
  50. {
  51. KStarsDateTime dt( KStarsDateTime::currentDateTime() );
  52. Date->setDate( dt.date() );
  53. UT->setTime( dt.time() );
  54. EpochTarget->setText( QString::number( dt.epoch(), 'f', 3 ) );
  55. }
  56. void modCalcApCoord::slotCompute(){
  57. KStarsDateTime dt( Date->date(), UT->time() );
  58. long double jd = dt.djd();
  59. dt.setFromEpoch( EpochCat->value() );
  60. long double jd0 = dt.djd();
  61. SkyPoint sp( RACat->createDms(false), DecCat->createDms() );
  62. sp.apparentCoord(jd0, jd);
  63. RA->setText( sp.ra().toHMSString() );
  64. Dec->setText( sp.dec().toDMSString() );
  65. }
  66. void modCalcApCoord::slotObject() {
  67. QPointer<FindDialog> fd = new FindDialog( this );
  68. if ( fd->exec() == QDialog::Accepted ) {
  69. SkyObject *o = fd->selectedObject();
  70. RACat->showInHours( o->ra0() );
  71. DecCat->showInDegrees( o->dec0() );
  72. EpochCat->setValue( 2000.0 );
  73. slotCompute();
  74. }
  75. delete fd;
  76. }
  77. void modCalcApCoord::slotUtCheckedBatch(){
  78. if ( utCheckBatch->isChecked() )
  79. utBoxBatch->setEnabled( false );
  80. else {
  81. utBoxBatch->setEnabled( true );
  82. }
  83. }
  84. void modCalcApCoord::slotDateCheckedBatch(){
  85. if ( dateCheckBatch->isChecked() )
  86. dateBoxBatch->setEnabled( false );
  87. else {
  88. dateBoxBatch->setEnabled( true );
  89. }
  90. }
  91. void modCalcApCoord::slotRaCheckedBatch(){
  92. if ( raCheckBatch->isChecked() )
  93. raBoxBatch->setEnabled( false );
  94. else {
  95. raBoxBatch->setEnabled( true );
  96. }
  97. }
  98. void modCalcApCoord::slotDecCheckedBatch(){
  99. if ( decCheckBatch->isChecked() )
  100. decBoxBatch->setEnabled( false );
  101. else {
  102. decBoxBatch->setEnabled( true );
  103. }
  104. }
  105. void modCalcApCoord::slotEpochCheckedBatch(){
  106. if ( epochCheckBatch->isChecked() )
  107. epochBoxBatch->setEnabled( false );
  108. else {
  109. epochBoxBatch->setEnabled( true );
  110. }
  111. }
  112. void modCalcApCoord::slotRunBatch() {
  113. QString inputFileName = InputLineEditBatch->url().toLocalFile();
  114. // We open the input file and read its content
  115. if ( QFile::exists(inputFileName) ) {
  116. QFile f( inputFileName );
  117. if ( !f.open( QIODevice::ReadOnly) ) {
  118. QString message = xi18n( "Could not open file %1.", f.fileName() );
  119. KMessageBox::sorry( 0, message, xi18n( "Could Not Open File" ) );
  120. inputFileName.clear();
  121. return;
  122. }
  123. // processLines(&f);
  124. QTextStream istream(&f);
  125. processLines(istream);
  126. // readFile( istream );
  127. f.close();
  128. } else {
  129. QString message = xi18n( "Invalid file: %1", inputFileName );
  130. KMessageBox::sorry( 0, message, xi18n( "Invalid file" ) );
  131. inputFileName.clear();
  132. InputLineEditBatch->setText( inputFileName );
  133. return;
  134. }
  135. }
  136. //void modCalcApCoord::processLines( const QFile * fIn ) {
  137. void modCalcApCoord::processLines( QTextStream &istream ) {
  138. // we open the output file
  139. // QTextStream istream(&fIn);
  140. QString outputFileName;
  141. outputFileName = OutputLineEditBatch->text();
  142. QFile fOut( outputFileName );
  143. fOut.open(QIODevice::WriteOnly);
  144. QTextStream ostream(&fOut);
  145. QString line;
  146. QChar space = ' ';
  147. int i = 0;
  148. long double jd, jd0;
  149. SkyPoint sp;
  150. QTime utB;
  151. QDate dtB;
  152. dms raB, decB;
  153. QString epoch0B;
  154. while ( ! istream.atEnd() ) {
  155. line = istream.readLine();
  156. line.trimmed();
  157. //Go through the line, looking for parameters
  158. QStringList fields = line.split( ' ' );
  159. i = 0;
  160. // Read Ut and write in ostream if corresponds
  161. if(utCheckBatch->isChecked() ) {
  162. utB = QTime::fromString( fields[i] );
  163. i++;
  164. } else
  165. utB = utBoxBatch->time();
  166. if ( allRadioBatch->isChecked() )
  167. ostream << QLocale().toString( utB ) << space;
  168. else
  169. if(utCheckBatch->isChecked() )
  170. ostream << QLocale().toString( utB ) << space;
  171. // Read date and write in ostream if corresponds
  172. if(dateCheckBatch->isChecked() ) {
  173. dtB = QDate::fromString( fields[i] );
  174. i++;
  175. } else
  176. dtB = dateBoxBatch->date();
  177. if ( allRadioBatch->isChecked() )
  178. ostream << QLocale().toString( dtB, QLocale::LongFormat ).append(space);
  179. else
  180. if(dateCheckBatch->isChecked() )
  181. ostream << QLocale().toString( dtB, QLocale::LongFormat ).append(space);
  182. // Read RA and write in ostream if corresponds
  183. if(raCheckBatch->isChecked() ) {
  184. raB = dms::fromString( fields[i],false);
  185. i++;
  186. } else
  187. raB = raBoxBatch->createDms(false);
  188. if ( allRadioBatch->isChecked() )
  189. ostream << raB.toHMSString() << space;
  190. else
  191. if(raCheckBatch->isChecked() )
  192. ostream << raB.toHMSString() << space;
  193. // Read DEC and write in ostream if corresponds
  194. if(decCheckBatch->isChecked() ) {
  195. decB = dms::fromString( fields[i], true);
  196. i++;
  197. } else
  198. decB = decBoxBatch->createDms();
  199. if ( allRadioBatch->isChecked() )
  200. ostream << decB.toDMSString() << space;
  201. else
  202. if(decCheckBatch->isChecked() )
  203. ostream << decB.toHMSString() << space;
  204. // Read Epoch and write in ostream if corresponds
  205. if(epochCheckBatch->isChecked() ) {
  206. epoch0B = fields[i];
  207. i++;
  208. } else
  209. epoch0B = epochBoxBatch->text();
  210. if ( allRadioBatch->isChecked() )
  211. ostream << epoch0B;
  212. else
  213. if(decCheckBatch->isChecked() )
  214. ostream << epoch0B;
  215. KStarsDateTime dt;
  216. dt.setFromEpoch( epoch0B );
  217. jd = KStarsDateTime(dtB,utB).djd();
  218. jd0 = dt.djd();
  219. sp = SkyPoint (raB, decB);
  220. sp.apparentCoord(jd0, jd);
  221. ostream << sp.ra().toHMSString() << sp.dec().toDMSString() << endl;
  222. }
  223. fOut.close();
  224. }