feat: show selected part bounding box in status bar

Add SelectionChanged event to PlateView and display the selected part's
location and size in a new status bar label. Shows combined bounding box
when multiple parts are selected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-20 09:38:48 -04:00
parent 3756ea255e
commit 2ed02c2dae
4 changed files with 59 additions and 2 deletions

View File

@@ -171,6 +171,7 @@ namespace OpenNest.Actions
part.IsSelected = true;
}
plateView.NotifySelectionChanged();
plateView.Invalidate();
return true;
}
@@ -187,6 +188,8 @@ namespace OpenNest.Actions
plateView.SelectedParts.Add(part);
part.IsSelected = true;
}
plateView.NotifySelectionChanged();
}
private void UpdateBrushAndPen()

View File

@@ -65,6 +65,7 @@ namespace OpenNest.Controls
public event EventHandler<ItemAddedEventArgs<Part>> PartAdded;
public event EventHandler<ItemRemovedEventArgs<Part>> PartRemoved;
public event EventHandler StatusChanged;
public event EventHandler SelectionChanged;
public PlateView()
: this(ColorScheme.Default)
@@ -1017,12 +1018,19 @@ namespace OpenNest.Controls
{
SelectedParts.ForEach(p => p.IsSelected = false);
SelectedParts.Clear();
SelectionChanged?.Invoke(this, EventArgs.Empty);
}
public void SelectAll()
{
parts.ForEach(p => p.IsSelected = true);
SelectedParts.AddRange(parts);
SelectionChanged?.Invoke(this, EventArgs.Empty);
}
public void NotifySelectionChanged()
{
SelectionChanged?.Invoke(this, EventArgs.Empty);
}
public override void ZoomToPoint(Vector pt, float zoomFactor, bool redraw = true)

View File

@@ -132,6 +132,7 @@
plateSizeStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
plateQtyStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
gpuStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
selectionStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
toolStrip1 = new System.Windows.Forms.ToolStrip();
btnNew = new System.Windows.Forms.ToolStripButton();
btnOpen = new System.Windows.Forms.ToolStripButton();
@@ -828,7 +829,7 @@
//
// statusStrip1
//
statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { statusLabel1, locationStatusLabel, spacerLabel, plateIndexStatusLabel, plateSizeStatusLabel, plateQtyStatusLabel, gpuStatusLabel });
statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { statusLabel1, locationStatusLabel, selectionStatusLabel, spacerLabel, plateIndexStatusLabel, plateSizeStatusLabel, plateQtyStatusLabel, gpuStatusLabel });
statusStrip1.Location = new System.Drawing.Point(0, 630);
statusStrip1.Name = "statusStrip1";
statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0);
@@ -850,7 +851,14 @@
locationStatusLabel.Size = new System.Drawing.Size(102, 19);
locationStatusLabel.Text = "Location : [0, 0]";
locationStatusLabel.Click += LocationStatusLabel_Click;
//
//
// selectionStatusLabel
//
selectionStatusLabel.BorderSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Left;
selectionStatusLabel.Name = "selectionStatusLabel";
selectionStatusLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0);
selectionStatusLabel.Size = new System.Drawing.Size(14, 19);
//
// spacerLabel
//
spacerLabel.Name = "spacerLabel";
@@ -1181,6 +1189,7 @@
private System.Windows.Forms.ToolStripButton btnSaveAs;
private System.Windows.Forms.ToolStripMenuItem centerPartsToolStripMenuItem;
private System.Windows.Forms.ToolStripStatusLabel gpuStatusLabel;
private System.Windows.Forms.ToolStripStatusLabel selectionStatusLabel;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
private System.Windows.Forms.ToolStripLabel engineLabel;
private System.Windows.Forms.ToolStripComboBox engineComboBox;

View File

@@ -221,10 +221,38 @@ namespace OpenNest.Forms
activeForm.PlateView.Plate.Quantity);
}
private void UpdateSelectionStatus()
{
if (activeForm == null || activeForm.PlateView.SelectedParts.Count == 0)
{
selectionStatusLabel.Text = string.Empty;
return;
}
var selected = activeForm.PlateView.SelectedParts;
if (selected.Count == 1)
{
var box = selected[0].BoundingBox;
selectionStatusLabel.Text = string.Format("Selected: [{0}, {1}] {2} x {3}",
box.X.ToString("n4"), box.Y.ToString("n4"),
box.Width.ToString("n4"), box.Length.ToString("n4"));
}
else
{
var bounds = selected.Select(p => p.BasePart).ToList().GetBoundingBox();
selectionStatusLabel.Text = string.Format("Selected ({0}): [{1}, {2}] {3} x {4}",
selected.Count,
bounds.X.ToString("n4"), bounds.Y.ToString("n4"),
bounds.Width.ToString("n4"), bounds.Length.ToString("n4"));
}
}
private void UpdateStatus()
{
UpdateLocationStatus();
UpdatePlateStatus();
UpdateSelectionStatus();
}
private void UpdateGpuStatus()
@@ -313,6 +341,7 @@ namespace OpenNest.Forms
activeForm.PlateView.MouseMove -= PlateView_MouseMove;
activeForm.PlateView.MouseClick -= PlateView_MouseClick;
activeForm.PlateView.StatusChanged -= PlateView_StatusChanged;
activeForm.PlateView.SelectionChanged -= PlateView_SelectionChanged;
}
// If nesting is in progress and the active form changed, cancel nesting
@@ -330,11 +359,14 @@ namespace OpenNest.Forms
if (activeForm == null)
{
statusLabel1.Text = "";
selectionStatusLabel.Text = "";
return;
}
UpdateLocationMode();
UpdateSelectionStatus();
activeForm.PlateView.StatusChanged += PlateView_StatusChanged;
activeForm.PlateView.SelectionChanged += PlateView_SelectionChanged;
mnuViewDrawRapids.Checked = activeForm.PlateView.DrawRapid;
mnuViewDrawBounds.Checked = activeForm.PlateView.DrawBounds;
statusLabel1.Text = activeForm.PlateView.Status;
@@ -1199,6 +1231,11 @@ namespace OpenNest.Forms
statusLabel1.Text = activeForm.PlateView.Status;
}
private void PlateView_SelectionChanged(object sender, EventArgs e)
{
UpdateSelectionStatus();
}
#endregion PlateView Events
private void centerPartsToolStripMenuItem_Click(object sender, EventArgs e)