diff --git a/OpenNest/Controls/FileListControl.cs b/OpenNest/Controls/FileListControl.cs index e41daec..28f7df0 100644 --- a/OpenNest/Controls/FileListControl.cs +++ b/OpenNest/Controls/FileListControl.cs @@ -19,6 +19,7 @@ namespace OpenNest.Controls public List Entities { get; set; } = new(); public List OriginalEntities { get; set; } public List Bends { get; set; } = new(); + public HashSet SuppressedEntityIds { get; set; } public Box Bounds { get; set; } public int EntityCount { get; set; } } diff --git a/OpenNest/Forms/CadConverterForm.cs b/OpenNest/Forms/CadConverterForm.cs index a5e9c74..213dba0 100644 --- a/OpenNest/Forms/CadConverterForm.cs +++ b/OpenNest/Forms/CadConverterForm.cs @@ -169,6 +169,7 @@ namespace OpenNest.Forms if (item.Entities.Any(e => e.Layer != null)) item.Entities.ForEach(e => e.Layer.IsVisible = true); ReHidePromotedEntities(item.Bends); + ReHideSuppressedEntities(item); filterPanel.LoadItem(item.Entities, item.Bends); @@ -245,6 +246,7 @@ namespace OpenNest.Forms filterPanel.ApplyFilters(item.Entities); ReHidePromotedEntities(item.Bends); + SyncSuppressedState(item); entityView1.Invalidate(); staleProgram = true; } @@ -646,6 +648,9 @@ namespace OpenNest.Forms Quantity = drawing.Quantity.Required, Customer = drawing.Customer ?? string.Empty, Bends = drawing.Bends?.ToList() ?? new List(), + SuppressedEntityIds = drawing.SuppressedEntityIds.Count > 0 + ? new HashSet(drawing.SuppressedEntityIds) + : null, Bounds = bounds, EntityCount = entities.Count }; @@ -734,6 +739,47 @@ namespace OpenNest.Forms } } + private static void ReHideSuppressedEntities(FileListItem item) + { + if (item.SuppressedEntityIds == null || item.SuppressedEntityIds.Count == 0) + return; + + foreach (var entity in item.Entities) + { + if (item.SuppressedEntityIds.Contains(entity.Id)) + entity.IsVisible = false; + } + + // If all entities on a layer are suppressed, uncheck the layer too + var layerGroups = item.Entities + .Where(e => e.Layer != null) + .GroupBy(e => e.Layer); + + foreach (var group in layerGroups) + { + if (group.All(e => !e.IsVisible)) + group.Key.IsVisible = false; + } + } + + private static void SyncSuppressedState(FileListItem item) + { + var bendSources = new HashSet( + (item.Bends ?? new List()) + .Where(b => b.SourceEntity != null) + .Select(b => b.SourceEntity)); + + var suppressed = item.Entities + .Where(e => !(e.Layer.IsVisible && e.IsVisible)) + .Where(e => !bendSources.Contains(e)) + .Select(e => e.Id); + + item.SuppressedEntityIds = new HashSet(suppressed); + + if (item.SuppressedEntityIds.Count == 0) + item.SuppressedEntityIds = null; + } + private static Color GetNextColor() => Drawing.GetNextColor();