mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-02 17:59:27 -05:00
Merge M05 status bar and engine list into the Avalonia port work
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> # Conflicts: # OpenNest.Avalonia/MainWindow.axaml
This commit is contained in:
commit
14641f1392
17 files changed
+777
-99
No files matched your search
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenNest.Data;
|
||||
|
||||
namespace OpenNest.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// One entry of the machine list: <see cref="Machine"/> is the machine to assign when it is
|
||||
/// chosen, or null for an entry that only informs.
|
||||
/// </summary>
|
||||
public sealed record MachineMenuItem(string Text, MachineConfig Machine, bool Checked, bool Enabled);
|
||||
|
||||
/// <summary>
|
||||
/// The machines listed by Nest > Machine and the status bar's machine label: those on
|
||||
/// file by name, the active nest's checked; one assigned but no longer on file is shown
|
||||
/// checked and disabled so the nest still says what it was made for.
|
||||
/// </summary>
|
||||
public static class MachineMenu
|
||||
{
|
||||
public const string NoNestText = "(no nest open)";
|
||||
public const string NoMachinesText = "(no machines; see Tools > Machine Configuration)";
|
||||
|
||||
/// <summary>The entries for <paramref name="nest"/> (null when no nest is open).</summary>
|
||||
public static IReadOnlyList<MachineMenuItem> Items(Nest nest, IEnumerable<MachineConfig> machines)
|
||||
{
|
||||
if (nest == null)
|
||||
return new[] { new MachineMenuItem(NoNestText, null, false, false) };
|
||||
|
||||
var sorted = (machines ?? Enumerable.Empty<MachineConfig>())
|
||||
.OrderBy(m => m.Name, StringComparer.CurrentCultureIgnoreCase)
|
||||
.ToList();
|
||||
var items = sorted
|
||||
.Select(m => new MachineMenuItem(m.Name, m, m.Id == nest.Machine?.Id, true))
|
||||
.ToList();
|
||||
if (nest.Machine is { } assigned && sorted.All(m => m.Id != assigned.Id))
|
||||
items.Add(new MachineMenuItem($"{assigned.Name} (not on file)", null, true, false));
|
||||
if (items.Count == 0)
|
||||
items.Add(new MachineMenuItem(NoMachinesText, null, false, false));
|
||||
return items;
|
||||
}
|
||||
|
||||
/// <summary>Whether <paramref name="machine"/> is already the nest's, so choosing it changes nothing.</summary>
|
||||
public static bool IsAssigned(Nest nest, MachineConfig machine)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(nest);
|
||||
ArgumentNullException.ThrowIfNull(machine);
|
||||
return nest.Machine?.Id == machine.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using OpenNest.Desktop;
|
||||
using OpenNest.Geometry;
|
||||
|
||||
namespace OpenNest.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// The main window's status bar text, worded as the WinForms main window words it: cursor
|
||||
/// location, nest machine and material, plate utilization and the version, with the labels'
|
||||
/// tooltips and the location display mode both desktop apps keep in user-settings.json.
|
||||
/// Numbers are in the current culture.
|
||||
/// </summary>
|
||||
public static class MainStatusText
|
||||
{
|
||||
/// <summary>The user setting: true while the location follows the mouse, false while it shows the last left click.</summary>
|
||||
public const string LocationFollowsMouseName = "StatusBarLocationFollowsMouse";
|
||||
|
||||
public const string MachineToolTip = "Click or right-click to change the machine";
|
||||
public const string MaterialToolTip = "Click to edit nest info; right-click for more";
|
||||
public const string VersionToolTip = "OpenNest version";
|
||||
|
||||
/// <summary>Whether the location follows the mouse (the WinForms default) rather than only left clicks.</summary>
|
||||
public static bool ReadLocationFollowsMouse(IReadOnlyDictionary<string, string> settings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
return UserSettingText.ReadBool(settings, LocationFollowsMouseName, true);
|
||||
}
|
||||
|
||||
/// <summary>Stores the location mode in the WinForms format.</summary>
|
||||
public static void WriteLocationFollowsMouse(IDictionary<string, string> settings, bool followsMouse)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(settings);
|
||||
settings[LocationFollowsMouseName] = UserSettingText.Format(followsMouse);
|
||||
}
|
||||
|
||||
/// <summary>"Location: [x, y]", to four places.</summary>
|
||||
public static string Location(Vector point) =>
|
||||
string.Format(
|
||||
"Location: [{0}, {1}]",
|
||||
point.X.ToString("n4"),
|
||||
point.Y.ToString("n4"));
|
||||
|
||||
/// <summary>"Util: 61.3%", the plate's utilization to one place.</summary>
|
||||
public static string Utilization(double utilization) =>
|
||||
string.Format("Util: {0:P1}", utilization);
|
||||
|
||||
/// <summary>Status text for the nest's machine, e.g. "Machine: Generic Laser".</summary>
|
||||
public static string Machine(NestMachine machine)
|
||||
{
|
||||
if (machine == null)
|
||||
return "Machine: (none)";
|
||||
return "Machine: " + (string.IsNullOrWhiteSpace(machine.Name) ? "(unnamed)" : machine.Name.Trim());
|
||||
}
|
||||
|
||||
/// <summary>The material text for <paramref name="nest"/> (see <see cref="Material(string, string, double, Units)"/>).</summary>
|
||||
public static string Material(Nest nest)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(nest);
|
||||
return Material(nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Status text for the nest's material, grade and thickness, e.g. "Material: Steel A36 · 0.25 in".
|
||||
/// </summary>
|
||||
public static string Material(string name, string grade, double thickness, Units units)
|
||||
{
|
||||
var parts = new List<string>();
|
||||
var description = string.Join(" ", new[] { name?.Trim(), grade?.Trim() }
|
||||
.Where(s => !string.IsNullOrEmpty(s)));
|
||||
if (description.Length > 0)
|
||||
parts.Add(description);
|
||||
if (thickness > 0)
|
||||
parts.Add(thickness.ToString("0.####", CultureInfo.CurrentCulture) + " " + UnitsHelper.GetShortString(units));
|
||||
|
||||
return "Material: " + (parts.Count == 0 ? "(none)" : string.Join(" · ", parts));
|
||||
}
|
||||
|
||||
/// <summary>The version label: "v" and the version.</summary>
|
||||
public static string Version(string version) => "v" + version;
|
||||
|
||||
/// <summary>
|
||||
/// The informational version of <paramref name="assembly"/> without its "+commit" build
|
||||
/// metadata, else its version, else "unknown".
|
||||
/// </summary>
|
||||
public static string DisplayVersion(Assembly assembly)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(assembly);
|
||||
var version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
|
||||
?? assembly.GetName().Version?.ToString()
|
||||
?? "unknown";
|
||||
var metadata = version.IndexOf('+');
|
||||
return metadata < 0 ? version : version.Substring(0, metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenNest.Desktop.Interaction;
|
||||
|
||||
namespace OpenNest.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// The guard for plate commands (WinForms IsPlateWorkBusy): a running nesting job, or a
|
||||
/// busy active tool on any view of the nest. The Select tool counts as busy while anything
|
||||
/// is selected, as the WinForms select action does.
|
||||
/// </summary>
|
||||
public static class PlateWorkGuard
|
||||
{
|
||||
/// <summary>What a refused plate command tells the user.</summary>
|
||||
public const string BusyMessage = "Finish or cancel the current nesting or plate action first.";
|
||||
|
||||
/// <summary>Whether a plate command must wait: <paramref name="jobRunning"/>, or a busy tool among <paramref name="tools"/>.</summary>
|
||||
public static bool IsBusy(bool jobRunning, IEnumerable<PlateTool> tools) =>
|
||||
jobRunning || (tools ?? Enumerable.Empty<PlateTool>()).Any(tool => tool?.IsBusy == true);
|
||||
}
|
||||
}
|
||||
@@ -218,6 +218,23 @@ public sealed class MachineSettingsSource
|
||||
nest.SetSupportBed(grid.Enabled ? grid.BedFor(nest.Units) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nest > Machine: assigns <paramref name="machine"/> with its support grid
|
||||
/// (<see cref="AssignMachine"/>), gives each of <paramref name="cutOffSettings"/> (the nest's
|
||||
/// views) its cut-off defaults and the nest its spacing. Plates' own cutting parameters are
|
||||
/// kept, and of the sheets only an untouched trailing one takes the spacing. The caller
|
||||
/// records it as one nest edit.
|
||||
/// </summary>
|
||||
public void ApplyMachine(Nest nest, MachineConfig machine, PlateManager plates, IEnumerable<CutOffSettings> cutOffSettings)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(nest);
|
||||
ArgumentNullException.ThrowIfNull(plates);
|
||||
AssignMachine(nest, machine);
|
||||
foreach (var settings in cutOffSettings ?? Enumerable.Empty<CutOffSettings>())
|
||||
ApplyCutOffDefaults(settings, nest);
|
||||
plates.ChangePlateDefaults(() => MachineCuttingDefaults.ApplySpacingTo(nest, machine));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The cutting parameters a plate of <paramref name="nest"/> without its own starts from:
|
||||
/// the last ones applied (or the built-in defaults), with the lead-ins, lead-outs and kerf
|
||||
|
||||
Reference in new issue
Block a user