mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-06 20:42:12 -04:00
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
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace OpenNest.IO.Bom;
|
|
|
|
/// <summary>
|
|
/// The .dxf and .dwg files in one folder, looked up by the name a BOM uses.
|
|
/// A .dxf wins over a .dwg with the same name.
|
|
/// </summary>
|
|
internal sealed class DrawingFileIndex
|
|
{
|
|
private readonly Dictionary<string, string> files = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
private DrawingFileIndex(string folder)
|
|
{
|
|
FolderExists = Directory.Exists(folder);
|
|
if (!FolderExists)
|
|
return;
|
|
|
|
foreach (var file in Directory.GetFiles(folder, "*.dxf"))
|
|
files[Path.GetFileNameWithoutExtension(file)] = file;
|
|
foreach (var file in Directory.GetFiles(folder, "*.dwg"))
|
|
files.TryAdd(Path.GetFileNameWithoutExtension(file), file);
|
|
}
|
|
|
|
public bool FolderExists { get; }
|
|
|
|
public static DrawingFileIndex Load(string folder) => new(folder);
|
|
|
|
/// <summary>
|
|
/// The drawing file for a BOM file name, ignoring case and a .dxf or
|
|
/// .dwg extension; null when there is none.
|
|
/// </summary>
|
|
public string Find(string bomFileName) =>
|
|
files.TryGetValue(LookupName(bomFileName), out var path) ? path : null;
|
|
|
|
/// <summary>The BOM file name without a .dxf or .dwg extension.</summary>
|
|
public static string LookupName(string fileName)
|
|
{
|
|
fileName ??= "";
|
|
if (
|
|
fileName.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase)
|
|
|| fileName.EndsWith(".dwg", StringComparison.OrdinalIgnoreCase)
|
|
)
|
|
return Path.GetFileNameWithoutExtension(fileName);
|
|
return fileName;
|
|
}
|
|
}
|