WindowBlowing.xaml.cs 11.3 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 36 37 38 39 40 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
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.Blowing;

namespace FLYAD7_Simulation_Wpf
{
    
    /// <summary>
    /// WindowBlowing.xaml 的交互逻辑
    /// </summary>
    public partial class WindowBlowing : Window
    {
        public Blowing mBlowing;
        public WindowBlowing()
        {
            InitializeComponent();
            InitializeComponent_chart1();
            InitializeComponent_chart2();
        }
        public void InitializeComponent_chart1()
        {
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
            System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
            System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();

            // 
            // chart1
            // 

            chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.BackColor = System.Drawing.Color.OldLace;
            //chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            //chartArea1.BackSecondaryColor = System.Drawing.Color.White;
            chartArea1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            chartArea1.Name = "Default";
            chartArea1.ShadowColor = System.Drawing.Color.Transparent;
            //对数坐标
            //chartArea1.AxisY.IsLogarithmic = true;
            //chartArea1.AxisY.LogarithmBase = Math.E;
            this.chart1.ChartAreas.Add(chartArea1);



            legend1.BackColor = System.Drawing.Color.Transparent;
            legend1.Enabled = false;
            legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            legend1.IsTextAutoFit = false;
            legend1.Name = "Default";
            this.chart1.Legends.Add(legend1);
            //this.chart1.Location = new System.Drawing.Point(16, 32);
            this.chart1.Name = "chart1";
            series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series1.BorderWidth = 3;
            series1.ChartArea = "Default";
            series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
            series1.Legend = "Default";
            //series1.MarkerSize = 8;
            //series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.None;
            series1.Name = "Series 1";
            series1.ShadowColor = System.Drawing.Color.Black;
            series1.ShadowOffset = 2;
            series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;


            chartArea1.CursorX.IsUserEnabled = true;
            chartArea1.CursorX.Position = 2;
            chartArea1.CursorX.SelectionColor = System.Drawing.Color.Gray;


            this.chart1.Series.Add(series1);

            this.chart1.BackColor = System.Drawing.Color.Transparent;
        }

        public void InitializeComponent_chart2()
        {
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
            System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
            System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();

            // 
            // chart1
            // 

            chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.BackColor = System.Drawing.Color.OldLace;
            //chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            //chartArea1.BackSecondaryColor = System.Drawing.Color.White;
            chartArea1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            chartArea1.Name = "Default";
            chartArea1.ShadowColor = System.Drawing.Color.Transparent;
            //对数坐标
            //chartArea1.AxisY.IsLogarithmic = true;
            //chartArea1.AxisY.LogarithmBase = Math.E;
            this.chart2.ChartAreas.Add(chartArea1);
            this.chart2.Name = "chart2";

            series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series1.BorderWidth = 3;
            series1.ChartArea = "Default";
            series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
            series1.Legend = "Default";
            //series1.MarkerSize = 8;
            //series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.None;
            series1.Name = "Series 1";
            series1.ShadowColor = System.Drawing.Color.Black;
            series1.ShadowOffset = 2;
            series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;


            chartArea1.CursorX.IsUserEnabled = true;
            chartArea1.CursorX.Position = 2;
            chartArea1.CursorX.SelectionColor = System.Drawing.Color.Gray;


            this.chart2.Series.Add(series1);

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

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = mBlowing;
150
            this.spPlc.DataContext = mBlowing.mHMI;
潘栩锋's avatar
潘栩锋 committed
151 152 153 154 155 156 157 158 159 160
            mBlowing.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mBlowing_PropertyChanged);
            DataBindAll();
            chart1.ChartAreas["Default"].CursorX.Position = mBlowing.TestPos;

            DataBindAll_chart2();

        }

        void mBlowing_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
161
            if (e.PropertyName == nameof(mBlowing.TestPos)) 
潘栩锋's avatar
潘栩锋 committed
162 163 164
            {
                chart1.ChartAreas["Default"].CursorX.Position = mBlowing.TestPos;
            }
165
            else if (e.PropertyName == nameof(mBlowing.AfterDatas)) 
潘栩锋's avatar
潘栩锋 committed
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
            {
                this.Dispatcher.Invoke(new Action(DataBindAll2_chart2));
                this.Dispatcher.Invoke(new Action(DataBindAll2));
            }
        }
        public void DataBindAll()
        {
            chart1.Series["Series 1"].Points.Clear();
            for (int i = 0; i < mBlowing.AfterDatas.Count(); i++)
            {
                chart1.Series["Series 1"].Points.AddXY(i, mBlowing.AfterDatas[i]);
            }
            int max = mBlowing.AfterDatas.Max();
            int min = mBlowing.AfterDatas.Min();
            int avg = (int)mBlowing.AfterDatas.Average();
            if (max == min)
            {
                max = (int)(avg * 1.1);
                min = (int)(avg * 0.9);
            }
            chart1.ChartAreas["Default"].AxisY.Maximum = max + (max - min);
            chart1.ChartAreas["Default"].AxisY.Minimum = min - (max - min);
            chart1.Invalidate();
        }
        public void DataBindAll2()
        {
            for (int i = 0; i < mBlowing.AfterDatas.Count(); i++)
            {
                chart1.Series["Series 1"].Points[i].SetValueY(mBlowing.AfterDatas[i]);
            }
            chart1.Invalidate();
        }

        public void DataBindAll_chart2()
        {
            chart2.Series["Series 1"].Points.Clear();
            for (int i = 0; i < mBlowing.mAirRing2.Heats.Count(); i++)
            {
                chart2.Series["Series 1"].Points.AddXY(i, mBlowing.mAirRing2.Heats[i]);
            }
            chart2.ChartAreas["Default"].AxisY.Maximum = 100;
            chart2.ChartAreas["Default"].AxisY.Minimum = 0;
            chart2.Invalidate();
        }
        public void DataBindAll2_chart2()
        {
            for (int i = 0; i < mBlowing.mAirRing2.Heats.Count(); i++)
            {
                chart2.Series["Series 1"].Points[i].SetValueY(mBlowing.mAirRing2.Heats[i]);
            }
            chart2.Invalidate();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            mBlowing.Test();
        }
222 223 224 225 226 227

        private void btnSaveClick(object sender, RoutedEventArgs e)
        {
            mBlowing.Save();
            MessageBox.Show("已经保存数据,请重启");
        }
潘栩锋's avatar
潘栩锋 committed
228 229
    }
}