增加 称重分析 点位Tip弹窗显示点位详细信息
This commit is contained in:
@@ -35,12 +35,15 @@ namespace MesWork.Pages
|
|||||||
private readonly Label lbl_Product = new Label();
|
private readonly Label lbl_Product = new Label();
|
||||||
private readonly Label lbl_Sample = new Label();
|
private readonly Label lbl_Sample = new Label();
|
||||||
private readonly Label lbl_Status = new Label();
|
private readonly Label lbl_Status = new Label();
|
||||||
|
private readonly ToolTip tip_Point = new ToolTip();
|
||||||
|
|
||||||
private readonly List<decimal> _points = new List<decimal>();
|
private readonly List<decimal> _points = new List<decimal>();
|
||||||
|
private PointF[] _chartPoints = new PointF[0];
|
||||||
private int _finalStartSeq;
|
private int _finalStartSeq;
|
||||||
private int _finalEndSeq;
|
private int _finalEndSeq;
|
||||||
private decimal? _finalWeight;
|
private decimal? _finalWeight;
|
||||||
private int _sampleIntervalMs;
|
private int _sampleIntervalMs;
|
||||||
|
private int _lastTipSeq;
|
||||||
|
|
||||||
private static readonly Color ClrPrimary = Color.FromArgb(74, 144, 217);
|
private static readonly Color ClrPrimary = Color.FromArgb(74, 144, 217);
|
||||||
private static readonly Color ClrPrimaryDark = Color.FromArgb(30, 58, 95);
|
private static readonly Color ClrPrimaryDark = Color.FromArgb(30, 58, 95);
|
||||||
@@ -61,6 +64,8 @@ namespace MesWork.Pages
|
|||||||
SetHint(txt_OrderNo, "工单号...");
|
SetHint(txt_OrderNo, "工单号...");
|
||||||
pnl_Chart.Paint += pnl_Chart_Paint;
|
pnl_Chart.Paint += pnl_Chart_Paint;
|
||||||
pnl_Chart.Resize += (s, e) => pnl_Chart.Invalidate();
|
pnl_Chart.Resize += (s, e) => pnl_Chart.Invalidate();
|
||||||
|
pnl_Chart.MouseMove += pnl_Chart_MouseMove;
|
||||||
|
pnl_Chart.MouseLeave += (s, e) => HidePointTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeLayout()
|
private void InitializeLayout()
|
||||||
@@ -283,6 +288,7 @@ namespace MesWork.Pages
|
|||||||
private void LoadCurve(DataRow row)
|
private void LoadCurve(DataRow row)
|
||||||
{
|
{
|
||||||
_points.Clear();
|
_points.Clear();
|
||||||
|
HidePointTip();
|
||||||
string pointValues = row.Table.Columns.Contains("点位值") ? row["点位值"]?.ToString() : "";
|
string pointValues = row.Table.Columns.Contains("点位值") ? row["点位值"]?.ToString() : "";
|
||||||
foreach (string item in (pointValues ?? "").Split('|'))
|
foreach (string item in (pointValues ?? "").Split('|'))
|
||||||
{
|
{
|
||||||
@@ -311,6 +317,7 @@ namespace MesWork.Pages
|
|||||||
private void ClearCurve(string msg)
|
private void ClearCurve(string msg)
|
||||||
{
|
{
|
||||||
_points.Clear();
|
_points.Clear();
|
||||||
|
HidePointTip();
|
||||||
_finalWeight = null;
|
_finalWeight = null;
|
||||||
_finalStartSeq = 0;
|
_finalStartSeq = 0;
|
||||||
_finalEndSeq = 0;
|
_finalEndSeq = 0;
|
||||||
@@ -357,6 +364,7 @@ namespace MesWork.Pages
|
|||||||
|
|
||||||
if (_points.Count == 0)
|
if (_points.Count == 0)
|
||||||
{
|
{
|
||||||
|
_chartPoints = new PointF[0];
|
||||||
DrawCenterText(g, rect, "选择一条称重记录后显示曲线");
|
DrawCenterText(g, rect, "选择一条称重记录后显示曲线");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -372,10 +380,10 @@ namespace MesWork.Pages
|
|||||||
|
|
||||||
DrawGrid(g, padL, padT, chartW, chartH, minVal, maxVal);
|
DrawGrid(g, padL, padT, chartW, chartH, minVal, maxVal);
|
||||||
|
|
||||||
PointF[] points = BuildPointLocations(padL, padT, chartW, chartH, minVal, maxVal);
|
_chartPoints = BuildPointLocations(padL, padT, chartW, chartH, minVal, maxVal);
|
||||||
DrawHighlightWindow(g, points, padT, chartH);
|
DrawHighlightWindow(g, _chartPoints, padT, chartH);
|
||||||
DrawCurve(g, points);
|
DrawCurve(g, _chartPoints);
|
||||||
DrawPoints(g, points);
|
DrawPoints(g, _chartPoints);
|
||||||
DrawFinalLine(g, padL, padT, chartW, chartH, minVal, maxVal);
|
DrawFinalLine(g, padL, padT, chartW, chartH, minVal, maxVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,6 +478,60 @@ namespace MesWork.Pages
|
|||||||
return _finalStartSeq > 0 && _finalEndSeq > 0 && seq >= _finalStartSeq && seq <= _finalEndSeq;
|
return _finalStartSeq > 0 && _finalEndSeq > 0 && seq >= _finalStartSeq && seq <= _finalEndSeq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void pnl_Chart_MouseMove(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
int index = FindNearestPointIndex(e.Location);
|
||||||
|
if (index < 0)
|
||||||
|
{
|
||||||
|
HidePointTip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int seq = index + 1;
|
||||||
|
if (seq == _lastTipSeq) return;
|
||||||
|
|
||||||
|
_lastTipSeq = seq;
|
||||||
|
string finalText = IsInFinalWindow(seq) ? "\r\n取值依据:最终采用区间内" : "";
|
||||||
|
string tipText = $"第 {seq} 点\r\n重量:{_points[index]:F3} kg\r\n时间:{FormatElapsedTime(seq)}{finalText}";
|
||||||
|
tip_Point.Show(tipText, pnl_Chart, e.Location.X + 16, e.Location.Y + 16, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int FindNearestPointIndex(Point mouse)
|
||||||
|
{
|
||||||
|
if (_chartPoints.Length == 0 || _points.Count == 0) return -1;
|
||||||
|
|
||||||
|
int nearestIndex = -1;
|
||||||
|
double nearestDistance = double.MaxValue;
|
||||||
|
for (int i = 0; i < _chartPoints.Length; i++)
|
||||||
|
{
|
||||||
|
double dx = _chartPoints[i].X - mouse.X;
|
||||||
|
double dy = _chartPoints[i].Y - mouse.Y;
|
||||||
|
double distance = dx * dx + dy * dy;
|
||||||
|
if (distance < nearestDistance)
|
||||||
|
{
|
||||||
|
nearestDistance = distance;
|
||||||
|
nearestIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nearestDistance <= 144 ? nearestIndex : -1; // 鼠标离点 12px 内才显示,避免误触。
|
||||||
|
}
|
||||||
|
|
||||||
|
private string FormatElapsedTime(int seq)
|
||||||
|
{
|
||||||
|
int interval = _sampleIntervalMs > 0 ? _sampleIntervalMs : 200;
|
||||||
|
int totalMs = Math.Max(0, seq - 1) * interval; // 第1点按采集起点0ms估算。
|
||||||
|
int seconds = totalMs / 1000;
|
||||||
|
int milliseconds = totalMs % 1000;
|
||||||
|
return $"{seconds}秒{milliseconds:D3}毫秒";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HidePointTip()
|
||||||
|
{
|
||||||
|
_lastTipSeq = 0;
|
||||||
|
tip_Point.Hide(pnl_Chart);
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawCenterText(Graphics g, Rectangle rect, string text)
|
private void DrawCenterText(Graphics g, Rectangle rect, string text)
|
||||||
{
|
{
|
||||||
using (var font = new Font("微软雅黑", 14F))
|
using (var font = new Font("微软雅黑", 14F))
|
||||||
|
|||||||
Reference in New Issue
Block a user