mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 06:41:42 -05:00
The Plates tab lists each plate as the WinForms list does: its number
("New plate" for the trailing empty one), size, part count, utilization
and, beside it, how many sheets are cut from it. A click shows the
plate, a double-click edits it, and its menu duplicates or deletes it.
Dragging a row moves the plate, Ctrl+drag drops a copy, a line showing
where; Alt+Up and Alt+Down move the current plate. The empty plate at
the end stays last.
The Plate menu gains Edit, Set as Default (the nest's default plate and
the defaults new nests start from), Rotate 90 degrees either way or 180
(fitting the turned plate), and Resize to Fit (Ctrl+P, by the auto-size
factor in Options); the Nest menu gains Remove Empty Plates. Each is
one undo step under its WinForms label, through the shared
PlateCommands, and none runs while Auto Nest works on the nest.
Edit Plate edits the quantity, size, part and edge spacing, the
quadrant with a picker (click or arrow keys) and the sheet: rectangular,
or an outline imported from a DXF, DWG or SVG file (an SVG that does not
state its size asks what its units are first), with Clear to make it a
rectangle again. Done is enabled only when the size parses and the edge
spacing leaves room on the sheet; an empty plate's new settings become
the nest's defaults.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
3.1 KiB
C#
76 lines
3.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
using OpenNest.Data;
|
|
using OpenNest.Desktop;
|
|
|
|
namespace OpenNest.Avalonia
|
|
{
|
|
/// <summary>
|
|
/// The Plate menu's Edit, Set as Default, Rotate and Resize to Fit (Ctrl+P), and Nest >
|
|
/// Remove Empty Plates, on the active nest's shown plate as in the WinForms main window. None
|
|
/// runs while Auto Nest works on the nest.
|
|
/// </summary>
|
|
public partial class MainWindow
|
|
{
|
|
private void InitializePlateCommands() =>
|
|
KeyBindings.Add(new KeyBinding
|
|
{
|
|
Gesture = new KeyGesture(Key.P, KeyModifiers.Control),
|
|
Command = new Command(() => OnResizeToFit(null, null)),
|
|
});
|
|
|
|
// The active view, when its plates can be changed now; otherwise says why not.
|
|
private NestView PlateCommandView(string doing)
|
|
{
|
|
var view = ActiveView;
|
|
if (view == null || IsNesting(view.Tab, doing) || !view.CanEditPlates)
|
|
return null;
|
|
return view;
|
|
}
|
|
|
|
private async void OnEditPlate(object sender, RoutedEventArgs e)
|
|
{
|
|
if (PlateCommandView("editing a plate") is { } view)
|
|
await view.EditCurrentPlateAsync();
|
|
}
|
|
|
|
// As WinForms: the nest's next plates and every new nest start from the shown plate.
|
|
private async void OnSetPlateAsDefault(object sender, RoutedEventArgs e)
|
|
{
|
|
if (PlateCommandView("changing its default plate") is not { } view
|
|
|| view.SetPlateAsNestDefault() is not { } plate)
|
|
return;
|
|
var nest = view.Tab.Document.Nest;
|
|
try
|
|
{
|
|
var machines = DesktopSettings.Machines;
|
|
machines.SaveNestDefaults(PlateCommands.NewNestDefaults(nest, plate, machines.LoadSavedNestDefaults(out _)));
|
|
}
|
|
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
|
{
|
|
await ConfirmDialog.ShowAsync(this, "Nest Defaults",
|
|
"The nest defaults could not be saved.\n\n" + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void OnRotatePlateCw(object sender, RoutedEventArgs e) => RotatePlate(PlateRotation.Clockwise);
|
|
|
|
private void OnRotatePlateCcw(object sender, RoutedEventArgs e) => RotatePlate(PlateRotation.CounterClockwise);
|
|
|
|
private void OnRotatePlate180(object sender, RoutedEventArgs e) => RotatePlate(PlateRotation.HalfTurn);
|
|
|
|
private void RotatePlate(PlateRotation rotation) =>
|
|
PlateCommandView("rotating a plate")?.RotatePlate(rotation);
|
|
|
|
// The rounding is Tools > Options' auto-size factor, read at each use as WinForms reads its setting.
|
|
private void OnResizeToFit(object sender, RoutedEventArgs e) =>
|
|
PlateCommandView("resizing a plate")?.ResizePlateToFit(
|
|
DesktopOptions.Read(UserSettingsFile.Read(UserSettingsFile.DefaultPath)).AutoSizePlateFactor);
|
|
|
|
private void OnRemoveEmptyPlates(object sender, RoutedEventArgs e) =>
|
|
PlateCommandView("removing its empty plates")?.RemoveEmptyPlates();
|
|
}
|
|
}
|