PgBorderSearch.xaml.cs 21.7 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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.Navigation;
using System.Windows.Shapes;
using System.Net;

using FLY.Thick.Base.Client;
using System.Windows.Forms.DataVisualization.Charting;
using System.Drawing;
19 20
using Unity;
using FLY.Thick.Base.IService;
潘栩锋's avatar
潘栩锋 committed
21 22 23
using System.ComponentModel;
using Misc;
using GalaSoft.MvvmLight.Command;
24
using FLY.Thick.Base.Server;
潘栩锋's avatar
潘栩锋 committed
25
using FLY.Thick.Base.Common;
潘栩锋's avatar
潘栩锋 committed
26

潘栩锋's avatar
潘栩锋 committed
27
namespace FLY.Thick.Base.UI
潘栩锋's avatar
潘栩锋 committed
28 29 30 31
{
    /// <summary>
    /// Page_BorderSearch.xaml 的交互逻辑
    /// </summary>
潘栩锋's avatar
潘栩锋 committed
32
    public partial class PgBorderSearch : Page
潘栩锋's avatar
潘栩锋 committed
33
    {
潘栩锋's avatar
潘栩锋 committed
34
        PgBorderSearchVm viewModel;
35
        IUnityContainer container;
潘栩锋's avatar
潘栩锋 committed
36
        public PgBorderSearch()
潘栩锋's avatar
潘栩锋 committed
37 38 39 40 41 42 43 44 45
        {
            InitializeComponent();
            InitializeChart();
        }
        void InitializeChart()
        {
            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 series_datas = new System.Windows.Forms.DataVisualization.Charting.Series();
46 47
            System.Windows.Forms.DataVisualization.Charting.Series series_border = new System.Windows.Forms.DataVisualization.Charting.Series();

潘栩锋's avatar
潘栩锋 committed
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

            // 
            // chart1
            // 
            //this.chart1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(211)), ((System.Byte)(223)), ((System.Byte)(240)));
            //this.chart1.BackSecondaryColor = System.Drawing.Color.White;
            //this.chart1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            //this.chart1.BorderlineColor = System.Drawing.Color.FromArgb(((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
            //this.chart1.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
            //this.chart1.BorderlineWidth = 2;
            //this.chart1.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;
            #region chartArea
            #region chartArea1

            chartArea1.Name = "chartArea1";

            chartArea1.AxisX.IsLabelAutoFit = false;
            chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            //chartArea1.AxisX.LabelStyle.IsEndLabelVisible = false;
            chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea1.AxisX.Title = "位置(脉冲)";

            chartArea1.AxisY.IsLabelAutoFit = false;
            chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea1.AxisY.Title = "AD值";
            //chartArea1.AxisY.IsStartedFromZero = false;

            chartArea1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(165)), ((System.Byte)(191)), ((System.Byte)(228)));
            chartArea1.BackSecondaryColor = System.Drawing.Color.White;
            chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            chartArea1.BorderColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea1.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;

            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.Position.Auto = true;
            chartArea1.ShadowColor = System.Drawing.Color.Transparent;

            #endregion

            this.chart1.ChartAreas.Add(chartArea1);
            #endregion

            #region legend
            legend1.Name = "legend1";

            legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Right;
            legend1.Alignment = System.Drawing.StringAlignment.Far;
            legend1.LegendStyle = LegendStyle.Column;
            legend1.IsDockedInsideChartArea = true;
            legend1.DockedToChartArea = chartArea1.Name;

            legend1.IsTextAutoFit = false;
            legend1.BackColor = System.Drawing.Color.Transparent;
            legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            legend1.Position.Auto = true;
            chart1.Legends.Add(legend1);
            #endregion

            #region series
            series_datas.Name = "series_datas";
            series_datas.BorderColor = System.Drawing.Color.FromArgb(((System.Byte)(180)), ((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
            series_datas.BorderWidth = 2;
            series_datas.ChartArea = chartArea1.Name;
            series_datas.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series_datas.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
            
            series_datas.LegendText = "AD数据";
            series_datas.IsVisibleInLegend = true;
            series_datas.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series_datas.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;

            series_datas.ShadowColor = System.Drawing.Color.Black;
            series_datas.ShadowOffset = 2;

132 133 134 135 136 137 138
            series_border.Name = "series_border";
            series_border.LegendText = "边界点";
            series_border.ChartArea = chartArea1.Name;
            series_border.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
            series_border.Color = System.Drawing.Color.Violet;
            series_border.BorderColor = System.Drawing.Color.DarkViolet;
            series_border.BorderWidth = 3;
潘栩锋's avatar
潘栩锋 committed
139

140 141 142 143
            series_border.MarkerSize = 6;
            series_border.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series_border.MarkerBorderColor = System.Drawing.Color.DarkViolet;
            series_border.MarkerColor = System.Drawing.Color.Violet;
潘栩锋's avatar
潘栩锋 committed
144

145 146
            series_border.ShadowColor = System.Drawing.Color.Black;
            series_border.ShadowOffset = 2;
潘栩锋's avatar
潘栩锋 committed
147 148

            chart1.Series.Add(series_datas);
149
            chart1.Series.Add(series_border);
潘栩锋's avatar
潘栩锋 committed
150 151 152 153 154 155
            #endregion

            chart1.Name = "chart1";
            chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.BrightPastel;
            //chart1.Location = new System.Drawing.Point(0, 0);

潘栩锋's avatar
潘栩锋 committed
156
            //chart1.PrePaint += Chart1_PrePaint;
潘栩锋's avatar
潘栩锋 committed
157 158
        }

潘栩锋's avatar
潘栩锋 committed
159
        [InjectionMethod]
160 161 162 163
        public void Init(
            IUnityContainer container,
            IBorderSearchService borderSearchService, 
            IInitParamService initParamService,
潘栩锋's avatar
潘栩锋 committed
164
            ITDGageService gageService) 
潘栩锋's avatar
潘栩锋 committed
165
        {
166 167 168
            this.container = container;
            container.BuildUp(mircoGage);

潘栩锋's avatar
潘栩锋 committed
169
            viewModel = new PgBorderSearchVm();
潘栩锋's avatar
潘栩锋 committed
170
            viewModel.Init(borderSearchService, initParamService, gageService, chart1);
潘栩锋's avatar
潘栩锋 committed
171

潘栩锋's avatar
潘栩锋 committed
172
            this.DataContext = viewModel;
潘栩锋's avatar
潘栩锋 committed
173
        }
潘栩锋's avatar
潘栩锋 committed
174
    }
潘栩锋's avatar
潘栩锋 committed
175

潘栩锋's avatar
潘栩锋 committed
176 177 178 179 180
    public class PgBorderSearchVm : INotifyPropertyChanged
    {
        #region 延时推送 MARKNO
        const int MARKNO_UPDATE_BORDER = 0;
        const int MARKNO_UPDATE_DATAS = 1;
181

潘栩锋's avatar
潘栩锋 committed
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
        #endregion
        public event PropertyChangedEventHandler PropertyChanged;

        #region 参数
        /// <summary>
        /// 启动与否
        /// </summary>
        public bool Enable { get; set; }

        /// <summary>
        /// 边界拐点检测,找到的边界更加精确
        /// </summary>
        public bool IsBreakDetect { get; set; }

        /// <summary>
        /// 有限范围
        /// </summary>
        public Range Valid { get; set; }

        /// <summary>
        /// 手动设置温修AD值
        /// </summary>
        public bool TempADBySet { set; get; }
        /// <summary>
        /// 温修AD值
        /// </summary>
        public int TempAD { get; set; }

        /// <summary>
        /// AD超过了范围, 就认为开始找到边界
        /// </summary>
        public int TempRange { get; set; }
        /// <summary>
        /// 温修范围是温修的百分比
        /// </summary>
        public bool IsTempRangeByPercent { get; set; }

        /// <summary>
        ///  温修范围百分比
        /// </summary>
        public double TempRangePercent { get; set; }
        /// <summary>
        /// 有滤波器,只有非空的连续N个pos以上,才开始算边界开始
        /// </summary>
        public int N { get; set; }

        /// <summary>
        /// 探头直径,单位脉冲, 膜宽 = 边界范围 - 探头直径
        /// </summary>
        public int SensorWidth { get; set; }

        /// <summary>
        /// 找到边界后,边界 + 探头半径  + N2个脉冲。 这个是数据有效的开始
        /// </summary>
        public int N2 { get; set; }

        /// <summary>
        /// 记录两个边界以后扫描,以它们再外扩N3个脉冲,作为扫描范围 
        /// </summary>
        public int N3 { get; set; }
潘栩锋's avatar
潘栩锋 committed
242

潘栩锋's avatar
潘栩锋 committed
243 244 245 246 247
        #endregion
        #region Command
        public RelayCommand ApplyCmd { get; private set; }
        #endregion

248
        public Misc.DIRECTION Direction { get; private set; } = DIRECTION.FIX;
潘栩锋's avatar
潘栩锋 committed
249 250
        public IBorderSearchService BorderSearchService { get; private set; }
        public IInitParamService InitParamService { get; private set; }
潘栩锋's avatar
潘栩锋 committed
251
        DynArea dynArea;
252
        BorderSearchGetViewReponse getViewReponse;
潘栩锋's avatar
潘栩锋 committed
253 254 255

        System.Windows.Forms.DataVisualization.Charting.Chart chart1;
        public PgBorderSearchVm() 
潘栩锋's avatar
潘栩锋 committed
256
        {
潘栩锋's avatar
潘栩锋 committed
257 258
            ApplyCmd = new RelayCommand(Apply);
        }
潘栩锋's avatar
潘栩锋 committed
259 260


潘栩锋's avatar
潘栩锋 committed
261 262 263
        public void Init(
            IBorderSearchService borderSearchService,
            IInitParamService initParamService,
潘栩锋's avatar
潘栩锋 committed
264
            ITDGageService gageService,
潘栩锋's avatar
潘栩锋 committed
265 266 267 268
            System.Windows.Forms.DataVisualization.Charting.Chart chart)
        {
            BorderSearchService = borderSearchService;
            InitParamService = initParamService;
潘栩锋's avatar
潘栩锋 committed
269 270

            dynArea = gageService.DynArea;
潘栩锋's avatar
潘栩锋 committed
271 272
            chart1 = chart;

潘栩锋's avatar
潘栩锋 committed
273 274
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.Enable), this, nameof(Enable));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.IsBreakDetect),this, nameof(IsBreakDetect));
275 276 277 278
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.Valid), ()=> {
                Valid = new Range(BorderSearchService.Valid);
            });
            
潘栩锋's avatar
潘栩锋 committed
279 280 281 282 283 284 285 286 287
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.TempADBySet),this, nameof(TempADBySet));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.TempAD),this, nameof(TempAD));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.TempRange),this, nameof(TempRange));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.IsTempRangeByPercent),this, nameof(IsTempRangeByPercent));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.TempRangePercent),this, nameof(TempRangePercent));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.N),this, nameof(N));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.SensorWidth),this, nameof(SensorWidth));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.N2),this, nameof(N2));
            Misc.BindingOperations.SetBinding(BorderSearchService, nameof(BorderSearchService.N3),this, nameof(N3));
潘栩锋's avatar
潘栩锋 committed
288 289 290 291


            BorderSearchService.PropertyChanged += MBorderSearchService_PropertyChanged;
            InitParamService.PropertyChanged += MInitParamService_PropertyChanged;
潘栩锋's avatar
潘栩锋 committed
292 293
            UpdateX();

潘栩锋's avatar
潘栩锋 committed
294
            chart1.PrePaint += Chart1_PrePaint;
295 296

            getView();
297
        }
潘栩锋's avatar
潘栩锋 committed
298 299 300 301 302 303 304 305 306 307
        private void MInitParamService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "PosLength")
            {
                UpdateX();
            }
        }

        private void MBorderSearchService_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
308 309

            if (e.PropertyName == "UpdateTime") 
潘栩锋's avatar
潘栩锋 committed
310
            {
311
                getView();
潘栩锋's avatar
潘栩锋 committed
312 313 314 315 316 317 318
            }
            else if ((e.PropertyName == "TempAD") ||
                (e.PropertyName == "TempRange"))
            {
                chart1.Invalidate();
            }
        }
319 320 321 322 323
        void getView() {
            BorderSearchService.GetView((asyncContext, retData) =>
            {
                this.getViewReponse = retData as BorderSearchGetViewReponse;
                UpdateDatas();
324 325
                UpdateBorder();
                UpdateSensorWidth();
326 327
            }, this);
        }
潘栩锋's avatar
潘栩锋 committed
328 329 330 331 332 333 334 335 336 337 338 339 340
        private void Chart1_PrePaint(object sender, ChartPaintEventArgs e)
        {
            if (e.ChartElement is ChartArea)
            {
                ChartArea area = (ChartArea)e.ChartElement;
                if (Double.IsNaN(area.AxisY.Minimum))
                    return;

                //阀值线
                System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Red, 2);

                int threshold = BorderSearchService.TempAD - BorderSearchService.TempRange;
                DrawYGridTick(e.ChartGraphics, pen, threshold);
341 342 343

                threshold = BorderSearchService.TempAD + BorderSearchService.TempRange;
                DrawYGridTick(e.ChartGraphics, pen, threshold);
潘栩锋's avatar
潘栩锋 committed
344 345 346 347 348 349 350 351 352 353
            }
        }

        private void Apply()
        {
            if (!WdPassword.Authorize("BorderSearch"))
                return;

            BorderSearchService.Enable = Enable;
            BorderSearchService.IsBreakDetect = IsBreakDetect;
354
            BorderSearchService.Valid = Valid.ToStruct();
潘栩锋's avatar
潘栩锋 committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
            BorderSearchService.TempADBySet = TempADBySet;
            BorderSearchService.TempAD = TempAD;
            BorderSearchService.TempRange = TempRange;
            BorderSearchService.IsTempRangeByPercent = IsTempRangeByPercent;
            BorderSearchService.TempRangePercent = TempRangePercent;
            BorderSearchService.N = N;
            BorderSearchService.SensorWidth = SensorWidth;
            BorderSearchService.N2 = N2;
            BorderSearchService.N3 = N3;

            BorderSearchService.Apply();
            FLY.ControlLibrary.Window_Tip.Show("应用成功",
                null,
                TimeSpan.FromSeconds(2));
            
        }
潘栩锋's avatar
潘栩锋 committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
        void DrawYGridTick(ChartGraphics cg, System.Drawing.Pen pen, double y)
        {
            ChartArea area = chart1.ChartAreas[0];

            if (y > area.AxisY.Maximum || y < area.AxisY.Minimum)
                return;

            // Take Graphics object from chart
            Graphics graph = cg.Graphics;

            // Convert X and Y values to screen position
            double py = cg.GetPositionFromAxis(area.Name, AxisName.Y, y);

            double XMin = cg.GetPositionFromAxis(area.Name, AxisName.X, area.AxisX.Minimum);
            double XMax = cg.GetPositionFromAxis(area.Name, AxisName.X, area.AxisX.Maximum);

            System.Drawing.PointF[] points = new System.Drawing.PointF[2];
            points[0].X = (float)XMin;
            points[1].X = (float)XMax;
            points[0].Y = points[1].Y = (float)py;

            // Convert relative coordinates to absolute coordinates.
            points[0] = cg.GetAbsolutePoint(points[0]);
            points[1] = cg.GetAbsolutePoint(points[1]);

            graph.DrawLine(pen, points[0], points[1]);

        }
        void UpdateY()
        {
401 402 403
            if (getViewReponse == null)
                return;
            int[] grid = getViewReponse.dat;
潘栩锋's avatar
潘栩锋 committed
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
            if (grid == null)
                return;

            int max = Misc.MyMath.Max(grid);
            int min = Misc.MyMath.Min(grid);
            if (Misc.MyBase.ISVALIDATA(max))
            {
                if (max != min)
                {
                    chart1.ChartAreas[0].AxisY.Maximum = max + (max - min) * 0.1;
                    chart1.ChartAreas[0].AxisY.Minimum = min - (max - min) * 0.1;
                    if (chart1.ChartAreas[0].AxisY.Minimum < 0)
                        chart1.ChartAreas[0].AxisY.Minimum = 0;
                }
                else
                {
                    chart1.ChartAreas[0].AxisY.Minimum = 0;
潘栩锋's avatar
潘栩锋 committed
421
                    chart1.ChartAreas[0].AxisY.Maximum = dynArea.ADMax;
潘栩锋's avatar
潘栩锋 committed
422 423 424 425 426
                }
            }
            else
            {
                chart1.ChartAreas[0].AxisY.Minimum = 0;
潘栩锋's avatar
潘栩锋 committed
427
                chart1.ChartAreas[0].AxisY.Maximum = dynArea.ADMax;
潘栩锋's avatar
潘栩锋 committed
428 429 430 431 432 433 434 435 436 437 438
            }

            if (chart1.ChartAreas[0].AxisY.Minimum == chart1.ChartAreas[0].AxisY.Maximum)
            {
                chart1.ChartAreas[0].AxisY.Minimum -= 1000;
                chart1.ChartAreas[0].AxisY.Maximum += 1000;
            }
        }
        void UpdateX()
        {
            chart1.ChartAreas[0].AxisX.Minimum = 0;
潘栩锋's avatar
潘栩锋 committed
439
            chart1.ChartAreas[0].AxisX.Maximum = InitParamService.PosLength;
潘栩锋's avatar
潘栩锋 committed
440 441 442 443 444 445
        }
        void UpdateDatas()
        {
            System.Windows.Forms.DataVisualization.Charting.Series series = chart1.Series["series_datas"];

            series.Points.Clear();
446 447
            if (getViewReponse == null)
                return;
潘栩锋's avatar
潘栩锋 committed
448

449 450
            this.Direction = getViewReponse.direction;
            int[] grid = getViewReponse.dat;
潘栩锋's avatar
潘栩锋 committed
451 452
            if (grid == null)
                return;
453
            int posOfGrid = getViewReponse.posOfGrid;
潘栩锋's avatar
潘栩锋 committed
454

潘栩锋's avatar
潘栩锋 committed
455 456
            for (int i = 0; i < grid.Length; i++)
            {
457
                series.Points.AddXY((i+ getViewReponse.gridBegin) * posOfGrid, grid[i]);
潘栩锋's avatar
潘栩锋 committed
458 459 460 461 462 463 464 465 466 467 468 469 470 471
                if (!Misc.MyBase.ISVALIDATA(grid[i]))
                {
                    series.Points[i].IsEmpty = true;
                }
            }
            UpdateY();
        }


        #region 更新边界
        bool UpdateBorder_pos(
            System.Windows.Forms.DataVisualization.Charting.Series series,
            int pos)
        {
472 473 474 475
            if (getViewReponse == null)
                return false;

            int[] grid = getViewReponse.dat;
潘栩锋's avatar
潘栩锋 committed
476 477 478
            if (grid == null)
                return false;

479
            int posOfGrid = getViewReponse.posOfGrid;
潘栩锋's avatar
潘栩锋 committed
480

481
            int grid_idx = pos / posOfGrid - getViewReponse.gridBegin;
潘栩锋's avatar
潘栩锋 committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495
            if (grid_idx < 0)
                return false;
            if (grid_idx >= grid.Length)
                return false;

            int d = grid[grid_idx];
            if (!Misc.MyBase.ISVALIDATA(d))
                return false;

            series.Points.AddXY(pos, d);
            return true;
        }


496
        void UpdateBorder()
潘栩锋's avatar
潘栩锋 committed
497
        {
498
            System.Windows.Forms.DataVisualization.Charting.Series series = chart1.Series["series_border"];
潘栩锋's avatar
潘栩锋 committed
499
            series.Points.Clear();
500 501 502 503 504 505 506
            if (getViewReponse == null)
                return;

            Misc.Range border = getViewReponse.border;
            if (border == null)
                return;

潘栩锋's avatar
潘栩锋 committed
507 508
            if (!border.IsValid)
                return;
509

潘栩锋's avatar
潘栩锋 committed
510 511 512 513 514 515 516 517 518 519 520 521
            if (!UpdateBorder_pos(series, border.Begin))
                return;

            if (!UpdateBorder_pos(series, border.End))
                return;
        }

        void UpdateSensorWidth()
        {
            StripLinesCollection stripLines = chart1.ChartAreas[0].AxisX.StripLines;

            stripLines.Clear();
522 523 524
            if (getViewReponse == null)
                return;
            Misc.Range border = getViewReponse.border;
潘栩锋's avatar
潘栩锋 committed
525

526 527 528 529
            if (border == null)
                return;

            if (!border.IsValid)
潘栩锋's avatar
潘栩锋 committed
530 531 532 533 534
                return;

            StripLine stripline = new StripLine();
            stripline.BackColor = System.Drawing.Color.FromArgb(64, System.Drawing.Color.Green);
            stripline.Interval = 0;
535
            stripline.IntervalOffset = border.Begin - BorderSearchService.SensorWidth/2;
潘栩锋's avatar
潘栩锋 committed
536
            stripline.StripWidth = BorderSearchService.SensorWidth;
潘栩锋's avatar
潘栩锋 committed
537 538 539 540 541
            stripLines.Add(stripline);

            stripline = new StripLine();
            stripline.BackColor = System.Drawing.Color.FromArgb(64, System.Drawing.Color.Green);
            stripline.Interval = 0;
542
            stripline.IntervalOffset = border.End - BorderSearchService.SensorWidth/2;
潘栩锋's avatar
潘栩锋 committed
543
            stripline.StripWidth = BorderSearchService.SensorWidth;
潘栩锋's avatar
潘栩锋 committed
544 545 546 547 548 549
            stripLines.Add(stripline);
        }

        #endregion
    }
}