using System;
using System.Drawing;
using System.Windows.Forms;
using ZedGraph;
using CRVM.CIDExcuter;
using CRVM.Entity;

namespace CRVM
{
    public partial class PlottingReview : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        private int oneStepPoints;
        private double timeSpan;
        private int displayPoints;
        private int indexPos = 0;
        private int orient = 1;//正为正向，负为反向
        private int coeff = 1;//步数放大比例
        private MasterPane master;
        private GraphPane gpt;
        IViewHelper fileHelper;
        private Machine macReview = null;



        Color[] rollLineColor = { Color.FromArgb(20, 25, 244), Color.FromArgb(11, 147, 47), Color.FromArgb(209, 184, 37) };

        public PlottingReview(IViewHelper fileHelper, Machine mac)
        {
            this.fileHelper = fileHelper;
            this.macReview = mac;
            timeSpan = Convert.ToDouble(SysParam.Instance.reTimeSpan);
            displayPoints = Convert.ToInt32(timeSpan * SysParam.Instance.reSampleFre);
            oneStepPoints = SysParam.Instance.reSamplePoint;
            InitializeComponent();
        }

        private void Plot_Load(object sender, EventArgs e)
        {
            LoadIni();
        }

        private void LoadIni()
        {
            indexPos = 0;
            btLeft.Enabled = false;
            btRight.Enabled = false;
            btPause.Enabled = false;
            btStart.Enabled = true;
            btStop.Enabled = false;
            stepBar.Maximum = fileHelper.signalLengthOrigin - Convert.ToInt32(SysParam.Instance.reTimeSpan) * SysParam.Instance.reSampleFre;
            stepBar.Minimum = 0;
            stepBar.LargeChange = 5 * oneStepPoints;
            stepBar.SmallChange = oneStepPoints;
            GraRefresh();
        }


        public void GraRefresh()
        {
            SubExcute();
        }

        private void SubExcute()
        {
            if (fileHelper != null)
            {
                //zedGraphControl1.IsShowPointValues = false;
                master = new MasterPane();
                master.PaneList.Clear();

                if (SysParam.Instance.orderByOther)
                {
                    if (SysParam.Instance.orderByChannel)
                    {
                        for (int i = SysParam.Instance.channelCount - 1; i >= 0; i--)
                        {
                            if (SysParam.Instance.channel[i].ChChecked)
                            {
                                if (SysParam.Instance.checkBoxTime)
                                    OrderByChannel_Time(macReview.Stand[i], i);
                                if (SysParam.Instance.checkBoxEnergy)
                                    OrderByChannel_Energy(i);
                            }
                        }
                    }
                    else
                    {
                        if (SysParam.Instance.checkBoxTime)
                            OrderByKind_Time();
                        if (SysParam.Instance.checkBoxEnergy)
                            OrderByKind_Energy();
                    }
                }
                else if (SysParam.Instance.orderByStandnoR2L)
                {
                    if (SysParam.Instance.checkBoxTime)
                        OrderByKind_Time();
                    if (SysParam.Instance.checkBoxEnergy)
                        OrderByKind_Energy();
                }
                else if (SysParam.Instance.orderByStandnoL2R)
                {
                    if (SysParam.Instance.checkBoxTime)
                        OrderByKind_Time2();
                    if (SysParam.Instance.checkBoxEnergy)
                        OrderByKind_Energy2();
                }
                master.Border.IsVisible = false;
                master.Margin.All = 3f;
                master.InnerPaneGap = 3f;
                master.Fill = new Fill(SysParam.Instance.colorBackgroud);
                master.AxisChange();
                zedGraphControl1.MasterPane = master;

                if (SysParam.Instance.orderByStandnoR2L || SysParam.Instance.orderByStandnoL2R)
                {
                    int colNumTemp = 0;//显示的列数，按机架排列
                    for (int i = 0; i < SysParam.Instance.SpeedChannelCount; i++)
                    {
                        if (SysParam.Instance.channel[i].ChChecked)
                        {
                            colNumTemp++;
                        }
                    }

                    int picNumber = 0;
                    if (SysParam.Instance.checkBoxTime)
                    {
                        if (SysParam.Instance.checkBoxTimeAll)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxTimeL)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxTimeM)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxTimeH)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxTimeFre)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxTimeFilt)
                        {
                            picNumber++;
                        }
                    }
                    if (SysParam.Instance.checkBoxEnergy)
                    {
                        if (SysParam.Instance.checkBoxEnergyAll)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxEnergyL)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxEnergyM)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxEnergyH)
                        {
                            picNumber++;
                        }
                        if (SysParam.Instance.checkBoxEnergySpeed)
                        {
                            picNumber++;
                        }
                    }
                    if (picNumber == 0)
                    {
                        picNumber = 1;
                    }
                    zedGraphControl1.MasterPane.RowNum = picNumber;

                    if (colNumTemp == 0 || colNumTemp > SysParam.Instance.SpeedChannelCount)
                    {

                    }
                    else
                    {
                        zedGraphControl1.MasterPane.ColNum = colNumTemp;
                    }

                    zedGraphControl1.MasterPane.SetLayout(zedGraphControl1.CreateGraphics(), PaneLayout.UserFormat);
                }
                else if (SysParam.Instance.orderByOther)
                {
                    if (SysParam.Instance.orderBySingleColumn)
                    {
                        zedGraphControl1.MasterPane.SetLayout(zedGraphControl1.CreateGraphics(), PaneLayout.SingleColumn);
                    }
                    else
                    {
                        zedGraphControl1.MasterPane.SetLayout(zedGraphControl1.CreateGraphics(), PaneLayout.SquareRowPreferred);
                    }
                }
                zedGraphControl1.Height = ClientRectangle.Height;
                zedGraphControl1.Refresh();

                //Console.WriteLine(DateTime.Now.ToString("mmss.fff")+"结束");

            }
        }

        private void OrderByChannel_Time(Stand stand, int standNo)
        {
            if (standNo >= SysParam.Instance.SpeedChannelCount)
            {
                return;
            }
            double[] tvib = getData(standNo, indexPos, displayPoints);
            double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
            double x_max = x_min + timeSpan;
            double[] tx = new double[displayPoints];
            GetAlarmParam(fileHelper.originSpeedList[standNo][indexPos], stand);

            for (int i = 0; i < displayPoints; i++)
            {
                tx[i] = x_min + Convert.ToDouble(i) / SysParam.Instance.reSampleFre;
            }
            if (SysParam.Instance.checkBoxTimeAll)
            {
                SetTimeGra_All(tx, tvib, x_min, x_max, SysParam.Instance.comboBoxTimeAll, (standNo + 1) + "号机架时域波形", standNo);
            }
            if (SysParam.Instance.checkBoxTimeL)
            {
                SetTimeGra_LMH(tx, tvib, x_min, x_max, stand.band_Fre_L1, stand.band_Fre_L2, SysParam.Instance.comboBoxTimeL, (standNo + 1) + "号机架低频时域", standNo);
            }
            if (SysParam.Instance.checkBoxTimeM)
            {
                SetTimeGra_LMH(tx, tvib, x_min, x_max, stand.band_Fre_M1, stand.band_Fre_M2, SysParam.Instance.comboBoxTimeM, (standNo + 1) + "号机架中频时域", standNo);
            }
            if (SysParam.Instance.checkBoxTimeH)
            {
                SetTimeGra_LMH(tx, tvib, x_min, x_max, stand.band_Fre_H1, stand.band_Fre_H2, SysParam.Instance.comboBoxTimeH, (standNo + 1) + "号机架高频时域", standNo);
            }
            if (SysParam.Instance.checkBoxTimeFre)
            {
                SetTimeGra_Fre(tvib, SysParam.Instance.comboBoxTimeFre, (standNo + 1) + "号机架频谱");
            }
            if (SysParam.Instance.checkBoxTimeFilt)
            {
                SetTimeGra_LMH(tx, tvib, x_min, x_max, Convert.ToInt32(SysParam.Instance.textBoxf1), Convert.ToInt32(SysParam.Instance.textBoxf2), SysParam.Instance.ComboBoxTimeFilt, (standNo + 1) + "号机架带通滤波", standNo);
            }
        }

        private void OrderByKind_Time()
        {
            if (SysParam.Instance.checkBoxTimeAll)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    double[] tvib = getData(i, indexPos, displayPoints);
                    double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                    double x_max = x_min + timeSpan;
                    double[] tx = new double[displayPoints];
                    for (int j = 0; j < displayPoints; j++)
                    {
                        tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                    }
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        SetTimeGra_All(tx, tvib, x_min, x_max, SysParam.Instance.comboBoxTimeAll, (i + 1) + "号机架时域波形", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeL)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 0; i < 5; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        GetAlarmParam(fileHelper.originSpeedList[i][indexPos], macReview.Stand[i]);
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, macReview.Stand[i].band_Fre_L1, macReview.Stand[i].band_Fre_L2, SysParam.Instance.comboBoxTimeL, (i + 1) + "号机架低频时域", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeM)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 0; i < 5; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        GetAlarmParam(fileHelper.originSpeedList[i][indexPos], macReview.Stand[i]);
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, macReview.Stand[i].band_Fre_M1, macReview.Stand[i].band_Fre_M2, SysParam.Instance.comboBoxTimeM, (i + 1) + "号机架中频时域", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeH)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 0; i < 5; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        GetAlarmParam(fileHelper.originSpeedList[i][indexPos], macReview.Stand[i]);
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, macReview.Stand[i].band_Fre_H1, macReview.Stand[i].band_Fre_H2, SysParam.Instance.comboBoxTimeH, (i + 1) + "号机架高频时域", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeFre)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        SetTimeGra_Fre(tvib, SysParam.Instance.comboBoxTimeFre, (i + 1) + "号机架频谱");
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeFilt)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, Convert.ToInt32(SysParam.Instance.textBoxf1), Convert.ToInt32(SysParam.Instance.textBoxf2), SysParam.Instance.ComboBoxTimeFilt, (i + 1) + "号机架带通滤波", i);
                    }
                }
            }
        }

        private void OrderByKind_Time2()
        {
            if (SysParam.Instance.checkBoxTimeAll)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    double[] tvib = getData(i, indexPos, displayPoints);
                    double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                    double x_max = x_min + timeSpan;
                    double[] tx = new double[displayPoints];
                    for (int j = 0; j < displayPoints; j++)
                    {
                        tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                    }
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        SetTimeGra_All(tx, tvib, x_min, x_max, SysParam.Instance.comboBoxTimeAll, (i + 1) + "号机架时域波形", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeL)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 0; i < 5; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        GetAlarmParam(fileHelper.originSpeedList[i][indexPos], macReview.Stand[i]);
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, macReview.Stand[i].band_Fre_L1, macReview.Stand[i].band_Fre_L2, SysParam.Instance.comboBoxTimeL, (i + 1) + "号机架低频时域", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeM)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 0; i < 5; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        GetAlarmParam(fileHelper.originSpeedList[i][indexPos], macReview.Stand[i]);
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, macReview.Stand[i].band_Fre_M1, macReview.Stand[i].band_Fre_M2, SysParam.Instance.comboBoxTimeM, (i + 1) + "号机架中频时域", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeH)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 0; i < 5; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        GetAlarmParam(fileHelper.originSpeedList[i][indexPos], macReview.Stand[i]);
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, macReview.Stand[i].band_Fre_H1, macReview.Stand[i].band_Fre_H2, SysParam.Instance.comboBoxTimeH, (i + 1) + "号机架高频时域", i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeFre)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        SetTimeGra_Fre(tvib, SysParam.Instance.comboBoxTimeFre, (i + 1) + "号机架频谱");
                    }
                }
            }
            if (SysParam.Instance.checkBoxTimeFilt)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        double[] tvib = getData(i, indexPos, displayPoints);
                        double x_min = indexPos * Convert.ToDouble(SysParam.Instance.reSamplePoint) / SysParam.Instance.reSampleFre;
                        double x_max = x_min + timeSpan;
                        double[] tx = new double[displayPoints];
                        for (int j = 0; j < displayPoints; j++)
                        {
                            tx[j] = x_min + Convert.ToDouble(j) / SysParam.Instance.reSampleFre;
                        }
                        SetTimeGra_LMH(tx, tvib, x_min, x_max, Convert.ToInt32(SysParam.Instance.textBoxf1), Convert.ToInt32(SysParam.Instance.textBoxf2), SysParam.Instance.ComboBoxTimeFilt, (i + 1) + "号机架带通滤波", i);
                    }
                }
            }
        }
        private void OrderByChannel_Energy(int standNo)
        {
            if (standNo >= SysParam.Instance.SpeedChannelCount)
            {
                return;
            }
            if (SysParam.Instance.checkBoxEnergyAll)
            {
                energy_All(fileHelper.energyData, SysParam.Instance.comboBoxEnergyAll, standNo);
            }
            if (SysParam.Instance.checkBoxEnergyL)
            {
                energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyL, standNo, 0, "低频");
            }
            if (SysParam.Instance.checkBoxEnergyM)
            {
                energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyM, standNo, 1, "中频");
            }
            if (SysParam.Instance.checkBoxEnergyH)
            {
                energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyH, standNo, 2, "高频");
            }
            if (SysParam.Instance.checkBoxEnergySpeed && (standNo < SysParam.Instance.SpeedChannelCount))
            {
                energy_Speed(fileHelper.energyData, SysParam.Instance.comboBoxEnergySpeed, standNo);
            }
        }
        private void OrderByKind_Energy()
        {
            if (SysParam.Instance.checkBoxEnergyAll)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_All(fileHelper.energyData, SysParam.Instance.comboBoxEnergyAll, i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergyL)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyL, i, 0, "低频");
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergyM)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyM, i, 1, "中频");
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergyH)
            {
                //for (int i = 0; i < SysParam.Instance.channelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyH, i, 2, "高频");
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergySpeed)
            {
                //for (int i = 0; i < SysParam.Instance.SpeedChannelCount; i++)
                for (int i = SysParam.Instance.SpeedChannelCount-1; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_Speed(fileHelper.energyData, SysParam.Instance.comboBoxEnergySpeed, i);
                    }
                }
            }
        }

        private void OrderByKind_Energy2()
        {
            if (SysParam.Instance.checkBoxEnergyAll)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_All(fileHelper.energyData, SysParam.Instance.comboBoxEnergyAll, i);
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergyL)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyL, i, 0, "低频");
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergyM)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyM, i, 1, "中频");
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergyH)
            {
                for (int i = 0; i < SysParam.Instance.channelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_LMH(fileHelper.energyData, SysParam.Instance.comboBoxEnergyH, i, 2, "高频");
                    }
                }
            }
            if (SysParam.Instance.checkBoxEnergySpeed)
            {
                for (int i = 0; i < SysParam.Instance.SpeedChannelCount; i++)
                //for (int i = 4; i >= 0; i--)
                {
                    if (SysParam.Instance.channel[i].ChChecked)
                    {
                        energy_Speed(fileHelper.energyData, SysParam.Instance.comboBoxEnergySpeed, i);
                    }
                }
            }
        }

        private void SetTimeGra_All(double[] tx, double[] lineList, double xmin, double xmax, string yAxisVal, string title, int standno)
        {
            if (standno >= SysParam.Instance.SpeedChannelCount)
            {
                return;
            }
            //DevelopLog.DeBug.WriteLogFile("review", "XXXXXXXXXX");
            gpt = new GraphPane();
            gpt.CurveList.Clear();
            if (standno < SysParam.Instance.SpeedChannelCount)
            {
                //辊系故障判别线
                if (SysParam.Instance.rollLineVisible && fileHelper.originSpeedList[standno][indexPos] > 5)
                {
                    double rotatetimeB, rotatetimeM, rotatetimeW;
                    rotatetimeB = (Math.PI * (macReview.Stand[standno].rollDiameterBL + macReview.Stand[standno].rollDiameterBU) / 2.0) / (fileHelper.originSpeedList[standno][indexPos] / 60 * 1000);//支撑辊的旋转周期
                    rotatetimeM = (Math.PI * (macReview.Stand[standno].rollDiameterML + macReview.Stand[standno].rollDiameterMU) / 2.0) / (fileHelper.originSpeedList[standno][indexPos] / 60 * 1000);//中间辊的旋转周期
                    rotatetimeW = (Math.PI * (macReview.Stand[standno].rollDiameterWL + macReview.Stand[standno].rollDiameterWU) / 2.0) / (fileHelper.originSpeedList[standno][indexPos] / 60 * 1000);//工作辊的旋转周期

                    if (rotatetimeB < timeSpan)
                    {
                        double[] x = { rotatetimeB + xmin, rotatetimeB + xmin };
                        double[] y = { Convert.ToDouble(yAxisVal), -Convert.ToDouble(yAxisVal) };
                        gpt.AddStick("支撑辊(" + rotatetimeB.ToString("0.000") + "s)", x, y, SysParam.Instance.colorBackupRoll).Line.Width = 2f;
                    }
                    if (rotatetimeM < timeSpan)
                    {
                        double[] x = { rotatetimeM + xmin, rotatetimeM + xmin };
                        double[] y = { Convert.ToDouble(yAxisVal), -Convert.ToDouble(yAxisVal) };
                        gpt.AddStick("中间辊(" + rotatetimeM.ToString("0.000") + "s)", x, y, SysParam.Instance.colorMidRoll).Line.Width = 2f;
                    }
                    if (rotatetimeW < timeSpan)
                    {
                        double[] x = { rotatetimeW + xmin, rotatetimeW + xmin };
                        double[] y = { Convert.ToDouble(yAxisVal), -Convert.ToDouble(yAxisVal) };
                        gpt.AddStick("工作辊(" + rotatetimeW.ToString("0.000") + "s)", x, y, SysParam.Instance.colorWorkRoll).Line.Width = 2f;
                    }
                }
            }
            gpt.AddCurve("", tx, lineList, SysParam.Instance.colorTime, SymbolType.None);
            gpt.XAxis.Scale.Min = xmin;
            gpt.XAxis.Scale.Max = xmax;
            gpt.YAxis.Scale.Min = -Convert.ToSingle(yAxisVal);
            gpt.YAxis.Scale.Max = Convert.ToSingle(yAxisVal);
            gpt.Title.Text = title;
            GraPaneSetting(gpt);
            master.Add(gpt);
        }

        private void SetTimeGra_LMH(double[] tx, double[] lineList, double xmin, double xmax, int fre_1, int fre_2, string yAxisVal, string title, int standno)
        {
            if (standno >= SysParam.Instance.SpeedChannelCount)
            {
                return;
            }
            gpt = new GraphPane();
            gpt.CurveList.Clear();
            if (standno < SysParam.Instance.SpeedChannelCount)
            {
                //辊系故障判别线
                if (SysParam.Instance.rollLineVisible && fileHelper.originSpeedList[standno][indexPos] > 5)
                {
                    double rotatetimeB, rotatetimeM, rotatetimeW;
                    rotatetimeB = (Math.PI * (macReview.Stand[standno].rollDiameterBL + macReview.Stand[standno].rollDiameterBU) / 2.0) / (fileHelper.originSpeedList[standno][indexPos] / 60 * 1000);//支撑辊的旋转周期
                    rotatetimeM = (Math.PI * (macReview.Stand[standno].rollDiameterML + macReview.Stand[standno].rollDiameterMU) / 2.0) / (fileHelper.originSpeedList[standno][indexPos] / 60 * 1000);//中间辊的旋转周期
                    rotatetimeW = (Math.PI * (macReview.Stand[standno].rollDiameterWL + macReview.Stand[standno].rollDiameterWU) / 2.0) / (fileHelper.originSpeedList[standno][indexPos] / 60 * 1000);//工作辊的旋转周期

                    if (rotatetimeB < timeSpan)
                    {
                        double[] x = { rotatetimeB + xmin, rotatetimeB + xmin };
                        double[] y = { Convert.ToDouble(yAxisVal), -Convert.ToDouble(yAxisVal) };
                        gpt.AddStick("支撑辊(" + rotatetimeB.ToString("0.000") + "s)", x, y, SysParam.Instance.colorBackupRoll).Line.Width = 2f;
                    }
                    if (rotatetimeM < timeSpan)
                    {
                        double[] x = { rotatetimeM + xmin, rotatetimeM + xmin };
                        double[] y = { Convert.ToDouble(yAxisVal), -Convert.ToDouble(yAxisVal) };
                        gpt.AddStick("中间辊(" + rotatetimeM.ToString("0.000") + "s)", x, y, SysParam.Instance.colorMidRoll).Line.Width = 2f;
                    }
                    if (rotatetimeW < timeSpan)
                    {
                        double[] x = { rotatetimeW + xmin, rotatetimeW + xmin };
                        double[] y = { Convert.ToDouble(yAxisVal), -Convert.ToDouble(yAxisVal) };
                        gpt.AddStick("工作辊(" + rotatetimeW.ToString("0.000") + "s)", x, y, SysParam.Instance.colorWorkRoll).Line.Width = 2f;
                    }
                }
            }

            int length = lineList.Length;
            //double[] tXAxis = new double[length];
            double[] llf;
            llf = SysParam.Instance.filterAlgor(lineList, fre_1, fre_2, length, 100, Convert.ToInt32(SysParam.Instance.reSampleFre));
            //for (int i = 0; i < length; i++)
            //{
            //    tXAxis[i] = Convert.ToDouble(i) / SysParam.Instance.sampleFre;
            //}
            gpt.AddCurve("", tx, llf, SysParam.Instance.colorTime, SymbolType.None);
            gpt.XAxis.Scale.Min = xmin;
            gpt.XAxis.Scale.Max = xmax;
            gpt.YAxis.Scale.Min = -Convert.ToSingle(yAxisVal);
            gpt.YAxis.Scale.Max = Convert.ToSingle(yAxisVal);
            gpt.Title.Text = title;
            GraPaneSetting(gpt);
            master.Add(gpt);
        }

        private void SetTimeGra_Fre(double[] lineList, string yAxisVal, string title)
        {

            gpt = new GraphPane();
            gpt.CurveList.Clear();
            PointPairList list_f = new PointPairList();
            list_f.Clear();
            int orgLength = lineList.Length;
            int length = Convert.ToInt32(Math.Pow(2, SysParam.Instance.N2M(orgLength)));
            double[] f = new double[length];
            double[] tt = new double[length];
            for (int i = 0; i < length; i++)
            {
                tt[i] = lineList[orgLength - length + i];
            }
            SysParam.Instance.FFT(tt, f, length, 1);
            for (int i = 0; i < length / 2; i++)
            {
                f[i] = 2 * Math.Sqrt(tt[i] * tt[i] + f[i] * f[i]) / length;
                list_f.Add(Convert.ToDouble(i) * SysParam.Instance.reSampleFre / length, f[i]);
            }
            gpt.AddCurve("", list_f, SysParam.Instance.colorFre, SymbolType.None);
            gpt.XAxis.Scale.Max = 1000;
            gpt.XAxis.Scale.Min = 0;
            gpt.YAxis.Scale.Max = Convert.ToSingle(yAxisVal);
            gpt.YAxis.Scale.Min = 0;
            gpt.Title.Text = title;
            GraPaneSetting(gpt);
            master.Add(gpt);
        }
        private void energy_All(double[,] lineList, string yAxisVal, int stdNo)
        {
            if (stdNo >= SysParam.Instance.SpeedChannelCount)
            {
                return;
            }
            gpt = new GraphPane();
            gpt.CurveList.Clear();
            int length = fileHelper.signalLengthEnergy;
            double[] tx = new double[length];
            double[] ty = new double[length];
            for (int i = 0; i < length; i++)
            {
                tx[i] = i * SysParam.Instance.reSamplePoint / Convert.ToDouble(SysParam.Instance.reSampleFre);
                ty[i] = lineList[stdNo * 8 + 1, i];
            }
            gpt.AddCurve("", tx, ty, SysParam.Instance.colorEnergy, SymbolType.None);
            gpt.XAxis.Scale.Min = 0.0;
            gpt.XAxis.Scale.Max = tx[length - 1];
            gpt.YAxis.Scale.Min = 0.0;
            gpt.YAxis.Scale.Max = Convert.ToDouble(yAxisVal);
            gpt.Title.Text = (stdNo + 1) + "号机架全局能量";
            GraPaneSetting(gpt);
            this.master.Add(gpt);
        }

        private void energy_LMH(double[,] lineList, string yAxisVal, int stdNo, int typeNo, string type)
        {
            if (stdNo >= SysParam.Instance.SpeedChannelCount)
            {
                return;
            }
            gpt = new GraphPane();
            gpt.CurveList.Clear();
            int length = fileHelper.signalLengthEnergy;
            double[] tx = new double[length];
            double[] ty = new double[length];
            double[] tyalarm = new double[length];
            for (int i = 0; i < length; i++)
            {
                tx[i] = i * SysParam.Instance.reSamplePoint / Convert.ToDouble(SysParam.Instance.reSampleFre);
                ty[i] = lineList[stdNo * 8 + 2 + typeNo, i];
                tyalarm[i] = lineList[stdNo * 8 + 5 + typeNo, i];
            }
            gpt.AddCurve("能量线", tx, ty, SysParam.Instance.colorEnergy, SymbolType.None);
            gpt.AddCurve("报警线", tx, tyalarm, SysParam.Instance.colorAlarm, SymbolType.None).Line.Width = 2f;

            gpt.XAxis.Scale.Min = 0.0;
            gpt.XAxis.Scale.Max = tx[length - 1];
            gpt.YAxis.Scale.Min = 0.0;
            gpt.YAxis.Scale.Max = Convert.ToDouble(yAxisVal);
            gpt.Title.Text = (stdNo + 1) + "号机架" + type + "能量";
            GraPaneSetting(gpt);
            this.master.Add(gpt);
        }

        private void energy_Speed(double[,] lineList, string yAxisVal, int stdNo)
        {
            if (stdNo >= SysParam.Instance.SpeedChannelCount)
            {
                return;
            }
            gpt = new GraphPane();
            gpt.CurveList.Clear();
            int length = fileHelper.signalLengthEnergy;
            double[] tx = new double[length];
            double[] ty = new double[length];
            for (int i = 0; i < length; i++)
            {
                tx[i] = i * SysParam.Instance.reSamplePoint / Convert.ToDouble(SysParam.Instance.reSampleFre);
                ty[i] = lineList[stdNo * 8, i];
            }
            gpt.AddCurve("", tx, ty, SysParam.Instance.colorSpeed, SymbolType.None).Line.IsSmooth = true;
            gpt.XAxis.Scale.Min = 0.0;
            gpt.XAxis.Scale.Max = tx[length - 1];
            gpt.YAxis.Scale.Min = 0.0;
            gpt.YAxis.Scale.Max = Convert.ToDouble(yAxisVal);
            gpt.Title.Text = (stdNo + 1) + "号机架速度";
            GraPaneSetting(gpt);
            this.master.Add(gpt);
        }

        private static void GraPaneSetting(GraphPane tempGraph)
        {
            float fontsize = SysParam.Instance.fontSize;
            Color myFontColor = SysParam.Instance.colorFont;
            //tempGraph.Margin.All = 2f;
            tempGraph.Fill.IsVisible = false;
            tempGraph.IsFontsScaled = false;
            tempGraph.TitleGap = 0f;
            tempGraph.Margin.All = 3f;
            tempGraph.Border.Color = Color.FromArgb(127, myFontColor);

            tempGraph.Chart.Border.Color = myFontColor;
            tempGraph.Chart.Fill.IsVisible = false;

            tempGraph.Title.FontSpec.FontColor = myFontColor;
            tempGraph.Title.FontSpec.Family = "微软雅黑";
            tempGraph.Title.FontSpec.IsBold = false;
            tempGraph.Title.FontSpec.Size = 1.2f * fontsize;

            tempGraph.Legend.Border.IsVisible = false;
            tempGraph.Legend.Position = LegendPos.InsideTopLeft;
            tempGraph.Legend.IsHStack = false;
            tempGraph.Legend.IsShowLegendSymbols = false;
            tempGraph.Legend.FontSpec.Size = 0.8f * fontsize;
            tempGraph.Legend.Fill.IsVisible = false;
            tempGraph.Legend.FontSpec.FontColor = myFontColor;
            tempGraph.Legend.FontSpec.Family = "微软雅黑";

            tempGraph.XAxis.Title.FontSpec.Family = "微软雅黑";
            tempGraph.XAxis.Title.FontSpec.IsBold = false;
            tempGraph.XAxis.Scale.FontSpec.FontColor = myFontColor;
            tempGraph.XAxis.Scale.FontSpec.Size = fontsize;
            tempGraph.XAxis.Title.IsVisible = false;
            tempGraph.XAxis.MajorTic.IsOutside = false;
            tempGraph.XAxis.MajorTic.Color = Color.FromArgb(127, myFontColor);
            tempGraph.XAxis.MinorTic.IsAllTics = false;

            tempGraph.YAxis.Title.FontSpec.Family = "微软雅黑";
            tempGraph.YAxis.Title.FontSpec.IsBold = false;
            tempGraph.YAxis.Scale.FontSpec.FontColor = myFontColor;
            tempGraph.YAxis.Scale.FontSpec.Size = fontsize;
            tempGraph.XAxis.Title.IsVisible = false;
            tempGraph.YAxis.MajorTic.IsOutside = false;
            tempGraph.YAxis.MajorTic.Color = Color.FromArgb(127, myFontColor);
            tempGraph.YAxis.MinorTic.IsAllTics = false;
            tempGraph.YAxis.MajorGrid.IsZeroLine = false;


            if (SysParam.Instance.BackgroundGridOn)
            {
                tempGraph.XAxis.MajorGrid.IsVisible = true;
                tempGraph.XAxis.MajorGrid.Color = Color.FromArgb(127, myFontColor);
                tempGraph.YAxis.MajorGrid.IsVisible = true;
                tempGraph.YAxis.MajorGrid.Color = Color.FromArgb(127, myFontColor);
            }
            else
            {
                tempGraph.XAxis.MajorGrid.IsVisible = false;
                tempGraph.YAxis.MajorGrid.IsVisible = false;
            }
        }

        private double[] getData(int standNo, int index, int length)
        {
            double[] originData = new double[length];
            index = index * SysParam.Instance.reSamplePoint;
            try
            {
                for (int i = 0; i < length; i++)
                {
                    originData[i] = fileHelper.originDataList[standNo][index + i];
                }
            }
            catch (Exception)
            {
                originData = new double[length];
                for (int i = 0; i < length; i++)
                {
                    originData[i] = fileHelper.originDataList[standNo][fileHelper.signalLengthOrigin - length + i];
                }
            }
            return originData;
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (fileHelper.signalLengthOrigin >= SysParam.Instance.reSampleFre)
            {
                stepBar.Maximum = fileHelper.signalLengthOrigin - Convert.ToInt32(SysParam.Instance.reTimeSpan) * SysParam.Instance.reSampleFre;
                int ecchstep = orient * coeff;
                timeSpan = Convert.ToDouble(SysParam.Instance.reTimeSpan);
                displayPoints = Convert.ToInt32(timeSpan * SysParam.Instance.reSampleFre);
                indexPos = indexPos + ecchstep;
                if (indexPos < 0)
                {
                    indexPos = 0;
                }
                if (indexPos * SysParam.Instance.reSamplePoint + displayPoints <= fileHelper.signalLengthOrigin)
                {
                    stepBar.Value = indexPos * SysParam.Instance.reSamplePoint;
                    GraRefresh();
                }
                else
                {
                    timer1.Enabled = false;
                    btRight.Enabled = false;
                    btLeft.Enabled = true;
                }
            }
            else
            {
                timer1.Enabled = false;
                MessageBox.Show("记录长度短于1秒，不可回放！", "警告");
                btRight.Enabled = false;
                btPause.Enabled = false;
                btStart.Enabled = false;
                master.PaneList.Clear();
            }

        }

        private void btStart_Click(object sender, EventArgs e)
        {
            //indexPos = 0;
            orient = 1;
            timer1.Enabled = true;
            btStop.Enabled = true;
            btPause.Enabled = true;
            btStart.Enabled = false;
            btRight.Enabled = false;
            btLeft.Enabled = true;
        }

        private void btStop_Click(object sender, EventArgs e)
        {
            indexPos = 0;
            timer1.Enabled = false;
            btStart.Enabled = true;
            btStop.Enabled = false;
            btPause.Enabled = false;
            btRight.Enabled = false;
            btLeft.Enabled = false;
            stepBar.Value = 0;
            LoadIni();
        }

        private void btPaues_Click(object sender, EventArgs e)
        {
            stepBar.Enabled = true;
            timer1.Enabled = false;
            btStart.Enabled = false;
            btStop.Enabled = false;
            btPause.Enabled = false;
            btRight.Enabled = true;
            btLeft.Enabled = true;
        }

        private void btRight_Click(object sender, EventArgs e)
        {
            orient = 1;
            timer1.Enabled = true;
            btStart.Enabled = false;
            btStop.Enabled = true;
            btPause.Enabled = true;
            btRight.Enabled = false;
            btLeft.Enabled = true;
        }

        private void stepBar_Scroll(object sender, ScrollEventArgs e)
        {
            stepBar.Maximum = fileHelper.signalLengthOrigin - Convert.ToInt32(SysParam.Instance.reTimeSpan) * SysParam.Instance.reSampleFre;
            //int eachstep = orient * coeff;
            timeSpan = Convert.ToDouble(SysParam.Instance.reTimeSpan);
            displayPoints = Convert.ToInt32(timeSpan * SysParam.Instance.reSampleFre);
            indexPos = Convert.ToInt32(stepBar.Value / SysParam.Instance.reSamplePoint);
            if (indexPos * SysParam.Instance.reSamplePoint + displayPoints <= fileHelper.signalLengthOrigin)
            {
                stepBar.Value = indexPos * SysParam.Instance.reSamplePoint;
            }
            else
            {
                btRight.Enabled = false;
                btLeft.Enabled = true;
            }
            GraRefresh();
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            int itmp = trackBar1.Value;
            if (itmp < 0)
            {
                timer1.Interval = -itmp * 200;
            }
            else if (itmp == 0)
            {
                timer1.Interval = 200;
            }
            else
            {
                timer1.Interval = 200 / itmp;
            }
            if (itmp > 1)
            {
                coeff = itmp / 2;
            }
            else
            {
                coeff = 1;
            }
        }

        private void btLeft_Click(object sender, EventArgs e)
        {
            orient = -1;
            timer1.Enabled = true;
            btStart.Enabled = false;
            btStop.Enabled = true;
            btPause.Enabled = true;
            btRight.Enabled = true;
            btLeft.Enabled = false;
        }

        private void GetAlarmParam(double speed, Stand std)
        {
            int ias = std.alarm_spd.Length;
            int i_fre = std.fre_l_S1.Length - 1;
            int iIndex = std.alarm_spd[0].alarmSpeed;
            if (speed <= std.alarm_spd[0].alarmSpeed)
            {
                std.band_Fre_L1 = std.fre_l_S1[0];//.fre_l_A1;
                std.band_Fre_L2 = std.fre_l_S2[0];
                std.band_Fre_M1 = std.fre_m_S1[0];
                std.band_Fre_M2 = std.fre_m_S2[0];
                std.band_Fre_H1 = std.fre_h_S1[0];
                std.band_Fre_H2 = std.fre_h_S2[0];
                std.alarm_L_Value_ck = std.fre_l_V[0];
                std.alarm_M_Value_ck = std.fre_m_V[0];
                std.alarm_H_Value_ck = std.fre_h_V[0];
                std.defect_L_Value_ck = std.fre_l_D[0];
                std.defect_M_Value_ck = std.fre_m_D[0];
                std.defect_H_Value_ck = std.fre_h_D[0];
            }
            else if (speed >= std.alarm_spd[ias - 1].alarmSpeed)
            {
                std.band_Fre_L1 = std.fre_l_S1[i_fre];
                std.band_Fre_L2 = std.fre_l_S2[i_fre];
                std.band_Fre_M1 = std.fre_m_S1[i_fre];
                std.band_Fre_M2 = std.fre_m_S2[i_fre];
                std.band_Fre_H1 = std.fre_h_S1[i_fre];
                std.band_Fre_H2 = std.fre_h_S2[i_fre];
                std.alarm_L_Value_ck = std.fre_l_V[i_fre];
                std.alarm_M_Value_ck = std.fre_m_V[i_fre];
                std.alarm_H_Value_ck = std.fre_h_V[i_fre];
                std.defect_L_Value_ck = std.fre_l_D[i_fre];
                std.defect_M_Value_ck = std.fre_m_D[i_fre];
                std.defect_H_Value_ck = std.fre_h_D[i_fre];
            }
            else
            {
                std.band_Fre_L1 = std.fre_l_S1[Convert.ToInt32(speed - iIndex)];
                std.band_Fre_L2 = std.fre_l_S2[Convert.ToInt32(speed - iIndex)];
                std.band_Fre_M1 = std.fre_m_S1[Convert.ToInt32(speed - iIndex)];
                std.band_Fre_M2 = std.fre_m_S2[Convert.ToInt32(speed - iIndex)];
                std.band_Fre_H1 = std.fre_h_S1[Convert.ToInt32(speed - iIndex)];
                std.band_Fre_H2 = std.fre_h_S2[Convert.ToInt32(speed - iIndex)];
                std.alarm_L_Value_ck = std.fre_l_V[Convert.ToInt32(speed - iIndex)];
                std.alarm_M_Value_ck = std.fre_m_V[Convert.ToInt32(speed - iIndex)];
                std.alarm_H_Value_ck = std.fre_h_V[Convert.ToInt32(speed - iIndex)];
                std.defect_L_Value_ck = std.fre_l_D[Convert.ToInt32(speed - iIndex)];
                std.defect_M_Value_ck = std.fre_m_D[Convert.ToInt32(speed - iIndex)];
                std.defect_H_Value_ck = std.fre_h_D[Convert.ToInt32(speed - iIndex)];
            }
        }

        private string zedGraphControl1_PointValueEvent(ZedGraphControl sender, GraphPane pane, CurveItem curve, int iPt)
        {
            if (pane.Title.Text.Contains("能量"))
            {
                if (iPt < curve.Points.Count)
                {
                    PointPair pt = curve[iPt];
                    return "X:" + (pt.X.ToString("0.0") + "s   " + pt.Y.ToString("0.00000") + "g   Y:" + fileHelper.originDistanceList[iPt].ToString("0.0") + "m");
                }
                else
                {
                    return "";
                }
            }
            else if (pane.Title.Text.Contains("速度"))
            {
                if (iPt < curve.Points.Count)
                {
                    PointPair pt = curve[iPt];
                    return "X:" + (pt.X.ToString("0.0") + "s   " + pt.Y.ToString("0.0") + "m/min   Y:" + fileHelper.originDistanceList[iPt].ToString("0.0") + "m");
                }
                else
                {
                    return "";
                }
            }
            else if (pane.Title.Text.Contains("频谱"))
            {
                if (iPt < curve.Points.Count)
                {
                    PointPair pt = curve[iPt];
                    return "X:" + (pt.X.ToString("0.0") + "Hz   Y:" + pt.Y.ToString("0.00000") + "g");
                }
                else
                {
                    return "";
                }
            }
            else
            {
                if (iPt < curve.Points.Count)
                {
                    PointPair pt = curve[iPt];
                    return "X:" + (pt.X.ToString("0.000") + "s   Y:" + pt.Y.ToString("0.00000") + "g");
                }
                else
                {
                    return "";
                }
            }
        }

        private void zedGraphControl1_ContextMenuBuilder(ZedGraphControl sender, ContextMenuStrip menuStrip, Point mousePt, ZedGraphControl.ContextMenuObjectState objState)
        {
            for (int i = 0; i < menuStrip.Items.Count; i++)
            {
                switch (menuStrip.Items[i].Tag.ToString().Trim())
                {
                    case "copy":
                        menuStrip.Items[i].Text = "复制图片";
                        break;
                    case "show_val":
                        menuStrip.Items[i].Text = "查看坐标";
                        break;
                    case "save_as":
                        menuStrip.Items[i].Text = "图片保存至...";
                        break;
                    case "page_setup":
                        menuStrip.Items[i].Text = "页面设置";
                        break;
                    case "print":
                        menuStrip.Items[i].Text = "打印";
                        break;
                    case "unzoom":
                        menuStrip.Items[i].Text = "还原缩放";
                        break;
                    case "undo_all":
                        menuStrip.Items[i].Text = @"还原缩放\移动";
                        break;
                    case "set_default":
                        menuStrip.Items[i].Text = "恢复默认设置";
                        break;
                }
            }
        }

        private void zedGraphControl1_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
        {
            if (cursorPane == null)
            {
                return;
            }
            else
            {
                for (int i = 0; i < sender.MasterPane.PaneList.Count; i++)
                {
                    bool isZoom = false;
                    GraphPane tempPane = sender.MasterPane.PaneList[i];

                    string selectTxt = cursorPane.Title.Text.Substring(1, cursorPane.Title.Text.Length - 1);
                    string tempTxt = tempPane.Title.Text.Substring(1, tempPane.Title.Text.Length - 1);

                    if (selectTxt == tempTxt)//不同机架同类型的图谱一起缩放
                    {
                        isZoom = true;
                    }

                    if (isZoom)
                    {
                        //tempPane.CurveList.Contains
                        if (newState.IsChanged(tempPane))
                        {
                            newState.ApplyState(tempPane);
                        }
                    }
                }

            }

        }


        private void zedGraphControl1_MouseMove(object sender, MouseEventArgs e)
        {
            /*for (int i = 0; i < zedGraphControl1.MasterPane.PaneList.Count; i++)
            {
                GraphPane tempPane = zedGraphControl1.MasterPane.PaneList[i];

                double[] x = { tempPane.XAxis.Scale.Min, tempPane.XAxis.Scale.Min };
                double[] y = { tempPane.YAxis.Scale.Max, -tempPane.YAxis.Scale.Max };

                tempPane.AddStick("", x, y, SysParam.Instance.colorBackupRoll).Line.Width = 2f;
                zedGraphControl1.Refresh();
            }*/

            /*using (Graphics gc = zedGraphControl1.CreateGraphics())
            using (Pen pen = new Pen(Color.Green))
            {
                //设置画笔的宽度
                pen.Width = 1;
                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;

                for (int i = 0; i < zedGraphControl1.MasterPane.PaneList.Count; i++)
                {
                    RectangleF rect = zedGraphControl1.MasterPane.PaneList[i].Chart.Rect;
                    //确保在画图区域
                    if (rect.Contains(e.Location))
                    {
                        zedGraphControl1.Refresh();
                        textBox_Msg.Text += "moving" + "\r\n";
                        //画竖线
                        gc.DrawLine(pen, e.X, rect.Top, e.X, rect.Bottom);
                        //画横线
                        //gc.DrawLine(pen, rect.Left, e.Y, rect.Right, e.Y);
                    }
                }

            }*/
        }

        GraphPane cursorPane = null;
        private string zedGraphControl1_CursorValueEvent(ZedGraphControl sender, GraphPane pane, Point mousePt)
        {

            CurveItem nearstCure;
            int iPt;
            pane.FindNearestPoint(mousePt, out nearstCure, out iPt);

            cursorPane = pane;

            //textBox_Msg.Text += "curisng" + "\r\n";

            if (!pane.Title.Text.Contains("能量") && !pane.Title.Text.Contains("速度") && nearstCure != null)
            {
                iPtClick = -1;

                if (pane.Title.Text.Contains("能量"))
                {
                    PointPair pt = nearstCure[iPt];
                    return (pt.X.ToString("0.0") + "s   " + pt.Y.ToString("0.00000") + "g   " + fileHelper.originDistanceList[iPt].ToString("0.0") + "m");
                }
                else if (pane.Title.Text.Contains("速度"))
                {
                    PointPair pt = nearstCure[iPt];
                    return (pt.X.ToString("0.0") + "s   " + pt.Y.ToString("0.0") + "m/min   " + fileHelper.originDistanceList[iPt].ToString("0.0") + "m");
                }
                else if (pane.Title.Text.Contains("频谱"))
                {
                    PointPair pt = nearstCure[iPt];
                    return (pt.X.ToString("0.0") + "Hz   " + pt.Y.ToString("0.00000") + "g");
                }
                else
                {
                    PointPair pt = nearstCure[iPt];
                    return (pt.X.ToString("0.000") + "s   " + pt.Y.ToString("0.00000") + "g");
                }
            }


            if (iPtClick != iPt)
            {
                textBox_Msg.Text = "";
            }

            if (nearstCure != null && nearstCure.Points[iPt] != null)
            {
                if ((iPt < fileHelper.originDistanceList.Count) && (iPt >= 0))
                {
                    double disX = fileHelper.originDistanceList[iPt];
                    double y = nearstCure.Points[iPt].Y;
                    double x = nearstCure.Points[iPt].X;

                    iPtClick = iPt;



                    if (pane.Title.Text.Contains("能量"))
                    {
                        return (x.ToString("0.0") + "s " + disX.ToString("0.0") + "m  " + y.ToString("0.0000") + "g");
                    }
                    else if (pane.Title.Text.Contains("速度"))
                    {
                        return (x.ToString("0.0") + "s " + disX.ToString("0.0") + "m  " + y.ToString("0.0") + "m/min");
                    }
                    else
                    {
                        return "";
                    }
                }
                else
                {
                    return "";
                }
            }



            return default(string);
        }

        private void zedGraphControl1_MouseLeave(object sender, EventArgs e)
        {
            /*using (Graphics gc = zedGraphControl1.CreateGraphics())
            using (Pen pen = new Pen(Color.Green))
            {
                //设置画笔的宽度
                pen.Width = 1;
                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;

                for (int i = 0; i < zedGraphControl1.MasterPane.PaneList.Count; i++)
                {
                    RectangleF rect = zedGraphControl1.MasterPane.PaneList[i].Chart.Rect;

                    zedGraphControl1.Refresh();
                    //画竖线
                    gc.DrawLine(pen, 0, 0, 0, 0);
                    //画横线
                    //gc.DrawLine(pen, 0, 0, 0, 0);

                }

            }*/
        }



        private void zedGraphControl1_Click(object sender, EventArgs e)
        {

        }


        int iPtClick = 0;
        private void zedGraphControl1_MouseClick(object sender, MouseEventArgs e)
        {
            if (iPtClick == -1 || iPtClick > fileHelper.originDistanceList.Count)
            {
                textBox_Msg.Text = "";
                return;
            }

            string postion = "轧制距离：" + fileHelper.originDistanceList[iPtClick].ToString("0.0") + "m" + "\r\n";

            string allMsg = "";
            allMsg += postion + "\r\n";

            for (int i = 0; i < zedGraphControl1.MasterPane.PaneList.Count; i++)
            {
                GraphPane itemPane = zedGraphControl1.MasterPane.PaneList[i];
                if (itemPane.Title.Text.Contains("全局能量"))
                {
                    allMsg += itemPane.Title.Text + "\r\n";

                    string aMsg = "";
                    for (int j = 0; j < itemPane.CurveList.Count; j++)
                    {
                        CurveItem tempCurve = itemPane.CurveList[j];
                        PointPair pt = tempCurve[iPtClick];
                        aMsg += pt.Y.ToString("0.00000") + " g   " + "\r\n";
                    }

                    allMsg = allMsg + aMsg + "\r\n";
                }

                if (itemPane.Title.Text.Contains("低频能量") || itemPane.Title.Text.Contains("中频能量") || itemPane.Title.Text.Contains("高频能量"))
                {
                    allMsg += itemPane.Title.Text + "\r\n";

                    string aMsg = "";
                    for (int j = 0; j < itemPane.CurveList.Count; j++)
                    {
                        CurveItem tempCurve = itemPane.CurveList[j];
                        PointPair pt = tempCurve[iPtClick];

                        if (tempCurve.Label.Text == "能量线")
                        {
                            aMsg += "能量值:" + pt.Y.ToString("0.00000") + " g   " + "\r\n";
                        }
                        else if (tempCurve.Label.Text == "报警线")
                        {
                            aMsg += "报警值:" + pt.Y.ToString("0.00000") + " g   " + "\r\n";
                        }
                        else
                        {
                            aMsg += tempCurve.Label.Text + ":" + pt.Y.ToString("0.00000") + " g   " + "\r\n";
                        }

                    }

                    allMsg = allMsg + aMsg + "\r\n";
                }

                if (itemPane.Title.Text.Contains("速度"))
                {
                    allMsg += itemPane.Title.Text + "\r\n";

                    string aMsg = "";
                    for (int j = 0; j < itemPane.CurveList.Count; j++)
                    {
                        CurveItem tempCurve = itemPane.CurveList[j];
                        PointPair pt = tempCurve[iPtClick];
                        aMsg += pt.Y.ToString("0.0") + " m/min   " + "\r\n";
                    }

                    allMsg = allMsg + aMsg + "\r\n";
                }
            }

            textBox_Msg.Text = allMsg;

        }
    }
}
