Restructured files
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CutToLength
|
||||
namespace CutToLength.Controls
|
||||
{
|
||||
class BinLayoutView : Control
|
||||
{
|
||||
@@ -53,33 +53,36 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ArchUnits.cs" />
|
||||
<Compile Include="BestFitEngine.cs" />
|
||||
<Compile Include="Nesting\BestFitEngine.cs" />
|
||||
<Compile Include="Bin.cs" />
|
||||
<Compile Include="BinItem.cs" />
|
||||
<Compile Include="BinLayoutView.cs">
|
||||
<Compile Include="Controls\BinLayoutView.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Fraction.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<Compile Include="Forms\MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainForm.Designer.cs">
|
||||
<Compile Include="Forms\MainForm.Designer.cs">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ResultsForm.cs">
|
||||
<Compile Include="Forms\ResultsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ResultsForm.Designer.cs">
|
||||
<Compile Include="Forms\ResultsForm.Designer.cs">
|
||||
<DependentUpon>ResultsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Nesting\Engine2.cs" />
|
||||
<Compile Include="Nesting\IEngine.cs" />
|
||||
<Compile Include="Nesting\Result.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tool.cs" />
|
||||
<Compile Include="UIItem.cs" />
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
<EmbeddedResource Include="Forms\MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="ResultsForm.resx">
|
||||
<EmbeddedResource Include="Forms\ResultsForm.resx">
|
||||
<DependentUpon>ResultsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
@@ -106,7 +109,7 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Content Include="Tools.json">
|
||||
<Content Include="Data\Tools.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace CutToLength
|
||||
namespace CutToLength.Forms
|
||||
{
|
||||
partial class MainForm
|
||||
{
|
||||
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using CutToLength.Nesting;
|
||||
using Newtonsoft.Json;
|
||||
using SimpleExpressionEvaluator;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,7 +10,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CutToLength
|
||||
namespace CutToLength.Forms
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
@@ -246,7 +247,7 @@ namespace CutToLength
|
||||
|
||||
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()
|
||||
@@ -1,38 +1,38 @@
|
||||
namespace CutToLength
|
||||
namespace CutToLength.Forms
|
||||
{
|
||||
partial class ResultsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
partial class ResultsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
||||
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.uIItemBindingSource = new System.Windows.Forms.BindingSource(this.components);
|
||||
this.spacingDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
@@ -79,14 +79,14 @@
|
||||
//
|
||||
// class11
|
||||
//
|
||||
this.class11.BackColor = System.Drawing.Color.White;
|
||||
this.class11.Bin = null;
|
||||
this.class11.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.class11.Location = new System.Drawing.Point(0, 0);
|
||||
this.class11.Name = "class11";
|
||||
this.class11.Size = new System.Drawing.Size(892, 181);
|
||||
this.class11.TabIndex = 1;
|
||||
this.class11.Text = "class11";
|
||||
this.binLayoutView1.BackColor = System.Drawing.Color.White;
|
||||
this.binLayoutView1.Bin = null;
|
||||
this.binLayoutView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.binLayoutView1.Location = new System.Drawing.Point(0, 0);
|
||||
this.binLayoutView1.Name = "class11";
|
||||
this.binLayoutView1.Size = new System.Drawing.Size(892, 181);
|
||||
this.binLayoutView1.TabIndex = 1;
|
||||
this.binLayoutView1.Text = "class11";
|
||||
//
|
||||
// splitContainer1
|
||||
//
|
||||
@@ -102,7 +102,7 @@
|
||||
//
|
||||
// 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.SplitterDistance = 256;
|
||||
this.splitContainer1.TabIndex = 2;
|
||||
@@ -167,15 +167,15 @@
|
||||
((System.ComponentModel.ISupportInitialize)(this.uIItemBindingSource)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataGridView dataGridView1;
|
||||
private BinLayoutView class11;
|
||||
private System.Windows.Forms.BindingSource binBindingSource;
|
||||
private System.Windows.Forms.SplitContainer splitContainer1;
|
||||
private System.Windows.Forms.BindingSource uIItemBindingSource;
|
||||
private System.Windows.Forms.DataGridView dataGridView1;
|
||||
private Controls.BinLayoutView binLayoutView1;
|
||||
private System.Windows.Forms.BindingSource binBindingSource;
|
||||
private System.Windows.Forms.SplitContainer splitContainer1;
|
||||
private System.Windows.Forms.BindingSource uIItemBindingSource;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn spacingDataGridViewTextBoxColumn;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn lengthDataGridViewTextBoxColumn;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn usedLengthDataGridViewTextBoxColumn;
|
||||
@@ -8,7 +8,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace CutToLength
|
||||
namespace CutToLength.Forms
|
||||
{
|
||||
public partial class ResultsForm : Form
|
||||
{
|
||||
@@ -41,8 +41,8 @@ namespace CutToLength
|
||||
if (selectedBin == null)
|
||||
return;
|
||||
|
||||
class11.Bin = selectedBin;
|
||||
class11.Invalidate();
|
||||
binLayoutView1.Bin = selectedBin;
|
||||
binLayoutView1.Invalidate();
|
||||
}
|
||||
|
||||
public List<Bin> Bins
|
||||
91
CutToLength/Nesting/BestFitEngine.cs
Normal file
91
CutToLength/Nesting/BestFitEngine.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,92 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
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 double StockLength { get; set; }
|
||||
@@ -227,21 +143,4 @@ namespace CutToLength
|
||||
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; }
|
||||
}
|
||||
}
|
||||
9
CutToLength/Nesting/IEngine.cs
Normal file
9
CutToLength/Nesting/IEngine.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CutToLength.Nesting
|
||||
{
|
||||
public interface IEngine
|
||||
{
|
||||
Result Pack(List<BinItem> items);
|
||||
}
|
||||
}
|
||||
16
CutToLength/Nesting/Result.cs
Normal file
16
CutToLength/Nesting/Result.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace CutToLength
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MainForm());
|
||||
Application.Run(new Forms.MainForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user