fix(avalonia): lock the nest while the simulator opens and keep a dragged cut-off selected

Simulate Cutting took its view-only lock only after reading the machines,
so Auto Nest or Nest > Edit started in that wait ran under the open
simulator, and closing it restored a stale lock that left the plate
refusing edits. The lock is now taken before the read and released if
the simulator does not open.

A cut-off drag that changed how many segments the line is trimmed into
rebuilt the selection by part index, which drops selected cut-offs; the
view now keeps them by reference while the plate is the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-30 19:09:40 -05:00
1 parent a85b0cc45f
commit cabcec642e
2 files changed
+25 -9

No files matched your search

@@ -82,10 +82,18 @@ namespace OpenNest.Avalonia.Controls
/// </summary>
public void ReplacePlate(Plate value, IEnumerable<int> selectedIndices)
{
// Cut-offs are kept by reference while the plate stays the same: an edit that
// re-trims them (a cut-off drag) changes the segment parts, so the part-index
// selection would otherwise drop the selected line.
var keptCutOffs = ReferenceEquals(plate, value)
? selection.CutOffs.Where(c => value.CutOffs.Any(d => ReferenceEquals(c, d))).ToList()
: new List<CutOff>();
var fit = fitPending;
Plate = value;
fitPending = fit;
selection.SelectIndices(selectedIndices);
if (keptCutOffs.Count > 0)
selection.Select(keptCutOffs);
}
/// <summary>The colours drawn with: the application's active scheme unless set.</summary>
+17 -9
View File
@@ -63,15 +63,22 @@ namespace OpenNest.Avalonia
var view = ActiveView;
if (view?.PlateView.Plate == null || IsNesting(view.Tab, "simulating its cutting"))
return;
var machines = await DesktopSettings.RefreshMachinesAsync();
// The nest may have changed or closed, or the simulator opened, while the machines were read.
if (closed || simulator != null || ActiveView != view || view.PlateView.Plate == null)
return;
// As WinForms: the plate tool ends and the nest is view-only until the simulator closes.
// The lock is taken before the machines are read, so Auto Nest, Nest > Edit or
// another edit cannot start while they load and then run under the simulator.
view.PlateView.Tools.EndTool();
view.CancelPickup();
inspection = new InspectionLock(this, view.PlateView, view.InspectionControls);
var opening = new InspectionLock(this, view.PlateView, view.InspectionControls);
inspection = opening;
var machines = await DesktopSettings.RefreshMachinesAsync();
// The window may have closed, or the user switched tabs, while the machines were read.
if (closed || ActiveView != view || view.PlateView.Plate == null)
{
opening.Dispose();
if (ReferenceEquals(inspection, opening))
inspection = null;
return;
}
simulator = new CutSimulatorWindow(view, machines);
simulator.Closed += (_, _) =>
{
@@ -83,18 +90,19 @@ namespace OpenNest.Avalonia
}
/// <summary>
/// While the simulator is open, as the WinForms main window while inspecting: Escape
/// While the simulator is open (or opening), as the WinForms main window while inspecting: Escape
/// closes it, the zoom keys zoom, and other Ctrl, Alt and command shortcuts (which could
/// change the nest) are swallowed. True when the key was taken.
/// </summary>
private bool ProcessSimulatorKeys(KeyEventArgs e)
{
if (simulator == null)
// Also while the simulator is opening: the lock is already held then.
if (inspection == null)
return false;
var modifiers = e.KeyModifiers;
if (e.Key == Key.Escape && modifiers == KeyModifiers.None)
{
simulator.Close();
simulator?.Close();
return true;
}
if (modifiers == KeyModifiers.Control && e.Key is Key.OemPlus or Key.Add)