| | |
| | | public event Action<int> SelectedPointIndexChangedEvent; |
| | | #endregion |
| | | |
| | | #region Initial |
| | | #region Private Initial |
| | | |
| | | /// <summary> |
| | | /// 初始化图表 |
| | |
| | | |
| | | #endregion Initial |
| | | |
| | | #region SetBindingData |
| | | #region Private Chart Event |
| | | |
| | | private int _pick_point_index = -1; |
| | | private void chartControl1_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | return; |
| | | var hitInfo = chartControl1.CalcHitInfo(e.Location); |
| | | _pick_point_index = -1; |
| | | if (e.Button == MouseButtons.Left) |
| | | { |
| | | if (hitInfo.InSeries && hitInfo.Series != _series_edit_pt) |
| | | { |
| | | return; |
| | | } |
| | | if (hitInfo.InSeriesPoint && hitInfo.SeriesPoint.Tag is int index) |
| | | { |
| | | _pick_point_index = index; |
| | | this.SelectedPointIndexChangedEvent?.Invoke(_pick_point_index); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private void chartControl1_MouseMove(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var diagram_coordinates = _diagram.PointToDiagram(e.Location); |
| | | AxisYBase axis_y = null; |
| | | if (_edit_curve_type == Ahart.eCurveType.QL) |
| | | { |
| | | axis_y = _axis_y_head_loss; |
| | | } |
| | | else |
| | | { |
| | | axis_y = _axis_y_k_loss; |
| | | } |
| | | var axis_value = diagram_coordinates.GetAxisValue(axis_y); |
| | | if (axis_value == null) |
| | | return; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = axis_value.NumericalValue; |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = diagram_coordinates.NumericalArgument; |
| | | } |
| | | |
| | | private void chartControl1_MouseUp(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | var y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | SetPointValue(_pick_point_index, x, y); |
| | | _pick_point_index = -1; |
| | | } |
| | | |
| | | private void chartControl1_KeyUp(object sender, KeyEventArgs e) |
| | | { |
| | | if (_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | double coord_space_x, coord_space_y; |
| | | if (_edit_curve_type == Ahart.eCurveType.QL) |
| | | { |
| | | coord_space_x = _coordinate.QL.CoordSpaceX; |
| | | coord_space_y = _coordinate.QL.CoordSpaceY; |
| | | } |
| | | else |
| | | { |
| | | coord_space_x = _coordinate.OL.CoordSpaceX; |
| | | coord_space_y = _coordinate.OL.CoordSpaceY; |
| | | } |
| | | double space_x = coord_space_x / 50; |
| | | double space_y = coord_space_y / 50; |
| | | double x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | double y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | if (e.KeyCode == Keys.Up) |
| | | { |
| | | y += space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Down) |
| | | { |
| | | y -= space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Left) |
| | | { |
| | | x -= space_x; |
| | | } |
| | | else if (e.KeyCode == Keys.Right) |
| | | { |
| | | x += space_x; |
| | | } |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = x; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = y; |
| | | SetPointValue(_pick_point_index, x, y); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新数据 |
| | | /// </summary> |
| | | private void SetPointValue(int index, double x, double y) |
| | | { |
| | | if (IsInvalidData()) |
| | | return; |
| | | var vm = _vm_list.Find(x => x.IsUpdate); |
| | | if (vm == null) |
| | | return; |
| | | vm.DefPointList[index].X = x; |
| | | vm.DefPointList[index].Y = y; |
| | | this.DefinePointChangedEvent?.Invoke(vm.DefPointList); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region Set |
| | | |
| | | /// <summary> |
| | | /// 绑定数据 |
| | |
| | | |
| | | foreach (var vm in _vm_list) |
| | | { |
| | | if (vm.DefPointList == null || !vm.DefPointList.Any()) |
| | | { |
| | | continue; |
| | | |
| | | } |
| | | if (vm.CurveType == Ahart.eCurveType.QL) |
| | | { |
| | | _min_x_flow = Math.Min(vm.DefPointList.Min(x => x.X), _min_x_flow); |
| | |
| | | |
| | | #endregion Calc |
| | | |
| | | #region Chart Event |
| | | |
| | | private int _pick_point_index = -1; |
| | | private void chartControl1_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | return; |
| | | var hitInfo = chartControl1.CalcHitInfo(e.Location); |
| | | _pick_point_index = -1; |
| | | if (e.Button == MouseButtons.Left) |
| | | { |
| | | if (hitInfo.InSeries&& hitInfo.Series != _series_edit_pt) |
| | | { |
| | | return; |
| | | } |
| | | if (hitInfo.InSeriesPoint && hitInfo.SeriesPoint.Tag is int index) |
| | | { |
| | | _pick_point_index = index; |
| | | this.SelectedPointIndexChangedEvent?.Invoke(_pick_point_index); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | private void chartControl1_MouseMove(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var diagram_coordinates = _diagram.PointToDiagram(e.Location); |
| | | AxisYBase axis_y = null; |
| | | if (_edit_curve_type == Ahart.eCurveType.QL) |
| | | { |
| | | axis_y = _axis_y_head_loss; |
| | | } |
| | | else |
| | | { |
| | | axis_y = _axis_y_k_loss; |
| | | } |
| | | var axis_value = diagram_coordinates.GetAxisValue(axis_y); |
| | | if (axis_value == null) |
| | | return; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = axis_value.NumericalValue; |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = diagram_coordinates.NumericalArgument; |
| | | } |
| | | |
| | | private void chartControl1_MouseUp(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | var x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | var y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | SetPointValue(_pick_point_index, x, y); |
| | | _pick_point_index = -1; |
| | | } |
| | | |
| | | private void chartControl1_KeyUp(object sender, KeyEventArgs e) |
| | | { |
| | | if (_mouse_mode) |
| | | return; |
| | | if (_pick_point_index < 0) |
| | | return; |
| | | if (IsInvalidData()) |
| | | return; |
| | | double coord_space_x, coord_space_y; |
| | | if (_edit_curve_type == Ahart.eCurveType.QL) |
| | | { |
| | | coord_space_x = _coordinate.QL.CoordSpaceX; |
| | | coord_space_y = _coordinate.QL.CoordSpaceY; |
| | | } |
| | | else |
| | | { |
| | | coord_space_x = _coordinate.OL.CoordSpaceX; |
| | | coord_space_y = _coordinate.OL.CoordSpaceY; |
| | | } |
| | | double space_x = coord_space_x / 50; |
| | | double space_y = coord_space_y / 50; |
| | | double x = _series_edit_pt.Points[_pick_point_index].NumericalArgument; |
| | | double y = _series_edit_pt.Points[_pick_point_index].Values[0]; |
| | | if (e.KeyCode == Keys.Up) |
| | | { |
| | | y += space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Down) |
| | | { |
| | | y -= space_y; |
| | | } |
| | | else if (e.KeyCode == Keys.Left) |
| | | { |
| | | x -= space_x; |
| | | } |
| | | else if (e.KeyCode == Keys.Right) |
| | | { |
| | | x += space_x; |
| | | } |
| | | x = Math.Round(x, 2); |
| | | y = Math.Round(y, 2); |
| | | _series_edit_pt.Points[_pick_point_index].NumericalArgument = x; |
| | | _series_edit_pt.Points[_pick_point_index].Values[0] = y; |
| | | SetPointValue(_pick_point_index, x, y); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新数据 |
| | | /// </summary> |
| | | private void SetPointValue(int index, double x, double y) |
| | | { |
| | | if (IsInvalidData()) |
| | | return; |
| | | var vm = _vm_list.Find(x => x.IsUpdate); |
| | | if (vm == null) |
| | | return; |
| | | vm.DefPointList[index].X = x; |
| | | vm.DefPointList[index].Y = y; |
| | | this.DefinePointChangedEvent?.Invoke(vm.DefPointList); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | |