using DevExpress.XtraEditors;
|
using System.Data;
|
|
|
//编辑原始的性能曲线
|
namespace Yw.WinFrmUI.Phart
|
{
|
public partial class PumpPerform2dEditCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public PumpPerform2dEditCtrl()
|
{
|
InitializeComponent();
|
|
this.gridView1.SetNormalEditView();
|
this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
|
this.curveExpressEditChart.OnDefinePointChanged += FeatCurvesDispCtrl1_OnDefinePointChanged;
|
}
|
|
|
|
|
private List<Yw.Geometry.Point2d> _pt_qh_list = null;
|
private List<Yw.Geometry.Point2d> _pt_qe_list = null;
|
private List<Yw.Geometry.Point2d> _pt_qp_list = null;
|
|
private List<Yw.Geometry.Point2d> _fitCurvePoints = null;
|
|
|
Yw.Pump.eCurveType _editCurveType = Yw.Pump.eCurveType.QH;
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
_pt_qh_list = null;
|
_pt_qe_list = null;
|
_pt_qp_list = null;
|
|
_fitCurvePoints = new List<Yw.Geometry.Point2d>();
|
this.bindingSource1.DataSource = _fitCurvePoints;
|
}
|
|
|
/// <summary>
|
/// 初始化数据(目前没有定义点)
|
/// </summary>
|
public void SetBindingData(Yw.Geometry.CubicSpline2d cubic_spline_qh,
|
Yw.Geometry.CubicSpline2d cubic_spline_qe,
|
Yw.Geometry.CubicSpline2d cubic_spline_qp)
|
{
|
if (cubic_spline_qh == null)
|
return;
|
List<Yw.Geometry.Point2d> pt_qh_list, pt_qe_list = null, pt_qp_list = null;
|
|
pt_qh_list = cubic_spline_qh.GetPointList(12);
|
|
if (cubic_spline_qe != null)
|
pt_qe_list = cubic_spline_qe.GetPointList(12);
|
|
if (cubic_spline_qp != null)
|
pt_qp_list = cubic_spline_qp.GetPointList(12);
|
|
SetBindingData(pt_qh_list, pt_qe_list, pt_qp_list, pt_qh_list, pt_qe_list, pt_qp_list);
|
|
}
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void SetBindingData(List<Yw.Geometry.Point2d> pt_qh_list,
|
List<Yw.Geometry.Point2d> pt_qe_list,
|
List<Yw.Geometry.Point2d> pt_qp_list,
|
List<Yw.Geometry.Point2d> def_pt_qh_list,
|
List<Yw.Geometry.Point2d> def_pt_qe_list,
|
List<Yw.Geometry.Point2d> def_pt_qp_list)
|
{
|
|
_fitCurvePoints = new List<Yw.Geometry.Point2d>();
|
this.bindingSource1.DataSource = _fitCurvePoints;
|
|
_pt_qh_list = null;
|
_pt_qe_list = null;
|
_pt_qp_list = null;
|
|
|
if (pt_qh_list == null || pt_qh_list.Count < 4)
|
{
|
this.curveExpressEditChart.InitialChartData();
|
return;
|
}
|
|
_pt_qh_list = pt_qh_list;
|
_pt_qe_list = pt_qe_list;
|
_pt_qp_list = pt_qp_list;
|
|
|
this.cmbCurveType.Properties.Items.Clear();
|
this.cmbCurveType.Properties.Items.Add("流量扬程曲线");
|
if (_pt_qe_list != null && _pt_qe_list.Count > 3)
|
this.cmbCurveType.Properties.Items.Add("流量效率曲线");
|
if (_pt_qp_list != null && _pt_qp_list.Count > 3)
|
this.cmbCurveType.Properties.Items.Add("流量功率曲线");
|
this.cmbCurveType.SelectedIndex = 0;
|
|
this.curveExpressEditChart.SetBindingData(_pt_qh_list, _pt_qe_list, _pt_qp_list, def_pt_qh_list,def_pt_qe_list,def_pt_qp_list);
|
|
ReloadCurvePoints();
|
}
|
|
//性能曲线点修改事件
|
private void FeatCurvesDispCtrl1_OnDefinePointChanged(Yw.Pump.eCurveType type, List<Yw.Geometry.Point2d> points)
|
{
|
_fitCurvePoints.Clear();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
_pt_qh_list = points;
|
foreach (Yw.Geometry.Point2d pt in _pt_qh_list)
|
_fitCurvePoints.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
_pt_qe_list = points;
|
foreach (Yw.Geometry.Point2d pt in _pt_qe_list)
|
_fitCurvePoints.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
_pt_qp_list = points;
|
foreach (Yw.Geometry.Point2d pt in _pt_qp_list)
|
_fitCurvePoints.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
}
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
|
//编辑性能曲线类型修改
|
private void cmbCurveType_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
string curve_type = cmbCurveType.SelectedItem.ToString();
|
if (string.Equals("流量扬程曲线", curve_type))
|
{
|
|
_editCurveType = Yw.Pump.eCurveType.QH;
|
}
|
else if (string.Equals("流量效率曲线", curve_type))
|
{
|
_editCurveType = Yw.Pump.eCurveType.QE;
|
|
}
|
else if (string.Equals("流量功率曲线", curve_type))
|
{
|
_editCurveType = Yw.Pump.eCurveType.QP;
|
}
|
ReloadCurvePoints();
|
}
|
|
//单元格修改后触发
|
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
{
|
var points = _fitCurvePoints.Select(x => new Yw.Geometry.Point2d(x)).ToList();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
_pt_qh_list = points;
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
|
_pt_qe_list = points;
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
_pt_qp_list = points;
|
}
|
break;
|
}
|
ReloadCurvePoints();
|
}
|
|
//按钮点击事件
|
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;
|
}
|
}
|
|
|
/// <summary>
|
/// 刷新数据
|
/// </summary>
|
private void ReloadCurvePoints()
|
{
|
_fitCurvePoints.Clear();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
foreach (Yw.Geometry.Point2d pt in _pt_qh_list)
|
_fitCurvePoints.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
foreach (Yw.Geometry.Point2d pt in _pt_qe_list)
|
_fitCurvePoints.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
foreach (Yw.Geometry.Point2d pt in _pt_qp_list)
|
_fitCurvePoints.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
}
|
var list = _fitCurvePoints?.Select(x => new Yw.Geometry.Point2d(x.X, x.Y)).ToList();
|
this.curveExpressEditChart.UpdateCurve(_editCurveType, list);
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
//删除点
|
private void DeletePoint()
|
{
|
var row = this.gridView1.GetFocusedRow() as Yw.Geometry.Point2d;
|
if (row == null)
|
return;
|
if (XtraMessageBox.Show("是否删除此点?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes)
|
return;
|
_fitCurvePoints.Remove(row);
|
this.bindingSource1.ResetBindings(false);
|
|
var points = new List<Yw.Geometry.Point2d>();
|
foreach (var curvePoint in _fitCurvePoints)
|
{
|
var x = curvePoint.X;
|
var y = curvePoint.Y;
|
points.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH: _pt_qh_list = points.ToList(); break;
|
case Yw.Pump.eCurveType.QE: _pt_qe_list = points.ToList(); break;
|
case Yw.Pump.eCurveType.QP: _pt_qp_list = points.ToList(); break;
|
}
|
|
this.curveExpressEditChart.UpdateCurve(_editCurveType, points);
|
}
|
|
|
//插入点
|
private void InsertPoint()
|
{
|
var dlg = new InputXYDlg();
|
List<Yw.Geometry.Point2d> points = null;
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("H");
|
points = _pt_qh_list;
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("E");
|
points = _pt_qe_list;
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("P");
|
points = _pt_qp_list;
|
}
|
break;
|
}
|
if (dlg.ShowDialog() != DialogResult.OK)
|
return;
|
|
points.Add(new Yw.Geometry.Point2d(dlg.X, dlg.Y));
|
ReloadCurvePoints();
|
}
|
|
//重新计算
|
private void ReloadCalcu()
|
{
|
if (_fitCurvePoints == null)
|
return;
|
bool isFromZero = false;
|
if (_pt_qh_list.Last().X > 20)
|
{
|
if (_pt_qh_list.First().X < 1)
|
isFromZero = true;
|
}
|
else
|
{
|
if (_pt_qh_list.First().X < 0.3)
|
isFromZero = true;
|
}
|
if (_editCurveType == Yw.Pump.eCurveType.QE)
|
{
|
_pt_qe_list = PumpCalcHelper.CalculateELineByP(_pt_qh_list, _pt_qp_list, isFromZero);
|
}
|
else if (_editCurveType == Yw.Pump.eCurveType.QP)
|
{
|
|
double ref_zero_power = -1;
|
if (_pt_qp_list != null && _pt_qe_list.Count > 0)
|
{
|
ref_zero_power = _pt_qp_list.First().Y;
|
}
|
_pt_qp_list = PumpCalcHelper.CalculateP_AlignPointE(_pt_qh_list, _pt_qe_list, Constant.WaterDensity, ref_zero_power, isFromZero);
|
}
|
ReloadCurvePoints();
|
}
|
|
|
/// <summary>
|
/// 设置曲线坐标
|
/// </summary>
|
public void SetCoordinateByDialog()
|
{
|
this.curveExpressEditChart.SetChartAxis();
|
}
|
|
|
|
/// <summary>
|
/// 获取点信息
|
/// </summary>
|
/// <param name="pt_qh_list"></param>
|
/// <param name="pt_qe_list"></param>
|
/// <param name="pt_qp_list"></param>
|
/// <returns></returns>
|
public bool GetPoints(out List<Yw.Geometry.Point2d> pt_qh_list,
|
out List<Yw.Geometry.Point2d> pt_qe_list,
|
out List<Yw.Geometry.Point2d> pt_qp_list)
|
{
|
pt_qh_list = _pt_qh_list?.ToList();
|
pt_qe_list = _pt_qe_list?.ToList();
|
pt_qp_list = _pt_qp_list?.ToList();
|
if (pt_qh_list == null || pt_qh_list.Count < 4)
|
{
|
XtraMessageBox.Show("点数过少!");
|
return false;
|
}
|
|
return true;
|
}
|
|
|
}
|
}
|