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

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

@@ -26,6 +26,10 @@ namespace DrillTools
private bool _canMoveDown;
private string _originalFilePath = string.Empty;
private bool _isTopmost = true; // 默认置顶
private string _fileNameWithoutExtension = string.Empty;
private double _minDrillDiameter;
private double _minSlotDiameter;
private double _minEADiameter;
/// <summary>
/// 刀具列表
@@ -90,6 +94,16 @@ namespace DrillTools
{
// 当原始文件路径改变时,通知 HasOriginalFile 属性也已更改
OnPropertyChanged(nameof(HasOriginalFile));
// 更新文件名(不包含后缀)
if (!string.IsNullOrEmpty(value))
{
FileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(value);
}
else
{
FileNameWithoutExtension = string.Empty;
}
}
}
}
@@ -129,6 +143,42 @@ namespace DrillTools
/// </summary>
public string TopmostButtonText => IsTopmost ? "取消置顶" : "窗口置顶";
/// <summary>
/// 文件名(不包含后缀)
/// </summary>
public string FileNameWithoutExtension
{
get => _fileNameWithoutExtension;
set => SetProperty(ref _fileNameWithoutExtension, value);
}
/// <summary>
/// 最小钻咀直径
/// </summary>
public double MinDrillDiameter
{
get => _minDrillDiameter;
set => SetProperty(ref _minDrillDiameter, value);
}
/// <summary>
/// 最小槽刀直径
/// </summary>
public double MinSlotDiameter
{
get => _minSlotDiameter;
set => SetProperty(ref _minSlotDiameter, value);
}
/// <summary>
/// 最小EA刀直径
/// </summary>
public double MinEADiameter
{
get => _minEADiameter;
set => SetProperty(ref _minEADiameter, value);
}
/// <summary>
/// 从钻带内容加载刀具信息
/// </summary>
@@ -182,15 +232,26 @@ namespace DrillTools
if (match.Success)
{
string holeSection = match.Groups[1].Value;
// 查找机台码坐标行
var coordinatePattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var coordinateMatches = System.Text.RegularExpressions.Regex.Matches(holeSection, coordinatePattern);
// 按行分割孔位数据,保持原始顺序
var lines = holeSection.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
toolItem.HoleLocations = new List<string>();
foreach (Match coordMatch in coordinateMatches)
// 按原始顺序处理坐标行
foreach (var line in lines)
{
toolItem.HoleLocations.Add(coordMatch.Value);
var trimmedLine = line.Trim();
if (string.IsNullOrEmpty(trimmedLine)) continue;
// 检查是否是坐标行
var coordinatePattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
var coordinateMatch = System.Text.RegularExpressions.Regex.Match(trimmedLine, coordinatePattern);
if (coordinateMatch.Success)
{
toolItem.HoleLocations.Add(coordinateMatch.Value);
}
}
System.Diagnostics.Debug.WriteLine($"[机台码坐标] T{toolResult.ToolNumber:D2}: 找到{toolItem.HoleLocations.Count}个坐标");
@@ -218,6 +279,9 @@ namespace DrillTools
// 更新按钮状态
UpdateMoveButtonsState();
// 计算并更新最小直径信息
UpdateMinDiameterInfo();
// 检查并应用-sort.txt文件中的刀具排序
if (!string.IsNullOrEmpty(OriginalFilePath))
{
@@ -683,6 +747,7 @@ namespace DrillTools
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)
@@ -699,6 +764,7 @@ namespace DrillTools
result.Add($"{tool.MachineCodeCommand},{tool.MachineCodeType},$S $N");
// 添加机台码的坐标数据
// HoleLocations现在应该已经保持了原始顺序
if (tool.HoleLocations != null && tool.HoleLocations.Count > 0)
{
foreach (var location in tool.HoleLocations)
@@ -866,6 +932,9 @@ namespace DrillTools
// 更新按钮状态
UpdateMoveButtonsState();
// 计算并更新最小直径信息
UpdateMinDiameterInfo();
// 加载示例钻带内容
DrillTapeContent = @"M48
@@ -1342,5 +1411,48 @@ M30";
{
IsTopmost = !IsTopmost;
}
/// <summary>
/// 更新最小直径信息
/// </summary>
private void UpdateMinDiameterInfo()
{
// 初始化为最大值,以便找到最小值
MinDrillDiameter = double.MaxValue;
MinSlotDiameter = double.MaxValue;
MinEADiameter = double.MaxValue;
foreach (var tool in Tools)
{
// 根据刀具类型分类计算最小直径
if (tool.ToolType == ToolType.Regular)
{
// 普通钻咀
if (tool.Diameter < MinDrillDiameter)
MinDrillDiameter = tool.Diameter;
}
else if (tool.ToolType == ToolType.Slot)
{
// 槽刀
if (tool.Diameter < MinSlotDiameter)
MinSlotDiameter = tool.Diameter;
// 检查是否是EA型槽刀尾号为2或6
if ((tool.ToolSuffixType == ToolSuffixType.EASlot || tool.ToolSuffixType == ToolSuffixType.EASlot2)
&& tool.Diameter < MinEADiameter)
MinEADiameter = tool.Diameter;
}
}
// 如果没有找到对应的刀具类型将值设为0
if (MinDrillDiameter == double.MaxValue)
MinDrillDiameter = 0;
if (MinSlotDiameter == double.MaxValue)
MinSlotDiameter = 0;
if (MinEADiameter == double.MaxValue)
MinEADiameter = 0;
}
}
}