lixiaojun
2024-12-09 725f20b576bdd40d57d9a1e806ce3f6f39181a84
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
using System.Data;
using Yw.Geometry;
using Yw.WinFrmUI.Phart;
 
namespace HStation.WinFrmUI.PhartRelation
{
    public partial class PumpParallelAnalyDlg : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public PumpParallelAnalyDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.pumpSerialParallelChart.LineVisible = true;
            this.pumpParallelInfoCtrl1.SetEvent += (id, qh, qe, qp) =>
            {
                var list = this.pumpParallelInfoCtrl1.GetRunList();
                SetParallel(list);
            };
            this.pumpParallelInfoCtrl1.SetInfoEvent += (id, name, color) =>
            {
                this.pumpSerialParallelChart.SetInfo(id, name, color);
            };
 
            this.pumpParallelInfoCtrl1.SetDesignPointEvent += (q, h) =>
            {
                this.pumpSerialParallelChart.SetDesignPt(new Point2d(q, h));
            };
 
            this.pumpParallelInfoCtrl1.AddEvent += (vm) =>
            {
                var list = this.pumpParallelInfoCtrl1.GetRunList();
                SetParallel(list);
            };
 
            this.pumpParallelInfoCtrl1.DeleteEvent += (id) =>
            {
                var list = this.pumpParallelInfoCtrl1.GetRunList();
                SetParallel(list);
            };
 
            this.pumpSerialParallelChart.OnCalcQueryPoint += (id, pt) =>
            {
                this.pumpParallelInfoCtrl1.SetQueryInfo(id, pt);
            };
            this.pumpParallelInfoCtrl1.ResetEvent += () =>
            {
                var list = this.pumpParallelInfoCtrl1.GetRunList();
                SetParallel(list);
            };
            this.pumpParallelInfoCtrl1.SaveEvent += () =>
            {
                var run_list = this.pumpParallelInfoCtrl1.GetRunList();
                var list = new List<XhsSingleResultViewModel>();
                if (run_list != null && run_list.Any())
                {
                    foreach (var x in run_list)
                    {
                        var vm = new XhsSingleResultViewModel();
                        vm.ID = x.ID;
                        vm.Name = x.Name;
                        vm.Code = x.Code;
                        vm.IsBp = x.IsBp;
                        vm.RunStatus = x.RunStatus;
                        vm.CurrentHz = x.CurrentHz;
                        list.Add(vm);
                    }
                }
                var bol = this.ReloadDataEvent?.Invoke(list);
                if (bol.HasValue && bol.Value)
                {
                    this.Close();
                }
            };
        }
 
        private string _parallel_id = "parallel";
        public event Func<List<XhsSingleResultViewModel>, bool> ReloadDataEvent;
 
 
        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="list"></param> 
        /// <returns></returns>
        public string SetBindingData(
            List<XhsSinglePumpViewModel> list)
        {
            if (list == null || !list.Any())
            {
                return "数据为空!";
            }
 
            var vm_list = new List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel>();
            for (int i = 0; i < list.Count; i++)
            {
                var x = list[i];
                if (x.CurveQH == null || !x.CurveQH.Any())
                {
                    continue;
                }
 
                var vm = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel();
                vm.ID = x.ID;
                vm.Id = x.ID.ToString();
                vm.Name = x.Name;
                vm.Code = x.Code;
                vm.IsBp = x.IsBp;
                vm.RatedSpeed = x.RatedSpeed;
                vm.CurrentSpeed = x.CurrentSpeed;
                vm.RunStatus = x.RunStatus;
                vm.CurrentHz = x.CurrentHz;
                var qh_pt_list = x.CurveQH.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                vm.Qh = new CubicSpline2d(qh_pt_list);
                if (x.CurveQE != null && x.CurveQE.Any())
                {
                    var qe_pt_list = x.CurveQE.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                    vm.Qe = new CubicSpline2d(qe_pt_list);
                }
                if (x.CurveQP != null && x.CurveQP.Any())
                {
                    var qp_pt_list = x.CurveQP.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                    vm.Qp = new CubicSpline2d(qp_pt_list);
                }
 
                vm.CalcuQ = x.CalcuQ;
                vm.CalcuH = x.CalcuH;
                vm.Color = GetRandomColor(i);
                vm.Calc();
                vm_list.Add(vm);
 
                if (!x.RunStatus)
                    continue;
 
                if (!x.CalcuQ.HasValue || !x.CalcuH.HasValue)
                    continue;
                var calc_flow = x.CalcuQ.Value;
                var calc_head = x.CalcuH.Value;
 
                var max_flow = vm.Qh.MaxX;
                var max_flow_head = vm.Qh.GetPointY(max_flow);
 
                var min_flow = vm.Qh.MinX;
                var min_flow_head = vm.Qh.GetPointY(min_flow);
 
                if (max_flow_head < calc_head && min_flow_head > calc_head)
                    continue;
 
                var extend_ratio = 1m;
                var extend_success = false;
                for (decimal num = 0.01m; num <= 5; num += 0.01m)
                {
                    extend_ratio += num;
                    var ex_pt_list = qh_pt_list.GetExpandFitPointList((double)extend_ratio);
                    var ex_x_array = ex_pt_list.GetInterPointsX(calc_head);
                    if (ex_x_array != null && ex_x_array.Any())
                    {
                        extend_success = true;
                        vm.ExtendRatio = Math.Round((double)extend_ratio * 100, 1);
                        vm.Calc();
                        break;
                    }
                }
                if (!extend_success)
                {
 
                }
            }
 
            this.pumpParallelInfoCtrl1.SetBindingData(vm_list, null);
            var run_list = this.pumpParallelInfoCtrl1.GetRunList();
            var msg = SetParallel(run_list);
            this.pumpSerialParallelChart.SetQeVisible(false);
            if (!string.IsNullOrEmpty(msg))
            {
                return msg;
            }
            return string.Empty;
        }
 
        private string SetParallel(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list)
        {
            var msg = "并联成功";
            this.pumpSerialParallelChart.Delete();
            if (list == null || !list.Any())
            {
                msg = "无数据";
                return msg;
            }
            else
            {
                if (list.Count < 2)
                {
                    msg = "并联失败";
                }
                else
                {
                    var vm_parallel = CalcParallel(list);
                    if (vm_parallel != null)
                    {
                        list.Add(vm_parallel);
                    }
                    else
                    {
                        msg = "并联失败";
                    }
                }
            }
            Set(list);
            this.barInfo.Caption = $"<b><color=red>{msg}</color></b>";
            return msg;
 
        }
 
 
        private Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel CalcParallel(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list)
        {
            if (list == null || !list.Any())
            {
                return default;
            }
 
            var calc_bol = false;
            var line_name = "";
            List<Yw.Geometry.Point2d> calc_pt_qh_list;
            List<Yw.Geometry.Point2d> calc_pt_qe_list;
            List<Yw.Geometry.Point2d> calc_pt_qp_list;
 
            var helper = new Yw.WinFrmUI.Phart.PumpParallelConnectionHelper();
            list.ForEach(x => helper.Add(x.QhCalc, x.QpCalc));
            line_name = "并联曲线";
            calc_bol = helper.CalculateParallel(out calc_pt_qh_list, out calc_pt_qe_list, out calc_pt_qp_list);
 
            if (!calc_bol || calc_pt_qh_list.Count < 4)
            {
                return default;
            }
            double total_flow = list.Sum(x => x.CalcuQ ?? 0);
            double total_head = list.Average(x => x.CalcuH ?? 0);
 
            var qh = new Yw.Geometry.CubicSpline2d(calc_pt_qh_list);
            var qe = new Yw.Geometry.CubicSpline2d(calc_pt_qe_list);
            var qp = new Yw.Geometry.CubicSpline2d(calc_pt_qp_list);
 
 
            var vm_sp = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel();
            vm_sp.Id = _parallel_id;
            vm_sp.Name = line_name;
            vm_sp.Qh = qh;
            vm_sp.Qe = qe;
            vm_sp.Qp = qp;
 
            vm_sp.QhCalc = qh;
            vm_sp.QeCalc = qe;
            vm_sp.QpCalc = qp;
 
            vm_sp.CalcuH = total_head;
            vm_sp.CalcuQ = total_flow;
 
 
            vm_sp.Color = Color.Black;
            vm_sp.IsBp = true;
            vm_sp.IsDefault = true;
            return vm_sp;
 
        }
 
        private void Set(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list)
        {
            if (list == null || !list.Any())
            {
                this.pumpSerialParallelChart.InitialChartData();
                return;
            }
 
            this.pumpSerialParallelChart.Add(list);
            var run_list = list.Where(x => x.RunStatus).ToList();
            if (run_list != null && run_list.Any())
            {
                double total_flow = run_list.Sum(x => x.CalcuQ ?? 0);
                double total_head = run_list.Average(x => x.CalcuH ?? 0);
                total_flow = Math.Round(total_flow, 1);
                total_head = Math.Round(total_head, 1);
                this.pumpParallelInfoCtrl1.SetDesignPoint(total_flow, total_head);
                this.pumpSerialParallelChart.CalcWorkPointByQ(total_flow);
            }
 
        }
 
 
 
        #region Color
 
        private List<Color> _color_array = new List<Color>()
        {
            Color.Red, Color.Blue, Color.Green,Color.DodgerBlue,
            Color.Fuchsia, Color.MidnightBlue,  Color.Maroon, Color.Aquamarine,
            Color.Bisque,Color.BurlyWood
        };
 
        /// <summary>
        /// 获取随机颜色
        /// </summary>
        /// <returns></returns>
        private Color GetRandomColor(int count)
        {
            if (count < _color_array.Count)
            {
                return _color_array[count];
            }
 
            var _random = new Random();
            int r = _random.Next(1, 256);
            int g = _random.Next(1, 256);
            int b = _random.Next(1, 256);
            return Color.FromArgb(r, g, b);
        }
 
        #endregion
 
 
 
    }
}