diff --git a/OpenNest.Reporting/NestPdfWriter.cs b/OpenNest.Reporting/NestPdfWriter.cs index 32f8161a..80ac6892 100644 --- a/OpenNest.Reporting/NestPdfWriter.cs +++ b/OpenNest.Reporting/NestPdfWriter.cs @@ -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); } + /// + /// Sheet weight and cut time columns appear only when the report has them; the stock size + /// column takes whatever width they leave. + /// + private static void AddPlatesTable(Section section, NestReportSnapshot snapshot) + { + var hasWeights = snapshot.Plates.Any(plate => plate.Weight != null); + var widths = new List { 40, 0, 56, 92, 68 }; + var headings = new List { "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 + { + 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()); + } + } + + /// One sheet, then all its copies on a second line. + 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"; + /// /// One card per drawing, 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"; /// Whole seconds as "1h 02m 03s", "4m 05s" or "45s". private static string Duration(TimeSpan time) diff --git a/OpenNest.Reporting/NestReportBuilder.cs b/OpenNest.Reporting/NestReportBuilder.cs index a2dcf2e4..1bbe362c 100644 --- a/OpenNest.Reporting/NestReportBuilder.cs +++ b/OpenNest.Reporting/NestReportBuilder.cs @@ -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 /// 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); + } + + /// The nest material's density, then the machine catalog's; zero when neither has one. + private static double SheetDensity(Nest nest, double catalogDensity) + { + var density = nest.Material?.Density ?? 0; + return density > 0 ? density : catalogDensity; + } + + /// Area x nest thickness x density (lb/in^3); null when any of them is missing. + 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; diff --git a/OpenNest.Reporting/NestReportSnapshot.cs b/OpenNest.Reporting/NestReportSnapshot.cs index 3bdea205..bd432159 100644 --- a/OpenNest.Reporting/NestReportSnapshot.cs +++ b/OpenNest.Reporting/NestReportSnapshot.cs @@ -38,6 +38,12 @@ public sealed record ReportPlate(int Number, ReportBounds Bounds, int Copies, do { /// Estimated time to cut one copy of this plate; null when no estimate was requested. public TimeSpan? CutTime { get; init; } + + /// + /// Weight of one full sheet (outline area x nest thickness x the nest material's density) in + /// ; null when the thickness or density is unknown. + /// + public double? Weight { get; init; } } /// A detached value snapshot. No domain objects or mutable geometry are retained. diff --git a/OpenNest.Tests/Reporting/NestPdfWriterTests.cs b/OpenNest.Tests/Reporting/NestPdfWriterTests.cs index efe3903c..06643f43 100644 --- a/OpenNest.Tests/Reporting/NestPdfWriterTests.cs +++ b/OpenNest.Tests/Reporting/NestPdfWriterTests.cs @@ -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); } diff --git a/OpenNest.Tests/Reporting/NestReportBuilderTests.cs b/OpenNest.Tests/Reporting/NestReportBuilderTests.cs index 87a7a690..a3aadf6a 100644 --- a/OpenNest.Tests/Reporting/NestReportBuilderTests.cs +++ b/OpenNest.Tests/Reporting/NestReportBuilderTests.cs @@ -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() { diff --git a/docs/nest-reports.md b/docs/nest-reports.md index 078724ae..3ab580f5 100644 --- a/docs/nest-reports.md +++ b/docs/nest-reports.md @@ -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.