mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-11 15:41:14 -05:00
Drawing Sets > More > Import BOM reads a BOM and its drawing folder, matches each drawing to the library by its D4 identity and geometry (reuse, new revision, or new drawing) and opens the set editor with a new set prefilled with the BOM quantities. Reading only queries the library; Create Set lists the uploads and revisions and asks before storing them, and the set is stored only by the editor's Save. Parts with no material or thickness still import and are flagged for Edit Drawing. DrawingPackage.GeometryKey compares geometry independent of the fresh entity ids each DXF import assigns. In Database mode File > Import BOM opens this flow instead of creating nests directly; File mode is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
1.9 KiB
C#
59 lines
1.9 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. 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The job a BOM file is for: its file name without the extension or a trailing
|
|
/// " BOM" ("Frame A BOM.xlsx" is "Frame A").
|
|
/// </summary>
|
|
public static string JobName(string bomPath)
|
|
{
|
|
var name = Path.GetFileNameWithoutExtension(bomPath ?? "");
|
|
if (name.EndsWith(" BOM", StringComparison.OrdinalIgnoreCase))
|
|
name = name.Substring(0, name.Length - 4).TrimEnd();
|
|
return name;
|
|
}
|
|
}
|