lixiaojun
2024-12-10 513c72dd3c97787b0845bcc8526e004da9e50e64
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Yw.Geometry;
using Yw.Pump;
using Yw.Vmo;
using Yw.WinFrmUI.Phart;
 
namespace HStation.WinFrmUI
{
    public partial class SimulationSingleWorkingPumpCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SimulationSingleWorkingPumpCtrl()
        {
            InitializeComponent();
        }
 
        private HydroWorkingVmo _working = null;
        private Yw.Model.HydroModelInfo _hydroInfo = null;
        private Dictionary<string, HydroCalcuVisualResult> _allCalcuResultVisualDict = null;
 
        public void SetBindingData
            (HydroWorkingVmo working, Yw.Model.HydroModelInfo hydroInfo, HydroCalcuResult calcuResult)
        {
            var allCalcuResultVisualDict = calcuResult.GetVisualDict();
            SetBindingData(working, hydroInfo, allCalcuResultVisualDict);
        }
 
        public void SetBindingData
            (HydroWorkingVmo working, Yw.Model.HydroModelInfo hydroInfo, Dictionary<string, HydroCalcuVisualResult> allCalcuResultVisualDict)
        {
            _working = working;
            _hydroInfo = hydroInfo;
            _allCalcuResultVisualDict = allCalcuResultVisualDict;
            var vm = CreateViewModel();
            this.pumpWorkingViewChart1.SetBindingData(vm);
        }
 
        //创建
        private PumpWorkingViewViewModel CreateViewModel()
        {
            if (_working == null)
            {
                return default;
            }
            if (_hydroInfo == null)
            {
                return default;
            }
            if (_allCalcuResultVisualDict == null || _allCalcuResultVisualDict.Count < 1)
            {
                return default;
            }
            var vm = new PumpWorkingViewViewModel();
            vm.Id = _working.ID.ToString();
            vm.Name = _working.Name;
            vm.CurveName = $"装置线";
            vm.Color = Color.Black;
 
            vm.StartH = 2;
 
            if (_hydroInfo.Pumps != null && _hydroInfo.Pumps.Count > 0)
            {
                var pumps = _hydroInfo.Pumps.Where(x => x.LinkStatus == Yw.Hydro.PumpStatus.Open).ToList();
                if (pumps.Count > 0)
                {
                    vm.Items = new List<PumpWorkingViewItemViewModel>();
                    foreach (var pump in pumps)
                    {
                        var vmItem = new PumpWorkingViewItemViewModel();
                        vm.Items.Add(vmItem);
                        vmItem.Id = pump.Code;
                        vmItem.Name = pump.Name;
                        vmItem.CurveName = pump.Name;
                        vmItem.Color = HydroPumpCurveColorHelper.GetRandomColor(pumps.IndexOf(pump));
                        var calcuResult = _allCalcuResultVisualDict?.GetValue(pump.Code) as HydroCalcuPumpResult;
                        if (calcuResult != null)
                        {
                            vmItem.Q = calcuResult.CalcuQ ?? 0;
                            vmItem.H = calcuResult.CalcuH ?? 0;
                            vmItem.P = calcuResult.CalcuP;
                            vmItem.E = calcuResult.CalcuE;
                        }
                        vmItem.Hz = Math.Round(pump.SpeedRatio * pump.RatedHz, 1);
                        vmItem.N = pump.RatedN.HasValue ? Math.Round(pump.SpeedRatio * pump.RatedN.Value, 1) : 0;
 
 
                        var curveqh = _hydroInfo.Curves?.Find(x => x.Code == pump.CurveQH);
                        if (curveqh != null)
                        {
                            var qh_pts = curveqh.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                            if (qh_pts != null && qh_pts.Count > 3)
                            {
                                var qh_run_pts = qh_pts.GetQHPointListByN(pump.RatedHz, vmItem.Hz);
                                vmItem.CurveQH = new CubicSpline2d(qh_run_pts);
                            }
                        }
 
                        var curveqp = _hydroInfo.Curves?.Find(x => x.Code == pump.CurveQP);
                        if (curveqp != null)
                        {
                            var qp_pts = curveqp.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                            if (qp_pts != null && qp_pts.Count > 3)
                            {
                                var qp_run_pts = qp_pts.GetQPPointListByN(pump.RatedHz, vmItem.Hz);
                                vmItem.CurveQP = new CubicSpline2d(qp_run_pts);
                            }
                        }
 
                        var curveqe = _hydroInfo.Curves?.Find(x => x.Code == pump.CurveQE);
                        if (curveqe != null)
                        {
                            var qe_pts = curveqe.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                            if (qe_pts != null && qe_pts.Count > 3)
                            {
                                var qe_run_pts = qe_pts.GetQEPointListByN(pump.RatedHz, vmItem.Hz);
                                vmItem.CurveQE = new CubicSpline2d(qe_run_pts);
                            }
                        }
 
                    }
 
                    vm.PipeQ = vm.Items.Sum(t => t.Q);
                    vm.PipeH = vm.Items.Max(t => t.H);
                }
            }
 
            return vm;
        }
 
 
    }
}