mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-09 06:52:32 -04:00
fix(bom): match BOM file names that include the drawing extension
A BOM row whose File Name carried its extension ("PT01.dxf") showed
"No DXF", was locked and was never imported, although BomAnalyzer had
found the file: the matched paths were stored under the raw BOM name
and looked up by the name without the extension. Both sides now use
the extension-less name.
The new BomImportRowsTests row failed at its IsEditable assertion
against the previous commit.
Project Memory: f3be7a4b-e679-470c-bb52-7057899228e4
This commit is contained in:
1 parent
ca153a1c20
commit
f4d1d45c81
2 files changed
+33
-9
No files matched your search
@@ -22,7 +22,7 @@ public static class BomImportRows
|
||||
foreach (var group in analysis.Groups)
|
||||
foreach (var part in group.Parts)
|
||||
if (part.DxfPath != null)
|
||||
matchedPaths[part.Item.FileName ?? ""] = part.DxfPath;
|
||||
matchedPaths[LookupName(part.Item.FileName)] = part.DxfPath;
|
||||
|
||||
var rows = new List<BomPartRow>();
|
||||
|
||||
@@ -45,14 +45,7 @@ public static class BomImportRows
|
||||
}
|
||||
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))
|
||||
if (matchedPaths.TryGetValue(LookupName(item.FileName), out var dxfPath))
|
||||
{
|
||||
row.DxfPath = dxfPath;
|
||||
row.Status = "Matched";
|
||||
@@ -70,4 +63,19 @@ public static class BomImportRows
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The drawing name a BOM file name refers to: the name without a
|
||||
/// .dxf or .dwg extension, as <see cref="BomAnalyzer"/> matches it.
|
||||
/// </summary>
|
||||
private static string LookupName(string fileName)
|
||||
{
|
||||
fileName ??= "";
|
||||
if (
|
||||
fileName.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase)
|
||||
|| fileName.EndsWith(".dwg", StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
return Path.GetFileNameWithoutExtension(fileName);
|
||||
return fileName;
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,22 @@ public sealed class BomImportRowsTests : IDisposable
|
||||
Assert.Equal(Path.Combine(folder, "PT01.dxf"), rows[0].DxfPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_MatchesFileNamesThatIncludeTheExtension()
|
||||
{
|
||||
Touch("PT01.dxf");
|
||||
Touch("PT02.dwg");
|
||||
|
||||
var rows = BomImportRows.Build(
|
||||
new List<BomItem> { Item("PT01.dxf"), Item("PT02.DWG") },
|
||||
folder
|
||||
);
|
||||
|
||||
Assert.All(rows, r => Assert.True(r.IsEditable, r.FileName));
|
||||
Assert.Equal(Path.Combine(folder, "PT01.dxf"), rows[0].DxfPath);
|
||||
Assert.Equal(Path.Combine(folder, "PT02.dwg"), rows[1].DxfPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Build_WithMissingFolder_FindsNoDrawings()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user