• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

modcalcangdist.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           modcalcapcoord.cpp  -  description
00003                              -------------------
00004     begin                : Sun May 30 2004
00005     copyright            : (C) 2004 by Pablo de Vicente
00006     email                : vicente@oan.es
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "modcalcangdist.h"
00019 #include "modcalcangdist.moc"
00020 #include "dms.h"
00021 #include "dmsbox.h"
00022 #include "skypoint.h"
00023 
00024 #include <qcheckbox.h>
00025 #include <qradiobutton.h>
00026 #include <qtextstream.h>
00027 #include <klocale.h>
00028 #include <kfiledialog.h>
00029 #include <kmessagebox.h>
00030 
00031 //#include <kapplication.h> ..already included in modcalcapcoord.h
00032 
00033 modCalcAngDist::modCalcAngDist(QWidget *parentSplit, const char *name) : modCalcAngDistDlg(parentSplit,name) {
00034 
00035     ra0Box->setDegType(FALSE);
00036     ra1Box->setDegType(FALSE);
00037     show();
00038 
00039 }
00040 
00041 modCalcAngDist::~modCalcAngDist(){
00042 }
00043 
00044 SkyPoint modCalcAngDist::getCoords (dmsBox* rBox, dmsBox* dBox) {
00045     dms raCoord, decCoord;
00046 
00047     raCoord = rBox->createDms(FALSE);
00048     decCoord = dBox->createDms();
00049 
00050     SkyPoint sp = SkyPoint (raCoord, decCoord);
00051 
00052     return sp;
00053 }
00054 
00055 void modCalcAngDist::showDist ( dms angDist ) {
00056     distBox->show( angDist );
00057 }
00058 
00059 void modCalcAngDist::slotClearCoords(){
00060 
00061     ra0Box->clearFields();
00062     dec0Box->clearFields();
00063     ra1Box->clearFields();
00064     dec1Box->clearFields();
00065     distBox->clearFields();
00066 }
00067 
00068 void modCalcAngDist::slotComputeDist(){
00069 
00070     SkyPoint sp0,sp1;
00071     sp0 = getCoords(ra0Box, dec0Box);
00072     sp1 = getCoords(ra1Box, dec1Box);
00073 
00074     dms aDist = sp0.angularDistanceTo(&sp1);
00075     showDist( aDist );
00076 }
00077 
00078 void modCalcAngDist::slotInputFile() {
00079     QString inputFileName;
00080     inputFileName = KFileDialog::getOpenFileName( );
00081     InputLineEditBatch->setText( inputFileName );
00082 }
00083 
00084 void modCalcAngDist::slotOutputFile() {
00085     QString outputFileName;
00086     outputFileName = KFileDialog::getSaveFileName( );
00087     OutputLineEditBatch->setText( outputFileName );
00088 }
00089 
00090 void modCalcAngDist::slotRunBatch() {
00091 
00092     QString inputFileName;
00093 
00094     inputFileName = InputLineEditBatch->text();
00095 
00096     // We open the input file and read its content
00097 
00098     if ( QFile::exists(inputFileName) ) {
00099         QFile f( inputFileName );
00100         if ( !f.open( IO_ReadOnly) ) {
00101             QString message = i18n( "Could not open file %1.").arg( f.name() );
00102             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00103             inputFileName = "";
00104             return;
00105         }
00106 
00107 //      processLines(&f);
00108         QTextStream istream(&f);
00109         processLines(istream);
00110 //      readFile( istream );
00111         f.close();
00112     } else  {
00113         QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00114         KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00115         inputFileName = "";
00116         InputLineEditBatch->setText( inputFileName );
00117         return;
00118     }
00119 }
00120 
00121 //void modCalcAngDist::processLines( const QFile * fIn ) {
00122 void modCalcAngDist::processLines( QTextStream &istream ) {
00123 
00124     // we open the output file
00125 
00126 //  QTextStream istream(&fIn);
00127     QString outputFileName;
00128     outputFileName = OutputLineEditBatch->text();
00129     QFile fOut( outputFileName );
00130     fOut.open(IO_WriteOnly);
00131     QTextStream ostream(&fOut);
00132 
00133     QString line;
00134     QString space = " ";
00135     int i = 0;
00136     SkyPoint sp0, sp1;
00137     dms ra0B, dec0B, ra1B, dec1B, dist;
00138 
00139     while ( ! istream.eof() ) {
00140         line = istream.readLine();
00141         line.stripWhiteSpace();
00142 
00143         //Go through the line, looking for parameters
00144 
00145         QStringList fields = QStringList::split( " ", line );
00146 
00147         i = 0;
00148 
00149         // Read RA and write in ostream if corresponds
00150 
00151         if(ra0CheckBatch->isChecked() ) {
00152             ra0B = dms::fromString( fields[i],FALSE);
00153             i++;
00154         } else
00155             ra0B = ra0BoxBatch->createDms(FALSE);
00156 
00157         if ( allRadioBatch->isChecked() )
00158             ostream << ra0B.toHMSString() << space;
00159         else
00160             if(ra0CheckBatch->isChecked() )
00161                 ostream << ra0B.toHMSString() << space;
00162 
00163         // Read DEC and write in ostream if corresponds
00164 
00165         if(dec0CheckBatch->isChecked() ) {
00166             dec0B = dms::fromString( fields[i], TRUE);
00167             i++;
00168         } else
00169             dec0B = dec0BoxBatch->createDms();
00170 
00171         if ( allRadioBatch->isChecked() )
00172             ostream << dec0B.toDMSString() << space;
00173         else
00174             if(dec0CheckBatch->isChecked() )
00175                 ostream << dec0B.toDMSString() << space;
00176         
00177         // Read RA and write in ostream if corresponds
00178 
00179         if(ra1CheckBatch->isChecked() ) {
00180             ra1B = dms::fromString( fields[i],FALSE);
00181             i++;
00182         } else
00183             ra1B = ra1BoxBatch->createDms(FALSE);
00184 
00185         if ( allRadioBatch->isChecked() )
00186             ostream << ra1B.toHMSString() << space;
00187         else
00188             if(ra1CheckBatch->isChecked() )
00189                 ostream << ra1B.toHMSString() << space;
00190 
00191         // Read DEC and write in ostream if corresponds
00192 
00193         if(dec1CheckBatch->isChecked() ) {
00194             dec1B = dms::fromString( fields[i], TRUE);
00195             i++;
00196         } else
00197             dec1B = dec1BoxBatch->createDms();
00198 
00199         if ( allRadioBatch->isChecked() )
00200             ostream << dec1B.toDMSString() << space;
00201         else
00202             if(dec1CheckBatch->isChecked() )
00203                 ostream << dec1B.toDMSString() << space;
00204 
00205         sp0 = SkyPoint (ra0B, dec0B);
00206         sp1 = SkyPoint (ra1B, dec1B);
00207         dist = sp0.angularDistanceTo(&sp1);
00208 
00209         ostream << dist.toDMSString() << endl;
00210     }
00211 
00212     fOut.close();
00213 }

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal