feat(io): add DWG file import support via ACadSharp DwgReader
ACadSharp already includes DwgReader, so this wires it up across the entire import pipeline — Dxf.Import, CadConverter drag-drop, nest import dialog, console CLI, BOM analyzer, and training data collector. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,11 @@ namespace OpenNest.IO.Bom
|
||||
var nameWithoutExt = Path.GetFileNameWithoutExtension(file);
|
||||
dxfFiles[nameWithoutExt] = file;
|
||||
}
|
||||
foreach (var file in Directory.GetFiles(dxfFolder, "*.dwg"))
|
||||
{
|
||||
var nameWithoutExt = Path.GetFileNameWithoutExtension(file);
|
||||
dxfFiles.TryAdd(nameWithoutExt, file);
|
||||
}
|
||||
}
|
||||
|
||||
// Partition items into: skipped, unmatched, or matched (grouped)
|
||||
@@ -57,8 +62,8 @@ namespace OpenNest.IO.Bom
|
||||
|
||||
var lookupName = item.FileName;
|
||||
|
||||
// Strip .dxf extension if the BOM includes it
|
||||
if (lookupName.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase))
|
||||
if (lookupName.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase)
|
||||
|| lookupName.EndsWith(".dwg", StringComparison.OrdinalIgnoreCase))
|
||||
lookupName = Path.GetFileNameWithoutExtension(lookupName);
|
||||
|
||||
if (!folderExists)
|
||||
|
||||
+19
-4
@@ -27,8 +27,7 @@ namespace OpenNest.IO
|
||||
/// </summary>
|
||||
public static DxfImportResult Import(string path)
|
||||
{
|
||||
using var reader = new DxfReader(path);
|
||||
var doc = reader.Read();
|
||||
var doc = ReadDocument(path);
|
||||
|
||||
return new DxfImportResult
|
||||
{
|
||||
@@ -41,8 +40,7 @@ namespace OpenNest.IO
|
||||
{
|
||||
try
|
||||
{
|
||||
using var reader = new DxfReader(path);
|
||||
var doc = reader.Read();
|
||||
var doc = ReadDocument(path);
|
||||
return ConvertEntities(doc);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -113,6 +111,23 @@ namespace OpenNest.IO
|
||||
|
||||
#region Private
|
||||
|
||||
private static bool IsDwg(string path) =>
|
||||
Path.GetExtension(path).Equals(".dwg", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static CadDocument ReadDocument(string path)
|
||||
{
|
||||
if (IsDwg(path))
|
||||
{
|
||||
using var reader = new DwgReader(path);
|
||||
return reader.Read();
|
||||
}
|
||||
else
|
||||
{
|
||||
using var reader = new DxfReader(path);
|
||||
return reader.Read();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Entity> ConvertEntities(CadDocument doc)
|
||||
{
|
||||
var entities = new List<Entity>();
|
||||
|
||||
Reference in New Issue
Block a user