diff --git a/CutList/CutList.csproj b/CutList/CutList.csproj
index eec0ded..282ca27 100644
--- a/CutList/CutList.csproj
+++ b/CutList/CutList.csproj
@@ -99,6 +99,7 @@
ResultsForm.cs
+
diff --git a/CutList/Forms/MainForm.cs b/CutList/Forms/MainForm.cs
index 9817340..7504258 100644
--- a/CutList/Forms/MainForm.cs
+++ b/CutList/Forms/MainForm.cs
@@ -9,6 +9,7 @@ using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace CutList.Forms
{
@@ -17,6 +18,7 @@ namespace CutList.Forms
private BindingList parts;
private BindingList bins;
private string documentPath;
+ private Toolbox toolbox;
public MainForm()
{
@@ -34,27 +36,8 @@ namespace CutList.Forms
binInputItemBindingSource.DataSource = bins;
binInputItemBindingSource.ListChanged += BinInputItemBindingSource_ListChanged;
- LoadTools();
- }
-
- private void LoadTools()
- {
- if (!File.Exists(ToolsFilePath))
- {
- var tools = new List
- {
- new Tool { Name = "Shear", Kerf = 0.0 },
- new Tool { Name = "Saw", Kerf = 0.125 }
- };
-
- SaveTools(tools);
-
- comboBox1.DataSource = tools;
- }
- else
- {
- comboBox1.DataSource = GetTools();
- }
+ toolbox = new Toolbox();
+ comboBox1.DataSource = toolbox.Tools;
}
private void UpdateRunButtonState()
@@ -166,19 +149,6 @@ namespace CutList.Forms
return name;
}
- private string ToolsFilePath
- {
- get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\Tools.json"); }
- }
-
- private List GetTools()
- {
- var json = File.ReadAllText(ToolsFilePath);
- var list = JsonConvert.DeserializeObject>(json);
-
- return list;
- }
-
private List GetItems()
{
var items2 = new List();
@@ -206,12 +176,6 @@ namespace CutList.Forms
return comboBox1.SelectedItem as Tool;
}
- private void SaveTools(IEnumerable tools)
- {
- var json = JsonConvert.SerializeObject(tools, Formatting.Indented);
- File.WriteAllText(ToolsFilePath, json);
- }
-
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
@@ -275,7 +239,7 @@ namespace CutList.Forms
if (tools != null)
{
- SaveTools(tools);
+ toolbox.Save();
}
}
@@ -333,9 +297,7 @@ namespace CutList.Forms
[JsonIgnore]
public string SavePath { get; set; }
- public List Tools { get; set; }
-
- public List PartsToNest { get; set; }
+ public List PartsToNest { get; set; }
public List StockBins { get; set; }
}
diff --git a/CutList/Forms/Toolbox.cs b/CutList/Forms/Toolbox.cs
new file mode 100644
index 0000000..99d896f
--- /dev/null
+++ b/CutList/Forms/Toolbox.cs
@@ -0,0 +1,71 @@
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace CutList.Forms
+{
+ public class Toolbox
+ {
+ public Toolbox()
+ {
+ Load();
+ }
+
+ public List Tools { get; set; }
+
+ public string ToolsFilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\Tools.json");
+
+ private void LoadDefaultTools()
+ {
+ Tools = new List
+ {
+ new Tool { Name = "Shear", Kerf = 0.0 },
+ new Tool { Name = "Saw", Kerf = 0.125 },
+ new Tool { Name = "Channel Muncher", Kerf = 0.5 },
+ new Tool { Name = "Custom", Kerf = 1, AllowUserToChange = true }
+ };
+ }
+
+ ///
+ /// Loads the tool list from the file at ToolsFilePath
+ ///
+ public void Load()
+ {
+ try
+ {
+ if (!File.Exists(ToolsFilePath))
+ {
+ LoadDefaultTools();
+ Save();
+ }
+ else
+ {
+ var json = File.ReadAllText(ToolsFilePath);
+ var list = JsonConvert.DeserializeObject>(json);
+ Tools = list;
+ }
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+ }
+
+ public void Save()
+ {
+ try
+ {
+ if (Tools == null)
+ return;
+
+ var json = JsonConvert.SerializeObject(Tools, Formatting.Indented);
+ File.WriteAllText(ToolsFilePath, json);
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/CutList/Models/BinInputItem.cs b/CutList/Models/BinInputItem.cs
index 7939885..b5418b9 100644
--- a/CutList/Models/BinInputItem.cs
+++ b/CutList/Models/BinInputItem.cs
@@ -1,8 +1,4 @@
-using Newtonsoft.Json;
-using SawCut;
-using System;
-
-namespace CutList.Models
+namespace CutList.Models
{
public class BinInputItem : LengthItem
{
diff --git a/SawCut/Bin.cs b/SawCut/Bin.cs
index 5b92404..6581cdf 100644
--- a/SawCut/Bin.cs
+++ b/SawCut/Bin.cs
@@ -42,7 +42,7 @@ namespace SawCut
///
public double Utilization
{
- get { return UsedLength / Length; }
+ get { return UsedLength / Length; }
}
public override string ToString()