feat: 铆钉孔4.503作为PP钻带来源孔径 — PpSourceDiameters集合含3.203/4.503,legacy 3孔与外框13/15孔规则不变
This commit is contained in:
@@ -46,9 +46,16 @@ namespace DrillTools
|
||||
private const int SvsiEnsureVisible = 0x8;
|
||||
private const int SvsiFocused = 0x10;
|
||||
private const int SelectFileFlags = SvsiSelect | SvsiDeselectOthers | SvsiEnsureVisible | SvsiFocused;
|
||||
private const double PpSourceDiameter = 3.203;
|
||||
private static readonly double[] PpSourceDiameters = { 3.203, 4.503 };
|
||||
private const int PpSideCoordinateTolerance = 1500;
|
||||
|
||||
/// <summary>
|
||||
/// PP 钻带来源孔径集合(3.203 PP 定位孔 / 4.503 铆钉孔)。
|
||||
/// 比较使用容差 < 0.001,与 <see cref="ToolItem.IsSpecialFixedDiameter"/> 同风格。
|
||||
/// </summary>
|
||||
private static bool IsPpSourceDiameter(double diameter)
|
||||
=> PpSourceDiameters.Any(d => Math.Abs(diameter - d) < 0.001);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
@@ -1226,7 +1233,7 @@ M30";
|
||||
return null;
|
||||
|
||||
var sourceTool = OriginalTools[OriginalTools.Count - 2];
|
||||
if (Math.Abs(sourceTool.Diameter - PpSourceDiameter) >= 0.001)
|
||||
if (!IsPpSourceDiameter(sourceTool.Diameter))
|
||||
return null;
|
||||
|
||||
if (sourceTool.TotalHoles != 3)
|
||||
@@ -1249,7 +1256,7 @@ M30";
|
||||
private PpGenerationRule? GetOuterPpGenerationRule()
|
||||
{
|
||||
var sourceTool = OriginalTools.FirstOrDefault(tool =>
|
||||
Math.Abs(tool.Diameter - PpSourceDiameter) < 0.001
|
||||
IsPpSourceDiameter(tool.Diameter)
|
||||
&& (tool.TotalHoles == 13 || tool.TotalHoles == 15)
|
||||
&& tool.HoleLocations != null
|
||||
&& tool.HoleLocations.Count >= 4
|
||||
@@ -1261,13 +1268,13 @@ M30";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 3.203 外框孔中按右、上、左、下四边各取一个中位孔,并保持原钻带坐标文本。
|
||||
/// 从 PP 来源孔径(3.203 PP 定位孔 / 4.503 铆钉孔)外框中按右、上、左、下四边各取一个中位孔,并保持原钻带坐标文本。
|
||||
/// </summary>
|
||||
private static List<string> SelectPpDrillTapeLocations(ToolItem sourceTool)
|
||||
{
|
||||
var points = ParsePpHolePoints(sourceTool.HoleLocations);
|
||||
if (points.Count < 4)
|
||||
throw new InvalidOperationException("3.203 刀具坐标不足,无法生成 PP 钻带");
|
||||
throw new InvalidOperationException("PP 来源孔径刀具坐标不足,无法生成 PP 钻带");
|
||||
|
||||
int minX = points.Min(point => point.X);
|
||||
int maxX = points.Max(point => point.X);
|
||||
@@ -1283,7 +1290,7 @@ M30";
|
||||
};
|
||||
|
||||
if (selected.Any(point => point == null))
|
||||
throw new InvalidOperationException("3.203 刀具未形成完整的上下左右四边孔位,无法生成 PP 钻带");
|
||||
throw new InvalidOperationException("PP 来源孔径刀具未形成完整的上下左右四边孔位,无法生成 PP 钻带");
|
||||
|
||||
var selectedTexts = selected
|
||||
.Select(point => point!.Text)
|
||||
@@ -1291,9 +1298,9 @@ M30";
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
|
||||
if (selectedTexts.Count != 4)
|
||||
throw new InvalidOperationException("3.203 刀具四边中位孔存在重复,无法生成 PP 钻带");
|
||||
throw new InvalidOperationException("PP 来源孔径刀具四边中位孔存在重复,无法生成 PP 钻带");
|
||||
|
||||
// 输出顺序沿用原 3.203 刀具中的孔位顺序,避免改变已有钻带坐标排序习惯。
|
||||
// 输出顺序沿用原 PP 来源孔径刀具(3.203/4.503)中的孔位顺序,避免改变已有钻带坐标排序习惯。
|
||||
return points
|
||||
.Where(point => selectedTexts.Contains(point.Text))
|
||||
.Select(point => point.Text)
|
||||
|
||||
Reference in New Issue
Block a user