feat(report): add sheet weight to the plates table

The shop needs each sheet's weight for handling, so the summary's plates
table gains a Sheet weight column: one full sheet from its area, the nest
thickness and the nest (or catalog) density. A drawing's own material is
not used, since it doesn't say what the stock is; with no density the
column is left out.

Plates with copies now put the total cut time (and total weight) on a
second line instead of after a comma, which wrapped mid-phrase.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-09 12:59:31 -05:00
1 parent ae8e7c6e42
commit e58e8b85c4
6 files changed
+114 -25

No files matched your search

+46 -17
View File
@@ -146,23 +146,8 @@ public static class NestPdfWriter
AddHeading(section, "Plates");
if (snapshot.Plates.Length == 0)
section.AddParagraph("No plates in this job.");
else if (!snapshot.HasCutTimes)
{
var plates = AddTable(section, 60, 200, 80, 100, 100);
AddHeader(plates, "Plate", "Stock size", "Quantity", "Parts per plate", "Utilization");
foreach (var plate in snapshot.Plates)
AddRow(plates, $"Plate {plate.Number}", false, plate.Number.ToString(Invariant), SheetSize(snapshot, plate),
plate.Copies.ToString(Invariant), plate.Parts.Length.ToString(Invariant), Percent(plate.Utilization));
}
else
{
var plates = AddTable(section, 44, 150, 60, 96, 74, 116);
AddHeader(plates, "Plate", "Stock size", "Quantity", "Parts per plate", "Utilization", "Est. cut time");
foreach (var plate in snapshot.Plates)
AddRow(plates, $"Plate {plate.Number}", false, plate.Number.ToString(Invariant), SheetSize(snapshot, plate),
plate.Copies.ToString(Invariant), plate.Parts.Length.ToString(Invariant), Percent(plate.Utilization),
PlateCutTime(plate));
}
AddPlatesTable(section, snapshot);
AddHeading(section, "Parts");
if (snapshot.Drawings.Length == 0)
@@ -179,6 +164,50 @@ public static class NestPdfWriter
AddPartCards(section, snapshot);
}
/// <summary>
/// Sheet weight and cut time columns appear only when the report has them; the stock size
/// column takes whatever width they leave.
/// </summary>
private static void AddPlatesTable(Section section, NestReportSnapshot snapshot)
{
var hasWeights = snapshot.Plates.Any(plate => plate.Weight != null);
var widths = new List<double> { 40, 0, 56, 92, 68 };
var headings = new List<string> { "Plate", "Stock size", "Quantity", "Parts per plate", "Utilization" };
if (hasWeights)
{
widths.Add(92);
headings.Add("Sheet weight");
}
if (snapshot.HasCutTimes)
{
widths.Add(92);
headings.Add("Est. cut time");
}
widths[1] = PortraitWidth - widths.Sum();
var plates = AddTable(section, widths.ToArray());
AddHeader(plates, headings.ToArray());
foreach (var plate in snapshot.Plates)
{
var cells = new List<string>
{
plate.Number.ToString(Invariant), SheetSize(snapshot, plate), plate.Copies.ToString(Invariant),
plate.Parts.Length.ToString(Invariant), Percent(plate.Utilization),
};
if (hasWeights)
cells.Add(SheetWeight(snapshot, plate));
if (snapshot.HasCutTimes)
cells.Add(PlateCutTime(plate));
AddRow(plates, $"Plate {plate.Number}", false, cells.ToArray());
}
}
/// <summary>One sheet, then all its copies on a second line.</summary>
private static string SheetWeight(NestReportSnapshot snapshot, ReportPlate plate) =>
plate.Weight is not { } each ? "-"
: plate.Copies == 1 ? $"{Weight(each)} {snapshot.WeightUnits}"
: $"{Weight(each)} {snapshot.WeightUnits} each\n{Weight(each * plate.Copies)} {snapshot.WeightUnits} total";
/// <summary>
/// One card per drawing, <see cref="CardsPerRow"/> to a row. Cards are table cells with
/// unbordered spacer columns between them; MigraDoc never splits a row across pages.
@@ -612,7 +641,7 @@ public static class NestPdfWriter
private static string PlateCutTime(ReportPlate plate) =>
plate.CutTime is not { } time ? ""
: plate.Copies == 1 ? Duration(time)
: $"{Duration(time)} each, {Duration(time * plate.Copies)} total";
: $"{Duration(time)} each\n{Duration(time * plate.Copies)} total";
/// <summary>Whole seconds as "1h 02m 03s", "4m 05s" or "45s".</summary>
private static string Duration(TimeSpan time)
+18 -6
View File
@@ -23,7 +23,7 @@ public static class NestReportBuilder
var plateCount = ReportedPlateCount(nest);
for (var index = 0; index < plateCount; index++)
plates.Add(CapturePlate(nest.Plates[index], index + 1, registry, cutParameters));
plates.Add(CapturePlate(nest.Plates[index], index + 1, registry, cutParameters, nest, catalogDensity));
// OrderBy is stable, so the original enumeration breaks equal name/path ties.
foreach (var drawing in nest.Drawings
@@ -60,7 +60,8 @@ public static class NestReportBuilder
return plateCount;
}
private static ReportPlate CapturePlate(Plate plate, int number, DrawingRegistry registry, CutParameters? cutParameters)
private static ReportPlate CapturePlate(Plate plate, int number, DrawingRegistry registry, CutParameters? cutParameters,
Nest nest, double catalogDensity)
{
ValidatePlate(plate, number);
var bounds = CaptureBounds(plate, number);
@@ -103,6 +104,7 @@ public static class NestReportBuilder
utilization, parts.ToImmutable(), cutoffs.ToImmutable())
{
CutTime = cutParameters == null ? null : EstimateCutTime(plate, cutParameters, number),
Weight = Weight(plate.Area(), nest, SheetDensity(nest, catalogDensity)),
};
}
@@ -156,12 +158,22 @@ public static class NestReportBuilder
/// </summary>
internal static double? PartWeight(Drawing drawing, Nest nest, double catalogDensity = 0)
{
var density = nest.Material?.Density ?? 0;
if (!(density > 0))
density = catalogDensity;
var density = SheetDensity(nest, catalogDensity);
if (!(density > 0))
density = drawing.Material?.Density ?? 0;
var area = drawing.Area;
return Weight(drawing.Area, nest, density);
}
/// <summary>The nest material's density, then the machine catalog's; zero when neither has one.</summary>
private static double SheetDensity(Nest nest, double catalogDensity)
{
var density = nest.Material?.Density ?? 0;
return density > 0 ? density : catalogDensity;
}
/// <summary>Area x nest thickness x density (lb/in^3); null when any of them is missing.</summary>
private static double? Weight(double area, Nest nest, double density)
{
if (!PositiveFinite(density) || !PositiveFinite(nest.Thickness) || !double.IsFinite(area) || area < 0)
return null;
var volume = area * nest.Thickness;
+6
View File
@@ -38,6 +38,12 @@ public sealed record ReportPlate(int Number, ReportBounds Bounds, int Copies, do
{
/// <summary>Estimated time to cut one copy of this plate; null when no estimate was requested.</summary>
public TimeSpan? CutTime { get; init; }
/// <summary>
/// Weight of one full sheet (outline area x nest thickness x the nest material's density) in
/// <see cref="NestReportSnapshot.WeightUnits"/>; null when the thickness or density is unknown.
/// </summary>
public double? Weight { get; init; }
}
/// <summary>A detached value snapshot. No domain objects or mutable geometry are retained.</summary>
@@ -48,6 +48,9 @@ public sealed class NestPdfWriterTests : IDisposable
Assert.Matches(@"Distinct layouts:\s+1", summary);
Assert.Matches(@"Total physical sheets:\s+2", summary);
Assert.Matches(@"1\s+24 x 48 in\s+2\s+4\s+\d+\.\d%", summary);
Assert.Contains("40.8 lb each", summary);
Assert.Contains("Sheet weight", summary);
Assert.Contains("81.7 lb total", summary);
Assert.Equal(new[]
{
"1 SHORT 1\nBracket\nSize: 10 x 10 in\nWeight: 3.43 lb ea\nTotal weight: 13.7 lb\nRequired 5, nested 4\nPlates: 1",
@@ -227,6 +230,10 @@ public sealed class NestPdfWriterTests : IDisposable
Assert.Contains("Estimated cut time:", summary);
Assert.DoesNotContain("basis", summary, StringComparison.OrdinalIgnoreCase);
Assert.Contains("Est. cut time", summary);
// A plate with copies puts its total on a second line, not after a comma.
Assert.Matches(@"\d+s each", summary);
Assert.Matches(@"\d+s total", summary);
Assert.DoesNotContain("each,", summary);
Assert.Contains("per plate", plate);
Assert.Contains("Total cut time:", plate);
}
@@ -29,6 +29,32 @@ public class NestReportBuilderTests
Assert.Equal(8 * 0.125 * 0.2836, snapshot.Drawings[1].Weight!.Value, 9);
}
[Fact]
public void Capture_WeighsEachFullSheetFromItsAreaThicknessAndTheNestDensity()
{
var snapshot = NestReportBuilder.Capture(NestReportTestData.CreateNest(), NestReportTestData.GeneratedAt);
// One copy of the whole 24 x 48 sheet, not just the parts on it.
Assert.Equal(24 * 48 * 0.125 * 0.2836, snapshot.Plates[0].Weight!.Value, 9);
}
[Fact]
public void Capture_SheetWeightIgnoresTheDrawingsOwnMaterial()
{
var nest = new Nest("Weights") { Units = Units.Inches, Thickness = 0.125, Material = new Material("Steel", "", 0) };
var drawing = NestReportTestData.Rectangle("Plate", 1, 1);
drawing.Material = new Material("Steel", "", 0.2836);
nest.Drawings.Add(drawing);
var plate = new Plate(24, 48) { Quantity = 1 };
plate.Parts.Add(new Part(drawing));
nest.Plates.Add(plate);
var snapshot = NestReportBuilder.Capture(nest, NestReportTestData.GeneratedAt);
Assert.NotNull(snapshot.Drawings[0].Weight);
Assert.Null(snapshot.Plates[0].Weight);
}
[Fact]
public void Capture_MillimeterJobConvertsTheVolumeAndReportsKilograms()
{
+11 -2
View File
@@ -61,6 +61,9 @@ the selected plate, or certify that a layout passed geometry/pre-post checks.
fallback. Millimeter jobs convert the volume to
cubic inches and report kilograms. With no thickness or no density the weight
is unknown, never zero.
- A plate's sheet weight is one full sheet (its outline area for an irregular
sheet) times the nest thickness and density, from the nest material or the
catalog only: a drawing's own material does not say what the stock is.
## Layout, pagination and dense-label fallback
@@ -81,9 +84,14 @@ beside the ID; complete drawings show no status. Cards without a weight show
"-" with a note under the Parts heading saying what is missing. A card row is
a table row, so a card never splits across pages.
The summary's header lists the job and material on the left and the dates and
totals on the right, to leave room for part cards on the first page.
Stock sizes read **width x length** in job units. Plate tables use **Quantity**
and **Parts per plate**; the plate quantity multiplies per-plate part counts for
the totals.
the totals. The summary's Plates table adds a **Sheet weight** column when any
plate's weight is known; a plate with copies shows one sheet's weight, then all
copies on a second line.
Individual IDs use 7 pt text centered on the part's pole of inaccessibility
(`PolyLabel`, as in `PlateView`), clear of edges, holes, cutoffs and other labels.
@@ -136,7 +144,8 @@ settings last used in Calculate Cut Time or the simulator), each plate gets an
estimated time per copy from `CutSimulation`, plus clamp-removal minutes, the same
as Calculate Cut Time (see [cut-time estimates](cut-time-estimates.md)). The summary
shows the job total over all sheets, and the plates table gains an "Est. cut time"
column. Each plate page shows the time per plate and for all its copies. The report
column (a plate with copies gives the time for each, then the total on a second
line). Each plate page shows the time per plate and for all its copies. The report
does not state the settings behind the estimate. These are estimates, not
machine-reported times. Without `CutParameters` the report has no timing rows or column.