duheng
2025-04-24 4de480ec624d3b79ca690dc906e10cd2fbdc9be7
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
using DevExpress.Utils;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 
 
//编辑原始的性能曲线
namespace IStation.WinFrmUI.Curve
{
    public partial class FeatCurveByEditCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public FeatCurveByEditCtrl()
        {
            InitializeComponent();
            this.gridView1.OptionsFind.FindNullPrompt = "检索";
            this.gridView1.OptionsSelection.MultiSelect = false;
            this.gridView1.OptionsMenu.EnableColumnMenu = true;
 
            this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
            this.gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            this.gridView1.Appearance.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
            this.gridView1.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
            this.gridView1.OptionsCustomization.AllowFilter = true;
            this.gridView1.OptionsCustomization.AllowSort = true;
            this.gridView1.OptionsCustomization.AllowQuickHideColumns = false;
            this.gridView1.OptionsView.ShowAutoFilterRow = false;
            this.gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;
            this.gridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.None;
            this.gridView1.OptionsView.ShowGroupPanel = false;
            this.gridView1.OptionsClipboard.AllowCopy = DefaultBoolean.True;
            this.gridView1.OptionsBehavior.Editable = true;
            this.gridView1.OptionsBehavior.ReadOnly = false;
 
            this.gridView1.OptionsView.EnableAppearanceOddRow = true;
            this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
            this.gridView1.Appearance.OddRow.BackColor = Color.White;
            this.gridView1.Appearance.EvenRow.BackColor = Color.FromArgb(244, 248, 251);
 
            int height = 30;
            this.gridView1.RowHeight = height;
            this.gridView1.ColumnPanelRowHeight = height;
            this.gridView1.GroupRowHeight = height;
            this.gridView1.BestFitColumns();
 
            this.gridView1.OptionsView.ShowIndicator = true;
            this.gridView1.IndicatorWidth = height;
            this.gridView1.CustomDrawRowIndicator += (sender, e) =>
            {
                if (e.Info.IsRowIndicator && e.RowHandle >= 0)
                {
                    e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();
                    e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
                }
            };
            this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
 
            this.featCurvesDispCtrl1.ChangeFeatPointEvent += OnChangeFeatPoint;
        }
 
        //性能曲线点变换事件
        private void OnChangeFeatPoint(object sender, EventArgs e)
        {
            _featCurvePoints.Clear();
            switch (_editCurveType)
            {
                case Model.eFeatCurveType.QH:
                    {
                        foreach (Model.CurvePoint pt in _qhPoints)
                            _featCurvePoints.Add(new Model.CurvePoint(pt.X, pt.Y));
                    }
                    break;
                case Model.eFeatCurveType.QE:
                    {
                        foreach (Model.CurvePoint pt in _qePoints)
                            _featCurvePoints.Add(new Model.CurvePoint(pt.X, pt.Y));
                    }
                    break;
                case Model.eFeatCurveType.QP:
                    {
                        foreach (Model.CurvePoint pt in _qpPoints)
                            _featCurvePoints.Add(new Model.CurvePoint(pt.X, pt.Y));
                    }
                    break;
            }
            this.bindingSource1.ResetBindings(false);
        }
 
        Model.eCurveFitType _qhFitType = Model.eCurveFitType.CubicCurve;
        Model.eCurveFitType _qeFitType = Model.eCurveFitType.CubicCurve;
        Model.eCurveFitType _qpFitType = Model.eCurveFitType.CubicCurve;
 
        private List<Model.CurvePoint> _qhPoints = null;
        private List<Model.CurvePoint> _qePoints = null;
        private List<Model.CurvePoint> _qpPoints = null;
 
        private List<Model.CurvePoint> _featCurvePoints = null;
 
        Unit.eUnitQ _unitQ = Unit.eUnitQ.M3H;
        Unit.eUnitH _unitH = Unit.eUnitH.M;
        Model.eFeatCurveType _editCurveType = Model.eFeatCurveType.QH;
 
        /// <summary>
        /// 初始化数据
        /// </summary> 
        public void InitialBindingData(List<Model.CurvePoint> qhPoints, List<Model.CurvePoint> qePoints, List<Model.CurvePoint> qpPoints,
                                Model.eCurveFitType qhFitType, Model.eCurveFitType qeFitType, Model.eCurveFitType qpFitType)
        {
            _featCurvePoints = new List<Model.CurvePoint>();
            this.bindingSource1.DataSource = _featCurvePoints;
 
            _qhPoints = null;
            _qePoints = null;
            _qpPoints = null;
 
 
            if (qhPoints == null || qhPoints.Count < 4)
            {
                this.featCurvesDispCtrl1.UpdateChart(false);
                return;
            }
 
            _qhPoints = qhPoints;
            _qePoints = qePoints;
            _qpPoints = qpPoints;
 
            _qhFitType = qhFitType;
            _qeFitType = qeFitType;
            _qpFitType = qpFitType;
 
 
            this.cmbCurveType.Properties.Items.Clear();
            this.cmbCurveType.Properties.Items.Add("流量扬程曲线");
            if (_qePoints != null && _qePoints.Count > 3)
                this.cmbCurveType.Properties.Items.Add("流量效率曲线");
            if (_qpPoints != null && _qpPoints.Count > 3)
                this.cmbCurveType.Properties.Items.Add("流量功率曲线");
            this.cmbCurveType.SelectedIndex = 0;
 
            //默认修改QHcurve
            _editCurveType = Model.eFeatCurveType.QH;
 
            SetBindingData();
            this.featCurvesDispCtrl1.SetFeatCurvePoint(_qhPoints, _qePoints, _qpPoints, _qhFitType, _qeFitType, _qpFitType);
            this.featCurvesDispCtrl1.UpdateChart(true);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void SetBindingData()
        {
            _featCurvePoints.Clear();
            switch (_editCurveType)
            {
                case Model.eFeatCurveType.QH:
                    {
                        foreach (Model.CurvePoint pt in _qhPoints)
                            _featCurvePoints.Add(new Model.CurvePoint(pt.X, pt.Y));
 
                        this.featCurvesDispCtrl1.IsEditCurve(ChartEditLxpCurveCtrl.eEditCurveType.QHcurve);
                    }
                    break;
                case Model.eFeatCurveType.QE:
                    {
 
                        foreach (Model.CurvePoint pt in _qePoints)
                            _featCurvePoints.Add(new Model.CurvePoint(pt.X, pt.Y));
 
                        this.featCurvesDispCtrl1.IsEditCurve(ChartEditLxpCurveCtrl.eEditCurveType.QEcurve);
                    }
                    break;
                case Model.eFeatCurveType.QP:
                    {
 
                        foreach (Model.CurvePoint pt in _qpPoints)
                            _featCurvePoints.Add(new Model.CurvePoint(pt.X, pt.Y));
 
                        this.featCurvesDispCtrl1.IsEditCurve(ChartEditLxpCurveCtrl.eEditCurveType.QPcurve);
                    }
                    break;
            }
            this.bindingSource1.ResetBindings(false);
        }
 
        /// <summary>
        /// 绑定坐标
        /// </summary> 
        public void SetLxpCoordinateParas(Model.CurveCoordinateParas coord)
        {
            this.featCurvesDispCtrl1.CoordinateParas = coord;
        }
 
        /// <summary>
        /// 设置曲线坐标
        /// </summary>
        public void SetCoordinateByDialog()
        {
            this.featCurvesDispCtrl1.SetCoordinateByDialog();
        }
 
        //编辑性能曲线类型修改
        private void cmbCurveType_SelectedIndexChanged(object sender, EventArgs e)
        {
            string curveType = cmbCurveType.SelectedItem.ToString();
            if (string.Equals("流量扬程曲线", curveType))
            {
                _editCurveType = Model.eFeatCurveType.QH;
                featCurvesDispCtrl1.IsEditCurve(ChartEditLxpCurveCtrl.eEditCurveType.QHcurve);
            }
            else if (string.Equals("流量效率曲线", curveType))
            {
                _editCurveType = Model.eFeatCurveType.QE;
                featCurvesDispCtrl1.IsEditCurve(ChartEditLxpCurveCtrl.eEditCurveType.QEcurve);
            }
            else if (string.Equals("流量功率曲线", curveType))
            {
                _editCurveType = Model.eFeatCurveType.QP;
                featCurvesDispCtrl1.IsEditCurve(ChartEditLxpCurveCtrl.eEditCurveType.QPcurve);
            }
            SetBindingData();
        }
 
        //单元格修改后触发
        private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            ReloadChart();
        }
 
        //删除点
        private void DeletePoint()
        {
            var row = this.gridView1.GetFocusedRow() as Model.CurvePoint;
            if (row == null)
                return;
            if (XtraMessageBox.Show("是否删除此点?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes)
                return;
            _featCurvePoints.Remove(row);
            this.bindingSource1.ResetBindings(false);
            UpdateCurveChart(GetCurrentCurvePoints());
        }
 
        //获取当前编辑曲线点
        public List<Model.CurvePoint> GetCurrentCurvePoints()
        {
            var points = new List<Model.CurvePoint>();
            if (_featCurvePoints != null && _featCurvePoints.Any())
            {
                if (_editCurveType == Model.eFeatCurveType.QH && _unitH == Unit.eUnitH.MPa)
                {
                    _featCurvePoints.ForEach(curvePoint =>
                    {
                        var x = Unit.UnitQHelper.Convert(_unitQ, Unit.eUnitQ.M3H, curvePoint.X);
                        var y = 100 * curvePoint.Y;
                        var point = new Model.CurvePoint(x, y);
                        points.Add(point);
                    });
                }
                else
                {
                    _featCurvePoints.ForEach(curvePoint =>
                    {
                        var x = Unit.UnitQHelper.Convert(_unitQ, Unit.eUnitQ.M3H, curvePoint.X);
                        var y = curvePoint.Y;
                        var point = new Model.CurvePoint(x, y);
                        points.Add(point);
                    });
                }
            }
            return points;
        }
 
        //更新图表
        private void UpdateCurveChart(List<Model.CurvePoint> points)
        {
            if (_editCurveType == Model.eFeatCurveType.QH)
            {
                _qhPoints = points;
            }
            else if (_editCurveType == Model.eFeatCurveType.QE)
            {
                _qePoints = points;
            }
            else if (_editCurveType == Model.eFeatCurveType.QP)
            {
                _qpPoints = points;
            }
            this.featCurvesDispCtrl1.SetEditPoint(points);
        }
 
 
        //插入点
        private void InsertPoint()
        {
            var dlg = new Curve.InputXYDialog();
            List<Model.CurvePoint> points = null;
            switch (_editCurveType)
            {
                case Model.eFeatCurveType.QH:
                    {
                        dlg.SetLabelX("Q");
                        dlg.SetLabelY("H");
                        points = _qhPoints;
                    }
                    break;
                case Model.eFeatCurveType.QE:
                    {
                        dlg.SetLabelX("Q");
                        dlg.SetLabelY("E");
                        points = _qePoints;
                    }
                    break;
                case Model.eFeatCurveType.QP:
                    {
                        dlg.SetLabelX("Q");
                        dlg.SetLabelY("P");
                        points = _qpPoints;
                    }
                    break;
            }
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
 
            var curvePoint = new Model.CurvePoint(dlg.X, dlg.Y);
            points.Add(curvePoint);
 
            SetBindingData();
            this.featCurvesDispCtrl1.SetEditPoint(points);
 
        }
 
        //重新计算
        private void ReloadCalcu()
        {
            if (_featCurvePoints == null)
                return;
            bool isFromZero = false;
            if (_qhPoints.Last().X > 20)
            {
                if (_qhPoints.First().X < 1)
                    isFromZero = true;
            }
            else
            {
                if (_qhPoints.First().X < 0.3)
                    isFromZero = true;
            }
            if (_editCurveType == Model.eFeatCurveType.QE)
            {
                _qePoints = LxpFeatCurveHelper.CalculateE_AlignPointP(_qhFitType, _qpFitType, _qhPoints, _qpPoints, IStation.Formula.ConstantParas.WaterDensity, isFromZero);
                this.featCurvesDispCtrl1.SetEditPoint(_qePoints);
            }
            else if (_editCurveType == Model.eFeatCurveType.QP)
            {
 
                double ref_zero_power = -1;
                if (_qpPoints != null && _qePoints.Count > 0)
                {
                    ref_zero_power = _qpPoints.First().Y;
                }
                _qpPoints = LxpFeatCurveHelper.CalculateP_AlignPointE(_qhFitType, _qeFitType, _qhPoints, _qePoints, IStation.Formula.ConstantParas.WaterDensity, ref_zero_power, isFromZero);
                this.featCurvesDispCtrl1.SetEditPoint(_qpPoints);
            }
            SetBindingData();
            this.featCurvesDispCtrl1.UpdateChart(true);
        }
 
        //刷新图表
        private void ReloadChart()
        {
            //更新曲线,暂时有问题,应该P跟着其余曲线变化,暂时未处理
            var points = _featCurvePoints?.Select(x => new Model.CurvePoint(x)).ToList();
            switch (_editCurveType)
            {
                case Model.eFeatCurveType.QH:
                    {
                        _qhPoints = points;
                    }
                    break;
                case Model.eFeatCurveType.QE:
                    {
 
                        _qePoints = points;
                    }
                    break;
                case Model.eFeatCurveType.QP:
                    {
 
                        _qpPoints = points;
                    }
                    break;
            }
            this.featCurvesDispCtrl1.SetEditPoint(points);
        }
 
        //按钮点击事件
        private void buttonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Tag == null)
                return;
            var tag = e.Button.Tag.ToString();
            switch (tag)
            {
                case "Delete": DeletePoint(); break;
                case "InsertPoint": InsertPoint(); break;
                case "ReloadCalcu": ReloadCalcu(); break;
                case "Refresh": ReloadChart(); break;
                case "Extend": XtraMessageBox.Show("待补充"); break;
            }
        }
 
        #region Get
        public bool GetPointListInfo(out List<Model.CurvePoint> pointsQH, out List<Model.CurvePoint> pointsQE, out List<Model.CurvePoint> pointsQP)
        {
            if (_qhPoints != null)
                pointsQH = _qhPoints.ToList();
            else
                pointsQH = null;
 
            if (_qePoints != null)
                pointsQE = _qePoints.ToList();
            else
                pointsQE = null;
 
            if (_qpPoints != null)
                pointsQP = _qpPoints.ToList();
            else
                pointsQP = null;
 
            return true;
        }
        public Model.CurveCoordinateParas GetLxpCoordinateParas()
        {
            return this.featCurvesDispCtrl1.CoordinateParas;
        }
        #endregion
 
 
    }
}