diff --git a/DeepNestLib/Background.cs b/DeepNestLib/Background.cs index 365add8..7463b9e 100644 --- a/DeepNestLib/Background.cs +++ b/DeepNestLib/Background.cs @@ -196,24 +196,23 @@ public class MergedResult public static NFP[] cloneNfp(NFP[] nfp, bool inner = false) { - if (!inner) { return new[] { clone(nfp.First()) }; } - throw new NotImplementedException(); + // inner nfp is actually an array of nfps List newnfp = new List(); for (var i = 0; i < nfp.Count(); i++) { - // newnfp.push(clone(nfp[i])); + newnfp.Add(clone(nfp[i])); } - //return newnfp; + return newnfp.ToArray(); } + public static NFP clone(NFP nfp) { - NFP newnfp = new NFP(); newnfp.source = nfp.source; for (var i = 0; i < nfp.length; i++) diff --git a/DeepNestLib/NFP.cs b/DeepNestLib/NFP.cs index 08a64b7..d253fd8 100644 --- a/DeepNestLib/NFP.cs +++ b/DeepNestLib/NFP.cs @@ -3,8 +3,6 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; -using System.Text; -using System.Xml.Linq; namespace DeepNestLib { diff --git a/DeepNestLib/NestingContext.cs b/DeepNestLib/NestingContext.cs index 036e069..8bc8a0f 100644 --- a/DeepNestLib/NestingContext.cs +++ b/DeepNestLib/NestingContext.cs @@ -12,7 +12,7 @@ public class NestingContext { public List Polygons { get; private set; } = new List(); public List Sheets { get; private set; } = new List(); - + public double MaterialUtilization { get; private set; } = 0; public int PlacedPartsCount { get; private set; } = 0; diff --git a/DeepNestPort/AddSheetDialog.Designer.cs b/DeepNestPort/AddSheetDialog.Designer.cs new file mode 100644 index 0000000..3fdeccb --- /dev/null +++ b/DeepNestPort/AddSheetDialog.Designer.cs @@ -0,0 +1,141 @@ +namespace DeepNestPort +{ + partial class AddSheetDialog + { + /// + /// 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); + } + + #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() + { + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + this.button1 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + this.SuspendLayout(); + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(54, 12); + this.numericUpDown1.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.numericUpDown1.Minimum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(94, 20); + this.numericUpDown1.TabIndex = 0; + this.numericUpDown1.Value = new decimal(new int[] { + 3000, + 0, + 0, + 0}); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 14); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(35, 13); + this.label1.TabIndex = 1; + this.label1.Text = "Width"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 43); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(38, 13); + this.label2.TabIndex = 2; + this.label2.Text = "Height"; + // + // numericUpDown2 + // + this.numericUpDown2.Location = new System.Drawing.Point(56, 41); + this.numericUpDown2.Maximum = new decimal(new int[] { + 10000, + 0, + 0, + 0}); + this.numericUpDown2.Minimum = new decimal(new int[] { + 10, + 0, + 0, + 0}); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(92, 20); + this.numericUpDown2.TabIndex = 3; + this.numericUpDown2.Value = new decimal(new int[] { + 1500, + 0, + 0, + 0}); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(12, 67); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(136, 23); + this.button1.TabIndex = 4; + this.button1.Text = "Add"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // AddSheetDialog + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(158, 101); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.button1); + this.Controls.Add(this.numericUpDown2); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "AddSheetDialog"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "New sheet"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/DeepNestPort/AddSheetDialog.cs b/DeepNestPort/AddSheetDialog.cs new file mode 100644 index 0000000..efeb29d --- /dev/null +++ b/DeepNestPort/AddSheetDialog.cs @@ -0,0 +1,23 @@ +using System; +using System.Windows.Forms; + +namespace DeepNestPort +{ + public partial class AddSheetDialog : Form + { + public AddSheetDialog() + { + InitializeComponent(); + } + + public int SheetWidth { get; set; } + public int SheetHeight { get; set; } + private void button1_Click(object sender, EventArgs e) + { + SheetWidth = (int)numericUpDown1.Value; + SheetHeight = (int)numericUpDown2.Value; + DialogResult = DialogResult.OK; + Close(); + } + } +} diff --git a/DeepNestPort/AddSheetDialog.resx b/DeepNestPort/AddSheetDialog.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DeepNestPort/AddSheetDialog.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DeepNestPort/DeepNestPort.csproj b/DeepNestPort/DeepNestPort.csproj index c6af30c..fcfaac2 100644 --- a/DeepNestPort/DeepNestPort.csproj +++ b/DeepNestPort/DeepNestPort.csproj @@ -48,6 +48,12 @@ + + Form + + + AddSheetDialog.cs + @@ -70,6 +76,9 @@ QntDialog.cs + + AddSheetDialog.cs + Form1.cs diff --git a/DeepNestPort/Form1.Designer.cs b/DeepNestPort/Form1.Designer.cs index e576c9f..1269c3c 100644 --- a/DeepNestPort/Form1.Designer.cs +++ b/DeepNestPort/Form1.Designer.cs @@ -43,6 +43,12 @@ private void InitializeComponent() this.olvColumn3 = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); this.olvColumn4 = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); this.olvColumn5 = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); + this.olvColumn6 = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); + this.contextMenuStrip5 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.addSheetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.rectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dxfToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteToolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); this.panel4 = new System.Windows.Forms.Panel(); this.objectListView1 = new BrightIdeasSoftware.ObjectListView(); this.olvColumn1 = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn())); @@ -163,7 +169,6 @@ private void InitializeComponent() this.timer1 = new System.Windows.Forms.Timer(this.components); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); - this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.tabControl1.SuspendLayout(); this.tabPage3.SuspendLayout(); @@ -172,6 +177,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); this.toolStrip3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.objectListView2)).BeginInit(); + this.contextMenuStrip5.SuspendLayout(); this.panel4.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.objectListView1)).BeginInit(); this.contextMenuStrip4.SuspendLayout(); @@ -217,7 +223,6 @@ private void InitializeComponent() this.pictureBox1.Size = new System.Drawing.Size(832, 463); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; - this.pictureBox1.MouseEnter += new System.EventHandler(this.pictureBox1_MouseEnter); // // tabControl1 // @@ -323,12 +328,15 @@ private void InitializeComponent() this.objectListView2.AllColumns.Add(this.olvColumn3); this.objectListView2.AllColumns.Add(this.olvColumn4); this.objectListView2.AllColumns.Add(this.olvColumn5); + this.objectListView2.AllColumns.Add(this.olvColumn6); this.objectListView2.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.DoubleClick; this.objectListView2.CellEditUseWholeCell = false; this.objectListView2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.olvColumn3, this.olvColumn4, - this.olvColumn5}); + this.olvColumn5, + this.olvColumn6}); + this.objectListView2.ContextMenuStrip = this.contextMenuStrip5; this.objectListView2.Cursor = System.Windows.Forms.Cursors.Default; this.objectListView2.Dock = System.Windows.Forms.DockStyle.Fill; this.objectListView2.FullRowSelect = true; @@ -341,15 +349,19 @@ private void InitializeComponent() this.objectListView2.TabIndex = 3; this.objectListView2.UseCompatibleStateImageBehavior = false; this.objectListView2.View = System.Windows.Forms.View.Details; + this.objectListView2.SelectedIndexChanged += new System.EventHandler(this.objectListView2_SelectedIndexChanged); + this.objectListView2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.objectListView2_KeyDown); // // olvColumn3 // this.olvColumn3.AspectName = "Width"; + this.olvColumn3.IsEditable = false; this.olvColumn3.Text = "Width"; // // olvColumn4 // this.olvColumn4.AspectName = "Height"; + this.olvColumn4.IsEditable = false; this.olvColumn4.Text = "Height"; // // olvColumn5 @@ -357,6 +369,50 @@ private void InitializeComponent() this.olvColumn5.AspectName = "Quantity"; this.olvColumn5.Text = "Quantity"; // + // olvColumn6 + // + this.olvColumn6.AspectName = "Info"; + this.olvColumn6.Text = "Info"; + this.olvColumn6.Width = 180; + // + // contextMenuStrip5 + // + this.contextMenuStrip5.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.addSheetToolStripMenuItem, + this.deleteToolStripMenuItem3}); + this.contextMenuStrip5.Name = "contextMenuStrip5"; + this.contextMenuStrip5.Size = new System.Drawing.Size(126, 48); + // + // addSheetToolStripMenuItem + // + this.addSheetToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.rectToolStripMenuItem, + this.dxfToolStripMenuItem}); + this.addSheetToolStripMenuItem.Name = "addSheetToolStripMenuItem"; + this.addSheetToolStripMenuItem.Size = new System.Drawing.Size(125, 22); + this.addSheetToolStripMenuItem.Text = "add sheet"; + // + // rectToolStripMenuItem + // + this.rectToolStripMenuItem.Name = "rectToolStripMenuItem"; + this.rectToolStripMenuItem.Size = new System.Drawing.Size(94, 22); + this.rectToolStripMenuItem.Text = "rect"; + this.rectToolStripMenuItem.Click += new System.EventHandler(this.rectToolStripMenuItem_Click); + // + // dxfToolStripMenuItem + // + this.dxfToolStripMenuItem.Name = "dxfToolStripMenuItem"; + this.dxfToolStripMenuItem.Size = new System.Drawing.Size(94, 22); + this.dxfToolStripMenuItem.Text = "dxf"; + this.dxfToolStripMenuItem.Click += new System.EventHandler(this.dxfToolStripMenuItem_Click); + // + // deleteToolStripMenuItem3 + // + this.deleteToolStripMenuItem3.Name = "deleteToolStripMenuItem3"; + this.deleteToolStripMenuItem3.Size = new System.Drawing.Size(125, 22); + this.deleteToolStripMenuItem3.Text = "delete"; + this.deleteToolStripMenuItem3.Click += new System.EventHandler(this.deleteToolStripMenuItem3_Click); + // // panel4 // this.panel4.Controls.Add(this.objectListView1); @@ -390,6 +446,7 @@ private void InitializeComponent() this.objectListView1.UseCompatibleStateImageBehavior = false; this.objectListView1.View = System.Windows.Forms.View.Details; this.objectListView1.SelectedIndexChanged += new System.EventHandler(this.objectListView1_SelectedIndexChanged); + this.objectListView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.objectListView1_KeyDown); // // olvColumn1 // @@ -490,7 +547,6 @@ private void InitializeComponent() // // tabPage2 // - this.tabPage2.Controls.Add(this.propertyGrid1); this.tabPage2.Controls.Add(this.groupBox9); this.tabPage2.Controls.Add(this.label2); this.tabPage2.Controls.Add(this.textBox6); @@ -1683,13 +1739,6 @@ private void InitializeComponent() this.toolStripStatusLabel1.Size = new System.Drawing.Size(13, 17); this.toolStripStatusLabel1.Text = ".."; // - // propertyGrid1 - // - this.propertyGrid1.Location = new System.Drawing.Point(399, 56); - this.propertyGrid1.Name = "propertyGrid1"; - this.propertyGrid1.Size = new System.Drawing.Size(265, 326); - this.propertyGrid1.TabIndex = 33; - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1710,6 +1759,7 @@ private void InitializeComponent() this.toolStrip3.ResumeLayout(false); this.toolStrip3.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.objectListView2)).EndInit(); + this.contextMenuStrip5.ResumeLayout(false); this.panel4.ResumeLayout(false); this.panel4.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.objectListView1)).EndInit(); @@ -1897,7 +1947,12 @@ private void InitializeComponent() private System.Windows.Forms.Label label12; private System.Windows.Forms.TextBox textBox7; private System.Windows.Forms.Button button9; - private System.Windows.Forms.PropertyGrid propertyGrid1; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip5; + private System.Windows.Forms.ToolStripMenuItem addSheetToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem rectToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem dxfToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem3; + private BrightIdeasSoftware.OLVColumn olvColumn6; } } diff --git a/DeepNestPort/Form1.cs b/DeepNestPort/Form1.cs index 8a80d39..c55f0b8 100644 --- a/DeepNestPort/Form1.cs +++ b/DeepNestPort/Form1.cs @@ -21,7 +21,8 @@ public Form1() InitializeComponent(); LoadSettings(); - sheetsInfos.Add(new SheetLoadInfo() { Width = 3000, Height = 1500, Quantity = 10 }); + + sheetsInfos.Add(new SheetLoadInfo() { Nfp = NewSheet(), Width = 3000, Height = 1500, Quantity = 10 }); //hack toolStripButton9.BackgroundImageLayout = ImageLayout.None; @@ -105,7 +106,6 @@ private void PictureBox1_MouseDown(object sender, MouseEventArgs e) if (e.Button == MouseButtons.Left && hoveredNfp != null && enableEdit) { dragNfp = hoveredNfp; - propertyGrid1.SelectedObject = dragNfp; startx = dragNfp.x; starty = dragNfp.y; drag = true; @@ -215,6 +215,7 @@ public void RedrawPreview(DrawingContext ctx, object previewObject) { var g = ctx.Draw(nfp, Pens.Black, Brushes.LightBlue); bnd = g.GetBounds(); + bnd = new RectangleF(0, 0, bnd.Value.Width / ctx.zoom, bnd.Value.Height / ctx.zoom); } var cap = $"{bnd.Value.Width:N2} x {bnd.Value.Height:N2}"; @@ -346,20 +347,15 @@ public void Redraw() { item.Z = 0; } - if (dragNfp != null) - { - dragNfp.Z = 1; - } + if (dragNfp != null) dragNfp.Z = 1; + foreach (var item in polygons.Union(sheets).OrderBy(z => z.Z)) { if (!checkBox1.Checked) - { continue; - } + if (!(item is Sheet)) - { if (!item.fitted) continue; - } GraphicsPath path = new GraphicsPath(); if (item.Points != null && item.Points.Any()) @@ -385,31 +381,15 @@ public void Redraw() } ctx.gr.ResetTransform(); - - /*if (selected == item) + if (!sheets.Contains(item)) { - ctx.gr.FillPath(new SolidBrush(Color.FromArgb(128, Color.Orange)), path); - ctx.gr.DrawPath(Pens.DarkBlue, path); - - } - else*/ - { - if (!sheets.Contains(item)) - { - bool hovered = item == hoveredNfp; - - if (hovered || dragNfp == item) - { - ctx.gr.FillPath(new SolidBrush(Color.Blue), path); - } - else - { - ctx.gr.FillPath(new SolidBrush(Color.FromArgb(128, Color.LightBlue)), path); - } - - } - ctx.gr.DrawPath(Pens.Black, path); + bool hovered = item == hoveredNfp; + if (hovered || dragNfp == item) + ctx.gr.FillPath(new SolidBrush(Color.Blue), path); + else + ctx.gr.FillPath(new SolidBrush(Color.FromArgb(128, Color.LightBlue)), path); } + ctx.gr.DrawPath(Pens.Black, path); if (item is Sheet) { @@ -421,7 +401,6 @@ public void Redraw() bool was = false; foreach (var zitem in fr.placements.First()) { - var sheetid = zitem.sheetId; if (sheetid != item.id) continue; var sheet = sheets.FirstOrDefault(z => z.id == sheetid); @@ -547,7 +526,6 @@ public void UpdateNestsList() } } - Thread th; internal void displayProgress(float progress) @@ -565,13 +543,7 @@ private void listView1_SelectedIndexChanged(object sender, EventArgs e) Preview = selected; } } - - private void pictureBox1_MouseEnter(object sender, EventArgs e) - { - //pictureBox1.Focus(); - } - - + public void UpdateFilesList(string path) { var di = new DirectoryInfo(path); @@ -628,11 +600,7 @@ public Sheet NewCircleSheet(int w = 3000) tt.Height = w; tt.Width = w; - tt.Points = new SvgPoint[] { }; - int x = 0; - int y = 0; - - + tt.Points = new SvgPoint[] { }; for (int i = 0; i < 360; i += 5) { @@ -641,8 +609,6 @@ public Sheet NewCircleSheet(int w = 3000) tt.AddPoint(new SvgPoint(xx + w / 2, yy + w / 2)); } - - return tt; } @@ -651,7 +617,6 @@ private void clearAllToolStripMenuItem_Click(object sender, EventArgs e) polygons.Clear(); UpdateList(); } - private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) @@ -664,8 +629,6 @@ private void deleteToolStripMenuItem_Click(object sender, EventArgs e) } } - - private void textBox1_TextChanged(object sender, EventArgs e) { try @@ -750,14 +713,12 @@ private void moveToSheetsToolStripMenuItem_Click(object sender, EventArgs e) } } - private void clearAllToolStripMenuItem1_Click(object sender, EventArgs e) { sheets.Clear(); UpdateList(); } - private void moveToPolygonsToolStripMenuItem_Click(object sender, EventArgs e) { if (listView2.SelectedItems.Count > 0) @@ -1520,9 +1481,14 @@ private void toolStripButton6_Click(object sender, EventArgs e) src = context.GetNextSheetSource(); for (int i = 0; i < item.Quantity; i++) { - var ns = NewSheet(item.Width, item.Height); - sheets.Add(ns); - ns.source = src; + var ns = Background.clone(item.Nfp); + Sheet sheet = new Sheet(); + sheet.Points = ns.Points; + sheet.children = ns.children; + sheets.Add(sheet); + sheet.Width = sheet.WidthCalculated; + sheet.Height = sheet.HeightCalculated; + sheet.source = src; } } @@ -1586,7 +1552,7 @@ private void clearToolStripMenuItem_Click(object sender, EventArgs e) List sheetsInfos = new List(); - private void deleteToolStripMenuItem2_Click(object sender, EventArgs e) + void deleteParts() { if (objectListView1.SelectedObjects.Count == 0) return; if (ShowQuestion($"Are you to sure to delete {objectListView1.SelectedObjects.Count} items?") == DialogResult.No) return; @@ -1597,6 +1563,10 @@ private void deleteToolStripMenuItem2_Click(object sender, EventArgs e) } objectListView1.SetObjects(Infos); } + private void deleteToolStripMenuItem2_Click(object sender, EventArgs e) + { + deleteParts(); + } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Process.Start(linkLabel1.Text); @@ -1620,14 +1590,21 @@ private void toolStripButton8_Click(object sender, EventArgs e) void fitAll() { if (Preview == null) return; - if (!(Preview is RawDetail raw)) return; - - GraphicsPath gp = new GraphicsPath(); - foreach (var item in raw.Outers) + if (Preview is RawDetail raw) + { + GraphicsPath gp = new GraphicsPath(); + foreach (var item in raw.Outers) + { + gp.AddPolygon(item.Points.ToArray()); + } + ctx3.FitToPoints(gp.PathPoints, 5); + } + if (Preview is NFP nfp) { - gp.AddPolygon(item.Points.ToArray()); + GraphicsPath gp = new GraphicsPath(); + gp.AddPolygon(nfp.Points.Select(z => new PointF((float)z.x, (float)z.y)).ToArray()); + ctx3.FitToPoints(gp.PathPoints, 5); } - ctx3.FitToPoints(gp.PathPoints, 5); } bool autoFit = true; @@ -1707,8 +1684,6 @@ private void checkBox5_CheckedChanged(object sender, EventArgs e) drawSimplification = checkBox5.Checked; } - - private void radioButton4_CheckedChanged(object sender, EventArgs e) { SvgNest.Config.clipByHull = radioButton4.Checked; @@ -1747,7 +1722,109 @@ private void button9_Click(object sender, EventArgs e) button9.BackColor = enableEdit ? Color.Green : SystemColors.Control; button9.ForeColor = enableEdit ? Color.White : Color.Black; + } + private void objectListView2_SelectedIndexChanged(object sender, EventArgs e) + { + if (objectListView2.SelectedObject == null) return; + Preview = (objectListView2.SelectedObject as SheetLoadInfo).Nfp; + if (autoFit) fitAll(); + } + + private void dxfToolStripMenuItem_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "Dxf files (*.dxf)|*.dxf|Svg files (*.svg)|*.svg"; + ofd.FilterIndex = lastOpenFilterIndex; + ofd.Multiselect = true; + if (ofd.ShowDialog() != DialogResult.OK) return; + for (int i = 0; i < ofd.FileNames.Length; i++) + { + lastOpenFilterIndex = ofd.FilterIndex; + try + { + RawDetail det = null; + if (ofd.FileNames[i].ToLower().EndsWith("dxf")) + det = DxfParser.LoadDxf(ofd.FileNames[i]); + + if (ofd.FileNames[i].ToLower().EndsWith("svg")) + det = SvgParser.LoadSvg(ofd.FileNames[i]); + + var fr = sheetsInfos.FirstOrDefault(z => z.Path == ofd.FileNames[i]); + if (fr != null) + fr.Quantity++; + else + { + + var nfp = det.ToNfp(); + var bbox = det.BoundingBox(); + sheetsInfos.Add(new SheetLoadInfo() + { + Quantity = 1, + Nfp = nfp, + Width = bbox.Width, + Height = bbox.Height, + Info = new FileInfo(ofd.FileNames[i]).Name, + Path = ofd.FileNames[i] + }); + } + } + catch (Exception ex) + { + MessageBox.Show($"{ofd.FileNames[i]}: {ex.Message}", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + updateSheetInfos(); + } + + void updateSheetInfos() + { + objectListView2.SetObjects(sheetsInfos); + } + + void deleteSheet() + { + if (objectListView2.SelectedObjects.Count == 0) return; + if (ShowQuestion($"Are you to sure to delete {objectListView2.SelectedObjects.Count} sheets?") == DialogResult.No) return; + foreach (var item in objectListView2.SelectedObjects) + { + sheetsInfos.Remove(item as SheetLoadInfo); + } + updateSheetInfos(); + } + private void objectListView2_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Delete) + { + deleteSheet(); + } + } + + private void rectToolStripMenuItem_Click(object sender, EventArgs e) + { + AddSheetDialog a = new AddSheetDialog(); + if (a.ShowDialog() != DialogResult.OK) return; + sheetsInfos.Add(new SheetLoadInfo() + { + Height = a.SheetHeight, + Width = a.SheetWidth, + Nfp = NewSheet(a.SheetWidth, a.SheetHeight), + Quantity = 1 + }); + updateSheetInfos(); + } + + private void deleteToolStripMenuItem3_Click(object sender, EventArgs e) + { + deleteSheet(); + } + + private void objectListView1_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Delete) + { + deleteParts(); + } } } } \ No newline at end of file diff --git a/DeepNestPort/Form1.resx b/DeepNestPort/Form1.resx index 7f91459..497d06d 100644 --- a/DeepNestPort/Form1.resx +++ b/DeepNestPort/Form1.resx @@ -154,6 +154,9 @@ TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + 1260, 17 + 895, 17 diff --git a/DeepNestPort/SheetLoadInfo.cs b/DeepNestPort/SheetLoadInfo.cs index ba71000..15ee27f 100644 --- a/DeepNestPort/SheetLoadInfo.cs +++ b/DeepNestPort/SheetLoadInfo.cs @@ -1,9 +1,14 @@ -namespace DeepNestPort +using DeepNestLib; + +namespace DeepNestPort { public class SheetLoadInfo { - public int Width { get; set; } - public int Height { get; set; } + public NFP Nfp; + public string Path; + public string Info { get; set; } + public float Width { get; set; } + public float Height { get; set; } public int Quantity { get; set; } } }