| | |
| | | using DevExpress.Utils; |
| | | using DevExpress.Utils.Drawing; |
| | | using DevExpress.Utils.Html.Internal; |
| | | using DevExpress.XtraCharts; |
| | | |
| | | namespace Yw.WinFrmUI.Phart |
| | |
| | | InitializeComponent(); |
| | | InitialChart(); |
| | | this.chartControl1.RuntimeHitTesting = true; |
| | | this.chartControl1.SelectionMode = ElementSelectionMode.Extended; |
| | | this.chartControl1.SeriesSelectionMode = SeriesSelectionMode.Point; |
| | | } |
| | | |
| | | #region Private Variable |
| | |
| | | private bool _qe_visible = true; |
| | | private bool _qp_visible = true; |
| | | |
| | | private bool _run_visible = true; |
| | | private bool _run_point_visible = true; |
| | | |
| | | private bool _initial_data = false; |
| | | |
| | | private PumpRunViewViewModel _vm = null; |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region Public Variable |
| | | |
| | | /// <summary> |
| | | /// 效率显示 |
| | | /// </summary> |
| | | public bool QEVisible |
| | | { |
| | | get => _qe_visible; |
| | | set |
| | | { |
| | | _qe_visible = value; |
| | | SetQEVisible(_qe_visible); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 功率显示 |
| | | /// </summary> |
| | | public bool QPVisble |
| | | { |
| | | get => _qp_visible; |
| | | set |
| | | { |
| | | _qp_visible = value; |
| | | SetQPVisible(_qp_visible); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 运行点显示 |
| | | /// </summary> |
| | | public bool RunPointVisible |
| | | { |
| | | get => _run_point_visible; |
| | | set |
| | | { |
| | | _run_point_visible = value; |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | |
| | | /// 坐标变换事件 |
| | | /// </summary> |
| | | public event Action<PumpCoordinate> CoordinateChangedEvent = null; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 运行点选择事件 |
| | | /// </summary> |
| | | public event Action<PumpRunViewItemViewModel> RunPointSelectedEvent = null; |
| | | |
| | | |
| | | #endregion |
| | | |
| | |
| | | _bottom_pane = (XYDiagramPane)_diagram.FindPaneByName("BottomPanel"); |
| | | |
| | | _axis_x_flow = _diagram.AxisX; |
| | | _axis_x_flow.SetAxisXQDisplay(); |
| | | _axis_x_flow.SetAxisXQDisplay(); |
| | | _axis_y_head = _diagram.AxisY; |
| | | _axis_y_head.SetAxisYQHDisplay(); |
| | | _axis_y_eff = _diagram.SecondaryAxesY.GetAxisByName("AxisYQE"); |
| | |
| | | _axis_y_power = _diagram.SecondaryAxesY.GetAxisByName("AxisYQP"); |
| | | _axis_y_power.SetSecondaryAxisYQPDisplay(); |
| | | |
| | | this.chartControl1.SetChartMonoColorDisplay(); |
| | | this.chartControl1.SetChartMonoColorDisplay(); |
| | | |
| | | _axis_x_flow.Visibility = DefaultBoolean.False; |
| | | _axis_x_flow.GridLines.Visible = false; |
| | |
| | | _axis_y_power.Visibility = DefaultBoolean.False; |
| | | _axis_y_power.GridLines.Visible = false; |
| | | |
| | | |
| | | |
| | | this.chartControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseDown); |
| | | this.chartControl1.CustomPaint += ChartControl1_CustomPaint; |
| | | } |
| | | |
| | | private List<Tuple<Rectangle, Color, PumpRunViewItemViewModel>> _rect_list = new(); |
| | | private Point? _rect_point = null; |
| | | private void chartControl1_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (!_initial_data) |
| | | return; |
| | | if (!_run_point_visible) |
| | | return; |
| | | if (_rect_list == null || !_rect_list.Any()) |
| | | return; |
| | | foreach (var rect in _rect_list) |
| | | { |
| | | if (rect.Item1.Contains(e.Location)) |
| | | { |
| | | _rect_point = new Point(rect.Item1.X + 5, rect.Item1.Y + 5); |
| | | this.RunPointSelectedEvent?.Invoke(rect.Item3); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void ChartControl1_CustomPaint(object sender, CustomPaintEventArgs e) |
| | | { |
| | | if (e is not DXCustomPaintEventArgs dxArgs) |
| | | return; |
| | | if (_vm == null) |
| | | return; |
| | | |
| | | if (_vm.Items!=null&&_vm.Items.Any()&& _run_visible) |
| | | _rect_list.Clear(); |
| | | if (_vm.Items != null && _vm.Items.Any() && _run_point_visible) |
| | | { |
| | | using Pen pen = new(Color.Black, 2); |
| | | pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot; |
| | | foreach (var vm in _vm.Items) |
| | | { |
| | | var color = vm.Color; |
| | |
| | | var head = vm.H; |
| | | var eff = vm.E; |
| | | var power = vm.P; |
| | | DrawWorkPoint(dxArgs.Cache, color, _axis_y_head, flow, head); |
| | | if (eff.HasValue && _qe_visible) |
| | | DrawWorkPoint(dxArgs.Cache, color, _axis_y_eff, flow, eff.Value); |
| | | if (power.HasValue && _qp_visible) |
| | | DrawWorkPoint(dxArgs.Cache, color, _axis_y_power, flow, power.Value); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | { |
| | | var dg_pt = _diagram.DiagramToPoint(flow, head, _axis_x_flow, _axis_y_head); |
| | | var dg_x = dg_pt.Point.X - 5; |
| | | var dg_y = dg_pt.Point.Y - 5; |
| | | |
| | | private void DrawWorkPoint(GraphicsCache cache, Color color, AxisYBase axis_y, double x, double y) |
| | | { |
| | | var dg_pt = _diagram.DiagramToPoint(x, y, _axis_x_flow, axis_y); |
| | | cache.FillEllipse((int)(dg_pt.Point.X - 5), (int)(dg_pt.Point.Y - 5), 10, 10, color); |
| | | dxArgs.Cache.FillEllipse(dg_x, dg_y, 10, 10, color); |
| | | _rect_list.Add(new(new Rectangle(dg_x, dg_y, 10, 10), color, vm)); |
| | | } |
| | | if (eff.HasValue && _qe_visible) |
| | | { |
| | | var dg_pt = _diagram.DiagramToPoint(flow, eff.Value, _axis_x_flow, _axis_y_eff); |
| | | var dg_x = dg_pt.Point.X - 5; |
| | | var dg_y = dg_pt.Point.Y - 5; |
| | | dxArgs.Cache.FillEllipse(dg_x, dg_y, 10, 10, color); |
| | | _rect_list.Add(new(new Rectangle(dg_x, dg_y, 10, 10), color, vm)); |
| | | } |
| | | |
| | | if (power.HasValue && _qp_visible) |
| | | { |
| | | var dg_pt = _diagram.DiagramToPoint(flow, power.Value, _axis_x_flow, _axis_y_power); |
| | | var dg_x = dg_pt.Point.X - 5; |
| | | var dg_y = dg_pt.Point.Y - 5; |
| | | dxArgs.Cache.FillEllipse(dg_x, dg_y, 10, 10, color); |
| | | _rect_list.Add(new(new Rectangle(dg_x, dg_y, 10, 10), color, vm)); |
| | | } |
| | | } |
| | | if (_rect_point.HasValue) |
| | | { |
| | | var x = _rect_point.Value.X; |
| | | var y = _rect_point.Value.Y; |
| | | var length = 20; |
| | | using Pen pen = new Pen(Color.Magenta, 2); |
| | | dxArgs.Cache.DrawLine(pen, new Point(x - length, y), new Point(x + length, y)); |
| | | dxArgs.Cache.DrawLine(pen, new Point(x, y - length), new Point(x, y + length)); |
| | | dxArgs.Cache.DrawEllipse(pen, new Rectangle(x - 10, y - 10, length, length)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public void InitialChartData() |
| | | { |
| | | _initial_data = false; |
| | | _coordinate = null; |
| | | |
| | | _coordinate = null; |
| | | UpdateChart(false); |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | public void UpdateChart(bool calc_coordinate = false) |
| | | { |
| | | _rect_point = null; |
| | | _rect_list = new (); |
| | | if (calc_coordinate || _coordinate == null) |
| | | { |
| | | //不强迫计算,就用上次更新的坐标系 |
| | |
| | | |
| | | this.chartControl1.EndInit(); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 创建线系列 |
| | | /// </summary> |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 创建线系列 |
| | | /// </summary> |
| | |
| | | |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region Right Click Menu |
| | | |
| | | #region Event |
| | | |
| | | private void barBtnSetChartAxis_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | SetChartAxis(); |
| | | } |
| | | |
| | | private void barCekCurveQEVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | _qe_visible = this.barCekCurveQEVisible.Checked; |
| | | UpdateChart(); |
| | | } |
| | | |
| | | private void barCekCurveQPVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | _bottom_pane.Visibility = _bottom_pane.Visibility == ChartElementVisibility.Visible ? ChartElementVisibility.Hidden : ChartElementVisibility.Visible; |
| | | _qp_visible = _bottom_pane.Visibility == ChartElementVisibility.Visible ? true : false; |
| | | UpdateChart(); |
| | | } |
| | | |
| | | private void barCekCurveEQVisible_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | _run_visible = this.barCekCurveEQVisible.Checked; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置坐标轴 |
| | | /// </summary> |
| | |
| | | dlg.ShowDialog(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置运行点显示 |
| | | /// </summary> |
| | | public void SetEQVisible(bool visible) |
| | | { |
| | | _run_point_visible = visible; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置效率显示 |
| | | /// </summary> |
| | | public void SetQEVisible(bool visible) |
| | | { |
| | | _qe_visible = visible; |
| | | UpdateChart(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置功率显示 |
| | | /// </summary> |
| | | public void SetQPVisible(bool visible) |
| | | { |
| | | _qp_visible = visible; |
| | | _bottom_pane.Visibility = _qp_visible ? ChartElementVisibility.Visible : ChartElementVisibility.Hidden; |
| | | UpdateChart(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |