fix: 按尾号标准计算最小刀径,排除粉尘刀与去毛刺刀

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-09 17:44:07 +08:00
parent c20a2c62b8
commit b51a5cecf8
4 changed files with 94 additions and 111 deletions

View File

@@ -302,46 +302,14 @@ namespace DrillTools
/// <summary>
/// 从 MainWindowViewModel.Tools 独立遍历计算叠板用最小刀径。
/// 分类逻辑与 UpdateMinDiameterInfo 一致(按 ToolType 区分圆孔/槽孔),不排除 0.749mm
/// 分类逻辑与 UpdateMinDiameterInfo 一致(按尾号使用标准),不排除 0.749mm
/// 特殊固定孔径3.203 等)不参与叠板计算。
/// </summary>
private static void CalculateStackMinDiameters(
ObservableCollection<ToolItem> tools,
StartupSelectionViewModel selectionViewModel)
{
double minDrill = 0;
double minSlot = 0;
double minEA = 0;
foreach (var tool in tools)
{
if (tool.ToolType == ToolType.MachineCode)
continue;
if (ToolItem.IsSpecialFixedDiameter(tool.Diameter))
continue;
if (tool.ToolType == ToolType.Regular)
{
if (minDrill == 0 || tool.Diameter < minDrill)
minDrill = tool.Diameter;
}
else if (tool.ToolType == ToolType.Slot)
{
if (tool.ToolSuffixType != ToolSuffixType.EASlot && tool.ToolSuffixType != ToolSuffixType.EASlot2)
{
if (minSlot == 0 || tool.Diameter < minSlot)
minSlot = tool.Diameter;
}
if ((tool.ToolSuffixType == ToolSuffixType.EASlot || tool.ToolSuffixType == ToolSuffixType.EASlot2)
&& (minEA == 0 || tool.Diameter < minEA))
{
minEA = tool.Diameter;
}
}
}
var (minDrill, minSlot, minEA) = ToolItem.CalculateMinDiameters(tools, exclude749ForDisplay: false);
selectionViewModel.StackCalcMinDrill = minDrill;
selectionViewModel.StackCalcMinSlot = minSlot;
selectionViewModel.StackCalcMinEA = minEA;

View File

@@ -47,7 +47,6 @@ namespace DrillTools
private const int SvsiFocused = 0x10;
private const int SelectFileFlags = SvsiSelect | SvsiDeselectOthers | SvsiEnsureVisible | SvsiFocused;
private const double PpSourceDiameter = 3.203;
private const double MinDiameterExcludedDiameter = 0.749;
private const int PpSideCoordinateTolerance = 1500;
[DllImport("user32.dll")]
@@ -1851,79 +1850,10 @@ M30";
/// </summary>
private void UpdateMinDiameterInfo()
{
// 初始化为最大值,以便找到最小值
MinDrillDiameter = double.MaxValue;
MinSlotDiameter = double.MaxValue;
MinEADiameter = double.MaxValue;
// 添加调试日志
System.Diagnostics.Debug.WriteLine("=== 开始计算最小直径信息 ===");
foreach (var tool in Tools)
{
// 添加详细的刀具信息日志
System.Diagnostics.Debug.WriteLine($"[刀具分析] T{tool.ToolNumber:D2}: 直径={tool.Diameter:F3}, 类型={tool.ToolType}, 尾号类型={tool.ToolSuffixType}, 大类={tool.ToolCategory}");
// 0.749mm 不参与最小孔径显示,刀具本身仍保留在列表和后续业务流程中。
if (Math.Abs(tool.Diameter - MinDiameterExcludedDiameter) < 0.001)
{
System.Diagnostics.Debug.WriteLine($"[最小孔径排除] T{tool.ToolNumber:D2}: 直径={tool.Diameter:F3} 不参与最小直径计算");
continue;
}
// 根据刀具类型分类计算最小直径
if (tool.ToolType == ToolType.Regular)
{
// 普通钻咀
if (tool.Diameter < MinDrillDiameter)
MinDrillDiameter = tool.Diameter;
System.Diagnostics.Debug.WriteLine($"[钻咀] 当前最小钻咀直径: {MinDrillDiameter:F3}");
}
else if (tool.ToolType == ToolType.Slot)
{
// 槽刀 - 修复只有真正的槽刀非EA型槽刀才计入最小槽刀直径
// EA型槽刀不应该计入最小槽刀直径的计算
if (tool.ToolSuffixType != ToolSuffixType.EASlot && tool.ToolSuffixType != ToolSuffixType.EASlot2)
{
if (tool.Diameter < MinSlotDiameter)
MinSlotDiameter = tool.Diameter;
System.Diagnostics.Debug.WriteLine($"[槽刀] T{tool.ToolNumber:D2}是真正的槽刀,当前最小槽刀直径: {MinSlotDiameter:F3}");
}
else
{
System.Diagnostics.Debug.WriteLine($"[EA刀] T{tool.ToolNumber:D2}是EA型槽刀不计入最小槽刀直径计算");
}
// 检查是否是EA型槽刀尾号为2或6
if ((tool.ToolSuffixType == ToolSuffixType.EASlot || tool.ToolSuffixType == ToolSuffixType.EASlot2)
&& tool.Diameter < MinEADiameter)
MinEADiameter = tool.Diameter;
// 特别标记EA型槽刀
if (tool.ToolSuffixType == ToolSuffixType.EASlot || tool.ToolSuffixType == ToolSuffixType.EASlot2)
{
System.Diagnostics.Debug.WriteLine($"[EA刀] T{tool.ToolNumber:D2}是EA型槽刀直径={tool.Diameter:F3}");
}
}
}
// 如果没有找到对应的刀具类型将值设为0
if (MinDrillDiameter == double.MaxValue)
MinDrillDiameter = 0;
if (MinSlotDiameter == double.MaxValue)
MinSlotDiameter = 0;
if (MinEADiameter == double.MaxValue)
MinEADiameter = 0;
System.Diagnostics.Debug.WriteLine($"=== 最终结果 ===");
System.Diagnostics.Debug.WriteLine($"最小钻咀: {MinDrillDiameter:F3}");
System.Diagnostics.Debug.WriteLine($"最小槽刀: {MinSlotDiameter:F3}");
System.Diagnostics.Debug.WriteLine($"最小EA刀: {MinEADiameter:F3}");
System.Diagnostics.Debug.WriteLine($"=== 计算完成 ===");
var (minDrill, minSlot, minEA) = ToolItem.CalculateMinDiameters(Tools, exclude749ForDisplay: true);
MinDrillDiameter = minDrill;
MinSlotDiameter = minSlot;
MinEADiameter = minEA;
}
/// <summary>

View File

@@ -175,12 +175,12 @@ namespace DrillTools
public double StackCalcMinDrill { get; set; }
/// <summary>
/// 叠板计算用的最小槽刀直径(仅真实槽孔刀,由调用方独立计算)
/// 叠板计算用的最小槽刀直径(尾号 1 槽刀,由调用方按尾号标准独立计算)
/// </summary>
public double StackCalcMinSlot { get; set; }
/// <summary>
/// 叠板计算用的最小EA刀直径由调用方独立计算)
/// 叠板计算用的最小 EA 刀直径(尾号 2/6 EA 型槽刀,由调用方按尾号标准独立计算)
/// </summary>
public double StackCalcMinEA { get; set; }

View File

@@ -30,6 +30,19 @@ namespace DrillTools
Special // 7 - 特殊刀具
}
/// <summary>
/// 最小刀径参数分组(按尾号使用标准)
/// </summary>
public enum MinDiameterParameterGroup
{
None,
Drill,
Slot,
EA,
Dust,
Deburr
}
/// <summary>
/// 刀具大类枚举
/// </summary>
@@ -330,5 +343,77 @@ namespace DrillTools
_ => "未知"
};
}
/// <summary>
/// 0.749mm 不参与界面最小孔径显示。
/// </summary>
public const double MinDiameterExcludedDiameter = 0.749;
/// <summary>
/// 按尾号使用标准映射到最小刀径参数分组。
/// 0/5/8/9→钻针1→槽刀2/6→EA3→粉尘刀4→去毛刺刀(BSH)7→不设定参数。
/// </summary>
public static MinDiameterParameterGroup GetMinDiameterParameterGroup(ToolSuffixType suffixType)
{
return suffixType switch
{
ToolSuffixType.Drill => MinDiameterParameterGroup.Drill,
ToolSuffixType.NonStandard => MinDiameterParameterGroup.Drill,
ToolSuffixType.Slot => MinDiameterParameterGroup.Slot,
ToolSuffixType.EASlot or ToolSuffixType.EASlot2 => MinDiameterParameterGroup.EA,
ToolSuffixType.DustSlot => MinDiameterParameterGroup.Dust,
ToolSuffixType.DeburrSlot => MinDiameterParameterGroup.Deburr,
ToolSuffixType.Special => MinDiameterParameterGroup.None,
_ => MinDiameterParameterGroup.None
};
}
/// <summary>
/// 按尾号规则计算最小钻针、槽刀、EA 刀直径。
/// 粉尘刀与去毛刺刀使用独立参数表,不参与三者最小值;特殊刀与固定孔径不参与。
/// </summary>
/// <param name="tools">刀具集合</param>
/// <param name="exclude749ForDisplay">为 true 时排除 0.749mm(界面显示用)</param>
public static (double MinDrill, double MinSlot, double MinEA) CalculateMinDiameters(
IEnumerable<ToolItem> tools,
bool exclude749ForDisplay = false)
{
double minDrill = 0;
double minSlot = 0;
double minEA = 0;
foreach (var tool in tools)
{
if (tool.ToolType == ToolType.MachineCode)
continue;
if (IsSpecialFixedDiameter(tool.Diameter))
continue;
if (exclude749ForDisplay
&& Math.Abs(tool.Diameter - MinDiameterExcludedDiameter) < 0.001)
{
continue;
}
switch (GetMinDiameterParameterGroup(tool.ToolSuffixType))
{
case MinDiameterParameterGroup.Drill:
if (minDrill == 0 || tool.Diameter < minDrill)
minDrill = tool.Diameter;
break;
case MinDiameterParameterGroup.Slot:
if (minSlot == 0 || tool.Diameter < minSlot)
minSlot = tool.Diameter;
break;
case MinDiameterParameterGroup.EA:
if (minEA == 0 || tool.Diameter < minEA)
minEA = tool.Diameter;
break;
}
}
return (minDrill, minSlot, minEA);
}
}
}
}