From a8d90be2ea7501b215ad94ce9721cbda18b0e92b Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Thu, 23 Apr 2026 11:07:04 -0400 Subject: [PATCH] feat: add layer filter overloads to Dxf.GetGeometry() Add optional Func layerFilter parameter to ConvertEntities and two new GetGeometry overloads (path and stream) that accept a layer filter. This lets callers control which layers to exclude instead of being limited to the hardcoded IsNonCutLayer check. Existing overloads without the filter continue to use the default IsNonCutLayer behavior. Co-Authored-By: Claude Opus 4.6 --- OpenNest.IO/Dxf.cs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/OpenNest.IO/Dxf.cs b/OpenNest.IO/Dxf.cs index 5c2548c..4c20f89 100644 --- a/OpenNest.IO/Dxf.cs +++ b/OpenNest.IO/Dxf.cs @@ -65,6 +65,36 @@ namespace OpenNest.IO } } + public static List GetGeometry(string path, Func layerFilter) + { + try + { + using var reader = new DxfReader(path); + var doc = reader.Read(); + return ConvertEntities(doc, layerFilter); + } + catch (Exception ex) + { + Debug.WriteLine(ex.Message); + return new List(); + } + } + + public static List GetGeometry(Stream stream, Func layerFilter) + { + try + { + using var reader = new DxfReader(stream); + var doc = reader.Read(); + return ConvertEntities(doc, layerFilter); + } + catch (Exception ex) + { + Debug.WriteLine(ex.Message); + return new List(); + } + } + #endregion #region Export @@ -128,15 +158,16 @@ namespace OpenNest.IO } } - private static List ConvertEntities(CadDocument doc) + private static List ConvertEntities(CadDocument doc, Func layerFilter = null) { var entities = new List(); var lines = new List(); var arcs = new List(); + var filter = layerFilter ?? IsNonCutLayer; foreach (var entity in doc.Entities) { - if (IsNonCutLayer(entity.Layer?.Name)) + if (filter(entity.Layer?.Name)) continue; switch (entity)