00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00022
00023
00024
00026
00027
00028 #include <cassert>
00029
00030
00031 #include <qapplication.h>
00032 #include <qevent.h>
00033 #include <qfile.h>
00034 #include <qtextstream.h>
00035
00036
00037 #include "densitybase.h"
00038 #include "densityloadthread.h"
00039
00043
00045 DensityLoadThread::DensityLoadThread(std::vector<double>* densityPoints, QTextStream* stream, DensityBase* densityDialog, const unsigned int numSkipValues, const unsigned int totalPoints) : QThread(),
00046 data(densityPoints),
00047 textStream(stream),
00048 numSkip(numSkipValues),
00049 numValues(totalPoints),
00050 stopRequested(false),
00051 parent(densityDialog)
00052
00059 {
00060 assert(data != 0);
00061 assert(textStream != 0);
00062 assert(parent != 0);
00063 }
00064
00066 DensityLoadThread::~DensityLoadThread()
00068 {
00069
00070 }
00071
00073 void DensityLoadThread::run()
00076 {
00078 QFile* file = dynamic_cast<QFile*>(textStream->device());
00079 assert(file != 0);
00080
00081 if(numValues == 0)
00082 {
00083 delete textStream;
00084 delete file;
00085 return;
00086 }
00087
00088 data->clear();
00089 data->reserve(numValues);
00090 const unsigned int updateFreq = numValues/100;
00091 double value = 0.0;
00092
00093 for(unsigned int i = 0; i < numValues; i++)
00094 {
00095
00096 *textStream >> value;
00097 data->push_back(value);
00098 if(i % updateFreq == 0)
00099 {
00100 progress = i;
00101 QCustomEvent* e = new QCustomEvent(static_cast<QEvent::Type>(1001),&progress);
00102 QApplication::postEvent(parent, e);
00103 }
00104
00105 for(unsigned int skip = 0; skip < numSkip; skip++)
00106 *textStream >> value;
00107 if(stopRequested || textStream->atEnd())
00108 break;
00109 }
00110
00111
00112 if(data->size() != numValues)
00113 data->clear();
00114
00115
00116 delete textStream;
00117 delete file;
00118
00119
00120 QCustomEvent* e = new QCustomEvent(static_cast<QEvent::Type>(1002));
00121 QApplication::postEvent(parent, e);
00122 }
00123
00125 void DensityLoadThread::stop()
00127 {
00128 stopRequested = true;
00129 }
00130
00132 bool DensityLoadThread::success()
00134 {
00135 return data->size() == numValues;
00136 }
00137