duheng
2024-12-05 580201d86a324677a1d64a87c7ff79dceb27a58e
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
using Yw.Geometry;
 
namespace HStation.WinFrmUI.PhartRelation
{
    public partial class PumpSerialParallelChartDlg : XtraForm
    {
        public PumpSerialParallelChartDlg()
        {
            InitializeComponent();
            this.Text = "曲线视图";
            this.WindowState = FormWindowState.Maximized;
 
            this.pumpSerialParallelInfoCtrl1.SetEvent += (id, qh, qe, qp) =>
            {
                this.pumpSerialParallelChart.Set(id, qh, qe, qp);
                var list = this.pumpSerialParallelInfoCtrl1.GetList();
                SetSerialParallel(list, _design_pt, _is_parallel);
            };
 
            this.pumpSerialParallelInfoCtrl1.SetInfoEvent += (id, name, color) =>
            {
                this.pumpSerialParallelChart.Set(id, name, color);
            };
 
            this.pumpSerialParallelInfoCtrl1.SetDesignPointEvent += (q, h) =>
            {
                _design_pt = new Point2d(q, h);
                this.pumpSerialParallelChart.SetDesignPoint(new Point2d(q, h));
            };
 
            this.pumpSerialParallelChart.QueryPointChangedEvent += (id, pt) =>
            {
                this.pumpSerialParallelInfoCtrl1.SetQueryInfo(id, pt);
            };
        }
 
        private string _serial_parallel_id = "serial_parallel";
        private Yw.Geometry.Point2d _design_pt;
        private bool _is_parallel;
 
        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="list"></param>
        /// <param name="design_pt"></param> 
        /// <param name="is_parallel"></param>
        /// <returns></returns>
        public string SetBindingData(
            List<Yw.WinFrmUI.Phart.PumpParallelViewModel> list,
            Yw.Geometry.Point2d design_pt,
            bool is_parallel = true)
        {
            if (list == null || !list.Any())
            {
                return "数据为空!";
            }
 
            _is_parallel = is_parallel;
            _design_pt = design_pt;
            var vm_list = new List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel>();
            for (int i = 0; i < list.Count; i++)
            {
                var x = list[i];
                var vm = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel(x);
                vm.Color = GetRandomColor(i);
                vm.Calc();
                vm_list.Add(vm);
            }
 
            this.pumpSerialParallelInfoCtrl1.SetBindingData(vm_list, _design_pt);
            this.pumpSerialParallelChart.Add(vm_list, _design_pt);
 
            var msg = SetSerialParallel(vm_list, _design_pt, _is_parallel);
            if (!string.IsNullOrEmpty(msg))
                return msg;
            return string.Empty;
        }
 
 
        private string SetSerialParallel(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list, Yw.Geometry.Point2d design_pt, bool is_parallel)
        {
            this.pumpSerialParallelChart.Delete(_serial_parallel_id);
            if (list == null || !list.Any())
            {
                return "无数据!";
            }
            var vm_serial_parallel = CalcSerialParallel(list, is_parallel);
            if (vm_serial_parallel == null)
            {
                return "无法计算串并联曲线!";
            }
 
            var qh = vm_serial_parallel.CurveQH;
            var min_h = qh.GetPointY(qh.MinX);
            var max_h = qh.GetPointY(qh.MaxX);
            if (design_pt != null)
            {
                if (design_pt.X > qh.MaxX || design_pt.X < qh.MinX)
                {
                    return "设计流量无效!";
                }
 
                if (design_pt.Y > max_h * 2 || design_pt.Y < min_h * 0.5)
                {
                    return "设计扬程无效!";
                }
            }
            else
            {
                var design_q = qh.MaxX / 2;
                var design_h = qh.GetPointY(design_q);
                design_q = Math.Round(design_q, 1);
                design_h = Math.Round(design_h, 1);
                design_pt = new Point2d(design_q, design_h);
                _design_pt = design_pt;
                this.pumpSerialParallelInfoCtrl1.SetDesignPoint(design_pt);
            }
 
            this.pumpSerialParallelChart.Add(vm_serial_parallel, design_pt);
            return string.Empty;
        }
 
        private Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel CalcSerialParallel(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list, bool is_parallel)
        {
            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));
            if (is_parallel)
            {
                line_name = "并联曲线";
                calc_bol = helper.CalculateParallel(out calc_pt_qh_list, out calc_pt_qe_list, out calc_pt_qp_list);
            }
            else
            {
                line_name = "串联曲线";
                calc_bol = helper.CalculateSeries(out calc_pt_qh_list, out calc_pt_qe_list, out calc_pt_qp_list);
            }
 
            if (!calc_bol)
            {
                return default;
            }
 
            var vm_sp = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel();
            vm_sp.Id = _serial_parallel_id;
            vm_sp.Name = line_name;
            vm_sp.CurveQH = new Yw.Geometry.CubicSpline2d(calc_pt_qh_list);
            vm_sp.CurveQE = new Yw.Geometry.CubicSpline2d(calc_pt_qe_list);
            vm_sp.CurveQP = new Yw.Geometry.CubicSpline2d(calc_pt_qp_list);
            vm_sp.QhCalc = vm_sp.CurveQH;
            vm_sp.QeCalc = vm_sp.CurveQE;
            vm_sp.QpCalc = vm_sp.CurveQP;
            vm_sp.Color = Color.Black;
            vm_sp.IsBp = true;
            vm_sp.IsDefault = true;
            return vm_sp;
        }
 
 
        #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
 
    }
}