From f44c1d465f9f1e69fdfb6a88d885897dff6719ce Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 28 Sep 2026 08:20:49 -0400 Subject: [PATCH] feat(ui): defaults.json-backed new nests; retire .nstdot templates New nests now load plate defaults from %APPDATA%/OpenNest/defaults.json instead of a .nstdot nest template: - Tools > Nest Defaults... edits the file directly (new dialog). - Tools > Save Current Plate as Defaults captures the active plate with no dialog (visible when a nest is open). - New_Click no longer unzips a template; a corrupt defaults file warns once per session and falls back to built-in values. - First run converts an existing NestTemplatePath .nstdot to defaults.json and clears the legacy setting (kept readable on a failed conversion); the setting itself stays, marked legacy. - Save As no longer offers the .nstdot filter; SaveTemplate removed. - BomImportForm and OptionsForm template plumbing removed in favor of the shared NestDefaults store. --- OpenNest.Data/NestDefaults.cs | 51 ++- OpenNest.Tests/Data/NestDefaultsTests.cs | 27 +- OpenNest/Forms/BomImportForm.cs | 86 ++--- OpenNest/Forms/EditNestForm.cs | 28 +- OpenNest/Forms/MainForm.Designer.cs | 20 +- OpenNest/Forms/MainForm.cs | 121 +++++-- OpenNest/Forms/NestDefaultsForm.Designer.cs | 364 ++++++++++++++++++++ OpenNest/Forms/NestDefaultsForm.cs | 62 ++++ OpenNest/Forms/OptionsForm.Designer.cs | 59 +--- OpenNest/Forms/OptionsForm.cs | 11 - OpenNest/Properties/Settings.Designer.cs | 2 + 11 files changed, 644 insertions(+), 187 deletions(-) create mode 100644 OpenNest/Forms/NestDefaultsForm.Designer.cs create mode 100644 OpenNest/Forms/NestDefaultsForm.cs diff --git a/OpenNest.Data/NestDefaults.cs b/OpenNest.Data/NestDefaults.cs index 3424b05..b0d4c20 100644 --- a/OpenNest.Data/NestDefaults.cs +++ b/OpenNest.Data/NestDefaults.cs @@ -4,6 +4,19 @@ using OpenNest.Geometry; namespace OpenNest.Data; +/// Outcome of . +public enum NestDefaultsStatus +{ + /// Defaults were read from the file (invalid fields still fall back individually). + Ok, + + /// No file exists at the path; built-in fallback values were used. + Missing, + + /// The file exists but could not be read or parsed; fallback values were used. + Invalid, +} + /// /// Plate/nest defaults persisted to a single JSON file /// (by default %APPDATA%\OpenNest\defaults.json), replacing the @@ -56,18 +69,18 @@ public sealed class NestDefaults public static NestDefaults Load(string path) => Load(path, out _); /// - /// Loads defaults; is true when the file - /// was present (even if it failed to parse), so callers can surface a - /// warning when a present file did not load cleanly. + /// Loads defaults and reports whether the file was missing, loaded, or + /// present but unreadable/invalid, so callers can warn about a corrupt + /// file while still returning usable values. /// - public static NestDefaults Load(string path, out bool fileExisted) + public static NestDefaults Load(string path, out NestDefaultsStatus status) { - fileExisted = false; var defaults = Fallback; if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) + { + status = NestDefaultsStatus.Missing; return defaults; - - fileExisted = true; + } NestDefaultsDto? dto; try @@ -77,15 +90,22 @@ public sealed class NestDefaults } catch (JsonException) { + status = NestDefaultsStatus.Invalid; return defaults; } catch (IOException) { + status = NestDefaultsStatus.Invalid; return defaults; } if (dto is null) + { + status = NestDefaultsStatus.Invalid; return defaults; + } + + status = NestDefaultsStatus.Ok; if ( dto.Units is not null @@ -138,6 +158,23 @@ public sealed class NestDefaults }; } + /// + /// Captures defaults from an existing plate (a copy of its size, + /// quadrant, and spacing), e.g. the active plate in the desktop app. + /// + public static NestDefaults FromPlate(Units units, Plate plate) + { + ArgumentNullException.ThrowIfNull(plate); + return new NestDefaults + { + Units = units, + Size = plate.Size, + Quadrant = plate.Quadrant, + PartSpacing = plate.PartSpacing, + EdgeSpacing = plate.EdgeSpacing, + }; + } + public void ApplyTo(Nest nest) { ArgumentNullException.ThrowIfNull(nest); diff --git a/OpenNest.Tests/Data/NestDefaultsTests.cs b/OpenNest.Tests/Data/NestDefaultsTests.cs index baec274..db44927 100644 --- a/OpenNest.Tests/Data/NestDefaultsTests.cs +++ b/OpenNest.Tests/Data/NestDefaultsTests.cs @@ -34,9 +34,9 @@ public class NestDefaultsTests : IDisposable }; original.Save(_path); - var loaded = NestDefaults.Load(_path, out var loadedFromDisk); + var loaded = NestDefaults.Load(_path, out var status); - Assert.True(loadedFromDisk); + Assert.Equal(NestDefaultsStatus.Ok, status); Assert.Equal(Units.Millimeters, loaded.Units); Assert.Equal(original.Size, loaded.Size); Assert.Equal(3, loaded.Quadrant); @@ -58,20 +58,20 @@ public class NestDefaultsTests : IDisposable [Fact] public void Load_MissingFile_ReturnsFallback() { - var loaded = NestDefaults.Load(_path, out var loadedFromDisk); + var loaded = NestDefaults.Load(_path, out var status); - Assert.False(loadedFromDisk); + Assert.Equal(NestDefaultsStatus.Missing, status); AssertFallback(loaded); } [Fact] - public void Load_CorruptJson_ReturnsFallbackButReportsFile() + public void Load_CorruptJson_ReturnsFallbackButReportsInvalid() { File.WriteAllText(_path, "{ this is not json"); - var loaded = NestDefaults.Load(_path, out var loadedFromDisk); + var loaded = NestDefaults.Load(_path, out var status); - Assert.True(loadedFromDisk); + Assert.Equal(NestDefaultsStatus.Invalid, status); AssertFallback(loaded); } @@ -80,9 +80,9 @@ public class NestDefaultsTests : IDisposable { File.WriteAllText(_path, """{ "units": "millimeters", "partSpacing": 4 }"""); - var loaded = NestDefaults.Load(_path, out var loadedFromDisk); + var loaded = NestDefaults.Load(_path, out var status); - Assert.True(loadedFromDisk); + Assert.Equal(NestDefaultsStatus.Ok, status); Assert.Equal(Units.Millimeters, loaded.Units); Assert.Equal(4, loaded.PartSpacing); // Untouched fields keep fallback values. @@ -107,9 +107,10 @@ public class NestDefaultsTests : IDisposable """ ); - var loaded = NestDefaults.Load(_path, out var loadedFromDisk); + var loaded = NestDefaults.Load(_path, out var status); - Assert.True(loadedFromDisk); + // The file parses; only the invalid values fall back, so no warning. + Assert.Equal(NestDefaultsStatus.Ok, status); Assert.Equal(Units.Inches, loaded.Units); Assert.Equal(new Size(100, 100), loaded.Size); Assert.Equal(1, loaded.Quadrant); @@ -144,9 +145,9 @@ public class NestDefaultsTests : IDisposable """ ); - var loaded = NestDefaults.Load(_path, out var loadedFromDisk); + var loaded = NestDefaults.Load(_path, out var status); - Assert.True(loadedFromDisk); + Assert.Equal(NestDefaultsStatus.Ok, status); Assert.Equal(2, loaded.PartSpacing); } diff --git a/OpenNest/Forms/BomImportForm.cs b/OpenNest/Forms/BomImportForm.cs index 46df805..222c959 100644 --- a/OpenNest/Forms/BomImportForm.cs +++ b/OpenNest/Forms/BomImportForm.cs @@ -5,6 +5,7 @@ using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; +using OpenNest.Data; using OpenNest.Geometry; using OpenNest.IO; using OpenNest.IO.Bom; @@ -16,7 +17,7 @@ namespace OpenNest.Forms private List _parts; private Dictionary _groupSettings; private bool _suppressRegroup; - private Nest.PlateSettings _templateDefaults; + private NestDefaults _defaults; public Form MdiParentForm { get; set; } @@ -25,37 +26,14 @@ namespace OpenNest.Forms InitializeComponent(); _parts = new List(); _groupSettings = new Dictionary(); - _templateDefaults = LoadTemplateDefaults(); - ApplyTemplateDefaults(); + _defaults = NestDefaults.Load(NestDefaults.DefaultPath); + ApplyDefaults(); } - private Nest.PlateSettings LoadTemplateDefaults() + private void ApplyDefaults() { - var templatePath = Properties.Settings.Default.NestTemplatePath; - if (File.Exists(templatePath)) - { - try - { - var nest = new NestReader(templatePath).Read(); - return nest.PlateDefaults; - } - catch { } - } - - // Fallback defaults matching CreateDefaultNest - return new Nest.PlateSettings - { - Size = new Geometry.Size(100, 100), - Quadrant = 1, - PartSpacing = 1, - EdgeSpacing = new Spacing(1, 1, 1, 1), - }; - } - - private void ApplyTemplateDefaults() - { - txtPlateWidth.Text = _templateDefaults.Size.Width.ToString("0.####"); - txtPlateLength.Text = _templateDefaults.Size.Length.ToString("0.####"); + txtPlateWidth.Text = _defaults.Size.Width.ToString("0.####"); + txtPlateLength.Text = _defaults.Size.Length.ToString("0.####"); } #region File Browsing @@ -147,9 +125,9 @@ namespace OpenNest.Forms var matchedPaths = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var group in analysis.Groups) - foreach (var part in group.Parts) - if (part.DxfPath != null) - matchedPaths[part.Item.FileName ?? ""] = part.DxfPath; + foreach (var part in group.Parts) + if (part.DxfPath != null) + matchedPaths[part.Item.FileName ?? ""] = part.DxfPath; _parts = new List(); @@ -290,10 +268,10 @@ namespace OpenNest.Forms var defaultWidth = double.TryParse(txtPlateWidth.Text, out var w) ? w - : _templateDefaults.Size.Width; + : _defaults.Size.Width; var defaultLength = double.TryParse(txtPlateLength.Text, out var l) ? l - : _templateDefaults.Size.Length; + : _defaults.Size.Length; var groups = _parts .Where(p => @@ -336,11 +314,11 @@ namespace OpenNest.Forms group.Sum(p => p.Qty ?? 0), existing ? gs.PlateWidth : defaultWidth, existing ? gs.PlateLength : defaultLength, - existing ? gs.PartSpacing : _templateDefaults.PartSpacing, - existing ? gs.EdgeLeft : _templateDefaults.EdgeSpacing.Left, - existing ? gs.EdgeBottom : _templateDefaults.EdgeSpacing.Bottom, - existing ? gs.EdgeRight : _templateDefaults.EdgeSpacing.Right, - existing ? gs.EdgeTop : _templateDefaults.EdgeSpacing.Top + existing ? gs.PartSpacing : _defaults.PartSpacing, + existing ? gs.EdgeLeft : _defaults.EdgeSpacing.Left, + existing ? gs.EdgeBottom : _defaults.EdgeSpacing.Bottom, + existing ? gs.EdgeRight : _defaults.EdgeSpacing.Right, + existing ? gs.EdgeTop : _defaults.EdgeSpacing.Top ); } @@ -374,23 +352,23 @@ namespace OpenNest.Forms { PlateWidth = row["Plate Width"] is double pw ? pw - : _templateDefaults.Size.Width, + : _defaults.Size.Width, PlateLength = row["Plate Length"] is double pl ? pl - : _templateDefaults.Size.Length, + : _defaults.Size.Length, PartSpacing = row["Part Spacing"] is double ps ? ps - : _templateDefaults.PartSpacing, + : _defaults.PartSpacing, EdgeLeft = row["Edge Left"] is double el ? el - : _templateDefaults.EdgeSpacing.Left, + : _defaults.EdgeSpacing.Left, EdgeBottom = row["Edge Bottom"] is double eb ? eb - : _templateDefaults.EdgeSpacing.Bottom, + : _defaults.EdgeSpacing.Bottom, EdgeRight = row["Edge Right"] is double er ? er - : _templateDefaults.EdgeSpacing.Right, - EdgeTop = row["Edge Top"] is double et ? et : _templateDefaults.EdgeSpacing.Top, + : _defaults.EdgeSpacing.Right, + EdgeTop = row["Edge Top"] is double et ? et : _defaults.EdgeSpacing.Top, }; } } @@ -434,10 +412,10 @@ namespace OpenNest.Forms var defaultWidth = double.TryParse(txtPlateWidth.Text, out var dw) ? dw - : _templateDefaults.Size.Width; + : _defaults.Size.Width; var defaultLength = double.TryParse(txtPlateLength.Text, out var dl) ? dl - : _templateDefaults.Size.Length; + : _defaults.Size.Length; var groups = _parts .Where(p => @@ -477,11 +455,11 @@ namespace OpenNest.Forms var hasSettings = _groupSettings.TryGetValue(key, out var gs); var plateWidth = hasSettings ? gs.PlateWidth : defaultWidth; var plateLength = hasSettings ? gs.PlateLength : defaultLength; - var partSpacing = hasSettings ? gs.PartSpacing : _templateDefaults.PartSpacing; - var edgeLeft = hasSettings ? gs.EdgeLeft : _templateDefaults.EdgeSpacing.Left; - var edgeBottom = hasSettings ? gs.EdgeBottom : _templateDefaults.EdgeSpacing.Bottom; - var edgeRight = hasSettings ? gs.EdgeRight : _templateDefaults.EdgeSpacing.Right; - var edgeTop = hasSettings ? gs.EdgeTop : _templateDefaults.EdgeSpacing.Top; + var partSpacing = hasSettings ? gs.PartSpacing : _defaults.PartSpacing; + var edgeLeft = hasSettings ? gs.EdgeLeft : _defaults.EdgeSpacing.Left; + var edgeBottom = hasSettings ? gs.EdgeBottom : _defaults.EdgeSpacing.Bottom; + var edgeRight = hasSettings ? gs.EdgeRight : _defaults.EdgeSpacing.Right; + var edgeTop = hasSettings ? gs.EdgeTop : _defaults.EdgeSpacing.Top; var nestName = $"{jobName} - {thickness:0.###} {material}"; var nest = new Nest(nestName); @@ -490,7 +468,7 @@ namespace OpenNest.Forms nest.PlateDefaults.Size = new Geometry.Size(plateWidth, plateLength); nest.Thickness = thickness; nest.Material = new Material(material); - nest.PlateDefaults.Quadrant = _templateDefaults.Quadrant; + nest.PlateDefaults.Quadrant = _defaults.Quadrant; nest.PlateDefaults.PartSpacing = partSpacing; nest.PlateDefaults.EdgeSpacing = new Spacing( edgeLeft, diff --git a/OpenNest/Forms/EditNestForm.cs b/OpenNest/Forms/EditNestForm.cs index 46da225..99845df 100644 --- a/OpenNest/Forms/EditNestForm.cs +++ b/OpenNest/Forms/EditNestForm.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; @@ -301,16 +301,11 @@ namespace OpenNest.Forms public void SaveAs() { var dlg = new SaveFileDialog(); - dlg.Filter = $"{NestFormat.FileFilter}|Template File|*.nstdot"; + dlg.Filter = NestFormat.FileFilter; dlg.FileName = Nest.Name; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) - { - if (dlg.FilterIndex == 2) - SaveTemplate(dlg.FileName); - else - SaveAs(dlg.FileName); - } + SaveAs(dlg.FileName); } public void SaveAs(string path) @@ -319,17 +314,6 @@ namespace OpenNest.Forms Text = Document.Name; } - public void SaveTemplate(string path) - { - var nst = new Nest(); - nst.Name = Path.GetFileNameWithoutExtension(path); - nst.PlateDefaults = Nest.PlateDefaults; - nst.Units = Nest.Units; - - var writer = new NestWriter(nst); - writer.Write(path); - } - public void Import() { var dlg = new OpenFileDialog(); @@ -943,9 +927,9 @@ namespace OpenNest.Forms // Refresh all parts to use the updated programs foreach (var plate in Nest.Plates) - foreach (var part in plate.Parts) - if (!part.BaseDrawing.IsCutOff) - part.Update(); + foreach (var part in plate.Parts) + if (!part.BaseDrawing.IsCutOff) + part.Update(); UpdateDrawingList(); PlateView.Invalidate(); diff --git a/OpenNest/Forms/MainForm.Designer.cs b/OpenNest/Forms/MainForm.Designer.cs index 0882ef5..2e1b7f4 100644 --- a/OpenNest/Forms/MainForm.Designer.cs +++ b/OpenNest/Forms/MainForm.Designer.cs @@ -82,6 +82,8 @@ mnuSetRotationIncrement = new System.Windows.Forms.ToolStripMenuItem(); toolStripMenuItem15 = new System.Windows.Forms.ToolStripSeparator(); mnuToolsMachineConfig = new System.Windows.Forms.ToolStripMenuItem(); + mnuToolsNestDefaults = new System.Windows.Forms.ToolStripMenuItem(); + mnuToolsSaveCurrentAsDefaults = new System.Windows.Forms.ToolStripMenuItem(); mnuToolsOptions = new System.Windows.Forms.ToolStripMenuItem(); mnuNest = new System.Windows.Forms.ToolStripMenuItem(); mnuNestEdit = new System.Windows.Forms.ToolStripMenuItem(); @@ -420,7 +422,7 @@ // // mnuTools // - mnuTools.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { mnuToolsMeasureArea, mnuToolsBestFitViewer, mnuToolsPatternTile, mnuToolsExpandSpacing, mnuToolsAlign, toolStripMenuItem14, mnuSetOffsetIncrement, mnuSetRotationIncrement, toolStripMenuItem15, mnuToolsMachineConfig, mnuToolsOptions }); + mnuTools.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { mnuToolsMeasureArea, mnuToolsBestFitViewer, mnuToolsPatternTile, mnuToolsExpandSpacing, mnuToolsAlign, toolStripMenuItem14, mnuSetOffsetIncrement, mnuSetRotationIncrement, toolStripMenuItem15, mnuToolsMachineConfig, mnuToolsNestDefaults, mnuToolsSaveCurrentAsDefaults, mnuToolsOptions }); mnuTools.Name = "mnuTools"; mnuTools.Size = new System.Drawing.Size(47, 20); mnuTools.Text = "&Tools"; @@ -559,6 +561,20 @@ mnuToolsMachineConfig.Text = "Machine Configuration..."; mnuToolsMachineConfig.Click += MachineConfig_Click; // + // mnuToolsNestDefaults + // + mnuToolsNestDefaults.Name = "mnuToolsNestDefaults"; + mnuToolsNestDefaults.Size = new System.Drawing.Size(214, 22); + mnuToolsNestDefaults.Text = "Nest Defaults..."; + mnuToolsNestDefaults.Click += NestDefaults_Click; + // + // mnuToolsSaveCurrentAsDefaults + // + mnuToolsSaveCurrentAsDefaults.Name = "mnuToolsSaveCurrentAsDefaults"; + mnuToolsSaveCurrentAsDefaults.Size = new System.Drawing.Size(214, 22); + mnuToolsSaveCurrentAsDefaults.Text = "Save Current Plate as Defaults"; + mnuToolsSaveCurrentAsDefaults.Click += SaveCurrentAsDefaults_Click; + // // mnuToolsOptions // mnuToolsOptions.Name = "mnuToolsOptions"; @@ -1225,6 +1241,8 @@ private System.Windows.Forms.ToolStripSeparator toolStripMenuItem5; private System.Windows.Forms.ToolStripMenuItem mnuTools; private System.Windows.Forms.ToolStripMenuItem mnuToolsMachineConfig; + private System.Windows.Forms.ToolStripMenuItem mnuToolsNestDefaults; + private System.Windows.Forms.ToolStripMenuItem mnuToolsSaveCurrentAsDefaults; private System.Windows.Forms.ToolStripMenuItem mnuToolsOptions; private System.Windows.Forms.ToolStripMenuItem mnuNest; private System.Windows.Forms.ToolStripMenuItem mnuNestEdit; diff --git a/OpenNest/Forms/MainForm.cs b/OpenNest/Forms/MainForm.cs index 934d1f8..46da9c4 100644 --- a/OpenNest/Forms/MainForm.cs +++ b/OpenNest/Forms/MainForm.cs @@ -90,14 +90,38 @@ namespace OpenNest.Forms private Nest CreateDefaultNest() { var nest = new Nest(); - nest.Units = Properties.Settings.Default.DefaultUnit; - nest.PlateDefaults.EdgeSpacing = new Spacing(1, 1, 1, 1); - nest.PlateDefaults.PartSpacing = 1; - nest.PlateDefaults.Size = new OpenNest.Geometry.Size(100, 100); - nest.PlateDefaults.Quadrant = 1; + LoadNestDefaults().ApplyTo(nest); return nest; } + /// + /// Loads the persisted nest defaults. When no usable file exists, + /// units come from the legacy DefaultUnit setting; a corrupt file + /// warns once per session. + /// + private NestDefaults LoadNestDefaults() + { + var defaults = NestDefaults.Load(NestDefaults.DefaultPath, out var status); + if (status == NestDefaultsStatus.Ok) + return defaults; + + defaults.Units = Properties.Settings.Default.DefaultUnit; + + if (status == NestDefaultsStatus.Invalid && !defaultsWarned) + { + defaultsWarned = true; + MessageBox.Show( + $"The nest defaults file could not be read:\n{NestDefaults.DefaultPath}\n\nBuilt-in defaults will be used. Re-save your defaults from Tools > Nest Defaults.", + "Nest Defaults", + MessageBoxButtons.OK, + MessageBoxIcon.Warning + ); + } + return defaults; + } + + private bool defaultsWarned; + private string GetNestName(DateTime date, int id) { var year = (date.Year % 100).ToString("D2"); @@ -185,6 +209,7 @@ namespace OpenNest.Forms mnuToolsAlign.Visible = hasValue; mnuToolsMeasureArea.Visible = hasValue; mnuToolsExpandSpacing.Visible = hasValue; + mnuToolsSaveCurrentAsDefaults.Visible = hasValue; toolStripMenuItem14.Visible = hasValue; mnuSetOffsetIncrement.Visible = hasValue; @@ -454,10 +479,52 @@ namespace OpenNest.Forms { base.OnLoad(e); + MigrateNestTemplate(); + if (Settings.Default.CreateNewNestOnOpen) New_Click(this, new EventArgs()); } + /// + /// One-time upgrade: converts a legacy .nstdot nest template + /// (NestTemplatePath setting) into defaults.json, then clears the + /// setting so the template mechanism is never consulted again. + /// + private void MigrateNestTemplate() + { + var templatePath = Settings.Default.NestTemplatePath; + if (string.IsNullOrWhiteSpace(templatePath)) + return; + + // A failed conversion keeps the setting populated so the user + // can still find their template file. + var converted = true; + if (File.Exists(templatePath) && !File.Exists(NestDefaults.DefaultPath)) + { + try + { + var nest = new NestReader(templatePath).Read(); + NestDefaults.FromNest(nest).Save(NestDefaults.DefaultPath); + } + catch (Exception ex) + { + converted = false; + MessageBox.Show( + $"The nest template could not be converted to the new defaults file:\n{templatePath}\n\n{ex.Message}\n\nIt will no longer be loaded automatically. Set defaults under Tools > Nest Defaults.", + "Nest Template", + MessageBoxButtons.OK, + MessageBoxIcon.Warning + ); + } + } + + if (!converted) + return; + + Settings.Default.NestTemplatePath = ""; + Settings.Default.Save(); + } + protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { base.OnClosing(e); @@ -473,30 +540,7 @@ namespace OpenNest.Forms var windowState = ActiveMdiChild != null ? ActiveMdiChild.WindowState : FormWindowState.Maximized; - Nest nest; - - if (File.Exists(Properties.Settings.Default.NestTemplatePath)) - { - try - { - var reader = new NestReader(Properties.Settings.Default.NestTemplatePath); - nest = reader.Read(); - } - catch (Exception ex) - { - MessageBox.Show( - $"Failed to load nest template:\n{ex.Message}\n\nA default nest will be created instead.", - "Template Error", - MessageBoxButtons.OK, - MessageBoxIcon.Warning - ); - nest = CreateDefaultNest(); - } - } - else - { - nest = CreateDefaultNest(); - } + var nest = CreateDefaultNest(); nest.DateCreated = DateTime.Now; nest.DateLastModified = DateTime.Now; @@ -834,6 +878,25 @@ namespace OpenNest.Forms form.ShowDialog(); } + private void NestDefaults_Click(object sender, EventArgs e) + { + using (var form = new NestDefaultsForm(NestDefaults.Load(NestDefaults.DefaultPath))) + { + if (form.ShowDialog(this) == DialogResult.OK) + form.GetDefaults().Save(NestDefaults.DefaultPath); + } + } + + private void SaveCurrentAsDefaults_Click(object sender, EventArgs e) + { + if (activeForm == null) + return; + + NestDefaults + .FromPlate(activeForm.Nest.Units, activeForm.PlateView.Plate) + .Save(NestDefaults.DefaultPath); + } + private void MachineConfig_Click(object sender, EventArgs e) { var appDataPath = Path.Combine( diff --git a/OpenNest/Forms/NestDefaultsForm.Designer.cs b/OpenNest/Forms/NestDefaultsForm.Designer.cs new file mode 100644 index 0000000..da64459 --- /dev/null +++ b/OpenNest/Forms/NestDefaultsForm.Designer.cs @@ -0,0 +1,364 @@ +namespace OpenNest.Forms +{ + partial class NestDefaultsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.unitsLabel = new System.Windows.Forms.Label(); + this.unitsCombo = new System.Windows.Forms.ComboBox(); + this.widthLabel = new System.Windows.Forms.Label(); + this.widthBox = new OpenNest.Controls.NumericUpDown(); + this.lengthLabel = new System.Windows.Forms.Label(); + this.lengthBox = new OpenNest.Controls.NumericUpDown(); + this.partSpacingLabel = new System.Windows.Forms.Label(); + this.partSpacingBox = new OpenNest.Controls.NumericUpDown(); + this.edgeLeftLabel = new System.Windows.Forms.Label(); + this.edgeLeftBox = new OpenNest.Controls.NumericUpDown(); + this.edgeBottomLabel = new System.Windows.Forms.Label(); + this.edgeBottomBox = new OpenNest.Controls.NumericUpDown(); + this.edgeRightLabel = new System.Windows.Forms.Label(); + this.edgeRightBox = new OpenNest.Controls.NumericUpDown(); + this.edgeTopLabel = new System.Windows.Forms.Label(); + this.edgeTopBox = new OpenNest.Controls.NumericUpDown(); + this.quadrantLabel = new System.Windows.Forms.Label(); + this.quadrantSelect1 = new OpenNest.Controls.QuadrantSelect(); + this.saveButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.widthBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.lengthBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.partSpacingBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeLeftBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeBottomBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeRightBox)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeTopBox)).BeginInit(); + this.tableLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 2; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.Controls.Add(this.unitsLabel, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.unitsCombo, 1, 0); + this.tableLayoutPanel1.Controls.Add(this.widthLabel, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.widthBox, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.lengthLabel, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.lengthBox, 1, 2); + this.tableLayoutPanel1.Controls.Add(this.partSpacingLabel, 0, 3); + this.tableLayoutPanel1.Controls.Add(this.partSpacingBox, 1, 3); + this.tableLayoutPanel1.Controls.Add(this.edgeLeftLabel, 0, 4); + this.tableLayoutPanel1.Controls.Add(this.edgeLeftBox, 1, 4); + this.tableLayoutPanel1.Controls.Add(this.edgeBottomLabel, 0, 5); + this.tableLayoutPanel1.Controls.Add(this.edgeBottomBox, 1, 5); + this.tableLayoutPanel1.Controls.Add(this.edgeRightLabel, 0, 6); + this.tableLayoutPanel1.Controls.Add(this.edgeRightBox, 1, 6); + this.tableLayoutPanel1.Controls.Add(this.edgeTopLabel, 0, 7); + this.tableLayoutPanel1.Controls.Add(this.edgeTopBox, 1, 7); + this.tableLayoutPanel1.Controls.Add(this.quadrantLabel, 0, 8); + this.tableLayoutPanel1.Controls.Add(this.quadrantSelect1, 1, 8); + this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 9; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 11.11111F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(410, 260); + this.tableLayoutPanel1.TabIndex = 0; + // + // unitsLabel + // + this.unitsLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.unitsLabel.AutoSize = true; + this.unitsLabel.Location = new System.Drawing.Point(3, 9); + this.unitsLabel.Name = "unitsLabel"; + this.unitsLabel.Size = new System.Drawing.Size(100, 16); + this.unitsLabel.TabIndex = 0; + this.unitsLabel.Text = "Units:"; + // + // unitsCombo + // + this.unitsCombo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.unitsCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.unitsCombo.Items.AddRange(new object[] { "Inches", "Millimeters" }); + this.unitsCombo.Location = new System.Drawing.Point(109, 5); + this.unitsCombo.Name = "unitsCombo"; + this.unitsCombo.Size = new System.Drawing.Size(298, 24); + this.unitsCombo.TabIndex = 1; + // + // widthLabel + // + this.widthLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.widthLabel.AutoSize = true; + this.widthLabel.Location = new System.Drawing.Point(3, 37); + this.widthLabel.Name = "widthLabel"; + this.widthLabel.Size = new System.Drawing.Size(100, 16); + this.widthLabel.TabIndex = 2; + this.widthLabel.Text = "Plate width:"; + // + // widthBox + // + this.widthBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.widthBox.DecimalPlaces = 4; + this.widthBox.Location = new System.Drawing.Point(109, 33); + this.widthBox.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + this.widthBox.Minimum = new decimal(new int[] { 1, 0, 0, 196608 }); + this.widthBox.Name = "widthBox"; + this.widthBox.Size = new System.Drawing.Size(298, 22); + this.widthBox.Suffix = ""; + this.widthBox.TabIndex = 3; + // + // lengthLabel + // + this.lengthLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.lengthLabel.AutoSize = true; + this.lengthLabel.Location = new System.Drawing.Point(3, 65); + this.lengthLabel.Name = "lengthLabel"; + this.lengthLabel.Size = new System.Drawing.Size(100, 16); + this.lengthLabel.TabIndex = 4; + this.lengthLabel.Text = "Plate length:"; + // + // lengthBox + // + this.lengthBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.lengthBox.DecimalPlaces = 4; + this.lengthBox.Location = new System.Drawing.Point(109, 61); + this.lengthBox.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + this.lengthBox.Minimum = new decimal(new int[] { 1, 0, 0, 196608 }); + this.lengthBox.Name = "lengthBox"; + this.lengthBox.Size = new System.Drawing.Size(298, 22); + this.lengthBox.Suffix = ""; + this.lengthBox.TabIndex = 5; + // + // partSpacingLabel + // + this.partSpacingLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.partSpacingLabel.AutoSize = true; + this.partSpacingLabel.Location = new System.Drawing.Point(3, 93); + this.partSpacingLabel.Name = "partSpacingLabel"; + this.partSpacingLabel.Size = new System.Drawing.Size(100, 16); + this.partSpacingLabel.TabIndex = 6; + this.partSpacingLabel.Text = "Part spacing:"; + // + // partSpacingBox + // + this.partSpacingBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.partSpacingBox.DecimalPlaces = 4; + this.partSpacingBox.Location = new System.Drawing.Point(109, 89); + this.partSpacingBox.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + this.partSpacingBox.Name = "partSpacingBox"; + this.partSpacingBox.Size = new System.Drawing.Size(298, 22); + this.partSpacingBox.Suffix = ""; + this.partSpacingBox.TabIndex = 7; + // + // edgeLeftLabel + // + this.edgeLeftLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeLeftLabel.AutoSize = true; + this.edgeLeftLabel.Location = new System.Drawing.Point(3, 121); + this.edgeLeftLabel.Name = "edgeLeftLabel"; + this.edgeLeftLabel.Size = new System.Drawing.Size(100, 16); + this.edgeLeftLabel.TabIndex = 8; + this.edgeLeftLabel.Text = "Edge left:"; + // + // edgeLeftBox + // + this.edgeLeftBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeLeftBox.DecimalPlaces = 4; + this.edgeLeftBox.Location = new System.Drawing.Point(109, 117); + this.edgeLeftBox.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + this.edgeLeftBox.Name = "edgeLeftBox"; + this.edgeLeftBox.Size = new System.Drawing.Size(298, 22); + this.edgeLeftBox.Suffix = ""; + this.edgeLeftBox.TabIndex = 9; + // + // edgeBottomLabel + // + this.edgeBottomLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeBottomLabel.AutoSize = true; + this.edgeBottomLabel.Location = new System.Drawing.Point(3, 149); + this.edgeBottomLabel.Name = "edgeBottomLabel"; + this.edgeBottomLabel.Size = new System.Drawing.Size(100, 16); + this.edgeBottomLabel.TabIndex = 10; + this.edgeBottomLabel.Text = "Edge bottom:"; + // + // edgeBottomBox + // + this.edgeBottomBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeBottomBox.DecimalPlaces = 4; + this.edgeBottomBox.Location = new System.Drawing.Point(109, 145); + this.edgeBottomBox.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + this.edgeBottomBox.Name = "edgeBottomBox"; + this.edgeBottomBox.Size = new System.Drawing.Size(298, 22); + this.edgeBottomBox.Suffix = ""; + this.edgeBottomBox.TabIndex = 11; + // + // edgeRightLabel + // + this.edgeRightLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeRightLabel.AutoSize = true; + this.edgeRightLabel.Location = new System.Drawing.Point(3, 177); + this.edgeRightLabel.Name = "edgeRightLabel"; + this.edgeRightLabel.Size = new System.Drawing.Size(100, 16); + this.edgeRightLabel.TabIndex = 12; + this.edgeRightLabel.Text = "Edge right:"; + // + // edgeRightBox + // + this.edgeRightBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeRightBox.DecimalPlaces = 4; + this.edgeRightBox.Location = new System.Drawing.Point(109, 173); + this.edgeRightBox.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + this.edgeRightBox.Name = "edgeRightBox"; + this.edgeRightBox.Size = new System.Drawing.Size(298, 22); + this.edgeRightBox.Suffix = ""; + this.edgeRightBox.TabIndex = 13; + // + // edgeTopLabel + // + this.edgeTopLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeTopLabel.AutoSize = true; + this.edgeTopLabel.Location = new System.Drawing.Point(3, 205); + this.edgeTopLabel.Name = "edgeTopLabel"; + this.edgeTopLabel.Size = new System.Drawing.Size(100, 16); + this.edgeTopLabel.TabIndex = 14; + this.edgeTopLabel.Text = "Edge top:"; + // + // edgeTopBox + // + this.edgeTopBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.edgeTopBox.DecimalPlaces = 4; + this.edgeTopBox.Location = new System.Drawing.Point(109, 201); + this.edgeTopBox.Maximum = new decimal(new int[] { 1000000, 0, 0, 0 }); + this.edgeTopBox.Name = "edgeTopBox"; + this.edgeTopBox.Size = new System.Drawing.Size(298, 22); + this.edgeTopBox.Suffix = ""; + this.edgeTopBox.TabIndex = 15; + // + // quadrantLabel + // + this.quadrantLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.quadrantLabel.AutoSize = true; + this.quadrantLabel.Location = new System.Drawing.Point(3, 233); + this.quadrantLabel.Name = "quadrantLabel"; + this.quadrantLabel.Size = new System.Drawing.Size(100, 16); + this.quadrantLabel.TabIndex = 16; + this.quadrantLabel.Text = "Quadrant:"; + // + // quadrantSelect1 + // + this.quadrantSelect1.Anchor = System.Windows.Forms.AnchorStyles.None; + this.quadrantSelect1.BackColor = System.Drawing.Color.White; + this.quadrantSelect1.Location = new System.Drawing.Point(198, 225); + this.quadrantSelect1.Name = "quadrantSelect1"; + this.quadrantSelect1.Quadrant = 1; + this.quadrantSelect1.Size = new System.Drawing.Size(120, 28); + this.quadrantSelect1.TabIndex = 17; + // + // saveButton + // + this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.saveButton.DialogResult = System.Windows.Forms.DialogResult.OK; + this.saveButton.Location = new System.Drawing.Point(243, 285); + this.saveButton.Name = "saveButton"; + this.saveButton.Size = new System.Drawing.Size(90, 28); + this.saveButton.TabIndex = 1; + this.saveButton.Text = "Save"; + this.saveButton.UseVisualStyleBackColor = true; + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(339, 285); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(90, 28); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // NestDefaultsForm + // + this.AcceptButton = this.saveButton; + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.CancelButton = this.cancelButton; + this.ClientSize = new System.Drawing.Size(434, 322); + this.Controls.Add(this.tableLayoutPanel1); + this.Controls.Add(this.saveButton); + this.Controls.Add(this.cancelButton); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "NestDefaultsForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Nest Defaults"; + ((System.ComponentModel.ISupportInitialize)(this.widthBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.lengthBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.partSpacingBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeLeftBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeBottomBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeRightBox)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.edgeTopBox)).EndInit(); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Label unitsLabel; + private System.Windows.Forms.ComboBox unitsCombo; + private System.Windows.Forms.Label widthLabel; + private OpenNest.Controls.NumericUpDown widthBox; + private System.Windows.Forms.Label lengthLabel; + private OpenNest.Controls.NumericUpDown lengthBox; + private System.Windows.Forms.Label partSpacingLabel; + private OpenNest.Controls.NumericUpDown partSpacingBox; + private System.Windows.Forms.Label edgeLeftLabel; + private OpenNest.Controls.NumericUpDown edgeLeftBox; + private System.Windows.Forms.Label edgeBottomLabel; + private OpenNest.Controls.NumericUpDown edgeBottomBox; + private System.Windows.Forms.Label edgeRightLabel; + private OpenNest.Controls.NumericUpDown edgeRightBox; + private System.Windows.Forms.Label edgeTopLabel; + private OpenNest.Controls.NumericUpDown edgeTopBox; + private System.Windows.Forms.Label quadrantLabel; + private OpenNest.Controls.QuadrantSelect quadrantSelect1; + private System.Windows.Forms.Button saveButton; + private System.Windows.Forms.Button cancelButton; + } +} diff --git a/OpenNest/Forms/NestDefaultsForm.cs b/OpenNest/Forms/NestDefaultsForm.cs new file mode 100644 index 0000000..52955ed --- /dev/null +++ b/OpenNest/Forms/NestDefaultsForm.cs @@ -0,0 +1,62 @@ +using System; +using System.Windows.Forms; +using OpenNest.Data; +using OpenNest.Geometry; + +namespace OpenNest.Forms +{ + /// + /// Edits the persisted nest defaults (Tools > Nest Defaults), written + /// to the JSON file used when creating a new nest. + /// + public partial class NestDefaultsForm : Form + { + public NestDefaultsForm(NestDefaults defaults) + { + InitializeComponent(); + + unitsCombo.SelectedIndex = defaults.Units == Units.Millimeters ? 1 : 0; + widthBox.Value = Clamp(widthBox, defaults.Size.Width); + lengthBox.Value = Clamp(lengthBox, defaults.Size.Length); + partSpacingBox.Value = Clamp(partSpacingBox, defaults.PartSpacing); + edgeLeftBox.Value = Clamp(edgeLeftBox, defaults.EdgeSpacing.Left); + edgeBottomBox.Value = Clamp(edgeBottomBox, defaults.EdgeSpacing.Bottom); + edgeRightBox.Value = Clamp(edgeRightBox, defaults.EdgeSpacing.Right); + edgeTopBox.Value = Clamp(edgeTopBox, defaults.EdgeSpacing.Top); + quadrantSelect1.Quadrant = defaults.Quadrant; + } + + public Units Units => unitsCombo.SelectedIndex == 1 ? Units.Millimeters : Units.Inches; + + public NestDefaults GetDefaults() + { + return new NestDefaults + { + Units = Units, + Size = new Size((double)widthBox.Value, (double)lengthBox.Value), + Quadrant = quadrantSelect1.Quadrant, + PartSpacing = (double)partSpacingBox.Value, + EdgeSpacing = new Spacing( + (double)edgeLeftBox.Value, + (double)edgeBottomBox.Value, + (double)edgeRightBox.Value, + (double)edgeTopBox.Value + ), + }; + } + + private static decimal Clamp(NumericUpDown box, double value) + { + if (double.IsNaN(value) || double.IsInfinity(value)) + return box.Minimum; + + if (value < (double)box.Minimum) + return box.Minimum; + + if (value > (double)box.Maximum) + return box.Maximum; + + return (decimal)value; + } + } +} diff --git a/OpenNest/Forms/OptionsForm.Designer.cs b/OpenNest/Forms/OptionsForm.Designer.cs index 58c0fec..3425726 100644 --- a/OpenNest/Forms/OptionsForm.Designer.cs +++ b/OpenNest/Forms/OptionsForm.Designer.cs @@ -34,9 +34,6 @@ this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.numericUpDown1 = new OpenNest.Controls.NumericUpDown(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.label3 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); this.saveButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button(); this.bottomPanel1 = new OpenNest.Controls.BottomPanel(); @@ -94,55 +91,20 @@ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 297F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F)); - this.tableLayoutPanel1.Controls.Add(this.label1, 0, 1); - this.tableLayoutPanel1.Controls.Add(this.textBox1, 1, 0); - this.tableLayoutPanel1.Controls.Add(this.label3, 0, 0); - this.tableLayoutPanel1.Controls.Add(this.colorSchemeLabel, 0, 2); - this.tableLayoutPanel1.Controls.Add(this.colorSchemeCombo, 1, 2); - this.tableLayoutPanel1.Controls.Add(this.checkBox1, 0, 3); - this.tableLayoutPanel1.Controls.Add(this.numericUpDown1, 1, 1); - this.tableLayoutPanel1.Controls.Add(this.button1, 3, 0); + this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.colorSchemeLabel, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.colorSchemeCombo, 1, 1); + this.tableLayoutPanel1.Controls.Add(this.checkBox1, 0, 2); + this.tableLayoutPanel1.Controls.Add(this.numericUpDown1, 1, 0); this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 4; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F)); + this.tableLayoutPanel1.RowCount = 3; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 33.33333F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(684, 160); this.tableLayoutPanel1.TabIndex = 0; // - // textBox1 - // - this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); - this.tableLayoutPanel1.SetColumnSpan(this.textBox1, 2); - this.textBox1.Location = new System.Drawing.Point(154, 9); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(427, 22); - this.textBox1.TabIndex = 1; - // - // label3 - // - this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(3, 12); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(145, 16); - this.label3.TabIndex = 0; - this.label3.Text = "Nest Template Path:"; - // - // button1 - // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); - this.button1.Location = new System.Drawing.Point(588, 6); - this.button1.Margin = new System.Windows.Forms.Padding(4); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(92, 28); - this.button1.TabIndex = 2; - this.button1.Text = "Browse..."; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.BrowseNestTemplatePath_Click); - // // saveButton // this.saveButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); @@ -258,9 +220,6 @@ private System.Windows.Forms.ToolTip toolTip1; private Controls.BottomPanel bottomPanel1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.TextBox textBox1; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Button button1; private System.Windows.Forms.DataGridView strategyGrid; private System.Windows.Forms.GroupBox strategyGroupBox; private System.Windows.Forms.Label colorSchemeLabel; diff --git a/OpenNest/Forms/OptionsForm.cs b/OpenNest/Forms/OptionsForm.cs index 5d991d0..1ea4579 100644 --- a/OpenNest/Forms/OptionsForm.cs +++ b/OpenNest/Forms/OptionsForm.cs @@ -72,7 +72,6 @@ namespace OpenNest.Forms private void LoadSettings() { - textBox1.Text = Settings.Default.NestTemplatePath; checkBox1.Checked = Settings.Default.CreateNewNestOnOpen; numericUpDown1.Value = (decimal)Settings.Default.AutoSizePlateFactor; @@ -92,7 +91,6 @@ namespace OpenNest.Forms private void SaveSettings() { - Settings.Default.NestTemplatePath = textBox1.Text; Settings.Default.CreateNewNestOnOpen = checkBox1.Checked; Settings.Default.AutoSizePlateFactor = (double)numericUpDown1.Value; Settings.Default.ActiveColorScheme = @@ -144,14 +142,5 @@ namespace OpenNest.Forms { SaveSettings(); } - - private void BrowseNestTemplatePath_Click(object sender, EventArgs e) - { - var dlg = new OpenFileDialog(); - dlg.Filter = "Template File|*.nstdot"; - - if (dlg.ShowDialog() == DialogResult.OK) - textBox1.Text = dlg.FileName; - } } } diff --git a/OpenNest/Properties/Settings.Designer.cs b/OpenNest/Properties/Settings.Designer.cs index cbcb9d1..c9ca0ac 100644 --- a/OpenNest/Properties/Settings.Designer.cs +++ b/OpenNest/Properties/Settings.Designer.cs @@ -158,6 +158,8 @@ namespace OpenNest.Properties { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("")] + // Legacy .nstdot nest-template path. No longer read by the app + // except by the one-time migration to defaults.json in MainForm. public string NestTemplatePath { get { return ((string)(this["NestTemplatePath"]));