lixiaojun
2024-12-02 f54adb8f368def21b9aa01e466b09bed6cd8347c
WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/11-pump/01-parallel/SimulationPumpParallelCtrl.cs
@@ -9,6 +9,9 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Yw.Geometry;
using Yw.Pump;
using Yw.WinFrmUI.Phart;
namespace HStation.WinFrmUI
{
@@ -19,12 +22,21 @@
            InitializeComponent();
            this.layoutControl1.SetupLayoutControl();
            this.hydroPumpListExtendGridCtrl1.StateChangedEvent += HydroPumpListExtendGridCtrl1_StateChangedEvent;
            this.pumpParallelChart1.DesignPointChangedEvent += PumpParallelChart1_DesignPointChangedEvent;
            this.pumpParallelChart1.QueryPointChangedEvent += PumpParallelChart1_QueryPointChangedEvent;
            this.pumpParallelChart1.ParallelStatusChangedEvent += PumpParallelChart1_ParallelStatusChangedEvent;
        }
        /// <summary>
        /// 保存事件
        /// </summary>
        public event Action<List<SimulationPumpParallelSaveItemViewModel>> SaveEvent;
        /// <summary>
        /// 并联状态改变事件
        /// </summary>
        public event Action<bool, string> ParallelStatusChangedEvent;
        /// <summary>
        /// 绑定列表
@@ -32,12 +44,16 @@
        public void SetBindingData(Yw.Model.HydroModelInfo hydroInfo)
        {
            this.hydroPumpListExtendGridCtrl1.SetBindingData(hydroInfo);
            var allStateList = this.hydroPumpListExtendGridCtrl1.GetStateList();
            var allVmList = CreateParallelViewModels(allStateList);
            this.pumpParallelChart1.SetBindingData(allVmList);
        }
        //状态改变事件
        private void HydroPumpListExtendGridCtrl1_StateChangedEvent(List<HydroPumpListItemExtendViewModel> allPumpStateList)
        private void HydroPumpListExtendGridCtrl1_StateChangedEvent(List<HydroPumpListItemExtendViewModel> allStateList)
        {
            var allVmList = CreateParallelViewModels(allStateList);
            this.pumpParallelChart1.SetBindingData(allVmList);
        }
        //保存
@@ -62,6 +78,145 @@
            this.SaveEvent?.Invoke(allSaveList);
        }
        //创建
        private List<PumpParallelViewModel> CreateParallelViewModels(List<HydroPumpListItemExtendViewModel> allStateList)
        {
            var allRunList = allStateList?.Where(x => x.RunStatus).ToList();
            if (allRunList == null || allRunList.Count < 1)
            {
                return default;
            }
            var vmList = new List<PumpParallelViewModel>();
            foreach (var item in allRunList)
            {
                var vm = new PumpParallelViewModel();
                vm.Id = item.Code;
                vm.Name = item.Name;
                vm.RatedQ = item.Vmo.RatedQ.HasValue ? item.Vmo.RatedQ.Value : 0;
                vm.RatedH = item.Vmo.RatedH.HasValue ? item.Vmo.RatedH.Value : 0;
                vm.RatedP = item.Vmo.RatedP;
                vm.RatedN = item.Vmo.RatedN.HasValue ? item.Vmo.RatedN.Value : 0;
                vm.RatedHz = item.Vmo.RatedHz;
                vm.CurrentHz = item.Hz;
                vm.CurrentN = Math.Round(item.Hz / item.Vmo.RatedHz * vm.RatedN, 1);
                vm.CurrentColor = item.Color;
                double extend = 1;
                var curveqh = item.HydroInfo.Curves?.Find(x => x.Code == item.Vmo.CurveQH);
                if (curveqh != null)
                {
                    var qh_pts = curveqh.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                    if (qh_pts != null && qh_pts.Count > 3)
                    {
                        vm.CurveQH = new CubicSpline2d(qh_pts);
                        var qh_current_pts = qh_pts.GetQHPointListByN(item.Vmo.RatedHz, item.Hz);
                        vm.CurrentCurveQH = new CubicSpline2d(qh_current_pts);
                        if (item.Extend > 100)
                        {
                            vm.CurrentExtendFlow = vm.CurrentCurveQH.MaxX;
                            extend = item.Extend / 100;
                            var qh_current_extend_pts = vm.CurrentCurveQH.GetPointListByXRatioRange(1, extend, 20);
                            vm.CurrentCurveQH = new CubicSpline2d(qh_current_extend_pts);
                        }
                    }
                }
                var curveqp = item.HydroInfo.Curves?.Find(x => x.Code == item.Vmo.CurveQP);
                if (curveqp != null)
                {
                    var qppts = curveqp.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                    if (qppts != null && qppts.Count > 3)
                    {
                        vm.CurveQP = new CubicSpline2d(qppts);
                        var sqppts = qppts.GetQHPointListByN(item.Vmo.RatedHz, item.Hz);
                        vm.CurrentCurveQP = new CubicSpline2d(sqppts);
                        if (extend > 1)
                        {
                            var qp_current_extend_pts = vm.CurrentCurveQP.GetPointListByXRatioRange(1, extend, 20);
                            vm.CurrentCurveQP = new CubicSpline2d(qp_current_extend_pts);
                        }
                    }
                }
                var curveqe = item.HydroInfo.Curves?.Find(x => x.Code == item.Vmo.CurveQE);
                if (curveqe != null)
                {
                    var qepts = curveqe.CurveData?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
                    if (qepts != null && qepts.Count > 3)
                    {
                        vm.CurveQE = new CubicSpline2d(qepts);
                        var sqepts = qepts.GetQHPointListByN(item.Vmo.RatedHz, item.Hz);
                        vm.CurrentCurveQE = new CubicSpline2d(sqepts);
                        if (extend > 1)
                        {
                            var qe_current_extend_pts = vm.CurrentCurveQE.GetPointListByXRatioRange(1, extend, 20);
                            vm.CurrentCurveQE = new CubicSpline2d(qe_current_extend_pts);
                        }
                    }
                }
                vmList.Add(vm);
            }
            return vmList;
        }
        //设计点改变
        private void PumpParallelChart1_DesignPointChangedEvent(List<PumpDesignPointViewModel> obj)
        {
            var vmList = obj?.Select(x => new HydroPumpDesignPointViewModel()
            {
                Code = x.Id,
                Name = x.Name,
                DesignQ = Math.Round(x.Q, 1),
                DesignH = Math.Round(x.H, 2),
                DesignP = x.P.HasValue ? Math.Round(x.P.Value, 1) : null,
                DesignE = x.E.HasValue ? Math.Round(x.E.Value, 1) : null,
            }).ToList();
            this.hydroPumpDesignPointListGridCtrl1.SetBindingData(vmList);
        }
        //查询点改变
        private void PumpParallelChart1_QueryPointChangedEvent(List<PumpQueryPointViewModel> obj)
        {
            var vmList = obj?.Select(x => new HydroPumpQueryPointViewModel()
            {
                Code = x.Id,
                Name = x.Name,
                QueryQ = Math.Round(x.Q, 1),
                QueryH = Math.Round(x.H, 2),
                QueryP = x.P.HasValue ? Math.Round(x.P.Value, 1) : null,
                QueryE = x.E.HasValue ? Math.Round(x.E.Value, 1) : null,
            }).ToList();
            this.hydroPumpQueryPointListGridCtrl1.SetBindingData(vmList);
        }
        //并联状态改变事件
        private void PumpParallelChart1_ParallelStatusChangedEvent(bool status, string msg)
        {
            this.ParallelStatusChangedEvent?.Invoke(status, msg);
        }
        //设计点
        private void btnDesign_Click(object sender, EventArgs e)
        {
            var qtext = this.txtDesignQ.Text.Trim();
            if (string.IsNullOrEmpty(qtext))
            {
                TipFormHelper.ShowWarn("请输入设计点流量!");
                return;
            }
            var htext = this.txtDesignH.Text.Trim();
            if (string.IsNullOrEmpty(htext))
            {
                TipFormHelper.ShowWarn("请输入设计点扬程!");
                return;
            }
            var q = double.Parse(qtext);
            var h = double.Parse(htext);
            this.pumpParallelChart1.SetDesignPoint(q, h);
        }
    }
}