Compare commits

...

2 Commits

Author SHA1 Message Date
aj 28653e3a9f feat(shapes): generate unique drawing names from parameters and add toolbar button
Shape library drawings now get descriptive names based on their
parameters (e.g. "Rectangle 12x6", "Circle 8 Dia") instead of generic
type names, preventing silent duplicates in the DrawingCollection
HashSet. Added a Shape Library button to the Drawings tab toolbar
and removed separators between toolbar buttons for a cleaner look.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 15:48:45 -04:00
aj 7c3246c6e7 fix(cutting): restrict tabs to external perimeter and clarify tab UI
Tabs were being applied to internal cutouts and circle holes, which is
incorrect — only the external perimeter should be tabbed. Restructured
the Tabs panel to use radio buttons ("Tab all parts" vs "Auto-tab by
smallest dimension") so the two modes are clearly mutually exclusive
instead of the confusing implicit override behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 08:55:30 -04:00
21 changed files with 163 additions and 52 deletions
@@ -305,9 +305,6 @@ namespace OpenNest.CNC.CuttingStrategy
subPgm.Codes.AddRange(leadIn.Generate(relativePoint, normal, winding));
var reindexed = relativeShape.ReindexAt(relativePoint, relativeCircle);
if (Parameters.TabsEnabled && Parameters.TabConfig != null)
reindexed = TrimShapeForTab(reindexed, relativePoint, Parameters.TabConfig.Size);
subPgm.Codes.AddRange(ConvertShapeToMoves(reindexed, relativePoint));
subPgm.Codes.AddRange(leadOut.Generate(relativePoint, normal, winding));
subPgm.Mode = Mode.Incremental;
@@ -331,7 +328,7 @@ namespace OpenNest.CNC.CuttingStrategy
var reindexedShape = shape.ReindexAt(point, entity);
if (Parameters.TabsEnabled && Parameters.TabConfig != null)
if (Parameters.TabsEnabled && Parameters.TabConfig != null && contourType == ContourType.External)
reindexedShape = TrimShapeForTab(reindexedShape, point, Parameters.TabConfig.Size);
program.Codes.AddRange(ConvertShapeToMoves(reindexedShape, point));
+2
View File
@@ -7,6 +7,8 @@ namespace OpenNest.Shapes
{
public double Diameter { get; set; }
public override string GenerateName() => $"Circle {Dim(Diameter)} Dia";
public override void SetPreviewDefaults()
{
Diameter = 8;
@@ -8,6 +8,8 @@ namespace OpenNest.Shapes
public double Base { get; set; }
public double Height { get; set; }
public override string GenerateName() => $"Isosceles Triangle {Dim(Base)}x{Dim(Height)}";
public override void SetPreviewDefaults()
{
Base = 8;
+2
View File
@@ -10,6 +10,8 @@ namespace OpenNest.Shapes
public double LegWidth { get; set; }
public double LegHeight { get; set; }
public override string GenerateName() => $"L {Dim(Width)}x{Dim(Height)}";
public override void SetPreviewDefaults()
{
Width = 8;
+2
View File
@@ -8,6 +8,8 @@ namespace OpenNest.Shapes
public int Sides { get; set; }
public double Width { get; set; }
public override string GenerateName() => $"{Sides}-Sided Polygon {Dim(Width)}";
public override void SetPreviewDefaults()
{
Sides = 8;
+8
View File
@@ -13,6 +13,14 @@ namespace OpenNest.Shapes
public double PipeClearance { get; set; }
public bool Blind { get; set; }
public override string GenerateName()
{
var name = $"Pipe Flange {Dim(OD)} OD";
if (!string.IsNullOrEmpty(PipeSize))
name += $" {PipeSize} Pipe";
return name;
}
public override void SetPreviewDefaults()
{
OD = 7.5;
+2
View File
@@ -8,6 +8,8 @@ namespace OpenNest.Shapes
public double Length { get; set; }
public double Width { get; set; }
public override string GenerateName() => $"Rectangle {Dim(Length)}x{Dim(Width)}";
public override void SetPreviewDefaults()
{
Length = 12;
@@ -8,6 +8,8 @@ namespace OpenNest.Shapes
public double Width { get; set; }
public double Height { get; set; }
public override string GenerateName() => $"Right Triangle {Dim(Width)}x{Dim(Height)}";
public override void SetPreviewDefaults()
{
Width = 8;
+2
View File
@@ -8,6 +8,8 @@ namespace OpenNest.Shapes
public double OuterDiameter { get; set; }
public double InnerDiameter { get; set; }
public override string GenerateName() => $"Ring {Dim(OuterDiameter)}x{Dim(InnerDiameter)}";
public override void SetPreviewDefaults()
{
OuterDiameter = 10;
@@ -10,6 +10,8 @@ namespace OpenNest.Shapes
public double Width { get; set; }
public double Radius { get; set; }
public override string GenerateName() => $"Rounded Rectangle {Dim(Length)}x{Dim(Width)} R{Dim(Radius)}";
public override void SetPreviewDefaults()
{
Length = 12;
+10
View File
@@ -26,6 +26,14 @@ namespace OpenNest.Shapes
public abstract Drawing GetDrawing();
public virtual string GenerateName()
{
var typeName = GetType().Name;
return typeName.EndsWith("Shape")
? typeName.Substring(0, typeName.Length - 5)
: typeName;
}
public virtual void SetPreviewDefaults() { }
public static List<T> LoadFromJson<T>(string path) where T : ShapeDefinition
@@ -34,6 +42,8 @@ namespace OpenNest.Shapes
return JsonSerializer.Deserialize<List<T>>(json, JsonOptions);
}
protected static string Dim(double value) => value.ToString("0.###");
protected Drawing CreateDrawing(List<Entity> entities)
{
var pgm = ConvertGeometry.ToProgram(entities);
+2
View File
@@ -10,6 +10,8 @@ namespace OpenNest.Shapes
public double StemWidth { get; set; }
public double BarHeight { get; set; }
public override string GenerateName() => $"T {Dim(Width)}x{Dim(Height)}";
public override void SetPreviewDefaults()
{
Width = 10;
+2
View File
@@ -9,6 +9,8 @@ namespace OpenNest.Shapes
public double BottomWidth { get; set; }
public double Height { get; set; }
public override string GenerateName() => $"Trapezoid {Dim(TopWidth)}x{Dim(BottomWidth)}x{Dim(Height)}";
public override void SetPreviewDefaults()
{
TopWidth = 6;
+57 -18
View File
@@ -24,6 +24,8 @@ namespace OpenNest.Controls
private readonly CheckBox chkTabsEnabled;
private readonly NumericUpDown nudTabWidth;
private readonly RadioButton rbTabAll;
private readonly RadioButton rbAutoTab;
private readonly NumericUpDown nudAutoTabMin;
private readonly NumericUpDown nudAutoTabMax;
private readonly NumericUpDown nudPierceClearance;
@@ -112,7 +114,7 @@ namespace OpenNest.Controls
{
HeaderText = "Tabs",
Dock = DockStyle.Top,
ExpandedHeight = 120,
ExpandedHeight = 160,
IsExpanded = false
};
@@ -122,44 +124,78 @@ namespace OpenNest.Controls
Location = new Point(12, 4),
AutoSize = true
};
chkTabsEnabled.CheckedChanged += (s, e) =>
{
nudTabWidth.Enabled = chkTabsEnabled.Checked;
OnParametersChanged();
};
tabsPanel.ContentPanel.Controls.Add(chkTabsEnabled);
tabsPanel.ContentPanel.Controls.Add(new Label
{
Text = "Width:",
Text = "Tab Size:",
Location = new Point(160, 6),
AutoSize = true
});
nudTabWidth = CreateNumeric(215, 3, 0.25, 0.0625);
nudTabWidth = CreateNumeric(225, 3, 0.25, 0.0625);
nudTabWidth.Enabled = false;
tabsPanel.ContentPanel.Controls.Add(nudTabWidth);
rbTabAll = new RadioButton
{
Text = "Tab all parts",
Location = new Point(28, 28),
AutoSize = true,
Enabled = false,
Checked = true
};
tabsPanel.ContentPanel.Controls.Add(rbTabAll);
rbAutoTab = new RadioButton
{
Text = "Auto-tab when smallest part dimension is between:",
Location = new Point(28, 50),
AutoSize = true,
Enabled = false
};
tabsPanel.ContentPanel.Controls.Add(rbAutoTab);
tabsPanel.ContentPanel.Controls.Add(new Label
{
Text = "Auto-Tab Min Size:",
Location = new Point(12, 32),
Text = "Min:",
Location = new Point(44, 76),
AutoSize = true
});
nudAutoTabMin = CreateNumeric(140, 29, 0, 0.0625);
nudAutoTabMin = CreateNumeric(77, 73, 0, 0.0625);
nudAutoTabMin.Enabled = false;
tabsPanel.ContentPanel.Controls.Add(nudAutoTabMin);
tabsPanel.ContentPanel.Controls.Add(new Label
{
Text = "Auto-Tab Max Size:",
Location = new Point(12, 58),
Text = "Max:",
Location = new Point(210, 76),
AutoSize = true
});
nudAutoTabMax = CreateNumeric(140, 55, 0, 0.0625);
nudAutoTabMax = CreateNumeric(245, 73, 0, 0.0625);
nudAutoTabMax.Enabled = false;
tabsPanel.ContentPanel.Controls.Add(nudAutoTabMax);
chkTabsEnabled.CheckedChanged += (s, e) =>
{
var enabled = chkTabsEnabled.Checked;
nudTabWidth.Enabled = enabled;
rbTabAll.Enabled = enabled;
rbAutoTab.Enabled = enabled;
nudAutoTabMin.Enabled = enabled && rbAutoTab.Checked;
nudAutoTabMax.Enabled = enabled && rbAutoTab.Checked;
OnParametersChanged();
};
rbTabAll.CheckedChanged += (s, e) =>
{
nudAutoTabMin.Enabled = chkTabsEnabled.Checked && rbAutoTab.Checked;
nudAutoTabMax.Enabled = chkTabsEnabled.Checked && rbAutoTab.Checked;
OnParametersChanged();
};
// Pierce section
var piercePanel = new CollapsiblePanel
{
@@ -246,13 +282,13 @@ namespace OpenNest.Controls
InternalLeadOut = BuildLeadOut(cboInternalLeadOut, pnlInternalLeadOut),
ArcCircleLeadIn = BuildLeadIn(cboArcCircleLeadIn, pnlArcCircleLeadIn),
ArcCircleLeadOut = BuildLeadOut(cboArcCircleLeadOut, pnlArcCircleLeadOut),
TabsEnabled = chkTabsEnabled.Checked,
TabsEnabled = chkTabsEnabled.Checked && rbTabAll.Checked,
TabConfig = new NormalTab { Size = (double)nudTabWidth.Value },
PierceClearance = (double)nudPierceClearance.Value,
RoundLeadInAngles = chkRoundLeadInAngles.Checked,
LeadInAngleIncrement = (double)nudLeadInAngleIncrement.Value,
AutoTabMinSize = (double)nudAutoTabMin.Value,
AutoTabMaxSize = (double)nudAutoTabMax.Value
AutoTabMinSize = chkTabsEnabled.Checked && rbAutoTab.Checked ? (double)nudAutoTabMin.Value : 0,
AutoTabMaxSize = chkTabsEnabled.Checked && rbAutoTab.Checked ? (double)nudAutoTabMax.Value : 0
};
}
@@ -267,7 +303,10 @@ namespace OpenNest.Controls
LoadLeadIn(cboArcCircleLeadIn, pnlArcCircleLeadIn, p.ArcCircleLeadIn);
LoadLeadOut(cboArcCircleLeadOut, pnlArcCircleLeadOut, p.ArcCircleLeadOut);
chkTabsEnabled.Checked = p.TabsEnabled;
var hasAutoTab = p.AutoTabMinSize > 0 || p.AutoTabMaxSize > 0;
chkTabsEnabled.Checked = p.TabsEnabled || hasAutoTab;
rbAutoTab.Checked = hasAutoTab;
rbTabAll.Checked = !hasAutoTab;
if (p.TabConfig != null)
nudTabWidth.Value = (decimal)p.TabConfig.Size;
nudPierceClearance.Value = (decimal)p.PierceClearance;
+18 -27
View File
@@ -47,11 +47,9 @@
drawingListBox1 = new OpenNest.Controls.DrawingListBox();
toolStrip2 = new System.Windows.Forms.ToolStrip();
toolStripButton2 = new System.Windows.Forms.ToolStripButton();
toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
shapeLibraryButton = new System.Windows.Forms.ToolStripButton();
editDrawingsButton = new System.Windows.Forms.ToolStripButton();
toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
toolStripButton3 = new System.Windows.Forms.ToolStripButton();
toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
hideNestedButton = new System.Windows.Forms.ToolStripButton();
((System.ComponentModel.ISupportInitialize)splitContainer).BeginInit();
splitContainer.Panel1.SuspendLayout();
@@ -219,7 +217,7 @@
//
toolStrip2.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
toolStrip2.ImageScalingSize = new System.Drawing.Size(20, 20);
toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { toolStripButton2, toolStripSeparator4, editDrawingsButton, toolStripSeparator1, toolStripButton3, toolStripSeparator2, hideNestedButton });
toolStrip2.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { toolStripButton2, shapeLibraryButton, editDrawingsButton, toolStripButton3, hideNestedButton });
toolStrip2.Location = new System.Drawing.Point(4, 3);
toolStrip2.Name = "toolStrip2";
toolStrip2.Size = new System.Drawing.Size(265, 27);
@@ -237,14 +235,19 @@
toolStripButton2.Size = new System.Drawing.Size(34, 24);
toolStripButton2.Text = "Import Drawings";
toolStripButton2.Click += ImportDrawings_Click;
//
// toolStripSeparator4
//
toolStripSeparator4.Name = "toolStripSeparator4";
toolStripSeparator4.Size = new System.Drawing.Size(6, 27);
//
//
// shapeLibraryButton
//
shapeLibraryButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
shapeLibraryButton.Image = Properties.Resources.shapes;
shapeLibraryButton.Name = "shapeLibraryButton";
shapeLibraryButton.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
shapeLibraryButton.Size = new System.Drawing.Size(34, 24);
shapeLibraryButton.Text = "Shape Library";
shapeLibraryButton.Click += ShapeLibrary_Click;
//
// editDrawingsButton
//
//
editDrawingsButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
editDrawingsButton.Image = (System.Drawing.Image)resources.GetObject("editDrawingsButton.Image");
editDrawingsButton.Name = "editDrawingsButton";
@@ -252,14 +255,9 @@
editDrawingsButton.Size = new System.Drawing.Size(34, 24);
editDrawingsButton.Text = "Edit Drawings in Converter";
editDrawingsButton.Click += EditDrawingsInConverter_Click;
//
// toolStripSeparator1
//
toolStripSeparator1.Name = "toolStripSeparator1";
toolStripSeparator1.Size = new System.Drawing.Size(6, 27);
//
//
// toolStripButton3
//
//
toolStripButton3.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
toolStripButton3.Image = (System.Drawing.Image)resources.GetObject("toolStripButton3.Image");
toolStripButton3.Name = "toolStripButton3";
@@ -268,12 +266,7 @@
toolStripButton3.Size = new System.Drawing.Size(34, 24);
toolStripButton3.Text = "Cleanup unused Drawings";
toolStripButton3.Click += CleanUnusedDrawings_Click;
//
// toolStripSeparator2
//
toolStripSeparator2.Name = "toolStripSeparator2";
toolStripSeparator2.Size = new System.Drawing.Size(6, 27);
//
//
// hideNestedButton
//
hideNestedButton.CheckOnClick = true;
@@ -329,11 +322,9 @@
private System.Windows.Forms.ColumnHeader utilColumn;
private System.Windows.Forms.ToolStrip toolStrip2;
private System.Windows.Forms.ToolStripButton toolStripButton2;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripButton shapeLibraryButton;
private System.Windows.Forms.ToolStripButton editDrawingsButton;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripButton toolStripButton3;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripButton hideNestedButton;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripButton toolStripLabel1;
+12
View File
@@ -875,6 +875,18 @@ namespace OpenNest.Forms
Import();
}
private void ShapeLibrary_Click(object sender, EventArgs e)
{
var form = new ShapeLibraryForm(Nest.Drawings.Select(d => d.Name));
form.ShowDialog();
var drawings = form.GetDrawings();
if (drawings.Count == 0) return;
drawings.ForEach(d => Nest.Drawings.Add(d));
UpdateDrawingList();
}
private void EditDrawingsInConverter_Click(object sender, EventArgs e)
{
if (Nest.Drawings.Count == 0)
+1 -1
View File
@@ -837,7 +837,7 @@ namespace OpenNest.Forms
{
if (activeForm == null) return;
var form = new ShapeLibraryForm();
var form = new ShapeLibraryForm(activeForm.Nest.Drawings.Select(d => d.Name));
form.ShowDialog();
var drawings = form.GetDrawings();
+22 -1
View File
@@ -21,12 +21,17 @@ namespace OpenNest.Forms
private readonly List<Drawing> addedDrawings = new List<Drawing>();
private readonly List<ShapeEntry> shapeEntries = new List<ShapeEntry>();
private readonly List<ParameterBinding> parameterBindings = new List<ParameterBinding>();
private readonly HashSet<string> existingNames;
private ShapeEntry selectedEntry;
private bool suppressPreview;
public ShapeLibraryForm()
public ShapeLibraryForm(IEnumerable<string> existingDrawingNames = null)
{
existingNames = existingDrawingNames != null
? new HashSet<string>(existingDrawingNames, StringComparer.OrdinalIgnoreCase)
: new HashSet<string>(StringComparer.OrdinalIgnoreCase);
InitializeComponent();
DiscoverShapes();
PopulateShapeList();
@@ -259,6 +264,7 @@ namespace OpenNest.Forms
if (shape == null) return;
var drawing = shape.GetDrawing();
nameTextBox.Text = shape.GenerateName();
previewBox.ShowDrawing(drawing);
if (drawing?.Program != null)
@@ -405,10 +411,12 @@ namespace OpenNest.Forms
if (shape == null) return;
var drawing = shape.GetDrawing();
drawing.Name = GetUniqueName(drawing.Name);
drawing.Color = Drawing.GetNextColor();
drawing.Quantity.Required = (int)quantityUpDown.Value;
addedDrawings.Add(drawing);
existingNames.Add(drawing.Name);
DialogResult = DialogResult.OK;
addButton.Text = $"Added ({addedDrawings.Count})";
@@ -423,6 +431,19 @@ namespace OpenNest.Forms
}
}
private string GetUniqueName(string baseName)
{
if (!existingNames.Contains(baseName))
return baseName;
for (var i = 2; ; i++)
{
var candidate = $"{baseName} ({i})";
if (!existingNames.Contains(candidate))
return candidate;
}
}
private static string FriendlyName(string name)
{
if (name.EndsWith("Shape"))
+11 -1
View File
@@ -249,7 +249,17 @@ namespace OpenNest.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap shapes {
get {
object obj = ResourceManager.GetObject("shapes", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
+3
View File
@@ -187,4 +187,7 @@
<data name="delete" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="shapes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\shapes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB