From 21fc6d4c4c311afcd7a3471faa2b61931c5d389d Mon Sep 17 00:00:00 2001 From: "Mr.Xia" <1424473282@qq.com> Date: Thu, 21 May 2026 12:39:46 +0800 Subject: [PATCH] Handle G84 circular expansion hole counts --- DrillTapeProcessor.cs | 32 +++++++++++++++++++++-- SlotHoleCalculator.cs | 61 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 3 deletions(-) diff --git a/DrillTapeProcessor.cs b/DrillTapeProcessor.cs index 6cd9ed3..ac08bfd 100644 --- a/DrillTapeProcessor.cs +++ b/DrillTapeProcessor.cs @@ -54,7 +54,7 @@ namespace DrillTools.Integration foreach (var hole in toolHoles) { - if (hole.Type == HoleType.Slot) + if (hole.Type == HoleType.Slot || hole.Type == HoleType.CircularExpansion) { hasSlotHoles = true; break; @@ -135,6 +135,12 @@ namespace DrillTools.Integration string location = $"{startLocation}G85{endLocation}"; locations.Add(location); } + else if (hole.Type == HoleType.CircularExpansion) + { + slotHoles += hole.DrillHitCount; + slotCount++; + locations.Add(hole.OriginalCommand); + } } } @@ -326,6 +332,24 @@ namespace DrillTools.Integration var trimmedLine = line.Trim(); if (string.IsNullOrEmpty(trimmedLine)) continue; + // 检查是否是圆形扩孔(G84指令) + var circularExpansionPattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)G84X([+-]?\d+\.?\d*)"; + var circularExpansionMatch = Regex.Match(trimmedLine, circularExpansionPattern); + + if (circularExpansionMatch.Success) + { + var expansion = SlotHoleCalculator.ParseCircularExpansionFromG84(circularExpansionMatch.Value, tool.Diameter); + holes.Add(new HoleInfo + { + ToolNumber = tool.Number, + Type = HoleType.CircularExpansion, + CircularExpansion = expansion, + DrillHitCount = SlotHoleCalculator.CalculateCircularExpansionHoleCount(expansion), + OriginalCommand = trimmedLine + }); + continue; + } + // 检查是否是槽孔(G85指令) var slotPattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)G85X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)"; var slotMatch = Regex.Match(trimmedLine, slotPattern); @@ -450,6 +474,9 @@ namespace DrillTools.Integration public HoleType Type { get; set; } public Point2D Position { get; set; } public LineSlot Slot { get; set; } + public CircularExpansion CircularExpansion { get; set; } + public int DrillHitCount { get; set; } + public string OriginalCommand { get; set; } = string.Empty; } /// @@ -458,7 +485,8 @@ namespace DrillTools.Integration public enum HoleType { Regular, // 普通圆孔 - Slot // 槽孔 + Slot, // 槽孔 + CircularExpansion // 圆形扩孔 } /// diff --git a/SlotHoleCalculator.cs b/SlotHoleCalculator.cs index 2e17102..606033a 100644 --- a/SlotHoleCalculator.cs +++ b/SlotHoleCalculator.cs @@ -96,6 +96,26 @@ namespace DrillTools public double Radius => Math.Sqrt(Math.Pow(StartPoint.X - CenterPoint.X, 2) + Math.Pow(StartPoint.Y - CenterPoint.Y, 2)); } + /// + /// 圆形扩孔结构 + /// + public struct CircularExpansion + { + public Point2D CenterPoint { get; set; } + public double Diameter { get; set; } + public double ToolDiameter { get; set; } + + public CircularExpansion(Point2D centerPoint, double diameter, double toolDiameter) + { + CenterPoint = centerPoint; + Diameter = diameter; + ToolDiameter = toolDiameter; + } + + public double CenterPathDiameter => Math.Max(0, Diameter - ToolDiameter); + public double CenterPathLength => Math.PI * CenterPathDiameter; + } + /// /// 槽孔钻孔数量计算工具类 /// 提供与CAM350一致的槽孔孔数计算方法 @@ -153,6 +173,21 @@ namespace DrillTools return holeCount; } + /// + /// 计算圆形扩孔的钻孔数量 + /// + public static int CalculateCircularExpansionHoleCount(CircularExpansion expansion, double tolerance = DEFAULT_TOLERANCE) + { + if (expansion.CenterPathLength <= 0) + return 1; + + double radius = expansion.ToolDiameter / 2.0; + double holeCenterDistance = CalculateHoleCenterDistance(radius, tolerance); + int holeCount = (int)Math.Ceiling(expansion.CenterPathLength / holeCenterDistance); + + return Math.Max(1, holeCount); + } + /// /// 计算线段槽孔的钻孔位置 /// @@ -309,6 +344,30 @@ namespace DrillTools throw new ArgumentException($"无效的G85命令格式: {g85Command}"); } + /// + /// 从钻带G84命令解析圆形扩孔 + /// + public static CircularExpansion ParseCircularExpansionFromG84(string g84Command, double toolDiameter) + { + var pattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)G84X([+-]?\d+\.?\d*)"; + var match = Regex.Match(g84Command, pattern); + if (match.Success) + { + string centerX = match.Groups[1].Value; + string centerY = match.Groups[2].Value; + string diameter = match.Groups[3].Value; + + Point2D centerPoint = new Point2D( + double.Parse(centerX) / 1000.0, + double.Parse(centerY) / 1000.0, + $"X{centerX}Y{centerY}" + ); + + return new CircularExpansion(centerPoint, double.Parse(diameter) / 1000.0, toolDiameter); + } + throw new ArgumentException($"无效的G84命令格式: {g84Command}"); + } + // 辅助方法 /// @@ -404,4 +463,4 @@ namespace DrillTools ); } } -} \ No newline at end of file +}