MainWindow.xaml.cs 26.3 KB
Newer Older
1 2 3
using FlyADBase;
using Misc;
using System;
潘栩锋's avatar
潘栩锋 committed
4
using System.Collections.Generic;
5 6
using System.ComponentModel;
using System.IO;
潘栩锋's avatar
潘栩锋 committed
7 8 9 10
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
潘栩锋's avatar
潘栩锋 committed
11
using Unity;
潘栩锋's avatar
潘栩锋 committed
12 13 14 15 16 17

namespace Flyad7_WPF
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
18
    public partial class MainWindow : Window, INotifyPropertyChanged
潘栩锋's avatar
潘栩锋 committed
19
    {
潘栩锋's avatar
潘栩锋 committed
20
        IUnityContainer Container;
潘栩锋's avatar
潘栩锋 committed
21 22 23 24 25
        FlyAD7 flyad;
        DebugAppParam param;
        AutoForwBackw autofb;
        FlyADClientUI flyad_clientui;
        AutoSync mAutoSync;
26 27
        AutoGetGridAdv autoGetGridAdv;
        GridAdvVm gridAdvVm;
28

29 30
        public MainWindow()
        {
潘栩锋's avatar
潘栩锋 committed
31 32 33
            InitializeComponent();
            InitializeComponent2();
            InitializeComponent3();
潘栩锋's avatar
潘栩锋 committed
34 35 36
            InitializeComponent4();
            Init();
        }
潘栩锋's avatar
潘栩锋 committed
37

38
        public void Init()
潘栩锋's avatar
潘栩锋 committed
39 40 41 42 43 44 45 46 47 48
        {
            Container = App.Current.Properties["Container"] as IUnityContainer;
            param = Container.Resolve<DebugAppParam>();
            flyad = Container.Resolve<FlyAD7>();
            autofb = Container.Resolve<AutoForwBackw>();
            flyad_clientui = Container.Resolve<FlyADClientUI>();
            autoGetGridAdv = Container.Resolve<AutoGetGridAdv>();
            mAutoSync = Container.Resolve<AutoSync>();
            gridAdvVm = Container.Resolve<GridAdvVm>();
            gridAdvVm.Init(chart3);
49

潘栩锋's avatar
潘栩锋 committed
50 51

            this.DataContext = flyad;
潘栩锋's avatar
潘栩锋 committed
52
            this.grid_viewModel.DataContext = this;
潘栩锋's avatar
潘栩锋 committed
53 54 55
            this.grid_param.DataContext = param;
            this.groupBox_fb.DataContext = autofb;
            this.groupBox_adpos.DataContext = flyad_clientui;
56 57
            this.gbAutoGetGridAdv.DataContext = autoGetGridAdv;
            this.gbTimeGridAdv.DataContext = gridAdvVm;
潘栩锋's avatar
潘栩锋 committed
58

59 60 61
            flyad.GridEvent += flyad_GridEvent;
            flyad.TimeGridEvent += flyad_TimeGridEvent;

62

潘栩锋's avatar
潘栩锋 committed
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
            FObjBase.PollModule.Current.Start();
        }

        /// <summary>
        /// grid图
        /// </summary>
        void InitializeComponent2()
        {
            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();
            System.Windows.Forms.DataVisualization.Charting.Series series2 = 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 = true;
            legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            legend1.Alignment = System.Drawing.StringAlignment.Near;
            legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Right;
            legend1.IsDockedInsideChartArea = true;
            legend1.DockedToChartArea = chartArea1.Name;
            //legend1.IsTextAutoFit = false;
            legend1.Name = "Default";
            chart1.Legends.Add(legend1);

            series1.Name = "Series 1";
            series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series1.BorderWidth = 3;
            series1.ChartArea = chartArea1.Name;
            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 = legend1.Name;
            series1.LegendText = "正向";
            series1.ShadowColor = System.Drawing.Color.Black;
            series1.ShadowOffset = 2;
            series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            chart1.Series.Add(series1);

            series2.Name = "Series 2";
            series2.BorderColor = System.Drawing.Color.Pink;
            series2.BorderWidth = 3;
            series2.ChartArea = chartArea1.Name;
            series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series2.Color = System.Drawing.Color.Red;
            series2.Legend = legend1.Name;
            series2.LegendText = "反向";
            series2.ShadowColor = System.Drawing.Color.Black;
            series2.ShadowOffset = 2;
            series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series2.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            chart1.Series.Add(series2);

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

            chart1.BackColor = System.Drawing.Color.Transparent;
        }
        void InitializeComponent3()
        {
            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);



            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.chart2.Legends.Add(legend1);
            //this.chart2.Location = new System.Drawing.Point(16, 32);
            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.Circle;
            series1.Name = "Series 1";
            series1.ShadowColor = System.Drawing.Color.Black;
            series1.ShadowOffset = 2;
            series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;

            this.chart2.Series.Add(series1);

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

潘栩锋's avatar
潘栩锋 committed
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281
        void InitializeComponent4()
        {
            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();
            System.Windows.Forms.DataVisualization.Charting.Series series2 = 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.CursorX.IsUserEnabled = true;
            chartArea1.CursorX.IsUserSelectionEnabled = true;
            chartArea1.CursorX.SelectionColor = System.Drawing.SystemColors.Highlight;
            chartArea1.CursorY.IsUserEnabled = true;
            chartArea1.CursorY.IsUserSelectionEnabled = true;
            chartArea1.CursorY.SelectionColor = System.Drawing.SystemColors.Highlight;
            //对数坐标
            //chartArea1.AxisY.IsLogarithmic = true;
            //chartArea1.AxisY.LogarithmBase = Math.E;
            chart3.ChartAreas.Add(chartArea1);



            legend1.BackColor = System.Drawing.Color.Transparent;
            legend1.Enabled = true;
            legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            legend1.Alignment = System.Drawing.StringAlignment.Near;
            legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Right;
            legend1.IsDockedInsideChartArea = true;
            legend1.DockedToChartArea = chartArea1.Name;
            //legend1.IsTextAutoFit = false;
            legend1.Name = "Default";
            chart3.Legends.Add(legend1);

            series1.Name = "Series 1";
            series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series1.BorderWidth = 3;
            series1.ChartArea = chartArea1.Name;
            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 = legend1.Name;
            series1.LegendText = "Series 1";
            series1.ShadowColor = System.Drawing.Color.Black;
            series1.ShadowOffset = 2;
            series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            chart3.Series.Add(series1);

            series2.Name = "Series 2";
            series2.BorderColor = System.Drawing.Color.Pink;
            series2.BorderWidth = 3;
            series2.ChartArea = chartArea1.Name;
            series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series2.Color = System.Drawing.Color.Red;
            series2.Legend = legend1.Name;
            series2.LegendText = "Series 2";
            series2.ShadowColor = System.Drawing.Color.Black;
            series2.ShadowOffset = 2;
            series2.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series2.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            chart3.Series.Add(series2);

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

            chart3.BackColor = System.Drawing.Color.Transparent;
        }
潘栩锋's avatar
潘栩锋 committed
282 283 284
        #region grid
        void flyad_GridEvent(object sender, MiniGridEventArgs e)
        {
285 286
            if (!param.HasGrid)
                return;
潘栩锋's avatar
潘栩锋 committed
287

288
            run_gridmarker.Text = e.marker.ToString();
潘栩锋's avatar
潘栩锋 committed
289

290 291 292
            System.Windows.Forms.DataVisualization.Charting.Series series_forw = chart1.Series["Series 1"];
            System.Windows.Forms.DataVisualization.Charting.Series series_backw = chart1.Series["Series 2"];
            System.Windows.Forms.DataVisualization.Charting.Series series;
293

294 295 296
            series = (e.direction == DIRECTION.FORWARD) ? series_forw : series_backw;

            series.Points.Clear();
潘栩锋's avatar
潘栩锋 committed
297

298
            int gridLen = flyad.PosLen / flyad.PosOfGrid;
潘栩锋's avatar
潘栩锋 committed
299 300 301



302 303 304 305 306 307 308 309
            for (int i = 0; i < e.buf.Length; i++)
            {
                int pos = (e.grid_start + i) * flyad.PosOfGrid;
                int ad = e.buf[i];
                series.Points.AddXY(pos, ad);
                if (ad == Misc.MyBase.NULL_VALUE)
                    series.Points[i].IsEmpty = true;
            }
310

311 312
            chart1.ChartAreas[0].AxisX.Minimum = 0;
            chart1.ChartAreas[0].AxisX.Maximum = flyad.PosLen;
313

314 315 316
        }


潘栩锋's avatar
潘栩锋 committed
317 318 319 320
        private void button_cleargrid_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.DataVisualization.Charting.Series series_forw = chart1.Series["Series 1"];
            System.Windows.Forms.DataVisualization.Charting.Series series_backw = chart1.Series["Series 2"];
321

潘栩锋's avatar
潘栩锋 committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
            series_forw.Points.Clear();
            series_backw.Points.Clear();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            GetGrid(Misc.DIRECTION.FORWARD);
        }
        private void GetGrid(Misc.DIRECTION dir)
        {
            System.Windows.Forms.DataVisualization.Charting.Series series_forw = chart1.Series["Series 1"];
            System.Windows.Forms.DataVisualization.Charting.Series series_backw = chart1.Series["Series 2"];
            System.Windows.Forms.DataVisualization.Charting.Series series;

            if (dir == DIRECTION.FORWARD)
                series = series_forw;
            else
                series = series_backw;
            int[] data;
            int gridLen = flyad.PosLen / flyad.PosOfGrid;
            flyad.GetGrid(dir, 0, gridLen, out data);
            series.Points.Clear();
            for (int i = 0; i < data.Length; i++)
            {
                int ad = data[i];
                int pos = i * flyad.PosOfGrid;
                series.Points.AddXY(pos, ad);
                if (ad == Misc.MyBase.NULL_VALUE)
                    series.Points[i].IsEmpty = true;
                else
                    series.Points[i].IsEmpty = false;
            }
            series.Points.Add(30000);

            int max = Misc.MyMath.Max(data, 0, data.Length - 1);
            int min = Misc.MyMath.Min(data, 0, data.Length - 1);
            if (max == Misc.MyBase.NULL_VALUE)
            {
                max = 60000;
                min = 0;
            }

            int mid = max;
            max += 10;
            min -= 10;
            chart1.ChartAreas[0].AxisY.Maximum = max;
            chart1.ChartAreas[0].AxisY.Minimum = min;

            chart1.ChartAreas[0].AxisX.Minimum = 0;
            chart1.ChartAreas[0].AxisX.Maximum = flyad.PosLen;
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            GetGrid(Misc.DIRECTION.BACKWARD);
        }
        #endregion
潘栩锋's avatar
潘栩锋 committed
379

潘栩锋's avatar
潘栩锋 committed
380
        int timecnt = 0;
381
        class MaxMin
潘栩锋's avatar
潘栩锋 committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
        {
            /// <summary>
            /// 最大值
            /// </summary>
            public int max;
            /// <summary>
            /// 最小值
            /// </summary>
            public int min;
            /// <summary>
            /// 数量
            /// </summary>
            public int len;
        }
        List<MaxMin> mMMList = new List<MaxMin>();

潘栩锋's avatar
潘栩锋 committed
398 399
        public event PropertyChangedEventHandler PropertyChanged;

潘栩锋's avatar
潘栩锋 committed
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
        void flyad_TimeGridEvent(object sender, TimeGridEventArgs e)
        {
            if (!param.HasTimeGrid)
                return;
            MaxMin mm;
            while (timecnt > 5000)
            {
                //被删除对象
                mm = mMMList.First();
                for (int i = 0; i < mm.len; i++)
                {
                    chart2.Series["Series 1"].Points.RemoveAt(0);
                }
                timecnt -= mm.len;
                mMMList.RemoveAt(0);
            }
            mMMList.Add(
417 418 419
                new MaxMin()
                {
                    len = e.Data.Length,
潘栩锋's avatar
潘栩锋 committed
420
                    min = e.Data.Min(),
421 422
                    max = e.Data.Max()
                });
潘栩锋's avatar
潘栩锋 committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445

            for (int i = 0; i < mMMList.Last().len; i++)
            {
                int ad = e.Data[i];
                chart2.Series["Series 1"].Points.Add(ad);
            }

            int max = (from i in mMMList select i.max).Max();
            int min = (from i in mMMList select i.min).Min();

            if (max == min)
            {
                min -= 10;
                max += 10;
            }
            chart2.ChartAreas[0].AxisY.Maximum = max;
            chart2.ChartAreas[0].AxisY.Minimum = min;
            timecnt += mMMList.Last().len;
        }




潘栩锋's avatar
潘栩锋 committed
446
        private void btnConnectClick(object sender, RoutedEventArgs e)
潘栩锋's avatar
潘栩锋 committed
447
        {
潘栩锋's avatar
潘栩锋 committed
448 449
            if (txtIp.IsEnabled)
            {
450
                flyad.ReConnect();
潘栩锋's avatar
潘栩锋 committed
451 452
                txtIp.IsEnabled = false;
            }
453 454 455
            else
            {

潘栩锋's avatar
潘栩锋 committed
456 457 458
                txtIp.IsEnabled = true;
            }

潘栩锋's avatar
潘栩锋 committed
459 460 461 462 463 464 465 466 467 468 469 470
        }

        private void button_output_Click(object sender, RoutedEventArgs e)
        {
            string output = textbox_output.Text;
            flyad.SetOutput(UInt16.MaxValue, Convert.ToUInt16(output, 2));
        }

        private void button_runto_Click(object sender, RoutedEventArgs e)
        {
            int pos;

471
            if (int.TryParse(textBox_to.Text, out pos))
潘栩锋's avatar
潘栩锋 committed
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
            {
                flyad.Runto(pos);
            }
        }

        private void button_org_Click(object sender, RoutedEventArgs e)
        {
            flyad.Origin();
        }

        private void button_stop_Click(object sender, RoutedEventArgs e)
        {
            flyad.Stop();
        }

        private void button_backw_Click(object sender, RoutedEventArgs e)
        {
            flyad.Backward();
        }

        private void button_forw_Click(object sender, RoutedEventArgs e)
        {
            flyad.Forward();
        }




500

潘栩锋's avatar
潘栩锋 committed
501 502 503 504 505 506 507 508 509 510 511 512 513

        private void button_sync_Click(object sender, RoutedEventArgs e)
        {
            if (!Window_sync.HasOpen)
            {
                Window_sync w = new Window_sync();
                w.Init(flyad, mAutoSync);
                w.Show();
            }
        }

        private void button_setbit_Click(object sender, RoutedEventArgs e)
        {
514 515 516 517 518 519 520 521
            var btn = sender as Button;
            if (!int.TryParse((btn.Tag as string), out int index))
                return;

            if (Misc.MyBase.CHECKBIT(flyad.OStatus, index))
                flyad.SetOutputBit(index, false);
            else
                flyad.SetOutputBit(index, true);
522

潘栩锋's avatar
潘栩锋 committed
523 524 525 526 527 528 529 530 531 532 533
        }

        private void button_runto0_Click(object sender, RoutedEventArgs e)
        {
            flyad.RuntoMin();
        }

        private void button_runtoPosLen_Click(object sender, RoutedEventArgs e)
        {
            flyad.RuntoMax();
        }
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562

        private void button_gridSave_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.DataVisualization.Charting.Series series_forw = chart1.Series["Series 1"];
            System.Windows.Forms.DataVisualization.Charting.Series series_backw = chart1.Series["Series 2"];

            string strDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string path = System.IO.Path.Combine(strDesktopPath, $"grid_{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.csv");
            StreamWriter sw = new StreamWriter(path);
            //int count = Math.Max(series_forw.Points.Count(), series_backw.Points.Count());
            sw.WriteLine($"Index,Forw,Backw");
            int gridLen = flyad.PosLen / flyad.PosOfGrid;
            for (int i = 0; i < gridLen; i++)
            {
                int f_v = Misc.MyBase.NULL_VALUE;
                int b_v = Misc.MyBase.NULL_VALUE;
                if (i < series_forw.Points.Count)
                    f_v = (int)(series_forw.Points[i].YValues[0]);
                if (i < series_backw.Points.Count)
                    b_v = (int)(series_backw.Points[i].YValues[0]);

                sw.WriteLine($"{i},{f_v},{b_v}");
            }
            sw.Flush();
            sw.Close();

            MessageBox.Show($"成功保存到 {path}");

        }
潘栩锋's avatar
潘栩锋 committed
563 564 565 566 567 568


        DispatcherTimer timer = new DispatcherTimer();
        bool isTimerInited = false;
        public int OutIdx { get; private set; }
        public bool IsAutoOutRunning { get; private set; }
569 570
        void TimerInit()
        {
潘栩锋's avatar
潘栩锋 committed
571 572 573 574 575 576 577 578 579 580 581 582 583
            timer.Tick += (s, e) =>
            {
                flyad.SetOutputBit(OutIdx, true);
                OutIdx += 1;
                if (OutIdx > 7)
                    OutIdx = 0;
                flyad.SetOutputBit(OutIdx, false);
            };
            timer.Interval = TimeSpan.FromSeconds(1);
        }

        private void btnAutoOutClick(object sender, RoutedEventArgs e)
        {
584 585
            if (!isTimerInited)
            {
潘栩锋's avatar
潘栩锋 committed
586 587 588 589 590 591 592
                TimerInit();
            }
            if (timer.IsEnabled)
            {
                timer.Stop();
                IsAutoOutRunning = false;
            }
593 594
            else
            {
潘栩锋's avatar
潘栩锋 committed
595 596
                timer.Start();
                IsAutoOutRunning = true;
597

潘栩锋's avatar
潘栩锋 committed
598 599
            }
        }
600

潘栩锋's avatar
潘栩锋 committed
601
        private void btnSetPosParamClick(object sender, RoutedEventArgs e)
602
        {
潘栩锋's avatar
潘栩锋 committed
603 604 605
            WdSetVelocity wd = new WdSetVelocity();
            Container.BuildUp(wd);
            wd.Owner = this;
606 607 608 609 610 611 612 613 614 615 616 617
            if (wd.ShowDialog() == true)
            {

            }
        }


        private void btnCreateAccessClick(object sender, RoutedEventArgs e)
        {
            WdCreateAccess wd = new WdCreateAccess();
            Container.BuildUp(wd);
            wd.Owner = this;
潘栩锋's avatar
潘栩锋 committed
618 619
            if (wd.ShowDialog() == true) { 
            }
620
        }
潘栩锋's avatar
潘栩锋 committed
621

622 623 624 625 626 627 628 629 630 631
        private void btnTestClick(object sender, RoutedEventArgs e)
        {
            WdTest wd = new WdTest();
            Container.BuildUp(wd);
            wd.Owner = this;
            if (wd.ShowDialog() == true)
            {
            }
        }
    }
潘栩锋's avatar
潘栩锋 committed
632
}