using DevExpress.XtraEditors;
|
using System.Data;
|
|
|
//编辑原始的性能曲线
|
namespace Yw.WinFrmUI.Phart
|
{
|
public partial class PumpEditChartCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public PumpEditChartCtrl()
|
{
|
InitializeComponent();
|
|
this.gridView1.SetNormalEditView();
|
this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
this.curveExpressEditChart.OnDefinePointChanged += FeatCurvesDispCtrl1_OnDefinePointChanged;
|
}
|
|
|
private List<Yw.Geometry.Point2d> _qh_pt_list = null;
|
private List<Yw.Geometry.Point2d> _qe_pt_list = null;
|
private List<Yw.Geometry.Point2d> _qp_pt_list = null;
|
|
private List<Yw.Geometry.Point2d> _fit_pt_list = null;
|
|
|
Yw.Pump.eCurveType _editCurveType = Yw.Pump.eCurveType.QH;
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
_qh_pt_list = null;
|
_qe_pt_list = null;
|
_qp_pt_list = null;
|
|
_fit_pt_list = new List<Yw.Geometry.Point2d>();
|
this.bindingSource1.DataSource = _fit_pt_list;
|
}
|
|
|
/// <summary>
|
/// 初始化数据(目前没有定义点)
|
/// </summary>
|
public void SetBindingData(Yw.Geometry.CubicSpline2d qh,
|
Yw.Geometry.CubicSpline2d qe,
|
Yw.Geometry.CubicSpline2d qp)
|
{
|
if (qh == null)
|
return;
|
List<Yw.Geometry.Point2d> qh_pt_list, qe_pt_list = null, qp_pt_list = null;
|
|
qh_pt_list = qh.GetPointList(100);
|
|
if (qe != null)
|
qe_pt_list = qe.GetPointList(100);
|
|
if (qp != null)
|
qp_pt_list = qp.GetPointList(100);
|
|
SetBindingData(qh_pt_list, qe_pt_list, qp_pt_list, qh_pt_list, qe_pt_list, qp_pt_list);
|
|
}
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void SetBindingData(List<Yw.Geometry.Point2d> qh_pt_list,
|
List<Yw.Geometry.Point2d> qe_pt_list,
|
List<Yw.Geometry.Point2d> qp_pt_list,
|
List<Yw.Geometry.Point2d> def_qh_pt_list,
|
List<Yw.Geometry.Point2d> def_qe_pt_list,
|
List<Yw.Geometry.Point2d> def_qp_pt_list)
|
{
|
|
_fit_pt_list = new List<Yw.Geometry.Point2d>();
|
this.bindingSource1.DataSource = _fit_pt_list;
|
|
_qh_pt_list = null;
|
_qe_pt_list = null;
|
_qp_pt_list = null;
|
|
|
if (qh_pt_list == null || qh_pt_list.Count < 4)
|
{
|
this.curveExpressEditChart.InitialChartData();
|
return;
|
}
|
|
_qh_pt_list = qh_pt_list;
|
_qe_pt_list = qe_pt_list;
|
_qp_pt_list = qp_pt_list;
|
|
|
this.cmbCurveType.Properties.Items.Clear();
|
this.cmbCurveType.Properties.Items.Add("流量扬程曲线");
|
if (_qe_pt_list != null && _qe_pt_list.Count > 3)
|
this.cmbCurveType.Properties.Items.Add("流量效率曲线");
|
if (_qp_pt_list != null && _qp_pt_list.Count > 3)
|
this.cmbCurveType.Properties.Items.Add("流量功率曲线");
|
this.cmbCurveType.SelectedIndex = 0;
|
|
this.curveExpressEditChart.SetBindingData(_qh_pt_list, _qe_pt_list, _qp_pt_list, def_qh_pt_list, def_qe_pt_list, def_qp_pt_list);
|
|
ReloadCurvePoints();
|
}
|
|
//性能曲线点修改事件
|
private void FeatCurvesDispCtrl1_OnDefinePointChanged(Yw.Pump.eCurveType type, List<Yw.Geometry.Point2d> points)
|
{
|
_fit_pt_list.Clear();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
_qh_pt_list = points;
|
foreach (Yw.Geometry.Point2d pt in _qh_pt_list)
|
{
|
var x = Math.Round(pt.X, 2);
|
var y = Math.Round(pt.Y, 2);
|
_fit_pt_list.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
_qe_pt_list = points;
|
foreach (Yw.Geometry.Point2d pt in _qe_pt_list)
|
{
|
var x = Math.Round(pt.X, 2);
|
var y = Math.Round(pt.Y, 2);
|
_fit_pt_list.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
_qp_pt_list = points;
|
foreach (Yw.Geometry.Point2d pt in _qp_pt_list)
|
{
|
var x = Math.Round(pt.X, 2);
|
var y = Math.Round(pt.Y, 2);
|
_fit_pt_list.Add(new Yw.Geometry.Point2d(x, 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 = _fit_pt_list.Select(x => new Yw.Geometry.Point2d(x)).ToList();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
_qh_pt_list = points;
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
|
_qe_pt_list = points;
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
_qp_pt_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()
|
{
|
_fit_pt_list.Clear();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
foreach (Yw.Geometry.Point2d pt in _qh_pt_list)
|
{
|
var x = Math.Round(pt.X, 2);
|
var y = Math.Round(pt.Y, 2);
|
_fit_pt_list.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
foreach (Yw.Geometry.Point2d pt in _qe_pt_list)
|
{
|
var x = Math.Round(pt.X, 2);
|
var y = Math.Round(pt.Y, 2);
|
_fit_pt_list.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
foreach (Yw.Geometry.Point2d pt in _qp_pt_list)
|
{
|
var x = Math.Round(pt.X, 2);
|
var y = Math.Round(pt.Y, 2);
|
_fit_pt_list.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
}
|
break;
|
}
|
var list = _fit_pt_list?.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;
|
_fit_pt_list.Remove(row);
|
this.bindingSource1.ResetBindings(false);
|
|
var points = new List<Yw.Geometry.Point2d>();
|
foreach (var curvePoint in _fit_pt_list)
|
{
|
var x = curvePoint.X;
|
var y = curvePoint.Y;
|
points.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH: _qh_pt_list = points.ToList(); break;
|
case Yw.Pump.eCurveType.QE: _qe_pt_list = points.ToList(); break;
|
case Yw.Pump.eCurveType.QP: _qp_pt_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 = _qh_pt_list;
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("E");
|
points = _qe_pt_list;
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("P");
|
points = _qp_pt_list;
|
}
|
break;
|
}
|
if (dlg.ShowDialog() != DialogResult.OK)
|
return;
|
|
points.Add(new Yw.Geometry.Point2d(dlg.X, dlg.Y));
|
ReloadCurvePoints();
|
}
|
|
//重新计算
|
private void ReloadCalcu()
|
{
|
if (_fit_pt_list == null)
|
return;
|
bool isFromZero = false;
|
if (_qh_pt_list.Last().X > 20)
|
{
|
if (_qh_pt_list.First().X < 1)
|
isFromZero = true;
|
}
|
else
|
{
|
if (_qh_pt_list.First().X < 0.3)
|
isFromZero = true;
|
}
|
if (_editCurveType == Yw.Pump.eCurveType.QE)
|
{
|
_qe_pt_list = PumpCalcHelper.CalculateELineByP(_qh_pt_list, _qp_pt_list, isFromZero);
|
}
|
else if (_editCurveType == Yw.Pump.eCurveType.QP)
|
{
|
|
double ref_zero_power = -1;
|
if (_qp_pt_list != null && _qe_pt_list.Count > 0)
|
{
|
ref_zero_power = _qp_pt_list.First().Y;
|
}
|
_qp_pt_list = PumpCalcHelper.CalculateP_AlignPointE(_qh_pt_list, _qe_pt_list, Constant.WaterDensity, ref_zero_power, isFromZero);
|
}
|
ReloadCurvePoints();
|
}
|
|
|
/// <summary>
|
/// 设置曲线坐标
|
/// </summary>
|
public void SetCoordinateByDialog()
|
{
|
this.curveExpressEditChart.SetChartAxis();
|
}
|
|
|
|
/// <summary>
|
/// 获取点信息
|
/// </summary>
|
/// <param name="qh_pt_list"></param>
|
/// <param name="qe_pt_list"></param>
|
/// <param name="qp_pt_list"></param>
|
/// <returns></returns>
|
public bool GetPoints(out List<Yw.Geometry.Point2d> qh_pt_list,
|
out List<Yw.Geometry.Point2d> qe_pt_list,
|
out List<Yw.Geometry.Point2d> qp_pt_list)
|
{
|
qh_pt_list = _qh_pt_list?.ToList();
|
qe_pt_list = _qe_pt_list?.ToList();
|
qp_pt_list = _qp_pt_list?.ToList();
|
if (qh_pt_list == null || qh_pt_list.Count < 4)
|
{
|
XtraMessageBox.Show("点数过少!");
|
return false;
|
}
|
|
return true;
|
}
|
|
|
}
|
}
|