Shuxia Ning
2024-10-14 196635474fdbad173316b0dbeb30e4443b61297b
WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-pump/PumpFullInfoCtrl.cs
@@ -1,4 +1,9 @@
namespace HStation.WinFrmUI
using DevExpress.CodeParser;
using HStation.WinFrmUI.PhartRelation;
using System;
using Yw.WinFrmUI.Phart;
namespace HStation.WinFrmUI
{
    public partial class PumpFullInfoCtrl : DevExpress.XtraEditors.XtraUserControl
    {
@@ -13,10 +18,113 @@
            this.navBarControlPara.ClientSizeChanged += new System.EventHandler(this.NavBarControlPara_ClientSizeChanged);
        }
        private PumpMatchingViewModel _pump_mathing_vm = null;
        public void SetBindingData(PumpMatchingViewModel pumpMatchingViewModel)
        {
            _pump_mathing_vm = pumpMatchingViewModel;
            pumpPropViewCtrl1.SetBindingData(pumpMatchingViewModel.DbId);
            if (long.TryParse(_pump_mathing_vm.DbId,out long pump_mian_id))
            {
                Init(pump_mian_id);
            }
        }
        private async void Init(long pump_main_id)
        {
            var pump_main = await new BLL.AssetsPumpMain().GetByID(pump_main_id);
            if (pump_main == null)
            {
                return;
            }
            var phart_list = await new BLL.XhsPumpMainPhartMappingExtensions().GetByPumpMainID(pump_main_id);
            if (phart_list == null || !phart_list.Any())
            {
                return;
            }
            var phart = phart_list.OrderBy(x => x.Importance).First();
            var diagram = phart.Diagram;
            if (diagram == null)
            {
                return;
            }
            var graph_list = diagram.GraphList;
            if (graph_list == null || !graph_list.Any())
            {
                return;
            }
            var graph_qh = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
            var graph_qe = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
            var graph_qp = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
            if (graph_qh == null)
            {
                return;
            }
            List<Yw.Geometry.Point2d> points_qh = null, points_qe = null, points_qp = null;
            points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 12, null);
            if (graph_qe != null)
                points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 12, null);
            if (graph_qp != null)
                points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 12, null);
            var cubic_spline_qh = new Yw.Geometry.CubicSpline2d(points_qh);
            var cubic_spline_qe = new Yw.Geometry.CubicSpline2d(points_qe);
            var cubic_spline_qp = new Yw.Geometry.CubicSpline2d(points_qp);
            var design_pt = new Yw.Geometry.Point2d();
            design_pt.X = Math.Round(cubic_spline_qh.MaxX / 2);
            design_pt.Y = Math.Round(cubic_spline_qh.GetPointY(design_pt.X), 1);
            var disp_paras = diagram.DispParas;
            var is_calc_disp_paras = string.IsNullOrWhiteSpace(disp_paras);
            this.pumpPerformChart1.SetBindingData(cubic_spline_qh, cubic_spline_qe, cubic_spline_qp, disp_paras, is_calc_disp_paras);
            this.pumpPerformInfoCtrl1.SetDesignPoint(design_pt);
            var vm_vs = new Yw.WinFrmUI.Phart.PumpVariableSpeedViewModel();
            vm_vs.Id = phart.ID.ToString();
            vm_vs.Name = $"{pump_main.RatedSpeed}";
            //vm.IsBp = pump_mian.;
            vm_vs.RatedSpeed = pump_main.RatedSpeed;
            vm_vs.CurrentSpeed = pump_main.RatedSpeed;
            vm_vs.CurrentHz = 50;
            vm_vs.Qh = cubic_spline_qh;
            vm_vs.Qe = cubic_spline_qe;
            vm_vs.Qp = cubic_spline_qp;
            var vm_vs_info = new Yw.WinFrmUI.Phart.PumpVariableSpeedInfoViewModel(vm_vs);
            vm_vs_info.Color = Color.Black;
            vm_vs_info.IsDefault = true;
            this.pumpVariableSpeedInfoCtrl1.SetBindingData(vm_vs_info, design_pt);
            this.pumpVariableSpeedChart1.Add(vm_vs_info, design_pt);
            var vm_sp = new Yw.WinFrmUI.Phart.PumpSerialParallelViewModel();
            vm_sp.Id = phart.ID.ToString();
            vm_sp.Name = $"{pump_main.RatedSpeed}";
            //vm.IsBp = pump_mian.;
            vm_sp.RatedSpeed = pump_main.RatedSpeed;
            vm_sp.CurrentSpeed = pump_main.RatedSpeed;
            vm_sp.CurrentHz = 50;
            vm_sp.Qh = cubic_spline_qh;
            vm_sp.Qe = cubic_spline_qe;
            vm_sp.Qp = cubic_spline_qp;
            var vm_sp_info = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel(vm_sp);
            vm_sp_info.Color = GetRandomColor(0);
            this.pumpSingleSerialParallelInfoCtrl1.SetBindingData(vm_sp_info, design_pt);
            this.pumpSerialParallelChart1.Add(vm_sp_info, design_pt);
        }
        private void OnFrmLoad(object sender, EventArgs e)
        {
@@ -51,7 +159,403 @@
            //else if (this._m3dDispCtrlType == Model.e3dDispCtrlType.CAD_51JM)
            //{
            //}
            InitChart();
        }
        private void SetChart(PumpMatchingViewModel vm)
        {
            if (vm == null)
            {
                return;
            }
        }
        private void InitChart()
        {
            #region 曲线
            this.pumpPerformInfoCtrl1.SetDesignPointEvent += (q, h) =>
            {
                this.pumpPerformChart1.CalcDesignPointByQ(q, h);
            };
            this.pumpPerformChart1.OnCalcQueryPoint += (gropu_pt) =>
            {
                var vm_list = new List<Yw.WinFrmUI.Phart.PumpPointItmeViewModel>();
                vm_list.Add(new Yw.WinFrmUI.Phart.PumpPointItmeViewModel()
                {
                    Group = "查询点",
                    Name = "流量",
                    Value = $"{gropu_pt.Q:N1}",
                    Unit = "m³/h"
                });
                vm_list.Add(new Yw.WinFrmUI.Phart.PumpPointItmeViewModel()
                {
                    Group = "查询点",
                    Name = "扬程",
                    Value = $"{gropu_pt.H:N1}",
                    Unit = "m"
                });
                vm_list.Add(new Yw.WinFrmUI.Phart.PumpPointItmeViewModel()
                {
                    Group = "查询点",
                    Name = "效率",
                    Value = $"{gropu_pt.E:N1}",
                    Unit = "%"
                });
                vm_list.Add(new Yw.WinFrmUI.Phart.PumpPointItmeViewModel()
                {
                    Group = "查询点",
                    Name = "功率",
                    Value = $"{gropu_pt.P:N1}",
                    Unit = "kW"
                });
                this.pumpPerformInfoCtrl1.SetBindingData(vm_list);
            };
            #endregion
            #region 变速曲线
            this.pumpVariableSpeedInfoCtrl1.SetEvent += (id, qh, qe, qp) =>
            {
                this.pumpVariableSpeedChart1.Set(id, qh, qe, qp);
                ResetSectPointGrid();
            };
            this.pumpVariableSpeedInfoCtrl1.SetInfoEvent += (id, name, color) =>
            {
                this.pumpVariableSpeedChart1.SetInfo(id, name, color);
                ResetSectPointGrid();
            };
            this.pumpVariableSpeedChart1.AddBySpeedEvent += () =>
            {
                AddBySpeed();
                ResetSectPointGrid();
            };
            this.pumpVariableSpeedChart1.AddByHzEvent += () =>
            {
                AddByHz();
                ResetSectPointGrid();
            };
            this.pumpVariableSpeedChart1.AddByPointEvent += () =>
            {
                AddByPoint();
                ResetSectPointGrid();
            };
            this.pumpVariableSpeedInfoCtrl1.SetDesignPointEvent += (q, h) =>
            {
                this.pumpVariableSpeedChart1.SetDesignPt(new Yw.Geometry.Point2d(q, h));
                ResetSectPointGrid();
            };
            this.pumpVariableSpeedChart1.OnCalcQueryPoint += (id, pt) =>
            {
                this.pumpVariableSpeedInfoCtrl1.SetQueryInfo(id, pt);
            };
            void ResetSectPointGrid()
            {
                var vm_list = this.pumpVariableSpeedChart1.GetList();
                this.pumpVariableSpeedInfoCtrl1.SetSectPoint(vm_list);
            }
            void AddBySpeed()
            {
                var list = this.pumpVariableSpeedInfoCtrl1.GetList();
                if (list == null || list.Count < 1)
                {
                    return;
                }
                var design_pt = this.pumpVariableSpeedInfoCtrl1.GetDesignPoint();
                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 = this.pumpVariableSpeedChart1.LineNameShowHz ? hz.ToString() : speed.ToString();
                    vm.Color = GetRandomColor(index);
                    vm.CurrentHz = hz;
                    vm.CurrentSpeed = speed;
                    vm.Calc();
                    this.pumpVariableSpeedInfoCtrl1.Add(vm);
                    this.pumpVariableSpeedChart1.Add(vm, design_pt);
                    return true;
                };
                dlg.ShowDialog();
            }
            void AddByHz()
            {
                var list = this.pumpVariableSpeedInfoCtrl1.GetList();
                if (list == null || list.Count < 1)
                {
                    return;
                }
                var design_pt = this.pumpVariableSpeedInfoCtrl1.GetDesignPoint();
                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 = this.pumpVariableSpeedChart1.LineNameShowHz ? hz.ToString() : speed.ToString();
                    vm.Color = GetRandomColor(index);
                    vm.CurrentHz = hz;
                    vm.CurrentSpeed = speed;
                    vm.Calc();
                    this.pumpVariableSpeedInfoCtrl1.Add(vm);
                    this.pumpVariableSpeedChart1.Add(vm, design_pt);
                    return true;
                };
                dlg.ShowDialog();
            }
            void AddByPoint()
            {
                var list = this.pumpVariableSpeedInfoCtrl1.GetList();
                if (list == null || list.Count < 1)
                {
                    return;
                }
                var index = list.Count;
                var vm_def = list.First();
                var design_pt = this.pumpVariableSpeedInfoCtrl1.GetDesignPoint();
                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 = this.pumpVariableSpeedChart1.LineNameShowHz ? hz.ToString() : speed.ToString();
                    vm.Color = GetRandomColor(index);
                    vm.CurrentHz = hz;
                    vm.CurrentSpeed = speed;
                    vm.Calc();
                    this.pumpVariableSpeedInfoCtrl1.Add(vm);
                    this.pumpVariableSpeedChart1.Add(vm, design_pt);
                    return true;
                };
                dlg.ShowDialog();
            }
            #endregion
            #region 串并联曲线
            string _serial_parallel_id = "serial_parallel";
            this.pumpSingleSerialParallelInfoCtrl1.SetEvent += (id, design_pt, is_parallel, qh, qe, qp) =>
            {
                this.pumpSerialParallelChart1.Set(id, qh, qe, qp);
                var list = this.pumpSingleSerialParallelInfoCtrl1.GetList();
                SetSerialParallel(list, design_pt, is_parallel);
            };
            this.pumpSingleSerialParallelInfoCtrl1.SetInfoEvent += (id, name, color) =>
            {
                this.pumpSerialParallelChart1.SetInfo(id, name, color);
            };
            this.pumpSingleSerialParallelInfoCtrl1.SetDesignPointEvent += (q, h) =>
            {
                this.pumpSerialParallelChart1.SetDesignPt(new Yw.Geometry.Point2d(q, h));
            };
            this.pumpSingleSerialParallelInfoCtrl1.ResetEvent += (type, count) =>
            {
                if (count<1)
                {
                    return;
                }
                var is_parallel = type == 0;
                var list = this.pumpSingleSerialParallelInfoCtrl1.GetList();
                var first = list.First();
                var new_list = new List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel>();
                for (int i = 0; i <count; i++)
                {
                    var vm = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel(first);
                    vm.Id = Guid.NewGuid().ToString();
                    vm.Color = GetRandomColor(i);
                    vm.CurrentSpeed = vm.RatedSpeed;
                    vm.CurrentHz = 50;
                    vm.Calc();
                    new_list.Add(vm);
                }
                var design_pt = this.pumpSingleSerialParallelInfoCtrl1.GetDesignPoint();
                this.pumpSingleSerialParallelInfoCtrl1.SetBindingData(new_list,design_pt);
                this.pumpSerialParallelChart1.Add(new_list, design_pt);
                SetSerialParallel(new_list, design_pt, is_parallel);
            };
            this.pumpSerialParallelChart1.OnCalcQueryPoint += (id, pt) =>
            {
                this.pumpSingleSerialParallelInfoCtrl1.SetQueryInfo(id, pt);
            };
            string SetSerialParallel(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list, Yw.Geometry.Point2d design_pt, bool is_parallel)
            {
                this.pumpSerialParallelChart1.Delete(_serial_parallel_id);
                if (list == null || !list.Any())
                {
                    return "无数据!";
                }
                if (list.Count<2)
                {
                    return "数据过少!";
                }
                var vm_serial_parallel = CalcSerialParallel(list, is_parallel);
                if (vm_serial_parallel == null)
                {
                    return "无法计算串并联曲线!";
                }
                var qh = vm_serial_parallel.Qh;
                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 Yw.Geometry.Point2d(design_q, design_h);
                //    this.pumpSingleSerialParallelInfoCtrl1.SetDesignPoint(design_pt);
                //}
                this.pumpSerialParallelChart1.Add(vm_serial_parallel, design_pt);
                return string.Empty;
            }
            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.Qh = new Yw.Geometry.CubicSpline2d(calc_pt_qh_list);
                vm_sp.Qe = new Yw.Geometry.CubicSpline2d(calc_pt_qe_list);
                vm_sp.Qp = new Yw.Geometry.CubicSpline2d(calc_pt_qp_list);
                vm_sp.QhCalc = vm_sp.Qh;
                vm_sp.QeCalc = vm_sp.Qe;
                vm_sp.QpCalc = vm_sp.Qp;
                vm_sp.Color = Color.Black;
                vm_sp.IsBp = true;
                vm_sp.IsDefault = true;
                return vm_sp;
            }
            #endregion
        }
        #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
        #region 走马灯提示
@@ -134,6 +638,8 @@
        }
        #endregion 走马灯提示
        public void CloseFrm()
        {
@@ -264,44 +770,44 @@
        private void CalcBarHeight()
        {
            if (!navBarGroupPoint.Expanded)
                return;
            //if (!navBarGroupPoint.Expanded)
            //    return;
            int GroupTitleHeight = 55;//头部高度
            //int GroupTitleHeight = 55;//头部高度
            var height = this.Size.Height - 18;//18 : TAB 头部高度
            //var height = this.Size.Height - 18;//18 : TAB 头部高度
            if (navBarGroupPara.Expanded)
            {
                var grp_height = CalcGroupParaHeight();
                //if (row_count == 7)
                //{
                //    grp_height = 280;
                //}
                this.navBarGroupControlXPumpParas.Height = grp_height;
                this.navBarGroupPara.Expanded = true;
                this.navBarGroupPara.GroupClientHeight = grp_height;
                height = height - GroupTitleHeight - grp_height - 3;
            }
            else
            {
                height = height - GroupTitleHeight;
            }
            //if (navBarGroupPara.Expanded)
            //{
            //    var grp_height = CalcGroupParaHeight();
            //    //if (row_count == 7)
            //    //{
            //    //    grp_height = 280;
            //    //}
            //    this.navBarGroupControlXPumpParas.Height = grp_height;
            //    this.navBarGroupPara.Expanded = true;
            //    this.navBarGroupPara.GroupClientHeight = grp_height;
            //    height = height - GroupTitleHeight - grp_height - 3;
            //}
            //else
            //{
            //    height = height - GroupTitleHeight;
            //}
            if (navBarGroupJieZhi.Expanded)
            {
                height = height - 150;
            }
            else
            {
                height = height - GroupTitleHeight;
            }
            //if (navBarGroupJieZhi.Expanded)
            //{
            //    height = height - 150;
            //}
            //else
            //{
            //    height = height - GroupTitleHeight;
            //}
            if (height > 100)
            {//294, 393
                height = height - GroupTitleHeight;
                navBarGroupPoint.GroupClientHeight = height;
            }
            //if (height > 100)
            //{//294, 393
            //    height = height - GroupTitleHeight;
            //    navBarGroupPoint.GroupClientHeight = height;
            //}
        }
        #endregion 计算展示面板高度