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