Shuxia Ning
2024-12-10 cecd5e98941ff09c2e00b50d1c3e5733d2d9309c
WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-run-view/PumpRunViewChart.cs
@@ -1,7 +1,6 @@
using DevExpress.Office.Utils;
using DevExpress.PivotGrid.OLAP.AdoWrappers;
using DevExpress.Utils;
using DevExpress.Utils;
using DevExpress.Utils.Drawing;
using DevExpress.Utils.Html.Internal;
using DevExpress.XtraCharts;
namespace Yw.WinFrmUI.Phart
@@ -16,6 +15,8 @@
            InitializeComponent();
            InitialChart();
            this.chartControl1.RuntimeHitTesting = true;
            this.chartControl1.SelectionMode = ElementSelectionMode.Extended;
            this.chartControl1.SeriesSelectionMode = SeriesSelectionMode.Point;
        }
        #region Private Variable 
@@ -34,11 +35,55 @@
        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
@@ -53,7 +98,9 @@
        /// <summary>
        /// 运行点选择事件
        /// </summary>
        public event Action<PumpCoordinate> RunPointSelectedEvent = null;
        public event Action<PumpRunViewItemViewModel> RunPointSelectedEvent = null;
        #endregion
        #region Initial
@@ -91,46 +138,32 @@
            _axis_y_power.Visibility = DefaultBoolean.False;
            _axis_y_power.GridLines.Visible = false;
            this.chartControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseUp);
            this.chartControl1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseMove);
            this.chartControl1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chartControl1_MouseDown);
            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;
                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_sel = new Rectangle(rect.Item1.X, rect.Item1.Y, 12, 12);
                    _rect_color_sel = rect.Item2;
                    _rect_point = new Point(rect.Item1.X + 5, rect.Item1.Y + 5);
                    this.RunPointSelectedEvent?.Invoke(rect.Item3);
                    break;
                }
            }
        }
        private void chartControl1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!_initial_data)
                return;
            if (_rect_list == null || !_rect_list.Any())
                return;
        }
        private void chartControl1_MouseUp(object sender, MouseEventArgs e)
        {
            if (!_initial_data)
                return;
            if (_rect_list == null || !_rect_list.Any())
                return;
        }
        private void ChartControl1_CustomPaint(object sender, CustomPaintEventArgs e)
        {
            if (e is not DXCustomPaintEventArgs dxArgs)
@@ -138,8 +171,8 @@
            if (_vm == null)
                return;
            _rect_list.Clear();
            if (_vm.Items != null && _vm.Items.Any() && _run_visible)
            {
            if (_vm.Items != null && _vm.Items.Any() && _run_point_visible)
            {
                foreach (var vm in _vm.Items)
                {
                    var color = vm.Color;
@@ -153,7 +186,7 @@
                        var dg_y = dg_pt.Point.Y - 5;
                        dxArgs.Cache.FillEllipse(dg_x, dg_y, 10, 10, color);
                        _rect_list.Add(new Tuple<Rectangle, Color>(new Rectangle(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)
                    {
@@ -161,6 +194,7 @@
                        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)
@@ -169,32 +203,21 @@
                        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_sel.HasValue)
                if (_rect_point.HasValue)
                {
                    using Brush brush = new SolidBrush(_rect_color_sel.Value);
                    dxArgs.Cache.FillEllipse(brush, _rect_sel.Value);
                    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));
                }
            }
        }
        private List<Tuple<Rectangle,Color>> _rect_list = new List<Tuple<Rectangle, Color>>();
        private Rectangle? _rect_sel = null;
        private Color? _rect_color_sel = null;
        private Rectangle DrawWorkPoint(GraphicsCache cache, Color color, AxisYBase axis_y, double x, double y)
        {
            var dg_pt = _diagram.DiagramToPoint(x, y, _axis_x_flow, axis_y);
            var dg_x = dg_pt.Point.X - 5;
            var dg_y = dg_pt.Point.Y - 5;
            cache.FillEllipse(dg_x, dg_y, 10, 10, color);
            return new Rectangle(dg_x, dg_y, 10, 10);
        }
         
        /// <summary>
        /// 初始化图表数据
@@ -202,8 +225,7 @@
        public void InitialChartData()
        {
            _initial_data = false;
            _coordinate = null;
            _coordinate = null;
            UpdateChart(false);
        }
@@ -237,9 +259,8 @@
        /// </summary>
        public void UpdateChart(bool calc_coordinate = false)
        {
            _rect_sel = null;
            _rect_color_sel = null;
            _rect_list = new List<Tuple<Rectangle, Color>>();
            _rect_point = null;
            _rect_list = new ();
            if (calc_coordinate || _coordinate == null)
            {
                //不强迫计算,就用上次更新的坐标系
@@ -809,7 +830,7 @@
        /// </summary> 
        public void SetEQVisible(bool visible)
        {
            _run_visible = visible;
            _run_point_visible = visible;
        }