using DevExpress.Utils;
|
using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid.Views.Grid;
|
using System.Data;
|
using System.Drawing;
|
using System.Windows.Forms;
|
|
|
//编辑原始的性能曲线
|
namespace Yw.WinFrmUI.Phart
|
{
|
public partial class CurveExpressEditCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public CurveExpressEditCtrl()
|
{
|
InitializeComponent();
|
InitializeGridView();
|
|
this.curveExpressEditChart.OnDefinePointChanged += FeatCurvesDispCtrl1_OnDefinePointChanged;
|
}
|
|
private void InitializeGridView()
|
{
|
this.gridView1.OptionsFind.FindNullPrompt = "检索";
|
this.gridView1.OptionsSelection.MultiSelect = false;
|
this.gridView1.OptionsMenu.EnableColumnMenu = true;
|
|
this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
|
this.gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
this.gridView1.Appearance.Row.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
|
this.gridView1.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
|
this.gridView1.OptionsCustomization.AllowFilter = true;
|
this.gridView1.OptionsCustomization.AllowSort = true;
|
this.gridView1.OptionsCustomization.AllowQuickHideColumns = false;
|
this.gridView1.OptionsView.ShowAutoFilterRow = false;
|
this.gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;
|
this.gridView1.OptionsView.NewItemRowPosition = NewItemRowPosition.None;
|
this.gridView1.OptionsView.ShowGroupPanel = false;
|
this.gridView1.OptionsClipboard.AllowCopy = DefaultBoolean.True;
|
this.gridView1.OptionsBehavior.Editable = true;
|
this.gridView1.OptionsBehavior.ReadOnly = false;
|
|
this.gridView1.OptionsView.EnableAppearanceOddRow = true;
|
this.gridView1.OptionsView.EnableAppearanceEvenRow = true;
|
this.gridView1.Appearance.OddRow.BackColor = Color.White;
|
this.gridView1.Appearance.EvenRow.BackColor = Color.FromArgb(244, 248, 251);
|
|
int height = 30;
|
this.gridView1.RowHeight = height;
|
this.gridView1.ColumnPanelRowHeight = height;
|
this.gridView1.GroupRowHeight = height;
|
this.gridView1.BestFitColumns();
|
|
this.gridView1.OptionsView.ShowIndicator = true;
|
this.gridView1.IndicatorWidth = height;
|
this.gridView1.CustomDrawRowIndicator += (sender, e) =>
|
{
|
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
|
{
|
e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();
|
e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
|
}
|
};
|
this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
}
|
|
|
|
|
Yw.Pump.eFeatType _fitTypeQH = Yw.Pump.eFeatType.Cubic;
|
Yw.Pump.eFeatType _fitTypeQE = Yw.Pump.eFeatType.Cubic;
|
Yw.Pump.eFeatType _fitTypeQP = Yw.Pump.eFeatType.Cubic;
|
|
private List<Yw.Geometry.Point2d> _pointsQH = null;
|
private List<Yw.Geometry.Point2d> _pointsQE = null;
|
private List<Yw.Geometry.Point2d> _pointsQP = null;
|
|
private List<Yw.Geometry.Point2d> _fitYw.Geometry.Point2ds = null;
|
|
Yw.Pump.eCurveType _editCurveType = Yw.Pump.eCurveType.QH;
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
_pointsQH = null;
|
_pointsQE = null;
|
_pointsQP = null;
|
|
_fitYw.Geometry.Point2ds = new List<Yw.Geometry.Point2d>();
|
this.bindingSource1.DataSource = _fitYw.Geometry.Point2ds;
|
}
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void SetBindingData(Yw.Curve.CurveExpress curveQH,
|
Yw.Curve.CurveExpress curveQE,
|
Yw.Curve.CurveExpress curveQP)
|
{
|
if (curveQH == null)
|
return;
|
List<Yw.Geometry.Point2d> qhPoints, qePoints = null, qpPoints = null;
|
|
if (curveQH.DefinePoints != null)
|
qhPoints = curveQH.DefinePoints;
|
else
|
qhPoints = curveQH.GetFitPoints(12);
|
|
_fitTypeQH = curveQH.FitType;
|
if (curveQE != null)
|
{
|
_fitTypeQE = curveQE.FitType;
|
if (curveQE.DefinePoints != null)
|
qePoints = curveQE.DefinePoints;
|
else
|
qePoints = curveQE.GetFitPoints(12);
|
}
|
|
if (curveQP != null)
|
{
|
_fitTypeQP = curveQP.FitType;
|
if (curveQP?.DefinePoints != null)
|
qpPoints = curveQP.DefinePoints;
|
else
|
qpPoints = curveQP.GetFitPoints(12);
|
}
|
|
SetBindingData(qhPoints, qePoints, qpPoints, _fitTypeQH, _fitTypeQE, _fitTypeQP);
|
}
|
|
|
/// <summary>
|
/// 初始化数据
|
/// </summary>
|
public void SetBindingData(List<Yw.Geometry.Point2d> pointsQH,
|
List<Yw.Geometry.Point2d> pointsQE,
|
List<Yw.Geometry.Point2d> pointsQP,
|
Yw.Pump.eFeatType fitTypeQH,
|
Yw.Pump.eFeatType fitTypeQE,
|
Yw.Pump.eFeatType fitTypeQP)
|
{
|
|
_fitYw.Geometry.Point2ds = new List<Yw.Geometry.Point2d>();
|
this.bindingSource1.DataSource = _fitYw.Geometry.Point2ds;
|
|
_pointsQH = null;
|
_pointsQE = null;
|
_pointsQP = null;
|
|
|
if (pointsQH == null || pointsQH.Count < 4)
|
{
|
this.curveExpressEditChart.InitialChartData();
|
return;
|
}
|
|
_pointsQH = pointsQH;
|
_pointsQE = pointsQE;
|
_pointsQP = pointsQP;
|
|
_fitTypeQH = fitTypeQH;
|
_fitTypeQE = fitTypeQE;
|
_fitTypeQP = fitTypeQP;
|
|
|
this.cmbCurveType.Properties.Items.Clear();
|
this.cmbCurveType.Properties.Items.Add("流量扬程曲线");
|
if (_pointsQE != null && _pointsQE.Count > 3)
|
this.cmbCurveType.Properties.Items.Add("流量效率曲线");
|
if (_pointsQP != null && _pointsQP.Count > 3)
|
this.cmbCurveType.Properties.Items.Add("流量功率曲线");
|
this.cmbCurveType.SelectedIndex = 0;
|
|
this.curveExpressEditChart.SetBindingData(_pointsQH, _pointsQE, _pointsQP, _fitTypeQH, _fitTypeQE, _fitTypeQP);
|
|
ReloadYw.Geometry.Point2ds();
|
}
|
|
//性能曲线点修改事件
|
private void FeatCurvesDispCtrl1_OnDefinePointChanged(Yw.Pump.eCurveType type, List<Yw.Geometry.Point2d> points)
|
{
|
_fitYw.Geometry.Point2ds.Clear();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
_pointsQH = points;
|
foreach (Yw.Geometry.Point2d pt in _pointsQH)
|
_fitYw.Geometry.Point2ds.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
_pointsQE = points;
|
foreach (Yw.Geometry.Point2d pt in _pointsQE)
|
_fitYw.Geometry.Point2ds.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
_pointsQP = points;
|
foreach (Yw.Geometry.Point2d pt in _pointsQP)
|
_fitYw.Geometry.Point2ds.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
}
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
|
//编辑性能曲线类型修改
|
private void cmbCurveType_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
string curveType = cmbCurveType.SelectedItem.ToString();
|
if (string.Equals("流量扬程曲线", curveType))
|
{
|
|
_editCurveType = Yw.Pump.eCurveType.QH;
|
}
|
else if (string.Equals("流量效率曲线", curveType))
|
{
|
_editCurveType = Yw.Pump.eCurveType.QE;
|
|
}
|
else if (string.Equals("流量功率曲线", curveType))
|
{
|
_editCurveType = Yw.Pump.eCurveType.QP;
|
}
|
ReloadYw.Geometry.Point2ds();
|
}
|
|
//单元格修改后触发
|
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
{
|
var points = _fitYw.Geometry.Point2ds.Select(x => new Yw.Geometry.Point2d(x)).ToList();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
_pointsQH = points;
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
|
_pointsQE = points;
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
|
_pointsQP = points;
|
}
|
break;
|
}
|
ReloadYw.Geometry.Point2ds();
|
}
|
|
//按钮点击事件
|
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 ReloadYw.Geometry.Point2ds()
|
{
|
_fitYw.Geometry.Point2ds.Clear();
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
foreach (Yw.Geometry.Point2d pt in _pointsQH)
|
_fitYw.Geometry.Point2ds.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
foreach (Yw.Geometry.Point2d pt in _pointsQE)
|
_fitYw.Geometry.Point2ds.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
foreach (Yw.Geometry.Point2d pt in _pointsQP)
|
_fitYw.Geometry.Point2ds.Add(new Yw.Geometry.Point2d(pt.X, pt.Y));
|
}
|
break;
|
}
|
var list = _fitYw.Geometry.Point2ds?.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;
|
_fitYw.Geometry.Point2ds.Remove(row);
|
this.bindingSource1.ResetBindings(false);
|
|
var points = new List<Yw.Geometry.Point2d>();
|
foreach (var curvePoint in _fitYw.Geometry.Point2ds)
|
{
|
var x = curvePoint.X;
|
var y = curvePoint.Y;
|
points.Add(new Yw.Geometry.Point2d(x, y));
|
}
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH: _pointsQH = points.ToList(); break;
|
case Yw.Pump.eCurveType.QE: _pointsQE = points.ToList(); break;
|
case Yw.Pump.eCurveType.QP: _pointsQP = points.ToList(); break;
|
}
|
|
this.curveExpressEditChart.UpdateCurve(_editCurveType, points);
|
}
|
|
|
//插入点
|
private void InsertPoint()
|
{
|
var dlg = new Chart.InputXYDialog();
|
List<Yw.Geometry.Point2d> points = null;
|
switch (_editCurveType)
|
{
|
case Yw.Pump.eCurveType.QH:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("H");
|
points = _pointsQH;
|
}
|
break;
|
case Yw.Pump.eCurveType.QE:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("E");
|
points = _pointsQE;
|
}
|
break;
|
case Yw.Pump.eCurveType.QP:
|
{
|
dlg.SetLabelX("Q");
|
dlg.SetLabelY("P");
|
points = _pointsQP;
|
}
|
break;
|
}
|
if (dlg.ShowDialog() != DialogResult.OK)
|
return;
|
|
points.Add(new Yw.Geometry.Point2d(dlg.X, dlg.Y));
|
ReloadYw.Geometry.Point2ds();
|
}
|
|
//重新计算
|
private void ReloadCalcu()
|
{
|
if (_fitYw.Geometry.Point2ds == null)
|
return;
|
bool isFromZero = false;
|
if (_pointsQH.Last().X > 20)
|
{
|
if (_pointsQH.First().X < 1)
|
isFromZero = true;
|
}
|
else
|
{
|
if (_pointsQH.First().X < 0.3)
|
isFromZero = true;
|
}
|
if (_editCurveType == Yw.Pump.eCurveType.QE)
|
{
|
_pointsQE = Yw.Curve.PumpCalculateHelper.CalculateELineByP(_fitTypeQH, _fitTypeQP, _pointsQH, _pointsQP, isFromZero);
|
}
|
else if (_editCurveType == Yw.Pump.eCurveType.QP)
|
{
|
|
double ref_zero_power = -1;
|
if (_pointsQP != null && _pointsQE.Count > 0)
|
{
|
ref_zero_power = _pointsQP.First().Y;
|
}
|
_pointsQP = Yw.Curve.PumpCalculateHelper.CalculateP_AlignPointE(_fitTypeQH, _fitTypeQE, _pointsQH, _pointsQE, Yw.Curve.Constant.WaterDensity, ref_zero_power, isFromZero);
|
}
|
ReloadYw.Geometry.Point2ds();
|
}
|
|
|
/// <summary>
|
/// 设置曲线坐标
|
/// </summary>
|
public void SetCoordinateByDialog()
|
{
|
this.curveExpressEditChart.SetChartAxis();
|
}
|
|
|
|
/// <summary>
|
/// 获取点信息
|
/// </summary>
|
/// <param name="pointsQH"></param>
|
/// <param name="pointsQE"></param>
|
/// <param name="pointsQP"></param>
|
/// <returns></returns>
|
public bool GetPoints(out List<Yw.Geometry.Point2d> pointsQH,
|
out List<Yw.Geometry.Point2d> pointsQE,
|
out List<Yw.Geometry.Point2d> pointsQP,
|
out Yw.Pump.eFeatType fitTypeQH,
|
out Yw.Pump.eFeatType fitTypeQE,
|
out Yw.Pump.eFeatType fitTypeQP)
|
{
|
pointsQH = _pointsQH?.ToList();
|
pointsQE = _pointsQE?.ToList();
|
pointsQP = _pointsQP?.ToList();
|
fitTypeQH = _fitTypeQH;
|
fitTypeQE = _fitTypeQE;
|
fitTypeQP = _fitTypeQP;
|
if (pointsQH == null || pointsQH.Count < 4)
|
{
|
XtraMessageBox.Show("点数过少!");
|
return false;
|
}
|
|
return true;
|
}
|
|
|
}
|
}
|