Files
OpenNest/OpenNest.Avalonia/SvgScaleDialog.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

92 lines
3.5 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using OpenNest.Desktop;
namespace OpenNest.Avalonia
{
/// <summary>
/// What an SVG's numbers mean when the file does not state its real-world size, as the
/// WinForms SVG Scale form asks, showing the size each choice gives. OK returns the chosen
/// units per inch; Skip File, Esc or closing returns null and the file is not imported.
/// </summary>
internal sealed class SvgScaleDialog : Window
{
private SvgScaleDialog(string path, double width, double height, Units units)
{
Title = "SVG Scale";
Width = 440;
SizeToContent = SizeToContent.Height;
CanResize = false;
ShowInTaskbar = false;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
var size = new TextBlock();
var choices = new List<(RadioButton Button, double PerInch)>();
var options = new StackPanel { Spacing = 4 };
foreach (var (text, perInch) in SvgScale.Choices)
{
var button = new RadioButton { Content = text, GroupName = "SvgScale", IsChecked = choices.Count == 0 };
button.IsCheckedChanged += (_, _) => UpdateSize();
choices.Add((button, perInch));
options.Children.Add(button);
}
double Chosen()
{
foreach (var (button, perInch) in choices)
{
if (button.IsChecked == true)
return perInch;
}
return choices[0].PerInch;
}
void UpdateSize() => size.Text = SvgScale.ImportedSizeText(width, height, Chosen(), units);
UpdateSize();
var ok = new Button { Content = "OK", IsDefault = true, MinWidth = 80 };
ok.Click += (_, _) => Close(Chosen());
var skip = new Button { Content = "Skip File", IsCancel = true, MinWidth = 80 };
skip.Click += (_, _) => Close(null);
Content = new StackPanel
{
Margin = new Thickness(18),
Spacing = 12,
Children =
{
new TextBlock { Text = SvgScale.Question(Path.GetFileName(path)), TextWrapping = global::Avalonia.Media.TextWrapping.Wrap },
options,
size,
new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
Spacing = 8,
Children = { ok, skip },
},
},
};
}
/// <summary>
/// Whether to import <paramref name="path"/>, and the SVG user units per inch the user
/// chose: null when the file needs no scale (not an SVG, or one stating its size).
/// Import is false when the user skipped the file.
/// </summary>
public static async Task<(bool Import, double? UserUnitsPerInch)> ResolveAsync(
Window owner, string path, Units units)
{
if (SvgScale.SizeToAsk(path) is not { } size)
return (true, null);
var chosen = await new SvgScaleDialog(path, size.Width, size.Height, units)
.ShowDialog<double?>(owner);
return (chosen != null, chosen);
}
}
}