diff --git a/OpenNest.IO/CadImporter.cs b/OpenNest.IO/CadImporter.cs index 6afcea2..75f049a 100644 --- a/OpenNest.IO/CadImporter.cs +++ b/OpenNest.IO/CadImporter.cs @@ -40,6 +40,10 @@ namespace OpenNest.IO Bend.UpdateEtchEntities(dxf.Entities, bends); + HashSet 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(drawing.SourceEntities.Select(e => e.Id)); + foreach (var id in result.TitleBlockEntityIds) + { + if (sourceIds.Contains(id)) + drawing.SuppressedEntityIds.Add(id); + } + } + return drawing; } diff --git a/OpenNest.Tests/IO/CadImporterTests.cs b/OpenNest.Tests/IO/CadImporterTests.cs index bceb883..3f5102e 100644 --- a/OpenNest.Tests/IO/CadImporterTests.cs +++ b/OpenNest.Tests/IO/CadImporterTests.cs @@ -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); + } } }