using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Reflection; using OpenNest.Desktop; using OpenNest.Geometry; namespace OpenNest.Forms { /// /// 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. /// public static class MainStatusText { /// The user setting: true while the location follows the mouse, false while it shows the last left click. 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"; /// Whether the location follows the mouse (the WinForms default) rather than only left clicks. public static bool ReadLocationFollowsMouse(IReadOnlyDictionary settings) { ArgumentNullException.ThrowIfNull(settings); return UserSettingText.ReadBool(settings, LocationFollowsMouseName, true); } /// Stores the location mode in the WinForms format. public static void WriteLocationFollowsMouse(IDictionary settings, bool followsMouse) { ArgumentNullException.ThrowIfNull(settings); settings[LocationFollowsMouseName] = UserSettingText.Format(followsMouse); } /// "Location: [x, y]", to four places. public static string Location(Vector point) => string.Format( "Location: [{0}, {1}]", point.X.ToString("n4"), point.Y.ToString("n4")); /// "Util: 61.3%", the plate's utilization to one place. public static string Utilization(double utilization) => string.Format("Util: {0:P1}", utilization); /// Status text for the nest's machine, e.g. "Machine: Generic Laser". public static string Machine(NestMachine machine) { if (machine == null) return "Machine: (none)"; return "Machine: " + (string.IsNullOrWhiteSpace(machine.Name) ? "(unnamed)" : machine.Name.Trim()); } /// The material text for (see ). public static string Material(Nest nest) { ArgumentNullException.ThrowIfNull(nest); return Material(nest.Material?.Name, nest.Material?.Grade, nest.Thickness, nest.Units); } /// /// Status text for the nest's material, grade and thickness, e.g. "Material: Steel A36 · 0.25 in". /// public static string Material(string name, string grade, double thickness, Units units) { var parts = new List(); 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)); } /// The version label: "v" and the version. public static string Version(string version) => "v" + version; /// /// The informational version of without its "+commit" build /// metadata, else its version, else "unknown". /// public static string DisplayVersion(Assembly assembly) { ArgumentNullException.ThrowIfNull(assembly); var version = assembly.GetCustomAttribute()?.InformationalVersion ?? assembly.GetName().Version?.ToString() ?? "unknown"; var metadata = version.IndexOf('+'); return metadata < 0 ? version : version.Substring(0, metadata); } } }