moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / tools / modcalcangdist.cpp
blob409691527bfe51b4225585a5d91fa2d80df06191
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 ***************************************************************************/
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 ***************************************************************************/
18 #include "modcalcangdist.h"
19 #include "modcalcangdist.moc"
20 #include "dms.h"
21 #include "dmsbox.h"
22 #include "skypoint.h"
24 #include <qcheckbox.h>
25 #include <qradiobutton.h>
26 #include <qtextstream.h>
27 #include <klocale.h>
28 #include <kfiledialog.h>
29 #include <kmessagebox.h>
31 //#include <kapplication.h> ..already included in modcalcapcoord.h
33 modCalcAngDist::modCalcAngDist(QWidget *parentSplit, const char *name) : modCalcAngDistDlg(parentSplit,name) {
35 ra0Box->setDegType(FALSE);
36 ra1Box->setDegType(FALSE);
37 show();
41 modCalcAngDist::~modCalcAngDist(){
44 SkyPoint modCalcAngDist::getCoords (dmsBox* rBox, dmsBox* dBox) {
45 dms raCoord, decCoord;
47 raCoord = rBox->createDms(FALSE);
48 decCoord = dBox->createDms();
50 SkyPoint sp = SkyPoint (raCoord, decCoord);
52 return sp;
55 void modCalcAngDist::showDist ( dms angDist ) {
56 distBox->show( angDist );
59 void modCalcAngDist::slotClearCoords(){
61 ra0Box->clearFields();
62 dec0Box->clearFields();
63 ra1Box->clearFields();
64 dec1Box->clearFields();
65 distBox->clearFields();
68 void modCalcAngDist::slotComputeDist(){
70 SkyPoint sp0,sp1;
71 sp0 = getCoords(ra0Box, dec0Box);
72 sp1 = getCoords(ra1Box, dec1Box);
74 dms aDist = sp0.angularDistanceTo(&sp1);
75 showDist( aDist );
78 void modCalcAngDist::slotInputFile() {
79 QString inputFileName;
80 inputFileName = KFileDialog::getOpenFileName( );
81 InputLineEditBatch->setText( inputFileName );
84 void modCalcAngDist::slotOutputFile() {
85 QString outputFileName;
86 outputFileName = KFileDialog::getSaveFileName( );
87 OutputLineEditBatch->setText( outputFileName );
90 void modCalcAngDist::slotRunBatch() {
92 QString inputFileName;
94 inputFileName = InputLineEditBatch->text();
96 // We open the input file and read its content
98 if ( QFile::exists(inputFileName) ) {
99 QFile f( inputFileName );
100 if ( !f.open( IO_ReadOnly) ) {
101 QString message = i18n( "Could not open file %1.").arg( f.name() );
102 KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
103 inputFileName = "";
104 return;
107 // processLines(&f);
108 QTextStream istream(&f);
109 processLines(istream);
110 // readFile( istream );
111 f.close();
112 } else {
113 QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
114 KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
115 inputFileName = "";
116 InputLineEditBatch->setText( inputFileName );
117 return;
121 //void modCalcAngDist::processLines( const QFile * fIn ) {
122 void modCalcAngDist::processLines( QTextStream &istream ) {
124 // we open the output file
126 // QTextStream istream(&fIn);
127 QString outputFileName;
128 outputFileName = OutputLineEditBatch->text();
129 QFile fOut( outputFileName );
130 fOut.open(IO_WriteOnly);
131 QTextStream ostream(&fOut);
133 QString line;
134 QString space = " ";
135 int i = 0;
136 SkyPoint sp0, sp1;
137 dms ra0B, dec0B, ra1B, dec1B, dist;
139 while ( ! istream.eof() ) {
140 line = istream.readLine();
141 line.stripWhiteSpace();
143 //Go through the line, looking for parameters
145 QStringList fields = QStringList::split( " ", line );
147 i = 0;
149 // Read RA and write in ostream if corresponds
151 if(ra0CheckBatch->isChecked() ) {
152 ra0B = dms::fromString( fields[i],FALSE);
153 i++;
154 } else
155 ra0B = ra0BoxBatch->createDms(FALSE);
157 if ( allRadioBatch->isChecked() )
158 ostream << ra0B.toHMSString() << space;
159 else
160 if(ra0CheckBatch->isChecked() )
161 ostream << ra0B.toHMSString() << space;
163 // Read DEC and write in ostream if corresponds
165 if(dec0CheckBatch->isChecked() ) {
166 dec0B = dms::fromString( fields[i], TRUE);
167 i++;
168 } else
169 dec0B = dec0BoxBatch->createDms();
171 if ( allRadioBatch->isChecked() )
172 ostream << dec0B.toDMSString() << space;
173 else
174 if(dec0CheckBatch->isChecked() )
175 ostream << dec0B.toDMSString() << space;
177 // Read RA and write in ostream if corresponds
179 if(ra1CheckBatch->isChecked() ) {
180 ra1B = dms::fromString( fields[i],FALSE);
181 i++;
182 } else
183 ra1B = ra1BoxBatch->createDms(FALSE);
185 if ( allRadioBatch->isChecked() )
186 ostream << ra1B.toHMSString() << space;
187 else
188 if(ra1CheckBatch->isChecked() )
189 ostream << ra1B.toHMSString() << space;
191 // Read DEC and write in ostream if corresponds
193 if(dec1CheckBatch->isChecked() ) {
194 dec1B = dms::fromString( fields[i], TRUE);
195 i++;
196 } else
197 dec1B = dec1BoxBatch->createDms();
199 if ( allRadioBatch->isChecked() )
200 ostream << dec1B.toDMSString() << space;
201 else
202 if(dec1CheckBatch->isChecked() )
203 ostream << dec1B.toDMSString() << space;
205 sp0 = SkyPoint (ra0B, dec0B);
206 sp1 = SkyPoint (ra1B, dec1B);
207 dist = sp0.angularDistanceTo(&sp1);
209 ostream << dist.toDMSString() << endl;
212 fOut.close();