通孔填锡率:标签显示THTLimit参数,右键标签可编辑阈值,椭圆轴手柄调整

This commit is contained in:
李伟
2026-04-24 16:18:06 +08:00
parent ef2ef5cb83
commit 5900907236
2 changed files with 92 additions and 2 deletions
@@ -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 =