Restructured files

This commit is contained in:
AJ
2020-06-17 07:17:06 -04:00
parent b305aaa0d4
commit 6aeadc458e
14 changed files with 182 additions and 163 deletions

View File

@@ -2,7 +2,7 @@
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Windows.Forms; using System.Windows.Forms;
namespace CutToLength namespace CutToLength.Controls
{ {
class BinLayoutView : Control class BinLayoutView : Control
{ {

View File

@@ -53,33 +53,36 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ArchUnits.cs" /> <Compile Include="ArchUnits.cs" />
<Compile Include="BestFitEngine.cs" /> <Compile Include="Nesting\BestFitEngine.cs" />
<Compile Include="Bin.cs" /> <Compile Include="Bin.cs" />
<Compile Include="BinItem.cs" /> <Compile Include="BinItem.cs" />
<Compile Include="BinLayoutView.cs"> <Compile Include="Controls\BinLayoutView.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Fraction.cs" /> <Compile Include="Fraction.cs" />
<Compile Include="MainForm.cs"> <Compile Include="Forms\MainForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="MainForm.Designer.cs"> <Compile Include="Forms\MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="ResultsForm.cs"> <Compile Include="Forms\ResultsForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="ResultsForm.Designer.cs"> <Compile Include="Forms\ResultsForm.Designer.cs">
<DependentUpon>ResultsForm.cs</DependentUpon> <DependentUpon>ResultsForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Nesting\Engine2.cs" />
<Compile Include="Nesting\IEngine.cs" />
<Compile Include="Nesting\Result.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tool.cs" /> <Compile Include="Tool.cs" />
<Compile Include="UIItem.cs" /> <Compile Include="UIItem.cs" />
<EmbeddedResource Include="MainForm.resx"> <EmbeddedResource Include="Forms\MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="ResultsForm.resx"> <EmbeddedResource Include="Forms\ResultsForm.resx">
<DependentUpon>ResultsForm.cs</DependentUpon> <DependentUpon>ResultsForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
@@ -106,7 +109,7 @@
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<Content Include="Tools.json"> <Content Include="Data\Tools.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>

View File

@@ -1,4 +1,4 @@
namespace CutToLength namespace CutToLength.Forms
{ {
partial class MainForm partial class MainForm
{ {

View File

@@ -1,4 +1,5 @@
using Newtonsoft.Json; using CutToLength.Nesting;
using Newtonsoft.Json;
using SimpleExpressionEvaluator; using SimpleExpressionEvaluator;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -9,7 +10,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
namespace CutToLength namespace CutToLength.Forms
{ {
public partial class MainForm : Form public partial class MainForm : Form
{ {
@@ -246,7 +247,7 @@ namespace CutToLength
private string ToolsFilePath private string ToolsFilePath
{ {
get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools.json"); } get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data\\Tools.json"); }
} }
private List<Tool> GetTools() private List<Tool> GetTools()

View File

@@ -1,38 +1,38 @@
namespace CutToLength namespace CutToLength.Forms
{ {
partial class ResultsForm partial class ResultsForm
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) if (disposing && (components != null))
{ {
components.Dispose(); components.Dispose();
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container(); this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.binBindingSource = new System.Windows.Forms.BindingSource(this.components); this.binBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.class11 = new CutToLength.BinLayoutView(); this.binLayoutView1 = new CutToLength.Controls.BinLayoutView();
this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.uIItemBindingSource = new System.Windows.Forms.BindingSource(this.components); this.uIItemBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.spacingDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.spacingDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -79,14 +79,14 @@
// //
// class11 // class11
// //
this.class11.BackColor = System.Drawing.Color.White; this.binLayoutView1.BackColor = System.Drawing.Color.White;
this.class11.Bin = null; this.binLayoutView1.Bin = null;
this.class11.Dock = System.Windows.Forms.DockStyle.Fill; this.binLayoutView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.class11.Location = new System.Drawing.Point(0, 0); this.binLayoutView1.Location = new System.Drawing.Point(0, 0);
this.class11.Name = "class11"; this.binLayoutView1.Name = "class11";
this.class11.Size = new System.Drawing.Size(892, 181); this.binLayoutView1.Size = new System.Drawing.Size(892, 181);
this.class11.TabIndex = 1; this.binLayoutView1.TabIndex = 1;
this.class11.Text = "class11"; this.binLayoutView1.Text = "class11";
// //
// splitContainer1 // splitContainer1
// //
@@ -102,7 +102,7 @@
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.class11); this.splitContainer1.Panel2.Controls.Add(this.binLayoutView1);
this.splitContainer1.Size = new System.Drawing.Size(892, 441); this.splitContainer1.Size = new System.Drawing.Size(892, 441);
this.splitContainer1.SplitterDistance = 256; this.splitContainer1.SplitterDistance = 256;
this.splitContainer1.TabIndex = 2; this.splitContainer1.TabIndex = 2;
@@ -167,15 +167,15 @@
((System.ComponentModel.ISupportInitialize)(this.uIItemBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.uIItemBindingSource)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
#endregion #endregion
private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.DataGridView dataGridView1;
private BinLayoutView class11; private Controls.BinLayoutView binLayoutView1;
private System.Windows.Forms.BindingSource binBindingSource; private System.Windows.Forms.BindingSource binBindingSource;
private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.BindingSource uIItemBindingSource; private System.Windows.Forms.BindingSource uIItemBindingSource;
private System.Windows.Forms.DataGridViewTextBoxColumn spacingDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn spacingDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn usedLengthDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn usedLengthDataGridViewTextBoxColumn;

View File

@@ -8,7 +8,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace CutToLength namespace CutToLength.Forms
{ {
public partial class ResultsForm : Form public partial class ResultsForm : Form
{ {
@@ -41,8 +41,8 @@ namespace CutToLength
if (selectedBin == null) if (selectedBin == null)
return; return;
class11.Bin = selectedBin; binLayoutView1.Bin = selectedBin;
class11.Invalidate(); binLayoutView1.Invalidate();
} }
public List<Bin> Bins public List<Bin> Bins

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace CutToLength.Nesting
{
public class BestFitEngine : IEngine
{
public double StockLength { get; set; }
public double Spacing { get; set; }
private List<BinItem> Items { get; set; }
public Result Pack(List<BinItem> items)
{
if (StockLength <= 0)
throw new Exception("Stock length must be greater than 0");
Items = items.OrderByDescending(i => i.Length).ToList();
var result = new Result();
result.ItemsNotUsed = Items.Where(i => i.Length > StockLength).ToList();
foreach (var item in result.ItemsNotUsed)
{
Items.Remove(item);
}
result.Bins = GetBins();
return result;
}
private List<Bin> GetBins()
{
var bins = new List<Bin>();
foreach (var item in Items)
{
Bin best_bin;
if (!FindBin(bins.ToArray(), item.Length, out best_bin))
{
if (item.Length > StockLength)
continue;
best_bin = CreateBin();
bins.Add(best_bin);
}
best_bin.Items.Add(item);
}
return bins
.OrderByDescending(b => b.Utilization)
.ThenBy(b => b.Items.Count)
.ToList();
}
private Bin CreateBin()
{
var length = StockLength;
return new Bin(length)
{
Spacing = Spacing
};
}
private static bool FindBin(IEnumerable<Bin> bins, double length, out Bin found)
{
found = null;
foreach (var bin in bins)
{
if (bin.RemainingLength < length)
continue;
if (found == null)
found = bin;
if (bin.RemainingLength < found.RemainingLength)
found = bin;
}
return (found != null);
}
}
}

View File

@@ -3,92 +3,8 @@ using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
namespace CutToLength namespace CutToLength.Nesting
{ {
public class BestFitEngine : IEngine
{
public double StockLength { get; set; }
public double Spacing { get; set; }
private List<BinItem> Items { get; set; }
public Result Pack(List<BinItem> items)
{
if (StockLength <= 0)
throw new Exception("Stock length must be greater than 0");
Items = items.OrderByDescending(i => i.Length).ToList();
var result = new Result();
result.ItemsNotUsed = Items.Where(i => i.Length > StockLength).ToList();
foreach (var item in result.ItemsNotUsed)
{
Items.Remove(item);
}
result.Bins = GetBins();
return result;
}
private List<Bin> GetBins()
{
var bins = new List<Bin>();
foreach (var item in Items)
{
Bin best_bin;
if (!FindBin(bins.ToArray(), item.Length, out best_bin))
{
if (item.Length > StockLength)
continue;
best_bin = CreateBin();
bins.Add(best_bin);
}
best_bin.Items.Add(item);
}
return bins
.OrderByDescending(b => b.Utilization)
.ThenBy(b => b.Items.Count)
.ToList();
}
private Bin CreateBin()
{
var length = StockLength;
return new Bin(length)
{
Spacing = Spacing
};
}
private static bool FindBin(IEnumerable<Bin> bins, double length, out Bin found)
{
found = null;
foreach (var bin in bins)
{
if (bin.RemainingLength < length)
continue;
if (found == null)
found = bin;
if (bin.RemainingLength < found.RemainingLength)
found = bin;
}
return (found != null);
}
}
public class Engine2 : IEngine public class Engine2 : IEngine
{ {
public double StockLength { get; set; } public double StockLength { get; set; }
@@ -227,21 +143,4 @@ namespace CutToLength
return false; return false;
} }
} }
public interface IEngine
{
Result Pack(List<BinItem> items);
}
public class Result
{
public Result()
{
ItemsNotUsed = new List<BinItem>();
}
public List<BinItem> ItemsNotUsed { get; set; }
public List<Bin> Bins { get; set; }
}
} }

View File

@@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace CutToLength.Nesting
{
public interface IEngine
{
Result Pack(List<BinItem> items);
}
}

View File

@@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace CutToLength.Nesting
{
public class Result
{
public Result()
{
ItemsNotUsed = new List<BinItem>();
}
public List<BinItem> ItemsNotUsed { get; set; }
public List<Bin> Bins { get; set; }
}
}

View File

@@ -16,7 +16,7 @@ namespace CutToLength
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm()); Application.Run(new Forms.MainForm());
} }
} }
} }