Files
OpenNest/OpenNest.IO/Bom/BomImportSummary.cs
T
aj b83aeb0e41 fix(bom): find the drawing for rows that still need a thickness
A BOM row with a file name and a matching drawing but a blank thickness
was reported "No DXF" and locked, so its thickness could not be entered
and the part was dropped: BomAnalyzer skips such items before looking
for a drawing, and the form only knew drawings the analyzer matched.
A row with a blank material read "Matched" but was silently left out
of every group.

Rows now resolve their drawing through a DrawingFileIndex shared with
BomAnalyzer (whose behavior and tests are unchanged), and a row's status
is computed from its values:

  Ready | Needs material | Needs thickness | No drawing found | No file name

Rows with a drawing stay editable, and an edit updates the status cell.
Groups take only Ready rows (a zero, negative or non-finite thickness is
not Ready). The summary line counts ready rows and each problem.

Build_RowWithoutThickness_StillFindsItsDrawing failed at its DxfPath
assertion against the previous commit. Mutation reds: removing the
material check, accepting zero or non-finite thickness, skipping the
drawing for rows without thickness, and grouping without the status
each fail the Bom tests.

Project Memory: b8e3a978-2cfe-4fe7-b2a5-eb01c6c54679
2026-10-05 17:50:54 -04:00

31 lines
1.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
namespace OpenNest.IO.Bom;
/// <summary>The import dialog's one-line summary of the part rows.</summary>
public static class BomImportSummary
{
/// <summary>
/// For example "12 ready, 2 need a thickness, 1 no drawing found".
/// </summary>
public static string Describe(IEnumerable<BomPartRow> rows)
{
var counts = rows.GroupBy(r => r.Status).ToDictionary(g => g.Key, g => g.Count());
int Count(BomRowStatus status) => counts.TryGetValue(status, out var n) ? n : 0;
var parts = new List<string> { $"{Count(BomRowStatus.Ready)} ready" };
Add(parts, Count(BomRowStatus.NeedsMaterial), "needs a material", "need a material");
Add(parts, Count(BomRowStatus.NeedsThickness), "needs a thickness", "need a thickness");
Add(parts, Count(BomRowStatus.NoDrawing), "no drawing found", "no drawing found");
Add(parts, Count(BomRowStatus.NoFileName), "no file name", "no file name");
return string.Join(", ", parts);
}
private static void Add(List<string> parts, int count, string one, string many)
{
if (count > 0)
parts.Add($"{count} {(count == 1 ? one : many)}");
}
}