From 399f8dda6eab86d2a5fd8b161d488f433b7e4d8f Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 10 Apr 2026 12:59:06 -0400 Subject: [PATCH] feat: add CadImporter.ImportDrawing convenience method Co-Authored-By: Claude Sonnet 4.6 --- OpenNest.IO/CadImporter.cs | 17 +++++++++++++++++ OpenNest.Tests/IO/CadImporterTests.cs | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/OpenNest.IO/CadImporter.cs b/OpenNest.IO/CadImporter.cs index bbfda92..ef989e9 100644 --- a/OpenNest.IO/CadImporter.cs +++ b/OpenNest.IO/CadImporter.cs @@ -48,6 +48,23 @@ namespace OpenNest.IO }; } + /// + /// Convenience for headless callers: Import a file and build a Drawing + /// in a single call, using all loaded entities and detected bends. + /// + public static Drawing ImportDrawing(string path, CadImportOptions options = null) + { + options ??= CadImportOptions.Default; + var result = Import(path, options); + return BuildDrawing( + result, + result.Entities, + result.Bends, + options.Quantity, + options.Customer, + editedProgram: null); + } + /// /// Build a fully-populated from an import result plus /// the caller's current entity and bend state. UI callers pass the currently diff --git a/OpenNest.Tests/IO/CadImporterTests.cs b/OpenNest.Tests/IO/CadImporterTests.cs index c7d55d2..7a52338 100644 --- a/OpenNest.Tests/IO/CadImporterTests.cs +++ b/OpenNest.Tests/IO/CadImporterTests.cs @@ -108,5 +108,19 @@ namespace OpenNest.Tests.IO Assert.Same(edited, drawing.Program); } + + [Fact] + public void ImportDrawing_ComposesImportAndBuild() + { + var drawing = CadImporter.ImportDrawing(TestDxf, + new CadImportOptions { Quantity = 3, Customer = "ACME" }); + + Assert.NotNull(drawing); + Assert.Equal("4526 A14 PT11", drawing.Name); + Assert.Equal(3, drawing.Quantity.Required); + Assert.Equal("ACME", drawing.Customer); + Assert.NotNull(drawing.Program); + Assert.NotNull(drawing.SourceEntities); + } } }