Added tool selection for kerf width

This commit is contained in:
aj
2018-06-02 21:28:50 -04:00
parent e5f919a3e8
commit 0cded86d75
6 changed files with 225 additions and 80 deletions

View File

@@ -69,6 +69,7 @@
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tool.cs" />
<Compile Include="UIItem.cs" /> <Compile Include="UIItem.cs" />
<EmbeddedResource Include="MainForm.resx"> <EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
@@ -100,6 +101,9 @@
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<Content Include="Tools.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />

View File

@@ -33,26 +33,27 @@
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.lengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.quantityDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.TotalLength = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.TotalLength = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton(); this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.saveButton = new System.Windows.Forms.ToolStripButton(); this.saveButton = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.runButton = new System.Windows.Forms.ToolStripButton(); this.runButton = new System.Windows.Forms.ToolStripButton();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.lengthDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.quantityDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.itemBindingSource)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
this.toolStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.itemBindingSource)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// dataGridView1 // dataGridView1
@@ -82,46 +83,17 @@
this.dataGridView1.Size = new System.Drawing.Size(763, 361); this.dataGridView1.Size = new System.Drawing.Size(763, 361);
this.dataGridView1.TabIndex = 5; this.dataGridView1.TabIndex = 5;
// //
// nameDataGridViewTextBoxColumn
//
this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name";
this.nameDataGridViewTextBoxColumn.HeaderText = "Name";
this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";
this.nameDataGridViewTextBoxColumn.Width = 200;
//
// lengthDataGridViewTextBoxColumn
//
this.lengthDataGridViewTextBoxColumn.DataPropertyName = "Length";
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
this.lengthDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle4;
this.lengthDataGridViewTextBoxColumn.HeaderText = "Length";
this.lengthDataGridViewTextBoxColumn.Name = "lengthDataGridViewTextBoxColumn";
this.lengthDataGridViewTextBoxColumn.Width = 120;
//
// quantityDataGridViewTextBoxColumn
//
this.quantityDataGridViewTextBoxColumn.DataPropertyName = "Quantity";
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
this.quantityDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle5;
this.quantityDataGridViewTextBoxColumn.HeaderText = "Qty";
this.quantityDataGridViewTextBoxColumn.Name = "quantityDataGridViewTextBoxColumn";
this.quantityDataGridViewTextBoxColumn.Width = 50;
//
// TotalLength // TotalLength
// //
this.TotalLength.DataPropertyName = "TotalLength"; this.TotalLength.DataPropertyName = "TotalLength";
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Info; dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Info;
dataGridViewCellStyle6.Format = "N3"; dataGridViewCellStyle4.Format = "N3";
this.TotalLength.DefaultCellStyle = dataGridViewCellStyle6; this.TotalLength.DefaultCellStyle = dataGridViewCellStyle4;
this.TotalLength.HeaderText = "Total Length"; this.TotalLength.HeaderText = "Total Length";
this.TotalLength.Name = "TotalLength"; this.TotalLength.Name = "TotalLength";
this.TotalLength.ReadOnly = true; this.TotalLength.ReadOnly = true;
// //
// itemBindingSource
//
this.itemBindingSource.DataSource = typeof(CutToLength.UIItem);
//
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
@@ -161,35 +133,6 @@
0, 0,
0}); 0});
// //
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.ForeColor = System.Drawing.Color.Blue;
this.label3.Location = new System.Drawing.Point(282, 50);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(67, 17);
this.label3.TabIndex = 2;
this.label3.Text = "Cut width";
//
// numericUpDown2
//
this.numericUpDown2.DecimalPlaces = 4;
this.numericUpDown2.Location = new System.Drawing.Point(355, 48);
this.numericUpDown2.Maximum = new decimal(new int[] {
999999,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(139, 25);
this.numericUpDown2.TabIndex = 3;
this.numericUpDown2.Value = new decimal(new int[] {
125,
0,
0,
196608});
//
// toolStrip1 // toolStrip1
// //
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -244,14 +187,85 @@
this.runButton.Text = "Run"; this.runButton.Text = "Run";
this.runButton.Click += new System.EventHandler(this.runButton_Click); this.runButton.Click += new System.EventHandler(this.runButton_Click);
// //
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(409, 42);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(184, 25);
this.comboBox1.TabIndex = 8;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(409, 73);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(184, 25);
this.textBox1.TabIndex = 9;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// nameDataGridViewTextBoxColumn
//
this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name";
this.nameDataGridViewTextBoxColumn.HeaderText = "Name";
this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn";
this.nameDataGridViewTextBoxColumn.Width = 200;
//
// lengthDataGridViewTextBoxColumn
//
this.lengthDataGridViewTextBoxColumn.DataPropertyName = "Length";
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
this.lengthDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle5;
this.lengthDataGridViewTextBoxColumn.HeaderText = "Length";
this.lengthDataGridViewTextBoxColumn.Name = "lengthDataGridViewTextBoxColumn";
this.lengthDataGridViewTextBoxColumn.Width = 120;
//
// quantityDataGridViewTextBoxColumn
//
this.quantityDataGridViewTextBoxColumn.DataPropertyName = "Quantity";
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
this.quantityDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle6;
this.quantityDataGridViewTextBoxColumn.HeaderText = "Qty";
this.quantityDataGridViewTextBoxColumn.Name = "quantityDataGridViewTextBoxColumn";
this.quantityDataGridViewTextBoxColumn.Width = 50;
//
// itemBindingSource
//
this.itemBindingSource.DataSource = typeof(CutToLength.UIItem);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.ForeColor = System.Drawing.Color.Blue;
this.label3.Location = new System.Drawing.Point(322, 45);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(81, 17);
this.label3.TabIndex = 0;
this.label3.Text = "Cut method";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("Segoe UI Semibold", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.ForeColor = System.Drawing.Color.Blue;
this.label4.Location = new System.Drawing.Point(333, 76);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(70, 17);
this.label4.TabIndex = 0;
this.label4.Text = "Kerf width";
//
// MainForm // MainForm
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(787, 496); this.ClientSize = new System.Drawing.Size(787, 496);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.toolStrip1); this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.numericUpDown2);
this.Controls.Add(this.label3);
this.Controls.Add(this.numericUpDown1); this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.dataGridView1); this.Controls.Add(this.dataGridView1);
@@ -262,11 +276,10 @@
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Cut To Length"; this.Text = "Cut To Length";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.itemBindingSource)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
this.toolStrip1.ResumeLayout(false); this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout(); this.toolStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.itemBindingSource)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@@ -278,8 +291,6 @@
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.ToolStrip toolStrip1; private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton toolStripButton1; private System.Windows.Forms.ToolStripButton toolStripButton1;
private System.Windows.Forms.ToolStripButton saveButton; private System.Windows.Forms.ToolStripButton saveButton;
@@ -289,6 +300,10 @@
private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn quantityDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn quantityDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn TotalLength; private System.Windows.Forms.DataGridViewTextBoxColumn TotalLength;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
} }
} }

View File

@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
@@ -19,9 +20,25 @@ namespace CutToLength
items = new List<UIItem>(); items = new List<UIItem>();
itemBindingSource.DataSource = items; itemBindingSource.DataSource = items;
itemBindingSource.CurrentChanged += ItemBindingSource_CurrentChanged; itemBindingSource.CurrentChanged += ItemBindingSource_CurrentChanged;
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();
}
} }
protected override void OnLoad(EventArgs e) protected override void OnLoad(EventArgs e)
@@ -51,6 +68,8 @@ namespace CutToLength
{ {
var data = File.ReadAllText(openFileDialog.FileName); var data = File.ReadAllText(openFileDialog.FileName);
items = JsonConvert.DeserializeObject<List<UIItem>>(data); items = JsonConvert.DeserializeObject<List<UIItem>>(data);
dataGridView1.ClearSelection();
itemBindingSource.DataSource = items; itemBindingSource.DataSource = items;
} }
} }
@@ -133,7 +152,7 @@ namespace CutToLength
private Bin CreateBin() private Bin CreateBin()
{ {
var length = (double)numericUpDown1.Value; var length = (double)numericUpDown1.Value;
var spacing = (double)numericUpDown2.Value; var spacing = GetSelectedTool().Kerf;
return new Bin(length) return new Bin(length)
{ {
@@ -141,6 +160,11 @@ namespace CutToLength
}; };
} }
public Tool GetSelectedTool()
{
return comboBox1.SelectedItem as Tool;
}
private void SaveBins(string file, IEnumerable<Bin> bins) private void SaveBins(string file, IEnumerable<Bin> bins)
{ {
var writer = new StreamWriter(file); var writer = new StreamWriter(file);
@@ -202,5 +226,70 @@ namespace CutToLength
{ {
Run(); Run();
} }
private string ToolsFilePath
{
get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools.json"); }
}
private List<Tool> GetTools()
{
var json = File.ReadAllText(ToolsFilePath);
var list = JsonConvert.DeserializeObject<List<Tool>>(json);
return list;
}
private void SaveTools(IEnumerable<Tool> tools)
{
var json = JsonConvert.SerializeObject(tools);
File.WriteAllText(ToolsFilePath, json);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var tool = comboBox1.SelectedItem as Tool;
if (tool == null)
return;
textBox1.Text = tool.Kerf.ToString();
if (tool.AllowUserToChange)
{
textBox1.ReadOnly = false;
textBox1.BackColor = Color.White;
}
else
{
textBox1.ReadOnly = true;
textBox1.BackColor = SystemColors.Info;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
double value;
if (!double.TryParse(textBox1.Text, out value))
return;
var tool = comboBox1.SelectedItem as Tool;
if (tool == null)
return;
if (!tool.AllowUserToChange)
return;
tool.Kerf = value;
var tools = comboBox1.DataSource as List<Tool>;
if (tools != null)
{
SaveTools(tools);
}
}
} }
} }

View File

@@ -123,7 +123,13 @@
<metadata name="itemBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="itemBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="TotalLength.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>172, 17</value> <value>172, 17</value>
</metadata> </metadata>
<metadata name="itemBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>

14
CutToLength/Tool.cs Normal file
View File

@@ -0,0 +1,14 @@
namespace CutToLength
{
public class Tool
{
public string Name { get; set; }
public double Kerf { get; set; }
public bool AllowUserToChange { get; set; }
public override string ToString()
{
return Name;
}
}
}

17
CutToLength/Tools.json Normal file
View File

@@ -0,0 +1,17 @@
[
{
"Name": "Shear",
"Kerf": 0.0,
"AllowUserToChange": false
},
{
"Name": "Saw",
"Kerf": 0.125,
"AllowUserToChange": false
},
{
"Name": "Custom",
"Kerf": 0.125,
"AllowUserToChange": true
}
]