钻带解析顺序与格式优化,界面信息增强

本次更新聚焦于钻带文件解析顺序与格式的准确还原,提升了界面基础信息展示,并优化了相关数据结构和辅助方法。主要包括:
- 钻带孔位逐行顺序解析,完整保留原始坐标字符串格式,避免顺序错乱和格式丢失。
- 界面新增基础信息分组,自动统计并展示最小钻咀、槽刀、EA刀直径。
- 数据结构如Point2D等增加运算符重载和构造函数,便于几何计算。
- 机台码(0.499刀具)坐标行顺序提取及正则健壮性提升。
- 移除强制编码指定,提升跨平台兼容性。
- 清理冗余测试代码,更新示例/测试钻带文件内容。
- 新增《必读.md》,明确AI开发不需编写测试单元。
本次无其他功能或逻辑变动的占位diff。
This commit is contained in:
2025-12-22 16:50:42 +08:00
parent 44de1cb982
commit 0eab0f42ee
13 changed files with 30955 additions and 10232 deletions

View File

@@ -12,21 +12,21 @@ namespace DrillTools
public double X { get; set; }
public double Y { get; set; }
public string OriginalString { get; set; } // 存储原始坐标字符串
public Point2D(double x, double y)
{
X = x;
Y = y;
OriginalString = "";
}
public Point2D(double x, double y, string originalString)
{
X = x;
Y = y;
OriginalString = originalString;
}
/// <summary>
/// 从钻带坐标字符串创建点格式X+/-数字Y+/-数字)
/// </summary>
@@ -42,8 +42,9 @@ namespace DrillTools
}
throw new ArgumentException($"无效的钻带坐标格式: {drillString}");
}
public static Point2D operator +(Point2D p1, Point2D p2) => new Point2D(p1.X + p2.X, p1.Y + p2.Y);
public static Point2D operator -(Point2D p1, Point2D p2) => new Point2D(p1.X - p2.X, p1.Y - p2.Y);
}
@@ -55,14 +56,14 @@ namespace DrillTools
public Point2D StartPoint { get; set; }
public Point2D EndPoint { get; set; }
public double Width { get; set; } // 槽孔宽度/孔径单位mm
public LineSlot(Point2D startPoint, Point2D endPoint, double width)
{
StartPoint = startPoint;
EndPoint = endPoint;
Width = width;
}
/// <summary>
/// 获取槽孔长度
/// </summary>
@@ -79,7 +80,7 @@ namespace DrillTools
public Point2D CenterPoint { get; set; }
public double Width { get; set; } // 槽孔宽度/孔径单位mm
public bool CounterClockwise { get; set; } // 是否逆时针方向
public ArcSlot(Point2D startPoint, Point2D endPoint, Point2D centerPoint, double width, bool counterClockwise = false)
{
StartPoint = startPoint;
@@ -88,7 +89,7 @@ namespace DrillTools
Width = width;
CounterClockwise = counterClockwise;
}
/// <summary>
/// 获取弧段半径
/// </summary>
@@ -105,7 +106,7 @@ namespace DrillTools
/// 默认凸位高度值CAM350标准单位mm
/// </summary>
private const double DEFAULT_TOLERANCE = 0.0127;
/// <summary>
/// 计算线段槽孔的钻孔数量
/// </summary>
@@ -116,19 +117,19 @@ namespace DrillTools
{
// 计算孔半径
double radius = slot.Width / 2.0;
// 计算槽孔长度
double slotLength = slot.Length;
// 计算孔中心距
double holeCenterDistance = CalculateHoleCenterDistance(radius, tolerance);
// 计算孔数
int holeCount = (int)Math.Abs(Math.Floor(-slotLength / holeCenterDistance)) + 1;
return holeCount;
}
/// <summary>
/// 计算弧段槽孔的钻孔数量
/// </summary>
@@ -139,19 +140,19 @@ namespace DrillTools
{
// 计算孔半径
double radius = slot.Width / 2.0;
// 计算弧段长度
double arcLength = CalculateArcLength(slot);
// 计算孔中心距
double holeCenterDistance = CalculateHoleCenterDistance(radius, tolerance);
// 计算孔数
int holeCount = (int)Math.Abs(Math.Floor(-arcLength / holeCenterDistance)) + 1;
return holeCount;
}
/// <summary>
/// 计算线段槽孔的钻孔位置
/// </summary>
@@ -161,47 +162,47 @@ namespace DrillTools
public static List<Point2D> CalculateLineSlotHolePositions(LineSlot slot, double tolerance = DEFAULT_TOLERANCE)
{
List<Point2D> positions = new List<Point2D>();
// 计算孔半径
double radius = slot.Width / 2.0;
// 计算孔中心距
double holeCenterDistance = CalculateHoleCenterDistance(radius, tolerance);
// 计算槽孔长度
double slotLength = slot.Length;
// 计算孔数
int holeCount = CalculateLineSlotHoleCount(slot, tolerance);
// 计算方位角
double angle = CalculateAngle(slot.StartPoint, slot.EndPoint);
// 添加起点
positions.Add(slot.StartPoint);
// 计算中间点
if (holeCount > 2)
{
double avgDistance = slotLength / (holeCount - 1);
Point2D currentPoint = slot.StartPoint;
for (int i = 1; i < holeCount - 1; i++)
{
currentPoint = CalculateNextPoint(currentPoint, avgDistance, angle);
positions.Add(currentPoint);
}
}
// 添加终点
if (holeCount > 1)
{
positions.Add(slot.EndPoint);
}
return positions;
}
/// <summary>
/// 计算弧段槽孔的钻孔位置
/// </summary>
@@ -211,31 +212,31 @@ namespace DrillTools
public static List<Point2D> CalculateArcSlotHolePositions(ArcSlot slot, double tolerance = DEFAULT_TOLERANCE)
{
List<Point2D> positions = new List<Point2D>();
// 计算孔半径
double radius = slot.Width / 2.0;
// 计算孔中心距
double holeCenterDistance = CalculateHoleCenterDistance(radius, tolerance);
// 计算弧段半径
double arcRadius = slot.Radius;
// 计算弧段圆心角
double arcAngle = CalculateArcAngle(slot);
// 计算孔数
int holeCount = CalculateArcSlotHoleCount(slot, tolerance);
// 计算角度步长
double angleStep = arcAngle / (holeCount - 1);
// 计算起始角度
double startAngle = CalculateAngle(slot.CenterPoint, slot.StartPoint);
// 添加起点
positions.Add(slot.StartPoint);
// 计算中间点
if (holeCount > 2)
{
@@ -248,12 +249,12 @@ namespace DrillTools
{
currentAngle += angleStep;
}
for (int i = 1; i < holeCount - 1; i++)
{
Point2D point = CalculatePointOnArc(slot.CenterPoint, arcRadius, currentAngle);
positions.Add(point);
if (slot.CounterClockwise)
{
currentAngle -= angleStep;
@@ -264,16 +265,16 @@ namespace DrillTools
}
}
}
// 添加终点
if (holeCount > 1)
{
positions.Add(slot.EndPoint);
}
return positions;
}
/// <summary>
/// 从钻带G85命令解析线段槽孔
/// </summary>
@@ -291,7 +292,7 @@ namespace DrillTools
string startY = match.Groups[2].Value;
string endX = match.Groups[3].Value;
string endY = match.Groups[4].Value;
Point2D startPoint = new Point2D(
double.Parse(startX) / 1000.0,
double.Parse(startY) / 1000.0,
@@ -302,14 +303,14 @@ namespace DrillTools
double.Parse(endY) / 1000.0,
$"X{endX}Y{endY}"
);
return new LineSlot(startPoint, endPoint, width);
}
throw new ArgumentException($"无效的G85命令格式: {g85Command}");
}
// 辅助方法
/// <summary>
/// 计算两点间欧氏距离
/// </summary>
@@ -317,7 +318,7 @@ namespace DrillTools
{
return Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2));
}
/// <summary>
/// 计算方位角(度数)
/// </summary>
@@ -325,14 +326,14 @@ namespace DrillTools
{
double angleRad = Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X);
double angleDeg = angleRad * 180.0 / Math.PI;
// 转换为0-360度范围
if (angleDeg < 0)
angleDeg += 360;
return angleDeg;
}
/// <summary>
/// 计算弧段长度
/// </summary>
@@ -343,7 +344,7 @@ namespace DrillTools
double angleRad = angleDeg * Math.PI / 180.0;
return radius * angleRad;
}
/// <summary>
/// 计算弧段圆心角(度数)
/// </summary>
@@ -351,7 +352,7 @@ namespace DrillTools
{
double startAngle = CalculateAngle(arc.CenterPoint, arc.StartPoint);
double endAngle = CalculateAngle(arc.CenterPoint, arc.EndPoint);
double angleSum;
if (arc.CounterClockwise)
{
@@ -367,10 +368,10 @@ namespace DrillTools
else
angleSum = Math.Abs(startAngle - endAngle);
}
return angleSum;
}
/// <summary>
/// 计算孔中心距
/// </summary>
@@ -378,7 +379,7 @@ namespace DrillTools
{
return Math.Sqrt(Math.Pow(radius, 2) - Math.Pow(radius - tolerance, 2)) * 2;
}
/// <summary>
/// 根据起点、距离和角度计算下一个点
/// </summary>
@@ -390,7 +391,7 @@ namespace DrillTools
startPoint.Y + distance * Math.Sin(angleRad)
);
}
/// <summary>
/// 根据圆心、半径和角度计算圆弧上的点
/// </summary>