mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-20 19:17:40 -05:00
feat(common-line): place parts on common lines automatically at a chosen level
Slice 3 of common-line cutting. On costly plate (N26-295: 3/16 RA310S at about $2,500 a sheet) pairing parts one kerf apart fits the part the spacing cannot: the last plate's 38 parts fit on one 48x120 with Auto Nest only with pairs. - Drawing Properties gains "Allow common line" (Drawing.AllowCommonLine, off by default because customer edge-quality needs vary). The nest's CommonLineUsage (Off / When it adds parts / Whenever available) is set in Auto Nest and seeded from Tools > Nest Defaults; both persist (nest.json, defaults.json). - NestPipeline runs the ordinary solve, then, with a level on, trials where eligible parts are offered as kerf-gap pair compounds. Placed pairs expand into parts plus explicit NestJobCommonLine groups, are validated again, and CommonLineRanking keeps a trial only by the level: count first, then sheets; "when it adds parts" keeps the plain layout on a tie, "whenever" also takes a shorter cut or less material, never at the cost of a part. Engines, FillScore and their comparers are unchanged; Off asks the engine exactly what it did. - NestLayoutCheck exempts members only through a sheet's explicit group list and only when the job allows common lines; materializing and committing create Plate.CommonLines. - Server nesting writes common-line jobs as version 3 and replays the recorded trial answers, so the desktop binds the same groups. - Fill Area honors the level through a PlateFillService overload. - The benchmark gains --common-lines <level> --kerf <k>. Benchmark (synthetic nests + N26-295, --parallel 1): with no flag and with --common-lines off every engine matches the base commit; with a level on no layout becomes invalid and three runs save a sheet at equal nested area. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f9b2713420
commit
b026bd19d2
61 files changed
+2155
-118
No files matched your search
@@ -90,6 +90,11 @@ public static class NestLayoutCheck
|
||||
if (!double.IsFinite(pose.Rotation))
|
||||
violations.Add($"{description} has nonfinite Rotation ({pose.Rotation})");
|
||||
}
|
||||
var grouped = new HashSet<int>();
|
||||
foreach (var group in sheet.CommonLines)
|
||||
if (group.Placements.Count < 2 || !double.IsFinite(group.Kerf) || group.Kerf <= 0
|
||||
|| group.Placements.Any(i => i < 0 || i >= sheet.Placements.Count || !grouped.Add(i)))
|
||||
violations.Add($"Plate {sheet.PlateIndex} has a malformed common-line group");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +237,8 @@ public static class NestLayoutCheck
|
||||
|
||||
ValidateBounds(parts, plate, requirements, result);
|
||||
ValidateAreaBudget(parts, plate, result);
|
||||
ValidateSpacing(parts, plate.PartSpacing, requirements, result);
|
||||
ValidateSpacing(parts, plate.PartSpacing, requirements, result, plate.CommonLines);
|
||||
ValidateCommonLines(plate, parts, requirements, result);
|
||||
if (plate.ClampZones.Count > 0)
|
||||
ValidateClamps(parts, plate, requirements, result);
|
||||
}
|
||||
@@ -363,6 +369,9 @@ public static class NestLayoutCheck
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var sheet in jobResult.Plates)
|
||||
ValidateCommonLinesAgainstJob(job, sheet, partsById, displayNames, result);
|
||||
|
||||
foreach (var sheet in jobResult.Plates)
|
||||
{
|
||||
foreach (var placement in sheet.Placements)
|
||||
@@ -384,6 +393,43 @@ public static class NestLayoutCheck
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A sheet's explicit common-line groups must be allowed by the job: a common-line level on,
|
||||
/// the job's kerf, members that allow common lines, and positions on the sheet that no other
|
||||
/// group takes. Geometry (that the members really share edges) is checked on the plate.
|
||||
/// </summary>
|
||||
private static void ValidateCommonLinesAgainstJob(NestJob job, NestJobPlateResult sheet,
|
||||
IReadOnlyDictionary<string, NestJobPart> partsById, IReadOnlyDictionary<string, string> displayNames,
|
||||
List<string> result)
|
||||
{
|
||||
if (sheet.CommonLines.Count == 0)
|
||||
return;
|
||||
if (!job.Options.UsesCommonLines)
|
||||
{
|
||||
result.Add($"Plate {sheet.PlateIndex} has common-line groups, which this job does not allow");
|
||||
return;
|
||||
}
|
||||
var taken = new HashSet<int>();
|
||||
foreach (var group in sheet.CommonLines)
|
||||
{
|
||||
if (BitConverter.DoubleToInt64Bits(group.Kerf) != BitConverter.DoubleToInt64Bits(job.Options.CommonLineKerf))
|
||||
result.Add($"Plate {sheet.PlateIndex} has a common-line group at kerf {group.Kerf:F4}; the job's kerf is {job.Options.CommonLineKerf:F4}");
|
||||
if (group.Placements.Count < 2)
|
||||
result.Add($"Plate {sheet.PlateIndex} has a common-line group of fewer than two parts");
|
||||
foreach (var index in group.Placements)
|
||||
{
|
||||
if (index < 0 || index >= sheet.Placements.Count || !taken.Add(index))
|
||||
{
|
||||
result.Add($"Plate {sheet.PlateIndex} has a common-line group naming placement {index}, which is missing or already in a group");
|
||||
continue;
|
||||
}
|
||||
var id = sheet.Placements[index].PartId;
|
||||
if (id != null && partsById.TryGetValue(id, out var part) && !part.AllowCommonLine)
|
||||
result.Add($"'{displayNames.GetValueOrDefault(id, id)}' is in a common-line group on plate {sheet.PlateIndex} but does not allow common lines");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SameSettings(NestPlateStock expected, NestPlateStock actual) =>
|
||||
ReferenceEquals(expected, actual)
|
||||
|| (
|
||||
@@ -547,9 +593,16 @@ public static class NestLayoutCheck
|
||||
List<Part> parts,
|
||||
double spacing,
|
||||
IReadOnlyDictionary<Drawing, (string Name, int Quantity)> requirements,
|
||||
List<string> result
|
||||
List<string> result,
|
||||
IEnumerable<CommonLineGroup> commonLines = null
|
||||
)
|
||||
{
|
||||
// Members of one explicit common-line group are held to the group's kerf instead.
|
||||
var groupOf = new Dictionary<Part, CommonLineGroup>(ReferenceEqualityComparer.Instance);
|
||||
if (commonLines != null)
|
||||
foreach (var group in commonLines)
|
||||
foreach (var member in group.Members)
|
||||
groupOf.TryAdd(member, group);
|
||||
var profiles = new ShapeProfile[parts.Count];
|
||||
var raw = new SpacingOutline[parts.Count];
|
||||
var inflated = new SpacingOutline[parts.Count];
|
||||
@@ -596,6 +649,18 @@ public static class NestLayoutCheck
|
||||
if (!Overlaps(inflated[i], raw[j]))
|
||||
continue;
|
||||
|
||||
if (groupOf.TryGetValue(parts[i], out var shared)
|
||||
&& groupOf.TryGetValue(parts[j], out var partnerGroup) && ReferenceEquals(shared, partnerGroup))
|
||||
{
|
||||
native[i] ??= NativeContours.Of(profiles[i], parts[i].Location);
|
||||
native[j] ??= NativeContours.Of(profiles[j], parts[j].Location);
|
||||
if (native[i].TooClose(native[j], shared.Kerf))
|
||||
result.Add(
|
||||
$"'{DisplayName(parts[i], requirements)}' and '{DisplayName(parts[j], requirements)}' share a common line but are closer than its kerf ({shared.Kerf:F4})"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
// The outline circumscribes arcs by more than the slack, so confirm a spacing
|
||||
// candidate on the native contours. Zero spacing has no gap to confirm.
|
||||
if (inflateBy > Tolerance.Epsilon)
|
||||
@@ -613,6 +678,29 @@ public static class NestLayoutCheck
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every explicit common-line group must be intact: each member shares a straight edge one
|
||||
/// kerf apart with another member and the members form one connected group
|
||||
/// (<see cref="CommonLineGeometry.Check"/>). A group that does not share is not a common line,
|
||||
/// so its spacing exemption would hide a real violation.
|
||||
/// </summary>
|
||||
private static void ValidateCommonLines(Plate plate, List<Part> parts,
|
||||
IReadOnlyDictionary<Drawing, (string Name, int Quantity)> requirements, List<string> result)
|
||||
{
|
||||
foreach (var group in plate.CommonLines)
|
||||
{
|
||||
if (group.Members.Any(member => !parts.Contains(member)))
|
||||
{
|
||||
result.Add("A common-line group names a part that is not on its plate");
|
||||
continue;
|
||||
}
|
||||
if (!(group.Kerf < plate.PartSpacing))
|
||||
result.Add($"A common-line group's kerf ({group.Kerf:F4}) is not smaller than the part spacing ({plate.PartSpacing:F3})");
|
||||
foreach (var problem in CommonLineGeometry.Check(group).Problems)
|
||||
result.Add($"'{DisplayName(problem.Part, requirements)}' {problem.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Analytic world-space material bounds; surface marks never bound material.</summary>
|
||||
internal static Box MaterialBounds(Part part) => PlateRemnant.MaterialBounds(part);
|
||||
|
||||
|
||||
Reference in new issue
Block a user