Files
OpenNest/OpenNest.Desktop/Forms/MainStatusText.cs
T
ajandClaude Opus 5.5 6b161d7a8b feat(data): store a nest's thickness name and show it
Nests showed only the decimal (0.135), while the shop thinks in gauges.
A nest now keeps a ThicknessName in its file, record and the server
(schema v20), set from Nest Information's new box, which suggests the
machine's name or the nearest standard gauge. The Open list, status bar
and reports show "10 ga (0.135)"; nests saved without a name get one
looked up for display only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:02:41 -05:00

118 lines
5.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using OpenNest.Data;
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, string)"/>), its thickness named by
/// <see cref="Nest.ThicknessName"/> or, without one, the nearest standard gauge or fraction.
/// </summary>
public static string Material(Nest nest)
{
ArgumentNullException.ThrowIfNull(nest);
var thicknessName = string.IsNullOrWhiteSpace(nest.ThicknessName)
? ThicknessNames.For(Array.Empty<MachineConfig>(), nest)
: nest.ThicknessName;
return Material(nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units, thicknessName);
}
/// <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) =>
Material(name, grade, thickness, units, null);
/// <summary>
/// Status text for the nest's material, grade and thickness, the thickness after its name
/// when it has one, e.g. "Material: Steel A36 · 10 ga (0.135 in)".
/// </summary>
public static string Material(string name, string grade, double thickness, Units units, string thicknessName)
{
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)
{
var value = thickness.ToString("0.####", CultureInfo.CurrentCulture) + " " + UnitsHelper.GetShortString(units);
parts.Add(string.IsNullOrWhiteSpace(thicknessName) ? value : $"{thicknessName.Trim()} ({value})");
}
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);
}
}
}