kstars
filesource.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00027
00028 fileNumber = ksdata->starList.count() / 1000 + 1;
00029 lineNumber = ksdata->starList.count() % 1000;
00030
00031 if (fileNumber == 1) { lineNumber += 12; }
00032
00033
00034 if (fileNumber <= NHIPFILES) {
00035
00036 readingData = data->openStarFile(fileNumber);
00037 if (data->starFileReader->setLine(lineNumber) == true) {
00038
00039 } else {
00040
00041 }
00042 } else {
00043 readingData = false;
00044 }
00045 }
00046
00047 FileSource::~FileSource() {
00048 }
00049
00050 int FileSource::readyToSend() {
00051
00052
00053
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();
00065
00066 if (mag > maxMagnitude) {
00067 readingData = false;
00068 break;
00069 } else {
00070 stringArray[counter++] = line;
00071 }
00072 }
00073
00074 if (data->starFileReader->hasMoreLines() == false && readingData == true && fileNumber < NHIPFILES) {
00075 fileNumber++;
00076
00077 data->openStarFile(fileNumber);
00078 }
00079
00080 if (readingData == true && data->starFileReader != 0 && data->starFileReader->hasMoreLines() == true) {
00081 readingData = true;
00082 } else {
00083 readingData = false;
00084 }
00085
00086 sink->receive((uchar*) &stringArray[0], counter);
00087 }