using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace DrillTools
{
///
/// 刀具类型枚举
///
public enum ToolType
{
Regular, // 圆孔刀具
Slot, // 槽孔刀具
MachineCode // 机台码刀具
}
///
/// 刀具尾号类型枚举
///
public enum ToolSuffixType
{
Drill, // 0 - 钻针
Slot, // 1 - 槽刀
EASlot, // 2 - EA型槽刀
DustSlot, // 3 - 粉尘刀(槽刀)
DeburrSlot, // 4 - 去毛刺刀(槽刀)
NonStandard, // 5 - 非标刀
EASlot2, // 6 - EA型槽刀
Special // 7 - 特殊刀具
}
///
/// 刀具大类枚举
///
public enum ToolCategory
{
Drill, // 钻针
Slot, // 槽刀(包含槽刀、粉尘刀、去毛刺刀)
EA, // EA刀(EA型槽刀)
NonStandard,// 非标刀
Special // 特殊刀具
}
///
/// 刀具信息数据模型
///
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 _holeLocations = new();
///
/// 刀具编号
///
public int ToolNumber
{
get => _toolNumber;
set => SetProperty(ref _toolNumber, value);
}
///
/// 孔径(mm)
///
public double Diameter
{
get => _diameter;
set => SetProperty(ref _diameter, value);
}
// ///
// /// 普通孔数
// ///
// public int RegularHoles
// {
// get => _regularHoles;
// set => SetProperty(ref _regularHoles, value);
// }
// ///
// /// 槽孔数
// ///
// public int SlotHoles
// {
// get => _slotHoles;
// set => SetProperty(ref _slotHoles, value);
// }
// ///
// /// 总孔数
// ///
// public int TotalHoles
// {
// get => _totalHoles;
// set => SetProperty(ref _totalHoles, value);
// }
///
/// 钻机参数
///
public string Parameters
{
get => _parameters;
set => SetProperty(ref _parameters, value);
}
///
/// 刀具类型
///
public ToolType ToolType
{
get => _toolType;
set => SetProperty(ref _toolType, value);
}
///
/// 机台码类型 (A或B)
///
public string MachineCodeType
{
get => _machineCodeType;
set => SetProperty(ref _machineCodeType, value);
}
///
/// 机台码命令 (M97或M98)
///
public string MachineCodeCommand
{
get => _machineCodeCommand;
set => SetProperty(ref _machineCodeCommand, value);
}
///
/// 刀具尾号类型
///
public ToolSuffixType ToolSuffixType
{
get => _toolSuffixType;
set => SetProperty(ref _toolSuffixType, value);
}
///
/// 刀具大类
///
public ToolCategory ToolCategory
{
get => _toolCategory;
set => SetProperty(ref _toolCategory, value);
}
///
/// 孔位数据列表
///
public List HoleLocations
{
get => _holeLocations;
set => SetProperty(ref _holeLocations, value);
}
///
/// 刀具类型显示文本
///
public string ToolTypeDisplay => ToolType switch
{
ToolType.Regular => "圆孔",
ToolType.Slot => "槽孔",
ToolType.MachineCode => "机台码",
_ => "未知"
};
///
/// 刀具尾号类型显示文本
///
public string ToolSuffixTypeDisplay => GetToolSuffixTypeDisplay(ToolSuffixType);
///
/// 刀具大类显示文本
///
public string ToolCategoryDisplay => GetToolCategoryDisplay(ToolCategory);
public event PropertyChangedEventHandler? PropertyChanged;
protected bool SetProperty(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer.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));
}
///
/// 根据孔径尾号判断刀具尾号类型
///
/// 孔径
/// 刀具尾号类型
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)
{
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());
return 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
};
}
return ToolSuffixType.NonStandard; // 默认为非标刀
}
///
/// 根据刀具尾号类型获取刀具大类
///
/// 刀具尾号类型
/// 刀具大类
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
};
}
///
/// 获取刀具尾号类型的显示文本
///
/// 刀具尾号类型
/// 显示文本
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 => "特殊刀具",
_ => "未知"
};
}
///
/// 获取刀具大类的显示文本
///
/// 刀具大类
/// 显示文本
public static string GetToolCategoryDisplay(ToolCategory category)
{
return category switch
{
ToolCategory.Drill => "钻针",
ToolCategory.Slot => "槽刀",
ToolCategory.EA => "EA刀",
ToolCategory.NonStandard => "非标刀",
ToolCategory.Special => "特殊刀",
_ => "未知"
};
}
}
}