Files
OpenNest/OpenNest.Avalonia/Controls/QuadrantPicker.cs
T
ajandClaude Opus 5.5 7ccce96620 feat(avalonia): plates list, plate commands and Edit Plate
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>
2026-11-29 20:18:28 -05:00

98 lines
3.4 KiB
C#

using System;
using System.Globalization;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using OpenNest.Desktop;
namespace OpenNest.Avalonia.Controls
{
/// <summary>
/// Edit Plate's quadrant picker, as the WinForms one: a square split in four with the plate
/// origin's quadrant filled and numbered; a click picks the quadrant under the pointer. The
/// arrow keys move it too.
/// </summary>
public sealed class QuadrantPicker : Control
{
private static readonly IBrush CellFill = Brush.Parse("#87CEFA");
private static readonly IPen CellPen = new Pen(Brushes.Blue, 1);
private static readonly IPen AxisPen = new Pen(Brushes.Gray, 1);
private int quadrant = 1;
public QuadrantPicker()
{
Focusable = true;
MinWidth = 120;
MinHeight = 90;
}
/// <summary>The picked quadrant, 1 to 4; anything else is taken as 1.</summary>
public int Quadrant
{
get => quadrant;
set
{
var normalized = QuadrantPick.Normalize(value);
if (normalized == quadrant)
return;
quadrant = normalized;
InvalidateVisual();
QuadrantChanged?.Invoke(this, EventArgs.Empty);
}
}
public event EventHandler QuadrantChanged;
public override void Render(DrawingContext context)
{
var width = Bounds.Width;
var height = Bounds.Height;
context.FillRectangle(Brushes.White, new Rect(0, 0, width, height));
context.DrawLine(AxisPen, new Point(width / 2, 0), new Point(width / 2, height));
context.DrawLine(AxisPen, new Point(0, height / 2), new Point(width, height / 2));
var (x, y, w, h) = QuadrantPick.Cell(quadrant, width, height);
var cell = new Rect(x, y, w, h).Deflate(0.5);
context.FillRectangle(CellFill, cell);
context.DrawRectangle(CellPen, cell);
var text = new FormattedText(
quadrant.ToString(CultureInfo.InvariantCulture), CultureInfo.CurrentCulture,
FlowDirection.LeftToRight, Typeface.Default, 35, Brushes.White);
context.DrawText(text, new Point(
x + (w - text.Width) / 2, y + (h - text.Height) / 2));
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
return;
var at = e.GetPosition(this);
Quadrant = QuadrantPick.At(at.X, at.Y, Bounds.Width, Bounds.Height);
Focus();
e.Handled = true;
}
// Left and right cross the vertical axis, up and down the horizontal one.
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
var left = quadrant is 2 or 3;
var top = quadrant is 1 or 2;
switch (e.Key)
{
case Key.Left: left = true; break;
case Key.Right: left = false; break;
case Key.Up: top = true; break;
case Key.Down: top = false; break;
default: return;
}
Quadrant = left ? (top ? 2 : 3) : (top ? 1 : 4);
e.Handled = true;
}
}
}