feat(io): integrate TitleBlockDetector into CadImporter pipeline
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,10 @@ namespace OpenNest.IO
|
||||
|
||||
Bend.UpdateEtchEntities(dxf.Entities, bends);
|
||||
|
||||
HashSet<System.Guid> titleBlockIds = null;
|
||||
if (options.DetectTitleBlock)
|
||||
titleBlockIds = TitleBlockDetector.Detect(dxf.Entities, dxf.Document);
|
||||
|
||||
return new CadImportResult
|
||||
{
|
||||
Entities = dxf.Entities,
|
||||
@@ -48,6 +52,7 @@ namespace OpenNest.IO
|
||||
SourcePath = path,
|
||||
Name = options.Name ?? Path.GetFileNameWithoutExtension(path),
|
||||
Document = dxf.Document,
|
||||
TitleBlockEntityIds = titleBlockIds,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -138,6 +143,16 @@ namespace OpenNest.IO
|
||||
.Where(e => !(e.Layer != null && e.Layer.IsVisible && e.IsVisible))
|
||||
.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;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,5 +134,21 @@ namespace OpenNest.Tests.IO
|
||||
Assert.NotNull(drawing.Program);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user