Handle G84 circular expansion hole counts

This commit is contained in:
2026-05-21 12:39:46 +08:00
parent a27cef82b2
commit 21fc6d4c4c
2 changed files with 90 additions and 3 deletions

View File

@@ -54,7 +54,7 @@ namespace DrillTools.Integration
foreach (var hole in toolHoles) foreach (var hole in toolHoles)
{ {
if (hole.Type == HoleType.Slot) if (hole.Type == HoleType.Slot || hole.Type == HoleType.CircularExpansion)
{ {
hasSlotHoles = true; hasSlotHoles = true;
break; break;
@@ -135,6 +135,12 @@ namespace DrillTools.Integration
string location = $"{startLocation}G85{endLocation}"; string location = $"{startLocation}G85{endLocation}";
locations.Add(location); 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(); var trimmedLine = line.Trim();
if (string.IsNullOrEmpty(trimmedLine)) continue; 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指令 // 检查是否是槽孔G85指令
var slotPattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)G85X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)"; var slotPattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)G85X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var slotMatch = Regex.Match(trimmedLine, slotPattern); var slotMatch = Regex.Match(trimmedLine, slotPattern);
@@ -450,6 +474,9 @@ namespace DrillTools.Integration
public HoleType Type { get; set; } public HoleType Type { get; set; }
public Point2D Position { get; set; } public Point2D Position { get; set; }
public LineSlot Slot { get; set; } public LineSlot Slot { get; set; }
public CircularExpansion CircularExpansion { get; set; }
public int DrillHitCount { get; set; }
public string OriginalCommand { get; set; } = string.Empty;
} }
/// <summary> /// <summary>
@@ -458,7 +485,8 @@ namespace DrillTools.Integration
public enum HoleType public enum HoleType
{ {
Regular, // 普通圆孔 Regular, // 普通圆孔
Slot // 槽孔 Slot, // 槽孔
CircularExpansion // 圆形扩孔
} }
/// <summary> /// <summary>

View File

@@ -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 double Radius => Math.Sqrt(Math.Pow(StartPoint.X - CenterPoint.X, 2) + Math.Pow(StartPoint.Y - CenterPoint.Y, 2));
} }
/// <summary>
/// 圆形扩孔结构
/// </summary>
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;
}
/// <summary> /// <summary>
/// 槽孔钻孔数量计算工具类 /// 槽孔钻孔数量计算工具类
/// 提供与CAM350一致的槽孔孔数计算方法 /// 提供与CAM350一致的槽孔孔数计算方法
@@ -153,6 +173,21 @@ namespace DrillTools
return holeCount; return holeCount;
} }
/// <summary>
/// 计算圆形扩孔的钻孔数量
/// </summary>
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);
}
/// <summary> /// <summary>
/// 计算线段槽孔的钻孔位置 /// 计算线段槽孔的钻孔位置
/// </summary> /// </summary>
@@ -309,6 +344,30 @@ namespace DrillTools
throw new ArgumentException($"无效的G85命令格式: {g85Command}"); throw new ArgumentException($"无效的G85命令格式: {g85Command}");
} }
/// <summary>
/// 从钻带G84命令解析圆形扩孔
/// </summary>
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}");
}
// 辅助方法 // 辅助方法
/// <summary> /// <summary>
@@ -404,4 +463,4 @@ namespace DrillTools
); );
} }
} }
} }