From 2335894be70e4a2befead79b433ca7bf64698b5e Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Wed, 12 Aug 2026 10:25:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=96=E6=B6=88PP=E9=92=BB=E5=B8=A6?= =?UTF-8?q?=E5=A4=96=E6=A1=8613/15=E5=AD=94=E8=A7=84=E5=88=99=20=E2=80=94?= =?UTF-8?q?=20GetPpGenerationRule=E4=BB=85=E8=BF=94=E5=9B=9ELegacy=203?= =?UTF-8?q?=E5=AD=94=E8=A7=84=E5=88=99=EF=BC=9B=E5=88=A0=E9=99=A4=E5=A4=96?= =?UTF-8?q?=E6=A1=86=E8=A7=84=E5=88=99=E5=8F=8A=E4=B8=93=E5=B1=9E=E8=BE=85?= =?UTF-8?q?=E5=8A=A9=E6=AD=BB=E4=BB=A3=E7=A0=81(SelectPpDrillTapeLocations?= =?UTF-8?q?/ParsePpHolePoints/SelectMiddlePoint/PpHolePoint/PpSideCoordina?= =?UTF-8?q?teTolerance)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MainWindowViewModel.cs | 121 +---------------------------------------- 1 file changed, 1 insertion(+), 120 deletions(-) diff --git a/MainWindowViewModel.cs b/MainWindowViewModel.cs index 2a6ee9c..fb02a34 100644 --- a/MainWindowViewModel.cs +++ b/MainWindowViewModel.cs @@ -47,7 +47,6 @@ namespace DrillTools private const int SvsiFocused = 0x10; private const int SelectFileFlags = SvsiSelect | SvsiDeselectOthers | SvsiEnsureVisible | SvsiFocused; private static readonly double[] PpSourceDiameters = { 3.203, 4.503 }; - private const int PpSideCoordinateTolerance = 1500; /// /// PP 钻带来源孔径集合(3.203 PP 定位孔 / 4.503 铆钉孔)。 @@ -1220,11 +1219,7 @@ M30"; if (!HasOriginalFile || OriginalTools.Count == 0) return null; - var legacyRule = GetLegacyPpGenerationRule(); - if (legacyRule != null) - return legacyRule; - - return GetOuterPpGenerationRule(); + return GetLegacyPpGenerationRule(); } private PpGenerationRule? GetLegacyPpGenerationRule() @@ -1253,120 +1248,6 @@ M30"; : null; } - private PpGenerationRule? GetOuterPpGenerationRule() - { - var sourceTool = OriginalTools.FirstOrDefault(tool => - IsPpSourceDiameter(tool.Diameter) - && (tool.TotalHoles == 13 || tool.TotalHoles == 15) - && tool.HoleLocations != null - && tool.HoleLocations.Count >= 4 - && CanSelectPpDrillTapeLocations(tool)); - - return sourceTool == null - ? null - : new PpGenerationRule("T01C4.000", SelectPpDrillTapeLocations(sourceTool)); - } - - /// - /// 从 PP 来源孔径(3.203 PP 定位孔 / 4.503 铆钉孔)外框中按右、上、左、下四边各取一个中位孔,并保持原钻带坐标文本。 - /// - private static List SelectPpDrillTapeLocations(ToolItem sourceTool) - { - var points = ParsePpHolePoints(sourceTool.HoleLocations); - if (points.Count < 4) - throw new InvalidOperationException("PP 来源孔径刀具坐标不足,无法生成 PP 钻带"); - - int minX = points.Min(point => point.X); - int maxX = points.Max(point => point.X); - int minY = points.Min(point => point.Y); - int maxY = points.Max(point => point.Y); - - var selected = new[] - { - SelectMiddlePoint(points.Where(point => Math.Abs(point.X - maxX) <= PpSideCoordinateTolerance), sortByX: false, useUpperMiddle: true), - SelectMiddlePoint(points.Where(point => Math.Abs(point.Y - maxY) <= PpSideCoordinateTolerance), sortByX: true, useUpperMiddle: false), - SelectMiddlePoint(points.Where(point => Math.Abs(point.X - minX) <= PpSideCoordinateTolerance), sortByX: false, useUpperMiddle: true), - SelectMiddlePoint(points.Where(point => Math.Abs(point.Y - minY) <= PpSideCoordinateTolerance), sortByX: true, useUpperMiddle: false) - }; - - if (selected.Any(point => point == null)) - throw new InvalidOperationException("PP 来源孔径刀具未形成完整的上下左右四边孔位,无法生成 PP 钻带"); - - var selectedTexts = selected - .Select(point => point!.Text) - .Distinct(StringComparer.Ordinal) - .ToHashSet(StringComparer.Ordinal); - - if (selectedTexts.Count != 4) - throw new InvalidOperationException("PP 来源孔径刀具四边中位孔存在重复,无法生成 PP 钻带"); - - // 输出顺序沿用原 PP 来源孔径刀具(3.203/4.503)中的孔位顺序,避免改变已有钻带坐标排序习惯。 - return points - .Where(point => selectedTexts.Contains(point.Text)) - .Select(point => point.Text) - .ToList(); - } - - private static bool CanSelectPpDrillTapeLocations(ToolItem sourceTool) - { - try - { - return SelectPpDrillTapeLocations(sourceTool).Count == 4; - } - catch (InvalidOperationException) - { - return false; - } - } - - private static List ParsePpHolePoints(IEnumerable holeLocations) - { - var points = new List(); - foreach (var location in holeLocations) - { - if (string.IsNullOrWhiteSpace(location)) - continue; - - var match = Regex.Match(location.Trim(), @"X([+-]?\d+)Y([+-]?\d+)"); - if (!match.Success) - continue; - - points.Add(new PpHolePoint( - location.Trim(), - int.Parse(match.Groups[1].Value), - int.Parse(match.Groups[2].Value))); - } - - return points; - } - - private static PpHolePoint? SelectMiddlePoint(IEnumerable sourcePoints, bool sortByX, bool useUpperMiddle) - { - var points = sortByX - ? sourcePoints.OrderBy(point => point.X).ThenBy(point => point.Y).ToList() - : sourcePoints.OrderBy(point => point.Y).ThenBy(point => point.X).ToList(); - - if (points.Count == 0) - return null; - - int index = useUpperMiddle ? points.Count / 2 : (points.Count - 1) / 2; - return points[index]; - } - - private sealed class PpHolePoint - { - public PpHolePoint(string text, int x, int y) - { - Text = text; - X = x; - Y = y; - } - - public string Text { get; } - public int X { get; } - public int Y { get; } - } - private sealed class PpGenerationRule { public PpGenerationRule(string toolDefinition, List locations)