Files
AohDrllTools/ToolItem.cs
Mr.Xia 5e8b989add 刀具日志增强与PCB钻孔数据大规模更新
本次提交包含以下主要变更:

- 增强了刀具类型、尾号类型及最小直径计算的调试日志,便于问题追踪和数据分析。
- 修正了最小槽刀直径的计算逻辑,EA型槽刀单独处理,提升了判定准确性。
- 针对特殊直径的刀具类型判定增加了专门处理和日志输出。
- 删除了 General_sort.txt 和 s40024079g0-a2-cs-jp-sort.txt 文件内容。
- n40032386g0-a2-cs-jp.drl 文件新增了大量PCB钻孔、槽孔(G85)、外形轮廓等数控加工数据,完善了刀具分组与程序控制指令,满足PCB生产自动化需求。
2025-12-31 15:09:14 +08:00

314 lines
10 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace DrillTools
{
/// <summary>
/// 刀具类型枚举
/// </summary>
public enum ToolType
{
Regular, // 圆孔刀具
Slot, // 槽孔刀具
MachineCode // 机台码刀具
}
/// <summary>
/// 刀具尾号类型枚举
/// </summary>
public enum ToolSuffixType
{
Drill, // 0 - 钻针
Slot, // 1 - 槽刀
EASlot, // 2 - EA型槽刀
DustSlot, // 3 - 粉尘刀(槽刀)
DeburrSlot, // 4 - 去毛刺刀(槽刀)
NonStandard, // 5 - 非标刀
EASlot2, // 6 - EA型槽刀
Special // 7 - 特殊刀具
}
/// <summary>
/// 刀具大类枚举
/// </summary>
public enum ToolCategory
{
Drill, // 钻针
Slot, // 槽刀(包含槽刀、粉尘刀、去毛刺刀)
EA, // EA刀EA型槽刀
NonStandard,// 非标刀
Special // 特殊刀具
}
/// <summary>
/// 刀具信息数据模型
/// </summary>
public class ToolItem : INotifyPropertyChanged
{
private int _toolNumber;
private double _diameter;
// private int _regularHoles; // 孔数功能已移除
// private int _slotHoles; // 孔数功能已移除
// private int _totalHoles; // 孔数功能已移除
private string _parameters = string.Empty;
private ToolType _toolType;
private string _machineCodeType = string.Empty;
private string _machineCodeCommand = string.Empty;
private ToolSuffixType _toolSuffixType;
private ToolCategory _toolCategory;
private List<string> _holeLocations = new();
/// <summary>
/// 刀具编号
/// </summary>
public int ToolNumber
{
get => _toolNumber;
set => SetProperty(ref _toolNumber, value);
}
/// <summary>
/// 孔径(mm)
/// </summary>
public double Diameter
{
get => _diameter;
set => SetProperty(ref _diameter, value);
}
// /// <summary>
// /// 普通孔数
// /// </summary>
// public int RegularHoles
// {
// get => _regularHoles;
// set => SetProperty(ref _regularHoles, value);
// }
// /// <summary>
// /// 槽孔数
// /// </summary>
// public int SlotHoles
// {
// get => _slotHoles;
// set => SetProperty(ref _slotHoles, value);
// }
// /// <summary>
// /// 总孔数
// /// </summary>
// public int TotalHoles
// {
// get => _totalHoles;
// set => SetProperty(ref _totalHoles, value);
// }
/// <summary>
/// 钻机参数
/// </summary>
public string Parameters
{
get => _parameters;
set => SetProperty(ref _parameters, value);
}
/// <summary>
/// 刀具类型
/// </summary>
public ToolType ToolType
{
get => _toolType;
set => SetProperty(ref _toolType, value);
}
/// <summary>
/// 机台码类型 (A或B)
/// </summary>
public string MachineCodeType
{
get => _machineCodeType;
set => SetProperty(ref _machineCodeType, value);
}
/// <summary>
/// 机台码命令 (M97或M98)
/// </summary>
public string MachineCodeCommand
{
get => _machineCodeCommand;
set => SetProperty(ref _machineCodeCommand, value);
}
/// <summary>
/// 刀具尾号类型
/// </summary>
public ToolSuffixType ToolSuffixType
{
get => _toolSuffixType;
set => SetProperty(ref _toolSuffixType, value);
}
/// <summary>
/// 刀具大类
/// </summary>
public ToolCategory ToolCategory
{
get => _toolCategory;
set => SetProperty(ref _toolCategory, value);
}
/// <summary>
/// 孔位数据列表
/// </summary>
public List<string> HoleLocations
{
get => _holeLocations;
set => SetProperty(ref _holeLocations, value);
}
/// <summary>
/// 刀具类型显示文本
/// </summary>
public string ToolTypeDisplay => ToolType switch
{
ToolType.Regular => "圆孔",
ToolType.Slot => "槽孔",
ToolType.MachineCode => "机台码",
_ => "未知"
};
/// <summary>
/// 刀具尾号类型显示文本
/// </summary>
public string ToolSuffixTypeDisplay => GetToolSuffixTypeDisplay(ToolSuffixType);
/// <summary>
/// 刀具大类显示文本
/// </summary>
public string ToolCategoryDisplay => GetToolCategoryDisplay(ToolCategory);
public event PropertyChangedEventHandler? PropertyChanged;
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value))
return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
/// <summary>
/// 根据孔径尾号判断刀具尾号类型
/// </summary>
/// <param name="diameter">孔径</param>
/// <returns>刀具尾号类型</returns>
public static ToolSuffixType GetToolSuffixType(double diameter)
{
// 特殊孔径优先判断
if (Math.Abs(diameter - 1.049) < 0.001 ||
Math.Abs(diameter - 3.175) < 0.001 ||
Math.Abs(diameter - 0.499) < 0.001)
{
System.Diagnostics.Debug.WriteLine($"[尾号类型判断] 直径={diameter:F3}: 特殊孔径,尾号类型=钻针");
return ToolSuffixType.Drill; // 固定为圆孔
}
// 获取孔径的小数部分最后一位
string diameterStr = diameter.ToString("F3");
if (diameterStr.Length >= 4 && diameterStr.Contains('.'))
{
char lastChar = diameterStr[diameterStr.Length - 1];
int suffix = int.Parse(lastChar.ToString());
var suffixType = suffix switch
{
0 => ToolSuffixType.Drill,
1 => ToolSuffixType.Slot,
2 => ToolSuffixType.EASlot,
3 => ToolSuffixType.DustSlot,
4 => ToolSuffixType.DeburrSlot,
5 => ToolSuffixType.NonStandard,
6 => ToolSuffixType.EASlot2,
7 => ToolSuffixType.Special,
8 => ToolSuffixType.Drill,
9 => ToolSuffixType.Drill,
_ => ToolSuffixType.NonStandard
};
System.Diagnostics.Debug.WriteLine($"[尾号类型判断] 直径={diameter:F3}, 字符串={diameterStr}, 尾号={suffix}, 尾号类型={suffixType}");
return suffixType;
}
System.Diagnostics.Debug.WriteLine($"[尾号类型判断] 直径={diameter:F3}: 格式异常,尾号类型=非标刀");
return ToolSuffixType.NonStandard; // 默认为非标刀
}
/// <summary>
/// 根据刀具尾号类型获取刀具大类
/// </summary>
/// <param name="suffixType">刀具尾号类型</param>
/// <returns>刀具大类</returns>
public static ToolCategory GetToolCategory(ToolSuffixType suffixType)
{
return suffixType switch
{
ToolSuffixType.Drill => ToolCategory.Drill,
ToolSuffixType.Slot or ToolSuffixType.DustSlot or ToolSuffixType.DeburrSlot => ToolCategory.Slot,
ToolSuffixType.EASlot or ToolSuffixType.EASlot2 => ToolCategory.EA,
ToolSuffixType.NonStandard => ToolCategory.NonStandard,
ToolSuffixType.Special => ToolCategory.Special,
_ => ToolCategory.NonStandard
};
}
/// <summary>
/// 获取刀具尾号类型的显示文本
/// </summary>
/// <param name="suffixType">刀具尾号类型</param>
/// <returns>显示文本</returns>
public static string GetToolSuffixTypeDisplay(ToolSuffixType suffixType)
{
return suffixType switch
{
ToolSuffixType.Drill => "钻针",
ToolSuffixType.Slot => "槽刀",
ToolSuffixType.EASlot => "EA型槽刀",
ToolSuffixType.DustSlot => "粉尘刀",
ToolSuffixType.DeburrSlot => "去毛刺刀",
ToolSuffixType.NonStandard => "非标刀",
ToolSuffixType.EASlot2 => "EA型槽刀",
ToolSuffixType.Special => "特殊刀具",
_ => "未知"
};
}
/// <summary>
/// 获取刀具大类的显示文本
/// </summary>
/// <param name="category">刀具大类</param>
/// <returns>显示文本</returns>
public static string GetToolCategoryDisplay(ToolCategory category)
{
return category switch
{
ToolCategory.Drill => "钻针",
ToolCategory.Slot => "槽刀",
ToolCategory.EA => "EA刀",
ToolCategory.NonStandard => "非标刀",
ToolCategory.Special => "特殊刀",
_ => "未知"
};
}
}
}