From 590090723675eda3d47c0932d15997c16e021dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= Date: Fri, 24 Apr 2026 16:18:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E5=AD=94=E5=A1=AB=E9=94=A1=E7=8E=87?= =?UTF-8?q?=EF=BC=9A=E6=A0=87=E7=AD=BE=E6=98=BE=E7=A4=BATHTLimit=E5=8F=82?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E5=8F=B3=E9=94=AE=E6=A0=87=E7=AD=BE=E5=8F=AF?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=98=88=E5=80=BC=EF=BC=8C=E6=A4=AD=E5=9C=86?= =?UTF-8?q?=E8=BD=B4=E6=89=8B=E6=9F=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controls/PolygonRoiCanvas.xaml.cs | 92 ++++++++++++++++++- .../Models/FillRateGroup.cs | 2 +- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs b/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs index 716eede..28653c9 100644 --- a/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs +++ b/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs @@ -629,7 +629,9 @@ namespace XP.ImageProcessing.RoiControl.Controls g.FullLine = new Line { Stroke = Brushes.Red, StrokeThickness = 1, IsHitTestVisible = false }; g.FillLine = new Line { Stroke = Brushes.Lime, StrokeThickness = 2, IsHitTestVisible = false }; - g.Label = new TextBlock { FontSize = 13, FontWeight = FontWeights.Bold, IsHitTestVisible = false }; + g.Label = new TextBlock { FontSize = 13, FontWeight = FontWeights.Bold, Cursor = Cursors.Hand }; + g.Label.SetValue(ContextMenuService.IsEnabledProperty, false); + g.Label.MouseRightButtonUp += (s, ev) => { ShowTHTLimitEditor(g); ev.Handled = true; }; g.DotE1 = CreateMDot(Brushes.DodgerBlue); g.DotE2 = CreateMDot(Brushes.Cyan); @@ -851,6 +853,94 @@ namespace XP.ImageProcessing.RoiControl.Controls } } + // ── 填锡率阈值编辑 ── + + private TextBox _thtEditBox; + private TextBlock _thtEditLabel; + + private void RemoveTHTEditor() + { + if (_thtEditBox != null && _measureOverlay != null) + _measureOverlay.Children.Remove(_thtEditBox); + if (_thtEditLabel != null && _measureOverlay != null) + _measureOverlay.Children.Remove(_thtEditLabel); + _thtEditBox = null; + _thtEditLabel = null; + } + + private void ShowTHTLimitEditor(Models.FillRateGroup g) + { + if (_measureOverlay == null) return; + + // 移除旧的编辑框 + if (_thtEditBox != null) + { + _measureOverlay.Children.Remove(_thtEditBox); + _thtEditBox = null; + } + if (_thtEditLabel != null) + { + _measureOverlay.Children.Remove(_thtEditLabel); + _thtEditLabel = null; + } + + double left = Canvas.GetLeft(g.Label); + double top = Canvas.GetTop(g.Label) + 22; + + // 参数名称提示 + _thtEditLabel = new TextBlock + { + Text = "THTLimit(%):", + FontSize = 11, + Foreground = Brushes.White, + Background = new SolidColorBrush(Color.FromArgb(180, 0, 0, 0)), + Padding = new Thickness(3, 1, 3, 1) + }; + Canvas.SetLeft(_thtEditLabel, left); + Canvas.SetTop(_thtEditLabel, top); + _measureOverlay.Children.Add(_thtEditLabel); + + // 输入框 + _thtEditBox = new TextBox + { + Text = g.THTLimit.ToString("F1"), + Width = 60, + Height = 22, + FontSize = 12, + Background = Brushes.White, + BorderBrush = Brushes.Orange, + BorderThickness = new Thickness(2), + Padding = new Thickness(2, 0, 2, 0) + }; + Canvas.SetLeft(_thtEditBox, left + 80); + Canvas.SetTop(_thtEditBox, top); + _measureOverlay.Children.Add(_thtEditBox); + _thtEditBox.Focus(); + _thtEditBox.SelectAll(); + + // 回车确认 + _thtEditBox.KeyDown += (s, ev) => + { + if (ev.Key == System.Windows.Input.Key.Enter) + { + if (double.TryParse(_thtEditBox.Text, out double val)) + { + g.THTLimit = System.Math.Clamp(val, 0, 100); + g.UpdateVisuals(); + RaiseMeasureCompleted(g.E3, g.E4, g.FillRate, MeasureCount, "FillRate"); + } + RemoveTHTEditor(); + } + else if (ev.Key == System.Windows.Input.Key.Escape) + { + RemoveTHTEditor(); + } + }; + + // 失焦也关闭 + _thtEditBox.LostFocus += (s, ev) => RemoveTHTEditor(); + } + // ── 事件 ── public static readonly RoutedEvent MeasureCompletedEvent = diff --git a/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs b/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs index 3b2d6b1..34e789c 100644 --- a/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs +++ b/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs @@ -100,7 +100,7 @@ namespace XP.ImageProcessing.RoiControl.Models double rate = FillRate; string cls = Classification; - Label.Text = $"{rate:F1}% {cls}"; + Label.Text = $"Fill: {rate:F1}% | THTLimit: {THTLimit:F1}% | {cls}"; Label.Foreground = cls == "PASS" ? Brushes.Lime : Brushes.Red; double labelX = Math.Max(Math.Max(E1.X, E2.X), Math.Max(E3.X, E4.X)) + 15; double labelY = (E1.Y + E2.Y) / 2;