PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/kstars/tools/modcalcgalcoord.cpp

https://gitlab.com/g10h4ck/kstars
C++ | 333 lines | 229 code | 72 blank | 32 comment | 43 complexity | 07f4c123058f2e93cf49a5ffe7d58a73 MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0
  1. /***************************************************************************
  2. modcalcgal.cpp - description
  3. -------------------
  4. begin : Thu Jan 17 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 "modcalcgalcoord.h"
  17. #include <QTextStream>
  18. #include <QFileDialog>
  19. #include <KMessageBox>
  20. #include "dms.h"
  21. #include "skyobjects/skypoint.h"
  22. #include "kstars.h"
  23. #include "dialogs/finddialog.h"
  24. #include "widgets/dmsbox.h"
  25. modCalcGalCoord::modCalcGalCoord(QWidget *parentSplit)
  26. : QFrame(parentSplit) {
  27. setupUi(this);
  28. RA->setDegType(false);
  29. connect( RA, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
  30. connect( Dec, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
  31. connect( GalLongitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
  32. connect( GalLatitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
  33. connect( ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()) );
  34. connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()));
  35. connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()));
  36. connect(epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()));
  37. connect(galLongCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLongCheckedBatch()));
  38. connect(galLatCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLatCheckedBatch()));
  39. connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()));
  40. show();
  41. }
  42. modCalcGalCoord::~modCalcGalCoord() {
  43. }
  44. void modCalcGalCoord::slotObject()
  45. {
  46. QPointer<FindDialog> fd = new FindDialog( this );
  47. if ( fd->exec() == QDialog::Accepted ) {
  48. SkyObject *o = fd->selectedObject();
  49. RA->showInHours( o->ra() );
  50. Dec->showInDegrees( o->dec() );
  51. slotComputeCoords();
  52. }
  53. delete fd;
  54. }
  55. void modCalcGalCoord::slotComputeCoords() {
  56. if ( GalLongitude->hasFocus() )
  57. GalLongitude->clearFocus();
  58. //Determine whether we should compute galactic coords from
  59. //equatorial, or vice versa
  60. if ( sender()->objectName() == "GalLongitude" || sender()->objectName() == "GalLatitude" ) {
  61. //Validate GLong and GLat
  62. bool ok(false);
  63. dms glat;
  64. dms glong = GalLongitude->createDms( true, &ok );
  65. if ( ok )
  66. glat = GalLatitude->createDms( true, &ok );
  67. if ( ok ) {
  68. SkyPoint sp, ra, dec;
  69. sp.GalacticToEquatorial1950( &glong, &glat );
  70. sp.B1950ToJ2000();
  71. RA->showInHours( sp.ra() );
  72. Dec->showInDegrees( sp.dec() );
  73. }
  74. } else {
  75. //Validate RA and Dec
  76. bool ok(false);
  77. dms dec;
  78. dms ra = RA->createDms( false, &ok );
  79. if ( ok )
  80. dec = Dec->createDms( true, &ok );
  81. if ( ok ) {
  82. dms glong, glat;
  83. SkyPoint sp( ra, dec );
  84. sp.J2000ToB1950();
  85. sp.Equatorial1950ToGalactic(glong, glat);
  86. GalLongitude->showInDegrees(glong);
  87. GalLatitude->showInDegrees(glat);
  88. }
  89. }
  90. }
  91. void modCalcGalCoord::galCheck() {
  92. galLatCheckBatch->setChecked(false);
  93. galLatBoxBatch->setEnabled(false);
  94. galLongCheckBatch->setChecked(false);
  95. galLongBoxBatch->setEnabled(false);
  96. galInputCoords = false;
  97. }
  98. void modCalcGalCoord::equCheck() {
  99. raCheckBatch->setChecked(false);
  100. raBoxBatch->setEnabled(false);
  101. decCheckBatch->setChecked(false);
  102. decBoxBatch->setEnabled(false);
  103. epochCheckBatch->setChecked(false);
  104. galInputCoords = true;
  105. }
  106. void modCalcGalCoord::slotRaCheckedBatch(){
  107. if ( raCheckBatch->isChecked() ) {
  108. raBoxBatch->setEnabled( false );
  109. galCheck();
  110. } else {
  111. raBoxBatch->setEnabled( true );
  112. }
  113. }
  114. void modCalcGalCoord::slotDecCheckedBatch(){
  115. if ( decCheckBatch->isChecked() ) {
  116. decBoxBatch->setEnabled( false );
  117. galCheck();
  118. } else {
  119. decBoxBatch->setEnabled( true );
  120. }
  121. }
  122. void modCalcGalCoord::slotEpochCheckedBatch(){
  123. epochCheckBatch->setChecked(false);
  124. if ( epochCheckBatch->isChecked() ) {
  125. epochBoxBatch->setEnabled( false );
  126. galCheck();
  127. } else {
  128. epochBoxBatch->setEnabled( true );
  129. }
  130. }
  131. void modCalcGalCoord::slotGalLatCheckedBatch(){
  132. if ( galLatCheckBatch->isChecked() ) {
  133. galLatBoxBatch->setEnabled( false );
  134. equCheck();
  135. } else {
  136. galLatBoxBatch->setEnabled( true );
  137. }
  138. }
  139. void modCalcGalCoord::slotGalLongCheckedBatch(){
  140. if ( galLongCheckBatch->isChecked() ) {
  141. galLongBoxBatch->setEnabled( false );
  142. equCheck();
  143. } else {
  144. galLongBoxBatch->setEnabled( true );
  145. }
  146. }
  147. void modCalcGalCoord::slotRunBatch() {
  148. QString inputFileName;
  149. inputFileName = InputFileBoxBatch->url().toLocalFile();
  150. // We open the input file and read its content
  151. if ( QFile::exists(inputFileName) ) {
  152. QFile f( inputFileName );
  153. if ( !f.open( QIODevice::ReadOnly) ) {
  154. QString message = xi18n( "Could not open file %1.", f.fileName() );
  155. KMessageBox::sorry( 0, message, xi18n( "Could Not Open File" ) );
  156. inputFileName.clear();
  157. return;
  158. }
  159. // processLines(&f);
  160. QTextStream istream(&f);
  161. processLines(istream);
  162. // readFile( istream );
  163. f.close();
  164. } else {
  165. QString message = xi18n( "Invalid file: %1", inputFileName );
  166. KMessageBox::sorry( 0, message, xi18n( "Invalid file" ) );
  167. inputFileName.clear();
  168. InputFileBoxBatch->setUrl( inputFileName );
  169. return;
  170. }
  171. }
  172. void modCalcGalCoord::processLines( QTextStream &istream ) {
  173. // we open the output file
  174. // QTextStream istream(&fIn);
  175. QString outputFileName;
  176. outputFileName = OutputFileBoxBatch->url().toLocalFile();
  177. QFile fOut( outputFileName );
  178. fOut.open(QIODevice::WriteOnly);
  179. QTextStream ostream(&fOut);
  180. QString line;
  181. QChar space = ' ';
  182. int i = 0;
  183. SkyPoint sp;
  184. dms raB, decB, galLatB, galLongB;
  185. QString epoch0B;
  186. while ( ! istream.atEnd() ) {
  187. line = istream.readLine();
  188. line.trimmed();
  189. //Go through the line, looking for parameters
  190. QStringList fields = line.split( ' ' );
  191. i = 0;
  192. // Input coords are galactic coordinates:
  193. if (galInputCoords) {
  194. // Read Galactic Longitude and write in ostream if corresponds
  195. if(galLongCheckBatch->isChecked() ) {
  196. galLongB = dms::fromString( fields[i], true);
  197. i++;
  198. } else
  199. galLongB = galLongBoxBatch->createDms(true);
  200. if ( allRadioBatch->isChecked() )
  201. ostream << galLongB.toDMSString() << space;
  202. else
  203. if(galLongCheckBatch->isChecked() )
  204. ostream << galLongB.toDMSString() << space;
  205. // Read Galactic Latitude and write in ostream if corresponds
  206. if(galLatCheckBatch->isChecked() ) {
  207. galLatB = dms::fromString( fields[i], true);
  208. i++;
  209. } else
  210. galLatB = galLatBoxBatch->createDms(true);
  211. if ( allRadioBatch->isChecked() )
  212. ostream << galLatB.toDMSString() << space;
  213. else
  214. if(galLatCheckBatch->isChecked() )
  215. ostream << galLatB.toDMSString() << space;
  216. sp = SkyPoint ();
  217. sp.GalacticToEquatorial1950(&galLongB, &galLatB);
  218. ostream << sp.ra().toHMSString() << space << sp.dec().toDMSString() << epoch0B << endl;
  219. // Input coords. are equatorial coordinates:
  220. } else {
  221. // Read RA and write in ostream if corresponds
  222. if(raCheckBatch->isChecked() ) {
  223. raB = dms::fromString( fields[i],false);
  224. i++;
  225. } else
  226. raB = raBoxBatch->createDms(false);
  227. if ( allRadioBatch->isChecked() )
  228. ostream << raB.toHMSString() << space;
  229. else
  230. if(raCheckBatch->isChecked() )
  231. ostream << raB.toHMSString() << space;
  232. // Read DEC and write in ostream if corresponds
  233. if(decCheckBatch->isChecked() ) {
  234. decB = dms::fromString( fields[i], true);
  235. i++;
  236. } else
  237. decB = decBoxBatch->createDms();
  238. if ( allRadioBatch->isChecked() )
  239. ostream << decB.toDMSString() << space;
  240. else
  241. if(decCheckBatch->isChecked() )
  242. ostream << decB.toDMSString() << space;
  243. // Read Epoch and write in ostream if corresponds
  244. if(epochCheckBatch->isChecked() ) {
  245. epoch0B = fields[i];
  246. i++;
  247. } else
  248. epoch0B = epochBoxBatch->text();
  249. if ( allRadioBatch->isChecked() )
  250. ostream << epoch0B << space;
  251. else
  252. if(epochCheckBatch->isChecked() )
  253. ostream << epoch0B << space;
  254. sp = SkyPoint (raB, decB);
  255. sp.J2000ToB1950();
  256. sp.Equatorial1950ToGalactic(galLongB, galLatB);
  257. ostream << galLongB.toDMSString() << space << galLatB.toDMSString() << endl;
  258. }
  259. }
  260. fOut.close();
  261. }