feat: add layer filter overloads to Dxf.GetGeometry()

Add optional Func<string, bool> 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 <noreply@anthropic.com>
This commit is contained in:
2026-04-23 11:07:04 -04:00
parent c25b6bc23a
commit a8d90be2ea
+33 -2
View File
@@ -65,6 +65,36 @@ namespace OpenNest.IO
}
}
public static List<Entity> GetGeometry(string path, Func<string, bool> 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<Entity>();
}
}
public static List<Entity> GetGeometry(Stream stream, Func<string, bool> 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<Entity>();
}
}
#endregion
#region Export
@@ -128,15 +158,16 @@ namespace OpenNest.IO
}
}
private static List<Entity> ConvertEntities(CadDocument doc)
private static List<Entity> ConvertEntities(CadDocument doc, Func<string, bool> layerFilter = null)
{
var entities = new List<Entity>();
var lines = new List<Line>();
var arcs = new List<Arc>();
var filter = layerFilter ?? IsNonCutLayer;
foreach (var entity in doc.Entities)
{
if (IsNonCutLayer(entity.Layer?.Name))
if (filter(entity.Layer?.Name))
continue;
switch (entity)