1 /***************************************************************************
2 modcalcapcoord.cpp - description
4 begin : Sun May 30 2004
5 copyright : (C) 2004 by Pablo de Vicente
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
18 #include "modcalcangdist.h"
19 #include "modcalcangdist.moc"
24 #include <qcheckbox.h>
25 #include <qradiobutton.h>
26 #include <qtextstream.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
);
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
);
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(){
71 sp0
= getCoords(ra0Box
, dec0Box
);
72 sp1
= getCoords(ra1Box
, dec1Box
);
74 dms aDist
= sp0
.angularDistanceTo(&sp1
);
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" ) );
108 QTextStream
istream(&f
);
109 processLines(istream
);
110 // readFile( istream );
113 QString message
= i18n( "Invalid file: %1" ).arg( inputFileName
);
114 KMessageBox::sorry( 0, message
, i18n( "Invalid file" ) );
116 InputLineEditBatch
->setText( inputFileName
);
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
);
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
);
149 // Read RA and write in ostream if corresponds
151 if(ra0CheckBatch
->isChecked() ) {
152 ra0B
= dms::fromString( fields
[i
],FALSE
);
155 ra0B
= ra0BoxBatch
->createDms(FALSE
);
157 if ( allRadioBatch
->isChecked() )
158 ostream
<< ra0B
.toHMSString() << space
;
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
);
169 dec0B
= dec0BoxBatch
->createDms();
171 if ( allRadioBatch
->isChecked() )
172 ostream
<< dec0B
.toDMSString() << space
;
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
);
183 ra1B
= ra1BoxBatch
->createDms(FALSE
);
185 if ( allRadioBatch
->isChecked() )
186 ostream
<< ra1B
.toHMSString() << space
;
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
);
197 dec1B
= dec1BoxBatch
->createDms();
199 if ( allRadioBatch
->isChecked() )
200 ostream
<< dec1B
.toDMSString() << space
;
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
;