Files
OpenNest/OpenNest.Desktop/Forms/MainStatusText.cs
T
ajandClaude Opus 5.5 021af04222 feat(desktop): share the status bar text, machine list and plate-work guard
MainStatusText words the main window's location, machine, material,
utilization and version labels as WinForms does, with the labels'
tooltips and the StatusBarLocationFollowsMouse setting both apps keep.
MachineMenu lists the machines for Nest > Machine and the machine label
(by name, the nest's checked, one no longer on file checked and
disabled), and MachineSettingsSource.ApplyMachine assigns one with its
support grid, cut-off defaults and spacing. PlateWorkGuard holds the
"Finish or cancel the current nesting or plate action first." check.
The WinForms main window delegates to them unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 20:10:34 -05:00

100 lines
4.5 KiB
C#

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);
}
}
}