• 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
modcalcgalcoord.cpp
Go to the documentation of this file.
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  * *
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 "modcalcgalcoord.h"
19 
20 #include <QTextStream>
21 
22 #include <kfiledialog.h>
23 #include <kmessagebox.h>
24 
25 #include "dms.h"
26 #include "skyobjects/skypoint.h"
27 #include "kstars.h"
28 #include "dialogs/finddialog.h"
29 #include "widgets/dmsbox.h"
30 
31 modCalcGalCoord::modCalcGalCoord(QWidget *parentSplit)
32  : QFrame(parentSplit) {
33 
34  setupUi(this);
35  RA->setDegType(false);
36 
37  connect( RA, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
38  connect( Dec, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
39  connect( GalLongitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
40  connect( GalLatitude, SIGNAL(editingFinished()), this, SLOT(slotComputeCoords()) );
41 
42  connect( ObjectButton, SIGNAL(clicked()), this, SLOT(slotObject()) );
43 
44  connect(decCheckBatch, SIGNAL(clicked()), this, SLOT(slotDecCheckedBatch()));
45  connect(raCheckBatch, SIGNAL(clicked()), this, SLOT(slotRaCheckedBatch()));
46  connect(epochCheckBatch, SIGNAL(clicked()), this, SLOT(slotEpochCheckedBatch()));
47  connect(galLongCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLongCheckedBatch()));
48  connect(galLatCheckBatch, SIGNAL(clicked()), this, SLOT(slotGalLatCheckedBatch()));
49  connect(runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()));
50 
51  show();
52 }
53 
54 modCalcGalCoord::~modCalcGalCoord() {
55 }
56 
57 void modCalcGalCoord::slotObject()
58 {
59  QPointer<FindDialog> fd = new FindDialog( this );
60  if ( fd->exec() == QDialog::Accepted ) {
61  SkyObject *o = fd->selectedObject();
62  RA->showInHours( o->ra() );
63  Dec->showInDegrees( o->dec() );
64  slotComputeCoords();
65  }
66  delete fd;
67 }
68 
69 void modCalcGalCoord::slotComputeCoords() {
70  if ( GalLongitude->hasFocus() )
71  GalLongitude->clearFocus();
72 
73  //Determine whether we should compute galactic coords from
74  //equatorial, or vice versa
75  if ( sender()->objectName() == "GalLongitude" || sender()->objectName() == "GalLatitude" ) {
76  //Validate GLong and GLat
77  bool ok(false);
78  dms glat;
79  dms glong = GalLongitude->createDms( true, &ok );
80  if ( ok )
81  glat = GalLatitude->createDms( true, &ok );
82  if ( ok ) {
83  SkyPoint sp, ra, dec;
84  sp.GalacticToEquatorial1950( &glong, &glat );
85  sp.B1950ToJ2000();
86  RA->showInHours( sp.ra() );
87  Dec->showInDegrees( sp.dec() );
88  }
89 
90  } else {
91  //Validate RA and Dec
92  bool ok(false);
93  dms dec;
94  dms ra = RA->createDms( false, &ok );
95  if ( ok )
96  dec = Dec->createDms( true, &ok );
97  if ( ok ) {
98  dms glong, glat;
99  SkyPoint sp( ra, dec );
100  sp.J2000ToB1950();
101  sp.Equatorial1950ToGalactic(glong, glat);
102  GalLongitude->showInDegrees(glong);
103  GalLatitude->showInDegrees(glat);
104  }
105  }
106 }
107 
108 void modCalcGalCoord::galCheck() {
109 
110  galLatCheckBatch->setChecked(false);
111  galLatBoxBatch->setEnabled(false);
112  galLongCheckBatch->setChecked(false);
113  galLongBoxBatch->setEnabled(false);
114  galInputCoords = false;
115 
116 }
117 
118 void modCalcGalCoord::equCheck() {
119 
120  raCheckBatch->setChecked(false);
121  raBoxBatch->setEnabled(false);
122  decCheckBatch->setChecked(false);
123  decBoxBatch->setEnabled(false);
124  epochCheckBatch->setChecked(false);
125  galInputCoords = true;
126 
127 }
128 
129 void modCalcGalCoord::slotRaCheckedBatch(){
130 
131  if ( raCheckBatch->isChecked() ) {
132  raBoxBatch->setEnabled( false );
133  galCheck();
134  } else {
135  raBoxBatch->setEnabled( true );
136  }
137 }
138 
139 void modCalcGalCoord::slotDecCheckedBatch(){
140 
141  if ( decCheckBatch->isChecked() ) {
142  decBoxBatch->setEnabled( false );
143  galCheck();
144  } else {
145  decBoxBatch->setEnabled( true );
146  }
147 }
148 
149 void modCalcGalCoord::slotEpochCheckedBatch(){
150 
151  epochCheckBatch->setChecked(false);
152 
153  if ( epochCheckBatch->isChecked() ) {
154  epochBoxBatch->setEnabled( false );
155  galCheck();
156  } else {
157  epochBoxBatch->setEnabled( true );
158  }
159 }
160 
161 void modCalcGalCoord::slotGalLatCheckedBatch(){
162 
163  if ( galLatCheckBatch->isChecked() ) {
164  galLatBoxBatch->setEnabled( false );
165  equCheck();
166  } else {
167  galLatBoxBatch->setEnabled( true );
168  }
169 }
170 
171 void modCalcGalCoord::slotGalLongCheckedBatch(){
172 
173  if ( galLongCheckBatch->isChecked() ) {
174  galLongBoxBatch->setEnabled( false );
175  equCheck();
176  } else {
177  galLongBoxBatch->setEnabled( true );
178  }
179 }
180 
181 void modCalcGalCoord::slotRunBatch() {
182 
183  QString inputFileName;
184 
185  inputFileName = InputFileBoxBatch->url().toLocalFile();
186 
187  // We open the input file and read its content
188 
189  if ( QFile::exists(inputFileName) ) {
190  QFile f( inputFileName );
191  if ( !f.open( QIODevice::ReadOnly) ) {
192  QString message = i18n( "Could not open file %1.", f.fileName() );
193  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
194  inputFileName.clear();
195  return;
196  }
197 
198  // processLines(&f);
199  QTextStream istream(&f);
200  processLines(istream);
201  // readFile( istream );
202  f.close();
203  } else {
204  QString message = i18n( "Invalid file: %1", inputFileName );
205  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
206  inputFileName.clear();
207  InputFileBoxBatch->setUrl( inputFileName );
208  return;
209  }
210 }
211 
212 void modCalcGalCoord::processLines( QTextStream &istream ) {
213 
214  // we open the output file
215 
216  // QTextStream istream(&fIn);
217  QString outputFileName;
218  outputFileName = OutputFileBoxBatch->url().toLocalFile();
219  QFile fOut( outputFileName );
220  fOut.open(QIODevice::WriteOnly);
221  QTextStream ostream(&fOut);
222 
223  QString line;
224  QChar space = ' ';
225  int i = 0;
226  SkyPoint sp;
227  dms raB, decB, galLatB, galLongB;
228  QString epoch0B;
229 
230  while ( ! istream.atEnd() ) {
231  line = istream.readLine();
232  line.trimmed();
233 
234  //Go through the line, looking for parameters
235 
236  QStringList fields = line.split( ' ' );
237 
238  i = 0;
239 
240  // Input coords are galactic coordinates:
241 
242  if (galInputCoords) {
243 
244  // Read Galactic Longitude and write in ostream if corresponds
245 
246  if(galLongCheckBatch->isChecked() ) {
247  galLongB = dms::fromString( fields[i], true);
248  i++;
249  } else
250  galLongB = galLongBoxBatch->createDms(true);
251 
252  if ( allRadioBatch->isChecked() )
253  ostream << galLongB.toDMSString() << space;
254  else
255  if(galLongCheckBatch->isChecked() )
256  ostream << galLongB.toDMSString() << space;
257 
258  // Read Galactic Latitude and write in ostream if corresponds
259 
260  if(galLatCheckBatch->isChecked() ) {
261  galLatB = dms::fromString( fields[i], true);
262  i++;
263  } else
264  galLatB = galLatBoxBatch->createDms(true);
265 
266  if ( allRadioBatch->isChecked() )
267  ostream << galLatB.toDMSString() << space;
268  else
269  if(galLatCheckBatch->isChecked() )
270  ostream << galLatB.toDMSString() << space;
271 
272  sp = SkyPoint ();
273  sp.GalacticToEquatorial1950(&galLongB, &galLatB);
274  ostream << sp.ra().toHMSString() << space << sp.dec().toDMSString() << epoch0B << endl;
275  // Input coords. are equatorial coordinates:
276 
277  } else {
278 
279  // Read RA and write in ostream if corresponds
280 
281  if(raCheckBatch->isChecked() ) {
282  raB = dms::fromString( fields[i],false);
283  i++;
284  } else
285  raB = raBoxBatch->createDms(false);
286 
287  if ( allRadioBatch->isChecked() )
288  ostream << raB.toHMSString() << space;
289  else
290  if(raCheckBatch->isChecked() )
291  ostream << raB.toHMSString() << space;
292 
293  // Read DEC and write in ostream if corresponds
294 
295  if(decCheckBatch->isChecked() ) {
296  decB = dms::fromString( fields[i], true);
297  i++;
298  } else
299  decB = decBoxBatch->createDms();
300 
301  if ( allRadioBatch->isChecked() )
302  ostream << decB.toDMSString() << space;
303  else
304  if(decCheckBatch->isChecked() )
305  ostream << decB.toDMSString() << space;
306 
307  // Read Epoch and write in ostream if corresponds
308 
309  if(epochCheckBatch->isChecked() ) {
310  epoch0B = fields[i];
311  i++;
312  } else
313  epoch0B = epochBoxBatch->text();
314 
315  if ( allRadioBatch->isChecked() )
316  ostream << epoch0B << space;
317  else
318  if(epochCheckBatch->isChecked() )
319  ostream << epoch0B << space;
320 
321  sp = SkyPoint (raB, decB);
322  sp.J2000ToB1950();
323  sp.Equatorial1950ToGalactic(galLongB, galLatB);
324  ostream << galLongB.toDMSString() << space << galLatB.toDMSString() << endl;
325 
326  }
327 
328  }
329 
330 
331  fOut.close();
332 }
333 
334 #include "modcalcgalcoord.moc"
modCalcGalCoord::slotRaCheckedBatch
void slotRaCheckedBatch()
Definition: modcalcgalcoord.cpp:129
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
modCalcGalCoord::slotEpochCheckedBatch
void slotEpochCheckedBatch()
Definition: modcalcgalcoord.cpp:149
SkyPoint::J2000ToB1950
void J2000ToB1950(void)
Exact precession from epoch J2000 Besselian epoch 1950.
Definition: skypoint.cpp:527
QWidget
dms.h
NaN::f
const float f
Definition: nan.h:36
modCalcGalCoord::slotComputeCoords
void slotComputeCoords()
Definition: modcalcgalcoord.cpp:69
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
modCalcGalCoord::~modCalcGalCoord
~modCalcGalCoord()
Definition: modcalcgalcoord.cpp:54
modCalcGalCoord::modCalcGalCoord
modCalcGalCoord(QWidget *p)
Definition: modcalcgalcoord.cpp:31
modCalcGalCoord::slotGalLatCheckedBatch
void slotGalLatCheckedBatch()
Definition: modcalcgalcoord.cpp:161
modCalcGalCoord::slotDecCheckedBatch
void slotDecCheckedBatch()
Definition: modcalcgalcoord.cpp:139
modCalcGalCoord::slotRunBatch
void slotRunBatch()
Definition: modcalcgalcoord.cpp:181
SkyPoint::GalacticToEquatorial1950
void GalacticToEquatorial1950(const dms *galLong, const dms *galLat)
Computes equatorial coordinates referred to 1950 from galactic ones referred to epoch B1950...
Definition: skypoint.cpp:461
modCalcGalCoord::slotGalLongCheckedBatch
void slotGalLongCheckedBatch()
Definition: modcalcgalcoord.cpp:171
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
modcalcgalcoord.h
finddialog.h
SkyPoint::Equatorial1950ToGalactic
void Equatorial1950ToGalactic(dms &galLong, dms &galLat)
Computes galactic coordinates from equatorial coordinates referred to epoch 1950. ...
Definition: skypoint.cpp:442
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
modCalcGalCoord::slotObject
void slotObject()
Definition: modcalcgalcoord.cpp:57
SkyPoint::B1950ToJ2000
void B1950ToJ2000(void)
Exact precession from Besselian epoch 1950 to epoch J2000.
Definition: skypoint.cpp:480
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