fix: update drawings in-place when editing in converter so parts reflect changes
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user