mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-05 03:42:10 -04:00
fix(desktop): apply saved units to new and BOM-created nests
New only fell back to the legacy DefaultUnit setting when the whole defaults file was missing or invalid, so a readable file without a usable unit produced inches. BOM import never assigned units at all, and the Nest Defaults dialog showed inches for a missing file. All three now load through MainForm.LoadSavedNestDefaults, which passes DefaultUnit as the per-field unit fallback. BOM-created nests start from NestDefaults.ApplyTo, like New, before applying each group's plate size and spacing. The ApplyTo test now asserts units; removing the unit assignment from ApplyTo fails it. WinForms behaviour is compile-verified only on Linux.
This commit is contained in:
1 parent
b7dc7dee13
commit
90587803be
3 files changed
+24
-12
No files matched your search
@@ -261,7 +261,7 @@ public class NestDefaultsTests : IDisposable
|
||||
[Fact]
|
||||
public void ApplyTo_SetsUnitsAndPlateDefaults_AndDoesNotAliasSourceNest()
|
||||
{
|
||||
var source = new Nest();
|
||||
var source = new Nest { Units = Units.Millimeters };
|
||||
source.PlateDefaults.Size = new Size(48, 96);
|
||||
source.PlateDefaults.EdgeSpacing = new Spacing(1.25, 1.25, 1.25, 1.25);
|
||||
var defaults = NestDefaults.FromNest(source);
|
||||
@@ -273,6 +273,8 @@ public class NestDefaultsTests : IDisposable
|
||||
var target = new Nest();
|
||||
defaults.ApplyTo(target);
|
||||
|
||||
// New and BOM-created nests both take their units from ApplyTo.
|
||||
Assert.Equal(Units.Millimeters, target.Units);
|
||||
Assert.Equal(new Size(48, 96), target.PlateDefaults.Size);
|
||||
Assert.Equal(
|
||||
new Spacing(1.25, 1.25, 1.25, 1.25),
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenNest.Forms
|
||||
InitializeComponent();
|
||||
_parts = new List<BomPartRow>();
|
||||
_groupSettings = new Dictionary<string, GroupSettings>();
|
||||
_defaults = NestDefaults.Load(NestDefaults.DefaultPath);
|
||||
_defaults = MainForm.LoadSavedNestDefaults(out _);
|
||||
ApplyDefaults();
|
||||
}
|
||||
|
||||
@@ -465,10 +465,12 @@ namespace OpenNest.Forms
|
||||
var nest = new Nest(nestName);
|
||||
nest.DateCreated = DateTime.Now;
|
||||
nest.DateLastModified = DateTime.Now;
|
||||
// Saved defaults first (units, quadrant, plate), as New does;
|
||||
// then the group's own plate size and spacing.
|
||||
_defaults.ApplyTo(nest);
|
||||
nest.PlateDefaults.Size = new Geometry.Size(plateWidth, plateLength);
|
||||
nest.Thickness = thickness;
|
||||
nest.Material = new Material(material);
|
||||
nest.PlateDefaults.Quadrant = _defaults.Quadrant;
|
||||
nest.PlateDefaults.PartSpacing = partSpacing;
|
||||
nest.PlateDefaults.EdgeSpacing = new Spacing(
|
||||
edgeLeft,
|
||||
|
||||
@@ -108,17 +108,12 @@ namespace OpenNest.Forms
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the persisted nest defaults. When no usable file exists,
|
||||
/// units come from the legacy DefaultUnit setting; a corrupt file
|
||||
/// warns once per session.
|
||||
/// Loads the persisted nest defaults (see <see cref="LoadSavedNestDefaults"/>);
|
||||
/// a corrupt or unreadable file warns once per session.
|
||||
/// </summary>
|
||||
private NestDefaults LoadNestDefaults()
|
||||
{
|
||||
var defaults = NestDefaults.Load(NestDefaults.DefaultPath, out var status);
|
||||
if (status == NestDefaultsStatus.Ok)
|
||||
return defaults;
|
||||
|
||||
defaults.Units = Properties.Settings.Default.DefaultUnit;
|
||||
var defaults = LoadSavedNestDefaults(out var status);
|
||||
|
||||
if (status == NestDefaultsStatus.Invalid && !defaultsWarned)
|
||||
{
|
||||
@@ -135,6 +130,19 @@ namespace OpenNest.Forms
|
||||
|
||||
private bool defaultsWarned;
|
||||
|
||||
/// <summary>
|
||||
/// The single desktop entry point for persisted nest defaults. Units
|
||||
/// fall back to the legacy DefaultUnit setting whenever the file is
|
||||
/// missing or unusable or has no valid unit, so New, BOM import and
|
||||
/// the defaults dialog always agree.
|
||||
/// </summary>
|
||||
internal static NestDefaults LoadSavedNestDefaults(out NestDefaultsStatus status) =>
|
||||
NestDefaults.Load(
|
||||
NestDefaults.DefaultPath,
|
||||
Properties.Settings.Default.DefaultUnit,
|
||||
out status
|
||||
);
|
||||
|
||||
private string GetNestName(DateTime date, int id)
|
||||
{
|
||||
var year = (date.Year % 100).ToString("D2");
|
||||
@@ -1155,7 +1163,7 @@ namespace OpenNest.Forms
|
||||
|
||||
private void NestDefaults_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var form = new NestDefaultsForm(NestDefaults.Load(NestDefaults.DefaultPath)))
|
||||
using (var form = new NestDefaultsForm(LoadSavedNestDefaults(out _)))
|
||||
{
|
||||
if (form.ShowDialog(this) == DialogResult.OK)
|
||||
form.GetDefaults().Save(NestDefaults.DefaultPath);
|
||||
|
||||
Reference in new issue
Block a user