From c6c7cda0fcac9ab46ff9008f5e3eee0dae2b2544 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Thu, 30 Jun 2011 00:19:38 +1000 Subject: [PATCH] More unfinished ResMed stuff --- Graphs/graphwindow.cpp | 4 +- SleepLib/loader_plugins/resmed_loader.cpp | 192 +++++++++++++++++++++- SleepLib/loader_plugins/resmed_loader.h | 56 +++++++ daily.cpp | 51 +++++- daily.h | 11 ++ mainwindow.cpp | 5 + mainwindow.h | 1 + mainwindow.ui | 11 ++ 8 files changed, 320 insertions(+), 11 deletions(-) diff --git a/Graphs/graphwindow.cpp b/Graphs/graphwindow.cpp index 39114372..fe770b04 100644 --- a/Graphs/graphwindow.cpp +++ b/Graphs/graphwindow.cpp @@ -693,8 +693,8 @@ void gGraphWindow::Render(float w, float h) glEnd(); } else { - glClearColor(255,255,255,255); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(255,255,255,0); + glClear(GL_COLOR_BUFFER_BIT ); //| GL_DEPTH_BUFFER_BIT // glClear(GL_COLOR_BUFFER_BIT); } diff --git a/SleepLib/loader_plugins/resmed_loader.cpp b/SleepLib/loader_plugins/resmed_loader.cpp index c03c4ae2..8e970dcb 100644 --- a/SleepLib/loader_plugins/resmed_loader.cpp +++ b/SleepLib/loader_plugins/resmed_loader.cpp @@ -16,6 +16,120 @@ License: GPL #include "resmed_loader.h" #include "SleepLib/session.h" +EDFParser::EDFParser(QString name) +{ + buffer=NULL; + Open(name); +} +EDFParser::~EDFParser() +{ + vector::iterator s; + for (s=edfsignals.begin();s!=edfsignals.end();s++) { + if ((*s)->data) delete [] (*s)->data; + if ((*s)->adata) delete [] (*s)->adata; + delete *s; + } + if (buffer) delete [] buffer; +} +QString EDFParser::Read(int si) +{ + QString str; + if (pos>=filesize) return ""; + for (int i=0;idata=NULL; + signal->adata=NULL; + edfsignals[i]->label=Read(16); + } + + for (int i=0;itransducer_type=Read(80); + for (int i=0;iphysical_dimension=Read(8); + for (int i=0;iphysical_minimum=Read(8).toLong(&ok); + for (int i=0;iphysical_maximum=Read(8).toLong(&ok); + for (int i=0;idigital_minimum=Read(8).toLong(&ok); + for (int i=0;idigital_maximum=Read(8).toLong(&ok); + for (int i=0;iprefiltering=Read(80); + for (int i=0;inr=Read(8).toLong(&ok); + for (int i=0;ireserved=Read(32); + + for (int i=0;ilabel << endl; + if (edfsignals[i]->label!="EDF Annotations") { + // Waveforms + edfsignals[i]->data=new qint16 [edfsignals[i]->nr]; + for (int j=0;jnr;j++){ + long t; + t=Read(2).toLong(&ok); + if (!ok) + return false; + edfsignals[i]->data[j]=t & 0xffff; + } + + } else { // Annotation data.. + edfsignals[i]->adata=(char *) new char [edfsignals[i]->nr*2]; + //cout << signals[i]->nr << endl;; + for (int j=0;jnr*2;j++) + edfsignals[i]->adata[j]=buffer[pos++]; + } + //cout << "Read Signal" << endl; + } + return true; +} +bool EDFParser::Open(QString name) +{ + QFile f(name); + if (!f.open(QIODevice::ReadOnly)) return false; + if (!f.isReadable()) return false; + filename=name; + filesize=f.size(); + buffer=new char [filesize]; + f.read(buffer,filesize); + f.close(); + pos=0; +} + ResmedLoader::ResmedLoader() { } @@ -25,12 +139,11 @@ ResmedLoader::~ResmedLoader() Machine *ResmedLoader::CreateMachine(QString serial,Profile *profile) { - qDebug(("Create ResMed Machine "+serial).toLatin1()); assert(profile!=NULL); vector ml=profile->GetMachines(MT_CPAP); bool found=false; for (vector::iterator i=ml.begin(); i!=ml.end(); i++) { - if (((*i)->GetClass()=="ResMed") && ((*i)->properties["Serial"]==serial)) { + if (((*i)->GetClass()==resmed_class_name) && ((*i)->properties["Serial"]==serial)) { ResmedList[serial]=*i; //static_cast(*i); found=true; break; @@ -38,12 +151,15 @@ Machine *ResmedLoader::CreateMachine(QString serial,Profile *profile) } if (found) return ResmedList[serial]; + qDebug(("Create ResMed Machine %s"+serial).toLatin1()); Machine *m=new CPAP(profile,0); + m->SetClass(resmed_class_name); ResmedList[serial]=m; profile->AddMachine(m); m->properties["Serial"]=serial; + m->properties["Brand"]="ResMed"; return m; @@ -67,20 +183,82 @@ bool ResmedLoader::Open(QString & path,Profile *profile) return 0; qDebug(("ResmedLoader::Open newpath="+newpath).toLatin1()); - dir.setFilter(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks); + dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setSorting(QDir::Name); QFileInfoList flist=dir.entryInfoList(); - - - list SerialNumbers; - list::iterator sn; + map > sessfiles; + QString ext,rest,datestr,s,codestr; + SessionID sessionid; + QDateTime date; + map sessions; + Session *sess; + Machine *m; for (int i=0;iSetChanged(true); + switch(code) { + case 0: LoadEVE(m,sess,edf); + break; + case 1: LoadPLD(m,sess,edf); + break; + case 2: LoadBRP(m,sess,edf); + break; + case 3: LoadSAD(m,sess,edf); + break; + } } return 0; } +bool ResmedLoader::LoadEVE(Machine *mach,Session *sess,EDFParser &edf) +{ + QString t; + for (int s=0;snr); + qDebug((edf.edfsignals[s]->label+" "+t).toLatin1()); + if (edf.edfsignals[s]->adata) { + } + } +} +bool ResmedLoader::LoadBRP(Machine *mach,Session *sess,EDFParser &edf) +{ +} +bool ResmedLoader::LoadSAD(Machine *mach,Session *sess,EDFParser &edf) +{ +} +bool ResmedLoader::LoadPLD(Machine *mach,Session *sess,EDFParser &edf) +{ +} void ResInitModelMap() { diff --git a/SleepLib/loader_plugins/resmed_loader.h b/SleepLib/loader_plugins/resmed_loader.h index 01b074c9..3579f9c3 100644 --- a/SleepLib/loader_plugins/resmed_loader.h +++ b/SleepLib/loader_plugins/resmed_loader.h @@ -10,6 +10,7 @@ License: GPL #define RESMED_LOADER_H //#include //using namespace std; +#include #include "SleepLib/machine.h" // Base class: MachineLoader #include "SleepLib/machine_loader.h" #include "SleepLib/profiles.h" @@ -25,6 +26,56 @@ const int resmed_data_version=1; const QString resmed_class_name="ResMed"; +struct EDFSignal { +public: + QString label; + QString transducer_type; + QString physical_dimension; + long physical_minimum; + long physical_maximum; + long digital_minimum; + long digital_maximum; + QString prefiltering; + long nr; + QString reserved; + qint16 * data; + char *adata; +}; + +class EDFParser +{ +public: + EDFParser(QString filename); + ~EDFParser(); + bool Open(QString name); + + QString Read(int si); + + vector edfsignals; + + long GetNumSignals() { return num_signals; }; + long GetNumDataRecords() { return num_data_records; }; + long GetDuration() { return dur_data_record; }; + QString GetPatient() { return patientident; }; + bool Parse(); + char *buffer; + QString filename; + int filesize; + int pos; + + long version; + long num_header_bytes; + long num_data_records; + double dur_data_record; + long num_signals; + + QString patientident; + QString recordingident; + QString serialnumber; + QDateTime startdate; + QString reserved44; +}; + class ResmedLoader : public MachineLoader { public: @@ -39,6 +90,11 @@ public: static void Register(); protected: map ResmedList; + bool LoadEVE(Machine *mach,Session *sess,EDFParser &edf); + bool LoadBRP(Machine *mach,Session *sess,EDFParser &edf); + bool LoadSAD(Machine *mach,Session *sess,EDFParser &edf); + bool LoadPLD(Machine *mach,Session *sess,EDFParser &edf); + }; #endif // RESMED_LOADER_H diff --git a/daily.cpp b/daily.cpp index 6eecf72a..1dbbdead 100644 --- a/daily.cpp +++ b/daily.cpp @@ -443,7 +443,7 @@ void Daily::Load(QDate date) QString submodel=tr("Unknown Model"); - html=html+""+tr("Machine Information")+"\n"; + //html=html+""+tr("Machine Information")+"\n"; if (cpap->machine->properties.find("SubModel")!=cpap->machine->properties.end()) submodel="
"+cpap->machine->properties["SubModel"]; html=html+""+cpap->machine->properties["Brand"]+"
"+cpap->machine->properties["Model"]+" "+cpap->machine->properties["ModelNumber"]+submodel+"\n"; @@ -484,7 +484,7 @@ void Daily::Load(QDate date) html=html+("")+tr("Event Breakdown")+("\n"); { G_AHI->setFixedSize(gwwidth,gwheight); - QPixmap pixmap=G_AHI->renderPixmap(200,200,false); //gwwidth,gwheight,false); + QPixmap pixmap=G_AHI->renderPixmap(120,120,false); //gwwidth,gwheight,false); QByteArray byteArray; QBuffer buffer(&byteArray); // use buffer to store pixmap into byteArray buffer.open(QIODevice::WriteOnly); @@ -823,3 +823,50 @@ void Daily::on_JournalNotesUnderline_clicked() cursor.mergeCharFormat(format); //ui->JournalNotes->mergeCurrentCharFormat(format); } + + + +AHIGraph::AHIGraph(QObject * parent) +{ +} +AHIGraph::~AHIGraph() +{ +} +QObject * AHIGraph::create(const QString & mimeType, const QUrl & url, const QStringList & argumentNames, const QStringList & argumentValues) const +{ + gGraphWindow * ahi; + ahi=new gGraphWindow(NULL,"",(QGLWidget *)NULL); + ahi->SetMargins(0,0,0,0); + gPointData *g_ahi=new AHIData(); + //gCandleStick *l=new gCandleStick(g_ahi); + gPieChart *l=new gPieChart(g_ahi); + l->AddName(tr("H")); + l->AddName(tr("OA")); + l->AddName(tr("CA")); + l->AddName(tr("RE")); + l->AddName(tr("FL")); + l->AddName(tr("CSR")); + l->color.clear(); + l->color.push_back(QColor("blue")); + l->color.push_back(QColor(0x40,0xaf,0xbf,0xff)); //#40afbf + l->color.push_back(QColor(0xb2,0x54,0xcd,0xff)); //b254cd; //wxPURPLE); + l->color.push_back(QColor("yellow")); + l->color.push_back(QColor(0x40,0x40,0x40,255)); + l->color.push_back(QColor(0x60,0xff,0x60,0xff)); //80ff80 + + return ahi; +} +QList AHIGraph::plugins() const +{ + QWebPluginFactory::MimeType mimeType; + mimeType.name = "text/csv"; + mimeType.description = "Comma-separated values"; + mimeType.fileExtensions = QStringList() << "csv"; + + QWebPluginFactory::Plugin plugin; + plugin.name = "Pie Chart"; + plugin.description = "A Pie Chart Web plugin."; + plugin.mimeTypes = QList() << mimeType; + + return QList() << plugin; +} diff --git a/daily.h b/daily.h index 4d12ce27..8e87b898 100644 --- a/daily.h +++ b/daily.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -82,4 +83,14 @@ private: QLabel *NoData; }; +class AHIGraph:public QWebPluginFactory +{ +public: + AHIGraph(QObject * parent = 0); + virtual ~AHIGraph(); + virtual QObject * create ( const QString & mimeType, const QUrl & url, const QStringList & argumentNames, const QStringList & argumentValues) const; + virtual QList plugins () const; + //virtual void refreshPlugins (); +}; + #endif // DAILY_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 23043a99..f9afb2ef 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -77,6 +77,11 @@ MainWindow::~MainWindow() delete ui; Profiles::Done(); } +void MainWindow::showEvent(QShowEvent * event) +{ + if (daily) + daily->RedrawGraphs(); +} void MainWindow::Startup() { diff --git a/mainwindow.h b/mainwindow.h index 94fd284d..ce4248d1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -59,6 +59,7 @@ private slots: void on_action_Link_Graphs_triggered(bool checked); void on_actionUse_AntiAliasing_triggered(bool checked); + void showEvent(QShowEvent * event); private: Ui::MainWindow *ui; diff --git a/mainwindow.ui b/mainwindow.ui index e8cb1a6c..41c53b49 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -575,6 +575,17 @@ + + + toolBar + + + TopToolBarArea + + + false + + &Import Data