using Yw.Ahart; 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.repImgCmbFeatType.Items.Add("穿过点", Yw.Ahart.eFeatType.Through, -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; }; this.Enabled = false; this.gridControl1.DoubleClick += GridControl1_DoubleClick; } private void GridControl1_DoubleClick(object sender, EventArgs e) { if (_vm_list == null || !_vm_list.Any()) { return; } var vm_list = _vm_list.Where(x => x.CurveType == eCurveType.QL).ToList(); var dlg = new TestDlg(); dlg.SetBindingData(vm_list); dlg.ShowDialog(); } private Yw.Ahart.eCurveType _edit_curve_type = Ahart.eCurveType.QL; private List _vm_list = null; /// /// 绑定数据 /// public void SetBindingData(List vm_list) { if (vm_list == null || !vm_list.Any()) { this.valveEditChart1.Clear(); return; } _vm_list = vm_list; if (!_vm_list.Exists(x => x.IsUpdate)) { _vm_list.First().IsUpdate = true; } this.repImgCmbCurveType.BeginInit(); this.repImgCmbCurveType.Items.Clear(); if (_vm_list.Exists(x => x.CurveType == Ahart.eCurveType.QL)) { _edit_curve_type = Ahart.eCurveType.QL; this.repImgCmbCurveType.Items.Add("流量损失", Yw.Ahart.eCurveType.QL, -1); } if (_vm_list.Exists(x => x.CurveType == Ahart.eCurveType.OL)) { _edit_curve_type = Ahart.eCurveType.OL; this.repImgCmbCurveType.Items.Add("开度损失", Yw.Ahart.eCurveType.OL, -1); } this.repImgCmbCurveType.EndInit(); this.barImgCmbCurveType.EditValue = _edit_curve_type; this.Enabled = true; } //定义点变换 private void ValveEditChart1_DefinePointChangedEvent1(List 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(); if (this.barImgCmbCurveSel.EditValue == null) { this.barImgCmbCurveSel.EditValue = first.Id; } else { SetChart(); } 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; var bol = PhartVerifyHelper.VerifyCount(feat_type, vm.DefPointList.Count); if (!bol) { e.Cancel = true; } } //拟合类型 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 def_pt_list = vm.DefPointList; var row = this.gridView1.GetCurrentViewModel(def_pt_list); if (row == null) return; var count = def_pt_list.Count - 1; var bol = PhartVerifyHelper.VerifyCount(vm.FeatType, count); if (!bol) return; def_pt_list.Remove(row); this.bindingSource1.ResetBindings(false); SetChart(); } //粘贴板覆盖 private void barBtnPastePlateCovering_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var vm = _vm_list?.Find(x => x.IsUpdate); if (vm == null) { this.valveEditChart1.Clear(); return; } List def_pt_list = vm.DefPointList; var row = this.gridView1.GetCurrentViewModel(def_pt_list); if (row == null) return; if (!ClipboardCurveTextUIHelper.CopyDouble(out List> list)) return; if (list == null || list.Count < 1) return; if (list.Count != 2) { TipFormHelper.ShowError("数据不完整"); return; } var cell_count = list.Count; var min_row_count = list.Min(x => x.Count); var pt_list = new List(min_row_count); for (int i = 0; i < min_row_count; i++) { var x = list[0][i]; var y = list[1][i]; if (x.HasValue && y.HasValue) { pt_list.Add(new Geometry.Point2d(x.Value, y.Value)); } } var bol = PhartVerifyHelper.VerifyCount(vm.FeatType, pt_list.Count); if (!bol) return; def_pt_list.Clear(); def_pt_list.AddRange(pt_list); this.bindingSource1.ResetBindings(false); SetChart(); } private void SetChart() { if (_vm_list == null || !_vm_list.Any()) return; 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); } /// /// 获取数据 /// public bool Get(out List vm_list) { vm_list = _vm_list; if (_vm_list == null || !_vm_list.Any()) return false; return true; } } }