diff --git a/OpenNest/Actions/ActionSelect.cs b/OpenNest/Actions/ActionSelect.cs index 228cfec..410e3de 100644 --- a/OpenNest/Actions/ActionSelect.cs +++ b/OpenNest/Actions/ActionSelect.cs @@ -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() diff --git a/OpenNest/Controls/PlateView.cs b/OpenNest/Controls/PlateView.cs index 728ea53..7e7d874 100644 --- a/OpenNest/Controls/PlateView.cs +++ b/OpenNest/Controls/PlateView.cs @@ -65,6 +65,7 @@ namespace OpenNest.Controls public event EventHandler> PartAdded; public event EventHandler> 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) diff --git a/OpenNest/Forms/MainForm.Designer.cs b/OpenNest/Forms/MainForm.Designer.cs index 3238757..77be625 100644 --- a/OpenNest/Forms/MainForm.Designer.cs +++ b/OpenNest/Forms/MainForm.Designer.cs @@ -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; diff --git a/OpenNest/Forms/MainForm.cs b/OpenNest/Forms/MainForm.cs index e22f0be..66ef482 100644 --- a/OpenNest/Forms/MainForm.cs +++ b/OpenNest/Forms/MainForm.cs @@ -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)