mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-07 00:12:11 -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.
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
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, with the drawing file it
|
|
/// matched in <paramref name="dxfFolder"/> and its import status.
|
|
/// </summary>
|
|
public static List<BomPartRow> Build(List<BomItem> items, string dxfFolder)
|
|
{
|
|
var analysis = BomAnalyzer.Analyze(items, dxfFolder);
|
|
var matchedPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
foreach (var group in analysis.Groups)
|
|
foreach (var part in group.Parts)
|
|
if (part.DxfPath != null)
|
|
matchedPaths[part.Item.FileName ?? ""] = part.DxfPath;
|
|
|
|
var rows = new List<BomPartRow>();
|
|
|
|
foreach (var item in items)
|
|
{
|
|
var row = new BomPartRow
|
|
{
|
|
ItemNum = item.ItemNum,
|
|
FileName = item.FileName,
|
|
Qty = item.Qty,
|
|
Description = item.Description,
|
|
Material = item.Material,
|
|
Thickness = item.Thickness,
|
|
};
|
|
|
|
if (string.IsNullOrWhiteSpace(item.FileName))
|
|
{
|
|
row.Status = "Skipped";
|
|
row.IsEditable = false;
|
|
}
|
|
else
|
|
{
|
|
var lookupName = item.FileName;
|
|
if (
|
|
lookupName.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase)
|
|
|| lookupName.EndsWith(".dwg", StringComparison.OrdinalIgnoreCase)
|
|
)
|
|
lookupName = Path.GetFileNameWithoutExtension(lookupName);
|
|
|
|
if (matchedPaths.TryGetValue(lookupName, out var dxfPath))
|
|
{
|
|
row.DxfPath = dxfPath;
|
|
row.Status = "Matched";
|
|
row.IsEditable = true;
|
|
}
|
|
else
|
|
{
|
|
row.Status = "No DXF";
|
|
row.IsEditable = false;
|
|
}
|
|
}
|
|
|
|
rows.Add(row);
|
|
}
|
|
|
|
return rows;
|
|
}
|
|
}
|