Added Toolbox to manage tools
This commit is contained in:
@@ -99,6 +99,7 @@
|
||||
<Compile Include="Forms\ResultsForm.Designer.cs">
|
||||
<DependentUpon>ResultsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Forms\Toolbox.cs" />
|
||||
<Compile Include="Helper.cs" />
|
||||
<Compile Include="Models\BinInputItem.cs" />
|
||||
<Compile Include="Models\LengthItem.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<PartInputItem> parts;
|
||||
private BindingList<BinInputItem> 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<Tool>
|
||||
{
|
||||
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<Tool> GetTools()
|
||||
{
|
||||
var json = File.ReadAllText(ToolsFilePath);
|
||||
var list = JsonConvert.DeserializeObject<List<Tool>>(json);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<BinItem> GetItems()
|
||||
{
|
||||
var items2 = new List<BinItem>();
|
||||
@@ -206,12 +176,6 @@ namespace CutList.Forms
|
||||
return comboBox1.SelectedItem as Tool;
|
||||
}
|
||||
|
||||
private void SaveTools(IEnumerable<Tool> 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,8 +297,6 @@ namespace CutList.Forms
|
||||
[JsonIgnore]
|
||||
public string SavePath { get; set; }
|
||||
|
||||
public List<Tool> Tools { get; set; }
|
||||
|
||||
public List<PartInputItem> PartsToNest { get; set; }
|
||||
|
||||
public List<BinInputItem> StockBins { get; set; }
|
||||
|
||||
71
CutList/Forms/Toolbox.cs
Normal file
71
CutList/Forms/Toolbox.cs
Normal file
@@ -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<Tool> Tools { get; set; }
|
||||
|
||||
public string ToolsFilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\Tools.json");
|
||||
|
||||
private void LoadDefaultTools()
|
||||
{
|
||||
Tools = new List<Tool>
|
||||
{
|
||||
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 }
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the tool list from the file at ToolsFilePath
|
||||
/// </summary>
|
||||
public void Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(ToolsFilePath))
|
||||
{
|
||||
LoadDefaultTools();
|
||||
Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
var json = File.ReadAllText(ToolsFilePath);
|
||||
var list = JsonConvert.DeserializeObject<List<Tool>>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using SawCut;
|
||||
using System;
|
||||
|
||||
namespace CutList.Models
|
||||
namespace CutList.Models
|
||||
{
|
||||
public class BinInputItem : LengthItem
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user