Files
OpenNest/OpenNest.Avalonia/MainWindow.CutOffs.cs
T
ajandClaude Opus 5.5 66ad3ef587 feat(avalonia): sheet cut-offs, trim/extend, swap and automatic scrap cutoffs
Plate > Sheet Cut-Off and Trim/Extend Cut-Off (also toolbar buttons)
run the shared tools: a dashed preview of the line a click adds and a
cursor tag, Space turns the line, Tab switches full length or Trim and
Extend without moving focus. Select drags a cut-off with the lines that
meet it. A right click on a cut-off junction offers Swap Through-Cut,
taking the part menu's place only there.

Plate > Automatic Scrap Cutoffs and Nest > Automatic Scrap Cutoffs (All
Plates) open the dialog over the shared session: settings, measurements,
per-plate table, issues and a colored status, the active plate's
detached preview drawn as dashed lines, and Apply as one undo step that
keeps the head-lock choice for new cut-offs.

Rebuilding the plate list no longer passes through an empty selection,
so a tool is not ended when an edit changes the plate's part count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:51:42 -05:00

83 lines
3.7 KiB
C#

using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Interactivity;
using OpenNest.Desktop.Interaction;
using OpenNest.Forms;
namespace OpenNest.Avalonia
{
/// <summary>
/// Plate &gt; Sheet Cut-Off, Trim/Extend Cut-Off and Automatic Scrap Cutoffs, Nest &gt;
/// Automatic Scrap Cutoffs (All Plates) and the Swap Through-Cut menu on a cut-off junction,
/// as the WinForms main form: each edit is one undo step under the WinForms label (see
/// <see cref="CutOffEdits"/> and <see cref="AutomaticCutOffSession"/>). While Auto Nest works
/// on a nest its plate takes none of them.
/// </summary>
public partial class MainWindow
{
/// <summary>Shows Swap Through-Cut when a junction on <paramref name="view"/>'s plate is right-clicked.</summary>
private void WatchCutOffMenu(NestView view) =>
view.PlateView.CutOffMenuRequested += (_, junction) => ShowCutOffMenu(view, junction);
private void OnSheetCutOff(object sender, RoutedEventArgs e) => StartTool(canvas => canvas.StartSheetCutOff());
private void OnTrimExtendCutOff(object sender, RoutedEventArgs e) =>
StartTool(canvas => canvas.StartTrimExtendCutOff());
private void ShowCutOffMenu(NestView view, Controls.CutOffJunction junction)
{
var canvas = view.PlateView;
if (view != ActiveView || !ReferenceEquals(canvas.Plate, junction.Plate))
return;
var swap = new MenuItem { Header = CutOffEdits.SwapLabel };
swap.Click += (_, _) =>
{
// The view may have moved to another sheet, or Auto Nest started, while the menu was open.
if (!ReferenceEquals(junction.Plate, canvas.Plate) || canvas.EditsLocked || view.Tab == nestingTab)
return;
var (_, status) = CutOffEdits.Swap(junction.Plate, junction.Through, junction.Stopper,
canvas.CutOffSettings, label => view.Tab.Undo.BeginChange(label));
canvas.InvalidateVisual();
ShowNotice(status);
UpdateUndoMenu();
};
var menu = new ContextMenu { ItemsSource = new List<MenuItem> { swap } };
menu.Open(canvas);
}
private async void OnAutomaticCutOff(object sender, RoutedEventArgs e) => await ShowAutomaticCutOffAsync(allPlates: false);
private async void OnNestAutomaticCutOff(object sender, RoutedEventArgs e) => await ShowAutomaticCutOffAsync(allPlates: true);
private async System.Threading.Tasks.Task ShowAutomaticCutOffAsync(bool allPlates)
{
if (ActiveView is not { PlateView: { Plate: { } plate } canvas } view)
return;
var tab = view.Tab;
bool IsBusy() => PlateWorkGuard.IsBusy(tab == nestingTab || arrangingTab == tab,
new[] { canvas.Tools.Current });
if (IsBusy())
{
await ConfirmDialog.ShowAsync(this, AutomaticCutOffSession.Title, PlateWorkGuard.BusyMessage);
return;
}
try
{
// As WinForms, the dialog opens over Select with nothing selected.
canvas.Tools.Select();
canvas.Selection.Clear();
var nest = tab.Document.Nest;
var session = new AutomaticCutOffSession(plate, nest.Units, allPlates ? nest : null,
IsBusy, () => canvas.Plate);
await AutomaticCutOffDialog.ShowAsync(this, session, canvas, label => tab.Undo.BeginChange(label));
}
finally
{
canvas.CutOffPreviewParts = null;
UpdateUndoMenu();
}
}
}
}