• 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
modcalcangdist.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  modcalcapcoord.cpp - description
3  -------------------
4  begin : Sun May 30 2004
5  copyright : (C) 2004 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 "modcalcangdist.h"
19 #include "modcalcangdist.moc"
20 
21 #include <QTextStream>
22 
23 #include <klocale.h>
24 #include <kfiledialog.h>
25 #include <kmessagebox.h>
26 
27 #include "dms.h"
28 #include "widgets/dmsbox.h"
29 #include "skyobjects/skypoint.h"
30 #include "dialogs/finddialog.h"
31 #include "kstars.h"
32 
33 modCalcAngDist::modCalcAngDist(QWidget *parentSplit)
34  : QFrame(parentSplit) {
35 
36  setupUi(this);
37  FirstRA->setDegType(false);
38  SecondRA->setDegType(false);
39 
40  connect( FirstRA, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions()) );
41  connect( FirstDec, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions()) );
42  connect( SecondRA, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions()) );
43  connect( SecondDec, SIGNAL(editingFinished()), this, SLOT(slotValidatePositions()) );
44  connect( FirstRA, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle()) );
45  connect( FirstDec, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle()) );
46  connect( SecondRA, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle()) );
47  connect( SecondDec, SIGNAL(textEdited(QString)), this, SLOT(slotResetTitle()) );
48  connect( FirstObjectButton, SIGNAL(clicked()), this, SLOT(slotObjectButton()) );
49  connect( SecondObjectButton, SIGNAL(clicked()), this, SLOT(slotObjectButton()) );
50  connect( runButtonBatch, SIGNAL(clicked()), this, SLOT(slotRunBatch()) );
51 
52  show();
53  slotValidatePositions();
54 }
55 
56 modCalcAngDist::~modCalcAngDist(){
57 }
58 
59 SkyPoint modCalcAngDist::getCoords (dmsBox* rBox, dmsBox* dBox, bool *ok) {
60  dms raCoord, decCoord;
61 
62  bool ok2=false;
63  raCoord = rBox->createDms(false, &ok2);
64  if ( ok2 )
65  decCoord = dBox->createDms(true, &ok2);
66 
67  if ( ok2 ) {
68  if ( ok ) *ok = ok2;
69  return SkyPoint (raCoord, decCoord);
70  } else {
71  if ( ok ) *ok = ok2;
72  return SkyPoint();
73  }
74 }
75 
76 void modCalcAngDist::slotValidatePositions(){
77 
78  SkyPoint sp0,sp1;
79  bool ok;
80  sp0 = getCoords(FirstRA, FirstDec, &ok);
81 
82  if ( ok )
83  sp1 = getCoords(SecondRA, SecondDec, &ok);
84 
85  if ( ok )
86  AngDist->setText( sp0.angularDistanceTo(&sp1).toDMSString() );
87  else
88  AngDist->setText( " .... " );
89 }
90 
91 void modCalcAngDist::slotObjectButton() {
92  QPointer<FindDialog> fd = new FindDialog( this );
93  if ( fd->exec() == QDialog::Accepted ) {
94  SkyObject *o = fd->selectedObject();
95  if ( sender()->objectName() == QString("FirstObjectButton") ) {
96  FirstRA->showInHours( o->ra() );
97  FirstDec->showInDegrees( o->dec() );
98  FirstPositionBox->setTitle( i18n("First position: %1", o->name()) );
99  } else {
100  SecondRA->showInHours( o->ra() );
101  SecondDec->showInDegrees( o->dec() );
102  SecondPositionBox->setTitle( i18n("Second position: %1", o->name()) );
103  }
104 
105  slotValidatePositions();
106  }
107  delete fd;
108 }
109 
110 void modCalcAngDist::slotResetTitle() {
111  QString name = sender()->objectName();
112  if ( name.contains( "First" ) )
113  FirstPositionBox->setTitle( i18n("First position") );
114  else
115  SecondPositionBox->setTitle( i18n("Second position") );
116 }
117 
118 void modCalcAngDist::slotRunBatch() {
119 
120  QString inputFileName = InputLineEditBatch->url().toLocalFile();
121 
122  // We open the input file and read its content
123 
124  if ( QFile::exists(inputFileName) ) {
125  QFile f( inputFileName );
126  if ( !f.open( QIODevice::ReadOnly) ) {
127  QString message = i18n( "Could not open file %1.", f.fileName() );
128  KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
129  inputFileName.clear();
130  return;
131  }
132 
133  // processLines(&f);
134  QTextStream istream(&f);
135  processLines(istream);
136  // readFile( istream );
137  f.close();
138  } else {
139  QString message = i18n( "Invalid file: %1", inputFileName );
140  KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
141  inputFileName.clear();
142  InputLineEditBatch->setText( inputFileName );
143  return;
144  }
145 }
146 
147 //void modCalcAngDist::processLines( const QFile * fIn ) {
148 void modCalcAngDist::processLines( QTextStream &istream ) {
149 
150  // we open the output file
151 
152  // QTextStream istream(&fIn);
153  QString outputFileName;
154  outputFileName = OutputLineEditBatch->text();
155  QFile fOut( outputFileName );
156  fOut.open(QIODevice::WriteOnly);
157  QTextStream ostream(&fOut);
158 
159  QString line;
160  QChar space = ' ';
161  int i = 0;
162  SkyPoint sp0, sp1;
163  dms ra0B, dec0B, ra1B, dec1B, dist;
164 
165  while ( ! istream.atEnd() ) {
166  line = istream.readLine();
167  line.trimmed();
168 
169  //Go through the line, looking for parameters
170 
171  QStringList fields = line.split( ' ' );
172 
173  i = 0;
174 
175  // Read RA and write in ostream if corresponds
176 
177  if(ra0CheckBatch->isChecked() ) {
178  ra0B = dms::fromString( fields[i],false);
179  i++;
180  } else
181  ra0B = ra0BoxBatch->createDms(false);
182 
183  if ( allRadioBatch->isChecked() )
184  ostream << ra0B.toHMSString() << space;
185  else
186  if(ra0CheckBatch->isChecked() )
187  ostream << ra0B.toHMSString() << space;
188 
189  // Read DEC and write in ostream if corresponds
190 
191  if(dec0CheckBatch->isChecked() ) {
192  dec0B = dms::fromString( fields[i], true);
193  i++;
194  } else
195  dec0B = dec0BoxBatch->createDms();
196 
197  if ( allRadioBatch->isChecked() )
198  ostream << dec0B.toDMSString() << space;
199  else
200  if(dec0CheckBatch->isChecked() )
201  ostream << dec0B.toDMSString() << space;
202 
203  // Read RA and write in ostream if corresponds
204 
205  if(ra1CheckBatch->isChecked() ) {
206  ra1B = dms::fromString( fields[i],false);
207  i++;
208  } else
209  ra1B = ra1BoxBatch->createDms(false);
210 
211  if ( allRadioBatch->isChecked() )
212  ostream << ra1B.toHMSString() << space;
213  else
214  if(ra1CheckBatch->isChecked() )
215  ostream << ra1B.toHMSString() << space;
216 
217  // Read DEC and write in ostream if corresponds
218 
219  if(dec1CheckBatch->isChecked() ) {
220  dec1B = dms::fromString( fields[i], true);
221  i++;
222  } else
223  dec1B = dec1BoxBatch->createDms();
224 
225  if ( allRadioBatch->isChecked() )
226  ostream << dec1B.toDMSString() << space;
227  else
228  if(dec1CheckBatch->isChecked() )
229  ostream << dec1B.toDMSString() << space;
230 
231  sp0 = SkyPoint (ra0B, dec0B);
232  sp1 = SkyPoint (ra1B, dec1B);
233  dist = sp0.angularDistanceTo(&sp1);
234 
235  ostream << dist.toDMSString() << endl;
236  }
237 
238  fOut.close();
239 }
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
modCalcAngDist::slotResetTitle
void slotResetTitle()
Definition: modcalcangdist.cpp:110
modCalcAngDist::slotValidatePositions
void slotValidatePositions()
Definition: modcalcangdist.cpp:76
QWidget
dmsBox::createDms
dms createDms(bool deg=true, bool *ok=0)
Parse the text in the dmsBox as an angle.
Definition: dmsbox.cpp:163
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
modCalcAngDist::~modCalcAngDist
~modCalcAngDist()
Destructor.
Definition: modcalcangdist.cpp:56
FindDialog
Dialog window for finding SkyObjects by name.
Definition: finddialog.h:47
modcalcangdist.h
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
modCalcAngDist::slotObjectButton
void slotObjectButton()
Definition: modcalcangdist.cpp:91
dmsBox
A KLineEdit which is capable of displaying and parsing angle values flexibly and robustly.
Definition: dmsbox.h:44
finddialog.h
modCalcAngDist::modCalcAngDist
modCalcAngDist(QWidget *p)
Constructor.
Definition: modcalcangdist.cpp:33
modCalcAngDist::slotRunBatch
void slotRunBatch()
Definition: modcalcangdist.cpp:118
dmsbox.h
SkyObject::name
virtual QString name(void) const
Definition: skyobject.h:124
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
SkyPoint::angularDistanceTo
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=0) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:608
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