##// END OF EJS Templates
added zoom box.
jeandet -
r2:a262e3a4f8e7 default
parent child
Show More
@@ -1,42 +1,42
1 #-------------------------------------------------
1 #-------------------------------------------------
2 #
2 #
3 # Project created by QtCreator 2015-01-07T02:41:29
3 # Project created by QtCreator 2015-01-07T02:41:29
4 #
4 #
5 #-------------------------------------------------
5 #-------------------------------------------------
6
6
7 QT += core gui network
7 QT += core gui network
8
8
9 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
9 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
10
10
11 TARGET = QLop
11 TARGET = QLop
12 TEMPLATE = app
12 TEMPLATE = app
13
13
14 INCLUDEPATH += src/QCustomPlot src
14 INCLUDEPATH += src/QCustomPlot src
15
15
16 QMAKE_CXXFLAGS += -fopenmp
16 QMAKE_CXXFLAGS += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx
17 QMAKE_LFLAGS += -fopenmp
17 QMAKE_LFLAGS += -O5 -fopenmp -march=corei7-avx -mtune=corei7-avx -mavx
18
18
19 SOURCES += src/main.cpp\
19 SOURCES += src/main.cpp\
20 src/mainwindow.cpp \
20 src/mainwindow.cpp \
21 src/SocExplorerPlot.cpp \
21 src/SocExplorerPlot.cpp \
22 src/QCustomPlot/qcustomplot.cpp \
22 src/QCustomPlot/qcustomplot.cpp \
23 src/themisdatafile.cpp \
23 src/themisdatafile.cpp \
24 src/filedownloader.cpp \
24 src/filedownloader.cpp \
25 src/folderview.cpp \
25 src/folderview.cpp \
26 src/toolbarcontainer.cpp \
26 src/toolbarcontainer.cpp \
27 src/folderlistwidget.cpp
27 src/folderlistwidget.cpp
28
28
29 HEADERS += src/mainwindow.h \
29 HEADERS += src/mainwindow.h \
30 src/SocExplorerPlot.h \
30 src/SocExplorerPlot.h \
31 src/QCustomPlot/qcustomplot.h \
31 src/QCustomPlot/qcustomplot.h \
32 src/themisdatafile.h \
32 src/themisdatafile.h \
33 src/filedownloader.h \
33 src/filedownloader.h \
34 src/folderview.h \
34 src/folderview.h \
35 src/toolbarcontainer.h \
35 src/toolbarcontainer.h \
36 src/folderlistwidget.h
36 src/folderlistwidget.h
37
37
38 FORMS += src/mainwindow.ui \
38 FORMS += src/mainwindow.ui \
39 src/folderview.ui
39 src/folderview.ui
40
40
41 RESOURCES += \
41 RESOURCES += \
42 resources/qlop.qrc
42 resources/qlop.qrc
@@ -1,545 +1,586
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "SocExplorerPlot.h"
22 #include "SocExplorerPlot.h"
23
23
24
24
25
25
26 SocExplorerPlot::SocExplorerPlot(QWidget *parent) :
26 SocExplorerPlot::SocExplorerPlot(QWidget *parent) :
27 QWidget(parent)
27 QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this))
28 {
28 {
29 this->m_plot = new QCustomPlot(this);
29 this->m_plot = new QCustomPlot(this);
30 this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
30 this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
31 QCP::iSelectLegend | QCP::iSelectPlottables);
31 QCP::iSelectLegend | QCP::iSelectPlottables);
32 this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
32 this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
33 this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
33 this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
34 this->m_mainlayout = new QGridLayout(this);
34 this->m_mainlayout = new QGridLayout(this);
35 this->setLayout(this->m_mainlayout);
35 this->setLayout(this->m_mainlayout);
36 this->m_mainlayout->addWidget(this->m_plot);
36 this->m_mainlayout->addWidget(this->m_plot);
37 this->setMinimumSize(400,300);
37 this->setMinimumSize(400,300);
38 this->setFocusPolicy(Qt::WheelFocus);
38 this->setFocusPolicy(Qt::WheelFocus);
39 this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
39 this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
40 this->ctrl_hold = false;
40 this->ctrl_hold = false;
41 this->shift_hold = false;
41 this->shift_hold = false;
42 this->mouse_hold = false;
42 this->mouse_hold = false;
43 this->m_plot->setNoAntialiasingOnDrag(true);
43 this->m_plot->setNoAntialiasingOnDrag(true);
44 this->show();
44 this->show();
45 this->m_plot->legend->setVisible(true);
45 this->m_plot->legend->setVisible(true);
46
46
47 }
47 }
48
48
49 SocExplorerPlot::~SocExplorerPlot()
50 {
51 delete mRubberBand;
52 }
53
49 void SocExplorerPlot::show()
54 void SocExplorerPlot::show()
50 {
55 {
51 QWidget::show();
56 QWidget::show();
52 }
57 }
53
58
54 void SocExplorerPlot::replot()
59 void SocExplorerPlot::replot()
55 {
60 {
56 this->m_plot->replot();
61 this->m_plot->replot();
57 }
62 }
58
63
59 void SocExplorerPlot::setTitle(QString title)
64 void SocExplorerPlot::setTitle(QString title)
60 {
65 {
61 Q_UNUSED(title)
66 Q_UNUSED(title)
62 //this->m_plot->setTitle(title);
67 //this->m_plot->setTitle(title);
63 /*!
68 /*!
64 @todo Function borcken fixe this!
69 @todo Function borcken fixe this!
65 */
70 */
66 this->repaint();
71 this->repaint();
67 }
72 }
68
73
69 void SocExplorerPlot::setXaxisLabel(QString label)
74 void SocExplorerPlot::setXaxisLabel(QString label)
70 {
75 {
71 this->m_plot->xAxis->setLabel(label);
76 this->m_plot->xAxis->setLabel(label);
72 this->repaint();
77 this->repaint();
73 }
78 }
74
79
75 void SocExplorerPlot::setYaxisLabel(QString label)
80 void SocExplorerPlot::setYaxisLabel(QString label)
76 {
81 {
77 this->m_plot->yAxis->setLabel(label);
82 this->m_plot->yAxis->setLabel(label);
78 this->repaint();
83 this->repaint();
79 }
84 }
80
85
81 void SocExplorerPlot::setXaxisRange(double lower, double upper)
86 void SocExplorerPlot::setXaxisRange(double lower, double upper)
82 {
87 {
83 this->m_plot->xAxis->setRange(lower,upper);
88 this->m_plot->xAxis->setRange(lower,upper);
84 }
89 }
85
90
86 void SocExplorerPlot::setYaxisRange(double lower, double upper)
91 void SocExplorerPlot::setYaxisRange(double lower, double upper)
87 {
92 {
88 this->m_plot->yAxis->setRange(lower,upper);
93 this->m_plot->yAxis->setRange(lower,upper);
89 }
94 }
90
95
91
96
92 void SocExplorerPlot::rescaleAxis()
97 void SocExplorerPlot::rescaleAxis()
93 {
98 {
94 this->m_plot->rescaleAxes();
99 this->m_plot->rescaleAxes();
95 this->m_plot->replot();
100 this->m_plot->replot();
96 }
101 }
97
102
98 void SocExplorerPlot::setLegendFont(QFont font)
103 void SocExplorerPlot::setLegendFont(QFont font)
99 {
104 {
100 this->m_plot->legend->setFont(font);
105 this->m_plot->legend->setFont(font);
101 this->repaint();
106 this->repaint();
102 }
107 }
103
108
104 void SocExplorerPlot::setLegendSelectedFont(QFont font)
109 void SocExplorerPlot::setLegendSelectedFont(QFont font)
105 {
110 {
106 this->m_plot->legend->setSelectedFont(font);
111 this->m_plot->legend->setSelectedFont(font);
107 this->repaint();
112 this->repaint();
108 }
113 }
109
114
110 void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable)
115 void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable)
111 {
116 {
112 this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable);
117 this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable);
113 }
118 }
114
119
115 int SocExplorerPlot::addGraph()
120 int SocExplorerPlot::addGraph()
116 {
121 {
117 this->m_plot->addGraph();
122 this->m_plot->addGraph();
118 return this->m_plot->graphCount() -1;
123 return this->m_plot->graphCount() -1;
119 }
124 }
120
125
121 bool SocExplorerPlot::removeGraph(int graphIndex)
126 bool SocExplorerPlot::removeGraph(int graphIndex)
122 {
127 {
123 return this->m_plot->removeGraph(graphIndex);
128 return this->m_plot->removeGraph(graphIndex);
124 }
129 }
125
130
126 void SocExplorerPlot::removeAllGraphs()
131 void SocExplorerPlot::removeAllGraphs()
127 {
132 {
128 int graphCount=this->m_plot->graphCount();
133 int graphCount=this->m_plot->graphCount();
129 for(int i=0;i<graphCount;i++)
134 for(int i=0;i<graphCount;i++)
130 {
135 {
131 this->m_plot->removeGraph(0);
136 this->m_plot->removeGraph(0);
132 }
137 }
133 }
138 }
134
139
135
140
136 void SocExplorerPlot::setGraphName(int graphIndex,QString name)
141 void SocExplorerPlot::setGraphName(int graphIndex,QString name)
137 {
142 {
138 if(graphIndex<this->m_plot->graphCount())
143 if(graphIndex<this->m_plot->graphCount())
139 {
144 {
140 this->m_plot->graph(graphIndex)->setName(name);
145 this->m_plot->graph(graphIndex)->setName(name);
141 }
146 }
142 }
147 }
143
148
144
149
145 void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
150 void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
146 {
151 {
147 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double))
152 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double))
148 {
153 {
149 QVector<double> _x(x.count()), _y(y.count());
154 QVector<double> _x(x.count()), _y(y.count());
150 for(int i=0;i<x.count();i++)
155 for(int i=0;i<x.count();i++)
151 {
156 {
152 /*_x[i] = x.at(i).value<double>();
157 /*_x[i] = x.at(i).value<double>();
153 _y[i] = y.at(i).value<double>();*/
158 _y[i] = y.at(i).value<double>();*/
154 _x[i] = x.at(i).toDouble();
159 _x[i] = x.at(i).toDouble();
155 _y[i] = y.at(i).toDouble();
160 _y[i] = y.at(i).toDouble();
156 }
161 }
157 this->m_plot->graph(graphIndex)->setData(_x,_y);
162 this->m_plot->graph(graphIndex)->setData(_x,_y);
158 }
163 }
159 else
164 else
160 {
165 {
161 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime))
166 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime))
162 {
167 {
163 QVector<double> _x(x.count()), _y(y.count());
168 QVector<double> _x(x.count()), _y(y.count());
164 for(int i=0;i<x.count();i++)
169 for(int i=0;i<x.count();i++)
165 {
170 {
166 /*_x[i] = x.at(i).value<double>();
171 /*_x[i] = x.at(i).value<double>();
167 _y[i] = y.at(i).value<double>();*/
172 _y[i] = y.at(i).value<double>();*/
168 _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch();
173 _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch();
169 _y[i] = y.at(i).toDouble();
174 _y[i] = y.at(i).toDouble();
170 }
175 }
171 this->m_plot->graph(graphIndex)->setData(_x,_y);
176 this->m_plot->graph(graphIndex)->setData(_x,_y);
172 this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
177 this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
173 this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz");
178 this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz");
174
179
175 }
180 }
176 }
181 }
177 this->m_plot->replot();
182 this->m_plot->replot();
178 }
183 }
179
184
180 void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot)
185 void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot)
181 {
186 {
182 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
187 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
183 {
188 {
184 this->m_plot->graph(graphIndex)->setData(data,copy);
189 this->m_plot->graph(graphIndex)->setData(data,copy);
185 }
190 }
186 if(replot)
191 if(replot)
187 this->m_plot->replot();
192 this->m_plot->replot();
188 }
193 }
189
194
190 void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
195 void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
191 {
196 {
192 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
197 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
193 {
198 {
194 QVector<double> _x(x.count()), _y(y.count());
199 QVector<double> _x(x.count()), _y(y.count());
195 for(int i=0;i<x.count();i++)
200 for(int i=0;i<x.count();i++)
196 {
201 {
197 /*_x[i] = x.at(i).value<double>();
202 /*_x[i] = x.at(i).value<double>();
198 _y[i] = y.at(i).value<double>();*/
203 _y[i] = y.at(i).value<double>();*/
199 _x[i] = x.at(i).toDouble();
204 _x[i] = x.at(i).toDouble();
200 _y[i] = y.at(i).toDouble();
205 _y[i] = y.at(i).toDouble();
201 }
206 }
202 this->m_plot->graph(graphIndex)->addData(_x,_y);
207 this->m_plot->graph(graphIndex)->addData(_x,_y);
203 }
208 }
204 this->m_plot->replot();
209 this->m_plot->replot();
205 }
210 }
206
211
207 void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y)
212 void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y)
208 {
213 {
209 if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double))
214 if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double))
210 {
215 {
211 this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble());
216 this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble());
212 }
217 }
213 this->m_plot->replot();
218 this->m_plot->replot();
214 }
219 }
215
220
216 void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen)
221 void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen)
217 {
222 {
218 if(graphIndex<this->m_plot->graphCount())
223 if(graphIndex<this->m_plot->graphCount())
219 {
224 {
220 this->m_plot->graph(graphIndex)->setPen(pen);
225 this->m_plot->graph(graphIndex)->setPen(pen);
221 }
226 }
222 }
227 }
223
228
224 QPen SocExplorerPlot::getGraphPen(int graphIndex)
229 QPen SocExplorerPlot::getGraphPen(int graphIndex)
225 {
230 {
226 if(graphIndex<this->m_plot->graphCount())
231 if(graphIndex<this->m_plot->graphCount())
227 {
232 {
228 return this->m_plot->graph(graphIndex)->pen();
233 return this->m_plot->graph(graphIndex)->pen();
229 }
234 }
230 return this->m_plot->graph()->pen();
235 return this->m_plot->graph()->pen();
231 }
236 }
232
237
233
238
234
239
235 void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle)
240 void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle)
236 {
241 {
237 if(graphIndex<this->m_plot->graphCount())
242 if(graphIndex<this->m_plot->graphCount())
238 {
243 {
239 if(!lineStyle.compare("none"))
244 if(!lineStyle.compare("none"))
240 {
245 {
241 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone);
246 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone);
242 return;
247 return;
243 }
248 }
244 if(!lineStyle.compare("line"))
249 if(!lineStyle.compare("line"))
245 {
250 {
246 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine);
251 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine);
247 return;
252 return;
248 }
253 }
249 if(!lineStyle.compare("stepleft"))
254 if(!lineStyle.compare("stepleft"))
250 {
255 {
251 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft);
256 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft);
252 return;
257 return;
253 }
258 }
254 if(!lineStyle.compare("stepright"))
259 if(!lineStyle.compare("stepright"))
255 {
260 {
256 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight);
261 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight);
257 return;
262 return;
258 }
263 }
259 if(!lineStyle.compare("stepcenter"))
264 if(!lineStyle.compare("stepcenter"))
260 {
265 {
261 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter);
266 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter);
262 return;
267 return;
263 }
268 }
264 if(!lineStyle.compare("impulse"))
269 if(!lineStyle.compare("impulse"))
265 {
270 {
266 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse);
271 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse);
267 return;
272 return;
268 }
273 }
269
274
270
275
271 }
276 }
272 }
277 }
273
278
274 void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle)
279 void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle)
275 {
280 {
276 if(graphIndex<this->m_plot->graphCount())
281 if(graphIndex<this->m_plot->graphCount())
277 {
282 {
278 if(!scatterStyle.compare("none"))
283 if(!scatterStyle.compare("none"))
279 {
284 {
280 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone);
285 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone);
281 return;
286 return;
282 }
287 }
283 if(!scatterStyle.compare("dot"))
288 if(!scatterStyle.compare("dot"))
284 {
289 {
285 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot);
290 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot);
286 return;
291 return;
287 }
292 }
288 if(!scatterStyle.compare("cross"))
293 if(!scatterStyle.compare("cross"))
289 {
294 {
290 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross);
295 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross);
291 return;
296 return;
292 }
297 }
293 if(!scatterStyle.compare("plus"))
298 if(!scatterStyle.compare("plus"))
294 {
299 {
295 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus);
300 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus);
296 return;
301 return;
297 }
302 }
298 if(!scatterStyle.compare("circle"))
303 if(!scatterStyle.compare("circle"))
299 {
304 {
300 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle);
305 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle);
301 return;
306 return;
302 }
307 }
303 if(!scatterStyle.compare("disc"))
308 if(!scatterStyle.compare("disc"))
304 {
309 {
305 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc);
310 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc);
306 return;
311 return;
307 }
312 }
308 if(!scatterStyle.compare("square"))
313 if(!scatterStyle.compare("square"))
309 {
314 {
310 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare);
315 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare);
311 return;
316 return;
312 }
317 }
313 if(!scatterStyle.compare("diamond"))
318 if(!scatterStyle.compare("diamond"))
314 {
319 {
315 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond);
320 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond);
316 return;
321 return;
317 }
322 }
318 if(!scatterStyle.compare("star"))
323 if(!scatterStyle.compare("star"))
319 {
324 {
320 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar);
325 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar);
321 return;
326 return;
322 }
327 }
323 if(!scatterStyle.compare("triangle"))
328 if(!scatterStyle.compare("triangle"))
324 {
329 {
325 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle);
330 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle);
326 return;
331 return;
327 }
332 }
328 if(!scatterStyle.compare("invertedtriangle"))
333 if(!scatterStyle.compare("invertedtriangle"))
329 {
334 {
330 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted);
335 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted);
331 return;
336 return;
332 }
337 }
333 if(!scatterStyle.compare("crosssquare"))
338 if(!scatterStyle.compare("crosssquare"))
334 {
339 {
335 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare);
340 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare);
336 return;
341 return;
337 }
342 }
338 if(!scatterStyle.compare("plussquare"))
343 if(!scatterStyle.compare("plussquare"))
339 {
344 {
340 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare);
345 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare);
341 return;
346 return;
342 }
347 }
343 if(!scatterStyle.compare("crosscircle"))
348 if(!scatterStyle.compare("crosscircle"))
344 {
349 {
345 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle);
350 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle);
346 return;
351 return;
347 }
352 }
348 if(!scatterStyle.compare("pluscircle"))
353 if(!scatterStyle.compare("pluscircle"))
349 {
354 {
350 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle);
355 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle);
351 return;
356 return;
352 }
357 }
353 if(!scatterStyle.compare("peace"))
358 if(!scatterStyle.compare("peace"))
354 {
359 {
355 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace);
360 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace);
356 return;
361 return;
357 }
362 }
358
363
359 }
364 }
360 }
365 }
361
366
362 void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type)
367 void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type)
363 {
368 {
364 this->m_plot->xAxis->setTickLabelType(type);
369 this->m_plot->xAxis->setTickLabelType(type);
365 }
370 }
366
371
367 void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format)
372 void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format)
368 {
373 {
369 this->m_plot->xAxis->setDateTimeFormat(format);
374 this->m_plot->xAxis->setDateTimeFormat(format);
370 }
375 }
371
376
372
377
373
378
374
379
375
380
376 void SocExplorerPlot::keyPressEvent(QKeyEvent * event)
381 void SocExplorerPlot::keyPressEvent(QKeyEvent * event)
377 {
382 {
378 switch(event->key())
383 switch(event->key())
379 {
384 {
380 case Qt::Key_Control:
385 case Qt::Key_Control:
381 this->ctrl_hold = true;
386 this->ctrl_hold = true;
387 setCursor(Qt::CrossCursor);
382 break;
388 break;
383 case Qt::Key_Shift:
389 case Qt::Key_Shift:
384 this->shift_hold = true;
390 this->shift_hold = true;
385 break;
391 break;
386 case Qt::Key_M:
392 case Qt::Key_M:
387 this->rescaleAxis();
393 this->rescaleAxis();
388 break;
394 break;
389 case Qt::Key_Left:
395 case Qt::Key_Left:
390 if(!ctrl_hold)
396 if(!ctrl_hold)
391 {
397 {
392 move(-0.1,Qt::Horizontal);
398 move(-0.1,Qt::Horizontal);
393 }
399 }
394 else
400 else
395 {
401 {
396 zoom(2,this->width()/2,Qt::Horizontal);
402 zoom(2,this->width()/2,Qt::Horizontal);
397 }
403 }
398 break;
404 break;
399 case Qt::Key_Right:
405 case Qt::Key_Right:
400 if(!ctrl_hold)
406 if(!ctrl_hold)
401 {
407 {
402 move(0.1,Qt::Horizontal);
408 move(0.1,Qt::Horizontal);
403 }
409 }
404 else
410 else
405 {
411 {
406 zoom(0.5,this->width()/2,Qt::Horizontal);
412 zoom(0.5,this->width()/2,Qt::Horizontal);
407 }
413 }
408 break;
414 break;
409 case Qt::Key_Up:
415 case Qt::Key_Up:
410 if(!ctrl_hold)
416 if(!ctrl_hold)
411 {
417 {
412 move(0.1,Qt::Vertical);
418 move(0.1,Qt::Vertical);
413 }
419 }
414 else
420 else
415 {
421 {
416 zoom(0.5,this->height()/2,Qt::Vertical);
422 zoom(0.5,this->height()/2,Qt::Vertical);
417 }
423 }
418 break;
424 break;
419 case Qt::Key_Down:
425 case Qt::Key_Down:
420 if(!ctrl_hold)
426 if(!ctrl_hold)
421 {
427 {
422 move(-0.1,Qt::Vertical);
428 move(-0.1,Qt::Vertical);
423 }
429 }
424 else
430 else
425 {
431 {
426 zoom(2,this->height()/2,Qt::Vertical);
432 zoom(2,this->height()/2,Qt::Vertical);
427 }
433 }
428 break;
434 break;
429 default:
435 default:
430 QWidget::keyPressEvent(event);
436 QWidget::keyPressEvent(event);
431 break;
437 break;
432 }
438 }
433 }
439 }
434
440
435 void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event)
441 void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event)
436 {
442 {
437 switch(event->key())
443 switch(event->key())
438 {
444 {
439 case Qt::Key_Control:
445 case Qt::Key_Control:
440 event->accept();
446 event->accept();
441 this->ctrl_hold = false;
447 this->ctrl_hold = false;
442 break;
448 break;
443 case Qt::Key_Shift:
449 case Qt::Key_Shift:
444 event->accept();
450 event->accept();
445 this->shift_hold = false;
451 this->shift_hold = false;
446 break;
452 break;
447 default:
453 default:
448 QWidget::keyReleaseEvent(event);
454 QWidget::keyReleaseEvent(event);
449 break;
455 break;
450 }
456 }
457 setCursor(Qt::ArrowCursor);
451 }
458 }
452
459
453 void SocExplorerPlot::wheelEvent(QWheelEvent * event)
460 void SocExplorerPlot::wheelEvent(QWheelEvent * event)
454 {
461 {
455 double factor;
462 double factor;
456 double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
463 double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
457 if(ctrl_hold)
464 if(ctrl_hold)
458 {
465 {
459 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
466 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
460 {
467 {
468 setCursor(Qt::SizeVerCursor);
461 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
469 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
462 zoom(factor,event->pos().y(),Qt::Vertical);
470 zoom(factor,event->pos().y(),Qt::Vertical);
463 }
471 }
464 QWidget::wheelEvent(event);
472 QWidget::wheelEvent(event);
465 return;
473 return;
466 }
474 }
467 if(shift_hold)
475 if(shift_hold)
468 {
476 {
469 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
477 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
470 {
478 {
479 setCursor(Qt::SizeHorCursor);
471 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
480 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
472 zoom(factor,event->pos().x(),Qt::Horizontal);
481 zoom(factor,event->pos().x(),Qt::Horizontal);
473 }
482 }
474 QWidget::wheelEvent(event);
483 QWidget::wheelEvent(event);
475 return;
484 return;
476 }
485 }
477 move(wheelSteps/10,Qt::Horizontal);
486 move(wheelSteps/10,Qt::Horizontal);
478 QWidget::wheelEvent(event);
487 QWidget::wheelEvent(event);
479 }
488 }
480
489
481
490
482
491
483
492
484 void SocExplorerPlot::mousePressEvent(QMouseEvent *event)
493 void SocExplorerPlot::mousePressEvent(QMouseEvent *event)
485 {
494 {
486 if(event->button()==Qt::LeftButton)
495 if(event->button()==Qt::LeftButton)
487 {
496 {
488 mDragStart = event->pos();
497 if(ctrl_hold)
489 this->mouse_hold = true;
498 {
490 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
499 setCursor(Qt::CrossCursor);
491 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
500 mOrigin = event->pos();
501 mRubberBand->setGeometry(QRect(mOrigin, QSize()));
502 mRubberBand->show();
503 }
504 else
505 {
506 setCursor(Qt::ClosedHandCursor);
507 mDragStart = event->pos();
508 this->mouse_hold = true;
509 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
510 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
511 }
492 }
512 }
493 QWidget::mousePressEvent(event);
513 QWidget::mousePressEvent(event);
494 }
514 }
495
515
496 void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event)
516 void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event)
497 {
517 {
498 if(event->button()==Qt::LeftButton)
518 if(event->button()==Qt::LeftButton)
499 {
519 {
500 this->mouse_hold = false;
520 this->mouse_hold = false;
501 }
521 }
522 if (mRubberBand->isVisible())
523 {
524 const QRect & zoomRect = mRubberBand->geometry();
525 int xp1, yp1, xp2, yp2;
526 zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
527 double x1 = this->m_plot->xAxis->pixelToCoord(xp1);
528 double x2 = this->m_plot->xAxis->pixelToCoord(xp2);
529 double y1 = this->m_plot->yAxis->pixelToCoord(yp1);
530 double y2 = this->m_plot->yAxis->pixelToCoord(yp2);
531
532 this->m_plot->xAxis->setRange(x1, x2);
533 this->m_plot->yAxis->setRange(y1, y2);
534
535 mRubberBand->hide();
536 this->m_plot->replot();
537 }
538 setCursor(Qt::ArrowCursor);
502 QWidget::mouseReleaseEvent(event);
539 QWidget::mouseReleaseEvent(event);
503 }
540 }
504
541
505 void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation)
542 void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation)
506 {
543 {
507 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation);
544 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation);
508 axis->scaleRange(factor, axis->pixelToCoord(center));
545 axis->scaleRange(factor, axis->pixelToCoord(center));
509 this->m_plot->replot();
546 this->m_plot->replot();
510 }
547 }
511
548
512 void SocExplorerPlot::move(double factor, Qt::Orientation orientation)
549 void SocExplorerPlot::move(double factor, Qt::Orientation orientation)
513 {
550 {
514 QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation);
551 QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation);
515 double rg = (axis->range().upper - axis->range().lower)*(factor);
552 double rg = (axis->range().upper - axis->range().lower)*(factor);
516 axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
553 axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
517 this->m_plot->replot();
554 this->m_plot->replot();
518 }
555 }
519
556
520
557
521 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
558 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
522 {
559 {
523 if(mouse_hold)
560 if(mouse_hold)
524 {
561 {
525 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
562 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
526 QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
563 QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
527 double diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x());
564 double diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x());
528 Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff);
565 Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff);
529 diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y());
566 diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y());
530 Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff);
567 Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff);
531 this->m_plot->replot();
568 this->m_plot->replot();
532 }
569 }
570 if (mRubberBand->isVisible())
571 {
572 mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized());
573 }
533 QWidget::mouseMoveEvent(event);
574 QWidget::mouseMoveEvent(event);
534 }
575 }
535
576
536
577
537
578
538
579
539
580
540
581
541
582
542
583
543
584
544
585
545
586
@@ -1,85 +1,91
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef SOCEXPLORERPLOT_H
22 #ifndef SOCEXPLORERPLOT_H
23 #define SOCEXPLORERPLOT_H
23 #define SOCEXPLORERPLOT_H
24
24
25 #include <QWidget>
25 #include <QWidget>
26 #include <QGridLayout>
26 #include <QGridLayout>
27 #include <qcustomplot.h>
27 #include <qcustomplot.h>
28 #include <QRubberBand>
29 #include <QPoint>
28
30
29 class SocExplorerPlot : public QWidget
31 class SocExplorerPlot : public QWidget
30 {
32 {
31 Q_OBJECT
33 Q_OBJECT
32 public:
34 public:
33 explicit SocExplorerPlot(QWidget *parent = 0);
35 explicit SocExplorerPlot(QWidget *parent = 0);
36 ~SocExplorerPlot();
34 void setTitle(QString title);
37 void setTitle(QString title);
35 void setXaxisLabel(QString label);
38 void setXaxisLabel(QString label);
36 void setXaxisRange(double lower, double upper);
39 void setXaxisRange(double lower, double upper);
37 void setYaxisLabel(QString label);
40 void setYaxisLabel(QString label);
38 void setYaxisRange(double lower, double upper);
41 void setYaxisRange(double lower, double upper);
39 void rescaleAxis();
42 void rescaleAxis();
40 void setLegendFont(QFont font);
43 void setLegendFont(QFont font);
41 void setLegendSelectedFont(QFont font);
44 void setLegendSelectedFont(QFont font);
42 void setAdaptativeSampling(int graphIndex,bool enable);
45 void setAdaptativeSampling(int graphIndex,bool enable);
43 int addGraph();
46 int addGraph();
44 bool removeGraph(int graphIndex);
47 bool removeGraph(int graphIndex);
45 void removeAllGraphs();
48 void removeAllGraphs();
46 void setGraphName(int graphIndex,QString name);
49 void setGraphName(int graphIndex,QString name);
47 void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
50 void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
48 void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true);
51 void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true);
49 void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
52 void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
50 void addGraphData(int graphIndex, QVariant x, QVariant y);
53 void addGraphData(int graphIndex, QVariant x, QVariant y);
51 void setGraphPen(int graphIndex,QPen pen);
54 void setGraphPen(int graphIndex,QPen pen);
52 QPen getGraphPen(int graphIndex);
55 QPen getGraphPen(int graphIndex);
53 void setGraphLineStyle(int graphIndex,QString lineStyle);
56 void setGraphLineStyle(int graphIndex,QString lineStyle);
54 void setGraphScatterStyle(int graphIndex,QString scatterStyle);
57 void setGraphScatterStyle(int graphIndex,QString scatterStyle);
55 void setXaxisTickLabelType(QCPAxis::LabelType type);
58 void setXaxisTickLabelType(QCPAxis::LabelType type);
56 void setXaxisDateTimeFormat(const QString &format);
59 void setXaxisDateTimeFormat(const QString &format);
57 void show();
60 void show();
58 void replot();
61 void replot();
59
62
60 signals:
63 signals:
61
64
62 public slots:
65 public slots:
63
66
64 protected:
67 protected:
65 void keyPressEvent(QKeyEvent *);
68 void keyPressEvent(QKeyEvent *);
66 void keyReleaseEvent(QKeyEvent *);
69 void keyReleaseEvent(QKeyEvent *);
67 void wheelEvent(QWheelEvent *);
70 void wheelEvent(QWheelEvent *);
68 void mousePressEvent(QMouseEvent *);
71 void mousePressEvent(QMouseEvent *);
69 void mouseMoveEvent(QMouseEvent *);
72 void mouseMoveEvent(QMouseEvent *);
70 void mouseReleaseEvent(QMouseEvent *);
73 void mouseReleaseEvent(QMouseEvent *);
71
74
72 private:
75 private:
73 void zoom(double factor, int center, Qt::Orientation orientation);
76 void zoom(double factor, int center, Qt::Orientation orientation);
74 void move(double factor, Qt::Orientation orientation);
77 void move(double factor, Qt::Orientation orientation);
75 QCustomPlot* m_plot;
78 QCustomPlot* m_plot;
76 QGridLayout* m_mainlayout;
79 QGridLayout* m_mainlayout;
77 bool ctrl_hold;
80 bool ctrl_hold;
78 bool shift_hold;
81 bool shift_hold;
79 bool mouse_hold;
82 bool mouse_hold;
80 QCPRange DragStartHorzRange;
83 QCPRange DragStartHorzRange;
81 QCPRange DragStartVertRange;
84 QCPRange DragStartVertRange;
82 QPoint mDragStart;
85 QPoint mDragStart;
86 bool mZoomMode;
87 QRubberBand * mRubberBand;
88 QPoint mOrigin;
83 };
89 };
84
90
85 #endif // SOCEXPLORERPLOT_H
91 #endif // SOCEXPLORERPLOT_H
@@ -1,228 +1,232
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "mainwindow.h"
22 #include "mainwindow.h"
23 #include "ui_mainwindow.h"
23 #include "ui_mainwindow.h"
24 #include <QFileDialog>
24 #include <QFileDialog>
25 #include <QDir>
25 #include <QDir>
26 #include "qcustomplot.h"
26 #include "qcustomplot.h"
27 #include "filedownloader.h"
27 #include "filedownloader.h"
28 #include <omp.h>
28 #include <omp.h>
29
29
30 MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) :
30 MainWindow::MainWindow(int OMP_THREADS, QWidget *parent) :
31 QMainWindow(parent),
31 QMainWindow(parent),
32 ui(new Ui::MainWindow)
32 ui(new Ui::MainWindow)
33 {
33 {
34 this->OMP_THREADS = OMP_THREADS;
34 this->OMP_THREADS = OMP_THREADS;
35 ui->setupUi(this);
35 ui->setupUi(this);
36
36
37 connect(this->ui->addViewerQpb,SIGNAL(clicked()),this,SLOT(addFolderView()));
37 connect(this->ui->addViewerQpb,SIGNAL(clicked()),this,SLOT(addFolderView()));
38 connect(&this->fileReader,SIGNAL(dataReady(QCPDataMap*,QCPDataMap*,QCPDataMap*)),this,SLOT(dataReady(QCPDataMap*,QCPDataMap*,QCPDataMap*)));
38 connect(&this->fileReader,SIGNAL(dataReady(QCPDataMap*,QCPDataMap*,QCPDataMap*)),this,SLOT(dataReady(QCPDataMap*,QCPDataMap*,QCPDataMap*)));
39 connect(this->ui->calendar,SIGNAL(activated(QDate)),this,SLOT(downloadData(QDate)));
39 connect(this->ui->calendar,SIGNAL(activated(QDate)),this,SLOT(downloadData(QDate)));
40 for(int i=0;i<3;i++)
40 for(int i=0;i<3;i++)
41 {
41 {
42 this->ui->Plot->addGraph();
42 this->ui->Plot->addGraph();
43 this->ui->Plot->setAdaptativeSampling(i,true);
43 this->ui->Plot->setAdaptativeSampling(i,true);
44 }
44 }
45 QPen pen = this->ui->Plot->getGraphPen(0);
45 QPen pen = this->ui->Plot->getGraphPen(0);
46 pen.setColor(Qt::blue);
46 pen.setColor(Qt::blue);
47 this->ui->Plot->setGraphPen(0,pen);
47 this->ui->Plot->setGraphPen(0,pen);
48 pen.setColor(Qt::red);
48 pen.setColor(Qt::red);
49 this->ui->Plot->setGraphPen(1,pen);
49 this->ui->Plot->setGraphPen(1,pen);
50 pen.setColor(Qt::black);
50 pen.setColor(Qt::black);
51 this->ui->Plot->setGraphPen(2,pen);
51 this->ui->Plot->setGraphPen(2,pen);
52 this->ui->Plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
52 this->ui->Plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
53 this->ui->Plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
53 this->ui->Plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
54 this->progressWidget = new QWidget();
54 this->progressWidget = new QWidget();
55 this->progressLayout = new QVBoxLayout(this->progressWidget);
55 this->progressLayout = new QVBoxLayout(this->progressWidget);
56 this->progressWidget->setLayout(this->progressLayout);
56 this->progressWidget->setLayout(this->progressLayout);
57 this->progressWidget->setWindowModality(Qt::WindowModal);
57 this->progressWidget->setWindowModality(Qt::WindowModal);
58 progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
58 progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int));
59 for(int i=0;i<OMP_THREADS;i++)
59 for(int i=0;i<OMP_THREADS;i++)
60 {
60 {
61 this->progress.append(new QProgressBar(this->progressWidget));
61 this->progress.append(new QProgressBar(this->progressWidget));
62 this->progress.last()->setMinimum(0);
62 this->progress.last()->setMinimum(0);
63 this->progress.last()->setMaximum(100);
63 this->progress.last()->setMaximum(100);
64 connect(&this->fileReader,SIGNAL(updateProgress(int,int)),this,SLOT(updateProgress(int,int)));
64 connect(&this->fileReader,SIGNAL(updateProgress(int,int)),this,SLOT(updateProgress(int,int)));
65 this->progressLayout->addWidget(this->progress.last());
65 this->progressLayout->addWidget(this->progress.last());
66 this->progressWidget->hide();
66 this->progressWidget->hide();
67 this->progressThreadIds[i] = -1;
67 this->progressThreadIds[i] = -1;
68 }
68 }
69 this->progressWidget->setWindowTitle("Loading File");
69 this->progressWidget->setWindowTitle("Loading File");
70 }
70 }
71
71
72 MainWindow::~MainWindow()
72 MainWindow::~MainWindow()
73 {
73 {
74 delete ui;
74 delete ui;
75 }
75 }
76
76
77 QString MainWindow::getFilePath(const QString &name)
77 QString MainWindow::getFilePath(const QString &name)
78 {
78 {
79 for(int i=0;i<this->folderViews.count();i++)
79 for(int i=0;i<this->folderViews.count();i++)
80 {
80 {
81 if(folderViews.at(i)->isDraging(name))
81 if(folderViews.at(i)->isDraging(name))
82 return folderViews.at(i)->currentFolder();
82 return folderViews.at(i)->currentFolder();
83 }
83 }
84 return "";
84 return "";
85 }
85 }
86
86
87
87
88 void MainWindow::itemDoubleClicked(QListWidgetItem* item)
88 void MainWindow::itemDoubleClicked(QListWidgetItem* item)
89 {
89 {
90 if(item)
90 if(item)
91 {
91 {
92 plotFile(item->text());
92 plotFile(item->text());
93 }
93 }
94 }
94 }
95
95
96 void MainWindow::plotFile(const QString &File)
96 void MainWindow::plotFile(const QString &File)
97 {
97 {
98 if(!fileReader.isRunning())
98 if(!fileReader.isRunning())
99 {
99 {
100 for(int i=0;i<OMP_THREADS;i++)
100 for(int i=0;i<OMP_THREADS;i++)
101 {
101 {
102 this->progress.at(i)->setValue(0);
102 this->progress.at(i)->setValue(0);
103 }
103 }
104 this->progressWidget->show();
104 this->progressWidget->show();
105 fileReader.parseFile(File);
105 fileReader.parseFile(File);
106 this->ui->Plot->setTitle(File);
106 }
107 }
107 }
108 }
108
109
109 void MainWindow::dataReady(QCPDataMap *ch1, QCPDataMap *ch2, QCPDataMap *ch3)
110 void MainWindow::dataReady(QCPDataMap *ch1, QCPDataMap *ch2, QCPDataMap *ch3)
110 {
111 {
111 for(int i=0;i<OMP_THREADS;i++)
112 for(int i=0;i<OMP_THREADS;i++)
112 {
113 {
113 progressThreadIds[i]=-1;
114 progressThreadIds[i]=-1;
114 }
115 }
115 this->progressWidget->hide();
116 this->progressWidget->hide();
116 this->ui->Plot->setGraphName(0,"MAG_X");
117 this->ui->Plot->setGraphName(0,"MAG_X");
117 this->ui->Plot->setGraphName(1,"MAG_Y");
118 this->ui->Plot->setGraphName(1,"MAG_Y");
118 this->ui->Plot->setGraphName(2,"MAG_Z");
119 this->ui->Plot->setGraphName(2,"MAG_Z");
119 this->ui->Plot->setGraphData(0,ch1,false,false);
120 this->ui->Plot->setGraphData(0,ch1,false,false);
120 this->ui->Plot->setGraphData(1,ch2,false,false);
121 this->ui->Plot->setGraphData(1,ch2,false,false);
121 this->ui->Plot->setGraphData(2,ch3,false,false);
122 this->ui->Plot->setGraphData(2,ch3,false,false);
122 this->ui->Plot->rescaleAxis();
123 this->ui->Plot->rescaleAxis();
123 this->ui->Plot->replot();
124 this->ui->Plot->replot();
124 }
125 }
125
126
126 void MainWindow::downloadData(const QDate & date )
127 void MainWindow::downloadData(const QDate & date )
127 {
128 {
128 QDate tmpDate;
129 QDate tmpDate;
129 QStringList months=QStringList()<< "JAN" << "FEB" << "MAR" << "APR" << "MAY" << "JUN" << "JUI" << "AUG" << "SEP" << "OCT" << "NOV" << "DEC";
130 QStringList months=QStringList()<< "JAN" << "FEB" << "MAR" << "APR" << "MAY" << "JUN" << "JUI" << "AUG" << "SEP" << "OCT" << "NOV" << "DEC";
130 tmpDate.setDate(date.year(),date.month(),1);
131 tmpDate.setDate(date.year(),date.month(),1);
131 int firstDayOfMonth=tmpDate.dayOfYear();
132 int firstDayOfMonth=tmpDate.dayOfYear();
132 tmpDate.setDate(tmpDate.year(),tmpDate.month(),tmpDate.daysInMonth());
133 tmpDate.setDate(tmpDate.year(),tmpDate.month(),tmpDate.daysInMonth());
133 int lastDayOfMonth=tmpDate.dayOfYear();
134 int lastDayOfMonth=tmpDate.dayOfYear();
134 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/" \
135 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/" \
135 + QString("%1").arg(date.year()) +"/" + QString("%1_%2_").arg(firstDayOfMonth,3).arg(lastDayOfMonth,3).replace(' ','0') \
136 + QString("%1").arg(date.year()) +"/" + QString("%1_%2_").arg(firstDayOfMonth,3).arg(lastDayOfMonth,3).replace(' ','0') \
136 + months.at(date.month()-1) + "/" ;
137 + months.at(date.month()-1) + "/" ;
137 qDebug()<<link;
138 qDebug()<<link;
138 QString dataFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.TAB";
139 QString dataFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.TAB";
139 QString headerFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.LBL";
140 QString headerFileName= QString("%1%2").arg(date.year()-2000,2).arg(date.dayOfYear(),3).replace(' ','0') + "_FGM_KRTP.LBL";
140 // "_FGM_KRTP.TAB"
141 // "_FGM_KRTP.TAB"
141 FileDownloader* dataFile = new FileDownloader(QUrl(link + dataFileName),dataFileName,this);
142 FileDownloader* dataFile = new FileDownloader(QUrl(link + dataFileName),dataFileName,this);
142 FileDownloader* headerFile = new FileDownloader(QUrl(link + headerFileName),headerFileName,this);
143 FileDownloader* headerFile = new FileDownloader(QUrl(link + headerFileName),headerFileName,this);
143 this->ui->DownloadListLayout->addWidget(dataFile->getProgressBar());
144 this->ui->DownloadListLayout->addWidget(dataFile->getProgressBar());
144 this->ui->DownloadListLayout->addWidget(headerFile->getProgressBar());
145 this->ui->DownloadListLayout->addWidget(headerFile->getProgressBar());
145 this->pendingDownloads.append(dataFile);
146 this->pendingDownloads.append(dataFile);
146 this->pendingDownloads.append(headerFile);
147 this->pendingDownloads.append(headerFile);
147 connect(dataFile,SIGNAL(downloaded()),this,SLOT(fileDownloadComplete()));
148 connect(dataFile,SIGNAL(downloaded()),this,SLOT(fileDownloadComplete()));
148 connect(headerFile,SIGNAL(downloaded()),this,SLOT(fileDownloadComplete()));
149 connect(headerFile,SIGNAL(downloaded()),this,SLOT(fileDownloadComplete()));
149 }
150 }
150
151
151 void MainWindow::updateProgress(int threadId, int percentProgress)
152 void MainWindow::updateProgress(int threadId, int percentProgress)
152 {
153 {
153 bool updated=false;
154 bool updated=false;
154 for(int i=0;i<OMP_THREADS;i++)
155 for(int i=0;i<OMP_THREADS;i++)
155 {
156 {
156 if(progressThreadIds[i]==threadId)
157 if(progressThreadIds[i]==threadId)
157 {
158 {
158 this->progress.at(threadId)->setValue(percentProgress);
159 if(threadId<this->progress.count())
159 updated=true;
160 {
161 this->progress.at(threadId)->setValue(percentProgress);
162 updated=true;
163 }
160 }
164 }
161 }
165 }
162 if(Q_UNLIKELY(updated==false))
166 if(Q_UNLIKELY(updated==false))
163 {
167 {
164 for(int i=0;i<OMP_THREADS;i++)
168 for(int i=0;i<OMP_THREADS;i++)
165 {
169 {
166 if(progressThreadIds[i]==-1)
170 if(progressThreadIds[i]==-1)
167 {
171 {
168 progressThreadIds[i] = threadId;
172 progressThreadIds[i] = threadId;
169 updateProgress(threadId,percentProgress);
173 updateProgress(threadId,percentProgress);
170 }
174 }
171 }
175 }
172 }
176 }
173 }
177 }
174
178
175 void MainWindow::addFolderView()
179 void MainWindow::addFolderView()
176 {
180 {
177 this->folderViews.append(new FolderView(this));
181 this->folderViews.append(new FolderView(this));
178 this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last());
182 this->ui->folderViews->addDockWidget(Qt::TopDockWidgetArea,this->folderViews.last());
179 this->folderViews.last()->setWindowTitle( QString("Folder View %1").arg(this->folderViews.length()));
183 this->folderViews.last()->setWindowTitle( QString("Folder View %1").arg(this->folderViews.length()));
180 this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas);
184 this->folderViews.last()->setAllowedAreas(Qt::AllDockWidgetAreas);
181 connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString)));
185 connect(this->folderViews.last(),SIGNAL(itemActivated(QString)),this,SLOT(plotFile(QString)));
182
186
183 }
187 }
184
188
185 void MainWindow::fileDownloadComplete()
189 void MainWindow::fileDownloadComplete()
186 {
190 {
187 for(int i=0;i<this->pendingDownloads.count();i++)
191 for(int i=0;i<this->pendingDownloads.count();i++)
188 {
192 {
189 if(pendingDownloads.at(i)->downloadComplete())
193 if(pendingDownloads.at(i)->downloadComplete())
190 {
194 {
191 if(200<pendingDownloads.at(i)->donloadedDataSize())
195 if(200<pendingDownloads.at(i)->donloadedDataSize())
192 {
196 {
193 QFile file(QDir::homePath() +"/TΓ©lΓ©chargements/"+ pendingDownloads.at(i)->fileName());
197 QFile file(QDir::homePath() +"/TΓ©lΓ©chargements/"+ pendingDownloads.at(i)->fileName());
194 file.open(QIODevice::WriteOnly);
198 file.open(QIODevice::WriteOnly);
195 if(file.isOpen())
199 if(file.isOpen())
196 {
200 {
197 file.write(pendingDownloads.at(i)->downloadedData());
201 file.write(pendingDownloads.at(i)->downloadedData());
198 file.flush();
202 file.flush();
199 file.close();
203 file.close();
200
204
201 }
205 }
202 }
206 }
203 pendingDownloads.at(i)->clearData();
207 pendingDownloads.at(i)->clearData();
204 pendingDownloads.removeAt(i);
208 pendingDownloads.removeAt(i);
205 i--;
209 i--;
206 }
210 }
207 }
211 }
208 }
212 }
209
213
210 void MainWindow::askGlobalRescan()
214 void MainWindow::askGlobalRescan()
211 {
215 {
212 for(int i=0;i<this->folderViews.count();i++)
216 for(int i=0;i<this->folderViews.count();i++)
213 {
217 {
214 this->folderViews.at(i)->refreshFolder();
218 this->folderViews.at(i)->refreshFolder();
215 }
219 }
216 }
220 }
217
221
218 void MainWindow::changeEvent(QEvent *e)
222 void MainWindow::changeEvent(QEvent *e)
219 {
223 {
220 QMainWindow::changeEvent(e);
224 QMainWindow::changeEvent(e);
221 switch (e->type()) {
225 switch (e->type()) {
222 case QEvent::LanguageChange:
226 case QEvent::LanguageChange:
223 ui->retranslateUi(this);
227 ui->retranslateUi(this);
224 break;
228 break;
225 default:
229 default:
226 break;
230 break;
227 }
231 }
228 }
232 }
@@ -1,201 +1,186
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "themisdatafile.h"
22 #include "themisdatafile.h"
23 #include <QFile>
23 #include <QFile>
24 #include <stdio.h>
24 #include <stdio.h>
25 #include <QDateTime>
25 #include <QDateTime>
26 #include <QVector>
26 #include <QVector>
27 #include <QProgressDialog>
27 #include <QProgressDialog>
28 #include <omp.h>
28 #include <omp.h>
29 #include <QTimer>
29 #include <QTimer>
30 #include <QElapsedTimer>
30 #include <QElapsedTimer>
31 #include <time.h>
31 #include <sys/time.h>
32
32
33 ThemisDataFile::ThemisDataFile(QObject *parent) : QThread(parent)
33 ThemisDataFile::ThemisDataFile(QObject *parent) : QThread(parent)
34 {
34 {
35 }
35 }
36
36
37 ThemisDataFile::~ThemisDataFile()
37 ThemisDataFile::~ThemisDataFile()
38 {
38 {
39
39
40 }
40 }
41
41
42 void ThemisDataFile::parseFile(const QString &fileName)
42 void ThemisDataFile::parseFile(const QString &fileName)
43 {
43 {
44 this->fileName = fileName;
44 this->fileName = fileName;
45 this->start();
45 this->start();
46 }
46 }
47
47
48 inline double __decodeVal(int ofset,unsigned char* data)
48 inline double __decodeVal(int ofset,unsigned char* data)
49 {
49 {
50 if(data[ofset]=='-')
50 if(data[ofset]=='-')
51 return -0.001 * (double)(
51 return -0.001 * (double)(
52 (10000 * (int)(data[ofset+1] & 0x0F))
52 (10000 * (int)(data[ofset+1] & 0x0F))
53 + (1000 * (int)(data[ofset+2] & 0x0F))
53 + (1000 * (int)(data[ofset+2] & 0x0F))
54 + (100 * (int)(data[ofset+4] & 0x0F))
54 + (100 * (int)(data[ofset+4] & 0x0F))
55 + (10 * (int)(data[ofset+5] & 0x0F))
55 + (10 * (int)(data[ofset+5] & 0x0F))
56 + ( (int)(data[ofset+6] & 0x0F))
56 + ( (int)(data[ofset+6] & 0x0F))
57 );
57 );
58 else
58 else
59 {
59 {
60 if(data[ofset+1]=='-')
60 if(data[ofset+1]=='-')
61 {
61 {
62 return -0.001 * (double)(
62 return -0.001 * (double)(
63 (1000 * (int)(data[ofset+2] & 0x0F))
63 (1000 * (int)(data[ofset+2] & 0x0F))
64 + (100 * (int)(data[ofset+4] & 0x0F))
64 + (100 * (int)(data[ofset+4] & 0x0F))
65 + (10 * (int)(data[ofset+5] & 0x0F))
65 + (10 * (int)(data[ofset+5] & 0x0F))
66 + ( (int)(data[ofset+6] & 0x0F))
66 + ( (int)(data[ofset+6] & 0x0F))
67 );
67 );
68 }
68 }
69 else
69 else
70 {
70 {
71 return 0.001 * (double)(
71 return 0.001 * (double)(
72 (10000 * (int)(data[ofset+1] & 0x0F))
72 (10000 * (int)(data[ofset+1] & 0x0F))
73 + (1000 * (int)(data[ofset+2] & 0x0F))
73 + (1000 * (int)(data[ofset+2] & 0x0F))
74 + (100 * (int)(data[ofset+4] & 0x0F))
74 + (100 * (int)(data[ofset+4] & 0x0F))
75 + (10 * (int)(data[ofset+5] & 0x0F))
75 + (10 * (int)(data[ofset+5] & 0x0F))
76 + ( (int)(data[ofset+6] & 0x0F))
76 + ( (int)(data[ofset+6] & 0x0F))
77 );
77 );
78 }
78 }
79 }
79 }
80 }
80 }
81
81
82 inline QDate __decodeDate(int ofset,unsigned char* data)
82 inline QDate __decodeDate(int ofset,unsigned char* data)
83 {
83 {
84 int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F));
84 int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F));
85 int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F));
85 int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F));
86 int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F));
86 int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F));
87 return QDate(y,m,d);
87 return QDate(y,m,d);
88 }
88 }
89
89
90 inline QTime __decodeTime(int ofset,unsigned char* data)
90 inline QTime __decodeTime(int ofset,unsigned char* data)
91 {
91 {
92 int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F));
92 int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F));
93 int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F));
93 int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F));
94 int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F));
94 int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F));
95 int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F));
95 int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F));
96 return QTime(h,m,s,ms);
96 return QTime(h,m,s,ms);
97 }
97 }
98
98
99 double __decodeTimeFromEpochMs(int ofset,unsigned char* data)
99 double __decodeTimeFromEpochMs(int ofset,unsigned char* data)
100 {
100 {
101 struct tm t;
101 struct tm t;
102 time_t t_of_day;
102 time_t t_of_day;
103 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
103 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
104 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
104 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
105 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
105 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
106 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
106 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
107 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
107 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
108 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
108 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
109 int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
109 int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
110 t_of_day = mktime(&t);
110 t_of_day = mktime(&t);
111 return (t_of_day*1000.0)+ms;
111 return (t_of_day*1000.0)+ms;
112 }
112 }
113
113
114 double __decodeTimeFromEpoch(int ofset,unsigned char* data)
114 double __decodeTimeFromEpoch(int ofset,unsigned char* data)
115 {
115 {
116 struct tm t;
116 struct tm t;
117 time_t t_of_day;
117 time_t t_of_day;
118 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
118 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
119 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
119 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
120 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
120 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
121 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
121 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
122 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
122 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
123 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
123 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
124 int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
124 double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
125 t_of_day = mktime(&t);
125 t_of_day = mktime(&t);
126 return t_of_day+(ms*0.001);
126 return (double)t_of_day+((double)ms*(double)0.001);
127 }
127 }
128 void ThemisDataFile::run()
128 void ThemisDataFile::run()
129 {
129 {
130 FILE* dataFile;
130 FILE* dataFile;
131 dataFile = fopen(fileName.toStdString().c_str(),"r");
131 dataFile = fopen(fileName.toStdString().c_str(),"r");
132 QCPDataMap *ch1=new QCPDataMap();
132 QCPDataMap *ch1=new QCPDataMap();
133 QCPDataMap *ch2=new QCPDataMap();
133 QCPDataMap *ch2=new QCPDataMap();
134 QCPDataMap *ch3=new QCPDataMap();
134 QCPDataMap *ch3=new QCPDataMap();
135 QElapsedTimer timr;
135 QElapsedTimer timr;
136
136
137 double _x=0.0;
137 double _x=0.0;
138 char* line;
138 char* line;
139 QCPData data1,data2,data3;
139 QCPData data1,data2,data3;
140 if(dataFile != NULL)
140 if(dataFile != NULL)
141 {
141 {
142 fseek(dataFile, 0L, SEEK_END);
142 fseek(dataFile, 0L, SEEK_END);
143 int FileSize=ftell(dataFile);
143 int FileSize=ftell(dataFile);
144 int lineCnt = FileSize/58;
144 int lineCnt = FileSize/58;
145 int curLine=0;
145 int curLine=0;
146 int lastLineUpdate=0;
146 int lastLineUpdate=0;
147 int threadIndex,numThreads=omp_get_num_threads();
148 char* fileContent=(char*)malloc(FileSize);
147 char* fileContent=(char*)malloc(FileSize);
149 if(Q_UNLIKELY(fileContent==NULL))return;
148 if(Q_UNLIKELY(fileContent==NULL))return;
150 fseek(dataFile, 0L, SEEK_SET);
149 fseek(dataFile, 0L, SEEK_SET);
151 char* svglocale=NULL;
150 char* svglocale=NULL;
152 setlocale(LC_NUMERIC,svglocale);
151 setlocale(LC_NUMERIC,svglocale);
153 setlocale(LC_NUMERIC, "en_US");
152 setlocale(LC_NUMERIC, "en_US");
154 if(fread(fileContent,1,FileSize,dataFile))
153 if(fread(fileContent,1,FileSize,dataFile))
155 {
154 {
156 line = fileContent;
155 line = fileContent;
157 if(FileSize > 10000000)
158 {
159 lineCnt/=numThreads;
160 }
161 QDateTime date;
156 QDateTime date;
162 timr.start();
157 timr.start();
163 #pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt)
158 for(int i=0;i<(FileSize/(58));i++)
164 {
159 {
165 threadIndex = omp_get_thread_num();
160 // _x= i;
166 #pragma omp for
161 _x= __decodeTimeFromEpoch((i*58),(unsigned char*)line);
167 for(int i=0;i<(FileSize/(58));i++)
162 data1.key=_x;
168 {
163 data2.key=_x;
169 _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line);
164 data3.key=_x;
170 data1.key=_x;
165 data1.value=__decodeVal(((i*58)+27),(unsigned char*)line);
171 data2.key=_x;
166 data2.value=__decodeVal(((i*58)+38),(unsigned char*)line);
172 data3.key=_x;
167 data3.value=__decodeVal(((i*58)+49),(unsigned char*)line);
173 data1.value=__decodeVal(((i*58)+27),(unsigned char*)line);
168 ch1->insertMulti(_x,data1);
174 data2.value=__decodeVal(((i*58)+38),(unsigned char*)line);
169 ch2->insertMulti(_x,data2);
175 data3.value=__decodeVal(((i*58)+49),(unsigned char*)line);
170 ch3->insertMulti(_x,data3);
176 #pragma omp critical
171 curLine++;
172 if(lastLineUpdate++>8000)
177 {
173 {
178 ch1->insertMulti(_x,data1);
174 lastLineUpdate=0;
179 ch2->insertMulti(_x,data2);
175 int test=(curLine *100/ (lineCnt));
180 ch3->insertMulti(_x,data3);
176 emit updateProgress(0,test);
181 }
177 }
182 curLine++;
178 }
183 if(lastLineUpdate++>8000)
184 {
185 lastLineUpdate=0;
186 int test=(curLine *100/ (lineCnt));
187 emit updateProgress(threadIndex,test);
188 }
189 }
190 #pragma omp barrier
191 }
192 free(fileContent);
179 free(fileContent);
193
194 }
180 }
195
196 qDebug()<<timr.elapsed();
181 qDebug()<<timr.elapsed();
197 setlocale(LC_NUMERIC,svglocale);
182 setlocale(LC_NUMERIC,svglocale);
198 emit dataReady(ch1,ch2,ch3);
183 emit dataReady(ch1,ch2,ch3);
199 }
184 }
200 }
185 }
201
186
General Comments 0
You need to be logged in to leave comments. Login now