blob: 8a1854a43801fe5c320bc4bed68de4951d6e5f91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/***************************************************************************
filesource.cpp - description
-------------------
begin : Son Feb 10 2002
copyright : (C) 2002 by Thomas Kabelmann
email : tk78@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "filesource.h"
#include "ksfilereader.h"
#include "kstarsdata.h"
#include "ksutils.h"
FileSource::FileSource(KStarsData *ksdata, float magnitude)
: maxMagnitude(magnitude), data(ksdata) {
// kdDebug() << "new magnitude to load is " << maxMagnitude << endl;
// kdDebug() << "count()=" << data->starList.count() << endl;
fileNumber = ksdata->starList.count() / 1000 + 1;
lineNumber = ksdata->starList.count() % 1000;
// the first file tqcontains 12 comment lines at the beginning which must skipped
if (fileNumber == 1) { lineNumber += 12; }
// kdDebug() << "fileNumber=" << fileNumber << " lineNumber=" << lineNumber << endl;
if (fileNumber <= NHIPFILES) {
// if file opened it's true else false
readingData = data->openStarFile(fileNumber);
if (data->starFileReader->setLine(lineNumber) == true) {
// kdDebug() << "line reset ok" << endl;
} else {
// kdDebug() << "line reset not ok" << endl;
}
} else {
readingData = false;
}
}
FileSource::~FileSource() {
}
int FileSource::readyToSend() {
// readyToSend == 0 -> no data but not end of stream
// readyToSend > 0 -> data ready to send
// readyToSend == -1 -> end of stream, TQDataPump will destroy this FileSource object
if (readingData == true)
return 1;
else
return -1;
}
void FileSource::sendTo(TQDataSink *sink, int) {
counter = 0;
while (data->starFileReader->hasMoreLines() && counter < maxLines) {
TQString line = data->starFileReader->readLine();
float mag = line.mid( 46, 5 ).toFloat(); // check magnitude
// kdDebug() << "mag=" << mag << " maxmag=" << maxMagnitude << endl;
if (mag > maxMagnitude) {
readingData = false;
break;
} else {
stringArray[counter++] = line;
}
}
// open next file if end is reached
if (data->starFileReader->hasMoreLines() == false && readingData == true && fileNumber < NHIPFILES) {
fileNumber++;
// kdDebug() << "sendTo: open file #" << fileNumber << endl;
data->openStarFile(fileNumber);
}
// check if more data are available
if (readingData == true && data->starFileReader != 0 && data->starFileReader->hasMoreLines() == true) {
readingData = true;
} else {
readingData = false;
}
// send data to StarDataSink
sink->receive((uchar*) &stringArray[0], counter);
}
|