fix: preserve suppression state when reopening converter
LoadItem was resetting all entity visibility to true, overriding the suppression state set by LoadDrawings. Now stores suppressed entity IDs on FileListItem and re-applies after the reset. Also auto-unchecks layers where all entities are suppressed, and syncs suppression state back to the FileListItem when filters change. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ namespace OpenNest.Controls
|
||||
public List<Entity> Entities { get; set; } = new();
|
||||
public List<Entity> OriginalEntities { get; set; }
|
||||
public List<Bend> Bends { get; set; } = new();
|
||||
public HashSet<Guid> SuppressedEntityIds { get; set; }
|
||||
public Box Bounds { get; set; }
|
||||
public int EntityCount { get; set; }
|
||||
}
|
||||
|
||||
@@ -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<Bend>(),
|
||||
SuppressedEntityIds = drawing.SuppressedEntityIds.Count > 0
|
||||
? new HashSet<Guid>(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<Entity>(
|
||||
(item.Bends ?? new List<Bend>())
|
||||
.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<Guid>(suppressed);
|
||||
|
||||
if (item.SuppressedEntityIds.Count == 0)
|
||||
item.SuppressedEntityIds = null;
|
||||
}
|
||||
|
||||
|
||||
private static Color GetNextColor() => Drawing.GetNextColor();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user