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

本次更新聚焦于钻带文件解析顺序与格式的准确还原,提升了界面基础信息展示,并优化了相关数据结构和辅助方法。主要包括:
- 钻带孔位逐行顺序解析,完整保留原始坐标字符串格式,避免顺序错乱和格式丢失。
- 界面新增基础信息分组,自动统计并展示最小钻咀、槽刀、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

@@ -37,6 +37,9 @@ namespace DrillTools.Integration
// 检查是否是机台码 (0.499孔径)
bool isMachineCode = Math.Abs(tool.Diameter - 0.499) < 0.001;
// 获取当前刀具的孔位数据
var toolHoles = holesByTool.ContainsKey(tool.Number) ? holesByTool[tool.Number] : new List<HoleInfo>();
// 根据刀具类型设置
ToolType toolType;
if (isMachineCode)
@@ -45,17 +48,24 @@ namespace DrillTools.Integration
}
else
{
// 简化处理所有非机台码都设为Regular
// 实际应用中可以根据需要判断是否为槽孔
toolType = ToolType.Regular;
// 检查该刀具的孔位数据中是否包含G85槽孔
bool hasSlotHoles = false;
foreach (var hole in toolHoles)
{
if (hole.Type == HoleType.Slot)
{
hasSlotHoles = true;
break;
}
}
toolType = hasSlotHoles ? ToolType.Slot : ToolType.Regular;
}
// 计算刀具尾号类型和大类
var toolSuffixType = ToolItem.GetToolSuffixType(tool.Diameter);
var ToolCategory = ToolItem.GetToolCategory(toolSuffixType);
// 获取当前刀具的孔位数据
var toolHoles = holesByTool.ContainsKey(tool.Number) ? holesByTool[tool.Number] : new List<HoleInfo>();
var locations = new List<string>();
// 统计孔数并收集孔位坐标
@@ -89,6 +99,7 @@ namespace DrillTools.Integration
else
{
// 普通刀具和槽刀:正常处理
// 由于现在holes列表已经保持了原始顺序直接按顺序处理即可
foreach (var hole in toolHoles)
{
if (hole.Type == HoleType.Regular)
@@ -124,7 +135,7 @@ namespace DrillTools.Integration
// 为机台码刀具提取机台码命令和类型
string machineCodeCommand = string.Empty;
string machineCodeType = string.Empty;
if (isMachineCode)
{
// 从钻带内容中提取机台码信息
@@ -143,7 +154,7 @@ namespace DrillTools.Integration
{
machineCodeCommand = machineCodeMatch.Groups[1].Value; // M97或M98
machineCodeType = machineCodeMatch.Groups[2].Value; // A*或B*
// 添加日志验证机台码解析
System.Diagnostics.Debug.WriteLine($"[机台码解析] T{tool.Number:D2}: 命令={machineCodeCommand}, 类型={machineCodeType}");
}
@@ -230,10 +241,13 @@ namespace DrillTools.Integration
var toolPattern = $@"%.+?T{tool.Number:D2}(.*?)(?=T\d{{2}}|M30)";
var match = Regex.Match(drillTapeContent, toolPattern, RegexOptions.Singleline);
if (match.Success)
if (match.Success)//机台码
{
string holeSection = match.Groups[1].Value;
// 按行分割孔位数据,保持原始顺序
var lines = holeSection.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
// 查找机台码命令
var machineCodePattern = @"(M97|M98),(A\*|B\*),\$S \$N";
var machineCodeMatch = Regex.Match(holeSection, machineCodePattern);
@@ -246,10 +260,6 @@ namespace DrillTools.Integration
// 根据机台码类型确定孔数
int holeCount = (codeType == "A*") ? 57 : 58;
// 查找机台码坐标行
var coordinatePattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var coordinateMatches = Regex.Matches(holeSection, coordinatePattern);
// 添加机台码孔信息
for (int i = 0; i < holeCount; i++)
{
@@ -261,23 +271,33 @@ namespace DrillTools.Integration
});
}
// 这样可以确保坐标数据被正确保存到 ToolResult.Locations 中
foreach (Match coordMatch in coordinateMatches)
// 按原始顺序处理坐标行
foreach (var line in lines)
{
// 解析坐标
double x = double.Parse(coordMatch.Groups[1].Value);
double y = double.Parse(coordMatch.Groups[2].Value);
var trimmedLine = line.Trim();
if (string.IsNullOrEmpty(trimmedLine)) continue;
// 保存原始坐标字符串
string originalCoordString = coordMatch.Value;
// 检查是否是坐标行
var coordinatePattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var coordinateMatch = Regex.Match(trimmedLine, coordinatePattern);
// 添加一个特殊的孔位信息来保存实际坐标
holes.Add(new HoleInfo
if (coordinateMatch.Success)
{
ToolNumber = tool.Number,
Type = HoleType.Regular,
Position = new Point2D(x, y, originalCoordString)
});
// 解析坐标
double x = double.Parse(coordinateMatch.Groups[1].Value);
double y = double.Parse(coordinateMatch.Groups[2].Value);
// 保存原始坐标字符串
string originalCoordString = coordinateMatch.Value;
// 添加一个特殊的孔位信息来保存实际坐标
holes.Add(new HoleInfo
{
ToolNumber = tool.Number,
Type = HoleType.Regular,
Position = new Point2D(x, y, originalCoordString)
});
}
}
}
}
@@ -291,45 +311,48 @@ namespace DrillTools.Integration
if (match.Success)
{
string holeSection = match.Groups[1].Value;
// 先解析槽孔,并记录槽孔的起始坐标
var slotPattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)G85X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var slotMatches = Regex.Matches(holeSection, slotPattern);
var slotStartPositions = new System.Collections.Generic.HashSet<string>();
foreach (Match slotMatch in slotMatches)
// 按行分割孔位数据,保持原始顺序
var lines = holeSection.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
var slot = SlotHoleCalculator.ParseLineSlotFromG85(slotMatch.Value, tool.Diameter);
holes.Add(new HoleInfo
{
ToolNumber = tool.Number,
Type = HoleType.Slot,
Slot = slot
});
// 记录槽孔的起始坐标,以便后续排除
string startPos = $"X{slotMatch.Groups[1].Value}Y{slotMatch.Groups[2].Value}";
slotStartPositions.Add(startPos);
}
// 解析普通圆孔(排除槽孔的起始坐标)
var regularHolePattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var regularMatches = Regex.Matches(holeSection, regularHolePattern);
foreach (Match regularMatch in regularMatches)
{
// 排除槽孔的起始坐标
if (!slotStartPositions.Contains(regularMatch.Value))
var trimmedLine = line.Trim();
if (string.IsNullOrEmpty(trimmedLine)) continue;
// 检查是否是槽孔G85指令
var slotPattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)G85X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var slotMatch = Regex.Match(trimmedLine, slotPattern);
if (slotMatch.Success)
{
// 处理槽孔
var slot = SlotHoleCalculator.ParseLineSlotFromG85(slotMatch.Value, tool.Diameter);
holes.Add(new HoleInfo
{
ToolNumber = tool.Number,
Type = HoleType.Regular,
Position = Point2D.ParseFromDrillString(regularMatch.Value)
Type = HoleType.Slot,
Slot = slot
});
}
}
else
{
// 检查是否是普通圆孔
var regularHolePattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var regularMatch = Regex.Match(trimmedLine, regularHolePattern);
// 解析槽孔(已在上面处理)
if (regularMatch.Success)
{
// 处理普通圆孔
holes.Add(new HoleInfo
{
ToolNumber = tool.Number,
Type = HoleType.Regular,
Position = Point2D.ParseFromDrillString(regularMatch.Value)
});
}
}
}
}
}
}
@@ -462,12 +485,12 @@ namespace DrillTools.Integration
public ToolType ToolType { get; set; }
public ToolSuffixType ToolSuffixType { get; set; }
public ToolCategory ToolCategory { get; set; }
/// <summary>
/// 机台码命令 (M97或M98)
/// </summary>
public string MachineCodeCommand { get; set; } = string.Empty;
/// <summary>
/// 机台码类型 (A*或B*)
/// </summary>
@@ -604,6 +627,7 @@ namespace DrillTools.Integration
result.Add($"T{tool.ToolNumber:D2}");
// 添加该刀具对应的所有坐标数据
// HoleLocations现在应该已经保持了原始顺序
if (tool.ToolType != ToolType.MachineCode && tool.HoleLocations != null && tool.HoleLocations.Count > 0)
{
foreach (var location in tool.HoleLocations)
@@ -620,6 +644,7 @@ namespace DrillTools.Integration
result.Add($"{tool.MachineCodeCommand},{tool.MachineCodeType},$S $N");
// 添加机台码的坐标数据
// HoleLocations现在应该已经保持了原始顺序
if (tool.HoleLocations != null && tool.HoleLocations.Count > 0)
{
foreach (var location in tool.HoleLocations)