cassinitools.cpp
172 lines
| 4.5 KiB
| text/x-c
|
CppLexer
r5 | #include "cassinitools.h" | |||
#include <qlopplots.h> | ||||
#include <QPen> | ||||
r6 | #include <QAction> | |||
r5 | ||||
CassiniTools* CassiniTools::_self=NULL; | ||||
QDockWidget* CassiniTools::m_gui=NULL; | ||||
CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL; | ||||
CassiniDataFile* CassiniTools::m_dataFile=NULL; | ||||
r6 | int CassiniTools::m_defaultPlot=-1; | |||
r5 | ||||
Qt::GlobalColor QLopColours[]= {Qt::black, | ||||
Qt::red, | ||||
Qt::blue, | ||||
Qt::green, | ||||
Qt::darkGreen, | ||||
Qt::cyan, | ||||
Qt::darkRed, | ||||
Qt::gray, | ||||
Qt::yellow, | ||||
Qt::darkBlue, | ||||
Qt::darkCyan, | ||||
Qt::magenta, | ||||
Qt::darkMagenta, | ||||
Qt::darkYellow, | ||||
Qt::darkGray, | ||||
Qt::lightGray}; | ||||
int QLopColoursCount=16; | ||||
#define _INIT() if(Q_UNLIKELY(_self==NULL)){init();} | ||||
CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent) | ||||
{ | ||||
m_dataFile = new CassiniDataFile(); | ||||
connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList))); | ||||
m_serviceName="CassiniTools"; | ||||
m_noGui=noGUI; | ||||
} | ||||
CassiniTools::~CassiniTools() | ||||
{ | ||||
delete m_dataFile; | ||||
delete m_CassiniToolsGUI; | ||||
delete m_gui; | ||||
} | ||||
r6 | void CassiniTools::makePlot() | |||
{ | ||||
m_defaultPlot = QLopPlots::addPlot(); | ||||
SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot); | ||||
if(plot) | ||||
{ | ||||
plot->setTitle(_self->m_serviceName + " plot"); | ||||
plot->setXaxisTickLabelType(QCPAxis::ltDateTime); | ||||
plot->setXaxisDateTimeFormat("hh:mm:ss.zzz"); | ||||
plot->setContextMenuPolicy(Qt::ActionsContextMenu); | ||||
r7 | SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self); | |||
r6 | plot->addAction(action); | |||
r8 | QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int))); | |||
r6 | } | |||
} | ||||
r5 | void CassiniTools::init(bool noGUI, QObject *parent) | |||
{ | ||||
if(Q_UNLIKELY(_self==NULL)) | ||||
{ | ||||
_self=new CassiniTools(noGUI,parent); | ||||
} | ||||
} | ||||
CassiniTools *CassiniTools::self() | ||||
{ | ||||
_INIT(); | ||||
return _self; | ||||
} | ||||
void CassiniTools::decodeFGMData(const QString &file) | ||||
{ | ||||
_INIT(); | ||||
m_dataFile->parseFile(file); | ||||
} | ||||
void CassiniTools::plotFile(const QString &File) | ||||
{ | ||||
if(!m_dataFile->isRunning()) | ||||
{ | ||||
m_dataFile->parseFile(File); | ||||
r6 | // TODO fixme | |||
SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); | ||||
if(plot==NULL) | ||||
{ | ||||
makePlot(); | ||||
plot = QLopPlots::getPlot(m_defaultPlot); | ||||
} | ||||
if(plot) | ||||
plot->setTitle(File); | ||||
r5 | } | |||
} | ||||
void CassiniTools::plot_TAB_File(const QString &fileName) | ||||
{ | ||||
r6 | //TODO fix: accent not accepted | |||
plotFile(fileName); | ||||
} | ||||
r5 | ||||
r7 | void CassiniTools::export_view(int PID) | |||
r6 | { | |||
r7 | SocExplorerPlot* plot = QLopPlots::getPlot(PID); | |||
r6 | if(plot==NULL) | |||
r7 | return; | |||
r6 | { | |||
QString fileName = QFileDialog::getSaveFileName(); | ||||
r8 | if(fileName!="") | |||
{ | ||||
QLopDataList vectors; | ||||
for(int i=0;i<plot->graphCount();i++) | ||||
{ | ||||
QLopData* vect = new QLopData(); | ||||
vect->data = plot->getVisibleData(i); | ||||
vectors.append(vect); | ||||
} | ||||
m_dataFile->saveFile(fileName,vectors); | ||||
} | ||||
r6 | } | |||
r5 | } | |||
QDockWidget *CassiniTools::getGUI() | ||||
{ | ||||
if(!m_noGui && (m_gui==NULL)) | ||||
{ | ||||
m_gui=new QDockWidget("Cassini Tools"); | ||||
m_CassiniToolsGUI = new CassiniToolsGUI(); | ||||
m_gui->setWidget(m_CassiniToolsGUI); | ||||
m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable); | ||||
} | ||||
return m_gui; | ||||
} | ||||
const QString &CassiniTools::serviceName() | ||||
{ | ||||
_INIT(); | ||||
return m_serviceName; | ||||
} | ||||
void CassiniTools::dataReady(QLopDataList data) | ||||
{ | ||||
r6 | SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot); | |||
if(plot==NULL) | ||||
{ | ||||
makePlot(); | ||||
plot = QLopPlots::getPlot(m_defaultPlot); | ||||
} | ||||
if(plot) | ||||
{ | ||||
plot->removeAllGraphs(); | ||||
r5 | for(int i=0;i<data.count();i++) | |||
{ | ||||
r6 | plot->addGraph(); | |||
plot->setAdaptativeSampling(i,true); | ||||
plot->setUseFastVector(i,true); | ||||
QPen pen = plot->getGraphPen(i); | ||||
r5 | pen.setColor(QLopColours[i%QLopColoursCount]); | |||
r6 | plot->setGraphPen(i,pen); | |||
plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")"); | ||||
plot->setGraphData(i,data.at(i)->data,false); | ||||
r5 | } | |||
r6 | plot->rescaleAxis(); | |||
plot->replot(); | ||||
} | ||||
r5 | } | |||