using NetTaste;
|
|
namespace Yw.WinFrmUI.Phart
|
{
|
public partial class ValveChartExcelEditCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public ValveChartExcelEditCtrl()
|
{
|
InitializeComponent();
|
this.gridView1.SetDefaultEditView();
|
this.gridView1.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
|
|
this.repImgCmbCurveType.Items.Add("流量损失", Yw.Ahart.eCurveType.QL, -1);
|
this.repImgCmbCurveType.Items.Add("开度损失", Yw.Ahart.eCurveType.OL, -1);
|
|
this.repImgCmbFeatType.Items.Add("二次拟合", Yw.Ahart.eFeatType.Quadratic, -1);
|
this.repImgCmbFeatType.Items.Add("三次拟合", Yw.Ahart.eFeatType.Cubic, -1);
|
this.repImgCmbFeatType.Items.Add("四次拟合", Yw.Ahart.eFeatType.Quartic, -1);
|
this.repImgCmbFeatType.EditValueChanging += RepImgCmbFeatType_EditValueChanging;
|
|
this.repImgCmbEditModel.Items.Add("鼠标", 0, -1);
|
this.repImgCmbEditModel.Items.Add("键盘", 1, -1);
|
|
|
this.valveEditChart1.DefinePointChangedEvent += ValveEditChart1_DefinePointChangedEvent1;
|
this.valveEditChart1.SelectedPointIndexChangedEvent += (index) =>
|
{
|
this.gridView1.FocusedRowHandle = index;
|
};
|
|
}
|
|
private Yw.Ahart.eCurveType _edit_curve_type = Ahart.eCurveType.QL;
|
private List<ValveEditChartViewModel> _vm_list = null;
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(List<ValveEditChartViewModel> vm_list)
|
{
|
if (vm_list == null || !vm_list.Any())
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
|
_edit_curve_type = Ahart.eCurveType.QL;
|
_vm_list = vm_list;
|
if (!_vm_list.Exists(x => x.IsUpdate))
|
{
|
_vm_list.First().IsUpdate = true;
|
}
|
|
this.barImgCmbCurveType.EditValue = _edit_curve_type;
|
}
|
|
|
//定义点变换
|
private void ValveEditChart1_DefinePointChangedEvent1(List<Geometry.Point2d> def_pt_list)
|
{
|
var vm = _vm_list?.Find(x => x.IsUpdate);
|
if (vm == null)
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
vm.DefPointList = def_pt_list;
|
vm.IsUpdate = true;
|
SetChart();
|
}
|
|
|
//值变换
|
private void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
|
{
|
this.bindingSource1.ResetBindings(false);
|
SetChart();
|
}
|
|
//曲线类型
|
private void barImgCmbCurveType_EditValueChanged(object sender, EventArgs e)
|
{
|
_edit_curve_type = (Yw.Ahart.eCurveType)this.barImgCmbCurveType.EditValue;
|
var (axis_x_title, axis_y_title) = PhartAxisTitleHelper.Get(_edit_curve_type);
|
this.colX.Caption = axis_x_title;
|
this.colY.Caption = axis_y_title;
|
|
this.repImgCmbCurveSel.Items.Clear();
|
var vm_list = _vm_list?.Where(x => x.CurveType == _edit_curve_type).ToList();
|
if (vm_list == null || !vm_list.Any())
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
|
foreach (var vm in vm_list)
|
{
|
this.repImgCmbCurveSel.Items.Add(vm.Name, vm.Id, -1);
|
}
|
var first= vm_list.First();
|
this.barImgCmbCurveSel.EditValue = first.Id;
|
this.barFeatType.EditValue = first.FeatType;
|
this.barEditModel.EditValue = 0;
|
}
|
|
//曲线变换
|
private void barImgCmbCurveSel_EditValueChanged(object sender, EventArgs e)
|
{
|
var id = this.barImgCmbCurveSel.EditValue.ToString();
|
var vm = _vm_list?.Find(x => x.Id == id);
|
if (vm == null)
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
_vm_list.ForEach(x => x.IsUpdate = false);
|
vm.IsUpdate = true;
|
if (this.barFeatType.EditValue == null || vm.FeatType != (Yw.Ahart.eFeatType)this.barFeatType.EditValue)
|
{
|
this.barFeatType.EditValue = vm.FeatType;
|
}
|
else
|
{
|
SetChart();
|
}
|
}
|
|
//拟合类型
|
private void RepImgCmbFeatType_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
|
{
|
var vm = _vm_list?.Find(x => x.IsUpdate);
|
if (vm == null)
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
if (vm.DefPointList == null)
|
{
|
e.Cancel = true;
|
}
|
var feat_type = (Yw.Ahart.eFeatType)e.NewValue;
|
switch (feat_type)
|
{
|
case Ahart.eFeatType.Cubic:
|
{
|
if (vm.DefPointList.Count < 4)
|
{
|
TipFormHelper.ShowInfo("点数少于4个点");
|
e.Cancel = true;
|
}
|
}
|
break;
|
case Ahart.eFeatType.Through:
|
{
|
if (vm.DefPointList.Count < 1)
|
{
|
TipFormHelper.ShowInfo("点数少于1个点");
|
e.Cancel = true;
|
}
|
}
|
break;
|
case Ahart.eFeatType.Quadratic:
|
{
|
if (vm.DefPointList.Count < 3)
|
{
|
TipFormHelper.ShowInfo("点数少于3个点");
|
e.Cancel = true;
|
}
|
}
|
break;
|
case Ahart.eFeatType.Quartic:
|
{
|
if (vm.DefPointList.Count < 5)
|
{
|
TipFormHelper.ShowInfo("点数少于5个点");
|
e.Cancel = true;
|
}
|
}
|
break;
|
}
|
}
|
|
//拟合类型
|
private void barFeatType_EditValueChanged(object sender, EventArgs e)
|
{
|
var feat_type = (Yw.Ahart.eFeatType)this.barFeatType.EditValue;
|
var vm = _vm_list?.Find(x => x.IsUpdate);
|
if (vm == null)
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
vm.FeatType = feat_type;
|
SetChart();
|
|
}
|
|
//鼠标模式
|
private void barEditModel_EditValueChanged(object sender, EventArgs e)
|
{
|
var index = (int)this.barEditModel.EditValue;
|
this.valveEditChart1.MouseModel = index == 0;
|
}
|
|
|
//添加点
|
private void barAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var vm= _vm_list?.Find(x => x.IsUpdate);
|
if (vm==null)
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
|
if (vm.DefPointList == null)
|
return;
|
double x = 0;
|
double y = 1;
|
if (vm.DefPointList.Count > 0)
|
{
|
x = vm.DefPointList.Last().X;
|
y = vm.DefPointList.Last().Y;
|
}
|
vm.DefPointList.Add(new Geometry.Point2d(x, y));
|
this.bindingSource1.ResetBindings(false);
|
this.gridView1.FocusedRowHandle = vm.DefPointList.Count - 1;
|
SetChart();
|
}
|
|
|
//删除点
|
private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var vm = _vm_list?.Find(x => x.IsUpdate);
|
if (vm == null)
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
List<Yw.Geometry.Point2d> def_pt_list = vm.DefPointList;
|
var row = this.gridView1.GetCurrentViewModel(def_pt_list);
|
if (row == null)
|
return;
|
var count = vm.DefPointList.Count - 1;
|
switch (vm.FeatType)
|
{
|
case Ahart.eFeatType.Cubic:
|
{
|
if (count < 4)
|
{
|
TipFormHelper.ShowInfo("点数少于4个点");
|
return;
|
}
|
}
|
break;
|
case Ahart.eFeatType.Through:
|
{
|
if (count < 1)
|
{
|
TipFormHelper.ShowInfo("点数少于1个点");
|
return;
|
}
|
}
|
break;
|
case Ahart.eFeatType.Quadratic:
|
{
|
if (count < 3)
|
{
|
TipFormHelper.ShowInfo("点数少于3个点");
|
return;
|
}
|
}
|
break;
|
case Ahart.eFeatType.Quartic:
|
{
|
if (count < 5)
|
{
|
TipFormHelper.ShowInfo("点数少于5个点");
|
return;
|
}
|
}
|
break;
|
}
|
def_pt_list.Remove(row);
|
this.bindingSource1.ResetBindings(false);
|
SetChart();
|
}
|
|
private void SetChart()
|
{
|
var vm = _vm_list?.Find(x => x.IsUpdate);
|
if (vm == null)
|
{
|
this.valveEditChart1.Clear();
|
return;
|
}
|
vm.FitPointList = vm.DefPointList.GetPointList(vm.FeatType,50);
|
this.bindingSource1.DataSource = vm.DefPointList;
|
this.bindingSource1.ResetBindings(false);
|
this.valveEditChart1.SetBindingData(_vm_list);
|
}
|
|
|
/// <summary>
|
/// 获取数据
|
/// </summary>
|
public bool Get(out List<ValveEditChartViewModel> vm_list)
|
{
|
vm_list = _vm_list;
|
if (_vm_list == null || !_vm_list.Any())
|
return false;
|
return true;
|
}
|
|
|
}
|
|
}
|