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
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
using DevExpress.Spreadsheet;
using Yw.Geometry;
using Yw.WinFrmUI.Phart;
 
namespace HStation.WinFrmUI.PhartRelation
{
    public partial class PumpVariableSpeedChartDlg : XtraForm
    {
        public PumpVariableSpeedChartDlg()
        {
            InitializeComponent();
            this.Text = "曲线视图";
            this.WindowState = FormWindowState.Maximized;
 
            this.pumpVariableSpeedChart.SetQeVisible(false);
            this.pumpVariableSpeedInfoCtrl1.SetEvent += (id, hz, ex_ratio, qh, qe, qp) =>
            {
                this.pumpVariableSpeedChart.Set(id, hz, ex_ratio, qh, qe, qp);
                ResetSectPointGrid();
            };
 
            this.pumpVariableSpeedInfoCtrl1.SetInfoEvent += (id, color) =>
            {
                this.pumpVariableSpeedChart.SetInfo(id, color);
                ResetSectPointGrid();
            };
 
            this.pumpVariableSpeedChart.AddBySpeedEvent += () =>
            {
                AddBySpeed();
                ResetSectPointGrid();
            };
 
            this.pumpVariableSpeedChart.AddByHzEvent += () =>
            {
                AddByHz();
                ResetSectPointGrid();
            };
 
            this.pumpVariableSpeedChart.AddByPointEvent += () =>
            {
                AddByPoint();
                ResetSectPointGrid();
            };
 
            this.pumpVariableSpeedInfoCtrl1.SetDesignPointEvent += (q, h) =>
            {
                _design_pt = new Point2d(q, h);
                this.pumpVariableSpeedChart.SetEquipPt(_design_pt);
                ResetSectPointGrid();
            };
 
            this.pumpVariableSpeedChart.OnCalcQueryPoint += (id, pt) =>
            {
                this.pumpVariableSpeedInfoCtrl1.SetQueryInfo(id, pt);
            };
 
 
        }
 
        private Yw.Geometry.Point2d _design_pt;
 
 
        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="list"></param>
        /// <param name="design_pt"></param> 
        /// <param name="is_parallel"></param>
        /// <returns></returns>
        public string SetBindingData(
            Yw.WinFrmUI.Phart.PumpVariableSpeedViewModel vm,
            Yw.Geometry.Point2d design_pt)
        {
            _design_pt = design_pt;
            var vm_list = new List<Yw.WinFrmUI.Phart.PumpVariableSpeedInfoViewModel>();
 
            var vm_info = new Yw.WinFrmUI.Phart.PumpVariableSpeedInfoViewModel(vm);
            vm_info.IsDefault = true;
            vm_info.Name = $"{vm.CurrentSpeed}({vm.CurrentHz}hz)";
            vm_info.Color = GetRandomColor(0);
            vm_info.Calc();
            vm_list.Add(vm_info);
             
            this.pumpVariableSpeedInfoCtrl1.SetBindingData(vm_list, _design_pt);
            this.pumpVariableSpeedChart.Add(vm_list, _design_pt);
 
            return string.Empty;
        }
 
 
        private void ResetSectPointGrid()
        {
            var vm_list = this.pumpVariableSpeedChart.GetVmList();
            this.pumpVariableSpeedInfoCtrl1.SetSectPoint(vm_list);
        }
 
 
        private void AddBySpeed()
        {
            var list = this.pumpVariableSpeedInfoCtrl1.GetList();
            if (list == null || list.Count < 1)
            {
                return;
            }
            var index = list.Count;
            var vm_def = list.First();
            var dlg = new SetValueDlg();
            dlg.SetBindingData(vm_def.RatedSpeed);
            dlg.VerifyValueChanged += (speed) =>
            {
                var hz = Math.Round(speed / vm_def.RatedSpeed * 50, 1);
                if (hz > 50 || hz < 10)
                {
                    return false;
                }
                var vm = new PumpVariableSpeedInfoViewModel(vm_def);
                vm.Id = Guid.NewGuid().ToString();
                vm.Name = $"{speed}({hz}hz)";
                vm.Color = GetRandomColor(index);
                vm.CurrentHz = hz;
                vm.CurrentSpeed = speed;
                vm.Calc();
 
                this.pumpVariableSpeedInfoCtrl1.Add(vm);
                this.pumpVariableSpeedChart.Add(vm, _design_pt);
 
                return true;
            };
            dlg.ShowDialog();
 
        }
 
        private void AddByHz()
        {
 
            var list = this.pumpVariableSpeedInfoCtrl1.GetList();
            if (list == null || list.Count < 1)
            {
                return;
            }
            var index = list.Count;
            var vm_def = list.First();
            var dlg = new SetValueDlg();
            dlg.VerifyValueChanged += (hz) =>
            {
                if (hz > 50 || hz < 10)
                {
                    return false;
                }
                var speed = Math.Round(hz / 50 * vm_def.RatedSpeed);
                var vm = new PumpVariableSpeedInfoViewModel(vm_def);
                vm.Id = Guid.NewGuid().ToString();
                vm.Name = $"{speed}({hz}hz)";
                vm.Color = GetRandomColor(index);
                vm.CurrentHz = hz;
                vm.CurrentSpeed = speed;
                vm.Calc();
 
                this.pumpVariableSpeedInfoCtrl1.Add(vm);
                this.pumpVariableSpeedChart.Add(vm, _design_pt);
 
                return true;
            };
            dlg.ShowDialog();
        }
 
        private void AddByPoint()
        {
            var list = this.pumpVariableSpeedInfoCtrl1.GetList();
            if (list == null || list.Count < 1)
            {
                return;
            }
            var index = list.Count;
            var vm_def = list.First();
 
            var dlg = new SetPointDlg();
            dlg.SetBindingData();
            dlg.VerifyValueChanged += (x, y) =>
            {
                var pt = new Yw.Geometry.Point2d(x, y);
                var speed = PumpCalcHelper.GetSimuValue(vm_def.Qh, pt, vm_def.RatedSpeed);
                var hz = Math.Round(speed / vm_def.RatedSpeed * 50, 1);
                if (hz > 50 || hz < 20)
                {
                    return false;
                }
                var vm = new PumpVariableSpeedInfoViewModel(vm_def);
                vm.Id = Guid.NewGuid().ToString();
                vm.Name = $"{speed}({hz}hz)";
                vm.Color = GetRandomColor(index);
                vm.CurrentHz = hz;
                vm.CurrentSpeed = speed;
                vm.Calc();
 
                this.pumpVariableSpeedInfoCtrl1.Add(vm);
                this.pumpVariableSpeedChart.Add(vm, _design_pt);
                return true;
            };
            dlg.ShowDialog();
        }
 
 
        #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
 
    }
}