Shuxia Ning
2025-01-17 a0bce3b366451b3ca94e676eb98dd7b415375c14
WinFrmUI/HStation.WinFrmUI.PhartRelation.Core/01-pump/01-view/PumpChartViewCtrl.cs
@@ -1,5 +1,4 @@
using DevExpress.Spreadsheet;
using Mapster;
using StackExchange.Profiling.Internal;
using Yw.Ahart;
using Yw.Geometry;
@@ -8,21 +7,23 @@
namespace HStation.WinFrmUI
{
    /// <summary>
    /// 待整理 抽象到底层
    /// </summary>
    public partial class PumpChartViewCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public PumpChartViewCtrl()
        {
            InitializeComponent();
            this.barCekEqVisible.Checked = true;
            this.barCekEqulEffVisible.Checked = true;
            this.barCekPowerVisible.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.barCekEqVisible.Checked = true;
            this.barCekEqVisible.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.barBtnAddVariableSpeedMenu.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.barBtnAddEqualEffMenu.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.barCekEqulEffVisible.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.pumpViewChart1.AnnotationChangedEvent += PumpViewChart1_AnnotationChangedEvent;
        }
        private Yw.Vmo.PhartDiagramExGraphListVmo _vmo = null;
        private List<Yw.WinFrmUI.Phart.PumpViewChartViewModel> _vm_list = null;
@@ -32,7 +33,7 @@
        private bool _eff_visible = true;
        private bool _equal_eff_visible = true;
        private bool _split_panel = true;
        private double _nr;
        private double _nr;
        /// <summary>
        /// 绑定数据
@@ -55,12 +56,14 @@
                ClearBindingData();
                return;
            }
            _coordinate = vmo.DispParas;
            _coordinate = vmo.DispParas;
            foreach (var graph in vmo.GraphList)
            {
                bool is_default = false;
                double hz = 50;
                double n = nr;
                double eff = -1;
                var curve_type = (Yw.Ahart.eCurveType)graph.GraphType;
                switch (curve_type)
                {
@@ -69,6 +72,8 @@
                            var paras = PhartGraphHelper.GetGraphParas<Yw.WinFrmUI.Phart.QHGraphParasViewModel>(curve_type, graph.GraphParas);
                            hz = paras.Hz;
                            n = paras.N;
                            if (hz == 50)
                                is_default = true;
                        }
                        break;
                    case Yw.Ahart.eCurveType.QP:
@@ -76,6 +81,8 @@
                            var paras = PhartGraphHelper.GetGraphParas<Yw.WinFrmUI.Phart.QPGraphParasViewModel>(curve_type, graph.GraphParas);
                            hz = paras.Hz;
                            n = paras.N;
                            if (hz == 50)
                                is_default = true;
                        }
                        break;
                    case Yw.Ahart.eCurveType.QE:
@@ -83,6 +90,14 @@
                            var paras = PhartGraphHelper.GetGraphParas<Yw.WinFrmUI.Phart.QEGraphParasViewModel>(curve_type, graph.GraphParas);
                            hz = paras.Hz;
                            n = paras.N;
                            if (hz == 50)
                                is_default = true;
                        }
                        break;
                    case Yw.Ahart.eCurveType.EqualE:
                        {
                            var paras = PhartGraphHelper.GetGraphParas<EqualEGraphParasViewModel>(curve_type, graph.GraphParas);
                            eff = paras.Eff;
                        }
                        break;
                }
@@ -92,28 +107,44 @@
                var annotation_list = PhartGraphHelper.GetAnnotationParasList(curve_type, graph.AnnotationParas);
                if (curve_type == eCurveType.QE)
                    annotation_list = null;
                    var vm = new Yw.WinFrmUI.Phart.PumpViewChartViewModel();
                var vm = new Yw.WinFrmUI.Phart.PumpViewChartViewModel();
                vm.Id = graph.ID.ToString();
                vm.DbId = graph.ID;
                vm.Hz = hz;
                vm.N = n;
                vm.Eff = eff;
                vm.AnnotationList = annotation_list;
                vm.CurveType = feat_curve.CurveType;
                vm.FeatType = feat_curve.FeatType;
                vm.DefPointList = geometry_paras?.DefinePoints;
                vm.FitPointList = feat_curve.FeatCurve.GetPointList(100);
                if (vm.CurveType== eCurveType.EqualE)
                if (vm.CurveType == eCurveType.EqualE)
                    vm.FitPointList = feat_curve.FeatCurve.GetPointList(10);
                vm.IsDefault = is_default;
                vm.GraphParas = graph.GraphParas;
                vm_list.Add(vm);
            }
            _vm_list = vm_list;
            _vm_list[0].IsSelect = true;
            var list = _vm_list.Select(x => x.Hz).OrderByDescending(x => x).ToList();
            list = list.Distinct().ToList();
            this.repImgCmbCurveSel.BeginInit();
            this.repImgCmbCurveSel.Items.Clear();
            this.repImgCmbCurveSel.Items.Add($"无", null, -1);
            foreach (var hz in list)
            {
                this.repImgCmbCurveSel.Items.Add($"{hz}hz", hz, -1);
            }
            this.repImgCmbCurveSel.EndInit();
            this.barImgCmbChartSel.EditValue = null;
            SetColor(_vm_list);
            SetBindingData(_vm_list, _coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
            SetBindingData(_vm_list, _coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
        }
        /// <summary>
        /// 
@@ -136,9 +167,11 @@
                            vm.Color = Color.DarkGreen;
                    }
                }
            }
            else
            {
                var item = group.ElementAt(0);
                foreach (var vm in item)
                {
@@ -147,11 +180,16 @@
                        case Yw.Ahart.eCurveType.QH: vm.Color = Yw.WinFrmUI.Phart.PumpChartDisplay.CurveColorQH; break;
                        case Yw.Ahart.eCurveType.QP: vm.Color = Yw.WinFrmUI.Phart.PumpChartDisplay.CurveColorQP; break;
                        case Yw.Ahart.eCurveType.QE: vm.Color = Yw.WinFrmUI.Phart.PumpChartDisplay.CurveColorQE; break;
                        case Yw.Ahart.eCurveType.EqualE: vm.Color = Color.DarkGreen; break;
                    }
                }
                }
            }
        }
        /// <summary>
        /// 绑定数据
        /// </summary>
@@ -200,10 +238,12 @@
        {
            if (_vm_list == null || !_vm_list.Any())
            {
                TipFormHelper.ShowInfo("无数据");
                return true;
            }
            if (!_vm_list.Exists(x => x.CurveType == Yw.Ahart.eCurveType.QH))
            {
                TipFormHelper.ShowInfo("无数据");
                return true;
            }
            return false;
@@ -216,7 +256,6 @@
        {
            this.pumpViewChart1.Clear();
        }
        private void SetEquip()
        {
@@ -266,22 +305,68 @@
            this.pumpViewChart1.SetEquip(equip_pt_list, pump_sect_pt);
        }
        private void PumpViewChart1_AnnotationChangedEvent((long DbId, string Tag, double X, double Y) info)
        {
            Update(info);
        }
        private void barImgCmbChartSel_EditValueChanged(object sender, EventArgs e)
        {
            if (this.barImgCmbChartSel.EditValue==null)
            {
                this.pumpViewChart1.LineVisible = false;
                return;
            }
            var hz = Convert.ToDouble(this.barImgCmbChartSel.EditValue);
            _vm_list.ForEach(x => x.IsSelect = false);
            foreach (var vm in _vm_list)
            {
                if (vm.Hz != hz)
                    continue;
                switch (vm.CurveType)
                {
                    case Yw.Ahart.eCurveType.QH:
                        {
                            vm.IsSelect = true;
                        }
                        break;
                    case Yw.Ahart.eCurveType.QP:
                        {
                            vm.IsSelect = true;
                        }
                        break;
                    case Yw.Ahart.eCurveType.QE:
                        {
                            vm.IsSelect = true;
                        }
                        break;
                }
            }
            SetBindingData(_vm_list, _coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
            this.pumpViewChart1.SetAxisXValue();
            this.pumpViewChart1.LineVisible = true;
        }
        private void barCekLineVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
           // this.pumpViewChart1.LineVisible=this.barCekLineVisible.Checked;
        }
        private void barCekEffVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _eff_visible = this.barCekEffVisible.Checked;
            SetBindingData(_vm_list,_coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
            SetBindingData(_vm_list, _coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
        }
        private void barCekPowerVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _power_visible = this.barCekPowerVisible.Checked;
            SetBindingData(_vm_list,_coordinate, _split_panel,  _eff_visible, _power_visible, _equal_eff_visible);
            SetBindingData(_vm_list, _coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
        }
        private void barCekSplitPanel_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _split_panel = this.barCekSplitPanel.Checked;
            SetBindingData(_vm_list,_coordinate, _split_panel,  _eff_visible, _power_visible, _equal_eff_visible);
            SetBindingData(_vm_list, _coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
        }
        private void barCekEqVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
@@ -292,14 +377,14 @@
            }
            else
            {
                this.pumpViewChart1.SetEquip(null,null);
                this.pumpViewChart1.SetEquip(null, null);
            }
        }
        private void barCekEqulEffVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _equal_eff_visible = this.barCekEqulEffVisible.Checked;
            SetBindingData(_vm_list,_coordinate, _split_panel,  _eff_visible, _power_visible, _equal_eff_visible);
            SetBindingData(_vm_list, _coordinate, _split_panel, _eff_visible, _power_visible, _equal_eff_visible);
        }
        private void barBtnEqClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
@@ -307,7 +392,6 @@
            this.barTxtStartHead.EditValue = 0;
            this.barTxtPipeQ.EditValue = null;
            this.barTxtPipeHead.EditValue = null;
            this.pumpViewChart1.SetEquip(null, null);
        }
@@ -336,6 +420,55 @@
            AddByEff();
        }
        private void barBtnDeleteVariableSpeed_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (IsInvalidData())
            {
                return;
            }
            if (!_vm_list.Exists(x => x.Hz != 50))
            {
                TipFormHelper.ShowInfo("无变速线");
                return;
            }
            var list = _vm_list.Where(x => x.Hz != 50).Select(x => (x.Hz, x.N)).ToList();
            var dlg = new DeleteVariableSpeedDlg();
            dlg.SetBindingData(list);
            dlg.ReloadDataEvent += (del_list) =>
            {
                var del_info_list = _vm_list.Where(x => del_list.Contains(x.Hz)).Select(x => (x.DbId, x.Hz)).ToList();
                Delete(del_info_list);
                return true;
            };
            dlg.ShowDialog();
        }
        private void barBtnDeleteEqualEff_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (IsInvalidData())
            {
                return;
            }
            if (!_vm_list.Exists(x => x.CurveType == eCurveType.EqualE))
            {
                TipFormHelper.ShowInfo("无等效线");
                return;
            }
            var _vm_eff_list = _vm_list.Where(x => x.CurveType == eCurveType.EqualE).ToList();
            var list = _vm_eff_list.Select(x => x.Eff).ToList();
            var dlg = new DeleteEqualEDlg();
            dlg.SetBindingData(list);
            dlg.ReloadDataEvent += (del_list) =>
            {
                var del_info_list = _vm_eff_list.Where(x => del_list.Contains(x.Eff)).Select(x => (x.DbId, x.Eff)).ToList();
                Delete(del_info_list);
                return true;
            };
            dlg.ShowDialog();
        }
        private void AddByN()
        {
            if (IsInvalidData())
@@ -360,13 +493,13 @@
                    TipFormHelper.ShowWarn("转速已存在");
                    return false;
                }
                hz = Math.Round(hz, 1);
                hz = Math.Round(hz, 1);
                var pt_qh_list = qh50.FitPointList.GetQHPointListByN(50, hz);
                var pt_qe_list = qe50?.FitPointList?.GetQEPointListByN(50, hz);
                var pt_qp_list = qp50?.FitPointList?.GetQPPointListByN(50, hz);
                Insert(hz,speed,pt_qh_list,pt_qe_list,pt_qp_list);
                Insert(hz, speed, pt_qh_list, pt_qe_list, pt_qp_list);
                return true;
            };
            dlg.ShowDialog();
@@ -397,13 +530,13 @@
                }
                var speed = Math.Round(hz / 50 * _nr);
                speed = Math.Round(speed, 1);
                var pt_qh_list = qh50.FitPointList.GetQHPointListByN(50, hz);
                var pt_qe_list = qe50?.FitPointList?.GetQEPointListByN(50, hz);
                var pt_qp_list = qp50?.FitPointList?.GetQPPointListByN(50, hz);
                var pt_qp_list = qp50?.FitPointList?.GetQPPointListByN(50, hz);
                Insert(hz, speed, pt_qh_list, pt_qe_list, pt_qp_list);
                Insert(hz, speed, pt_qh_list, pt_qe_list, pt_qp_list);
                return true;
            };
            dlg.ShowDialog();
@@ -425,7 +558,7 @@
            dlg.VerifyValueChanged += (x, y) =>
            {
                var pt = new Yw.Geometry.Point2d(x, y);
                var curve = new Yw.Pump. CurveQH(qh50.FeatType, qh50.DefPointList);
                var curve = new Yw.Pump.CurveQH(qh50.FeatType, qh50.DefPointList);
                var sect_pt = Yw.Pump.PerformParabolaHelper.GetQHSectPoint(curve, pt);
                if (sect_pt == null || sect_pt.IsZeroPoint())
                    return false;
@@ -478,25 +611,29 @@
                foreach (var eff in eff_double_list)
                {
                    if (_vm_list.Exists(x => x.Eff == eff))
                    {
                        continue;
                    }
                    var eff_list = EqualParaCurveEListHelper.CalcEqualParaCurveE(qh, qe, max_hz, min_hz, eff);
                    if (eff_list != null && eff_list.Any())
                    {
                        foreach (var item in eff_list)
                        {
                            Insert(item.Eff,item.Tension,item.IsClosed,item.IsUShaped,item.DefinePoints);
                        {
                            Insert(item.Eff, item.Tension, item.IsClosed, item.IsUShaped, item.DefinePoints);
                        }
                    }
                }
                return true;
            };
            dlg.ShowDialog();
        }
        private async void Insert(double hz, double speed, List<Yw.Geometry.Point2d> pt_qh_list, List<Yw.Geometry.Point2d> pt_qe_list, List<Yw.Geometry.Point2d> pt_qp_list)
        {
        {
            var list = new List<Yw.Vmo.PhartGraphVmo>();
            var graph_qh = new Yw.Vmo.PhartGraphVmo()
            {
@@ -591,7 +728,7 @@
                list.Add(graph_qp);
            }
            list.ForEach(x => x.DiagramID = _vmo.ID);
            var bol = await new Yw.BLL.PhartGraph().Inserts(list);
            if (!bol)
@@ -599,7 +736,7 @@
                TipFormHelper.ShowWarn("添加失败!");
                return;
            }
            var newVmo = await new Yw.BLL.PhartDiagramExtensions().GetByID(_vmo.ID);
            if (newVmo == null)
            {
@@ -611,9 +748,9 @@
            SetEquip();
        }
        private async void Insert(double eff, double tension, bool is_closed,bool is_u, List<Yw.Geometry.Point2d> pt_equal_e_list)
        private async void Insert(double eff, double tension, bool is_closed, bool is_u, List<Yw.Geometry.Point2d> pt_equal_e_list)
        {
            if (tension<=0)
            if (tension <= 0)
            {
                tension = 0.5;
            }
@@ -634,7 +771,7 @@
                }.ToJson(),
                GeometryStyle = (int)HStation.PhartRelation.eGeometryStyle.FeatCurve,
                GeometryInfo = pt_equal_e_list.ToDbString(Yw.Ahart.eCurveType.EqualE, Yw.Ahart.eFeatType.Cubic),
            };
            var annotation_list = new List<Yw.WinFrmUI.Phart.AnnotationParasViewModel>();
@@ -677,6 +814,73 @@
            SetEquip();
        }
        private async void Update((long DbId, string Tag, double X, double Y) info)
        {
            var bll = new Yw.BLL.PhartGraph();
            var vm = _vm_list.Find(x => x.DbId == info.DbId);
            if (vm == null)
                return;
            var annotation = vm.AnnotationList.Find(x => x.Tag == info.Tag);
            if (annotation == null)
                return;
            annotation.X = info.X;
            annotation.Y = info.Y;
            var paras = vm.AnnotationList.ToJson();
            var bol = await bll.UpdateAnnotationParas(info.DbId, paras);
            if (!bol)
            {
                TipFormHelper.ShowError($"{annotation.Text}更新失败!");
                return;
            }
            //var newVmo = await new Yw.BLL.PhartDiagramExtensions().GetByID(_vmo.ID);
            //if (newVmo == null)
            //{
            //    TipFormHelper.ShowWarn("获取失败!");
            //    return;
            //}
            //SetBindingData(newVmo, _nr);
            //SetEquip();
        }
        private async void Delete(List<(long Id, double Basis)> graph_ids)
        {
            if (graph_ids == null || !graph_ids.Any())
            {
                return;
            }
            var bll = new Yw.BLL.PhartGraph();
            var err_hz_list = new List<double>();
            foreach (var graph_info in graph_ids)
            {
                var bol = await bll.DeleteByID(graph_info.Id);
                if (!bol)
                {
                    err_hz_list.Add(graph_info.Basis);
                    continue;
                }
            }
            if (err_hz_list != null && err_hz_list.Any())
            {
                var info = Yw.Untity.DoubleListHelper.ToString(err_hz_list);
                TipFormHelper.ShowError($"{info}删除失败!");
            }
            var newVmo = await new Yw.BLL.PhartDiagramExtensions().GetByID(_vmo.ID);
            if (newVmo == null)
            {
                TipFormHelper.ShowWarn("获取失败!");
                return;
            }
            SetBindingData(newVmo, _nr);
            SetEquip();
        }
        /// <summary>
        /// 获取
        /// </summary> 
@@ -685,6 +889,6 @@
            return new Yw.Vmo.PhartDiagramExGraphListVmo();
        }
    }
}