Shuxia Ning
2025-01-17 a0bce3b366451b3ca94e676eb98dd7b415375c14
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
namespace Yw.WinFrmUI.Phart
{
    public partial class PumpChartExcelEditCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public PumpChartExcelEditCtrl()
        {
 
            InitializeComponent();
            this.gridView1.SetDefaultEditView();
            this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
 
            this.repImgCmbCurveType.Items.Add("流量扬程", Yw.Ahart.eCurveType.QH, -1);
            this.repImgCmbCurveType.Items.Add("流量效率", Yw.Ahart.eCurveType.QE, -1);
            this.repImgCmbCurveType.Items.Add("流量功率", Yw.Ahart.eCurveType.QP, -1);
 
            this.repImgCmbFeatType.Items.Add("穿过点", Yw.Ahart.eFeatType.Through, -1);
            this.repImgCmbFeatType.Items.Add("二次拟合", Yw.Ahart.eFeatType.Quadratic, -1);
            this.repImgCmbFeatType.Items.Add("三次拟合", Yw.Ahart.eFeatType.Cubic, -1);
            this.repImgCmbFeatType.Items.Add("四次拟合", Yw.Ahart.eFeatType.Quartic, -1);
 
            this.repImgCmbEditModel.Items.Add("鼠标", 0, -1);
            this.repImgCmbEditModel.Items.Add("键盘", 1, -1);
 
            this.pumpEditChart1.DefinePointChangedEvent += PumpEditChart1_DefinePointChangedEvent1;
            this.pumpEditChart1.SelectedPointIndexChangedEvent += (index) =>
            {
                this.gridView1.FocusedRowHandle = index;
            };
 
            this.Enabled = false;
 
        }
 
 
        private List<Yw.Geometry.Point2d> _def_qh_pt_list;
        private List<Yw.Geometry.Point2d> _def_qe_pt_list;
        private List<Yw.Geometry.Point2d> _def_qp_pt_list;
 
        private Yw.Ahart.eFeatType _feat_type_qh;
        private Yw.Ahart.eFeatType _feat_type_qe;
        private Yw.Ahart.eFeatType _feat_type_qp;
 
        private Yw.Ahart.eCurveType _edit_curve_type;
 
 
        /// <summary>
        /// 绑定数据
        /// </summary> 
        public void SetBindingData(
            List<Yw.Geometry.Point2d> def_qh_pt_list,
            List<Yw.Geometry.Point2d> def_qe_pt_list,
            List<Yw.Geometry.Point2d> def_qp_pt_list,
            Yw.Ahart.eFeatType feat_type_qh = Ahart.eFeatType.Cubic,
            Yw.Ahart.eFeatType feat_type_qe = Ahart.eFeatType.Cubic,
            Yw.Ahart.eFeatType feat_type_qp = Ahart.eFeatType.Cubic,
            Yw.Ahart.eCurveType curve_type = Ahart.eCurveType.QH)
        {
            _edit_curve_type = curve_type;
 
            _feat_type_qh = feat_type_qh;
            _def_qh_pt_list = def_qh_pt_list?.Select(x => new Geometry.Point2d(x.X, x.Y)).ToList();
 
            _feat_type_qe = feat_type_qe;
            _def_qe_pt_list = def_qe_pt_list?.Select(x => new Geometry.Point2d(x.X, x.Y)).ToList();
 
            _feat_type_qp = feat_type_qp;
            _def_qp_pt_list = def_qp_pt_list?.Select(x => new Geometry.Point2d(x.X, x.Y)).ToList();
 
 
 
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
 
            this.barImgCmbCurveType.EditValue = _edit_curve_type;
            this.barEditModel.EditValue = 0;
            this.barFeatType.EditValue = _feat_type_qh;
            this.bindingSource1.DataSource = _def_qh_pt_list;
            this.bindingSource1.ResetBindings(false);
 
            this.Enabled = true;
        }
 
        private void PumpEditChart1_DefinePointChangedEvent1(Ahart.eCurveType curve_type, List<Geometry.Point2d> pt_list)
        {
            switch (curve_type)
            {
                case Ahart.eCurveType.QH:
                    {
                        _def_qh_pt_list = pt_list;
                        this.bindingSource1.DataSource = _def_qh_pt_list;
                    }
                    break;
                case Ahart.eCurveType.QE:
                    {
                        _def_qe_pt_list = pt_list;
                        this.bindingSource1.DataSource = _def_qe_pt_list;
                    }
                    break;
                case Ahart.eCurveType.QP:
                    {
                        _def_qp_pt_list = pt_list;
                        this.bindingSource1.DataSource = _def_qp_pt_list;
                    }
                    break;
            }
 
            this.bindingSource1.ResetBindings(false);
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
        }
 
 
 
        //设置图表
        private void SetChart(
            List<Yw.Geometry.Point2d> def_qh_pt_list,
            List<Yw.Geometry.Point2d> def_qe_pt_list,
            List<Yw.Geometry.Point2d> def_qp_pt_list,
            Yw.Ahart.eFeatType feat_type_qh,
            Yw.Ahart.eFeatType feat_type_qe,
            Yw.Ahart.eFeatType feat_type_qp,
            Yw.Ahart.eCurveType curve_type
            )
        {
            var fit_qh_pt_list = def_qh_pt_list?.GetPointList(feat_type_qh);
            var fit_qe_pt_list = def_qe_pt_list?.GetPointList(feat_type_qe);
            var fit_qp_pt_list = def_qp_pt_list?.GetPointList(feat_type_qp);
            this.pumpEditChart1.SetBindingData(def_qh_pt_list, fit_qh_pt_list, def_qe_pt_list, fit_qe_pt_list, def_qp_pt_list, fit_qp_pt_list, curve_type);
        }
 
 
 
        //值变换
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
        }
 
        //曲线类型
        private void barImgCmbCurveType_EditValueChanged(object sender, EventArgs e)
        {
            _edit_curve_type = (Yw.Ahart.eCurveType)this.barImgCmbCurveType.EditValue;
            var (axis_x_title, axis_y_title) = PhartAxisTitleHelper.Get(_edit_curve_type);
            this.colX.Caption = axis_x_title;
            this.colY.Caption = axis_y_title;
 
            switch (_edit_curve_type)
            {
                case Ahart.eCurveType.QH:
                    {
                        this.bindingSource1.DataSource = _def_qh_pt_list;
                    }
                    break;
                case Ahart.eCurveType.QE:
                    {
                        this.bindingSource1.DataSource = _def_qe_pt_list;
                    }
                    break;
                case Ahart.eCurveType.QP:
                    {
                        this.bindingSource1.DataSource = _def_qp_pt_list;
                    }
                    break;
            }
            this.bindingSource1.ResetBindings(false);
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
        }
 
 
        //拟合类型
        private void barFeatType_EditValueChanged(object sender, EventArgs e)
        {
            var feat_type = (Yw.Ahart.eFeatType)this.barFeatType.EditValue;
            switch (_edit_curve_type)
            {
                case Ahart.eCurveType.QH: _feat_type_qh = feat_type; break;
                case Ahart.eCurveType.QE: _feat_type_qe = feat_type; break;
                case Ahart.eCurveType.QP: _feat_type_qp = feat_type; break;
            }
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
        }
 
        //鼠标模式
        private void barEditModel_EditValueChanged(object sender, EventArgs e)
        {
            var index = (int)this.barEditModel.EditValue;
            this.pumpEditChart1.MouseModel = index == 0;
        }
 
        //计算
        private void barBtnCalc_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_def_qh_pt_list == null || !_def_qh_pt_list.Any())
                return;
            bool is_from_zero;
            if (_def_qh_pt_list.Last().X > 20)
                is_from_zero = _def_qh_pt_list.First().X < 1;
            else
                is_from_zero = _def_qh_pt_list.First().X < 0.3;
 
            switch (_edit_curve_type)
            {
                case Ahart.eCurveType.QE:
                    {
                        _def_qe_pt_list = Yw.Pump.CalculationHelper.CalcuE(_def_qh_pt_list, _feat_type_qh, _def_qp_pt_list, _feat_type_qp, Yw.Pump.ConstantParas.WaterDensity, is_from_zero);
                        this.bindingSource1.DataSource = _def_qe_pt_list;
                    }
                    break;
                case Ahart.eCurveType.QP:
                    {
                        double ref_zero_power = -1;
                        if (_def_qp_pt_list != null && _def_qp_pt_list.Count > 0)
                            ref_zero_power = _def_qp_pt_list.First().Y;
                        _def_qp_pt_list = Yw.Pump.CalculationHelper.CalcuP(_feat_type_qp, _def_qh_pt_list, _feat_type_qh, _def_qe_pt_list, _feat_type_qe, Yw.Pump.ConstantParas.WaterDensity, ref_zero_power, is_from_zero);
                        this.bindingSource1.DataSource = _def_qp_pt_list;
                    }
                    break;
            }
            this.bindingSource1.ResetBindings(false);
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
        }
 
        //添加点
        private void barAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_def_qh_pt_list == null || !_def_qh_pt_list.Any())
                return;
            List<Yw.Geometry.Point2d> def_pt_list = null;
            switch (_edit_curve_type)
            {
                case Ahart.eCurveType.QH: def_pt_list = _def_qh_pt_list; break;
                case Ahart.eCurveType.QE: def_pt_list = _def_qe_pt_list; break;
                case Ahart.eCurveType.QP: def_pt_list = _def_qp_pt_list; break;
            }
            if (def_pt_list == null)
                return;
            double x = 0;
            double y = 1;
            if (def_pt_list.Count > 0)
            {
                x = def_pt_list.Last().X;
                y = def_pt_list.Last().Y;
            }
            def_pt_list.Add(new Geometry.Point2d(x, y));
            this.bindingSource1.ResetBindings(false);
            this.gridView1.FocusedRowHandle = def_pt_list.Count - 1;
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
        }
 
 
        //删除点
        private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_def_qh_pt_list == null || !_def_qh_pt_list.Any())
                return;
            List<Yw.Geometry.Point2d> def_pt_list = null;
            Yw.Ahart.eFeatType feat_type = Ahart.eFeatType.Cubic;
            switch (_edit_curve_type)
            {
                case Ahart.eCurveType.QH: def_pt_list = _def_qh_pt_list; feat_type=_feat_type_qh; break;
                case Ahart.eCurveType.QE: def_pt_list = _def_qe_pt_list; feat_type = _feat_type_qe; break;
                case Ahart.eCurveType.QP: def_pt_list = _def_qp_pt_list; feat_type = _feat_type_qp; break;
            }
            var row = this.gridView1.GetCurrentViewModel(def_pt_list);
            if (row == null)
                return;
            var count = def_pt_list.Count - 1;
            switch (feat_type)
            {
                case Ahart.eFeatType.Cubic:
                    {
                        if (count < 4)
                        {
                            TipFormHelper.ShowInfo("点数少于4个点");
                            return;
                        }
                    }
                    break;
                case Ahart.eFeatType.Through:
                    {
                        if (count < 1)
                        {
                            TipFormHelper.ShowInfo("点数少于1个点");
                            return;
                        }
                    }
                    break;
                case Ahart.eFeatType.Quadratic:
                    {
                        if (count < 3)
                        {
                            TipFormHelper.ShowInfo("点数少于3个点");
                            return;
                        }
                    }
                    break;
                case Ahart.eFeatType.Quartic:
                    {
                        if (count < 5)
                        {
                            TipFormHelper.ShowInfo("点数少于5个点");
                            return;
                        }
                    }
                    break;
            }
            def_pt_list.Remove(row);
            this.bindingSource1.ResetBindings(false);
            SetChart(_def_qh_pt_list, _def_qe_pt_list, _def_qp_pt_list, _feat_type_qh, _feat_type_qe, _feat_type_qp, _edit_curve_type);
        }
 
        /// <summary>
        /// 获取数据
        /// </summary> 
        public bool Get(
           out List<Yw.Geometry.Point2d> def_qh_pt_list,
           out List<Yw.Geometry.Point2d> def_qe_pt_list,
           out List<Yw.Geometry.Point2d> def_qp_pt_list,
           out Yw.Ahart.eFeatType feat_type_qh,
           out Yw.Ahart.eFeatType feat_type_qe,
           out Yw.Ahart.eFeatType feat_type_qp)
        {
            def_qh_pt_list = _def_qh_pt_list;
            def_qe_pt_list = _def_qe_pt_list;
            def_qp_pt_list = _def_qp_pt_list;
            feat_type_qh = _feat_type_qh;
            feat_type_qe = _feat_type_qe;
            feat_type_qp = _feat_type_qp;
            if (def_qh_pt_list == null || !def_qh_pt_list.Any())
                return false;
            return true;
        }
 
 
    }
 
}