feat(io): integrate TitleBlockDetector into CadImporter pipeline

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-30 12:05:48 -04:00
parent 4f2a8d29d5
commit 4f849f1c06
2 changed files with 31 additions and 0 deletions
+15
View File
@@ -40,6 +40,10 @@ namespace OpenNest.IO
Bend.UpdateEtchEntities(dxf.Entities, bends); Bend.UpdateEtchEntities(dxf.Entities, bends);
HashSet<System.Guid> titleBlockIds = null;
if (options.DetectTitleBlock)
titleBlockIds = TitleBlockDetector.Detect(dxf.Entities, dxf.Document);
return new CadImportResult return new CadImportResult
{ {
Entities = dxf.Entities, Entities = dxf.Entities,
@@ -48,6 +52,7 @@ namespace OpenNest.IO
SourcePath = path, SourcePath = path,
Name = options.Name ?? Path.GetFileNameWithoutExtension(path), Name = options.Name ?? Path.GetFileNameWithoutExtension(path),
Document = dxf.Document, Document = dxf.Document,
TitleBlockEntityIds = titleBlockIds,
}; };
} }
@@ -138,6 +143,16 @@ namespace OpenNest.IO
.Where(e => !(e.Layer != null && e.Layer.IsVisible && e.IsVisible)) .Where(e => !(e.Layer != null && e.Layer.IsVisible && e.IsVisible))
.Select(e => e.Id)); .Select(e => e.Id));
if (result.TitleBlockEntityIds != null)
{
var sourceIds = new HashSet<System.Guid>(drawing.SourceEntities.Select(e => e.Id));
foreach (var id in result.TitleBlockEntityIds)
{
if (sourceIds.Contains(id))
drawing.SuppressedEntityIds.Add(id);
}
}
return drawing; return drawing;
} }
+16
View File
@@ -134,5 +134,21 @@ namespace OpenNest.Tests.IO
Assert.NotNull(drawing.Program); Assert.NotNull(drawing.Program);
Assert.NotNull(drawing.SourceEntities); Assert.NotNull(drawing.SourceEntities);
} }
[Fact]
public void Import_WhenDetectTitleBlockTrue_PopulatesTitleBlockEntityIds()
{
var result = CadImporter.Import(TestDxf);
Assert.NotNull(result.TitleBlockEntityIds);
}
[Fact]
public void Import_WhenDetectTitleBlockFalse_TitleBlockEntityIdsIsNull()
{
var result = CadImporter.Import(TestDxf, new CadImportOptions { DetectTitleBlock = false });
Assert.Null(result.TitleBlockEntityIds);
}
} }
} }