From 45929342d7825d680781001cbf6beb87be541faa Mon Sep 17 00:00:00 2001
From: Shuxia Ning <NingShuxia0927@outlook.com>
Date: 星期三, 04 十二月 2024 10:01:13 +0800
Subject: [PATCH] 曲线修改

---
 WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-variable-speed-view/PumpVariableSpeedViewChart.cs |  229 +++++++++++++++++++++++++-------------------------------
 1 files changed, 103 insertions(+), 126 deletions(-)

diff --git a/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-variable-speed-view/PumpVariableSpeedViewChart.cs b/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-variable-speed-view/PumpVariableSpeedViewChart.cs
index 9555024..3f754ad 100644
--- a/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-variable-speed-view/PumpVariableSpeedViewChart.cs
+++ b/WinFrmUI/Yw.WinFrmUI.Phart.Core/01-pump/01-single/04-variable-speed-view/PumpVariableSpeedViewChart.cs
@@ -17,16 +17,16 @@
         }
 
         #region Private Variable 
-         
+
         private readonly string _tag_qh = "QH", _tag_qe = "QE", _tag_qp = "QP";
 
         private XYDiagram _diagram;
-        private XYDiagramDefaultPane _default_pane; 
+        private XYDiagramDefaultPane _default_pane;
         private XYDiagramPane _bottom_pane;
         private AxisX _axis_x_flow;
         private AxisY _axis_y_head;
-        private SecondaryAxisY _axis_y_eff, _axis_y_power; 
-         
+        private SecondaryAxisY _axis_y_eff, _axis_y_power;
+
         private PumpCoordinate _coordinate;
 
         private bool _qe_visible = true;
@@ -34,23 +34,22 @@
 
         private bool _equip_visible = true;
         private Yw.Geometry.CubicSpline2d _equip_line = null;
-        private Yw.Geometry.Point2d _equip_pt = null; 
-        private List<Tuple<string, Yw.Geometry.Point2d, Yw.Geometry.Point2d, Yw.Geometry.Point2d>> _equip_sect_pt_list;
+        private Yw.Geometry.Point2d _equip_pt = null;
+        private List<Tuple<string, Color, double, double, double?, double?>> _equip_sect_pt_list;
 
         private bool _initial_data = false;
 
         private PumpVariableSpeedViewViewModel _vm = null;
 
         #endregion
-         
+
         #region Public Evnet
 
         /// <summary>
         /// 鍧愭爣鍙樻崲浜嬩欢
         /// </summary>
         public event Action<PumpCoordinate> CoordinateChangedEvent = null;
-         
-  
+
         #endregion
 
         #region Initial
@@ -64,11 +63,11 @@
             this.chartControl1.Legend.Direction = DevExpress.XtraCharts.LegendDirection.TopToBottom;
 
             _diagram = (XYDiagram)this.chartControl1.Diagram;
-            _default_pane = _diagram.DefaultPane; 
+            _default_pane = _diagram.DefaultPane;
             _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");
@@ -77,7 +76,7 @@
             _axis_y_power = _diagram.SecondaryAxesY.GetAxisByName("AxisYQP");
             _axis_y_power.SetSecondaryAxisYQPDisplay();
 
-       
+            this.chartControl1.SetChartMonoColorDisplay(); 
 
             _axis_x_flow.Visibility = DefaultBoolean.False;
             _axis_x_flow.GridLines.Visible = false;
@@ -87,7 +86,7 @@
             _axis_y_eff.GridLines.Visible = false;
             _axis_y_power.Visibility = DefaultBoolean.False;
             _axis_y_power.GridLines.Visible = false;
-             
+
 
             this.chartControl1.CustomPaint += ChartControl1_CustomPaint;
         }
@@ -105,7 +104,16 @@
                 pen.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
                 foreach (var tuple in _equip_sect_pt_list)
                 {
-                    DrawEquipPoint(dxArgs.Cache, pen, tuple.Item2, tuple.Item3, tuple.Item4);
+                    var color = tuple.Item2;
+                    var flow = tuple.Item3;
+                    var head = tuple.Item4;
+                    var eff = tuple.Item5;
+                    var power = tuple.Item6;
+                    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);
                 }
 
                 DrawEquipLine(dxArgs.Cache, pen, _equip_line);
@@ -131,36 +139,12 @@
             cache.DrawPath(pen, path);
         }
 
-        private void DrawEquipPoint(GraphicsCache cache, Pen pen, Yw.Geometry.Point2d qh_sect_pt, Yw.Geometry.Point2d qe_sect_pt, Yw.Geometry.Point2d qp_sect_pt)
+        private void DrawWorkPoint(GraphicsCache cache, Color color, AxisYBase axis_y, double x, double y)
         {
-            if (qh_sect_pt == null)
-                return;
-
-            var offset_size = 10;
-            var qh_x = qh_sect_pt.X;
-            var qh_pt = _diagram.DiagramToPoint(qh_sect_pt.X, qh_sect_pt.Y, _axis_x_flow, _axis_y_head);
-
-            var qh_pt_x = qh_pt.Point.X;
-            var qh_pt_y = qh_pt.Point.Y;
-            cache.DrawLine(pen, new Point(qh_pt_x, qh_pt_y - offset_size), new Point(qh_pt_x, qh_pt_y + offset_size));
-
-            if (qe_sect_pt != null && _qe_visible)
-            { 
-                var qe_pt = _diagram.DiagramToPoint(qe_sect_pt.X, qe_sect_pt.Y, _axis_x_flow, _axis_y_eff);
-                var qe_pt_x = qe_pt.Point.X;
-                var qe_pt_y = qe_pt.Point.Y;
-                cache.DrawLine(pen, new Point(qe_pt_x, qe_pt_y - offset_size), new Point(qe_pt_x, qe_pt_y + offset_size));
-            }
-            if (qp_sect_pt != null && _qp_visible)
-            {
-                var qp_pt = _diagram.DiagramToPoint(qp_sect_pt.X, qp_sect_pt.Y, _axis_x_flow, _axis_y_power);
-                var qp_pt_x = qp_pt.Point.X;
-                var qp_pt_y = qp_pt.Point.Y;
-                cache.DrawLine(pen, new Point(qp_pt_x, qp_pt_y - offset_size), new Point(qp_pt_x, qp_pt_y + offset_size));
-            }
-
+            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);
         }
-
+         
         /// <summary>
         /// 鍒濆鍖栧浘琛ㄦ暟鎹�
         /// </summary>
@@ -195,64 +179,61 @@
             _equip_line = null;
             _equip_sect_pt_list = null;
             if (_vm == null)
-            { 
+            {
                 return;
             }
 
             start_head ??= _coordinate.DispMinH();
-            
+
             var equip_line = Yw.Geometry.EquipCurveHelper.CalcEquipCurve(_vm.CurveQH, _equip_pt, start_head.Value, out Yw.Geometry.Point2d sect_pt);
             if (equip_line == null || sect_pt == null)
                 return;
             _equip_line = equip_line;
-            _equip_sect_pt_list = new List<Tuple<string, Geometry.Point2d, Geometry.Point2d, Geometry.Point2d>>();
+            _equip_sect_pt_list = new List<Tuple<string, Color, double, double, double?, double?>>();
 
-            Yw.Geometry.Point2d sect_pt_eff=null, sect_pt_power = null;
-            if (_vm.CurveQE != null)
-            {
-                var eff = _vm.CurveQE.GetPointY(sect_pt.X);
-                sect_pt_eff = new Geometry.Point2d(sect_pt.X, eff);
-            }
+            double sect_flow = sect_pt.X;
+            double sect_head = _vm.CurveQH.GetPointYUnlimited(sect_flow);
+            double? sect_eff = null, sect_power = null;
             if (_vm.CurveQP != null)
             {
-                var power = _vm.CurveQP.GetPointY(sect_pt.X);
-                sect_pt_power = new Geometry.Point2d(sect_pt.X, power);
+                sect_power = _vm.CurveQP.GetPointYUnlimited(sect_flow);
+                //sect_eff = PumpCalcHelper.CalculateE(sect_flow, sect_head, sect_power.Value); 
             }
-
-            _equip_sect_pt_list.Add(new(_vm.Id, sect_pt,sect_pt_eff, sect_pt_power));
-            foreach (var vm in _vm.Items)
+            if (_vm.CurveQE != null)
             {
-                double flow = 0, head = 0;
-                double? eff = null, power = null;
-
-                var pump_equip_line = Yw.Geometry.EquipCurveHelper.CalcEquipCurve(vm.CurveQH, _equip_pt, start_head.Value, out Yw.Geometry.Point2d pump_sect_pt);
-                if (pump_equip_line == null || pump_sect_pt == null)
-                    return;
-                Yw.Geometry.Point2d pump_sect_pt_eff = null, pump_sect_pt_power = null;
-
-                flow = pump_sect_pt.X;
-                head = vm.CurveQH.GetPointYUnlimited(flow);
-                if (vm.CurveQP != null)
-                {
-                    power = vm.CurveQP.GetPointYUnlimited(flow);
-                    eff = PumpCalcHelper.CalculateE(flow, head, power.Value);
-
-                    pump_sect_pt_eff = new Geometry.Point2d(flow, eff.Value);
-                    pump_sect_pt_power = new Geometry.Point2d(flow, power.Value);
-                }
-                else if (vm.CurveQE != null)
-                {
-                    eff = vm.CurveQE.GetPointYUnlimited(flow);
-                    power = PumpCalcHelper.CalculateP(flow, head, eff.Value);
-
-                    pump_sect_pt_eff = new Geometry.Point2d(flow, eff.Value);
-                    pump_sect_pt_power = new Geometry.Point2d(flow, power.Value);
-                }
-
-                _equip_sect_pt_list.Add(new(vm.Id, new Geometry.Point2d(flow, head), pump_sect_pt_eff, pump_sect_pt_power));
+                sect_eff = _vm.CurveQE.GetPointYUnlimited(sect_flow);
+                // sect_power = PumpCalcHelper.CalculateP(sect_flow, sect_head, sect_eff.Value);
             }
-             
-            UpdateChart(true); 
+
+            _equip_sect_pt_list.Add(new(_vm.Id, _vm.Color, sect_flow, sect_head, sect_eff, sect_power));
+            if (_vm.Items != null && _vm.Items.Any())
+            {
+                foreach (var vm in _vm.Items)
+                {
+                    double flow = 0, head = 0;
+                    double? eff = null, power = null;
+
+                    var pump_equip_line = Yw.Geometry.EquipCurveHelper.CalcEquipCurve(vm.CurveQH, _equip_pt, start_head.Value, out Yw.Geometry.Point2d pump_sect_pt);
+                    if (pump_equip_line == null || pump_sect_pt == null)
+                        return;
+
+                    flow = pump_sect_pt.X;
+                    head = vm.CurveQH.GetPointYUnlimited(flow);
+                    if (vm.CurveQP != null)
+                    {
+                        power = vm.CurveQP.GetPointYUnlimited(flow);
+                        //eff = PumpCalcHelper.CalculateE(flow, head, power.Value); 
+                    }
+                    if (vm.CurveQE != null)
+                    {
+                        eff = vm.CurveQE.GetPointYUnlimited(flow);
+                        //power = PumpCalcHelper.CalculateP(flow, head, eff.Value);
+                    }
+
+                    _equip_sect_pt_list.Add(new(vm.Id, vm.Color, flow, head, eff, power));
+                }
+            }
+            UpdateChart(true);
 
         }
 
@@ -279,7 +260,7 @@
 
             CalcSeries();
 
-            CalcChartAxis(); 
+            CalcChartAxis();
         }
 
         #endregion
@@ -416,11 +397,9 @@
             _axis_y_eff.GridLines.Visible = false;
             _axis_y_power.Visibility = DefaultBoolean.False;
             _axis_y_power.GridLines.Visible = false;
-             
+
 
             _bottom_pane.Visibility = ChartElementVisibility.Hidden;
-
-
             _bottom_pane.Visibility = _qp_visible ? ChartElementVisibility.Visible : ChartElementVisibility.Hidden;
 
             //璁$畻鍒诲害 Q
@@ -471,7 +450,7 @@
             }
 
             //鍔熺巼
-            if (_max_power > _min_power)
+            if (_max_power > _min_power && _qp_visible)
             {
                 //璁$畻鍒诲害
                 var labels = new List<CustomAxisLabel>();
@@ -511,7 +490,7 @@
             var grid_count_power = _coordinate.EndLineNoP - _coordinate.StartLineNoP;
             var min_axis_power = _coordinate.CoordMinP + _coordinate.StartLineNoP * _coordinate.CoordSpaceP;
             var max_axis_power = min_axis_power + grid_count_power * _coordinate.CoordSpaceP;
-            _axis_y_power.SetAxisRange(min_axis_power, max_axis_power);  
+            _axis_y_power.SetAxisRange(min_axis_power, max_axis_power);
         }
 
         /// <summary>
@@ -521,36 +500,33 @@
         {
             this.chartControl1.BeginInit();
             this.chartControl1.Series.Clear();
-
-            var annotation_count = this.chartControl1.AnnotationRepository.Count;
-            for (int i = annotation_count - 1; i > 0; i--)
-            {
-                if (i == 0)
-                    break;
-                this.chartControl1.AnnotationRepository.RemoveAt(i);
-            }
-
+            this.chartControl1.AnnotationRepository.Clear();
             this.chartControl1.Legend.CustomItems.Clear();
+
             if (_vm != null)
             {
-                CreateLineSeries(_vm.Id, _vm.Name, _vm.CurveQH, _vm.CurveQE, _vm.CurveQP);
+                _vm.Color = RandomColorHelper.Get(0);
+                CreateLineSeries(_vm.Id, _vm.Color, _vm.Name, _vm.CurveQH, _vm.CurveQE, _vm.CurveQP);
                 if (_vm.Items != null && _vm.Items.Any())
                 {
-                    foreach (var vm in _vm.Items)
+                    for (int i = 0; i < _vm.Items.Count; i++)
                     {
-                        CreateLineSeries(vm.Id, vm.Name, vm.CurveQH, vm.CurveQE, vm.CurveQP);
+                        var vm = _vm.Items[i];
+                        vm.Color = RandomColorHelper.Get(i + 1);
+                        CreateLineSeries(vm.Id, vm.Color, vm.CurveName, vm.CurveQH, vm.CurveQE, vm.CurveQP);
                     }
-                } 
+                }
+
             }
 
-            this.chartControl1.EndInit();
+            this.chartControl1.EndInit(); 
         }
-        銆�
+
 
         /// <summary>
         /// 鍒涘缓绾跨郴鍒�
         /// </summary> 
-        private void CreateLineSeries(string id, string curve_name, Yw.Geometry.CubicSpline2d qh, Yw.Geometry.CubicSpline2d qe, Yw.Geometry.CubicSpline2d qp)
+        private void CreateLineSeries(string id, Color color, string curve_name, Yw.Geometry.CubicSpline2d qh, Yw.Geometry.CubicSpline2d qe, Yw.Geometry.CubicSpline2d qp)
         {
             var series_qh = new DevExpress.XtraCharts.Series();
             series_qh.ArgumentScaleType = DevExpress.XtraCharts.ScaleType.Numerical;
@@ -563,7 +539,7 @@
 
             var series_qh_view = new DevExpress.XtraCharts.SplineSeriesView();
             series_qh_view.LineStyle.Thickness = 2;
-            //series_qh_view.Color = vm.Color;
+            series_qh_view.Color = color;
             series_qh_view.EnableAntialiasing = DefaultBoolean.True;
             series_qh_view.LineTensionPercent = 50;
 
@@ -594,7 +570,7 @@
             txt_qh.AutoHeight = true;
             txt_qh.AutoWidth = true;
             txt_qh.BackColor = System.Drawing.Color.Transparent;
-            //txt_qh.Border.Color = vm.Color;
+            txt_qh.Border.Color = color;
             txt_qh.ConnectorStyle = DevExpress.XtraCharts.AnnotationConnectorStyle.Line;
             txt_qh.DXFont = PumpChartDisplay.AnnoFontQH;
             txt_qh.Name = _tag_qh + id;
@@ -607,7 +583,7 @@
             txt_qh.RuntimeResizing = false;
             txt_qh.RuntimeRotation = false;
             txt_qh.Text = curve_name;
-            //txt_qh.TextColor = vm.Color;
+            txt_qh.TextColor = color;
             txt_qh.ShapePosition = position_qh;
             txt_qh.Visible = true;
             this.chartControl1.AnnotationRepository.Add(txt_qh);
@@ -625,7 +601,7 @@
 
                 var series_qe_view = new DevExpress.XtraCharts.SplineSeriesView();
                 series_qe_view.LineStyle.Thickness = 2;
-                //series_qe_view.Color = vm.Color;
+                series_qe_view.Color = color;
                 series_qe_view.AxisY = _axis_y_eff;
                 series_qe_view.Pane = _default_pane;
                 series_qe_view.EnableAntialiasing = DefaultBoolean.True;
@@ -657,7 +633,7 @@
 
                 var series_qp_view = new DevExpress.XtraCharts.SplineSeriesView();
                 series_qp_view.LineStyle.Thickness = 2;
-                //series_qp_view.Color = vm.Color;
+                series_qp_view.Color = color;
                 series_qp_view.AxisY = _axis_y_power;
                 series_qp_view.Pane = _bottom_pane;
                 series_qp_view.EnableAntialiasing = DefaultBoolean.True;
@@ -675,26 +651,27 @@
                 }
 
                 this.chartControl1.Series.Add(series_qp);
-            } 
+            }
+
         }
 
-        
+
         #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;
+            _qe_visible = this.barCekCurveQEVisible.Checked;
             UpdateChart();
         }
 
@@ -702,17 +679,17 @@
         {
             _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)
         {
-            _equip_visible = this.barCekCurveEQVisible.Checked; 
+            _equip_visible = this.barCekCurveEQVisible.Checked;
         }
 
         #endregion
- 
-  
+
+
         /// <summary>
         /// 璁剧疆鍧愭爣杞�
         /// </summary>
@@ -731,8 +708,8 @@
 
         #endregion
 
-       
-         
+
+
 
     }
 

--
Gitblit v1.9.3