tangxu
2024-04-24 1c5fa983ae3506c2edaa88c51a959d46685c1ba1
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
using DevExpress.XtraEditors;
using IStation.Untity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Curve
{
    /// <summary>
    /// 图片导入曲线控件窗体
    /// 下次优化
    /// 1.上一步下一步 记住选择范围
    /// 2.曲线来源带入
    /// 3.保存
    /// 4.代码整理
    /// </summary>
    public partial class SetCurveInfoByPictureDlg : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SetCurveInfoByPictureDlg()
        {
            InitializeComponent();
            InitialSelDisplayMode();
            InitialCurveFitType();
            InitialUnitQ();
            InitialEvent();
        }
 
        /// <summary>
        /// 数据返回事件
        /// </summary>
        public event Action<Model.FeatCurvePointGroup, Model.FeatCurveExpressGroup> ReloadDataEvent;
        private List<Model.CurvePoint> _picQHPoints = null;
        private List<Model.CurvePoint> _picQEPoints = null;
        private List<Model.CurvePoint> _picQPPoints = null;
        private Model.eCurveFitType _fitTypeQH = Model.eCurveFitType.ConicCurve;
        private Model.eCurveFitType _fitTypeQE = Model.eCurveFitType.ConicCurve;
        private Model.eCurveFitType _fitTypeQP = Model.eCurveFitType.ConicCurve;
 
 
        /// <summary>
        /// 绑定数据
        /// </summary> 
        public void SetBindingData()
        {
            LoadRibPage(this.PageQH);
        }
 
        #region 初始化事件
        /// <summary>
        /// 初始化事件
        /// </summary>
        private void InitialEvent()
        {
            this.setCurveInfoByPictureCtrl1.AllowSelBoundaryEvent += SetCurveInfoByPictureCtrl_AllowSelBoundaryEvent;
            this.setCurveInfoByPictureCtrl1.AllowSelPickPointEvent += SetCurveInfoByPictureCtrl1_AllowSelPickPointEvent;
        }
 
 
        //允许设置坐标事件
        private void SetCurveInfoByPictureCtrl_AllowSelBoundaryEvent(bool obj)
        {
            this.barCekSetCoord.Checked = obj;
        }
 
        //允许设置打点事件
        private void SetCurveInfoByPictureCtrl1_AllowSelPickPointEvent(bool obj)
        {
            this.barCekPickPoint.Checked = obj;
        }
        #endregion
 
        #region 初始化下拉按钮
 
        /// <summary>
        /// 初始化图片选中方式按钮
        /// </summary>
        private void InitialSelDisplayMode()
        {
            foreach (PictureBoxSizeMode item in Enum.GetValues(typeof(PictureBoxSizeMode)))
            {
                var btn = new DevExpress.XtraBars.BarCheckItem();
                btn.Caption = item.ToString();
                btn.Id = (int)item;
                btn.Name = $"barBtn{btn.Caption}";
                btn.ItemClick += (object sender, DevExpress.XtraBars.ItemClickEventArgs e) =>
                {
                    foreach (DevExpress.XtraBars.BarCheckItemLink link in barSelDisplayMode.ItemLinks)
                    {
                        ((DevExpress.XtraBars.BarCheckItem)link.Item).Checked = false;
                    }
                    var current_btn = (DevExpress.XtraBars.BarCheckItem)e.Item;
                    current_btn.Checked = true;
                    this.setCurveInfoByPictureCtrl1.SetPictureSizeMode((PictureBoxSizeMode)current_btn.Id);
                };
                if (item == PictureBoxSizeMode.StretchImage)
                {
                    btn.Checked = true;
                    this.setCurveInfoByPictureCtrl1.SetPictureSizeMode(item);
                }
                this.barSelDisplayMode.AddItem(btn);
            }
        }
 
        /// <summary>
        /// 初始化曲线拟合方式
        /// </summary>
        private void InitialCurveFitType()
        {
            foreach (Model.eCurveFitType item in Enum.GetValues(typeof(Model.eCurveFitType)))
            {
                var btn = new DevExpress.XtraBars.BarCheckItem();
                btn.Caption = item.GetDisplayText();
                btn.Id = (int)item;
                btn.Name = $"barBtn{btn.Caption}";
                btn.ItemClick += (object sender, DevExpress.XtraBars.ItemClickEventArgs e) =>
                {
                    foreach (DevExpress.XtraBars.BarCheckItemLink link in barSubCurveFitType.ItemLinks)
                    {
                        ((DevExpress.XtraBars.BarCheckItem)link.Item).Checked = false;
                    }
                    var current_btn = (DevExpress.XtraBars.BarCheckItem)e.Item;
                    current_btn.Checked = true;
                    this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType = (Model.eCurveFitType)current_btn.Id;
                    this.setCurveInfoByPictureCtrl1.RefreshPictureShape();
                };
                if (item == Model.eCurveFitType.CubicCurve)
                {
                    btn.Checked = true;
                    this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType = item;
                }
                this.barSubCurveFitType.AddItem(btn);
            }
        }
 
        /// <summary>
        /// 初始化流量单位
        /// </summary>
        private void InitialUnitQ()
        {
            foreach (Unit.eUnitQ item in Enum.GetValues(typeof(Unit.eUnitQ)))
            {
                var btn = new DevExpress.XtraBars.BarCheckItem();
                btn.Caption = item.ToString();
                btn.Id = (int)item;
                btn.Name = $"barBtn{btn.Caption}";
                btn.ItemClick += (object sender, DevExpress.XtraBars.ItemClickEventArgs e) =>
                {
                    foreach (DevExpress.XtraBars.BarCheckItemLink link in barSubUnitQ.ItemLinks)
                    {
                        ((DevExpress.XtraBars.BarCheckItem)link.Item).Checked = false;
                    }
                    var current_btn = (DevExpress.XtraBars.BarCheckItem)e.Item;
                    current_btn.Checked = true;
                    this.setCurveInfoByPictureCtrl1.UnitQ = (Unit.eUnitQ)current_btn.Id;
                };
                if (item == Unit.eUnitQ.M3H)
                {
                    btn.Checked = true;
                    this.setCurveInfoByPictureCtrl1.UnitQ = item;
                }
                this.barSubUnitQ.AddItem(btn);
            }
        }
        #endregion
 
        /// <summary>
        /// 初始化图表坐标
        /// </summary>
        private bool InitialChartCoord()
        {
            switch (this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve)
            {
                case Model.eFeatCurveType.QH:
                    {
                        if (this.barTxtMaxQ.EditValue == null || this.barTxtMinQ.EditValue == null || this.barTxtMaxH.EditValue == null || this.barTxtMinH.EditValue == null)
                        {
                            XtraMessageBox.Show("请将输入坐标!");
                            return false;
                        }
                        this.setCurveInfoByPictureCtrl1.ChartMaxX = Convert.ToDouble(this.barTxtMaxQ.EditValue);
                        this.setCurveInfoByPictureCtrl1.ChartMinX = Convert.ToDouble(this.barTxtMinQ.EditValue);
                        this.setCurveInfoByPictureCtrl1.ChartMaxY = Convert.ToDouble(this.barTxtMaxH.EditValue);
                        this.setCurveInfoByPictureCtrl1.ChartMinY = Convert.ToDouble(this.barTxtMinH.EditValue);
                    }
                    break;
                case Model.eFeatCurveType.QE:
                    {
                        if (this.barTxtMaxE.EditValue == null || this.barTxtMinE.EditValue == null)
                        {
                            XtraMessageBox.Show("请将输入坐标!");
                            return false;
                        }
                        this.setCurveInfoByPictureCtrl1.ChartMaxY = Convert.ToDouble(this.barTxtMaxE.EditValue);
                        this.setCurveInfoByPictureCtrl1.ChartMinY = Convert.ToDouble(this.barTxtMinE.EditValue);
                    }
                    break;
                case Model.eFeatCurveType.QP:
                    {
                        if (this.barTxtMaxP.EditValue == null || this.barTxtMinP.EditValue == null)
                        {
                            XtraMessageBox.Show("请将输入坐标!");
                            return false;
                        }
                        this.setCurveInfoByPictureCtrl1.ChartMaxY = Convert.ToDouble(this.barTxtMaxP.EditValue);
                        this.setCurveInfoByPictureCtrl1.ChartMinY = Convert.ToDouble(this.barTxtMinP.EditValue);
                    }
                    break;
            }
            return true;
        }
 
        //打开文件
        private void barBtnOpenFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new System.Windows.Forms.OpenFileDialog();
            dlg.Filter = "*.BMP;*.JPG;*.GIF;*.PNG|*.BMP;*.JPG;*.GIF;*.PNG";
            DialogResult ret = dlg.ShowDialog();
            if (ret != System.Windows.Forms.DialogResult.OK)
                return;
            this.setCurveInfoByPictureCtrl1.SetBindingData(dlg.FileName);
        }
 
 
        #region 基础操作
        /// <summary>
        /// 设置坐标
        /// </summary> 
        private void barCekSetCoord_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.barCekSetCoord.Checked)
                this.setCurveInfoByPictureCtrl1.StartSelectionRange();
        }
 
        /// <summary>
        /// 获取点
        /// </summary> 
        private void barCekPickPoint_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.barCekPickPoint.Checked)
            {
                if (!(this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve == Model.eFeatCurveType.QE && this.barCheckItem打点等效线.Checked))
                {
                    if (!InitialChartCoord())
                    {
                        this.barCekPickPoint.Checked = false;
                        return;
                    }
                }
 
                if (!this.setCurveInfoByPictureCtrl1.StartPickPoint())
                {
                    this.barCekPickPoint.Checked = false;
                    this.setCurveInfoByPictureCtrl1.EndPickPoint();
                    return;
                }
            }
            else
            {
                this.setCurveInfoByPictureCtrl1.EndPickPoint();
            }
        }
 
        /// <summary>
        /// 清空点
        /// </summary> 
        private void barBtnClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.setCurveInfoByPictureCtrl1.ClearPickPoint();
        }
 
        /// <summary>
        /// 刷新
        /// </summary> 
        private void barBtnReload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.setCurveInfoByPictureCtrl1.RefreshPictureShape();
        }
        #endregion
 
        /// <summary>
        /// 加载页面
        /// </summary>
        /// <param name="selPage">当前页</param>
        private void LoadRibPage(DevExpress.XtraBars.Ribbon.RibbonPage selPage)
        {
            selPage.Visible = true;
            foreach (DevExpress.XtraBars.Ribbon.RibbonPage tab in this.RibbCtrl.Pages)
            {
                if (tab != selPage)
                    tab.Visible = false;
            }
            if (selPage == this.PageQH)
            {
                this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve = Model.eFeatCurveType.QH;
                if (_picQHPoints != null)
                    this.setCurveInfoByPictureCtrl1.RefreshPictureShape(_picQHPoints);
            }
            else if (selPage == this.PageQE)
            {
                this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve = Model.eFeatCurveType.QE;
                if (_picQEPoints != null)
                    this.setCurveInfoByPictureCtrl1.RefreshPictureShape(_picQEPoints);
            }
            else if (selPage == this.PageQP)
            {
                this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve = Model.eFeatCurveType.QP;
                if (_picQPPoints != null)
                    this.setCurveInfoByPictureCtrl1.RefreshPictureShape(_picQPPoints);
            }
            this.RibbCtrl.SelectedPage = selPage;
        }
 
        /// <summary>
        /// 上一步
        /// </summary> 
        private void barBtnPreviousStep_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.RibbCtrl.SelectedPage == this.PageQE)
            {
                this.LoadRibPage(this.PageQH);
            }
            else if (this.RibbCtrl.SelectedPage == this.PageQP)
            {
                this.LoadRibPage(this.PageQE);
            }
        }
 
        /// <summary>
        /// 下一步
        /// </summary> 
        private void barBtnNextStep_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (this.RibbCtrl.SelectedPage == this.PageQH)
            {
                if (!SaveQH())
                    return;
                this.LoadRibPage(this.PageQE);
            }
            else if (this.RibbCtrl.SelectedPage == this.PageQE)
            {
                if (!SaveQE())
                    return;
                this.LoadRibPage(this.PageQP);
            }
        }
 
        /// <summary>
        /// 保存
        /// </summary> 
        private void barBtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show("是否导入?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK)
                return;
            if (!SaveQP())
                return;
            #region 临时作废 后续再维护
            //var unitQ = this.setCurveInfoByPictureCtrl1.UnitQ;
 
            //var pointsQH = new List<Model.CurvePoint>();
            //var pointsQE = new List<Model.CurvePoint>();
            //var pointsQP = new List<Model.CurvePoint>();
 
            //double rQmin = 0, rQmax = 0;
 
            //var picPointInfoQH = _picQHPoints;
            //var picPointInfoQE = _picQEPoints;
            //var picPointInfoQP = _picQPPoints;
 
            //if (this.setCurveInfoByPictureCtrl1.ChartMinX == 0)
            //    rQmin = 0;
            //else
            //    rQmin = _picQHPoints.Min(x => x.X);
 
            //rQmax = _picQHPoints.Max(x => x.X);
            ////换算单位
            //List<Model.CurvePoint> m3hPointInfoQH = null;
            //List<Model.CurvePoint> m3hPointInfoQE = null;
            //List<Model.CurvePoint> m3hPointInfoQP = null;
 
            //if (unitQ == Unit.eUnitQ.M3H)
            //{
            //    m3hPointInfoQH = picPointInfoQH;
            //    m3hPointInfoQE = picPointInfoQE;
            //    m3hPointInfoQP = picPointInfoQP;
            //}
            //else
            //{
            //    rQmin = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, rQmin);
            //    rQmax = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, rQmax);
            //    m3hPointInfoQH = ToM3H(unitQ, picPointInfoQH);
            //    m3hPointInfoQE = ToM3H(unitQ, picPointInfoQE);
            //    m3hPointInfoQP = ToM3H(unitQ, picPointInfoQP);
            //}
 
            //if (_fitTypeQH == Model.eCurveFitType.ThroughPoint)
            //{
            //    if (m3hPointInfoQP == null)
            //    {
            //        pointsQE = m3hPointInfoQE;
            //        pointsQH = m3hPointInfoQH;
 
            //        pointsQP = new List<Model.CurvePoint>();
            //        for (int i = 0; i < m3hPointInfoQE.Count(); i++)
            //        {
            //            var Q = m3hPointInfoQE[i].X;
            //            List<Model.CurvePoint> resultH = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQH, Q);
            //            if (resultH == null || resultH.Count == 0)
            //                continue;
            //            var H = resultH.Last().Y;
            //            var E = m3hPointInfoQE[i].Y;
            //            var P = Model.CurveCalcuHelper.CalculateP(Q, H, E);
            //            pointsQP.Add(new Model.CurvePoint(Q, P));
            //        }
            //    }
 
            //    double startE = 0;//起始点
            //    if (rQmin > 0.2)
            //        startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, rQmin);
            //    else
            //        startE = 0;
            //    pointsQE.Insert(0, new Model.CurvePoint(rQmin, startE));
            //}
            //else
            //{
            //    //均匀插值点,计算点坐标,首尾2点用延长的方法得到
            //    int insert_num = 15;
            //    double space = (rQmax - rQmin) / (insert_num - 1);
            //    int i = 0;
            //    double Q = rQmin;
            //    double H, E, P;
            //    for (i = 1; i < insert_num - 1; i++)
            //    {
            //        Q = Q + space;
            //        List<Model.CurvePoint> resultH = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQH, Q);
            //        if (resultH == null || resultH.Count == 0)
            //            continue;
            //        H = resultH.First().Y;
            //        pointsQH.Add(new Model.CurvePoint(Q, H));
 
            //        if (picPointInfoQE != null)
            //        {
            //            List<Model.CurvePoint> resultE = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQE, Q);
            //            if (resultE == null || resultE.Count == 0)
            //                continue;
            //            E = resultE.First().Y;
            //            P = ViewModel.Model.CurveCalcuHelper.CalculateP(Q, H, E);
            //        }
            //        else
            //        {
            //            List<Model.CurvePoint> resultP = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQP, Q);
            //            if (resultP == null || resultP.Count == 0)
            //                continue;
            //            P = resultP.First().Y;
            //            E = ViewModel.Model.CurveCalcuHelper.CalculateE(Q, H, P);
            //        }
 
            //        pointsQP.Add(new Model.CurvePoint(Q, P));
            //        pointsQE.Add(new Model.CurvePoint(Q, E));
            //    }
 
            //    if (!(this.barCekAutoAnalyQP.Checked && this.barCekAutoAnalyQP.Checked))
            //    {
            //        if (pointsQH.Count < 3 || pointsQE.Count < 3 || pointsQP.Count < 3)
            //        {
            //            pointsQH = null;
            //            pointsQE = null;
            //            pointsQP = null;
            //            XtraMessageBox.Show("未导入足够多的性能曲线点");
            //            return;
            //        }
            //    }
            //    else
            //    {
            //        if (pointsQH.Count < 3)
            //        {
            //            XtraMessageBox.Show("未导入足够多的性能曲线点");
            //            return;
            //        }
            //    }
 
            //    #region 首尾两点的处理:因为首尾2点按流量扬程获取范围,而点击不一定正好首尾2点流量一样
            //    //流量扬程首尾两点
            //    double startH = Model.CurveLineHelper.GetYbyX(pointsQH[0].X, pointsQH[0].Y, pointsQH[1].X, pointsQH[1].Y, rQmin);
            //    pointsQH.Insert(0, new Model.CurvePoint(rQmin, startH));
 
            //    int point_num = pointsQH.Count;//不一定和insert_num一样
            //    double endH = Model.CurveLineHelper.GetYbyX(pointsQH[point_num - 2].X, pointsQH[point_num - 2].Y,
            //        pointsQH[point_num - 1].X, pointsQH[point_num - 1].Y, rQmax);
            //    pointsQH.Add(new Model.CurvePoint(rQmax, endH));
 
            //    if (pointsQE != null && pointsQE.Count > 0)
            //    {
            //        //流量效率首尾两点
            //        double startE = 0;//起始点
            //        if (rQmin > 0.2)
            //            startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, rQmin);
            //        else
            //            startE = 0;
            //        pointsQE.Insert(0, new Model.CurvePoint(rQmin, startE));
 
            //        point_num = pointsQE.Count;//末尾点
            //        double endE = Model.CurveLineHelper.GetYbyX(pointsQE[point_num - 2].X, pointsQE[point_num - 2].Y,
            //            pointsQE[point_num - 1].X, pointsQE[point_num - 1].Y, rQmax);
            //        pointsQE.Add(new Model.CurvePoint(rQmax, endE));
            //    }
 
            //    if (pointsQE != null && pointsQE.Count > 0)
            //    {
            //        //流量功率首尾两点
            //        double startP = Model.CurveLineHelper.GetYbyX(pointsQP[0].X, pointsQP[0].Y, pointsQP[1].X, pointsQP[1].Y, rQmin);
            //        pointsQP.Insert(0, new Model.CurvePoint(rQmin, startP));
 
            //        point_num = pointsQP.Count;
            //        double endP = Model.CurveLineHelper.GetYbyX(pointsQP[point_num - 2].X, pointsQP[point_num - 2].Y,
            //            pointsQP[point_num - 1].X, pointsQP[point_num - 1].Y, rQmax);
            //        pointsQP.Add(new Model.CurvePoint(rQmax, endP));
            //    }
 
            //    #endregion
            //}
 
            ////圆整
            //pointsQH = Regulate(pointsQH, 2);
            //pointsQE = Regulate(pointsQE, 2);
            //pointsQP = Regulate(pointsQP, 2);
 
            //var pointListGroup = new Model.FeatCurvePointGroup();
            //pointListGroup.PointQH = pointsQH;
            //pointListGroup.PointQE = pointsQE;
            //pointListGroup.PointQP = pointsQP;
 
            //var curveExpressGroup = new Model.FeatCurveExpressGroup();
            //curveExpressGroup.CurveQH = new Model.CurveExpress(pointsQH, _fitTypeQH);
            //curveExpressGroup.CurveQE = new Model.CurveExpress(pointsQE, _fitTypeQE);
            //curveExpressGroup.CurveQP = new Model.CurveExpress(pointsQP, _fitTypeQP);
 
            //this.ReloadDataEvent?.Invoke(pointListGroup, curveExpressGroup);
            //this.DialogResult = DialogResult.OK;
            //this.Close(); 
            #endregion 
            Save();
        }
 
        /// <summary>
        /// 保存
        /// </summary>
        private void Save()
        {
            var unitQ = this.setCurveInfoByPictureCtrl1.UnitQ;
 
            List<Model.CurvePoint> pointsQH = new List<Model.CurvePoint>();
            List<Model.CurvePoint> pointsQE = new List<Model.CurvePoint>();
            List<Model.CurvePoint> pointsQP = new List<Model.CurvePoint>();
 
            double MinQ = 0;
            double MaxQ = 0;
 
            if (this.setCurveInfoByPictureCtrl1.ChartMinX == 0)
                MinQ = 0;
            else
                MinQ = _picQHPoints.Min(x => x.X);
 
            MaxQ = _picQHPoints.Max(x => x.X);
 
            //换算单位
            if (unitQ != Unit.eUnitQ.M3H)
            {
                MinQ = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, MinQ);
                MaxQ = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, MaxQ);
                _picQHPoints = ToM3H(unitQ, _picQHPoints);
                _picQEPoints = ToM3H(unitQ, _picQEPoints);
                _picQPPoints = ToM3H(unitQ, _picQPPoints);
            }
 
 
 
            /*if (_fitTypeQH == Model.eCurveFitType.ThroughPoint)
            {
                if (_picQPPoints == null || _picQPPoints.Count < 1)
                {
                    pointsQH = _picQHPoints;
                    pointsQE = _picQEPoints;
                    pointsQP = new List<Model.CurvePoint>();
                    for (int i = 0; i < _picQEPoints.Count(); i++)
                    {
                        var Q = _picQEPoints[i].X;
                        List<Model.CurvePoint> resultH = Model.FitCurveHelper.GetInterPointY(_picQHPoints, Q);
                        if (resultH == null || resultH.Count == 0)
                            continue;
                        var H = resultH.Last().Y;
                        var E = _picQEPoints[i].Y;
                        var P = Model.CurveCalcuHelper.CalculateP(Q, H, E);
                        pointsQP.Add(new Model.CurvePoint(Q, P));
                    }
                }
                else
                {
                    pointsQH = _picQHPoints;
                    pointsQE = _picQEPoints;
                    pointsQP = _picQPPoints;
                }
 
                double startE = 0;//起始点
                if (MinQ > 0.2)
                    startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, MinQ);
                else
                    startE = 0;
                pointsQE.Insert(0, new Model.CurvePoint(MinQ, startE));
            }
            else
            {*/
            //均匀插值点,计算点坐标,首尾2点用延长的方法得到
            int insert_num = 15;
            double space = (MaxQ - MinQ) / (insert_num - 1);
            int i = 0;
            double Q = MinQ;
            double H, E = 0, P = 0;
            for (i = 1; i < insert_num - 1; i++)
            {
                if (i == insert_num - 2)
                {
 
                }
                Q = Q + space;
                H = Model.FitCurveHelper.GetFitPointY(_picQHPoints, _fitTypeQH, Q);
                pointsQH.Add(new Model.CurvePoint(Q, H));
 
                if (!(this.barCekAutoAnalyQP.Checked && this.barCekAutoAnalyQP.Checked))
                {
                    E = Model.FitCurveHelper.GetFitPointY(_picQEPoints, _fitTypeQE, Q);
                    P = Model.FitCurveHelper.GetFitPointY(_picQPPoints, _fitTypeQP, Q);
                }
                else if (this.barCekAutoAnalyQP.Checked)
                {
                    E = Model.FitCurveHelper.GetFitPointY(_picQEPoints, _fitTypeQE, Q);
                    P = Model.CurveCalcuHelper.CalculateP(Q, H, E);
                }
                else if (this.barCekAutoAnalyQE.Checked)
                {
                    if (_picQPPoints == null)
                        continue;
                    P = Model.FitCurveHelper.GetFitPointY(_picQPPoints, _fitTypeQP, Q);
                    E = Model.CurveCalcuHelper.CalculateE(Q, H, P);
                }
 
 
                pointsQP.Add(new Model.CurvePoint(Q, P));
                pointsQE.Add(new Model.CurvePoint(Q, E));
            }
 
 
 
            if (!(this.barCekAutoAnalyQP.Checked && this.barCekAutoAnalyQP.Checked))
            {
                if (pointsQH.Count < 3 || pointsQE.Count < 3 || pointsQP.Count < 3)
                {
                    pointsQH = null;
                    pointsQE = null;
                    pointsQP = null;
                    XtraMessageBox.Show("未导入足够多的性能曲线点");
                    return;
                }
            }
            else
            {
                if (pointsQH.Count < 3)
                {
                    XtraMessageBox.Show("未导入足够多的性能曲线点");
                    return;
                }
            }
            #region 首尾两点的处理:因为首尾2点按流量扬程获取范围,而点击不一定正好首尾2点流量一样
            //流量扬程首尾两点
            double startH = Model.CurveLineHelper.GetYbyX(pointsQH[0].X, pointsQH[0].Y, pointsQH[1].X, pointsQH[1].Y, MinQ);
            pointsQH.Insert(0, new Model.CurvePoint(MinQ, startH));
 
            int point_num = pointsQH.Count;//不一定和insert_num一样
            double endH = Model.CurveLineHelper.GetYbyX(pointsQH[point_num - 2].X, pointsQH[point_num - 2].Y,
                pointsQH[point_num - 1].X, pointsQH[point_num - 1].Y, MaxQ);
            pointsQH.Add(new Model.CurvePoint(MaxQ, endH));
 
            if (pointsQE != null && pointsQE.Count > 0)
            {
                //流量效率首尾两点
                double startE = 0;//起始点
                if (MinQ > 0.2)
                    startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, MinQ);
                else
                    startE = 0;
                pointsQE.Insert(0, new Model.CurvePoint(MinQ, startE));
 
                point_num = pointsQE.Count;//末尾点
                double endE = Model.CurveLineHelper.GetYbyX(pointsQE[point_num - 2].X, pointsQE[point_num - 2].Y,
                    pointsQE[point_num - 1].X, pointsQE[point_num - 1].Y, MaxQ);
                pointsQE.Add(new Model.CurvePoint(MaxQ, endE));
            }
 
            if (pointsQP != null && pointsQP.Count > 0)
            {
                //流量功率首尾两点
                double startP = Model.CurveLineHelper.GetYbyX(pointsQP[0].X, pointsQP[0].Y, pointsQP[1].X, pointsQP[1].Y, MinQ);
                pointsQP.Insert(0, new Model.CurvePoint(MinQ, startP));
 
                point_num = pointsQP.Count;
                double endP = Model.CurveLineHelper.GetYbyX(pointsQP[point_num - 2].X, pointsQP[point_num - 2].Y,
                    pointsQP[point_num - 1].X, pointsQP[point_num - 1].Y, MaxQ);
                pointsQP.Add(new Model.CurvePoint(MaxQ, endP));
            }
            #endregion
            //}
 
            //圆整
            pointsQH = Regulate(pointsQH, 2);
            pointsQE = Regulate(pointsQE, 2);
            pointsQP = Regulate(pointsQP, 2);
 
            var pointListGroup = new Model.FeatCurvePointGroup();
            pointListGroup.PointQH = pointsQH;
            pointListGroup.PointQE = pointsQE;
            pointListGroup.PointQP = pointsQP;
 
            var curveExpressGroup = new Model.FeatCurveExpressGroup();
            curveExpressGroup.CurveQH = new Model.CurveExpress(pointsQH, _fitTypeQH, true);
            curveExpressGroup.CurveQE = new Model.CurveExpress(pointsQE, _fitTypeQE, true);
            //_fitTypeQP = Model.eCurveFitType.ThroughPoint;
            curveExpressGroup.CurveQP = new Model.CurveExpress(pointsQP, _fitTypeQP, true);
 
            this.ReloadDataEvent?.Invoke(pointListGroup, curveExpressGroup);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        #region 保存
        /// <summary>
        /// 保存扬程线
        /// </summary> 
        private bool SaveQH()
        {
            _fitTypeQH = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
            if (!this.setCurveInfoByPictureCtrl1.GetPicPointInCurve(out List<Model.CurvePoint> QH))
                return false;
            _picQHPoints = QH;
            return true;
        }
 
        /// <summary>
        /// 保存效率线
        /// </summary> 
        private bool SaveQE()
        {
            _picQEPoints = null;
            _fitTypeQE = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
            if (!this.barCekAutoAnalyQE.Checked)
            {
                if (!this.setCurveInfoByPictureCtrl1.GetPicPointInCurve(out List<Model.CurvePoint> QE))
                    return false;
                _picQEPoints = QE;
            }
            return true;
        }
 
        /// <summary>
        /// 保存功率线
        /// </summary> 
        private bool SaveQP()
        {
            _picQPPoints = null;
            _fitTypeQP = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
            if (!this.barCekAutoAnalyQP.Checked)
            {
                if (!this.setCurveInfoByPictureCtrl1.GetPicPointInCurve(out List<Model.CurvePoint> QP))
                    return false;
                var fitType = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
                _picQPPoints = QP;
            }
            return true;
        }
        #endregion
 
        /// <summary>
        /// 打点等效线
        /// </summary> 
        private void barCheckItem打点等效线_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.setCurveInfoByPictureCtrl1.IsCaputueEtaPtInEqupCurve = this.barCheckItem打点等效线.Checked;
        }
 
        private List<Model.CurvePoint> ToM3H(Unit.eUnitQ unit, List<Model.CurvePoint> points)
        {
            if (unit == Unit.eUnitQ.M3H)
            {
                return points;
            }
 
            if (points == null)
            {
                return null;
            }
 
            var list = new List<Model.CurvePoint>();
            for (int i = 0; i < points.Count; i++)
            {
                var point = new Model.CurvePoint(points[i]);
                point.X = Unit.UnitQHelper.Convert(unit, Unit.eUnitQ.M3H, point.X);
                list.Add(point);
            }
            return list;
        }
 
        //四舍五入圆整,如  0.44 -> 0.4  , 0.46 -> 0.5//flag--小数点后位数
        public static List<Model.CurvePoint> Regulate(List<Model.CurvePoint> inPoints, int flag)
        {
            if (inPoints == null)
                return null;
            List<Model.CurvePoint> outPoints = new List<Model.CurvePoint>();
            for (int i = 0; i < inPoints.Count(); i++)
            {
                outPoints.Add(new Model.CurvePoint(Regulate(inPoints[i].X, flag), Regulate(inPoints[i].Y, flag)));
            }
            return outPoints;
        }
 
        //四舍五入圆整,如  0.44 -> 0.4  , 0.46 -> 0.5//flag--小数点后位数
        public static double Regulate(double v, int flag)
        {
            bool isNegative = false;
            //如果是负数
            if (v < 0)
            {
                isNegative = true;
                v = Math.Abs(v);
            }
            else
            {
                isNegative = false;
            }
 
            double value = Math.Round(v, flag);
            if (isNegative)
            {
                value = -value;
            }
            return value;
        }
 
        private void barCekAutoAnalyQP_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
 
        }
    }
}