Changeset 235 in flair-src for trunk/tools/FlairGCS


Ignore:
Timestamp:
Apr 12, 2018, 3:05:25 PM (7 years ago)
Author:
Sanahuja Guillaume
Message:

resolved https://devel.hds.utc.fr/projects/flair/ticket/37

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/FlairGCS/src/DataPlot2D.cpp

    r221 r235  
    5151  alignScales();
    5252
    53   // d_x=new QList<double*>;
    54   // d_y=new QList<double*>;
    5553  datas = new QList<QwtPlotCurve *>;
    5654  datas_type = new QList<QString>;
     
    115113    addCurve(QPen(QColor(r, g, b, 255)), name, type);
    116114  } else {
     115    double saved_refresh_rate=refresh_rate;
    117116    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());
    118134  }
    119135}
     
    235251}
    236252
    237 void DataPlot2D::BufEvent(char **buf, int *buf_size, uint16_t period,
    238                           bool big_endian) {
    239   plot->setEnabled(IsEnabled());
     253void DataPlot2D::BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian) {
     254 
    240255  if (IsEnabled() == false || RefreshRate_ms() != period)
    241256    return;
     
    275290    }
    276291  }
    277 
    278292  plot->replot();
    279293}
     
    282296  if (index < d_y.count()) {
    283297    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].
    286299      for (int j = 0; j < view_size / refresh_rate - 1; j++)
    287300        d_y.at(index)[j] = d_y.at(index)[j + 1];
     
    306319    QMenu *menu = new QMenu("nom", plot);
    307320    // 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");
    311324    menu->addSeparator();
    312325
    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));
    314327
    315328    appendmenu(menu);
    316     z = execmenu(plot, menu, event->globalPos());
     329    action = execmenu(plot, menu, event->globalPos());
    317330    delete menu;
    318331
    319     if (z == a) {
     332    if (action == reset_zoom) {
    320333      // zoom to original size
    321334      plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig);
     
    323336    }
    324337
    325     if (z == d) {
     338    if (action == set_view_size) {
    326339      bool ok;
    327       float time = QInputDialog::getInt(
     340      float new_view_size = QInputDialog::getInt(
    328341          plot, QString("Set view size (%1)").arg(plot->title().text()),
    329342          tr("Value (s):"), view_size, 1, 65535, 10, &ok);
    330343      if (ok == true) {
    331344        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];
    355359            }
    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;
    372370          }
    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);
    375372        }
    376         view_size = time;
     373        view_size = new_view_size;
    377374      }
    378375    }
Note: See TracChangeset for help on using the changeset viewer.