Page_Graph.xaml.cs 34.8 KB
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 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 268 269 270 271 272 273 274 275 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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 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 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 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 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 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
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 System.Collections.ObjectModel;
using System.Windows.Forms.DataVisualization.Charting;
using System.ComponentModel;
using FObjBase;
using System.Windows.Threading;
using System.Diagnostics;
using FLY.FeedbackRenZiJia.IService;

namespace FLY.FeedbackRenZiJia.UI.Client.UIModule
{
    /// <summary>
    /// Page_Graph.xaml 的交互逻辑
    /// </summary>
    public partial class Page_Graph : Page, INotifyPropertyChanged
    {
        public SysParam sysparam;
        FLY.FeedbackRenZiJia.Client.FeedbackHeatServiceClient mFeedback;
        FLY.FeedbackRenZiJia.Client.HeatBufServiceClient mHeatBuf;
        FLY.FeedbackRenZiJia.Client.HeatCellServiceClient mHeatCell;

        /// <summary>
        /// 当前选择加热通道
        /// </summary>
        public int SelectBoltNo { get; set; }


        public Page_Graph()
        {
            InitializeComponent();

            InitializeChart();
            
        }
        public void Init(int id)
        {
            sysparam = SysParam.Current;

            UpdateChartArea();

            sysparam.PropertyChanged += (s,e) =>
            {
                UpdateChartArea();
            };


            //把 FeedbackHeat 共享。 1个程序,只能有一个 FeedbackHeat
            mFeedback = TDGage.Current.mFeedback;
            mHeatBuf = TDGage.Current.mHeatBuf;
            mHeatCell = TDGage.Current.mHeatCell;

            IPEndPoint ep = sysparam.ServerEP;

            mFeedback.PropertyChanged += mFeedbackHeatService_PropertyChanged;
            mHeatCell.PropertyChanged += MHeatCell_PropertyChanged;
            mHeatBuf.PropertyChanged += MHeatBuf_PropertyChanged;
            UpdateAxisX(mFeedback.ChannelCnt);

            MHeatCell_PropertyChanged(mFeedback, new PropertyChangedEventArgs("Kp"));

            this.DataContext = mFeedback;
            lpress.Init(button_clear_h);
            lpress.LongClick += (s, e) => {
                mHeatCell.ClearPreHeats();
            };
            grid_longpress.DataContext = lpress;
        }

        private void Sysparam_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            throw new NotImplementedException();
        }

        void InitializeChart() 
        {
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = 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.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();

            System.Windows.Forms.DataVisualization.Charting.Series series_heatoffsets = new System.Windows.Forms.DataVisualization.Charting.Series();
            System.Windows.Forms.DataVisualization.Charting.Series series_thicks = new System.Windows.Forms.DataVisualization.Charting.Series();
            System.Windows.Forms.DataVisualization.Charting.Series series_currs = new System.Windows.Forms.DataVisualization.Charting.Series();
            System.Windows.Forms.DataVisualization.Charting.Series series_heats = new System.Windows.Forms.DataVisualization.Charting.Series();
            
            // 
            // 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
            //下面3D设置都是没有------------------------------------
            chartArea1.Area3DStyle.IsClustered = true;
            chartArea1.Area3DStyle.Perspective = 10;
            chartArea1.Area3DStyle.IsRightAngleAxes = false;
            chartArea1.Area3DStyle.WallWidth = 0;
            chartArea1.Area3DStyle.Inclination = 15;
            chartArea1.Area3DStyle.Rotation = 10;
            //-------------------------------------------------------

            chartArea1.AxisX.IsLabelAutoFit = true;
            chartArea1.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont;
            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.Interval = 5;

            chartArea1.AxisY.IsLabelAutoFit = true;// false;
            chartArea1.AxisY.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont;
            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.IsStartedFromZero = true;

            chartArea1.AxisY.Maximum = 50;
            chartArea1.AxisY.Minimum = -50;
            //chartArea1.AxisY.Interval = 10;

            chartArea1.AxisY2.IsLabelAutoFit = true;// false;
            chartArea1.AxisY2.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont;
            chartArea1.AxisY2.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisY2.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea1.AxisY2.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea1.AxisY2.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.Name = "HeatOffsets";
            chartArea1.Position.Auto = false;
            chartArea1.Position.Height = 50F;
            chartArea1.Position.Width = 100F;
            chartArea1.Position.X = 0;
            chartArea1.Position.Y = 0;
            chartArea1.ShadowColor = System.Drawing.Color.Transparent;
            chartArea1.AxisY2.IntervalAutoMode = IntervalAutoMode.FixedCount;


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


            #endregion

            #region chartArea2
            
            //下面3D设置都是没有------------------------------------
            chartArea2.Area3DStyle.IsClustered = true;
            chartArea2.Area3DStyle.Perspective = 10;
            chartArea2.Area3DStyle.IsRightAngleAxes = false;
            chartArea2.Area3DStyle.WallWidth = 0;
            chartArea2.Area3DStyle.Inclination = 15;
            chartArea2.Area3DStyle.Rotation = 10;
            //------------------------------------------------------
            
            chartArea2.AxisX.IsLabelAutoFit = true;
            chartArea2.AxisX.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont;
            chartArea2.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea2.AxisX.LabelStyle.IsEndLabelVisible = false;
            chartArea2.AxisX.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea2.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea2.AxisX.Interval = 5;
            
            chartArea2.AxisY.IsLabelAutoFit = true;
            chartArea2.AxisY.LabelAutoFitStyle = LabelAutoFitStyles.DecreaseFont;
            chartArea2.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea2.AxisY.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea2.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
            chartArea2.AxisY.IsStartedFromZero = false;

            chartArea2.AxisY.Maximum = 100;
            chartArea2.AxisY.Minimum = 0;
            //chartArea2.AxisY.Interval = 20;

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

            chartArea2.AlignWithChartArea = chartArea1.Name;
            chartArea2.Position.Auto = false;
            chartArea2.Position.Height = chartArea1.Position.Height;
            chartArea2.Position.Width = chartArea1.Position.Width;
            chartArea2.Position.X = chartArea1.Position.X;
            chartArea2.Position.Y = 50F;
            chartArea2.ShadowColor = System.Drawing.Color.Transparent;

            chartArea2.CursorX.IsUserEnabled = true;
            chartArea2.CursorX.Position = 2;
            #endregion

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

            #region legend
            #region legend1
            legend1.Name = "legend1";
            legend1.Alignment = System.Drawing.StringAlignment.Near;
            legend1.IsTextAutoFit = false;
            legend1.BackColor = System.Drawing.Color.Transparent;
            legend1.Docking = Docking.Right;
            legend1.IsDockedInsideChartArea = true;
            legend1.DockedToChartArea = chartArea1.Name;
            legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            legend1.LegendStyle = System.Windows.Forms.DataVisualization.Charting.LegendStyle.Column;
            legend1.Position.Auto = true;
            #endregion

            #region legend2
            legend2.Name = "legend2";
            legend2.Alignment = System.Drawing.StringAlignment.Near;
            legend2.IsTextAutoFit = false;
            legend2.BackColor = System.Drawing.Color.Transparent;
            legend2.Docking = Docking.Right;
            legend2.IsDockedInsideChartArea = true;
            legend2.DockedToChartArea = chartArea2.Name;
            legend2.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            legend2.LegendStyle = System.Windows.Forms.DataVisualization.Charting.LegendStyle.Column;
            legend2.Position.Auto = true;
            #endregion
            chart1.Legends.Add(legend1);
            chart1.Legends.Add(legend2);
            #endregion

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

            //series_heatoffsets.MarkerSize = 6;
            //series_heatoffsets.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series_heatoffsets.ShadowColor = System.Drawing.Color.Black;
            series_heatoffsets.ShadowOffset = 2;
            series_heatoffsets.Legend = legend1.Name;
            series_heatoffsets.LegendText = "加热增量";


            series_thicks.Name = "Thicks";
            series_thicks.BorderColor = System.Drawing.Color.Red;
            series_thicks.BorderWidth = 2;
            series_thicks.ChartArea = chartArea1.Name;
            series_thicks.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series_thicks.Color = System.Drawing.Color.HotPink;

            //series_thicks.IsVisibleInLegend = true;
            series_thicks.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series_thicks.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
            series_thicks.YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;

            series_thicks.MarkerColor = series_thicks.Color;
            series_thicks.MarkerSize = 12;
            //series_thicks.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series_thicks.ShadowColor = System.Drawing.Color.Black;
            series_thicks.ShadowOffset = 2;
            series_thicks.Legend = legend1.Name;
            series_thicks.LegendText = "厚度%";



            series_heats.Name = "Heats";
            series_heats.BorderColor = System.Drawing.Color.FromArgb(((System.Byte)(180)), ((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
            series_heats.BorderWidth = 2;
            series_heats.ChartArea = chartArea2.Name;
            series_heats.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Column;
            series_heats.Color = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
            
            //series_heats.IsVisibleInLegend = true;
            series_heats.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series_heats.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            //series_heats.MarkerSize = 6;
            //series_heats.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series_heats.ShadowColor = System.Drawing.Color.Black;
            series_heats.ShadowOffset = 2;
            series_heats.Legend = legend2.Name;
            series_heats.LegendText = "加热目标总量";


            series_currs.Name = "Currs";
            series_currs.BorderColor = System.Drawing.Color.DarkSeaGreen;
            series_currs.BorderWidth = 2;
            series_currs.ChartArea = chartArea2.Name;
            series_currs.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            series_currs.Color = System.Drawing.Color.GreenYellow;
            //series_currs.IsVisibleInLegend = true;
            series_currs.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            series_currs.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
            
            //series_currs.MarkerSize = 6;
            //series_currs.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
            series_currs.ShadowColor = System.Drawing.Color.Black;
            series_currs.ShadowOffset = 2;
            series_currs.Legend = legend2.Name;
            series_currs.LegendText = "加热当前总量";


            chart1.Series.Add(series_heatoffsets);
            chart1.Series.Add(series_thicks);
            chart1.Series.Add(series_heats);
            chart1.Series.Add(series_currs);
            #endregion

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


            chart1.CursorPositionChanging += new EventHandler<CursorEventArgs>(chart1_CursorPositionChanging);

            //??????????????????????????????????????
            //((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();

        }

        public void UpdateChartArea() 
        {

            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = chart1.ChartAreas["HeatOffsets"];
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = chart1.ChartAreas["Heats"];

            
            chartArea1.InnerPlotPosition.X = (float)sysparam.InnerPlotPositionX;
            chartArea1.InnerPlotPosition.Width = (float)sysparam.InnerPlotPositionWidth;
            chartArea1.InnerPlotPosition.Y = (float)sysparam.InnerPlotPositionY;
            chartArea1.InnerPlotPosition.Height = (float)sysparam.InnerPlotPositionHeight;

            chartArea1.Position.Height = 50F;
            chartArea1.Position.Width= (float)sysparam.PositionWidth;
            chartArea1.Position.X = (float)sysparam.PositionX;
            chartArea1.Position.Y = 0;

                
            chartArea2.Position.Height = chartArea1.Position.Height;
            chartArea2.Position.Width = chartArea1.Position.Width; 
            chartArea2.Position.X = chartArea1.Position.X;
            chartArea2.Position.Y = 50F;

            chartArea2.InnerPlotPosition.X = chartArea1.InnerPlotPosition.X;
            chartArea2.InnerPlotPosition.Width = chartArea1.InnerPlotPosition.Width;
            chartArea2.InnerPlotPosition.Y = chartArea1.InnerPlotPosition.Y;
            chartArea2.InnerPlotPosition.Height = chartArea1.InnerPlotPosition.Height;
        }
        

        void chart1_CursorPositionChanging(object sender, CursorEventArgs e)
        {
            //e.ChartArea == chartarea1
            //e.Axis = AxisX
            int idx = (int)e.NewPosition;
            SelectBoltNo = idx;
        }


        private void MHeatBuf_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "BoltIsStable")
            {
                DataBindAll_Thicks();
            }
        }

        private void MHeatCell_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Kp")
            {
                chart1.ChartAreas["HeatOffsets"].AxisY2.Maximum = Math.Round(chart1.ChartAreas["HeatOffsets"].AxisY.Maximum / mHeatCell.Kp);
                chart1.ChartAreas["HeatOffsets"].AxisY2.Minimum = Math.Round(chart1.ChartAreas["HeatOffsets"].AxisY.Minimum / mHeatCell.Kp);
            }
            else if (e.PropertyName == "ThickPercents")
            {

                DataBindAll_Thicks();

            }
            else if (e.PropertyName == "Heats")
            {
                DataBindAll("Currs", mHeatCell.Heats );

            }
            else if (e.PropertyName == "Offsets")
            {
                DataBindAll("HeatOffsets", mHeatCell.Offsets);

            }
            else if ((e.PropertyName == "PreHeats") || (e.PropertyName == "Bads"))
            {
                DataBindAll_Heats();
            }
        }

        void mFeedbackHeatService_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "ChannelCnt"))
            {
                UpdateAxisX(mFeedback.ChannelCnt);
            }

        }


        void DataBindAll(string series_string, int[] datas)
        {

            int emptyvalue = Misc.MyBase.NULL_VALUE;
            double multi = 1;
            chart1.Series[series_string].Points.Clear();

            for (int i = 0; i < datas.Count(); i++)
            {
                chart1.Series[series_string].Points.AddXY(
                    1 + i,
                    (double)datas[i] / multi);
                DataPoint point = chart1.Series[series_string].Points[i];

                //设定空数据
                if (datas[i] == emptyvalue)
                    point.IsEmpty = true;
                else
                    point.IsEmpty = false;
            }
        }

        void DataBindAll_Thicks()
        {
            Series series = chart1.Series["Thicks"];
            series.Points.Clear();

            if (mHeatCell.ThickPercents == null)
                return;

            if (mHeatCell.ThickPercents.Count() != mFeedback.NBolts)
                return;

            int bpc = mFeedback.NBolts / mFeedback.ChannelCnt;

            for (int i = 0; i < mFeedback.ChannelCnt; i++)
            {
                //有任何一个稳定,它都是稳定的
                bool isStable = false;
                if (mHeatBuf.BoltIsStable != null)
                {
                    for (int j = 0; j < bpc; j++)
                    {
                        int idx = i * bpc + j;
                        if (idx < mHeatBuf.BoltIsStable.Count())
                        {
                            if (mHeatBuf.BoltIsStable[idx])
                            {
                                isStable = true;
                                break;
                            }
                        }
                    }
                }
                //计算平均值
                int avg = Misc.MyMath.Avg(mHeatCell.ThickPercents, i * bpc, (i + 1) * bpc - 1);

                series.Points.AddXY(1 + i, avg);
                
                DataPoint point = series.Points[i];
                if (Misc.MyBase.ISVALIDATA(avg))
                    point.IsEmpty = false;
                else
                    point.IsEmpty = true;

                if (!isStable)
                {
                    point.MarkerStyle = MarkerStyle.Cross;
                }
                else
                {
                    point.MarkerStyle = MarkerStyle.None;
                }

            }
        }
        void DataBindAll_Heats()
        {
            Series series = chart1.Series["Heats"];
            series.Points.Clear();
            
            if (mFeedback.Bads == null)
                return;
            if (mFeedback.Bads.Count() != mFeedback.ChannelCnt)
                return;
            if (mHeatCell.PreHeats.Count() != mFeedback.ChannelCnt)
                return;


            for (int i = 0; i < mFeedback.ChannelCnt; i++)
            {
                if (mFeedback.Bads[i] && mHeatCell.PreHeats[i] == 0)
                {
                    series.Points.AddXY(1 + i,
                        100);
                }
                else
                {
                    series.Points.AddXY(1 + i,
                        mHeatCell.PreHeats[i]);
                }

                DataPoint point = series.Points[i];
                if (mFeedback.Bads[i] && mHeatCell.PreHeats[i] == 0)
                {
                    point.Color = System.Drawing.Color.Red;
                }
                else if (!mFeedback.Bads[i])
                {
                    point.Color = System.Drawing.Color.FromArgb(((int)(((byte)(65)))), ((int)(((byte)(140)))), ((int)(((byte)(240)))));
                }
                else
                {
                    point.Color = System.Drawing.Color.Violet;
                    
                }
    
            }
        }
        void UpdateAxisX(int cnt) 
        {
            chart1.ChartAreas["Heats"].AxisX.Minimum = 0;
            chart1.ChartAreas["Heats"].AxisX.Maximum = cnt+1;

            chart1.ChartAreas["HeatOffsets"].AxisX.Minimum = 0;
            chart1.ChartAreas["HeatOffsets"].AxisX.Maximum = cnt+1;
        }

        private void button_info_click(object sender, RoutedEventArgs e)
        {

        }

        private void button_add_click(object sender, RoutedEventArgs e)
        {
            //获取chart1 当前选择
            mHeatCell.ModifyOffset(SelectBoltNo-1, mFeedback.Step);
        }

        private void button_sub_click(object sender, RoutedEventArgs e)
        {
            mHeatCell.ModifyOffset(SelectBoltNo-1, -mFeedback.Step);
        }

        private void button_undo_click(object sender, RoutedEventArgs e)
        {
            mFeedback.Undo();
        }

        private void button_cal_click(object sender, RoutedEventArgs e)
        {
            mHeatCell.Cal();
        }

        private void button_baseup_click(object sender, RoutedEventArgs e)
        {
            mHeatCell.ModifyBase(mFeedback.Step);
        }

        private void button_basedown_click(object sender, RoutedEventArgs e)
        {
            mHeatCell.ModifyBase( -mFeedback.Step);
        }

        private void button_apply_click(object sender, RoutedEventArgs e)
        {
            mHeatCell.HeatApply();
        }

        private void button_save_click(object sender, RoutedEventArgs e)
        {
            Window_Save w = new Window_Save();
            w.FileName = mFeedback.HeatsProductName;

            if (w.ShowDialog() == true)
            {
                if (string.IsNullOrEmpty(w.FileName))
                {
                    FLY.ControlLibrary.Window_WarningTip.Show("异常",
                        "产品名称 为空",
                        TimeSpan.FromSeconds(2));
                    return;
                }
                char[] invalids = System.IO.Path.GetInvalidFileNameChars();
                
                foreach (char invalidChar in invalids)
                {
                    if (w.FileName.Contains(invalidChar)) 
                    {
                        FLY.ControlLibrary.Window_WarningTip.Show("异常",
                            "产品名称 含有非法字符 "+invalidChar,
                            TimeSpan.FromSeconds(2));
                        return;
                    }
                }

                if (w.FileName.Length > 30)
                {
                    FLY.ControlLibrary.Window_WarningTip.Show("异常",
                       "产品名称 > 30字符",
                       TimeSpan.FromSeconds(2));
                    return;                   
                }

                mFeedback.SaveHeats(w.FileName);
                FLY.ControlLibrary.Window_Tip.Show("加载成功",
                    w.FileName,
                    TimeSpan.FromSeconds(2));
            }
        }

        private void button_load_click(object sender, RoutedEventArgs e)
        {
            Window_Load w = new Window_Load();
            w.Init(mFeedback);
            w.ShowDialog();
        }
        private void button_enable_click(object sender, RoutedEventArgs e)
        {
            mFeedback.SetEnable(!mFeedback.IsAuto);
        }
        private void button_checkenable_click(object sender, RoutedEventArgs e)
        {
            mFeedback.SetCheckEnable(!mFeedback.CheckEnable);
        }
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {

        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {

        }


        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        #endregion

        private void button_graphset_click(object sender, RoutedEventArgs e)
        {
            NavigationService ns = Application.Current.Properties["NavigationService"] as NavigationService;
            if (ns != null)
            {
                Page_Setup p = new Page_Setup();
                ns.Navigate(p);
            }
        }



        public LongPress lpress = new LongPress();


        private void button_clear_h_click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;
            
            if (!lpress.IsOK)
                mHeatCell.ClearOffsets();
        }
    }
    public class LongPress : INotifyPropertyChanged
    {

        private int progress = 0;
        /// <summary>
        /// 满9
        /// </summary>
        public int Progress
        {
            get { return progress; }
            set
            {
                if (progress != value)
                {
                    progress = value;
                    NotifyPropertyChanged("Progress");
                    NotifyPropertyChanged("IsOK");
                    NotifyPropertyChanged("IsRunning");
                }
            }
        }

        private int max = 360;
        /// <summary>
        /// Progress 最大值
        /// </summary>
        public int Max
        {
            get { return max; }
            set
            {
                if (max != value)
                {
                    max = value;
                    NotifyPropertyChanged("Max");
                }
            }
        }

        private int intervalMs = 2000;
        /// <summary>
        /// 时间间隔
        /// </summary>
        public int IntervalMs
        {
            get { return intervalMs; }
            set
            {
                if (intervalMs != value)
                {
                    intervalMs = value;
                    NotifyPropertyChanged("IntervalMs");
                }
            }
        }

        public RoutedEventHandler LongClick;

        private Stopwatch stopwatch = new Stopwatch();
        DispatcherTimer t = new DispatcherTimer();
        DispatcherTimer t_reset = new DispatcherTimer();

        public LongPress()
        {
            t.Tick += T_Tick;
            t.Interval = TimeSpan.FromSeconds(0.1);

            t_reset.Tick += T_reset_Tick;
            t.Interval = TimeSpan.FromSeconds(0.1);
        }

        private void T_reset_Tick(object sender, EventArgs e)
        {
            Reset();
            t_reset.Stop();
        }

        UIElement element;
        public void Init(UIElement element)
        {

            element.PreviewMouseDown += (s, e) => { button_MouseDown(); };
            element.PreviewTouchDown += (s, e) => { button_MouseDown(); };
            element.PreviewMouseUp += (s, e) => { button_MouseUp(); };
            element.PreviewTouchUp += (s, e) => { button_MouseUp(); };

            this.element = element;
        }

        public void button_MouseDown()
        {
            //必须点3秒
            Progress = 0;
            stopwatch.Restart();
            t.Start();
        }
        public void button_MouseUp()
        {
            t.Stop();
            t_reset.Start();
        }
        private void T_Tick(object sender, EventArgs e)
        {
            TimeSpan ts = stopwatch.Elapsed;

            double p = (double)(Max) * ts.TotalMilliseconds / IntervalMs;
            if (p >= Max)
            {
                Progress = Max;
                stopwatch.Stop();
                t.Stop();
                LongClick?.Invoke(element, null);
            }
            else
            {
                Progress = (int)p;
            }
        }

        public bool IsOK
        {
            get
            {
                return (Progress == Max);
            }
        }
        public bool IsRunning
        {
            get
            {
                return (Progress > 0);
            }
        }
        public void Reset()
        {
            Progress = 0;
        }

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyname)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        #endregion
    }





    public class UIModule_GraphFB : FLY.UI.Module.IUIModule
    {
        /// <summary>
        /// 控件标题
        /// 它的值取决于culture
        /// </summary>
        public string Title
        {
            get
            {
                return "自动风环调节";
            }
        }

        /// <summary>
        /// 控件
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetComponent(int id)
        {
            Page_Graph graph = new Page_Graph();
            graph.Init(id);
            return graph;
        }

        /// <summary>
        /// 控件缩略图,用于编辑界面时,大致看看
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public FrameworkElement GetThumbnail(int id)
        {
            return new System.Windows.Controls.Grid();
        }


        /// <summary>
        /// 给出全部控件ID, 控件自行删除没有的参数
        /// </summary>
        /// <param name="IDs"></param>
        public void MatchParam(int[] IDs)
        {
        }
    }
}