using Yw.Geometry;
|
|
namespace HStation.WinFrmUI.PhartRelation
|
{
|
public partial class PumpParallelChartDlg : XtraForm
|
{
|
public PumpParallelChartDlg()
|
{
|
InitializeComponent();
|
this.Text = "并联分析";
|
this.WindowState = FormWindowState.Maximized;
|
|
this.pumpParallelInfoCtrl1.SetEvent += (id, qh, qe, qp) =>
|
{
|
var list = this.pumpParallelInfoCtrl1.GetRunList();
|
SetParallel(list);
|
};
|
|
this.pumpParallelInfoCtrl1.SetInfoEvent += (id, name, color) =>
|
{
|
this.pumpSerialParallelChart.SetInfo(id, name, color);
|
};
|
|
this.pumpParallelInfoCtrl1.SetDesignPointEvent += (q, h) =>
|
{
|
this.pumpSerialParallelChart.SetDesignPt(new Point2d(q, h));
|
};
|
|
this.pumpParallelInfoCtrl1.AddEvent += (vm) =>
|
{
|
var list = this.pumpParallelInfoCtrl1.GetRunList();
|
SetParallel(list);
|
};
|
|
this.pumpParallelInfoCtrl1.DeleteEvent += (id) =>
|
{
|
var list = this.pumpParallelInfoCtrl1.GetRunList();
|
SetParallel(list);
|
};
|
|
this.pumpSerialParallelChart.OnCalcQueryPoint += (id, pt) =>
|
{
|
this.pumpParallelInfoCtrl1.SetQueryInfo(id, pt);
|
};
|
this.pumpParallelInfoCtrl1.SaveEvent += () =>
|
{
|
var run_list = this.pumpParallelInfoCtrl1.GetRunList();
|
var list = new List<XhsSingleResultViewModel>();
|
if (run_list != null && run_list.Any())
|
{
|
foreach (var x in run_list)
|
{
|
var vm = new XhsSingleResultViewModel();
|
vm.ID = x.ID;
|
vm.Name = x.Name;
|
vm.Code = x.Code;
|
vm.IsBp = x.IsBp;
|
vm.RunStatus = x.RunStatus;
|
vm.CurrentHz = x.CurrentHz;
|
list.Add(vm);
|
}
|
}
|
this.ReloadDataEvent?.Invoke(list);
|
};
|
}
|
|
private string _parallel_id = "parallel";
|
public event Func<List<XhsSingleResultViewModel>, Task<bool>> ReloadDataEvent;
|
|
|
/// <summary>
|
/// 设置
|
/// </summary>
|
/// <param name="list"></param>
|
/// <returns></returns>
|
public string SetBindingData(
|
List<XhsSinglePumpViewModel> list)
|
{
|
if (list == null || !list.Any())
|
{
|
return "数据为空!";
|
}
|
|
var vm_list = new List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel>();
|
for (int i = 0; i < list.Count; i++)
|
{
|
var x = list[i];
|
if (x.CurveQH == null || !x.CurveQH.Any())
|
{
|
continue;
|
}
|
|
var vm = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel();
|
vm.ID= x.ID;
|
vm.Id = x.ID.ToString();
|
vm.Name = x.Name;
|
vm.Code = x.Code;
|
vm.IsBp = x.IsBp;
|
vm.RatedSpeed = x.RatedSpeed;
|
vm.CurrentSpeed = x.CurrentSpeed;
|
vm.RunStatus = x.RunStatus;
|
vm.CurrentHz = x.CurrentHz;
|
var qh_pt_list = x.CurveQH.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
|
vm.Qh = new CubicSpline2d(qh_pt_list);
|
if (x.CurveQE != null && x.CurveQE.Any())
|
{
|
var qe_pt_list = x.CurveQE.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
|
vm.Qe = new CubicSpline2d(qe_pt_list);
|
}
|
if (x.CurveQP != null && x.CurveQP.Any())
|
{
|
var qp_pt_list = x.CurveQP.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
|
vm.Qp = new CubicSpline2d(qp_pt_list);
|
}
|
vm.CalcuQ = x.CalcuQ;
|
vm.CalcuH = x.CalcuH;
|
vm.Color = GetRandomColor(i);
|
vm.Calc();
|
vm_list.Add(vm);
|
|
}
|
|
|
this.pumpParallelInfoCtrl1.SetBindingData(vm_list, null);
|
var run_list = this.pumpParallelInfoCtrl1.GetRunList();
|
var msg = SetParallel(run_list);
|
if (!string.IsNullOrEmpty(msg))
|
return msg;
|
return string.Empty;
|
}
|
|
private string SetParallel(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list)
|
{
|
this.pumpSerialParallelChart.Delete();
|
if (list == null || !list.Any())
|
{
|
return "无数据!";
|
}
|
if (list.Count < 2)
|
{
|
CalcEqPoint(list);
|
this.pumpSerialParallelChart.Add(list);
|
return "无法计算 并联曲线!";
|
}
|
var vm_parallel = CalcParallel(list);
|
if (vm_parallel != null)
|
{
|
list.Add(vm_parallel);
|
CalcEqPoint(list);
|
this.pumpSerialParallelChart.Add(list);
|
return string.Empty;
|
}
|
else
|
{
|
return "无法计算 并联曲线!";
|
}
|
}
|
|
|
private Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel CalcParallel(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list)
|
{
|
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));
|
line_name = "并联曲线";
|
calc_bol = helper.CalculateParallel(out calc_pt_qh_list, out calc_pt_qe_list, out calc_pt_qp_list);
|
|
if (!calc_bol || calc_pt_qh_list.Count < 3)
|
{
|
return default;
|
}
|
|
var vm_sp = new Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel();
|
vm_sp.Id = _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;
|
|
var pt_list = vm_sp.Qp.GetPointList(12);
|
return vm_sp;
|
|
}
|
|
private void CalcEqPoint(List<Yw.WinFrmUI.Phart.PumpSerialParallelInfoViewModel> list)
|
{
|
if (list == null || !list.Any())
|
{
|
return;
|
}
|
|
double total_flow = list.Sum(x => x.CalcuQ ?? 0);
|
double total_head = list.Average(x => x.CalcuH ?? 0);
|
this.pumpParallelInfoCtrl1.SetDesignPoint(total_flow, total_head);
|
}
|
|
|
|
#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
|
|
}
|
}
|