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

@@ -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));
}
/// <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>
/// 槽孔钻孔数量计算工具类
/// 提供与CAM350一致的槽孔孔数计算方法
@@ -153,6 +173,21 @@ namespace DrillTools
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>
@@ -309,6 +344,30 @@ namespace DrillTools
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>
@@ -404,4 +463,4 @@ namespace DrillTools
);
}
}
}
}