|
|
/*------------------------------------------------------------------------------
|
|
|
-- 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);
|
|
|
progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
|
|
|
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->progressThreadIds[i] = -1;
|
|
|
}
|
|
|
this->progressWidget->setWindowTitle("Loading File");
|
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
{
|
|
|
delete ui;
|
|
|
}
|
|
|
|
|
|
QString MainWindow::getFilePath(const QString &name)
|
|
|
{
|
|
|
for(int i=0;i<this->folderViews.count();i++)
|
|
|
{
|
|
|
if(folderViews.at(i)->isDraging(name))
|
|
|
return folderViews.at(i)->currentFolder();
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
this->ui->Plot->setTitle(File);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::dataReady(QCPDataMap *ch1, QCPDataMap *ch2, QCPDataMap *ch3)
|
|
|
{
|
|
|
for(int i=0;i<OMP_THREADS;i++)
|
|
|
{
|
|
|
progressThreadIds[i]=-1;
|
|
|
}
|
|
|
this->progressWidget->hide();
|
|
|
this->ui->Plot->setGraphName(0,"MAG_X");
|
|
|
this->ui->Plot->setGraphName(1,"MAG_Y");
|
|
|
this->ui->Plot->setGraphName(2,"MAG_Z");
|
|
|
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)
|
|
|
{
|
|
|
bool updated=false;
|
|
|
for(int i=0;i<OMP_THREADS;i++)
|
|
|
{
|
|
|
if(progressThreadIds[i]==threadId)
|
|
|
{
|
|
|
if(threadId<this->progress.count())
|
|
|
{
|
|
|
this->progress.at(threadId)->setValue(percentProgress);
|
|
|
updated=true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(Q_UNLIKELY(updated==false))
|
|
|
{
|
|
|
for(int i=0;i<OMP_THREADS;i++)
|
|
|
{
|
|
|
if(progressThreadIds[i]==-1)
|
|
|
{
|
|
|
progressThreadIds[i] = threadId;
|
|
|
updateProgress(threadId,percentProgress);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::addFolderView()
|
|
|
{
|
|
|
this->folderViews.append(new FolderView(this));
|
|
|
this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last());
|
|
|
this->folderViews.last()->setWindowTitle( 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::askGlobalRescan()
|
|
|
{
|
|
|
for(int i=0;i<this->folderViews.count();i++)
|
|
|
{
|
|
|
this->folderViews.at(i)->refreshFolder();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void MainWindow::changeEvent(QEvent *e)
|
|
|
{
|
|
|
QMainWindow::changeEvent(e);
|
|
|
switch (e->type()) {
|
|
|
case QEvent::LanguageChange:
|
|
|
ui->retranslateUi(this);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|