mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-09 10:04:12 -04:00
Prepare BOM rows for quantity editing:
- BomQuantity.TryParse accepts only a whole number of at least 1
(surrounding spaces allowed; no sign, decimal, exponent, separator or
overflow).
- BomPartRow keeps the BOM's own quantity (BomQty), refuses invalid
typed quantities in TrySetQuantity, and raises PropertyChanged for
Material, Thickness and Qty plus the status they affect, so a bound
grid can refresh.
- A blank BOM quantity becomes 1, as it was imported before, but is now
visible in the row and counted in the summary ("had no BOM quantity
(1 used)"). A BOM quantity below 1 is no longer imported as 0: the
row reads "Needs quantity" until the operator enters one.
BomImportFlowTests covers BOM items to rows to an edited quantity to the
group total and the created nest's required quantity. Mutation reds:
a zero floor, signed or decimal input, ignoring the quantity in the
status, not assuming 1 for blanks, setting unparsed text and dropping
the status notification each fail the Bom tests.
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace OpenNest.IO.Bom;
|
|
|
|
/// <summary>
|
|
/// Builds the import dialog's part rows from the BOM items and the drawing
|
|
/// folder.
|
|
/// </summary>
|
|
public static class BomImportRows
|
|
{
|
|
/// <summary>
|
|
/// Returns one row per BOM item, in BOM order. Every row with a file
|
|
/// name gets the drawing it matches in <paramref name="dxfFolder"/>,
|
|
/// whether or not its material and thickness are filled in. A blank
|
|
/// BOM quantity becomes 1, marked as assumed.
|
|
/// </summary>
|
|
public static List<BomPartRow> Build(List<BomItem> items, string dxfFolder)
|
|
{
|
|
var index = DrawingFileIndex.Load(dxfFolder);
|
|
var rows = new List<BomPartRow>();
|
|
|
|
foreach (var item in items)
|
|
{
|
|
rows.Add(
|
|
new BomPartRow
|
|
{
|
|
ItemNum = item.ItemNum,
|
|
FileName = item.FileName,
|
|
BomQty = item.Qty,
|
|
Qty = item.Qty ?? 1,
|
|
QtyAssumed = item.Qty == null,
|
|
Description = item.Description,
|
|
Material = item.Material,
|
|
Thickness = item.Thickness,
|
|
DxfPath = string.IsNullOrWhiteSpace(item.FileName)
|
|
? null
|
|
: index.Find(item.FileName),
|
|
}
|
|
);
|
|
}
|
|
|
|
return rows;
|
|
}
|
|
}
|