| | |
| | | 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); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | _coordinate.QL = ValveQLCoordinate.CalcCoordinate(_min_x_flow, _max_x_flow, _min_y_head_loss, _max_y_head_loss); |
| | | if (_coordinate.QL.CoordMinX + _coordinate.QL.CoordSpaceX * this._coordinate.QL.GridNumberX < _max_x_flow * 1.05) |
| | | if (_coordinate.QL != null) |
| | | { |
| | | _coordinate.QL.GridNumberX++; |
| | | if (_coordinate.QL.CoordMinX + _coordinate.QL.CoordSpaceX * this._coordinate.QL.GridNumberX < _max_x_flow * 1.05) |
| | | { |
| | | _coordinate.QL.GridNumberX++; |
| | | } |
| | | } |
| | | |
| | | _coordinate.OL = ValveOLCoordinate.CalcCoordinate(_min_x_opening, _max_x_opening, _min_y_k_loss, _max_y_k_loss); |
| | |
| | | var display_x_flow = _coordinate.QL.CoordMinX; |
| | | for (int i = 0; i < _coordinate.QL.GridNumberX + 1; i++) |
| | | { |
| | | axis_x_flow_labels.Add(new CustomAxisLabel(display_x_flow.ToString("N0"), display_x_flow)); |
| | | var x = _coordinate.QL.CoordSpaceX < 1 ? $"{display_x_flow:N1}" : $"{display_x_flow:N0}"; |
| | | axis_x_flow_labels.Add(new CustomAxisLabel(x, display_x_flow)); |
| | | display_x_flow = display_x_flow + _coordinate.QL.CoordSpaceX; |
| | | } |
| | | |
| | |
| | | var display_y_head_loss = _coordinate.QL.CoordMinY + _coordinate.QL.CoordSpaceY * _coordinate.QL.StartLineNoY; |
| | | for (int i = _coordinate.QL.StartLineNoY; i < _coordinate.QL.EndLineNoY + 1; i++) |
| | | { |
| | | var y = display_y_head_loss < 1 ? $"{display_y_head_loss:N1}" : $"{display_y_head_loss:N0}"; |
| | | var y = _coordinate.QL.CoordSpaceY < 1 ? $"{display_y_head_loss:N1}" : $"{display_y_head_loss:N0}"; |
| | | axis_y_head_loss_labels.Add(new CustomAxisLabel(y, display_y_head_loss)); |
| | | display_y_head_loss = display_y_head_loss + _coordinate.QL.CoordSpaceY; |
| | | } |
| | |
| | | var display_x_opening = _coordinate.OL.CoordMinX; |
| | | for (int i = 0; i < _coordinate.OL.GridNumberX + 1; i++) |
| | | { |
| | | axis_x_opening_labels.Add(new CustomAxisLabel(display_x_opening.ToString("N0"), display_x_opening)); |
| | | var x = _coordinate.OL.CoordSpaceX < 1 ? $"{display_x_opening:N1}" : $"{display_x_opening:N0}"; |
| | | axis_x_opening_labels.Add(new CustomAxisLabel(x, display_x_opening)); |
| | | display_x_opening = display_x_opening + _coordinate.OL.CoordSpaceX; |
| | | } |
| | | |
| | |
| | | var display_y_k_loss = _coordinate.OL.CoordMinY + _coordinate.OL.CoordSpaceY * _coordinate.OL.StartLineNoY; |
| | | for (int i = _coordinate.OL.StartLineNoY; i < _coordinate.OL.EndLineNoY + 1; i++) |
| | | { |
| | | var y = display_y_k_loss < 1 ? $"{display_y_k_loss:N1}" : $"{display_y_k_loss:N0}"; |
| | | var y = _coordinate.OL.CoordSpaceY < 1 ? $"{display_y_k_loss:N1}" : $"{display_y_k_loss:N0}"; |
| | | axis_y_k_loss_labels.Add(new CustomAxisLabel(y, display_y_k_loss)); |
| | | display_y_k_loss = display_y_k_loss + _coordinate.OL.CoordSpaceY; |
| | | } |
| | |
| | | |
| | | #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 |
| | | |
| | | } |
| | | |