diff --git a/App.xaml.cs b/App.xaml.cs
index 198550f..a91554b 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -302,46 +302,14 @@ namespace DrillTools
///
/// 从 MainWindowViewModel.Tools 独立遍历计算叠板用最小刀径。
- /// 分类逻辑与 UpdateMinDiameterInfo 一致(按 ToolType 区分圆孔/槽孔),不排除 0.749mm;
+ /// 分类逻辑与 UpdateMinDiameterInfo 一致(按尾号使用标准),不排除 0.749mm;
/// 特殊固定孔径(3.203 等)不参与叠板计算。
///
private static void CalculateStackMinDiameters(
ObservableCollection 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;
diff --git a/MainWindowViewModel.cs b/MainWindowViewModel.cs
index 66d82cf..43cbec1 100644
--- a/MainWindowViewModel.cs
+++ b/MainWindowViewModel.cs
@@ -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";
///
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;
}
///
diff --git a/StartupSelectionViewModel.cs b/StartupSelectionViewModel.cs
index 2099ab6..83bf2f7 100644
--- a/StartupSelectionViewModel.cs
+++ b/StartupSelectionViewModel.cs
@@ -175,12 +175,12 @@ namespace DrillTools
public double StackCalcMinDrill { get; set; }
///
- /// 叠板计算用的最小槽刀直径(仅真实槽孔刀,由调用方独立计算)
+ /// 叠板计算用的最小槽刀直径(尾号 1 槽刀,由调用方按尾号标准独立计算)
///
public double StackCalcMinSlot { get; set; }
///
- /// 叠板计算用的最小EA刀直径(由调用方独立计算)
+ /// 叠板计算用的最小 EA 刀直径(尾号 2/6 EA 型槽刀,由调用方按尾号标准独立计算)
///
public double StackCalcMinEA { get; set; }
diff --git a/ToolItem.cs b/ToolItem.cs
index 91665af..d09edaf 100644
--- a/ToolItem.cs
+++ b/ToolItem.cs
@@ -30,6 +30,19 @@ namespace DrillTools
Special // 7 - 特殊刀具
}
+ ///
+ /// 最小刀径参数分组(按尾号使用标准)
+ ///
+ public enum MinDiameterParameterGroup
+ {
+ None,
+ Drill,
+ Slot,
+ EA,
+ Dust,
+ Deburr
+ }
+
///
/// 刀具大类枚举
///
@@ -330,5 +343,77 @@ namespace DrillTools
_ => "未知"
};
}
+
+ ///
+ /// 0.749mm 不参与界面最小孔径显示。
+ ///
+ public const double MinDiameterExcludedDiameter = 0.749;
+
+ ///
+ /// 按尾号使用标准映射到最小刀径参数分组。
+ /// 0/5/8/9→钻针,1→槽刀,2/6→EA,3→粉尘刀,4→去毛刺刀(BSH),7→不设定参数。
+ ///
+ 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
+ };
+ }
+
+ ///
+ /// 按尾号规则计算最小钻针、槽刀、EA 刀直径。
+ /// 粉尘刀与去毛刺刀使用独立参数表,不参与三者最小值;特殊刀与固定孔径不参与。
+ ///
+ /// 刀具集合
+ /// 为 true 时排除 0.749mm(界面显示用)
+ public static (double MinDrill, double MinSlot, double MinEA) CalculateMinDiameters(
+ IEnumerable 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);
+ }
}
-}
\ No newline at end of file
+}