mainwindow.cpp
182 lines
| 6.7 KiB
| text/x-c
|
CppLexer
/ src / mainwindow.cpp
r0 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the QLop Software | ||||
-- Copyright (C) 2015, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- 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. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
#include "mainwindow.h" | ||||
#include "ui_mainwindow.h" | ||||
#include <QFileDialog> | ||||
#include <QDir> | ||||
#include "qcustomplot.h" | ||||
#include "filedownloader.h" | ||||
#include <omp.h> | ||||
MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) : | ||||
QMainWindow(parent), | ||||
ui(new Ui::MainWindow) | ||||
{ | ||||
this->OMP_THREADS = OMP_THREADS; | ||||
ui->setupUi(this); | ||||
connect(this->ui->addViewerQpb,SIGNAL(clicked()),this,SLOT(addFolderView())); | ||||
connect(&this->fileReader,SIGNAL(dataReady(QCPDataMap*,QCPDataMap*,QCPDataMap*)),this,SLOT(dataReady(QCPDataMap*,QCPDataMap*,QCPDataMap*))); | ||||
connect(this->ui->calendar,SIGNAL(activated(QDate)),this,SLOT(downloadData(QDate))); | ||||
for(int i=0;i<3;i++) | ||||
{ | ||||
this->ui->Plot->addGraph(); | ||||
this->ui->Plot->setAdaptativeSampling(i,true); | ||||
} | ||||
QPen pen = this->ui->Plot->getGraphPen(0); | ||||
pen.setColor(Qt::blue); | ||||
this->ui->Plot->setGraphPen(0,pen); | ||||
pen.setColor(Qt::red); | ||||
this->ui->Plot->setGraphPen(1,pen); | ||||
pen.setColor(Qt::black); | ||||
this->ui->Plot->setGraphPen(2,pen); | ||||
this->ui->Plot->setXaxisTickLabelType(QCPAxis::ltDateTime); | ||||
this->ui->Plot->setXaxisDateTimeFormat("hh:mm:ss.zzz"); | ||||
this->progressWidget = new QWidget(); | ||||
this->progressLayout = new QVBoxLayout(this->progressWidget); | ||||
this->progressWidget->setLayout(this->progressLayout); | ||||
this->progressWidget->setWindowModality(Qt::WindowModal); | ||||
for(int i=0;i<OMP_THREADS;i++) | ||||
{ | ||||
this->progress.append(new QProgressBar(this->progressWidget)); | ||||
this->progress.last()->setMinimum(0); | ||||
this->progress.last()->setMaximum(100); | ||||
connect(&this->fileReader,SIGNAL(updateProgress(int,int)),this,SLOT(updateProgress(int,int))); | ||||
this->progressLayout->addWidget(this->progress.last()); | ||||
this->progressWidget->hide(); | ||||
} | ||||
this->progressWidget->setWindowTitle("Loading File"); | ||||
} | ||||
MainWindow::~MainWindow() | ||||
{ | ||||
delete ui; | ||||
} | ||||
void MainWindow::itemDoubleClicked(QListWidgetItem* item) | ||||
{ | ||||
if(item) | ||||
{ | ||||
plotFile(item->text()); | ||||
} | ||||
} | ||||
void MainWindow::plotFile(const QString &File) | ||||
{ | ||||
if(!fileReader.isRunning()) | ||||
{ | ||||
for(int i=0;i<OMP_THREADS;i++) | ||||
{ | ||||
this->progress.at(i)->setValue(0); | ||||
} | ||||
this->progressWidget->show(); | ||||
fileReader.parseFile(File); | ||||
} | ||||
} | ||||
void MainWindow::dataReady(QCPDataMap *ch1, QCPDataMap *ch2, QCPDataMap *ch3) | ||||
{ | ||||
this->progressWidget->hide(); | ||||
this->ui->Plot->setGraphData(0,ch1,false,false); | ||||
this->ui->Plot->setGraphData(1,ch2,false,false); | ||||
this->ui->Plot->setGraphData(2,ch3,false,false); | ||||
this->ui->Plot->rescaleAxis(); | ||||
this->ui->Plot->replot(); | ||||
} | ||||
void MainWindow::downloadData(const QDate & date ) | ||||
{ | ||||
QDate tmpDate; | ||||
QStringList months=QStringList()<< "JAN" << "FEB" << "MAR" << "APR" << "MAY" << "JUN" << "JUI" << "AUG" << "SEP" << "OCT" << "NOV" << "DEC"; | ||||
tmpDate.setDate(date.year(),date.month(),1); | ||||
int firstDayOfMonth=tmpDate.dayOfYear(); | ||||
tmpDate.setDate(tmpDate.year(),tmpDate.month(),tmpDate.daysInMonth()); | ||||
int lastDayOfMonth=tmpDate.dayOfYear(); | ||||
QString link="http://ppi.pds.nasa.gov/ditdos/download?id=pds://PPI/CO-E_SW_J_S-MAG-3-RDR-FULL-RES-V1.0/DATA/" \ | ||||
+ QString("%1").arg(date.year()) +"/" + QString("%1_%2_").arg(firstDayOfMonth,3).arg(lastDayOfMonth,3).replace(' ','0') \ | ||||
+ months.at(date.month()-1) + "/" ; | ||||
qDebug()<<link; | ||||
QString dataFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.TAB"; | ||||
QString headerFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.LBL"; | ||||
// "_FGM_KRTP.TAB" | ||||
FileDownloader* dataFile = new FileDownloader(QUrl(link + dataFileName),dataFileName,this); | ||||
FileDownloader* headerFile = new FileDownloader(QUrl(link + headerFileName),headerFileName,this); | ||||
this->ui->DownloadListLayout->addWidget(dataFile->getProgressBar()); | ||||
this->ui->DownloadListLayout->addWidget(headerFile->getProgressBar()); | ||||
this->pendingDownloads.append(dataFile); | ||||
this->pendingDownloads.append(headerFile); | ||||
connect(dataFile,SIGNAL(downloaded()),this,SLOT(fileDownloadComplete())); | ||||
connect(headerFile,SIGNAL(downloaded()),this,SLOT(fileDownloadComplete())); | ||||
} | ||||
void MainWindow::updateProgress(int threadId, int percentProgress) | ||||
{ | ||||
if(threadId<progress.count()) | ||||
this->progress.at(threadId)->setValue(percentProgress); | ||||
} | ||||
void MainWindow::addFolderView() | ||||
{ | ||||
this->folderViews.append(new FolderView()); | ||||
this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last()); | ||||
this->folderViews.last()->setWindowTitle( "test");//QString("Folder View %1").arg(this->folderViews.length())); | ||||
this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas); | ||||
connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString))); | ||||
} | ||||
void MainWindow::fileDownloadComplete() | ||||
{ | ||||
for(int i=0;i<this->pendingDownloads.count();i++) | ||||
{ | ||||
if(pendingDownloads.at(i)->downloadComplete()) | ||||
{ | ||||
if(200<pendingDownloads.at(i)->donloadedDataSize()) | ||||
{ | ||||
QFile file(QDir::homePath() +"/Téléchargements/"+ pendingDownloads.at(i)->fileName()); | ||||
file.open(QIODevice::WriteOnly); | ||||
if(file.isOpen()) | ||||
{ | ||||
file.write(pendingDownloads.at(i)->downloadedData()); | ||||
file.flush(); | ||||
file.close(); | ||||
} | ||||
} | ||||
pendingDownloads.at(i)->clearData(); | ||||
pendingDownloads.removeAt(i); | ||||
i--; | ||||
} | ||||
} | ||||
} | ||||
void MainWindow::changeEvent(QEvent *e) | ||||
{ | ||||
QMainWindow::changeEvent(e); | ||||
switch (e->type()) { | ||||
case QEvent::LanguageChange: | ||||
ui->retranslateUi(this); | ||||
break; | ||||
default: | ||||
break; | ||||
} | ||||
} | ||||