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;
|
var rotation = Rotation;
|
||||||
Program = BaseDrawing.Program.Clone() as Program;
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -874,11 +874,40 @@ namespace OpenNest.Forms
|
|||||||
if (converter.ShowDialog() != DialogResult.OK)
|
if (converter.ShowDialog() != DialogResult.OK)
|
||||||
return;
|
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
|
// Update existing drawings in-place so parts keep their BaseDrawing references
|
||||||
Nest.Drawings.Clear();
|
foreach (var existing in Nest.Drawings.ToList())
|
||||||
drawings.ForEach(d => Nest.Drawings.Add(d));
|
{
|
||||||
|
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)
|
private void CleanUnusedDrawings_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Reference in New Issue
Block a user