using DevExpress.XtraEditors;
|
using IStation.Untity;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI.Curve
|
{
|
/// <summary>
|
/// 图片导入曲线控件窗体
|
/// 下次优化
|
/// 1.上一步下一步 记住选择范围
|
/// 2.曲线来源带入
|
/// 3.保存
|
/// 4.代码整理
|
/// </summary>
|
public partial class SetCurveInfoByPictureDlg : DevExpress.XtraBars.Ribbon.RibbonForm
|
{
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public SetCurveInfoByPictureDlg()
|
{
|
InitializeComponent();
|
InitialSelDisplayMode();
|
InitialCurveFitType();
|
InitialUnitQ();
|
InitialEvent();
|
}
|
|
/// <summary>
|
/// 数据返回事件
|
/// </summary>
|
public event Action<Model.FeatCurvePointGroup, Model.FeatCurveExpressGroup> ReloadDataEvent;
|
private List<Model.CurvePoint> _picQHPoints = null;
|
private List<Model.CurvePoint> _picQEPoints = null;
|
private List<Model.CurvePoint> _picQPPoints = null;
|
private Model.eCurveFitType _fitTypeQH = Model.eCurveFitType.ConicCurve;
|
private Model.eCurveFitType _fitTypeQE = Model.eCurveFitType.ConicCurve;
|
private Model.eCurveFitType _fitTypeQP = Model.eCurveFitType.ConicCurve;
|
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
LoadRibPage(this.PageQH);
|
}
|
|
#region 初始化事件
|
/// <summary>
|
/// 初始化事件
|
/// </summary>
|
private void InitialEvent()
|
{
|
this.setCurveInfoByPictureCtrl1.AllowSelBoundaryEvent += SetCurveInfoByPictureCtrl_AllowSelBoundaryEvent;
|
this.setCurveInfoByPictureCtrl1.AllowSelPickPointEvent += SetCurveInfoByPictureCtrl1_AllowSelPickPointEvent;
|
}
|
|
|
//允许设置坐标事件
|
private void SetCurveInfoByPictureCtrl_AllowSelBoundaryEvent(bool obj)
|
{
|
this.barCekSetCoord.Checked = obj;
|
}
|
|
//允许设置打点事件
|
private void SetCurveInfoByPictureCtrl1_AllowSelPickPointEvent(bool obj)
|
{
|
this.barCekPickPoint.Checked = obj;
|
}
|
#endregion
|
|
#region 初始化下拉按钮
|
|
/// <summary>
|
/// 初始化图片选中方式按钮
|
/// </summary>
|
private void InitialSelDisplayMode()
|
{
|
foreach (PictureBoxSizeMode item in Enum.GetValues(typeof(PictureBoxSizeMode)))
|
{
|
var btn = new DevExpress.XtraBars.BarCheckItem();
|
btn.Caption = item.ToString();
|
btn.Id = (int)item;
|
btn.Name = $"barBtn{btn.Caption}";
|
btn.ItemClick += (object sender, DevExpress.XtraBars.ItemClickEventArgs e) =>
|
{
|
foreach (DevExpress.XtraBars.BarCheckItemLink link in barSelDisplayMode.ItemLinks)
|
{
|
((DevExpress.XtraBars.BarCheckItem)link.Item).Checked = false;
|
}
|
var current_btn = (DevExpress.XtraBars.BarCheckItem)e.Item;
|
current_btn.Checked = true;
|
this.setCurveInfoByPictureCtrl1.SetPictureSizeMode((PictureBoxSizeMode)current_btn.Id);
|
};
|
if (item == PictureBoxSizeMode.StretchImage)
|
{
|
btn.Checked = true;
|
this.setCurveInfoByPictureCtrl1.SetPictureSizeMode(item);
|
}
|
this.barSelDisplayMode.AddItem(btn);
|
}
|
}
|
|
/// <summary>
|
/// 初始化曲线拟合方式
|
/// </summary>
|
private void InitialCurveFitType()
|
{
|
foreach (Model.eCurveFitType item in Enum.GetValues(typeof(Model.eCurveFitType)))
|
{
|
var btn = new DevExpress.XtraBars.BarCheckItem();
|
btn.Caption = item.GetDisplayText();
|
btn.Id = (int)item;
|
btn.Name = $"barBtn{btn.Caption}";
|
btn.ItemClick += (object sender, DevExpress.XtraBars.ItemClickEventArgs e) =>
|
{
|
foreach (DevExpress.XtraBars.BarCheckItemLink link in barSubCurveFitType.ItemLinks)
|
{
|
((DevExpress.XtraBars.BarCheckItem)link.Item).Checked = false;
|
}
|
var current_btn = (DevExpress.XtraBars.BarCheckItem)e.Item;
|
current_btn.Checked = true;
|
this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType = (Model.eCurveFitType)current_btn.Id;
|
this.setCurveInfoByPictureCtrl1.RefreshPictureShape();
|
};
|
if (item == Model.eCurveFitType.CubicCurve)
|
{
|
btn.Checked = true;
|
this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType = item;
|
}
|
this.barSubCurveFitType.AddItem(btn);
|
}
|
}
|
|
/// <summary>
|
/// 初始化流量单位
|
/// </summary>
|
private void InitialUnitQ()
|
{
|
foreach (Unit.eUnitQ item in Enum.GetValues(typeof(Unit.eUnitQ)))
|
{
|
var btn = new DevExpress.XtraBars.BarCheckItem();
|
btn.Caption = item.ToString();
|
btn.Id = (int)item;
|
btn.Name = $"barBtn{btn.Caption}";
|
btn.ItemClick += (object sender, DevExpress.XtraBars.ItemClickEventArgs e) =>
|
{
|
foreach (DevExpress.XtraBars.BarCheckItemLink link in barSubUnitQ.ItemLinks)
|
{
|
((DevExpress.XtraBars.BarCheckItem)link.Item).Checked = false;
|
}
|
var current_btn = (DevExpress.XtraBars.BarCheckItem)e.Item;
|
current_btn.Checked = true;
|
this.setCurveInfoByPictureCtrl1.UnitQ = (Unit.eUnitQ)current_btn.Id;
|
};
|
if (item == Unit.eUnitQ.M3H)
|
{
|
btn.Checked = true;
|
this.setCurveInfoByPictureCtrl1.UnitQ = item;
|
}
|
this.barSubUnitQ.AddItem(btn);
|
}
|
}
|
#endregion
|
|
/// <summary>
|
/// 初始化图表坐标
|
/// </summary>
|
private bool InitialChartCoord()
|
{
|
switch (this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve)
|
{
|
case Model.eFeatCurveType.QH:
|
{
|
if (this.barTxtMaxQ.EditValue == null || this.barTxtMinQ.EditValue == null || this.barTxtMaxH.EditValue == null || this.barTxtMinH.EditValue == null)
|
{
|
XtraMessageBox.Show("请将输入坐标!");
|
return false;
|
}
|
this.setCurveInfoByPictureCtrl1.ChartMaxX = Convert.ToDouble(this.barTxtMaxQ.EditValue);
|
this.setCurveInfoByPictureCtrl1.ChartMinX = Convert.ToDouble(this.barTxtMinQ.EditValue);
|
this.setCurveInfoByPictureCtrl1.ChartMaxY = Convert.ToDouble(this.barTxtMaxH.EditValue);
|
this.setCurveInfoByPictureCtrl1.ChartMinY = Convert.ToDouble(this.barTxtMinH.EditValue);
|
}
|
break;
|
case Model.eFeatCurveType.QE:
|
{
|
if (this.barTxtMaxE.EditValue == null || this.barTxtMinE.EditValue == null)
|
{
|
XtraMessageBox.Show("请将输入坐标!");
|
return false;
|
}
|
this.setCurveInfoByPictureCtrl1.ChartMaxY = Convert.ToDouble(this.barTxtMaxE.EditValue);
|
this.setCurveInfoByPictureCtrl1.ChartMinY = Convert.ToDouble(this.barTxtMinE.EditValue);
|
}
|
break;
|
case Model.eFeatCurveType.QP:
|
{
|
if (this.barTxtMaxP.EditValue == null || this.barTxtMinP.EditValue == null)
|
{
|
XtraMessageBox.Show("请将输入坐标!");
|
return false;
|
}
|
this.setCurveInfoByPictureCtrl1.ChartMaxY = Convert.ToDouble(this.barTxtMaxP.EditValue);
|
this.setCurveInfoByPictureCtrl1.ChartMinY = Convert.ToDouble(this.barTxtMinP.EditValue);
|
}
|
break;
|
}
|
return true;
|
}
|
|
//打开文件
|
private void barBtnOpenFile_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var dlg = new System.Windows.Forms.OpenFileDialog();
|
dlg.Filter = "*.BMP;*.JPG;*.GIF;*.PNG|*.BMP;*.JPG;*.GIF;*.PNG";
|
DialogResult ret = dlg.ShowDialog();
|
if (ret != System.Windows.Forms.DialogResult.OK)
|
return;
|
this.setCurveInfoByPictureCtrl1.SetBindingData(dlg.FileName);
|
}
|
|
|
#region 基础操作
|
/// <summary>
|
/// 设置坐标
|
/// </summary>
|
private void barCekSetCoord_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.barCekSetCoord.Checked)
|
this.setCurveInfoByPictureCtrl1.StartSelectionRange();
|
}
|
|
/// <summary>
|
/// 获取点
|
/// </summary>
|
private void barCekPickPoint_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.barCekPickPoint.Checked)
|
{
|
if (!(this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve == Model.eFeatCurveType.QE && this.barCheckItem打点等效线.Checked))
|
{
|
if (!InitialChartCoord())
|
{
|
this.barCekPickPoint.Checked = false;
|
return;
|
}
|
}
|
|
if (!this.setCurveInfoByPictureCtrl1.StartPickPoint())
|
{
|
this.barCekPickPoint.Checked = false;
|
this.setCurveInfoByPictureCtrl1.EndPickPoint();
|
return;
|
}
|
}
|
else
|
{
|
this.setCurveInfoByPictureCtrl1.EndPickPoint();
|
}
|
}
|
|
/// <summary>
|
/// 清空点
|
/// </summary>
|
private void barBtnClear_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.setCurveInfoByPictureCtrl1.ClearPickPoint();
|
}
|
|
/// <summary>
|
/// 刷新
|
/// </summary>
|
private void barBtnReload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.setCurveInfoByPictureCtrl1.RefreshPictureShape();
|
}
|
#endregion
|
|
/// <summary>
|
/// 加载页面
|
/// </summary>
|
/// <param name="selPage">当前页</param>
|
private void LoadRibPage(DevExpress.XtraBars.Ribbon.RibbonPage selPage)
|
{
|
selPage.Visible = true;
|
foreach (DevExpress.XtraBars.Ribbon.RibbonPage tab in this.RibbCtrl.Pages)
|
{
|
if (tab != selPage)
|
tab.Visible = false;
|
}
|
if (selPage == this.PageQH)
|
{
|
this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve = Model.eFeatCurveType.QH;
|
if (_picQHPoints != null)
|
this.setCurveInfoByPictureCtrl1.RefreshPictureShape(_picQHPoints);
|
}
|
else if (selPage == this.PageQE)
|
{
|
this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve = Model.eFeatCurveType.QE;
|
if (_picQEPoints != null)
|
this.setCurveInfoByPictureCtrl1.RefreshPictureShape(_picQEPoints);
|
}
|
else if (selPage == this.PageQP)
|
{
|
this.setCurveInfoByPictureCtrl1.CurrentCaptureCruve = Model.eFeatCurveType.QP;
|
if (_picQPPoints != null)
|
this.setCurveInfoByPictureCtrl1.RefreshPictureShape(_picQPPoints);
|
}
|
this.RibbCtrl.SelectedPage = selPage;
|
}
|
|
/// <summary>
|
/// 上一步
|
/// </summary>
|
private void barBtnPreviousStep_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.RibbCtrl.SelectedPage == this.PageQE)
|
{
|
this.LoadRibPage(this.PageQH);
|
}
|
else if (this.RibbCtrl.SelectedPage == this.PageQP)
|
{
|
this.LoadRibPage(this.PageQE);
|
}
|
}
|
|
/// <summary>
|
/// 下一步
|
/// </summary>
|
private void barBtnNextStep_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (this.RibbCtrl.SelectedPage == this.PageQH)
|
{
|
if (!SaveQH())
|
return;
|
this.LoadRibPage(this.PageQE);
|
}
|
else if (this.RibbCtrl.SelectedPage == this.PageQE)
|
{
|
if (!SaveQE())
|
return;
|
this.LoadRibPage(this.PageQP);
|
}
|
}
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
private void barBtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
if (XtraMessageBox.Show("是否导入?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK)
|
return;
|
if (!SaveQP())
|
return;
|
#region 临时作废 后续再维护
|
//var unitQ = this.setCurveInfoByPictureCtrl1.UnitQ;
|
|
//var pointsQH = new List<Model.CurvePoint>();
|
//var pointsQE = new List<Model.CurvePoint>();
|
//var pointsQP = new List<Model.CurvePoint>();
|
|
//double rQmin = 0, rQmax = 0;
|
|
//var picPointInfoQH = _picQHPoints;
|
//var picPointInfoQE = _picQEPoints;
|
//var picPointInfoQP = _picQPPoints;
|
|
//if (this.setCurveInfoByPictureCtrl1.ChartMinX == 0)
|
// rQmin = 0;
|
//else
|
// rQmin = _picQHPoints.Min(x => x.X);
|
|
//rQmax = _picQHPoints.Max(x => x.X);
|
////换算单位
|
//List<Model.CurvePoint> m3hPointInfoQH = null;
|
//List<Model.CurvePoint> m3hPointInfoQE = null;
|
//List<Model.CurvePoint> m3hPointInfoQP = null;
|
|
//if (unitQ == Unit.eUnitQ.M3H)
|
//{
|
// m3hPointInfoQH = picPointInfoQH;
|
// m3hPointInfoQE = picPointInfoQE;
|
// m3hPointInfoQP = picPointInfoQP;
|
//}
|
//else
|
//{
|
// rQmin = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, rQmin);
|
// rQmax = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, rQmax);
|
// m3hPointInfoQH = ToM3H(unitQ, picPointInfoQH);
|
// m3hPointInfoQE = ToM3H(unitQ, picPointInfoQE);
|
// m3hPointInfoQP = ToM3H(unitQ, picPointInfoQP);
|
//}
|
|
//if (_fitTypeQH == Model.eCurveFitType.ThroughPoint)
|
//{
|
// if (m3hPointInfoQP == null)
|
// {
|
// pointsQE = m3hPointInfoQE;
|
// pointsQH = m3hPointInfoQH;
|
|
// pointsQP = new List<Model.CurvePoint>();
|
// for (int i = 0; i < m3hPointInfoQE.Count(); i++)
|
// {
|
// var Q = m3hPointInfoQE[i].X;
|
// List<Model.CurvePoint> resultH = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQH, Q);
|
// if (resultH == null || resultH.Count == 0)
|
// continue;
|
// var H = resultH.Last().Y;
|
// var E = m3hPointInfoQE[i].Y;
|
// var P = Model.CurveCalcuHelper.CalculateP(Q, H, E);
|
// pointsQP.Add(new Model.CurvePoint(Q, P));
|
// }
|
// }
|
|
// double startE = 0;//起始点
|
// if (rQmin > 0.2)
|
// startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, rQmin);
|
// else
|
// startE = 0;
|
// pointsQE.Insert(0, new Model.CurvePoint(rQmin, startE));
|
//}
|
//else
|
//{
|
// //均匀插值点,计算点坐标,首尾2点用延长的方法得到
|
// int insert_num = 15;
|
// double space = (rQmax - rQmin) / (insert_num - 1);
|
// int i = 0;
|
// double Q = rQmin;
|
// double H, E, P;
|
// for (i = 1; i < insert_num - 1; i++)
|
// {
|
// Q = Q + space;
|
// List<Model.CurvePoint> resultH = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQH, Q);
|
// if (resultH == null || resultH.Count == 0)
|
// continue;
|
// H = resultH.First().Y;
|
// pointsQH.Add(new Model.CurvePoint(Q, H));
|
|
// if (picPointInfoQE != null)
|
// {
|
// List<Model.CurvePoint> resultE = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQE, Q);
|
// if (resultE == null || resultE.Count == 0)
|
// continue;
|
// E = resultE.First().Y;
|
// P = ViewModel.Model.CurveCalcuHelper.CalculateP(Q, H, E);
|
// }
|
// else
|
// {
|
// List<Model.CurvePoint> resultP = Model.FitCurveHelper.GetInterPointY(m3hPointInfoQP, Q);
|
// if (resultP == null || resultP.Count == 0)
|
// continue;
|
// P = resultP.First().Y;
|
// E = ViewModel.Model.CurveCalcuHelper.CalculateE(Q, H, P);
|
// }
|
|
// pointsQP.Add(new Model.CurvePoint(Q, P));
|
// pointsQE.Add(new Model.CurvePoint(Q, E));
|
// }
|
|
// if (!(this.barCekAutoAnalyQP.Checked && this.barCekAutoAnalyQP.Checked))
|
// {
|
// if (pointsQH.Count < 3 || pointsQE.Count < 3 || pointsQP.Count < 3)
|
// {
|
// pointsQH = null;
|
// pointsQE = null;
|
// pointsQP = null;
|
// XtraMessageBox.Show("未导入足够多的性能曲线点");
|
// return;
|
// }
|
// }
|
// else
|
// {
|
// if (pointsQH.Count < 3)
|
// {
|
// XtraMessageBox.Show("未导入足够多的性能曲线点");
|
// return;
|
// }
|
// }
|
|
// #region 首尾两点的处理:因为首尾2点按流量扬程获取范围,而点击不一定正好首尾2点流量一样
|
// //流量扬程首尾两点
|
// double startH = Model.CurveLineHelper.GetYbyX(pointsQH[0].X, pointsQH[0].Y, pointsQH[1].X, pointsQH[1].Y, rQmin);
|
// pointsQH.Insert(0, new Model.CurvePoint(rQmin, startH));
|
|
// int point_num = pointsQH.Count;//不一定和insert_num一样
|
// double endH = Model.CurveLineHelper.GetYbyX(pointsQH[point_num - 2].X, pointsQH[point_num - 2].Y,
|
// pointsQH[point_num - 1].X, pointsQH[point_num - 1].Y, rQmax);
|
// pointsQH.Add(new Model.CurvePoint(rQmax, endH));
|
|
// if (pointsQE != null && pointsQE.Count > 0)
|
// {
|
// //流量效率首尾两点
|
// double startE = 0;//起始点
|
// if (rQmin > 0.2)
|
// startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, rQmin);
|
// else
|
// startE = 0;
|
// pointsQE.Insert(0, new Model.CurvePoint(rQmin, startE));
|
|
// point_num = pointsQE.Count;//末尾点
|
// double endE = Model.CurveLineHelper.GetYbyX(pointsQE[point_num - 2].X, pointsQE[point_num - 2].Y,
|
// pointsQE[point_num - 1].X, pointsQE[point_num - 1].Y, rQmax);
|
// pointsQE.Add(new Model.CurvePoint(rQmax, endE));
|
// }
|
|
// if (pointsQE != null && pointsQE.Count > 0)
|
// {
|
// //流量功率首尾两点
|
// double startP = Model.CurveLineHelper.GetYbyX(pointsQP[0].X, pointsQP[0].Y, pointsQP[1].X, pointsQP[1].Y, rQmin);
|
// pointsQP.Insert(0, new Model.CurvePoint(rQmin, startP));
|
|
// point_num = pointsQP.Count;
|
// double endP = Model.CurveLineHelper.GetYbyX(pointsQP[point_num - 2].X, pointsQP[point_num - 2].Y,
|
// pointsQP[point_num - 1].X, pointsQP[point_num - 1].Y, rQmax);
|
// pointsQP.Add(new Model.CurvePoint(rQmax, endP));
|
// }
|
|
// #endregion
|
//}
|
|
////圆整
|
//pointsQH = Regulate(pointsQH, 2);
|
//pointsQE = Regulate(pointsQE, 2);
|
//pointsQP = Regulate(pointsQP, 2);
|
|
//var pointListGroup = new Model.FeatCurvePointGroup();
|
//pointListGroup.PointQH = pointsQH;
|
//pointListGroup.PointQE = pointsQE;
|
//pointListGroup.PointQP = pointsQP;
|
|
//var curveExpressGroup = new Model.FeatCurveExpressGroup();
|
//curveExpressGroup.CurveQH = new Model.CurveExpress(pointsQH, _fitTypeQH);
|
//curveExpressGroup.CurveQE = new Model.CurveExpress(pointsQE, _fitTypeQE);
|
//curveExpressGroup.CurveQP = new Model.CurveExpress(pointsQP, _fitTypeQP);
|
|
//this.ReloadDataEvent?.Invoke(pointListGroup, curveExpressGroup);
|
//this.DialogResult = DialogResult.OK;
|
//this.Close();
|
#endregion
|
Save();
|
}
|
|
/// <summary>
|
/// 保存
|
/// </summary>
|
private void Save()
|
{
|
var unitQ = this.setCurveInfoByPictureCtrl1.UnitQ;
|
|
List<Model.CurvePoint> pointsQH = new List<Model.CurvePoint>();
|
List<Model.CurvePoint> pointsQE = new List<Model.CurvePoint>();
|
List<Model.CurvePoint> pointsQP = new List<Model.CurvePoint>();
|
|
double MinQ = 0;
|
double MaxQ = 0;
|
|
if (this.setCurveInfoByPictureCtrl1.ChartMinX == 0)
|
MinQ = 0;
|
else
|
MinQ = _picQHPoints.Min(x => x.X);
|
|
MaxQ = _picQHPoints.Max(x => x.X);
|
|
//换算单位
|
if (unitQ != Unit.eUnitQ.M3H)
|
{
|
MinQ = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, MinQ);
|
MaxQ = Unit.UnitQHelper.Convert(unitQ, Unit.eUnitQ.M3H, MaxQ);
|
_picQHPoints = ToM3H(unitQ, _picQHPoints);
|
_picQEPoints = ToM3H(unitQ, _picQEPoints);
|
_picQPPoints = ToM3H(unitQ, _picQPPoints);
|
}
|
|
|
|
/*if (_fitTypeQH == Model.eCurveFitType.ThroughPoint)
|
{
|
if (_picQPPoints == null || _picQPPoints.Count < 1)
|
{
|
pointsQH = _picQHPoints;
|
pointsQE = _picQEPoints;
|
pointsQP = new List<Model.CurvePoint>();
|
for (int i = 0; i < _picQEPoints.Count(); i++)
|
{
|
var Q = _picQEPoints[i].X;
|
List<Model.CurvePoint> resultH = Model.FitCurveHelper.GetInterPointY(_picQHPoints, Q);
|
if (resultH == null || resultH.Count == 0)
|
continue;
|
var H = resultH.Last().Y;
|
var E = _picQEPoints[i].Y;
|
var P = Model.CurveCalcuHelper.CalculateP(Q, H, E);
|
pointsQP.Add(new Model.CurvePoint(Q, P));
|
}
|
}
|
else
|
{
|
pointsQH = _picQHPoints;
|
pointsQE = _picQEPoints;
|
pointsQP = _picQPPoints;
|
}
|
|
double startE = 0;//起始点
|
if (MinQ > 0.2)
|
startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, MinQ);
|
else
|
startE = 0;
|
pointsQE.Insert(0, new Model.CurvePoint(MinQ, startE));
|
}
|
else
|
{*/
|
//均匀插值点,计算点坐标,首尾2点用延长的方法得到
|
int insert_num = 15;
|
double space = (MaxQ - MinQ) / (insert_num - 1);
|
int i = 0;
|
double Q = MinQ;
|
double H, E = 0, P = 0;
|
for (i = 1; i < insert_num - 1; i++)
|
{
|
if (i == insert_num - 2)
|
{
|
|
}
|
Q = Q + space;
|
H = Model.FitCurveHelper.GetFitPointY(_picQHPoints, _fitTypeQH, Q);
|
pointsQH.Add(new Model.CurvePoint(Q, H));
|
|
if (!(this.barCekAutoAnalyQP.Checked && this.barCekAutoAnalyQP.Checked))
|
{
|
E = Model.FitCurveHelper.GetFitPointY(_picQEPoints, _fitTypeQE, Q);
|
P = Model.FitCurveHelper.GetFitPointY(_picQPPoints, _fitTypeQP, Q);
|
}
|
else if (this.barCekAutoAnalyQP.Checked)
|
{
|
E = Model.FitCurveHelper.GetFitPointY(_picQEPoints, _fitTypeQE, Q);
|
P = Model.CurveCalcuHelper.CalculateP(Q, H, E);
|
}
|
else if (this.barCekAutoAnalyQE.Checked)
|
{
|
if (_picQPPoints == null)
|
continue;
|
P = Model.FitCurveHelper.GetFitPointY(_picQPPoints, _fitTypeQP, Q);
|
E = Model.CurveCalcuHelper.CalculateE(Q, H, P);
|
}
|
|
|
pointsQP.Add(new Model.CurvePoint(Q, P));
|
pointsQE.Add(new Model.CurvePoint(Q, E));
|
}
|
|
|
|
if (!(this.barCekAutoAnalyQP.Checked && this.barCekAutoAnalyQP.Checked))
|
{
|
if (pointsQH.Count < 3 || pointsQE.Count < 3 || pointsQP.Count < 3)
|
{
|
pointsQH = null;
|
pointsQE = null;
|
pointsQP = null;
|
XtraMessageBox.Show("未导入足够多的性能曲线点");
|
return;
|
}
|
}
|
else
|
{
|
if (pointsQH.Count < 3)
|
{
|
XtraMessageBox.Show("未导入足够多的性能曲线点");
|
return;
|
}
|
}
|
#region 首尾两点的处理:因为首尾2点按流量扬程获取范围,而点击不一定正好首尾2点流量一样
|
//流量扬程首尾两点
|
double startH = Model.CurveLineHelper.GetYbyX(pointsQH[0].X, pointsQH[0].Y, pointsQH[1].X, pointsQH[1].Y, MinQ);
|
pointsQH.Insert(0, new Model.CurvePoint(MinQ, startH));
|
|
int point_num = pointsQH.Count;//不一定和insert_num一样
|
double endH = Model.CurveLineHelper.GetYbyX(pointsQH[point_num - 2].X, pointsQH[point_num - 2].Y,
|
pointsQH[point_num - 1].X, pointsQH[point_num - 1].Y, MaxQ);
|
pointsQH.Add(new Model.CurvePoint(MaxQ, endH));
|
|
if (pointsQE != null && pointsQE.Count > 0)
|
{
|
//流量效率首尾两点
|
double startE = 0;//起始点
|
if (MinQ > 0.2)
|
startE = Model.CurveLineHelper.GetYbyX(pointsQE[0].X, pointsQE[0].Y, pointsQE[1].X, pointsQE[1].Y, MinQ);
|
else
|
startE = 0;
|
pointsQE.Insert(0, new Model.CurvePoint(MinQ, startE));
|
|
point_num = pointsQE.Count;//末尾点
|
double endE = Model.CurveLineHelper.GetYbyX(pointsQE[point_num - 2].X, pointsQE[point_num - 2].Y,
|
pointsQE[point_num - 1].X, pointsQE[point_num - 1].Y, MaxQ);
|
pointsQE.Add(new Model.CurvePoint(MaxQ, endE));
|
}
|
|
if (pointsQP != null && pointsQP.Count > 0)
|
{
|
//流量功率首尾两点
|
double startP = Model.CurveLineHelper.GetYbyX(pointsQP[0].X, pointsQP[0].Y, pointsQP[1].X, pointsQP[1].Y, MinQ);
|
pointsQP.Insert(0, new Model.CurvePoint(MinQ, startP));
|
|
point_num = pointsQP.Count;
|
double endP = Model.CurveLineHelper.GetYbyX(pointsQP[point_num - 2].X, pointsQP[point_num - 2].Y,
|
pointsQP[point_num - 1].X, pointsQP[point_num - 1].Y, MaxQ);
|
pointsQP.Add(new Model.CurvePoint(MaxQ, endP));
|
}
|
#endregion
|
//}
|
|
//圆整
|
pointsQH = Regulate(pointsQH, 2);
|
pointsQE = Regulate(pointsQE, 2);
|
pointsQP = Regulate(pointsQP, 2);
|
|
var pointListGroup = new Model.FeatCurvePointGroup();
|
pointListGroup.PointQH = pointsQH;
|
pointListGroup.PointQE = pointsQE;
|
pointListGroup.PointQP = pointsQP;
|
|
var curveExpressGroup = new Model.FeatCurveExpressGroup();
|
curveExpressGroup.CurveQH = new Model.CurveExpress(pointsQH, _fitTypeQH, true);
|
curveExpressGroup.CurveQE = new Model.CurveExpress(pointsQE, _fitTypeQE, true);
|
//_fitTypeQP = Model.eCurveFitType.ThroughPoint;
|
curveExpressGroup.CurveQP = new Model.CurveExpress(pointsQP, _fitTypeQP, true);
|
|
this.ReloadDataEvent?.Invoke(pointListGroup, curveExpressGroup);
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
#region 保存
|
/// <summary>
|
/// 保存扬程线
|
/// </summary>
|
private bool SaveQH()
|
{
|
_fitTypeQH = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
|
if (!this.setCurveInfoByPictureCtrl1.GetPicPointInCurve(out List<Model.CurvePoint> QH))
|
return false;
|
_picQHPoints = QH;
|
return true;
|
}
|
|
/// <summary>
|
/// 保存效率线
|
/// </summary>
|
private bool SaveQE()
|
{
|
_picQEPoints = null;
|
_fitTypeQE = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
|
if (!this.barCekAutoAnalyQE.Checked)
|
{
|
if (!this.setCurveInfoByPictureCtrl1.GetPicPointInCurve(out List<Model.CurvePoint> QE))
|
return false;
|
_picQEPoints = QE;
|
}
|
return true;
|
}
|
|
/// <summary>
|
/// 保存功率线
|
/// </summary>
|
private bool SaveQP()
|
{
|
_picQPPoints = null;
|
_fitTypeQP = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
|
if (!this.barCekAutoAnalyQP.Checked)
|
{
|
if (!this.setCurveInfoByPictureCtrl1.GetPicPointInCurve(out List<Model.CurvePoint> QP))
|
return false;
|
var fitType = this.setCurveInfoByPictureCtrl1.CurrentCaptureCruveFitType;
|
_picQPPoints = QP;
|
}
|
return true;
|
}
|
#endregion
|
|
/// <summary>
|
/// 打点等效线
|
/// </summary>
|
private void barCheckItem打点等效线_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
this.setCurveInfoByPictureCtrl1.IsCaputueEtaPtInEqupCurve = this.barCheckItem打点等效线.Checked;
|
}
|
|
private List<Model.CurvePoint> ToM3H(Unit.eUnitQ unit, List<Model.CurvePoint> points)
|
{
|
if (unit == Unit.eUnitQ.M3H)
|
{
|
return points;
|
}
|
|
if (points == null)
|
{
|
return null;
|
}
|
|
var list = new List<Model.CurvePoint>();
|
for (int i = 0; i < points.Count; i++)
|
{
|
var point = new Model.CurvePoint(points[i]);
|
point.X = Unit.UnitQHelper.Convert(unit, Unit.eUnitQ.M3H, point.X);
|
list.Add(point);
|
}
|
return list;
|
}
|
|
//四舍五入圆整,如 0.44 -> 0.4 , 0.46 -> 0.5//flag--小数点后位数
|
public static List<Model.CurvePoint> Regulate(List<Model.CurvePoint> inPoints, int flag)
|
{
|
if (inPoints == null)
|
return null;
|
List<Model.CurvePoint> outPoints = new List<Model.CurvePoint>();
|
for (int i = 0; i < inPoints.Count(); i++)
|
{
|
outPoints.Add(new Model.CurvePoint(Regulate(inPoints[i].X, flag), Regulate(inPoints[i].Y, flag)));
|
}
|
return outPoints;
|
}
|
|
//四舍五入圆整,如 0.44 -> 0.4 , 0.46 -> 0.5//flag--小数点后位数
|
public static double Regulate(double v, int flag)
|
{
|
bool isNegative = false;
|
//如果是负数
|
if (v < 0)
|
{
|
isNegative = true;
|
v = Math.Abs(v);
|
}
|
else
|
{
|
isNegative = false;
|
}
|
|
double value = Math.Round(v, flag);
|
if (isNegative)
|
{
|
value = -value;
|
}
|
return value;
|
}
|
|
private void barCekAutoAnalyQP_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
|
}
|
}
|
}
|