mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-10 16:44:13 -04:00
Move the BOM import dialog's row building, grouping and per-group nest construction out of BomImportForm into OpenNest.IO/Bom so they can be tested on Linux: - BomPartRow (now public) and BomImportRows.Build, a verbatim move of the form's BuildPartRows (still via BomAnalyzer). - BomImportGroups.Build: one grouping used by both the Groups tab and Create Nests, which each carried their own copy. Create Nests now creates nests in the Groups tab's order (material, then thickness). - BomNestBuilder.Build: the nest for one group (saved defaults first, then the group's plate size, spacing, material and thickness; one drawing per row with the row's quantity, 1 when blank). The form keeps the file dialogs, grids, EditNestForm windows and the completion message. Behavior is otherwise unchanged; the two row-status defects found while planning are fixed in the following commits.
72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using OpenNest.IO.Bom;
|
|
|
|
namespace OpenNest.Tests.Bom;
|
|
|
|
public class BomImportGroupsTests
|
|
{
|
|
[Fact]
|
|
public void Build_GroupsByMaterialIgnoringCaseThenThickness()
|
|
{
|
|
var rows = new List<BomPartRow>
|
|
{
|
|
Row("PT01", "Stainless", 0.25, qty: 2),
|
|
Row("PT02", "Aluminum", 0.125, qty: 1),
|
|
Row("PT03", "STAINLESS", 0.25, qty: null),
|
|
Row("PT04", "Stainless", 0.125, qty: 4),
|
|
Row("PT05", "Aluminum", 0.0625, qty: 3),
|
|
};
|
|
|
|
var groups = BomImportGroups.Build(rows);
|
|
|
|
Assert.Equal(
|
|
new[] { "Aluminum 0.0625", "Aluminum 0.125", "Stainless 0.125", "Stainless 0.25" },
|
|
groups.Select(g => $"{g.Material} {g.Thickness}")
|
|
);
|
|
var stainless = groups[3];
|
|
Assert.Equal(new[] { "PT01", "PT03" }, stainless.Parts.Select(p => p.FileName));
|
|
Assert.Equal(2, stainless.TotalQty);
|
|
Assert.Equal(BomImportGroups.Key("stainless", 0.25), stainless.Key);
|
|
}
|
|
|
|
[Fact]
|
|
public void Build_LeavesOutRowsThatCannotBeImported()
|
|
{
|
|
var locked = Row("PT02", "Stainless", 0.25);
|
|
locked.IsEditable = false;
|
|
var noDrawing = Row("PT05", "Stainless", 0.25);
|
|
noDrawing.DxfPath = null;
|
|
var rows = new List<BomPartRow>
|
|
{
|
|
Row("PT01", "Stainless", 0.25),
|
|
locked,
|
|
Row("PT03", " ", 0.25),
|
|
Row("PT04", "Stainless", null),
|
|
noDrawing,
|
|
};
|
|
|
|
var groups = BomImportGroups.Build(rows);
|
|
|
|
var group = Assert.Single(groups);
|
|
Assert.Equal("PT01", Assert.Single(group.Parts).FileName);
|
|
}
|
|
|
|
[Fact]
|
|
public void Key_IgnoresMaterialCase()
|
|
{
|
|
Assert.Equal(BomImportGroups.Key("Stainless", 0.25), BomImportGroups.Key("STAINLESS", 0.25));
|
|
Assert.NotEqual(BomImportGroups.Key("Stainless", 0.25), BomImportGroups.Key("Stainless", 0.125));
|
|
}
|
|
|
|
private static BomPartRow Row(string fileName, string material, double? thickness, int? qty = 1) =>
|
|
new()
|
|
{
|
|
FileName = fileName,
|
|
Material = material,
|
|
Thickness = thickness,
|
|
Qty = qty,
|
|
DxfPath = $"/drawings/{fileName}.dxf",
|
|
Status = "Matched",
|
|
IsEditable = true,
|
|
};
|
|
}
|