Index: trunk/tools/FlairGCS/src/DataPlot2D.cpp
===================================================================
--- trunk/tools/FlairGCS/src/DataPlot2D.cpp	(revision 234)
+++ trunk/tools/FlairGCS/src/DataPlot2D.cpp	(revision 235)
@@ -51,6 +51,4 @@
   alignScales();
 
-  // d_x=new QList<double*>;
-  // d_y=new QList<double*>;
   datas = new QList<QwtPlotCurve *>;
   datas_type = new QList<QString>;
@@ -115,5 +113,23 @@
     addCurve(QPen(QColor(r, g, b, 255)), name, type);
   } else {
+    double saved_refresh_rate=refresh_rate;
     XmlSetup(dom);
+    if(refresh_rate!=saved_refresh_rate) {//copy datas for the new refresh rate with same view size
+      double ratio=refresh_rate/saved_refresh_rate;
+      for (int i = 0; i < datas->count(); i++) {
+          double *bufx =(double *)malloc(view_size / refresh_rate * sizeof(double));
+          double *bufy =(double *)malloc(view_size / refresh_rate * sizeof(double));
+          for (int j=0;j<(int)(view_size/refresh_rate);j++) {
+            bufx[j] = d_x.at(i)[(int)(j*ratio)];
+            bufy[j] = d_y.at(i)[(int)(j*ratio)];
+          }
+          free(d_x[i]);
+          d_x[i] = bufx;
+          free(d_y[i]);
+          d_y[i] = bufy;
+          datas->at(i)->setRawSamples(d_x.at(i), d_y.at(i), view_size / refresh_rate);
+      }
+    }
+    plot->setEnabled(IsEnabled());
   }
 }
@@ -235,7 +251,6 @@
 }
 
-void DataPlot2D::BufEvent(char **buf, int *buf_size, uint16_t period,
-                          bool big_endian) {
-  plot->setEnabled(IsEnabled());
+void DataPlot2D::BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian) {
+  
   if (IsEnabled() == false || RefreshRate_ms() != period)
     return;
@@ -275,5 +290,4 @@
     }
   }
-
   plot->replot();
 }
@@ -282,6 +296,5 @@
   if (index < d_y.count()) {
     if (datas_first_update.at(index) == false) {
-      // Shift y array left and assign new value to y[view_size/refresh_rate -
-      // 1].
+      // Shift y array left and assign new value to y[view_size/refresh_rate-1].
       for (int j = 0; j < view_size / refresh_rate - 1; j++)
         d_y.at(index)[j] = d_y.at(index)[j + 1];
@@ -306,16 +319,16 @@
     QMenu *menu = new QMenu("nom", plot);
     // ajout des actions
-    QAction *a, *z, *d;
-
-    a = menu->addAction("reset zoom");
+    QAction *reset_zoom, *set_view_size, *action;
+
+    reset_zoom = menu->addAction("reset zoom");
     menu->addSeparator();
 
-    d = menu->addAction(QString("set view size (%1s)").arg(view_size));
+    set_view_size = menu->addAction(QString("set view size (%1s)").arg(view_size));
 
     appendmenu(menu);
-    z = execmenu(plot, menu, event->globalPos());
+    action = execmenu(plot, menu, event->globalPos());
     delete menu;
 
-    if (z == a) {
+    if (action == reset_zoom) {
       // zoom to original size
       plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig);
@@ -323,56 +336,40 @@
     }
 
-    if (z == d) {
+    if (action == set_view_size) {
       bool ok;
-      float time = QInputDialog::getInt(
+      float new_view_size = QInputDialog::getInt(
           plot, QString("Set view size (%1)").arg(plot->title().text()),
           tr("Value (s):"), view_size, 1, 65535, 10, &ok);
       if (ok == true) {
         for (int i = 0; i < datas->count(); i++) {
-          if (time > view_size) {
-            double *buf =
-                (double *)malloc(time / refresh_rate * sizeof(double));
-            d_x[i] = (double *)realloc(d_x.at(i),
-                                       time / refresh_rate * sizeof(double));
-            memcpy(buf, d_x[i], (view_size / refresh_rate) * sizeof(double));
-            memcpy(&d_x[i][(int)(time / refresh_rate) -
-                           (int)(view_size / refresh_rate)],
-                   buf, (view_size / refresh_rate) * sizeof(double));
-            d_y[i] = (double *)realloc(d_y.at(i),
-                                       time / refresh_rate * sizeof(double));
-            memcpy(buf, d_y[i], (view_size / refresh_rate) * sizeof(double));
-            memcpy(&d_y[i][(int)(time / refresh_rate) -
-                           (int)(view_size / refresh_rate)],
-                   buf, (view_size / refresh_rate) * sizeof(double));
-            free(buf);
-            for (int j = 0; j < (int)(time / refresh_rate) -
-                                    (int)(view_size / refresh_rate);
-                 j++) {
-              d_x.at(i)[j] = d_x.at(i)[(int)(time / refresh_rate) -
-                                       (int)(view_size / refresh_rate) + 1];
-              d_y.at(i)[j] = d_y.at(i)[(int)(time / refresh_rate) -
-                                       (int)(view_size / refresh_rate) + 1];
+          if (new_view_size > view_size) {//get last samples and expand
+            double *buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double));
+            memcpy(&buf[(int)(new_view_size / refresh_rate)-(int)(view_size / refresh_rate)], d_x[i], (view_size / refresh_rate) * sizeof(double));
+            free(d_x[i]);
+            d_x[i] = buf;
+            
+            buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double));
+            memcpy(&buf[(int)(new_view_size / refresh_rate)-(int)(view_size / refresh_rate)], d_y[i], (view_size / refresh_rate) * sizeof(double));
+            free(d_y[i]);
+            d_y[i] = buf;
+            
+            for (int j=0;j<(int)(new_view_size/refresh_rate)-(int)(view_size/refresh_rate);j++) {
+              d_x.at(i)[j] = d_x.at(i)[(int)(new_view_size/refresh_rate)-(int)(view_size/refresh_rate)+1];
+              d_y.at(i)[j] = d_y.at(i)[(int)(new_view_size/refresh_rate)-(int)(view_size/refresh_rate)+1];
             }
-          } else {
-            double *buf =
-                (double *)malloc(time / refresh_rate * sizeof(double));
-            memcpy(buf, &d_x[i][(int)(view_size / refresh_rate) -
-                                (int)(time / refresh_rate)],
-                   (time / refresh_rate) * sizeof(double));
-            d_x[i] = (double *)realloc(d_x.at(i),
-                                       time / refresh_rate * sizeof(double));
-            memcpy(d_x[i], buf, (time / refresh_rate) * sizeof(double));
-            memcpy(buf, &d_y[i][(int)(view_size / refresh_rate) -
-                                (int)(time / refresh_rate)],
-                   (time / refresh_rate) * sizeof(double));
-            d_y[i] = (double *)realloc(d_y.at(i),
-                                       time / refresh_rate * sizeof(double));
-            memcpy(d_y[i], buf, (time / refresh_rate) * sizeof(double));
-            free(buf);
+          } else {//get last samples
+            double *buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double));
+            memcpy(buf, &d_x[i][(int)(view_size / refresh_rate)-(int)(new_view_size / refresh_rate)],(new_view_size / refresh_rate) * sizeof(double));
+            free(d_x[i]);
+            d_x[i] = buf;
+            
+            buf =(double *)malloc(new_view_size / refresh_rate * sizeof(double));
+            memcpy(buf, &d_y[i][(int)(view_size / refresh_rate) -(int)(new_view_size / refresh_rate)],(new_view_size / refresh_rate) * sizeof(double));
+            free(d_y[i]);
+            d_y[i] = buf;
           }
-          datas->at(i)
-              ->setRawSamples(d_x.at(i), d_y.at(i), time / refresh_rate);
+          datas->at(i)->setRawSamples(d_x.at(i), d_y.at(i), new_view_size / refresh_rate);
         }
-        view_size = time;
+        view_size = new_view_size;
       }
     }
