From 0a294934aed22c913f4a8141175e8ea966c25c1b Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Wed, 25 Mar 2026 23:44:10 -0400 Subject: [PATCH] feat: integrate geometry simplifier into CadConverterForm Add "Simplify..." button to the detail bar and wire up SimplifierViewerForm as a tool window with lazy creation, positioning, and entity replacement on apply. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest/Forms/CadConverterForm.Designer.cs | 16 +++++++-- OpenNest/Forms/CadConverterForm.cs | 37 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/OpenNest/Forms/CadConverterForm.Designer.cs b/OpenNest/Forms/CadConverterForm.Designer.cs index 35b2b3d..b000691 100644 --- a/OpenNest/Forms/CadConverterForm.Designer.cs +++ b/OpenNest/Forms/CadConverterForm.Designer.cs @@ -28,6 +28,7 @@ namespace OpenNest.Forms lblDimensions = new System.Windows.Forms.Label(); lblEntityCount = new System.Windows.Forms.Label(); btnSplit = new System.Windows.Forms.Button(); + btnSimplify = new System.Windows.Forms.Button(); lblDetect = new System.Windows.Forms.Label(); cboBendDetector = new System.Windows.Forms.ComboBox(); bottomPanel1 = new OpenNest.Controls.BottomPanel(); @@ -127,6 +128,7 @@ namespace OpenNest.Forms detailBar.Controls.Add(lblDimensions); detailBar.Controls.Add(lblEntityCount); detailBar.Controls.Add(btnSplit); + detailBar.Controls.Add(btnSimplify); detailBar.Controls.Add(lblDetect); detailBar.Controls.Add(cboBendDetector); detailBar.Dock = System.Windows.Forms.DockStyle.Bottom; @@ -213,9 +215,18 @@ namespace OpenNest.Forms btnSplit.Size = new System.Drawing.Size(60, 24); btnSplit.TabIndex = 6; btnSplit.Text = "Split..."; - // + // + // btnSimplify + // + btnSimplify.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + btnSimplify.Font = new System.Drawing.Font("Segoe UI", 9F); + btnSimplify.Text = "Simplify..."; + btnSimplify.AutoSize = true; + btnSimplify.Margin = new System.Windows.Forms.Padding(4, 0, 0, 0); + btnSimplify.Click += new System.EventHandler(this.OnSimplifyClick); + // // lblDetect - // + // lblDetect.AutoSize = true; lblDetect.Font = new System.Drawing.Font("Segoe UI", 9F); lblDetect.Location = new System.Drawing.Point(361, 9); @@ -312,6 +323,7 @@ namespace OpenNest.Forms private System.Windows.Forms.NumericUpDown numQuantity; private System.Windows.Forms.TextBox txtCustomer; private System.Windows.Forms.Button btnSplit; + private System.Windows.Forms.Button btnSimplify; private System.Windows.Forms.ComboBox cboBendDetector; private System.Windows.Forms.Label lblQty; private System.Windows.Forms.Label lblCust; diff --git a/OpenNest/Forms/CadConverterForm.cs b/OpenNest/Forms/CadConverterForm.cs index 11026fd..48fb781 100644 --- a/OpenNest/Forms/CadConverterForm.cs +++ b/OpenNest/Forms/CadConverterForm.cs @@ -20,6 +20,7 @@ namespace OpenNest.Forms public partial class CadConverterForm : Form { private static int colorIndex; + private SimplifierViewerForm simplifierViewer; public CadConverterForm() { @@ -378,6 +379,42 @@ namespace OpenNest.Forms } } + private void OnSimplifyClick(object sender, EventArgs e) + { + if (entityView1.Entities == null || entityView1.Entities.Count == 0) + return; + + var shapes = ShapeBuilder.GetShapes(entityView1.Entities); + if (shapes.Count == 0) + return; + + if (simplifierViewer == null || simplifierViewer.IsDisposed) + { + simplifierViewer = new SimplifierViewerForm(); + simplifierViewer.Owner = this; + simplifierViewer.Applied += OnSimplifierApplied; + + // Position next to this form + var screen = Screen.FromControl(this); + simplifierViewer.Location = new Point( + System.Math.Min(Right, screen.WorkingArea.Right - simplifierViewer.Width), + Top); + } + + simplifierViewer.LoadShapes(shapes, entityView1); + } + + private void OnSimplifierApplied(List entities) + { + entityView1.Entities.Clear(); + entityView1.Entities.AddRange(entities); + entityView1.ZoomToFit(); + entityView1.Invalidate(); + + // Update entity count label + lblEntityCount.Text = $"{entities.Count} entities"; + } + #endregion #region Output