Browse Source

complete ivchart.

yuchuli 3 years ago
parent
commit
5f7c85ba94

+ 30 - 0
include/ivchart.h

@@ -0,0 +1,30 @@
+#ifndef IVCHART_H
+#define IVCHART_H
+
+#include <QtCore/qglobal.h>
+
+#include <string>
+
+#if defined(IVCHART_LIBRARY)
+#  define IVCHART_EXPORT Q_DECL_EXPORT
+#else
+#  define IVCHART_EXPORT Q_DECL_IMPORT
+#endif
+
+namespace iv {
+
+
+class IVCHART_EXPORT Ivchart
+{
+public:
+    Ivchart();
+    ~Ivchart();
+public:
+    void chartvalue(std::string varname,const double fvalue,const double fvalue_RangeMin = 0.0,const double fvalue_RangeMax = 1.0);
+private:
+    void * mpimpl;
+};
+
+}
+
+#endif // IVCHART_H

+ 5 - 3
src/test/testivchart/main.cpp

@@ -9,12 +9,12 @@
 iv::Ivchart * givchart;
 bool gbrun = true;
 
-void testthread(std::string varname,int ninter,double fratio,double foff)
+void testthread(std::string varname,int ninter,double fratio,double foff,double fmin,double fmax)
 {
     int index = 0;
     while(gbrun)
     {
-        givchart->chartvalue(varname,foff + fratio*sin(index*2.0*M_PI/100),-1,1);
+        givchart->chartvalue(varname,foff + fratio*sin(index*2.0*M_PI/100),fmin,fmax);
         index = index + 1;
         std::this_thread::sleep_for(std::chrono::milliseconds(ninter));
     }
@@ -25,6 +25,8 @@ int main(int argc, char *argv[])
     QCoreApplication a(argc, argv);
 
     givchart = new iv::Ivchart();
-    std::thread * pthread = new std::thread(testthread,"test",10,1.0,0.0);
+    std::thread * pthread = new std::thread(testthread,"test",10,1.0,0.0,-1,1);
+    pthread = new std::thread(testthread,"test2",30,10.0,0.0,-10,10);
+    pthread = new std::thread(testthread,"test3",30,10.0,0.0,-50,50);
     return a.exec();
 }

+ 229 - 0
src/tool/view_ivchart/dialogivctocsv.cpp

@@ -0,0 +1,229 @@
+#include "dialogivctocsv.h"
+#include "ui_dialogivctocsv.h"
+
+#include <QFileDialog>
+#include <QMessageBox>
+#include <QDateTime>
+
+#include <functional>
+
+Dialogivctocsv::Dialogivctocsv(QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::Dialogivctocsv)
+{
+    ui->setupUi(this);
+
+    ui->checkBox->setChecked(false);
+    ui->comboBox->addItem("ms");
+    ui->comboBox->addItem("s");
+    setWindowTitle("ivc to csv");
+}
+
+Dialogivctocsv::~Dialogivctocsv()
+{
+    delete ui;
+}
+
+
+class ivcdataunit
+{
+public:
+    qint64 ntime;
+    double fvalue;
+};
+
+class ivcdata
+{
+public:
+    std::string strvarname;
+    size_t hashname;
+    std::vector<ivcdataunit> mvectordata;
+    int nnowpos = 0;
+};
+
+void Dialogivctocsv::on_pushButton_Convert_clicked()
+{
+    QString strpath = QFileDialog::getOpenFileName(this,"Load ivc File",".","*.ivc");
+    if(strpath.isEmpty())return;
+
+    QString strpathSave = QFileDialog::getSaveFileName(this,"Save CSV File",".","*.csv");
+    if(strpathSave.isEmpty())return;
+
+    QFile xFileivc;
+    QFile xFilecsv;
+
+    if(strpathSave.right(4) != ".csv")
+    {
+        strpathSave.append(".csv");
+    }
+
+    xFileivc.setFileName(strpath);
+    xFilecsv.setFileName(strpathSave);
+
+    if(!xFileivc.open(QIODevice::ReadOnly))
+    {
+        QMessageBox::warning(this,"Waring","Can't Open IVC File.",QMessageBox::YesAll);
+        return;
+    }
+
+    if(!xFilecsv.open(QIODevice::ReadWrite))
+    {
+        xFileivc.close();
+        QMessageBox::warning(this,"Warning","Can't Open CSV File.",QMessageBox::YesAll);
+        return;
+    }
+
+    int ntimemode = ui->comboBox->currentIndex();
+    bool bFillData = ui->checkBox->isChecked();
+
+    int ndatasize;
+    iv::ivchart::ivchartarray xivarray;
+
+    std::vector<ivcdata> xvectorivcdata;
+    int nRead = xFileivc.read((char *)&ndatasize,sizeof(int));
+    while(nRead == sizeof(int))
+    {
+        if(ndatasize<=0)break;
+        char * str = new char[ndatasize];
+        nRead = xFileivc.read(str,ndatasize);
+        if(nRead == ndatasize)
+        {
+            if(xivarray.ParseFromArray(str,ndatasize))
+            {
+                unsigned int i;
+                for(i=0;i<xivarray.xivchartunit_size();i++)
+                {
+                    iv::ivchart::ivchartunit * punit = xivarray.mutable_xivchartunit(i);
+                    std::hash<std::string > h;
+                    size_t hash_unit = h(punit->strvarname());
+
+                    unsigned int j;
+                    bool bhave = false;
+                    for(j=0;j<xvectorivcdata.size();j++)
+                    {
+                        if(xvectorivcdata[j].hashname == hash_unit)
+                        {
+                            ivcdataunit iu;
+                            iu.ntime = punit->timex();
+                            iu.fvalue = punit->fvalue();
+                            xvectorivcdata[j].mvectordata.push_back(iu);
+                            bhave = true;
+                            break;
+                        }
+                    }
+                    if(bhave == false)
+                    {
+                        ivcdata xdata;
+                        xdata.hashname = hash_unit;
+                        xdata.strvarname = punit->strvarname();
+                        ivcdataunit iu;
+                        iu.ntime = punit->timex();
+                        iu.fvalue = punit->fvalue();
+                        xdata.mvectordata.push_back(iu);
+                        xvectorivcdata.push_back(xdata);
+
+                    }
+
+                }
+            }
+        }
+        else
+        {
+            break;
+        }
+        nRead = xFileivc.read((char *)&ndatasize,sizeof(int));
+    }
+
+    char strout[10000];
+    char strtem[1000];
+    double fDiv = 1;
+    if(ntimemode == 1)fDiv = 1000.0;
+    snprintf(strout,10000,"Time ; AbsTime ; RealTime");
+    unsigned int i;
+    double * xvectorlastvalue = new double[xvectorivcdata.size()];
+
+    for(i=0;i<xvectorivcdata.size();i++)
+    {
+        snprintf(strtem,1000," ; %s",xvectorivcdata[i].strvarname.data());
+        strncat(strout,strtem,10000);
+        xvectorivcdata[i].nnowpos = 0;
+        xvectorlastvalue[i] = -123456.6789;
+    }
+    snprintf(strtem,1000,"\n");
+    strncat(strout,strtem,10000);
+    xFilecsv.write(strout,strnlen(strout,10000));
+
+    qint64 nstarttime = xvectorivcdata[0].mvectordata[0].ntime;
+    qint64 nnowtime = nstarttime;
+    bool bComplete = false;
+    while(bComplete == false)
+    {
+        snprintf(strout,10000,"%s ; %d ; %f ",QDateTime::fromMSecsSinceEpoch(nnowtime).toString("yyyy-MM-dd hh:mm:ss:zzz").toLatin1().data(),
+                 nnowtime,((double)(nnowtime - nstarttime))/fDiv);
+        for(i=0;i<xvectorivcdata.size();i++)
+        {
+            if(xvectorivcdata[i].nnowpos <xvectorivcdata[i].mvectordata.size())
+            {
+                ivcdataunit * pdata = &xvectorivcdata[i].mvectordata[xvectorivcdata[i].nnowpos];
+                if(nnowtime == pdata->ntime)
+                {
+                    snprintf(strtem,1000," ; %f",pdata->fvalue);
+                    strncat(strout,strtem,10000);
+                    xvectorlastvalue[i] = pdata->fvalue;
+                    xvectorivcdata[i].nnowpos++;
+                }
+                else
+                {
+                    if((bFillData)&&(xvectorlastvalue[i] != -123456.6789))
+                    {
+                        snprintf(strtem,1000," ; %f",xvectorlastvalue[i]);
+                        strncat(strout,strtem,10000);
+                    }
+                    else
+                    {
+                        snprintf(strtem,1000," ; ");
+                        strncat(strout,strtem,10000);
+                    }
+                }
+            }
+            else
+            {
+                snprintf(strtem,1000," ; ");
+                strncat(strout,strtem,10000);
+            }
+        }
+
+        snprintf(strtem,1000,"\n");
+        strncat(strout,strtem,10000);
+        xFilecsv.write(strout,strnlen(strout,10000));
+
+
+        bool bFindNewNow = false;
+        for(i=0;i<xvectorivcdata.size();i++)
+        {
+            if(xvectorivcdata[i].nnowpos <xvectorivcdata[i].mvectordata.size())
+            {
+                ivcdataunit * pdata = &xvectorivcdata[i].mvectordata[xvectorivcdata[i].nnowpos];
+                if(bFindNewNow == false)
+                {
+                    bFindNewNow = true;
+                    nnowtime = pdata->ntime;
+                }
+                else
+                {
+                    if(nnowtime > pdata->ntime)
+                    {
+                        nnowtime = pdata->ntime;
+                    }
+                }
+            }
+        }
+        if(bFindNewNow == false)
+        {
+            bComplete = true;
+            break;
+        }
+    }
+    xFilecsv.close();
+    QMessageBox::information(this,"Info","Covert Complete.",QMessageBox::YesAll);
+}

+ 27 - 0
src/tool/view_ivchart/dialogivctocsv.h

@@ -0,0 +1,27 @@
+#ifndef DIALOGIVCTOCSV_H
+#define DIALOGIVCTOCSV_H
+
+#include <QDialog>
+
+#include "ivchart.pb.h"
+
+namespace Ui {
+class Dialogivctocsv;
+}
+
+class Dialogivctocsv : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit Dialogivctocsv(QWidget *parent = nullptr);
+    ~Dialogivctocsv();
+
+private slots:
+    void on_pushButton_Convert_clicked();
+
+private:
+    Ui::Dialogivctocsv *ui;
+};
+
+#endif // DIALOGIVCTOCSV_H

+ 68 - 0
src/tool/view_ivchart/dialogivctocsv.ui

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialogivctocsv</class>
+ <widget class="QDialog" name="Dialogivctocsv">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>360</width>
+    <height>303</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="pushButton_Convert">
+   <property name="geometry">
+    <rect>
+     <x>110</x>
+     <y>190</y>
+     <width>89</width>
+     <height>25</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Convert</string>
+   </property>
+  </widget>
+  <widget class="QComboBox" name="comboBox">
+   <property name="geometry">
+    <rect>
+     <x>150</x>
+     <y>40</y>
+     <width>91</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>50</x>
+     <y>40</y>
+     <width>71</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Unit</string>
+   </property>
+  </widget>
+  <widget class="QCheckBox" name="checkBox">
+   <property name="geometry">
+    <rect>
+     <x>53</x>
+     <y>120</y>
+     <width>191</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Fill Up Data</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 29 - 0
src/tool/view_ivchart/dialogsetaxisx.cpp

@@ -0,0 +1,29 @@
+#include "dialogsetaxisx.h"
+#include "ui_dialogsetaxisx.h"
+
+DialogSetAxisX::DialogSetAxisX(double * psel,const int nselnum, int &nsel,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogSetAxisX)
+{
+    ui->setupUi(this);
+    int i;
+    for(i=0;i<nselnum;i++)
+    {
+        ui->comboBox->addItem(QString::number(psel[i]));
+    }
+    ui->comboBox->setCurrentIndex(nsel);
+    mpnsel = &nsel;
+
+    setWindowTitle("Set AxisX");
+}
+
+DialogSetAxisX::~DialogSetAxisX()
+{
+    delete ui;
+}
+
+void DialogSetAxisX::on_pushButton_Set_clicked()
+{
+    *mpnsel = ui->comboBox->currentIndex();
+    this->accept();
+}

+ 27 - 0
src/tool/view_ivchart/dialogsetaxisx.h

@@ -0,0 +1,27 @@
+#ifndef DIALOGSETAXISX_H
+#define DIALOGSETAXISX_H
+
+#include <QDialog>
+
+namespace Ui {
+class DialogSetAxisX;
+}
+
+class DialogSetAxisX : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogSetAxisX(double * psel,const int nselnum, int &nsel,QWidget *parent = nullptr);
+    ~DialogSetAxisX();
+
+private slots:
+    void on_pushButton_Set_clicked();
+
+
+private:
+    Ui::DialogSetAxisX *ui;
+    int * mpnsel;
+};
+
+#endif // DIALOGSETAXISX_H

+ 55 - 0
src/tool/view_ivchart/dialogsetaxisx.ui

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogSetAxisX</class>
+ <widget class="QDialog" name="DialogSetAxisX">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>367</width>
+    <height>263</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="pushButton_Set">
+   <property name="geometry">
+    <rect>
+     <x>130</x>
+     <y>140</y>
+     <width>101</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Set</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>40</x>
+     <y>70</y>
+     <width>81</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Select</string>
+   </property>
+  </widget>
+  <widget class="QComboBox" name="comboBox">
+   <property name="geometry">
+    <rect>
+     <x>160</x>
+     <y>70</y>
+     <width>171</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 56 - 1
src/tool/view_ivchart/ivchartproc.cpp

@@ -23,6 +23,48 @@ void ivchartproc::run()
         int nsize = xvectorivarray.size();
         for(i=0;i<nsize;i++)
         {
+            if(mbSave)
+            {
+                if(mbSaving == false)
+                {
+                    char * strhome = getenv("HOME");
+                    QString strpath = strhome;
+                    strpath = strpath + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz.ivc");
+                    mFileSave.setFileName(strpath);
+                    if(mFileSave.open(QIODevice::ReadWrite))
+                    {
+                        mbSaving = true;
+                        mstrsavingpath = strpath;
+                    }
+                    else
+                    {
+                        qDebug("open file %s error.",strpath.toLatin1().data());
+                        mbSave = false;
+                    }
+                }
+                if(mbSaving)
+                {
+                    char * str;
+                    int ndatasize = xvectorivarray[i].ByteSize();
+                    str = new char[ndatasize];
+                    if(xvectorivarray[i].SerializeToArray(str,ndatasize))
+                    {
+                        mFileSave.write((char *)&ndatasize,sizeof(int));
+                        mFileSave.write(str,ndatasize);
+                    }
+                    delete str;
+                }
+            }
+            else
+            {
+                if(mbSaving)
+                {
+                    mbSaving = false;
+                    mFileSave.close();
+                    mstrsavingpath = "";
+
+                }
+            }
             unsigned int k;
             for(k=0;k<xvectorivarray[i].xivchartunit_size();k++)
             {
@@ -71,6 +113,7 @@ void ivchartproc::run()
                     break;
                 }
             }
+            if(j>0)mvectorCU[i].mvectorchartunit.erase(mvectorCU[i].mvectorchartunit.begin(),mvectorCU[i].mvectorchartunit.begin()+j);
         }
         mMutex.unlock();
 
@@ -86,7 +129,7 @@ void ivchartproc::run()
 void ivchartproc::onChartMsg(QByteArray value)
 {
 
-    qDebug("chart msg size is %d",value.size());
+ //   qDebug("chart msg size is %d",value.size());
     iv::ivchart::ivchartarray xivarray;
     if(xivarray.ParseFromArray(value.data(),value.size()))
     {
@@ -130,3 +173,15 @@ std::vector<iv::ivchart::ivchartunit> ivchartproc::GetChartUnit(std::string strn
     mMutex.unlock();
     return xvectorcu;
 }
+
+bool ivchartproc::GetSavingPath(std::string &strpath)
+{
+    if(mbSaving == false)return false;
+    strpath = mstrsavingpath.toStdString();
+    return true;
+}
+
+void ivchartproc::ChangeSaveMode()
+{
+    mbSave = !mbSave;
+}

+ 9 - 0
src/tool/view_ivchart/ivchartproc.h

@@ -9,6 +9,8 @@
 #include <QtDBus/qdbusmessage.h>
 #include <QtDBus/QDBusConnection>
 
+#include <QFile>
+
 #include "ivchart.pb.h"
 
 class ChartUnit
@@ -35,9 +37,16 @@ private:
     QMutex mMutexArray;
     bool mbrun = true;
 
+    bool mbSave = false;
+    bool mbSaving = false;
+    QString mstrsavingpath;
+    QFile mFileSave;
+
 public:
     std::vector<std::string > GetChartNameList();
     std::vector<iv::ivchart::ivchartunit> GetChartUnit(std::string strname);
+    bool GetSavingPath(std::string & strpath);
+    void ChangeSaveMode();
 };
 
 #endif // IVCHARTPROC_H

+ 148 - 17
src/tool/view_ivchart/mainwindow.cpp

@@ -9,10 +9,7 @@ MainWindow::MainWindow(QWidget *parent)
 {
     ui->setupUi(this);
 
-    std::hash<std::string> h;
-    size_t n = h("Just fucking google it");
-    std::cout << n << std::endl;
-
+    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));          //设
     m_chart = new QChart();
     m_chart->setTheme(QChart::ChartThemeLight);//设置白色主题
     m_chart->setDropShadowEnabled(true);//背景阴影    m_chart->setAutoFillBackground(true);  //设置背景自动填充
@@ -24,7 +21,20 @@ MainWindow::MainWindow(QWidget *parent)
     m_chart->setTitle("曲线图");
 
 
+    //创建X轴和Y轴
+    QValueAxis *axisX = new QValueAxis;
+    axisX->setRange(-1000* AXIS_X_SEL[mnDefAxisXIndex],0);    //默认则坐标为动态计算大小的
+    axisX->setLabelFormat("%dms");
+    mpAxisX = axisX;
 
+    //修改说明样式
+    m_chart->legend()->setVisible(true);
+    m_chart->legend()->setAlignment(Qt::AlignBottom);//底部对齐
+    m_chart->legend()->setBackgroundVisible(true);//设置背景是否可视
+    m_chart->legend()->setAutoFillBackground(true);//设置背景自动填充
+    m_chart->legend()->setColor(QColor(222,233,251));//设置颜色
+    m_chart->legend()->setLabelColor(QColor(0,100,255));//设置标签颜色
+    m_chart->legend()->setMaximumHeight(50);
 
 
 
@@ -41,8 +51,9 @@ MainWindow::MainWindow(QWidget *parent)
    QTimer * timer;
    timer = new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
-   timer->start(100);
+   timer->start(50);
 
+   mnTitleMode = 0;
    setWindowTitle("ADC IV Chart View");
 }
 
@@ -93,7 +104,11 @@ void MainWindow::on_actionSelect_Data_triggered()
         }
         if(bhave == false)
         {
+            m_chart->removeAxis(mvectorCUShow[i].mpaxisY);
+            m_chart->removeSeries(mvectorCUShow[i].mlineseries);
+            delete mvectorCUShow[i].mpaxisY;
             delete mvectorCUShow[i].mlineseries;
+
             mvectorCUShow.erase(mvectorCUShow.begin()+i);
         }
 
@@ -114,12 +129,14 @@ void MainWindow::on_actionSelect_Data_triggered()
         {
             CUShow xcu;
             xcu.mstrname = mvectorused[i];
-            mvectorCUShow.push_back(xcu);
 
-            mvectorCUShow[mvectorCUShow.size()-1].mlineseries = new QLineSeries();
-            QLineSeries * plineseries = mvectorCUShow[mvectorCUShow.size()-1].mlineseries;
 
-            plineseries->setColor(QColor(255,0,0));
+
+            xcu.mlineseries = new QLineSeries();
+            QLineSeries * plineseries = xcu.mlineseries;
+
+            xcu.mcolor = GetRandColor();
+            plineseries->setColor(xcu.mcolor);
 
             plineseries->setName(xcu.mstrname.data());
 
@@ -128,27 +145,63 @@ void MainWindow::on_actionSelect_Data_triggered()
             plineseries->setPointLabelsVisible(false);
 
 
+            std::vector<iv::ivchart::ivchartunit> xvectorcu = mpivchartproc->GetChartUnit(xcu.mstrname);
+
+            if(xvectorcu.size()>0)
+            {
+                xcu.mfRangeMin = xvectorcu[0].fvalue_rangemin();
+                xcu.mfRangeMax = xvectorcu[0].fvalue_rangemax();
+            }
+
             m_chart->addSeries(plineseries);//添加系列到QChart上
 
-            //创建X轴和Y轴
-            QValueAxis *axisX = new QValueAxis;
-            axisX->setRange(-3000,0);    //默认则坐标为动态计算大小的
-            axisX->setLabelFormat("%dms");
+
             QValueAxis *axisY = new QValueAxis;
-            axisY->setRange(-1,1);    //默认则坐标为动态计算大小的
-            axisY->setTitleText("value值");
+            axisY->setRange(xcu.mfRangeMin,xcu.mfRangeMax);    //默认则坐标为动态计算大小的
+            axisY->setTitleText(xcu.mstrname.data());
+
+            axisY->setLinePenColor(plineseries->pen().color());
+
 
-            axisY->setLinePenColor(QColor(0,255,0));
+   //          axisY->setGridLinePen((plineseries->pen()));
+            xcu.mpaxisY = axisY;
 
-            m_chart->setAxisX(axisX,plineseries);
+            m_chart->setAxisX(mpAxisX,plineseries);
             m_chart->setAxisY(axisY,plineseries);
+
+            mvectorCUShow.push_back(xcu);
         }
     }
 
+    mbViewPause = false;
+
 }
 
 void MainWindow::onTimer()
 {
+    std::string strsavingpath;
+    bool bsaving = false;
+    bsaving = mpivchartproc->GetSavingPath(strsavingpath);
+    if(bsaving == false)
+    {
+        if(mnTitleMode == 1)
+        {
+            setWindowTitle(mstrTitle.data());
+            mnTitleMode = 0;
+        }
+    }
+    else
+    {
+        if(mnTitleMode == 0)
+        {
+            std::string strtitle = mstrTitle;
+            strtitle = strtitle + strsavingpath;
+            setWindowTitle(strtitle.data());
+            mnTitleMode = 1;
+        }
+    }
+
+    if(mbViewPause)return;
     unsigned int i;
     for(i=0;i<mvectorCUShow.size();i++)
     {
@@ -156,6 +209,7 @@ void MainWindow::onTimer()
         unsigned int j;
         qint64 nnow = QDateTime::currentMSecsSinceEpoch();
         QList<QPointF> xListPoint;
+        mvectorCUShow[i].mlineseries->clear();
         for(j=0;j<xvectorcu.size();j++)
         {
 
@@ -163,6 +217,83 @@ void MainWindow::onTimer()
  //           qDebug("%f %f ",xListPoint[0].x(),xListPoint[0].y());
         }
 
+
         mvectorCUShow[i].mlineseries->replace(xListPoint);
+        xListPoint.clear();
+    }
+
+
+}
+
+QColor MainWindow::GetRandColor()
+{
+ //   qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
+    unsigned char R,G,B;
+    R = qrand()%255;
+    G = qrand()%255;
+    B = qrand()%255;
+
+    QColor xcolor(R,G,B);
+    return xcolor;
+}
+
+void MainWindow::keyPressEvent(QKeyEvent *event)
+{
+
+    //按键按下,key值放入容器,如果是长按触发的repeat就不判断
+    if(!event->isAutoRepeat())
+        mPressKeys.insert(event->key());
+
+    if(mPressKeys.contains(Qt::Key_P) &&(mPressKeys.contains(Qt::Key_Control)))
+    {
+        if(mbViewPause)mbViewPause = false;
+        else mbViewPause = true;
+    }
+    else
+    {
+        qDebug("key count is %d",mPressKeys.size());
+    }
+
+    if(mPressKeys.contains(Qt::Key_S) &&(mPressKeys.contains(Qt::Key_Control)))
+    {
+        mpivchartproc->ChangeSaveMode();
+    }
+
+
+}
+
+void MainWindow::keyReleaseEvent(QKeyEvent *event)
+{
+    if(!event->isAutoRepeat())mPressKeys.remove(event->key());
+}
+
+void MainWindow::on_actionSet_AxisX_triggered()
+{
+
+    int nsel = mnDefAxisXIndex;
+    DialogSetAxisX saxix(AXIS_X_SEL,6,nsel,this);
+    int nrtn = saxix.exec();
+    if(nrtn != saxix.Accepted)
+    {
+        return;
     }
+    if(nsel != mnDefAxisXIndex)
+    {
+        mnDefAxisXIndex = nsel;
+        mpAxisX->setRange((-1000)*AXIS_X_SEL[mnDefAxisXIndex],0);
+    }
+}
+
+void MainWindow::on_actionivc_to_csv_triggered()
+{
+    Dialogivctocsv ivctocst;
+    ivctocst.exec();
+}
+
+void MainWindow::on_actionHelp_triggered()
+{
+    QString helpinfo = tr("Select Data 选择绘图数据\nSet AxisX 设置X轴\nivctocsv 转换数据为csv\n"
+                          "Ctrl+P 暂停和继续\n"
+                          "Ctrl+S 保存和暂停保存");
+    QMessageBox::information(this,"Help",helpinfo,QMessageBox::Yes);
 }

+ 30 - 0
src/tool/view_ivchart/mainwindow.h

@@ -8,6 +8,9 @@
 
 #include "ivchartproc.h"
 #include "dialogselect.h"
+#include "dialogsetaxisx.h"
+#include "dialogivctocsv.h"
+
 
 QT_BEGIN_NAMESPACE
 namespace Ui { class MainWindow; }
@@ -18,6 +21,10 @@ struct CUShow
 public:
     std::string mstrname;
     QLineSeries * mlineseries;
+    QValueAxis * mpaxisY;
+    QColor mcolor;
+    double mfRangeMin = 0.0;
+    double mfRangeMax = 1.0;
 };
 
 class MainWindow : public QMainWindow
@@ -42,10 +49,33 @@ private:
     std::vector<std::string> mvectorused;
 
     std::vector<CUShow> mvectorCUShow;
+
+    QValueAxis * mpAxisX;
+
+    QSet<int> mPressKeys;
+
+    bool mbViewPause = false;
+
+    double AXIS_X_SEL[6] = {1,5,10,30,60,300};
+    int mnDefAxisXIndex = 2;
+
+    std::string mstrTitle = "ADC IV Char View ";
+    int mnTitleMode = 0;
+
+  private:
+    QColor GetRandColor();
+
 public:
      void resizeEvent(QResizeEvent *event);
 
+      void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+
+      void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
+
 private slots:
      void on_actionSelect_Data_triggered();
+     void on_actionSet_AxisX_triggered();
+     void on_actionivc_to_csv_triggered();
+     void on_actionHelp_triggered();
 };
 #endif // MAINWINDOW_H

+ 18 - 0
src/tool/view_ivchart/mainwindow.ui

@@ -28,6 +28,9 @@
      <string>Func</string>
     </property>
     <addaction name="actionSelect_Data"/>
+    <addaction name="actionSet_AxisX"/>
+    <addaction name="actionivc_to_csv"/>
+    <addaction name="actionHelp"/>
    </widget>
    <addaction name="menuFunc"/>
   </widget>
@@ -37,6 +40,21 @@
     <string>Select Data</string>
    </property>
   </action>
+  <action name="actionSet_AxisX">
+   <property name="text">
+    <string>Set AxisX</string>
+   </property>
+  </action>
+  <action name="actionivc_to_csv">
+   <property name="text">
+    <string>ivc to csv</string>
+   </property>
+  </action>
+  <action name="actionHelp">
+   <property name="text">
+    <string>Help</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections/>

+ 6 - 0
src/tool/view_ivchart/view_ivchart.pro

@@ -17,19 +17,25 @@ DEFINES += QT_DEPRECATED_WARNINGS
 
 SOURCES += \
     ../../include/msgtype/ivchart.pb.cc \
+    dialogivctocsv.cpp \
     dialogselect.cpp \
+    dialogsetaxisx.cpp \
     ivchartproc.cpp \
     main.cpp \
     mainwindow.cpp
 
 HEADERS += \
     ../../include/msgtype/ivchart.pb.h \
+    dialogivctocsv.h \
     dialogselect.h \
+    dialogsetaxisx.h \
     ivchartproc.h \
     mainwindow.h
 
 FORMS += \
+    dialogivctocsv.ui \
     dialogselect.ui \
+    dialogsetaxisx.ui \
     mainwindow.ui
 
 # Default rules for deployment.