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

kstars

filesource.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           filesource.cpp  -  description
00003                              -------------------
00004     begin                : Son Feb 10 2002
00005     copyright            : (C) 2002 by Thomas Kabelmann
00006     email                : tk78@gmx.de
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 "filesource.h"
00019 #include "ksfilereader.h"
00020 #include "kstarsdata.h"
00021 #include "ksutils.h"
00022 
00023 FileSource::FileSource(KStarsData *ksdata, float magnitude)
00024     : maxMagnitude(magnitude), data(ksdata) {
00025 
00026 //  kdDebug() << "new magnitude to load is " << maxMagnitude << endl;
00027 //  kdDebug() << "count()=" << data->starList.count() << endl;
00028     fileNumber = ksdata->starList.count() / 1000 + 1;
00029     lineNumber = ksdata->starList.count() % 1000;
00030     // the first file contains 12 comment lines at the beginning which must skipped
00031     if (fileNumber == 1) { lineNumber += 12; }
00032 //  kdDebug() << "fileNumber=" << fileNumber << " lineNumber=" << lineNumber << endl;
00033 
00034     if (fileNumber <= NHIPFILES) {
00035         // if file opened it's true else false
00036         readingData = data->openStarFile(fileNumber);
00037         if (data->starFileReader->setLine(lineNumber) == true) {
00038 //          kdDebug() << "line reset ok" << endl;
00039         } else {
00040 //          kdDebug() << "line reset not ok" << endl;
00041         }
00042     } else {
00043         readingData = false;
00044     }
00045 }
00046 
00047 FileSource::~FileSource() {
00048 }
00049 
00050 int FileSource::readyToSend() {
00051     // readyToSend ==  0 -> no data but not end of stream
00052     // readyToSend  >  0 -> data ready to send
00053     // readyToSend == -1 -> end of stream, QDataPump will destroy this FileSource object
00054     if (readingData == true)
00055         return 1;
00056     else
00057         return -1;
00058 }
00059 
00060 void FileSource::sendTo(QDataSink *sink, int) {
00061     counter = 0;
00062     while (data->starFileReader->hasMoreLines() && counter < maxLines) {
00063         QString line = data->starFileReader->readLine();
00064         float mag = line.mid( 46, 5 ).toFloat();  // check magnitude
00065 //      kdDebug() << "mag=" << mag << " maxmag=" << maxMagnitude << endl;
00066         if (mag > maxMagnitude) {
00067             readingData = false;
00068             break;
00069         } else {
00070             stringArray[counter++] = line;
00071         }
00072     }
00073     // open next file if end is reached
00074     if (data->starFileReader->hasMoreLines() == false && readingData == true && fileNumber < NHIPFILES) {
00075         fileNumber++;
00076 //      kdDebug() << "sendTo: open file #" << fileNumber << endl;
00077         data->openStarFile(fileNumber);
00078     }
00079     // check if more data are available
00080     if (readingData == true && data->starFileReader != 0 && data->starFileReader->hasMoreLines() == true) {
00081         readingData = true;
00082     } else {
00083         readingData = false;
00084     }
00085     // send data to StarDataSink
00086     sink->receive((uchar*) &stringArray[0], counter);
00087 }

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