测量工具标号:各类测量标签显示序号,删除后自动重编号

This commit is contained in:
李伟
2026-04-24 16:32:21 +08:00
parent 5900907236
commit b593805f11
5 changed files with 44 additions and 5 deletions
@@ -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;
@@ -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;
@@ -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;
@@ -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; }
}
}
@@ -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;