From df86d4367bea0add85b33c8c1e2200fd56dfddaa Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Wed, 8 Apr 2026 12:58:51 -0400 Subject: [PATCH] fix: update drawings in-place when editing in converter so parts reflect changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit EditDrawingsInConverter was replacing Drawing objects with new instances, but Part.BaseDrawing is readonly — parts kept referencing the old drawings with stale programs (e.g. etch lines that were removed). Now matches by name and updates existing drawings in-place, then refreshes all parts. Also fixes Part.Update() which applied rotation backwards and was missing UpdateBounds() and lead-in state reset. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Core/Part.cs | 9 ++++++++- OpenNest/Forms/EditNestForm.cs | 37 ++++++++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/OpenNest.Core/Part.cs b/OpenNest.Core/Part.cs index 7caea6f..01484d0 100644 --- a/OpenNest.Core/Part.cs +++ b/OpenNest.Core/Part.cs @@ -190,7 +190,14 @@ namespace OpenNest { var rotation = Rotation; Program = BaseDrawing.Program.Clone() as Program; - Program.Rotate(Program.Rotation - rotation); + + if (!Math.Tolerance.IsEqualTo(rotation, 0)) + Program.Rotate(rotation); + + HasManualLeadIns = false; + LeadInsLocked = false; + CuttingParameters = null; + UpdateBounds(); } /// diff --git a/OpenNest/Forms/EditNestForm.cs b/OpenNest/Forms/EditNestForm.cs index 61aa839..54ff52d 100644 --- a/OpenNest/Forms/EditNestForm.cs +++ b/OpenNest/Forms/EditNestForm.cs @@ -874,11 +874,40 @@ namespace OpenNest.Forms if (converter.ShowDialog() != DialogResult.OK) return; - var drawings = converter.GetDrawings(); + var newDrawings = converter.GetDrawings(); + var newByName = newDrawings.ToDictionary(d => d.Name); - // Replace all drawings — clear existing and add new ones - Nest.Drawings.Clear(); - drawings.ForEach(d => Nest.Drawings.Add(d)); + // Update existing drawings in-place so parts keep their BaseDrawing references + foreach (var existing in Nest.Drawings.ToList()) + { + if (newByName.TryGetValue(existing.Name, out var updated)) + { + existing.Program = updated.Program; + existing.Source = updated.Source; + existing.Customer = updated.Customer; + existing.Quantity.Required = updated.Quantity.Required; + existing.Bends.Clear(); + existing.Bends.AddRange(updated.Bends); + newByName.Remove(existing.Name); + } + else + { + Nest.Drawings.Remove(existing); + } + } + + // Add any new drawings that weren't in the original set + foreach (var d in newByName.Values) + Nest.Drawings.Add(d); + + // Refresh all parts to use the updated programs + foreach (var plate in Nest.Plates) + foreach (var part in plate.Parts) + if (!part.BaseDrawing.IsCutOff) + part.Update(); + + UpdateDrawingList(); + PlateView.Invalidate(); } private void CleanUnusedDrawings_Click(object sender, EventArgs e)