PgGageInfo.xaml.cs 17.8 KB
Newer Older
1 2 3
using FLY.Thick.Base.Client;
using FLY.Thick.Base.IService;
using FObjBase;
潘栩锋's avatar
潘栩锋 committed
4 5
using System.Collections.Generic;
using System.Linq;
6
using System.Net;
潘栩锋's avatar
潘栩锋 committed
7 8
using System.Windows;
using System.Windows.Controls;
9
using Unity;
潘栩锋's avatar
潘栩锋 committed
10

潘栩锋's avatar
潘栩锋 committed
11
namespace FLY.Thick.Base.UI
潘栩锋's avatar
潘栩锋 committed
12 13 14 15
{
    /// <summary>
    /// Page_GageInfo.xaml 的交互逻辑
    /// </summary>
潘栩锋's avatar
潘栩锋 committed
16
    public partial class PgGageInfo : Page
潘栩锋's avatar
潘栩锋 committed
17 18 19 20 21
    {
        #region 延时推送 MARKNO
        const int MARKNO_UPDATE = 1;
        #endregion

22 23 24
        IGageInfoService gageInfo = null;
        IGetSampleService getSample = null;
        IBorderSearchService borderSearch = null;
25
        IDynAreaService dynAreaService = null;
26
        IUnityContainer container;
潘栩锋's avatar
潘栩锋 committed
27
        public PgGageInfo()
潘栩锋's avatar
潘栩锋 committed
28 29 30 31
        {
            InitializeComponent();
            InitializeComponent2();
        }
32 33 34 35 36
        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            IGageInfoService gageInfoService,
            IGetSampleService getSample,
37 38
            IBorderSearchService borderSearch,
            IDynAreaService dynAreaService
39
            )
潘栩锋's avatar
潘栩锋 committed
40
        {
41 42 43
            this.gageInfo = gageInfoService;
            this.getSample = getSample;
            this.borderSearch = borderSearch;
44
            this.dynAreaService = dynAreaService;
45
            this.container = container;
潘栩锋's avatar
潘栩锋 committed
46
            container.BuildUp(mircoGage);
潘栩锋's avatar
潘栩锋 committed
47 48 49 50 51
        }
        private void Page_Loaded(object sender, RoutedEventArgs e1)
        {


52
            this.DataContext = gageInfo;
潘栩锋's avatar
潘栩锋 committed
53

54
            gageInfo.PropertyChanged += (s, e) =>
潘栩锋's avatar
潘栩锋 committed
55 56 57 58 59 60
            {
                if (e.PropertyName == "Data")
                {
                    DataBindAll();
                }
            };
61
            getSample.PropertyChanged += (s, e) =>
潘栩锋's avatar
潘栩锋 committed
62 63 64 65 66 67 68
            {
                if (e.PropertyName == "Enable")
                {
                    update();
                }
            };

69
            for (int i = 0; i < getSample.Samples.Count(); i++)
潘栩锋's avatar
潘栩锋 committed
70
            {
71
                getSample.Samples[i].PropertyChanged += (s, e) =>
潘栩锋's avatar
潘栩锋 committed
72 73 74 75
                {
                    if ((e.PropertyName == "Enable") ||
                        (e.PropertyName == "Position") ||
                        (e.PropertyName == "OrgAD"))
76 77 78
                    {
                        update();
                    }
潘栩锋's avatar
潘栩锋 committed
79 80
                };
            }
81
            for (int i = 0; i < getSample.Features.Count(); i++)
潘栩锋's avatar
潘栩锋 committed
82
            {
83
                getSample.Features[i].PropertyChanged += (s, e) =>
潘栩锋's avatar
潘栩锋 committed
84 85 86 87 88 89 90 91 92 93
                {
                    if ((e.PropertyName == "Enable") ||
                        (e.PropertyName == "StartPos") ||
                        (e.PropertyName == "EndPos"))
                    {
                        update();
                    }
                };
            }

94
            borderSearch.PropertyChanged += (s, e) =>
潘栩锋's avatar
潘栩锋 committed
95 96 97 98 99 100 101
            {
                if (e.PropertyName == "Enable")
                {
                    update();
                }
            };

102
            borderSearch.Valid.PropertyChanged += (s, e) =>
潘栩锋's avatar
潘栩锋 committed
103 104 105
            {
                update();
            };
潘栩锋's avatar
潘栩锋 committed
106 107 108

            DataBindAll();
            update();
潘栩锋's avatar
潘栩锋 committed
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
        }

        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();
            System.Windows.Forms.DataVisualization.Charting.Series series3 = new System.Windows.Forms.DataVisualization.Charting.Series();//样品
            // 
            // chart1
            // 
            chart1.BackColor = System.Drawing.Color.Transparent;

            chartArea1.Area3DStyle.Inclination = 15;
            chartArea1.Area3DStyle.IsClustered = true;
            chartArea1.Area3DStyle.IsRightAngleAxes = false;
            chartArea1.Area3DStyle.Perspective = 10;
            chartArea1.Area3DStyle.Rotation = 10;
            chartArea1.Area3DStyle.WallWidth = 0;
            chartArea1.AxisX.IsLabelAutoFit = false;
            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.AxisX.ScrollBar.BackColor = System.Drawing.Color.AliceBlue;
            chartArea1.AxisX.ScrollBar.ButtonColor = System.Drawing.SystemColors.Control;
            chartArea1.AxisX.ScrollBar.LineColor = System.Drawing.Color.FromArgb(((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.AxisY.ScrollBar.BackColor = System.Drawing.Color.AliceBlue;
            chartArea1.AxisY.ScrollBar.ButtonColor = System.Drawing.SystemColors.Control;
            chartArea1.AxisY.ScrollBar.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(165)))), ((int)(((byte)(191)))), ((int)(((byte)(228)))));
            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.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.InnerPlotPosition.Auto = false;
            chartArea1.InnerPlotPosition.Height = 75F;
            chartArea1.InnerPlotPosition.Width = 86.32634F;
            chartArea1.InnerPlotPosition.X = 11.21863F;
            chartArea1.InnerPlotPosition.Y = 3.96004F;
            chartArea1.Name = "Default";
            chartArea1.Position.Auto = false;// true;
            chartArea1.Position.Height = 100;//
            chartArea1.Position.Width = 100;// 81.46518F;
            chartArea1.Position.X = 0;// 9.267409F;
            chartArea1.Position.Y = 0;// 10F;

            chartArea1.ShadowColor = System.Drawing.Color.Transparent;
            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.IsTextAutoFit = false;
            legend1.Name = "Default";
            chart1.Legends.Add(legend1);
            //chart1.Location = new System.Drawing.Point(16, 48);
            chart1.Name = "chart1";


            //series1
            series1.BorderColor = System.Drawing.Color.DarkBlue;
            series1.BorderWidth = 3;

            series1.ChartArea = chartArea1.Name;
            series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series1.Color = System.Drawing.Color.Blue;// System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));

            series1.Legend = legend1.Name;
            series1.Name = "正向";
            //series1.MarkerSize = 6;
            //series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            try
            {
                series1.LegendText = Application.Current.FindResource("strForward") as string;
            }
192 193
            catch
            {
潘栩锋's avatar
潘栩锋 committed
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
            }
            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.Double;
            chart1.Series.Add(series1);


            //series2
            series2.BorderColor = System.Drawing.Color.DarkRed;
            series2.BorderWidth = 3;

            series2.ChartArea = chartArea1.Name;
            series2.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series2.Color = System.Drawing.Color.Red; //System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));

            series2.Legend = legend1.Name;
            //series2.MarkerSize = 6;
            //series2.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series2.Name = "反向";
            try
            {
                series2.LegendText = Application.Current.FindResource("strBackward") as string;
            }
            catch
            {
            }
            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.Double;

            chart1.Series.Add(series2);

            //series3
            series3.Name = "样品";
            try
            {
                series3.LegendText = Application.Current.FindResource("strSample") as string;
            }
            catch
            {
            }
            series3.ChartArea = chartArea1.Name;
            series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
            series3.Color = System.Drawing.Color.Green;
            series3.BorderColor = System.Drawing.Color.DarkGreen;
            series3.BorderWidth = 3;

            series3.MarkerSize = 6;
            series3.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series3.MarkerBorderColor = System.Drawing.Color.DarkGreen;
            series3.MarkerColor = System.Drawing.Color.Green;

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

            series3.Legend = legend1.Name;

            chart1.Series.Add(series3);
        }

        void DataBindAll()
        {
            string[] series = new string[2] { "正向", "反向" };
261 262
            List<int>[] datas = new List<int>[2] { gageInfo.ForwData, gageInfo.BackwData };
            if (gageInfo.PosOfGrid == 0)
潘栩锋's avatar
潘栩锋 committed
263
                return;
264 265 266
            int datadatasize = gageInfo.PosLen / gageInfo.PosOfGrid;
            if (datadatasize > gageInfo.ForwData.Count)
                datadatasize = gageInfo.ForwData.Count;
潘栩锋's avatar
潘栩锋 committed
267 268 269 270 271 272 273 274

            int max = Misc.MyBase.NULL_VALUE, min = Misc.MyBase.NULL_VALUE;
            for (int j = 0; j < 2; j++)
            {
                chart1.Series[j].Points.Clear();
                for (int i = 0; i < datadatasize; i++)
                {
                    int data = datas[j][i];
275
                    int pos = i * gageInfo.PosOfGrid;
潘栩锋's avatar
潘栩锋 committed
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305

                    chart1.Series[j].Points.AddXY(pos, data);

                    if (!Misc.MyBase.ISVALIDATA(data))
                    {
                        chart1.Series[j].Points[i].IsEmpty = true;
                    }
                    else
                    {
                        if (!Misc.MyBase.ISVALIDATA(max))
                        {
                            max = data;
                            min = data;
                        }
                        if (max < data)
                            max = data;
                        if (min > data)
                            min = data;
                    }
                }
            }
            //set max min
            //set max min
            if (max != min)
            {
                chart1.ChartAreas[0].AxisY.Maximum = max + (max - min) / 10;
                chart1.ChartAreas[0].AxisY.Minimum = min - (max - min) / 10;
                if (chart1.ChartAreas[0].AxisY.Minimum < 0)
                    chart1.ChartAreas[0].AxisY.Minimum = 0;

306 307
                if (chart1.ChartAreas[0].AxisY.Maximum > dynAreaService.DynArea.ADMax)
                    chart1.ChartAreas[0].AxisY.Maximum = dynAreaService.DynArea.ADMax;
潘栩锋's avatar
潘栩锋 committed
308 309
            }
            chart1.ChartAreas[0].AxisX.Minimum = 0;
310
            chart1.ChartAreas[0].AxisX.Maximum = gageInfo.PosLen;
潘栩锋's avatar
潘栩锋 committed
311
        }
312
        void update()
潘栩锋's avatar
潘栩锋 committed
313 314
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
315
                new PollModule.PollHandler(delegate ()
潘栩锋's avatar
潘栩锋 committed
316 317 318 319 320 321 322 323 324 325 326 327 328
                {
                    System.Windows.Forms.DataVisualization.Charting.StripLinesCollection stripLines = chart1.ChartAreas[0].AxisX.StripLines;
                    stripLines.Clear();
                    mBorderSearchService_update();
                    mGetSampleService_update();
                }), this, MARKNO_UPDATE);


        }
        void mBorderSearchService_update()
        {
            System.Windows.Forms.DataVisualization.Charting.StripLinesCollection stripLines = chart1.ChartAreas[0].AxisX.StripLines;

329
            if (borderSearch.Enable)
潘栩锋's avatar
潘栩锋 committed
330 331 332 333
            {
                System.Windows.Forms.DataVisualization.Charting.StripLine stripline = new System.Windows.Forms.DataVisualization.Charting.StripLine();
                stripline.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(191)))), ((int)(((byte)(191)))), ((int)(((byte)(191)))));
                stripline.Interval = 0;
334 335
                stripline.IntervalOffset = borderSearch.Valid.Begin;
                stripline.StripWidth = borderSearch.Valid.Width;
潘栩锋's avatar
潘栩锋 committed
336 337 338 339 340 341 342 343 344 345 346 347 348
                stripLines.Add(stripline);
            }
        }
        void mGetSampleService_update()
        {
            System.Windows.Forms.DataVisualization.Charting.StripLinesCollection stripLines = chart1.ChartAreas[0].AxisX.StripLines;
            //stripLines.Clear();

            System.Windows.Forms.DataVisualization.Charting.Series series = chart1.Series["样品"];
            series.Points.Clear();



349
            if (!getSample.Enable)
潘栩锋's avatar
潘栩锋 committed
350 351
                return;

352
            for (int i = 0; i < getSample.Samples.Count(); i++)
潘栩锋's avatar
潘栩锋 committed
353
            {
354 355
                var sample = getSample.Samples[i];
                if (sample.Enable)
潘栩锋's avatar
潘栩锋 committed
356 357 358 359 360 361 362
                {
                    int data = sample.OrgAD;
                    int pos = sample.Position;
                    series.Points.AddXY(pos, data);
                }
            }

363
            for (int i = 0; i < getSample.Features.Count(); i++)
潘栩锋's avatar
潘栩锋 committed
364
            {
365
                var feature = getSample.Features[i];
潘栩锋's avatar
潘栩锋 committed
366 367 368 369 370 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 401 402 403 404 405 406
                if (feature.Enable)
                {
                    System.Windows.Forms.DataVisualization.Charting.StripLine stripline = new System.Windows.Forms.DataVisualization.Charting.StripLine();


                    if (i == 0)
                    {
                        try
                        {
                            stripline.Text = Application.Current.FindResource("strForwFeature") as string;
                        }
                        catch
                        {
                            stripline.Text = "正向特征";
                        }
                    }
                    else
                    {
                        try
                        {
                            stripline.Text = Application.Current.FindResource("strBackwFeature") as string;
                        }
                        catch
                        {
                            stripline.Text = "反向特征";
                        }
                    }
                    //stripline.TextAlignment = System.Drawing.StringAlignment.Near;
                    //stripline.TextLineAlignment = System.Drawing.StringAlignment.Near;
                    stripline.TextOrientation = System.Windows.Forms.DataVisualization.Charting.TextOrientation.Stacked;

                    stripline.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(191)))), ((int)(((byte)(191)))), ((int)(((byte)(191)))));
                    stripline.Interval = 0;
                    stripline.IntervalOffset = feature.StartPos;
                    stripline.StripWidth = feature.EndPos - feature.StartPos + 1;
                    stripLines.Add(stripline);
                }
            }
        }
        void Page_Unloaded(object sender, RoutedEventArgs e)
        {
407

潘栩锋's avatar
潘栩锋 committed
408 409 410
        }
        void button_start_Click(object sender, RoutedEventArgs e)
        {
411 412
            if (gageInfo.IsRunning)
                gageInfo.Stop();
潘栩锋's avatar
潘栩锋 committed
413
            else
414 415 416 417 418 419 420
            {
                if (!WdPassword.Authorize("GageInfo"))
                    return;

                gageInfo.Start();
            }

潘栩锋's avatar
潘栩锋 committed
421 422 423
        }
    }
}