From b593805f11b89ecc94f4f1d5730c4f77803125e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F?= Date: Fri, 24 Apr 2026 16:32:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E9=87=8F=E5=B7=A5=E5=85=B7=E6=A0=87?= =?UTF-8?q?=E5=8F=B7=EF=BC=9A=E5=90=84=E7=B1=BB=E6=B5=8B=E9=87=8F=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=98=BE=E7=A4=BA=E5=BA=8F=E5=8F=B7=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=90=8E=E8=87=AA=E5=8A=A8=E9=87=8D=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controls/PolygonRoiCanvas.xaml.cs | 36 ++++++++++++++++++- .../Models/AngleGroup.cs | 3 +- .../Models/FillRateGroup.cs | 3 +- .../Models/MeasureGroup.cs | 4 ++- .../Models/PointToLineGroup.cs | 3 +- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs b/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs index 28653c9..0863dd1 100644 --- a/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs +++ b/XP.ImageProcessing.RoiControl/Controls/PolygonRoiCanvas.xaml.cs @@ -456,6 +456,7 @@ namespace XP.ImageProcessing.RoiControl.Controls var g = CreatePPGroup(_pendingPoint.Value, pos); _ppGroups.Add(g); _measureOverlay.Children.Remove(_pendingDot); + RenumberAll(); _pendingDot = null; _pendingPoint = null; RaiseMeasureCompleted(g.P1, g.P2, g.Distance, MeasureCount, "PointDistance"); CurrentMeasureMode = Models.MeasureMode.None; @@ -506,7 +507,7 @@ namespace XP.ImageProcessing.RoiControl.Controls // 完成:创建正式组,移除临时元素 var g = CreatePTLGroup(_ptlTempL1.Value, _ptlTempL2.Value, pos); _ptlGroups.Add(g); - + RenumberAll(); if (_ptlTempDot1 != null) _measureOverlay.Children.Remove(_ptlTempDot1); if (_ptlTempDot2 != null) _measureOverlay.Children.Remove(_ptlTempDot2); if (_ptlTempLine != null) _measureOverlay.Children.Remove(_ptlTempLine); @@ -568,6 +569,7 @@ namespace XP.ImageProcessing.RoiControl.Controls { var g = CreateAngleGroup(_angleTempV.Value, _angleTempA.Value, pos); _angleGroups.Add(g); + RenumberAll(); // 移除临时元素 if (_angleTempVDot != null) _measureOverlay.Children.Remove(_angleTempVDot); @@ -611,6 +613,7 @@ namespace XP.ImageProcessing.RoiControl.Controls var g = CreateFillRateGroup(e1, e2, e3, e4); _frGroups.Add(g); + RenumberAll(); double rate = g.FillRate; RaiseMeasureCompleted(g.E3, g.E4, rate, MeasureCount, "FillRate"); @@ -808,6 +811,7 @@ namespace XP.ImageProcessing.RoiControl.Controls foreach (var el in new UIElement[] { g.Dot1, g.Dot2, g.Line, g.Label }) _measureOverlay.Children.Remove(el); _ppGroups.Remove(g); + RenumberAll(); RaiseMeasureStatusChanged($"已删除测量 | 剩余 {MeasureCount} 条"); e.Handled = true; return; } @@ -820,6 +824,7 @@ namespace XP.ImageProcessing.RoiControl.Controls foreach (var el in new UIElement[] { g.DotL1, g.DotL2, g.DotP, g.MainLine, g.ExtLine, g.PerpLine, g.FootDot, g.Label }) _measureOverlay.Children.Remove(el); _ptlGroups.Remove(g); + RenumberAll(); RaiseMeasureStatusChanged($"已删除测量 | 剩余 {MeasureCount} 条"); e.Handled = true; return; } @@ -832,6 +837,7 @@ namespace XP.ImageProcessing.RoiControl.Controls foreach (var el in new UIElement[] { g.DotV, g.DotA, g.DotB, g.LineA, g.LineB, g.Arc, g.Label }) _measureOverlay.Children.Remove(el); _angleGroups.Remove(g); + RenumberAll(); RaiseMeasureStatusChanged($"已删除测量 | 剩余 {MeasureCount} 条"); e.Handled = true; return; } @@ -847,12 +853,40 @@ namespace XP.ImageProcessing.RoiControl.Controls foreach (var el in g.AllElements) _measureOverlay.Children.Remove(el); _frGroups.Remove(g); + RenumberAll(); RaiseMeasureStatusChanged($"已删除测量 | 剩余 {MeasureCount} 条"); e.Handled = true; return; } } } + // ── 重编号 ── + + private void RenumberAll() + { + for (int i = 0; i < _ppGroups.Count; i++) + { + _ppGroups[i].Index = i + 1; + _ppGroups[i].UpdateLine(); + _ppGroups[i].UpdateLabel(FormatDistance(_ppGroups[i].Distance)); + } + for (int i = 0; i < _ptlGroups.Count; i++) + { + _ptlGroups[i].Index = i + 1; + _ptlGroups[i].UpdateVisuals(FormatDistance(_ptlGroups[i].Distance)); + } + for (int i = 0; i < _angleGroups.Count; i++) + { + _angleGroups[i].Index = i + 1; + _angleGroups[i].UpdateVisuals(); + } + for (int i = 0; i < _frGroups.Count; i++) + { + _frGroups[i].Index = i + 1; + _frGroups[i].UpdateVisuals(); + } + } + // ── 填锡率阈值编辑 ── private TextBox _thtEditBox; diff --git a/XP.ImageProcessing.RoiControl/Models/AngleGroup.cs b/XP.ImageProcessing.RoiControl/Models/AngleGroup.cs index 85a3077..9127261 100644 --- a/XP.ImageProcessing.RoiControl/Models/AngleGroup.cs +++ b/XP.ImageProcessing.RoiControl/Models/AngleGroup.cs @@ -19,6 +19,7 @@ namespace XP.ImageProcessing.RoiControl.Models public Point V { get; set; } public Point A { get; set; } public Point B { get; set; } + public int Index { get; set; } public double AngleDeg { @@ -77,7 +78,7 @@ namespace XP.ImageProcessing.RoiControl.Models midAngle += Math.PI; double labelDist = arcRadius + 16; - Label.Text = $"{angleDeg:F1}°"; + Label.Text = (Index > 0 ? $"#{Index} " : "") + $"{angleDeg:F1}°"; Canvas.SetLeft(Label, V.X + labelDist * Math.Cos(midAngle) - 15); Canvas.SetTop(Label, V.Y + labelDist * Math.Sin(midAngle) - 8); Label.Visibility = Visibility.Visible; diff --git a/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs b/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs index 34e789c..7929b15 100644 --- a/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs +++ b/XP.ImageProcessing.RoiControl/Models/FillRateGroup.cs @@ -58,6 +58,7 @@ namespace XP.ImageProcessing.RoiControl.Models public double E4Angle { get; set; } public double THTLimit { get; set; } = 75.0; + public int Index { get; set; } public double FillRate { @@ -100,7 +101,7 @@ namespace XP.ImageProcessing.RoiControl.Models double rate = FillRate; string cls = Classification; - Label.Text = $"Fill: {rate:F1}% | THTLimit: {THTLimit:F1}% | {cls}"; + Label.Text = (Index > 0 ? $"#{Index} " : "") + $"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; diff --git a/XP.ImageProcessing.RoiControl/Models/MeasureGroup.cs b/XP.ImageProcessing.RoiControl/Models/MeasureGroup.cs index 2e5670d..32ba2aa 100644 --- a/XP.ImageProcessing.RoiControl/Models/MeasureGroup.cs +++ b/XP.ImageProcessing.RoiControl/Models/MeasureGroup.cs @@ -34,10 +34,12 @@ namespace XP.ImageProcessing.RoiControl.Models public void UpdateLabel(string distanceText = null) { - Label.Text = distanceText ?? $"{Distance:F2} px"; + Label.Text = (Index > 0 ? $"#{Index} " : "") + (distanceText ?? $"{Distance:F2} px"); Canvas.SetLeft(Label, (P1.X + P2.X) / 2 + 8); Canvas.SetTop(Label, (P1.Y + P2.Y) / 2 - 18); Label.Visibility = Visibility.Visible; } + + public int Index { get; set; } } } diff --git a/XP.ImageProcessing.RoiControl/Models/PointToLineGroup.cs b/XP.ImageProcessing.RoiControl/Models/PointToLineGroup.cs index 29163e4..6077a26 100644 --- a/XP.ImageProcessing.RoiControl/Models/PointToLineGroup.cs +++ b/XP.ImageProcessing.RoiControl/Models/PointToLineGroup.cs @@ -20,6 +20,7 @@ namespace XP.ImageProcessing.RoiControl.Models public Point L1 { get; set; } public Point L2 { get; set; } public Point P { get; set; } + public int Index { get; set; } public double Distance { @@ -85,7 +86,7 @@ namespace XP.ImageProcessing.RoiControl.Models FootDot.Visibility = Visibility.Visible; // 标签 - Label.Text = distanceText ?? $"{Distance:F2} px"; + Label.Text = (Index > 0 ? $"#{Index} " : "") + (distanceText ?? $"{Distance:F2} px"); Canvas.SetLeft(Label, (P.X + foot.X) / 2 + 8); Canvas.SetTop(Label, (P.Y + foot.Y) / 2 - 18); Label.Visibility = Visibility.Visible;