using DevExpress.XtraCharts;
|
using DevExpress.XtraEditors;
|
using IStation.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI.Monitor
|
{
|
/// <summary>
|
/// 单泵分析步骤图表控件
|
/// </summary>
|
public partial class Chart4SingleFeatCurve : XtraUserControl
|
{
|
public Chart4SingleFeatCurve()
|
{
|
InitializeComponent();
|
_boxSelHelper = new ChartBoxSelHelper(this.chartControl1);
|
_boxSelHelper.BoxSelCompletedEvent += _boxSelHelper_BoxSelCompletedEvent;
|
|
|
this.chartControl1.CustomPaint += new DevExpress.XtraCharts.CustomPaintEventHandler(this.chartControl1_CustomPaint);
|
this.chartControl1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseClick);
|
|
}
|
|
|
private ChartBoxSelHelper _boxSelHelper = null;//框选辅助类
|
|
public void CloseBoxSel()
|
{
|
this._boxSelHelper.CloseBoxSel();
|
}
|
|
#region Chart变量
|
|
//图
|
private XYDiagram _diagram
|
{
|
get { return this.chartControl1.Diagram as XYDiagram; }
|
}
|
|
//曲线点
|
private Series _seriesPoints
|
{
|
get { return this.chartControl1.GetSeriesByName("曲线点"); }
|
}
|
|
//曲线
|
private Series _seriesCurve
|
{
|
get { return this.chartControl1.GetSeriesByName("曲线"); }
|
}
|
|
|
//参照线
|
private Series _referenceCurve
|
{
|
get { return this.chartControl1.GetSeriesByName("参照线"); }
|
}
|
|
|
|
//流量X轴
|
private AxisX _qAxisX
|
{
|
get { return this._diagram.AxisX; }
|
}
|
|
//扬程Y轴
|
private AxisY _AxisY
|
{
|
get { return this._diagram.AxisY; }
|
}
|
#endregion
|
|
|
#region 框选
|
private bool _isPickPoint4Fit = false;
|
private IStation.Model.eCurveFitType _currentFitType = eCurveFitType.CubicCurve;
|
|
//打点拟合
|
public void StartPickPoint4Fit(IStation.Model.eCurveFitType currentFitType)
|
{
|
_isPickPoint4Fit = true;
|
_diagram.EnableAxisXScrolling = false;
|
_diagram.EnableAxisXZooming = false;
|
this._currentFitType = currentFitType;
|
}
|
|
public List<IStation.Model.CurvePoint> EndPickPoint4Fit()
|
{
|
_isPickPoint4Fit = false;
|
_diagram.EnableAxisXScrolling = true;
|
_diagram.EnableAxisXZooming = true;
|
|
return _customerPoints;
|
}
|
|
//框选拟合
|
// private bool _isBoxPoint4Fit = false;
|
public void StartBoxPoint4Fit(IStation.Model.eCurveFitType currentFitType)
|
{
|
_isPickPoint4Fit = false;
|
//_isBoxPoint4Fit = true;
|
_diagram.EnableAxisXScrolling = false;
|
_diagram.EnableAxisXZooming = false;
|
this._currentFitType = currentFitType;
|
_boxRectSelTag = "BoxFit";
|
_boxSelHelper.StartBoxSel();
|
}
|
public List<IStation.Model.CurvePoint> EndBoxPoint4Fit()
|
{
|
_isPickPoint4Fit = false;
|
_diagram.EnableAxisXScrolling = true;
|
_diagram.EnableAxisXZooming = true;
|
|
return _customerPoints;
|
}
|
|
|
|
|
//框选数据
|
string _boxRectSelTag = null;
|
public void StartRectSelect(string tag)
|
{
|
_diagram.EnableAxisXScrolling = false;
|
_diagram.EnableAxisXZooming = false;
|
_boxRectSelTag = tag;
|
_boxSelHelper.StartBoxSel();
|
}
|
|
|
//框选完成
|
public Action<string, List<SeriesPoint>> OnCompleteRectSelect = null;
|
private void _boxSelHelper_BoxSelCompletedEvent(MouseEventArgs e)
|
{
|
_diagram.EnableAxisXScrolling = true;
|
_diagram.EnableAxisXZooming = true;
|
if (_boxSelHelper == null)
|
return;
|
var boxSelSeriesPointList = _boxSelHelper.CalcuNumericalSelSeriesPoints(new List<Series>() { _seriesPoints });
|
if (boxSelSeriesPointList == null || boxSelSeriesPointList.Count < 1)
|
{
|
_boxSelHelper.CloseBoxSel();
|
return;
|
}
|
|
if (OnCompleteRectSelect != null)
|
{
|
OnCompleteRectSelect(_boxRectSelTag, boxSelSeriesPointList);
|
}
|
}
|
|
|
#endregion
|
|
//客户自定义点
|
List<IStation.Model.CurvePoint> _customerPoints = null;//手动打点和框选打点公用
|
List<IStation.Model.CurvePoint> _customerFitCurvePoints = null;
|
public void AddCustormPoint(IStation.Model.CurvePoint pt)
|
{
|
if (_customerPoints == null)
|
_customerPoints = new List<CurvePoint>();
|
|
_customerPoints.Add(pt);
|
|
if (_customerPoints.Count > 4)
|
{
|
_customerFitCurvePoints = IStation.Common.FitCurveHelper.GetFitPoints(_customerPoints, _currentFitType, 10);
|
}
|
else
|
{
|
_customerFitCurvePoints = null;
|
}
|
}
|
public void SetCustomerPointInfo(List<IStation.Model.CurvePoint> clckPoints)
|
{
|
_customerPoints = clckPoints;
|
}
|
|
//图表点击事件
|
private void chartControl1_MouseClick(object sender, MouseEventArgs e)
|
{
|
if (e.Button == MouseButtons.Right)
|
{
|
this.popupChart.ShowPopup(MousePosition);
|
}
|
else if (e.Button == MouseButtons.Left)
|
{
|
if (_isPickPoint4Fit)
|
{
|
var coord_pick = this._diagram.PointToDiagram(e.Location);
|
AddCustormPoint(new CurvePoint(coord_pick.NumericalArgument, coord_pick.NumericalValue));
|
}
|
}
|
}
|
|
private void chartControl1_CustomPaint(object sender, CustomPaintEventArgs e)
|
{
|
if (!(e is DXCustomPaintEventArgs dxArgs))
|
return;
|
|
if (_customerPoints != null)
|
{
|
var mainDiagram = this._diagram;
|
using (Pen penCurve = new Pen(Color.Red, 2f))
|
{
|
foreach (var curvePoint in _customerPoints)
|
{
|
ControlCoordinates coorEnd = mainDiagram.DiagramToPoint(curvePoint.X, curvePoint.Y);
|
dxArgs.Cache.DrawEllipse(penCurve, new Rectangle(coorEnd.Point.X - 3, coorEnd.Point.Y - 3, 6, 6));
|
}
|
}
|
|
if (_customerFitCurvePoints != null)
|
{
|
using (Pen penCurve = new Pen(Color.DarkRed, 2f))
|
{
|
List<PointF> points = new List<PointF>(_customerFitCurvePoints.Count);
|
foreach (var curvePoint in _customerFitCurvePoints)
|
{
|
ControlCoordinates coorEnd = mainDiagram.DiagramToPoint(curvePoint.X, curvePoint.Y);
|
points.Add(coorEnd.Point);
|
}
|
|
dxArgs.Cache.DrawBeziers(penCurve, points.ToArray());
|
}
|
}
|
}
|
}
|
|
|
|
//曲线类型
|
private Model.eFeatCurveType _curveType;
|
private List<Model.CurveAnaPoint> _allAnaPoints = null;
|
public void SetCurveType(Model.eFeatCurveType curveType)
|
{
|
this._curveType = curveType;
|
if (this._allAnaPoints == null)
|
return;
|
|
RefreshPointInfo(this._allAnaPoints);
|
}
|
|
public void InitialPointInfo(List<Model.CurveAnaPoint> allAnaPoints)
|
{
|
this._allAnaPoints = allAnaPoints;
|
}
|
|
public void RefreshPointInfo(List<Model.CurveAnaPoint> allAnaPoints)
|
{
|
this._allAnaPoints = allAnaPoints;
|
//SetColor();
|
if (_curveType == eFeatCurveType.QH)
|
{
|
_seriesPoints.Points.BeginUpdate();
|
_seriesPoints.BindToData(_allAnaPoints, "Qa", "Ha");
|
_seriesPoints.CrosshairLabelPattern = "流量: {A}: 扬程: {V}";
|
_seriesPoints.View.Color = Color.CornflowerBlue;
|
_seriesPoints.Points.EndUpdate();
|
|
if (_allAnaPoints != null && _allAnaPoints.Count > 0)
|
{
|
_AxisY.WholeRange.MaxValue = _allAnaPoints.Max(x => x.Ha) + 2;
|
_AxisY.WholeRange.MinValue = _allAnaPoints.Min(x => x.Ha);
|
}
|
_AxisY.Title.Text = "扬程(m)";
|
}
|
|
|
if (_curveType == eFeatCurveType.QP)
|
{
|
/* var list = _allAnaPoints?.Where(x => x.Pa != IStation.Default.Error).ToList();
|
_seriesPoints.Points.BeginUpdate();
|
_seriesPoints.BindToData(list, "Qa", "Pa");
|
_seriesPoints.CrosshairLabelPattern = "流量: {A}: 功率: {V}";
|
_seriesPoints.View.Color = Color.Goldenrod;
|
_seriesPoints.Points.EndUpdate();
|
|
if (list != null && list.Count > 0)
|
{
|
_AxisY.WholeRange.MaxValue = list.Max(x => x.Pa) + 2;
|
_AxisY.WholeRange.MinValue = list.Min(x => x.Pa) - 2;
|
}
|
else
|
{
|
_AxisY.WholeRange.MaxValue = 1000;
|
_AxisY.WholeRange.MinValue = 100;
|
}
|
*/
|
_seriesPoints.Points.BeginUpdate();
|
_seriesPoints.BindToData(_allAnaPoints, "Qa", "Pa");
|
_seriesPoints.CrosshairLabelPattern = "流量: {A}: 功率: {V}";
|
_seriesPoints.View.Color = Color.Goldenrod;
|
_seriesPoints.Points.EndUpdate();
|
|
if (_allAnaPoints != null && _allAnaPoints.Count > 0)
|
{
|
_AxisY.WholeRange.MaxValue = _allAnaPoints.Max(x => x.Pa) + 2;
|
_AxisY.WholeRange.MinValue = _allAnaPoints.Min(x => x.Pa) - 2;
|
}
|
else
|
{
|
_AxisY.WholeRange.MaxValue = 1000;
|
_AxisY.WholeRange.MinValue = 100;
|
}
|
_AxisY.Title.Text = "功率(kw)";
|
}
|
|
|
if (_curveType == eFeatCurveType.QE)
|
{
|
var list = _allAnaPoints?.Where(x => x.Ea != IStation.Default.Error).ToList();
|
_seriesPoints.Points.BeginUpdate();
|
_seriesPoints.BindToData(list, "Qa", "Ea");
|
_seriesPoints.CrosshairLabelPattern = "流量: {A}: 效率: {V}";
|
_seriesPoints.View.Color = Color.LightSeaGreen;
|
_seriesPoints.Points.EndUpdate();
|
|
if (list != null && list.Count > 0)
|
{
|
_AxisY.WholeRange.MaxValue = list.Max(x => x.Ea) + 2;
|
_AxisY.WholeRange.MinValue = list.Min(x => x.Ea);
|
}
|
else
|
{
|
_AxisY.WholeRange.MaxValue = 100;
|
_AxisY.WholeRange.MinValue = 20;
|
}
|
_AxisY.Title.Text = "效率(η)";
|
}
|
|
if (_allAnaPoints != null && _allAnaPoints.Count > 0)
|
{
|
_qAxisX.WholeRange.MaxValue = _allAnaPoints.Max(x => x.Qa) * 1.1;
|
_qAxisX.WholeRange.MinValue = _allAnaPoints.Min(x => x.Qa) * 0.8;
|
}
|
|
}
|
//
|
public void SetCurveInfo(List<Model.CurvePoint> curvePointList)
|
{
|
_seriesCurve.Points.BeginUpdate();
|
_seriesCurve.BindToData(curvePointList, "X", "Y");
|
_seriesCurve.Points.EndUpdate();
|
}
|
|
public void UpdateAxisRangeY(double min, double max)
|
{
|
_AxisY.WholeRange.MaxValue = max + 2;
|
_AxisY.WholeRange.MinValue = max - 2;
|
|
this.chartControl1.RefreshData();
|
}
|
|
|
public void SetCurveVisible(bool isShow)
|
{
|
_seriesCurve.Visible = isShow;
|
}
|
|
public void SetCurveLabelVisible(bool isShow)
|
{
|
if (isShow)
|
{
|
_seriesCurve.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
|
}
|
else
|
{
|
_seriesCurve.LabelsVisibility = DevExpress.Utils.DefaultBoolean.False;
|
}
|
}
|
|
|
//
|
|
public void InitialReferenceCurve(List<IStation.Model.CurvePoint> points)
|
{
|
if (points == null || points.Count < 1)
|
{
|
_referenceCurve.Points.Clear();
|
}
|
else
|
{
|
_referenceCurve.Points.BeginUpdate();
|
_referenceCurve.BindToData(points, "X", "Y");
|
_referenceCurve.Points.EndUpdate();
|
|
var maxX = points.Max(x => x.X);
|
var maxY = points.Max(x => x.Y);
|
|
var minX = points.Min(x => x.X);
|
var minY = points.Min(x => x.Y);
|
|
if (Convert.ToDouble(_qAxisX.WholeRange.MaxValue) < maxX)
|
{
|
_qAxisX.WholeRange.MaxValue = maxX;
|
}
|
|
if (Convert.ToDouble(_qAxisX.WholeRange.MinValue) > minX)
|
{
|
_qAxisX.WholeRange.MinValue = minX;
|
}
|
|
if (Convert.ToDouble(_AxisY.WholeRange.MaxValue) < maxY)
|
{
|
_AxisY.WholeRange.MaxValue = maxY;
|
}
|
|
if (Convert.ToDouble(_AxisY.WholeRange.MinValue) > minY)
|
{
|
_AxisY.WholeRange.MinValue = minY;
|
}
|
}
|
}
|
|
public void SetReferenceCurveVisible(bool isShow)
|
{
|
_referenceCurve.Visible = isShow;
|
}
|
|
//设置坐标
|
private void barbarSetCoord_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var minX = (double)_qAxisX.WholeRange.MinValue;
|
var maxX = (double)_qAxisX.WholeRange.MaxValue;
|
|
var minY = (double)_AxisY.WholeRange.MinValue;
|
var maxY = (double)_AxisY.WholeRange.MaxValue;
|
|
var dlg = new SetCoordDlg();
|
dlg.Set(minX, maxX, minY, maxY);
|
dlg.ReloadDataEvnet += (rangeArray) =>
|
{
|
_qAxisX.WholeRange.MinValue = rangeArray[0];
|
_qAxisX.WholeRange.MaxValue = rangeArray[1];
|
|
_AxisY.WholeRange.MinValue = rangeArray[2];
|
_AxisY.WholeRange.MaxValue = rangeArray[3];
|
};
|
dlg.ShowDialog();
|
}
|
|
|
/* public void SetColor()
|
{
|
if (_allAnaPoints == null || _allAnaPoints.Count < 1)
|
return;
|
var count = _allAnaPoints.Count;
|
for (int i = 0; i < count; i++)
|
{
|
var point = _allAnaPoints[i];
|
var month = point.Time.Month;
|
point.Color = Colors[month - 1];
|
}
|
}
|
|
private Color[] Colors =
|
{
|
Color.AliceBlue, Color.Aquamarine, Color.Bisque, Color.Black,
|
Color.Brown, Color.Chartreuse, Color.Chocolate, Color.CornflowerBlue,
|
Color.DarkOrange, Color.DarkTurquoise, Color.DimGray, Color.FloralWhite,
|
};
|
*/
|
|
|
}
|
}
|