feat(autonest): show required and placed quantities on the Parts grid

The Qty column only showed what this run would place, so the programmer
could not see how many a drawing needs or how many are already on plates
without leaving the dialog. Read-only Required and Placed columns show
both, and Load Required / Load Remaining set every row's Qty at once:
Required to re-nest a whole order, Remaining (required less placed, the
dialog's starting value) to finish it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-23 19:09:50 -05:00
1 parent 7634c95fc7
commit 5100eb288b
3 files changed
+167 -8

No files matched your search

@@ -0,0 +1,80 @@
using System.Windows.Forms;
using OpenNest.CNC;
using OpenNest.Forms;
namespace OpenNest.WinForms.Tests.Forms;
public class AutoNestFormQuantityTests
{
[Fact]
public void GridShowsRequiredAndPlacedAndQtyStartsAtRemaining()
{
RunSta(() =>
{
var (nest, drawing) = NestWithPlacedParts(required: 5, placed: 2);
using var form = new AutoNestForm(nest);
var grid = GetGrid(form);
Assert.Equal(5, grid.Rows[0].Cells[Column(grid, "Required")].Value);
Assert.Equal(2, grid.Rows[0].Cells[Column(grid, "Placed")].Value);
Assert.Equal(3, grid.Rows[0].Cells[Column(grid, "Quantity")].Value);
Assert.True(grid.Columns[Column(grid, "Required")].ReadOnly);
Assert.True(grid.Columns[Column(grid, "Placed")].ReadOnly);
});
}
[Fact]
public void LoadButtonsSwitchQtyBetweenRequiredAndRemaining()
{
RunSta(() =>
{
var (nest, _) = NestWithPlacedParts(required: 5, placed: 2);
var overPlaced = new Drawing("over", new Program()) { Quantity = { Required = 1 } };
nest.Drawings.Add(overPlaced);
var plate = nest.Plates[0];
plate.Parts.Add(new Part(overPlaced));
plate.Parts.Add(new Part(overPlaced));
using var form = new AutoNestForm(nest);
var grid = GetGrid(form);
form.LoadPartQuantities(remaining: false);
Assert.Equal(5, grid.Rows[0].Cells[Column(grid, "Quantity")].Value);
Assert.Equal(1, grid.Rows[1].Cells[Column(grid, "Quantity")].Value);
Assert.Equal(new[] { 5, 1 }, form.GetNestItems().Select(i => i.Quantity));
form.LoadPartQuantities(remaining: true);
Assert.Equal(3, grid.Rows[0].Cells[Column(grid, "Quantity")].Value);
Assert.Equal(0, grid.Rows[1].Cells[Column(grid, "Quantity")].Value);
Assert.Equal(3, Assert.Single(form.GetNestItems()).Quantity);
});
}
private static (Nest Nest, Drawing Drawing) NestWithPlacedParts(int required, int placed)
{
var drawing = new Drawing("bracket", new Program()) { Quantity = { Required = required } };
var nest = new Nest();
nest.Drawings.Add(drawing);
var plate = new Plate(48, 96) { Quantity = 1 };
nest.Plates.Add(plate);
for (var i = 0; i < placed; i++)
plate.Parts.Add(new Part(drawing));
Assert.Equal(placed, drawing.Quantity.Nested);
return (nest, drawing);
}
private static DataGridView GetGrid(AutoNestForm form)
{
// Binding needs a context even when the test does not show the form.
form.BindingContext = new BindingContext();
var grid = Assert.IsType<DataGridView>(form.Controls.Find("partsGrid", true).Single());
grid.CreateControl();
return grid;
}
private static int Column(DataGridView grid, string property) =>
grid.Columns.Cast<DataGridViewColumn>().Single(c => c.DataPropertyName == property).Index;
private static void RunSta(Action action) =>
StaTestThread.Run(action, TimeSpan.FromSeconds(15), "The STA test did not complete.");
}
+32 -2
View File
@@ -22,6 +22,8 @@ namespace OpenNest.Forms
this.platesTab = new System.Windows.Forms.TabPage();
this.partsGrid = new System.Windows.Forms.DataGridView();
this.summaryLabel = new System.Windows.Forms.Label();
this.loadRequiredButton = new System.Windows.Forms.Button();
this.loadRemainingButton = new System.Windows.Forms.Button();
this.engineLabel = new System.Windows.Forms.Label();
this.engineComboBox = new System.Windows.Forms.ComboBox();
this.nestOnServerBox = new System.Windows.Forms.CheckBox();
@@ -66,6 +68,8 @@ namespace OpenNest.Forms
//
this.partsTab.Controls.Add(this.partsGrid);
this.partsTab.Controls.Add(this.summaryLabel);
this.partsTab.Controls.Add(this.loadRequiredButton);
this.partsTab.Controls.Add(this.loadRemainingButton);
this.partsTab.Location = new System.Drawing.Point(4, 25);
this.partsTab.Name = "partsTab";
this.partsTab.Padding = new System.Windows.Forms.Padding(6);
@@ -99,18 +103,42 @@ namespace OpenNest.Forms
this.partsGrid.Name = "partsGrid";
this.partsGrid.RowHeadersVisible = false;
this.partsGrid.AutoGenerateColumns = false;
this.partsGrid.Size = new System.Drawing.Size(528, 420);
this.partsGrid.Size = new System.Drawing.Size(528, 406);
this.partsGrid.TabIndex = 0;
//
// summaryLabel
//
this.summaryLabel.AutoSize = true;
this.summaryLabel.ForeColor = System.Drawing.SystemColors.GrayText;
this.summaryLabel.Location = new System.Drawing.Point(10, 436);
this.summaryLabel.Location = new System.Drawing.Point(10, 429);
this.summaryLabel.Name = "summaryLabel";
this.summaryLabel.Size = new System.Drawing.Size(0, 16);
this.summaryLabel.TabIndex = 1;
//
// loadRequiredButton
//
this.loadRequiredButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.loadRequiredButton.Location = new System.Drawing.Point(290, 423);
this.loadRequiredButton.Name = "loadRequiredButton";
this.loadRequiredButton.Size = new System.Drawing.Size(120, 28);
this.loadRequiredButton.TabIndex = 2;
this.loadRequiredButton.Text = "Load Required";
this.ledgerToolTip.SetToolTip(this.loadRequiredButton, "Set each drawing's Qty to its required quantity.");
this.loadRequiredButton.UseVisualStyleBackColor = true;
this.loadRequiredButton.Click += new System.EventHandler(this.loadRequiredButton_Click);
//
// loadRemainingButton
//
this.loadRemainingButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.loadRemainingButton.Location = new System.Drawing.Point(418, 423);
this.loadRemainingButton.Name = "loadRemainingButton";
this.loadRemainingButton.Size = new System.Drawing.Size(120, 28);
this.loadRemainingButton.TabIndex = 3;
this.loadRemainingButton.Text = "Load Remaining";
this.ledgerToolTip.SetToolTip(this.loadRemainingButton, "Set each drawing's Qty to what is still left to place: required less placed.");
this.loadRemainingButton.UseVisualStyleBackColor = true;
this.loadRemainingButton.Click += new System.EventHandler(this.loadRemainingButton_Click);
//
// engineLabel
//
this.engineLabel.AutoSize = true;
@@ -332,6 +360,8 @@ namespace OpenNest.Forms
private System.Windows.Forms.TabPage platesTab;
private System.Windows.Forms.DataGridView partsGrid;
private System.Windows.Forms.Label summaryLabel;
private System.Windows.Forms.Button loadRequiredButton;
private System.Windows.Forms.Button loadRemainingButton;
private System.Windows.Forms.Label engineLabel;
private System.Windows.Forms.ComboBox engineComboBox;
private System.Windows.Forms.CheckBox nestOnServerBox;
+55 -6
View File
@@ -154,17 +154,40 @@ namespace OpenNest.Forms
{
DataPropertyName = "DrawingName",
HeaderText = "Drawing Name",
Width = 160,
Width = 130,
ReadOnly = true,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
}
);
var requiredColumn = new DataGridViewTextBoxColumn
{
DataPropertyName = "Required",
HeaderText = "Required",
ToolTipText = "The drawing's required quantity.",
Width = 62,
ReadOnly = true,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
};
requiredColumn.DefaultCellStyle.ForeColor = System.Drawing.SystemColors.GrayText;
partsGrid.Columns.Add(requiredColumn);
var placedColumn = new DataGridViewTextBoxColumn
{
DataPropertyName = "Placed",
HeaderText = "Placed",
ToolTipText = "Parts of the drawing already placed on the nest's plates.",
Width = 55,
ReadOnly = true,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
};
placedColumn.DefaultCellStyle.ForeColor = System.Drawing.SystemColors.GrayText;
partsGrid.Columns.Add(placedColumn);
partsGrid.Columns.Add(
new DataGridViewTextBoxColumn
{
DataPropertyName = "Quantity",
HeaderText = "Qty",
Width = 50,
ToolTipText = "How many of the drawing this Auto Nest places.",
Width = 45,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
}
);
@@ -173,7 +196,7 @@ namespace OpenNest.Forms
{
DataPropertyName = "Priority",
HeaderText = "Priority",
Width = 55,
Width = 52,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
}
);
@@ -182,7 +205,7 @@ namespace OpenNest.Forms
{
DataPropertyName = "RotationStart",
HeaderText = "Rot Start",
Width = 65,
Width = 62,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
}
);
@@ -191,7 +214,7 @@ namespace OpenNest.Forms
{
DataPropertyName = "RotationEnd",
HeaderText = "Rot End",
Width = 60,
Width = 57,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
}
);
@@ -200,7 +223,7 @@ namespace OpenNest.Forms
{
DataPropertyName = "StepAngle",
HeaderText = "Step",
Width = 55,
Width = 45,
AutoSizeMode = DataGridViewAutoSizeColumnMode.None,
}
);
@@ -591,6 +614,28 @@ namespace OpenNest.Forms
summaryLabel.Text = $"{totalQty} parts across {drawingCount} drawings";
}
private void loadRequiredButton_Click(object sender, EventArgs e) => LoadPartQuantities(remaining: false);
private void loadRemainingButton_Click(object sender, EventArgs e) => LoadPartQuantities(remaining: true);
/// <summary>
/// Sets every row's Qty to its drawing's required quantity, or to what is still left to
/// place (required less placed, never below zero).
/// </summary>
internal void LoadPartQuantities(bool remaining)
{
if (partsGrid.DataSource is not List<DataGridViewItem> gridItems)
return;
partsGrid.EndEdit();
foreach (var item in gridItems)
{
var quantity = remaining ? item.RefDrawing.Quantity.Remaining : item.Required;
item.Quantity = System.Math.Max(0, quantity);
}
partsGrid.Refresh();
UpdateSummary();
}
private void PartsGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0)
@@ -978,6 +1023,10 @@ namespace OpenNest.Forms
set { RefDrawing.Name = value; }
}
public int Required => RefDrawing.Quantity.Required;
public int Placed => RefDrawing.Quantity.Nested;
public int Quantity { get; set; }
public int Priority { get; set; }