Changeset 235 in flair-src for trunk/tools/FlairGCS/src
- Timestamp:
- Apr 12, 2018, 3:05:25 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/FlairGCS/src/DataPlot2D.cpp
r221 r235 51 51 alignScales(); 52 52 53 // d_x=new QList<double*>;54 // d_y=new QList<double*>;55 53 datas = new QList<QwtPlotCurve *>; 56 54 datas_type = new QList<QString>; … … 115 113 addCurve(QPen(QColor(r, g, b, 255)), name, type); 116 114 } else { 115 double saved_refresh_rate=refresh_rate; 117 116 XmlSetup(dom); 117 if(refresh_rate!=saved_refresh_rate) {//copy datas for the new refresh rate with same view size 118 double ratio=refresh_rate/saved_refresh_rate; 119 for (int i = 0; i < datas->count(); i++) { 120 double *bufx =(double *)malloc(view_size / refresh_rate * sizeof(double)); 121 double *bufy =(double *)malloc(view_size / refresh_rate * sizeof(double)); 122 for (int j=0;j<(int)(view_size/refresh_rate);j++) { 123 bufx[j] = d_x.at(i)[(int)(j*ratio)]; 124 bufy[j] = d_y.at(i)[(int)(j*ratio)]; 125 } 126 free(d_x[i]); 127 d_x[i] = bufx; 128 free(d_y[i]); 129 d_y[i] = bufy; 130 datas->at(i)->setRawSamples(d_x.at(i), d_y.at(i), view_size / refresh_rate); 131 } 132 } 133 plot->setEnabled(IsEnabled()); 118 134 } 119 135 } … … 235 251 } 236 252 237 void DataPlot2D::BufEvent(char **buf, int *buf_size, uint16_t period, 238 bool big_endian) { 239 plot->setEnabled(IsEnabled()); 253 void DataPlot2D::BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian) { 254 240 255 if (IsEnabled() == false || RefreshRate_ms() != period) 241 256 return; … … 275 290 } 276 291 } 277 278 292 plot->replot(); 279 293 } … … 282 296 if (index < d_y.count()) { 283 297 if (datas_first_update.at(index) == false) { 284 // Shift y array left and assign new value to y[view_size/refresh_rate - 285 // 1]. 298 // Shift y array left and assign new value to y[view_size/refresh_rate-1]. 286 299 for (int j = 0; j < view_size / refresh_rate - 1; j++) 287 300 d_y.at(index)[j] = d_y.at(index)[j + 1]; … … 306 319 QMenu *menu = new QMenu("nom", plot); 307 320 // ajout des actions 308 QAction * a, *z, *d;309 310 a= menu->addAction("reset zoom");321 QAction *reset_zoom, *set_view_size, *action; 322 323 reset_zoom = menu->addAction("reset zoom"); 311 324 menu->addSeparator(); 312 325 313 d= menu->addAction(QString("set view size (%1s)").arg(view_size));326 set_view_size = menu->addAction(QString("set view size (%1s)").arg(view_size)); 314 327 315 328 appendmenu(menu); 316 z= execmenu(plot, menu, event->globalPos());329 action = execmenu(plot, menu, event->globalPos()); 317 330 delete menu; 318 331 319 if ( z == a) {332 if (action == reset_zoom) { 320 333 // zoom to original size 321 334 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); … … 323 336 } 324 337 325 if ( z == d) {338 if (action == set_view_size) { 326 339 bool ok; 327 float time = QInputDialog::getInt(340 float new_view_size = QInputDialog::getInt( 328 341 plot, QString("Set view size (%1)").arg(plot->title().text()), 329 342 tr("Value (s):"), view_size, 1, 65535, 10, &ok); 330 343 if (ok == true) { 331 344 for (int i = 0; i < datas->count(); i++) { 332 if (time > view_size) { 333 double *buf = 334 (double *)malloc(time / refresh_rate * sizeof(double)); 335 d_x[i] = (double *)realloc(d_x.at(i), 336 time / refresh_rate * sizeof(double)); 337 memcpy(buf, d_x[i], (view_size / refresh_rate) * sizeof(double)); 338 memcpy(&d_x[i][(int)(time / refresh_rate) - 339 (int)(view_size / refresh_rate)], 340 buf, (view_size / refresh_rate) * sizeof(double)); 341 d_y[i] = (double *)realloc(d_y.at(i), 342 time / refresh_rate * sizeof(double)); 343 memcpy(buf, d_y[i], (view_size / refresh_rate) * sizeof(double)); 344 memcpy(&d_y[i][(int)(time / refresh_rate) - 345 (int)(view_size / refresh_rate)], 346 buf, (view_size / refresh_rate) * sizeof(double)); 347 free(buf); 348 for (int j = 0; j < (int)(time / refresh_rate) - 349 (int)(view_size / refresh_rate); 350 j++) { 351 d_x.at(i)[j] = d_x.at(i)[(int)(time / refresh_rate) - 352 (int)(view_size / refresh_rate) + 1]; 353 d_y.at(i)[j] = d_y.at(i)[(int)(time / refresh_rate) - 354 (int)(view_size / refresh_rate) + 1]; 345 if (new_view_size > view_size) {//get last samples and expand 346 double *buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double)); 347 memcpy(&buf[(int)(new_view_size / refresh_rate)-(int)(view_size / refresh_rate)], d_x[i], (view_size / refresh_rate) * sizeof(double)); 348 free(d_x[i]); 349 d_x[i] = buf; 350 351 buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double)); 352 memcpy(&buf[(int)(new_view_size / refresh_rate)-(int)(view_size / refresh_rate)], d_y[i], (view_size / refresh_rate) * sizeof(double)); 353 free(d_y[i]); 354 d_y[i] = buf; 355 356 for (int j=0;j<(int)(new_view_size/refresh_rate)-(int)(view_size/refresh_rate);j++) { 357 d_x.at(i)[j] = d_x.at(i)[(int)(new_view_size/refresh_rate)-(int)(view_size/refresh_rate)+1]; 358 d_y.at(i)[j] = d_y.at(i)[(int)(new_view_size/refresh_rate)-(int)(view_size/refresh_rate)+1]; 355 359 } 356 } else { 357 double *buf = 358 (double *)malloc(time / refresh_rate * sizeof(double)); 359 memcpy(buf, &d_x[i][(int)(view_size / refresh_rate) - 360 (int)(time / refresh_rate)], 361 (time / refresh_rate) * sizeof(double)); 362 d_x[i] = (double *)realloc(d_x.at(i), 363 time / refresh_rate * sizeof(double)); 364 memcpy(d_x[i], buf, (time / refresh_rate) * sizeof(double)); 365 memcpy(buf, &d_y[i][(int)(view_size / refresh_rate) - 366 (int)(time / refresh_rate)], 367 (time / refresh_rate) * sizeof(double)); 368 d_y[i] = (double *)realloc(d_y.at(i), 369 time / refresh_rate * sizeof(double)); 370 memcpy(d_y[i], buf, (time / refresh_rate) * sizeof(double)); 371 free(buf); 360 } else {//get last samples 361 double *buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double)); 362 memcpy(buf, &d_x[i][(int)(view_size / refresh_rate)-(int)(new_view_size / refresh_rate)],(new_view_size / refresh_rate) * sizeof(double)); 363 free(d_x[i]); 364 d_x[i] = buf; 365 366 buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double)); 367 memcpy(buf, &d_y[i][(int)(view_size / refresh_rate) -(int)(new_view_size / refresh_rate)],(new_view_size / refresh_rate) * sizeof(double)); 368 free(d_y[i]); 369 d_y[i] = buf; 372 370 } 373 datas->at(i) 374 ->setRawSamples(d_x.at(i), d_y.at(i), time / refresh_rate); 371 datas->at(i)->setRawSamples(d_x.at(i), d_y.at(i), new_view_size / refresh_rate); 375 372 } 376 view_size = time;373 view_size = new_view_size; 377 374 } 378 375 }
Note:
See TracChangeset
for help on using the changeset viewer.