feat(reporting): mark formed parts on nest report plate pages

A formed part's ID reads "7F" on the plate diagram (shared group labels
too, "7F*" when also tabbed) and in the plate's parts table, with an
"F Formed: goes to forming." legend line, so the operator can sort
formed and flat parts onto separate skids. A job with any formed part
adds a Formed column (Yes / blank) to every plate's parts table.
This commit is contained in:
aj committed 2026-11-26 19:10:23 -05:00
1 parent e498788c28
commit f298aa361d
5 files changed
+158 -13

No files matched your search

+18 -7
View File
@@ -383,10 +383,13 @@ public static class NestPdfWriter
// Only a removed clamp needs words: it is an action before cutting. Hatched clamps and the
// rulers (their unit sits in the corner) explain themselves, and the room goes to parts rows.
// Tabbed parts are marked too: the tabs must be broken to free them. Both lines share one.
// Tabbed parts are marked too: the tabs must be broken to free them. Formed parts are
// marked so the operator sorts them onto the forming skid. The lines share one paragraph.
var tabbed = plate.Parts.Where(part => part.Geometry.StrokeOnly).Select(part => part.ReportId)
.ToHashSet(StringComparer.Ordinal);
var notes = new List<string>();
if (plate.Parts.Any(part => part.Formed))
notes.Add($"{NestReportDiagram.FormedMark} Formed: goes to forming.");
if (tabbed.Count > 0)
notes.Add($"{NestReportDiagram.TabbedMark} Tabbed: held in the sheet by tabs.");
if (plate.Clamps.Any(clamp => clamp.Removed))
@@ -408,13 +411,15 @@ public static class NestPdfWriter
/// The plate's drawings as two side-by-side tables sharing one MigraDoc table, so twice as
/// many fit on the diagram's page. Entries run left to right, then down, which keeps ID order
/// intact when the table continues on later pages; an unbordered column separates the halves.
/// A job with formed parts adds a Formed column to every plate's table.
/// </summary>
private static void AddPlatePartsTable(Section section, NestReportSnapshot snapshot, ReportPlate plate,
IReadOnlyDictionary<string, XColor> colors, HashSet<string> tabbed)
{
const int Halves = 2;
const double Gap = 16;
double[] half = [40, 0, 86, 92];
var formedColumn = snapshot.HasFormedParts;
double[] half = formedColumn ? [40, 0, 48, 86, 92] : [40, 0, 86, 92];
half[1] = (LandscapeWidth - Gap) / Halves - half.Sum();
var widths = new List<double>(half);
widths.Add(Gap);
@@ -427,7 +432,9 @@ public static class NestPdfWriter
var drawings = snapshot.Drawings.Where(drawing => perSheet.ContainsKey(drawing.Id)).ToList();
var parts = AddTable(section, widths.ToArray());
string?[] heading = ["ID", "Drawing", "Parts per plate", $"Total ({plate.Copies} plates)"];
string?[] heading = formedColumn
? ["ID", "Drawing", "Formed", "Parts per plate", $"Total ({plate.Copies} plates)"]
: ["ID", "Drawing", "Parts per plate", $"Total ({plate.Copies} plates)"];
var header = AddRow(parts, "Table heading", true, [.. heading, null, .. heading]);
header.HeadingFormat = true;
header.Format.Font.Bold = true;
@@ -446,10 +453,14 @@ public static class NestPdfWriter
{
var drawing = entries[side];
var count = perSheet[drawing.Id];
cells[side * stride] = tabbed.Contains(drawing.Id) ? drawing.Id + NestReportDiagram.TabbedMark : drawing.Id;
cells[side * stride + 1] = names[drawing.Id];
cells[side * stride + 2] = count.ToString(Invariant);
cells[side * stride + 3] = checked(count * plate.Copies).ToString(Invariant);
var column = side * stride;
cells[column++] = NestReportDiagram.MarkedId(drawing.Id, drawing.Formed,
tabbed.Contains(drawing.Id));
cells[column++] = names[drawing.Id];
if (formedColumn)
cells[column++] = drawing.Formed ? "Yes" : "";
cells[column++] = count.ToString(Invariant);
cells[column] = checked(count * plate.Copies).ToString(Invariant);
}
var row = AddRow(parts, $"Plate {plate.Number}, drawing {entries[0].Id}", false, cells);
for (var side = 0; side < entries.Count; side++)
+5 -1
View File
@@ -84,7 +84,10 @@ public static class NestReportBuilder
}
var item = registry.Register(part.BaseDrawing);
parts.Add(new ReportPlacement(item.Id, geometry));
parts.Add(new ReportPlacement(item.Id, geometry)
{
Formed = part.BaseDrawing.IsFormed,
});
perSheet.TryGetValue(item, out var count);
perSheet[item] = checked(count + 1);
var partArea = part.BaseDrawing.Area;
@@ -178,6 +181,7 @@ public static class NestReportBuilder
System.Math.Max(checked(item.Nested - required), 0), item.Plates.ToImmutableArray(), geometry)
{
Weight = PartWeight(drawing, nest, catalogDensity),
Formed = drawing.IsFormed,
};
}
+15 -4
View File
@@ -100,9 +100,19 @@ internal static class NestReportDiagram
/// <summary>Appended to a tabbed part's ID: its outline is open at the tabs holding it in the sheet.</summary>
internal const string TabbedMark = "*";
/// <summary>A part's diagram label: its report ID, marked when the part is tabbed.</summary>
internal static string LabelText(ReportPlate plate, int index) =>
plate.Parts[index].ReportId + (plate.Parts[index].Geometry.StrokeOnly ? TabbedMark : "");
/// <summary>Appended to a formed part's ID: it goes to the brake or rolls after cutting.</summary>
internal const string FormedMark = "F";
/// <summary>A part's diagram label: its report ID, marked when it is formed or tabbed.</summary>
internal static string LabelText(ReportPlate plate, int index)
{
var part = plate.Parts[index];
return MarkedId(part.ReportId, part.Formed, part.Geometry.StrokeOnly);
}
/// <summary>An ID with its formed mark, then its tabbed mark: "7F*".</summary>
internal static string MarkedId(string id, bool formed, bool tabbed) =>
id + (formed ? FormedMark : "") + (tabbed ? TabbedMark : "");
internal static DiagramView Plan(ReportPlate plate, double width, double height)
{
@@ -254,7 +264,8 @@ internal static class NestReportDiagram
|| groups.Any(group => group.Boundary.IntersectsWith(boundary) || group.Label.Box.IntersectsWith(boundary)))
continue;
var text = members.Any(member => plate.Parts[member].Geometry.StrokeOnly) ? id + TabbedMark : id;
var text = MarkedId(id, plate.Parts[seed].Formed,
members.Any(member => plate.Parts[member].Geometry.StrokeOnly));
var size = ReportText.Size(text, font);
var labelWidth = size.Width + 2 * LabelPadding;
var labelHeight = size.Height + 2 * LabelPadding;
+11 -1
View File
@@ -29,9 +29,16 @@ public sealed record ReportDrawing(string Id, string Name, long Required, long N
/// has no thickness or the material has no density.
/// </summary>
public double? Weight { get; init; }
/// <summary>True when the part is formed (bent or rolled) after cutting.</summary>
public bool Formed { get; init; }
}
public sealed record ReportPlacement(string ReportId, ReportGeometry Geometry);
public sealed record ReportPlacement(string ReportId, ReportGeometry Geometry)
{
/// <summary>True when the part is formed (bent or rolled) after cutting.</summary>
public bool Formed { get; init; }
}
/// <summary>
/// A machine clamp footprint in the parts' placement frame. <paramref name="Removed"/> marks a
@@ -76,6 +83,9 @@ public sealed record NestReportSnapshot(string Name, string Customer, string Not
public bool HasCutTimes { get; init; }
/// <summary>Every plate's estimate times its copies; null when the report has no estimates.</summary>
/// <summary>True when any drawing in the job is formed after cutting.</summary>
public bool HasFormedParts => Drawings.Any(drawing => drawing.Formed);
public TimeSpan? TotalCutTime => !HasCutTimes
? null
: Plates.Aggregate(TimeSpan.Zero, (total, plate) => total + (plate.CutTime ?? TimeSpan.Zero) * plate.Copies);
@@ -0,0 +1,109 @@
using OpenNest.Bending;
using OpenNest.Geometry;
using OpenNest.Reporting;
namespace OpenNest.Tests.Reporting;
/// <summary>Formed parts (bent or rolled after cutting) are marked for sorting.</summary>
public sealed class NestReportFormedTests : IDisposable
{
private readonly string directory =
Path.Combine(Path.GetTempPath(), "opennest-formed-" + Guid.NewGuid().ToString("N"));
public NestReportFormedTests() => Directory.CreateDirectory(directory);
public void Dispose() => Directory.Delete(directory, true);
private static NestReportSnapshot Capture(Nest nest) =>
NestReportBuilder.Capture(nest, NestReportTestData.GeneratedAt);
/// <summary>
/// The report test job with "Bracket" 1 bent (a bend line), "Rotated" 2 formed (marked by
/// hand: its bend lines were lost) and the other "Bracket" 3 flat.
/// </summary>
private static Nest CreateFormedNest()
{
var nest = NestReportTestData.CreateNest();
var parts = nest.Plates[0].Parts;
parts[0].BaseDrawing.Bends.Add(new Bend
{
StartPoint = new Vector(0, 5),
EndPoint = new Vector(10, 5),
});
parts[2].BaseDrawing.FormedOverride = true;
return nest;
}
[Fact]
public void Capture_MarksBentAndHandMarkedDrawingsAndTheirPlacements()
{
var snapshot = Capture(CreateFormedNest());
Assert.Equal(new[] { true, true, false, false }, snapshot.Drawings.Select(d => d.Formed));
var placements = snapshot.Plates[0].Parts;
Assert.Equal(new[] { true, true, true, false }, placements.Select(p => p.Formed));
Assert.True(snapshot.HasFormedParts);
}
[Fact]
public void Capture_UncheckedBentDrawingIsFlat()
{
var nest = CreateFormedNest();
nest.Plates[0].Parts[0].BaseDrawing.FormedOverride = false;
var snapshot = NestReportBuilder.Capture(nest, NestReportTestData.GeneratedAt);
Assert.False(snapshot.Drawings[0].Formed);
Assert.False(snapshot.Plates[0].Parts[0].Formed);
}
[SkippableFact]
public void Write_PlatePageMarksFormedPartsInDiagramTableAndLegend()
{
var nest = CreateFormedNest();
var snapshot = NestReportBuilder.Capture(nest, NestReportTestData.GeneratedAt);
var plan = NestReportDiagram.Plan(snapshot.Plates[0], 720, 265);
Assert.Equal(new[] { "1F", "1F", "2F", "3" }, plan.Labels.Select(l => l.Id).Order());
var path = Path.Combine(directory, "formed.pdf");
NestPdfWriter.Write(snapshot, path);
var plate = ReportPdf.Text(path, 2);
Assert.Matches(@"ID\s+Drawing\s+Formed\s+Parts per plate", plate);
Assert.Matches(@"1F\s+Bracket\s+Yes\s+2\s+4", plate);
Assert.Matches(@"2F\s+Rotated\s+Yes\s+1\s+2", plate);
Assert.Matches(@"(?m)\b3\s+Bracket\s+1\s+2", plate);
Assert.Contains("F Formed: goes to forming.", plate);
}
[SkippableFact]
public void Write_JobWithoutFormedPartsHasNoFormedColumnOrLegend()
{
var path = Path.Combine(directory, "flat.pdf");
NestPdfWriter.Write(Capture(NestReportTestData.CreateNest()), path);
Assert.DoesNotContain("Formed", ReportPdf.Text(path, 2));
}
[Fact]
public void Plan_GroupedTinyFormedPartsCarryTheMarkOnTheirSharedLabel()
{
var nest = NestReportTestData.CreateDenseNest();
nest.Plates[0].Parts[2].BaseDrawing.FormedOverride = true;
var snapshot = NestReportBuilder.Capture(nest, NestReportTestData.GeneratedAt);
var plan = NestReportDiagram.Plan(snapshot.Plates[0], 720, 265);
Assert.Equal("2F", Assert.Single(plan.Groups).Label.Id);
}
[Fact]
public void LabelText_FormedTabbedPartShowsBothMarks()
{
var nest = NestReportTestData.CreateTabbedNest();
nest.Plates[0].Parts[0].BaseDrawing.FormedOverride = true;
var plate = NestReportBuilder.Capture(nest, NestReportTestData.GeneratedAt).Plates[0];
Assert.Equal("1F*", NestReportDiagram.LabelText(plate, 0));
}
}