WindowCoating.xaml.cs 12.2 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using FLY.Simulation.Coating;

namespace FLYAD7_Simulation_Wpf
{
    /// <summary>
    /// WindowCoating.xaml 的交互逻辑
    /// </summary>
    public partial class WindowCoating : Window
    {
        Coating mCoating;
        List<double> mTrendData=new List<double>();//1cm 一个数据
        int FilmLength_cm=0;
        List<double> datas = new List<double>();
        public WindowCoating()
        {
            InitializeComponent();
            InitializeComponent_chart1();
            InitializeComponent_chart2();
        }

        public void Init(Coating coating) 
        {
            mCoating = coating;
36 37 38
            hmi_cc.DataContext = mCoating.hmi_cc.NowCtrl;
            inner_cc.DataContext = mCoating.inner_cc.NowCtrl;
            hmi.DataContext = mCoating.hmi;
潘栩锋's avatar
潘栩锋 committed
39

40
            
潘栩锋's avatar
潘栩锋 committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267

            this.DataContext = coating;

            DataBindAll();

            mCoating.DatasChanged += new Action(mCoating_DatasChanged);
            mCoating.AvgChanged += new Action<double, int>(mCoating_AvgChanged);
        }

        void mCoating_AvgChanged(double arg1, int arg2)
        {
            int filmlength_cm = (int)(arg1*100);
            if(FilmLength_cm == filmlength_cm)
            {

            }
            else
            {
                FilmLength_cm = filmlength_cm;
                if (datas.Count() > 0)
                {
                    this.Dispatcher.Invoke(new Action<int>((d) =>
                    {
                        chart1.Series["Trend"].Points.AddXY(FilmLength_cm / 100.0, d / 100.0);
                        while (chart1.Series["Trend"].Points.Count() > 5 * 100)
                        {
                            chart1.Series["Trend"].Points.RemoveAt(0);
                        }
                        chart1.ChartAreas["Trend"].AxisX.Minimum = chart1.Series["Trend"].Points[0].XValue;
                        chart1.ChartAreas["Trend"].AxisX.Maximum = chart1.Series["Trend"].Points[0].XValue + 5;
                        chart1.Invalidate();
                    }), (int)(datas.Average()));
                }
                datas.Clear();
            }
            datas.Add(arg2);
        }

        void mCoating_DatasChanged()
        {
            this.Dispatcher.Invoke(new Action(DataBindAll));
        }
        private void button_set_out_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textbox_pumpset_out.Text)) 
            {
                MessageBox.Show("格式出错");
                return;
            }
            else if (string.IsNullOrEmpty(textbox_leftset_out.Text))
            {
                MessageBox.Show("格式出错");
                return;
            }
            else if (string.IsNullOrEmpty(textbox_rightset_out.Text))
            {
                MessageBox.Show("格式出错");
                return;
            }
            else
            {
                double pumpset = double.Parse(textbox_pumpset_out.Text);
                double leftset = double.Parse(textbox_leftset_out.Text);
                double rightset = double.Parse(textbox_rightset_out.Text);

                mCoating.hmi_cc.SetCoatingCtrl(pumpset, leftset, rightset);
            }
        }
        private void button_set_inner_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(textbox_pumpset_inner.Text)) 
            {
                MessageBox.Show("格式出错");
                return;
            }
            else if (string.IsNullOrEmpty(textbox_leftset_inner.Text))
            {
                MessageBox.Show("格式出错");
                return;
            }
            else if (string.IsNullOrEmpty(textbox_rightset_inner.Text))
            {
                MessageBox.Show("格式出错");
                return;
            }
            else
            {
                double pumpset = double.Parse(textbox_pumpset_inner.Text);
                double leftset = double.Parse(textbox_leftset_inner.Text);
                double rightset = double.Parse(textbox_rightset_inner.Text);

                mCoating.inner_cc.SetCoatingCtrl(pumpset, leftset, rightset);
            }
        }


        void InitializeComponent_chart1()
        {
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea_trend = new System.Windows.Forms.DataVisualization.Charting.ChartArea();           
            System.Windows.Forms.DataVisualization.Charting.Series series_trend = new System.Windows.Forms.DataVisualization.Charting.Series();

            // 
            // chart1
            // 

            this.chart1.Name = "chart1";



            chartArea_trend.Name = "Trend";
            chartArea_trend.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea_trend.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_trend.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_trend.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea_trend.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_trend.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_trend.BackColor = System.Drawing.Color.OldLace;
            //chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            //chartArea1.BackSecondaryColor = System.Drawing.Color.White;
            chartArea_trend.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_trend.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;

            chartArea_trend.ShadowColor = System.Drawing.Color.Transparent;
            //对数坐标
            //chartArea1.AxisY.IsLogarithmic = true;
            //chartArea1.AxisY.LogarithmBase = Math.E;
            chartArea_trend.CursorX.IsUserEnabled = true;
            chartArea_trend.CursorX.IsUserSelectionEnabled = true;
            chartArea_trend.CursorX.SelectionColor = System.Drawing.SystemColors.Highlight;
            chartArea_trend.CursorY.IsUserEnabled = true;
            chartArea_trend.CursorY.IsUserSelectionEnabled = true;
            chartArea_trend.CursorY.SelectionColor = System.Drawing.SystemColors.Highlight;

            chartArea_trend.AxisX.LabelStyle.Format = @"{0:0}";
            this.chart1.ChartAreas.Add(chartArea_trend);

            //this.chart1.Location = new System.Drawing.Point(16, 32);

            series_trend.Name = "Trend";

            series_trend.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series_trend.BorderWidth = 3;
            series_trend.ChartArea = chartArea_trend.Name;
            series_trend.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series_trend.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));

            series_trend.ShadowColor = System.Drawing.Color.Black;
            series_trend.ShadowOffset = 2;
            series_trend.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series_trend.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;

            this.chart1.Series.Add(series_trend);

            this.chart1.BackColor = System.Drawing.Color.Transparent;
        }
        void InitializeComponent_chart2()
        {

            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea_scan = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
            System.Windows.Forms.DataVisualization.Charting.Series series_scan = new System.Windows.Forms.DataVisualization.Charting.Series();

            // 
            // chart1
            // 

            this.chart2.Name = "chart2";



            chartArea_scan.Name = "Scan";
            chartArea_scan.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea_scan.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_scan.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_scan.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea_scan.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_scan.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_scan.BackColor = System.Drawing.Color.OldLace;
            //chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            //chartArea1.BackSecondaryColor = System.Drawing.Color.White;
            chartArea_scan.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea_scan.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;

            chartArea_scan.ShadowColor = System.Drawing.Color.Transparent;
            chartArea_scan.CursorX.IsUserEnabled = true;
            chartArea_scan.CursorX.IsUserSelectionEnabled = true;
            chartArea_scan.CursorX.SelectionColor = System.Drawing.SystemColors.Highlight;
            chartArea_scan.CursorY.IsUserEnabled = true;
            chartArea_scan.CursorY.IsUserSelectionEnabled = true;
            chartArea_scan.CursorY.SelectionColor = System.Drawing.SystemColors.Highlight;
            chart2.ChartAreas.Add(chartArea_scan);

            //this.chart1.Location = new System.Drawing.Point(16, 32);

            series_scan.Name = "Scan";

            series_scan.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series_scan.BorderWidth = 3;
            series_scan.ChartArea = chartArea_scan.Name;
            series_scan.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series_scan.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));

            series_scan.ShadowColor = System.Drawing.Color.Black;
            series_scan.ShadowOffset = 2;
            series_scan.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series_scan.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;

            chart2.Series.Add(series_scan);

            chart2.BackColor = System.Drawing.Color.Transparent;
        }

        void DataBindAll()
        {
            chart2.Series["Scan"].Points.Clear();
            for (int i = 0; i < mCoating.Datas_Horizontal.Count(); i++)
            {
                chart2.Series["Scan"].Points.AddXY(i, mCoating.Datas_Horizontal[i].Thick / 100.0);
            }
            chart2.Invalidate();
        }
        
    }
    public class CoatingModeConverter : EnumToIsCheckedConverter<FLY.Simulation.Coating.CoatingCtrl.COATINGMODE>
    {

    }
}