From 091e750e1b343f3793cc78a8bb037092437e297d Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 10 Apr 2026 14:13:44 -0400 Subject: [PATCH] chore(cad-importer): remove dead code and cover named detector branch - Drop CadImportResult.Document: no caller reads it after the migrations (BendDetectorRegistry runs inside CadImporter.Import itself, and downstream callers only consume the entity/bend data). - Drop dead CadConverterForm.GetNextColor() helper: zero callers since GetDrawings stopped needing it. - Drop stale 'using OpenNest.Properties;' and unused 'newItems' local in OnSplitClicked. - Add Import_WhenNamedDetectorDoesNotExist_ReturnsEmptyBends to cover the previously untested named-detector branch in CadImporter.Import. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.IO/CadImportResult.cs | 7 ------- OpenNest.IO/CadImporter.cs | 1 - OpenNest.Tests/IO/CadImporterTests.cs | 12 ++++++++++++ OpenNest/Forms/CadConverterForm.cs | 6 ------ 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/OpenNest.IO/CadImportResult.cs b/OpenNest.IO/CadImportResult.cs index d040ecd..9b0cf39 100644 --- a/OpenNest.IO/CadImportResult.cs +++ b/OpenNest.IO/CadImportResult.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using ACadSharp; using OpenNest.Bending; using OpenNest.Geometry; @@ -30,12 +29,6 @@ namespace OpenNest.IO /// public Box Bounds { get; set; } - /// - /// Underlying CAD document for callers that need to run additional - /// analysis (e.g., MText extraction). May be null for stream imports. - /// - public CadDocument Document { get; set; } - /// /// Absolute path to the source file. /// diff --git a/OpenNest.IO/CadImporter.cs b/OpenNest.IO/CadImporter.cs index ef989e9..aa2ed4a 100644 --- a/OpenNest.IO/CadImporter.cs +++ b/OpenNest.IO/CadImporter.cs @@ -42,7 +42,6 @@ namespace OpenNest.IO Entities = dxf.Entities, Bends = bends, Bounds = dxf.Entities.GetBoundingBox(), - Document = dxf.Document, SourcePath = path, Name = options.Name ?? Path.GetFileNameWithoutExtension(path), }; diff --git a/OpenNest.Tests/IO/CadImporterTests.cs b/OpenNest.Tests/IO/CadImporterTests.cs index 7a52338..bceb883 100644 --- a/OpenNest.Tests/IO/CadImporterTests.cs +++ b/OpenNest.Tests/IO/CadImporterTests.cs @@ -39,6 +39,18 @@ namespace OpenNest.Tests.IO Assert.Equal("custom", result.Name); } + [Fact] + public void Import_WhenNamedDetectorDoesNotExist_ReturnsEmptyBends() + { + // Exercises the named-detector branch: when BendDetectorName doesn't + // match any registered detector, bends should be an empty list + // (not a crash, and no fall-through to auto-detect). + var result = CadImporter.Import(TestDxf, + new CadImportOptions { BendDetectorName = "__nonexistent__" }); + + Assert.Empty(result.Bends); + } + [Fact] public void BuildDrawing_ProducesDrawingWithProgramAndMetadata() { diff --git a/OpenNest/Forms/CadConverterForm.cs b/OpenNest/Forms/CadConverterForm.cs index 3242d14..53fff87 100644 --- a/OpenNest/Forms/CadConverterForm.cs +++ b/OpenNest/Forms/CadConverterForm.cs @@ -5,7 +5,6 @@ using OpenNest.Converters; using OpenNest.Geometry; using OpenNest.IO; using OpenNest.IO.Bending; -using OpenNest.Properties; using System; using System.Collections.Generic; using System.Drawing; @@ -356,7 +355,6 @@ namespace OpenNest.Forms : Path.GetTempPath(); var index = fileList.SelectedIndex; - var newItems = new List(); var splitWriter = new SplitDxfWriter(); var splitItems = new List(); @@ -369,7 +367,6 @@ namespace OpenNest.Forms var splitPath = GetUniquePath(Path.Combine(writableDir, splitName)); splitWriter.Write(splitPath, splitDrawing); - newItems.Add(splitPath); // Re-import geometry but keep bends from the split drawing var result = Dxf.Import(splitPath); @@ -750,9 +747,6 @@ namespace OpenNest.Forms item.SuppressedEntityIds = null; } - - private static Color GetNextColor() => Drawing.GetNextColor(); - private static bool IsDirectoryWritable(string path) { try