using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Interactivity;
using OpenNest.Desktop.Interaction;
using OpenNest.Forms;
namespace OpenNest.Avalonia
{
///
/// Plate > Sheet Cut-Off, Trim/Extend Cut-Off and Automatic Scrap Cutoffs, Nest >
/// 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
/// and ). While Auto Nest works
/// on a nest its plate takes none of them.
///
public partial class MainWindow
{
/// Shows Swap Through-Cut when a junction on 's plate is right-clicked.
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