From 6aeadc458e9cec76f423cea9e5674f2297e0ed5b Mon Sep 17 00:00:00 2001 From: AJ Date: Wed, 17 Jun 2020 07:17:06 -0400 Subject: [PATCH] Restructured files --- CutToLength/{ => Controls}/BinLayoutView.cs | 2 +- CutToLength/CutToLength.csproj | 21 ++-- CutToLength/{ => Data}/Tools.json | 0 CutToLength/{ => Forms}/MainForm.Designer.cs | 2 +- CutToLength/{ => Forms}/MainForm.cs | 7 +- CutToLength/{ => Forms}/MainForm.resx | 0 .../{ => Forms}/ResultsForm.Designer.cs | 86 +++++++-------- CutToLength/{ => Forms}/ResultsForm.cs | 6 +- CutToLength/{ => Forms}/ResultsForm.resx | 0 CutToLength/Nesting/BestFitEngine.cs | 91 ++++++++++++++++ .../{BestFitEngine.cs => Nesting/Engine2.cs} | 103 +----------------- CutToLength/Nesting/IEngine.cs | 9 ++ CutToLength/Nesting/Result.cs | 16 +++ CutToLength/Program.cs | 2 +- 14 files changed, 182 insertions(+), 163 deletions(-) rename CutToLength/{ => Controls}/BinLayoutView.cs (98%) rename CutToLength/{ => Data}/Tools.json (100%) rename CutToLength/{ => Forms}/MainForm.Designer.cs (99%) rename CutToLength/{ => Forms}/MainForm.cs (98%) rename CutToLength/{ => Forms}/MainForm.resx (100%) rename CutToLength/{ => Forms}/ResultsForm.Designer.cs (81%) rename CutToLength/{ => Forms}/ResultsForm.cs (92%) rename CutToLength/{ => Forms}/ResultsForm.resx (100%) create mode 100644 CutToLength/Nesting/BestFitEngine.cs rename CutToLength/{BestFitEngine.cs => Nesting/Engine2.cs} (60%) create mode 100644 CutToLength/Nesting/IEngine.cs create mode 100644 CutToLength/Nesting/Result.cs diff --git a/CutToLength/BinLayoutView.cs b/CutToLength/Controls/BinLayoutView.cs similarity index 98% rename from CutToLength/BinLayoutView.cs rename to CutToLength/Controls/BinLayoutView.cs index b88aa10..0003d95 100644 --- a/CutToLength/BinLayoutView.cs +++ b/CutToLength/Controls/BinLayoutView.cs @@ -2,7 +2,7 @@ using System.Drawing.Drawing2D; using System.Windows.Forms; -namespace CutToLength +namespace CutToLength.Controls { class BinLayoutView : Control { diff --git a/CutToLength/CutToLength.csproj b/CutToLength/CutToLength.csproj index 313a8df..371cbf9 100644 --- a/CutToLength/CutToLength.csproj +++ b/CutToLength/CutToLength.csproj @@ -53,33 +53,36 @@ - + - + Component - + Form - + MainForm.cs - + Form - + ResultsForm.cs + + + - + MainForm.cs - + ResultsForm.cs @@ -106,7 +109,7 @@ Settings.settings True - + PreserveNewest diff --git a/CutToLength/Tools.json b/CutToLength/Data/Tools.json similarity index 100% rename from CutToLength/Tools.json rename to CutToLength/Data/Tools.json diff --git a/CutToLength/MainForm.Designer.cs b/CutToLength/Forms/MainForm.Designer.cs similarity index 99% rename from CutToLength/MainForm.Designer.cs rename to CutToLength/Forms/MainForm.Designer.cs index f6b1f64..821ee0e 100644 --- a/CutToLength/MainForm.Designer.cs +++ b/CutToLength/Forms/MainForm.Designer.cs @@ -1,4 +1,4 @@ -namespace CutToLength +namespace CutToLength.Forms { partial class MainForm { diff --git a/CutToLength/MainForm.cs b/CutToLength/Forms/MainForm.cs similarity index 98% rename from CutToLength/MainForm.cs rename to CutToLength/Forms/MainForm.cs index 9cfc839..6a6fc5b 100644 --- a/CutToLength/MainForm.cs +++ b/CutToLength/Forms/MainForm.cs @@ -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 GetTools() diff --git a/CutToLength/MainForm.resx b/CutToLength/Forms/MainForm.resx similarity index 100% rename from CutToLength/MainForm.resx rename to CutToLength/Forms/MainForm.resx diff --git a/CutToLength/ResultsForm.Designer.cs b/CutToLength/Forms/ResultsForm.Designer.cs similarity index 81% rename from CutToLength/ResultsForm.Designer.cs rename to CutToLength/Forms/ResultsForm.Designer.cs index 36bb87e..6ed2dea 100644 --- a/CutToLength/ResultsForm.Designer.cs +++ b/CutToLength/Forms/ResultsForm.Designer.cs @@ -1,38 +1,38 @@ -namespace CutToLength +namespace CutToLength.Forms { - partial class ResultsForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class ResultsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + 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 - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; diff --git a/CutToLength/ResultsForm.cs b/CutToLength/Forms/ResultsForm.cs similarity index 92% rename from CutToLength/ResultsForm.cs rename to CutToLength/Forms/ResultsForm.cs index 305c346..6b9a17f 100644 --- a/CutToLength/ResultsForm.cs +++ b/CutToLength/Forms/ResultsForm.cs @@ -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 Bins diff --git a/CutToLength/ResultsForm.resx b/CutToLength/Forms/ResultsForm.resx similarity index 100% rename from CutToLength/ResultsForm.resx rename to CutToLength/Forms/ResultsForm.resx diff --git a/CutToLength/Nesting/BestFitEngine.cs b/CutToLength/Nesting/BestFitEngine.cs new file mode 100644 index 0000000..be413c6 --- /dev/null +++ b/CutToLength/Nesting/BestFitEngine.cs @@ -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 Items { get; set; } + + public Result Pack(List 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 GetBins() + { + var bins = new List(); + + 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 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); + } + } +} diff --git a/CutToLength/BestFitEngine.cs b/CutToLength/Nesting/Engine2.cs similarity index 60% rename from CutToLength/BestFitEngine.cs rename to CutToLength/Nesting/Engine2.cs index 4d7e422..507b30b 100644 --- a/CutToLength/BestFitEngine.cs +++ b/CutToLength/Nesting/Engine2.cs @@ -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 Items { get; set; } - - public Result Pack(List 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 GetBins() - { - var bins = new List(); - - 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 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 items); - } - - public class Result - { - public Result() - { - ItemsNotUsed = new List(); - } - - public List ItemsNotUsed { get; set; } - - public List Bins { get; set; } - } } diff --git a/CutToLength/Nesting/IEngine.cs b/CutToLength/Nesting/IEngine.cs new file mode 100644 index 0000000..2ff467f --- /dev/null +++ b/CutToLength/Nesting/IEngine.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace CutToLength.Nesting +{ + public interface IEngine + { + Result Pack(List items); + } +} diff --git a/CutToLength/Nesting/Result.cs b/CutToLength/Nesting/Result.cs new file mode 100644 index 0000000..2c91a31 --- /dev/null +++ b/CutToLength/Nesting/Result.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace CutToLength.Nesting +{ + public class Result + { + public Result() + { + ItemsNotUsed = new List(); + } + + public List ItemsNotUsed { get; set; } + + public List Bins { get; set; } + } +} diff --git a/CutToLength/Program.cs b/CutToLength/Program.cs index dc9f365..bee9d9d 100644 --- a/CutToLength/Program.cs +++ b/CutToLength/Program.cs @@ -16,7 +16,7 @@ namespace CutToLength { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); + Application.Run(new Forms.MainForm()); } } }