feat(ui): add FillWithProgress to PlateView, use from ActionClone

Moves async fill+progress orchestration into PlateView so ActionClone's
Ctrl+F fill shows the NestProgressForm dialog.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 08:39:30 -04:00
parent fde285484a
commit 9773449563
2 changed files with 50 additions and 11 deletions

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using OpenNest.Controls; using OpenNest.Controls;
@@ -171,19 +170,14 @@ namespace OpenNest.Actions
private void Fill() private void Fill()
{ {
var sw = Stopwatch.StartNew();
var plate = plateView.Plate; var plate = plateView.Plate;
var engine = new NestEngine(plate);
var groupParts = parts.Select(p => p.BasePart).ToList(); var groupParts = parts.Select(p => p.BasePart).ToList();
var bounds = plate.WorkArea(); var bounds = plate.WorkArea();
if (plate.Parts.Count == 0) if (plate.Parts.Count == 0)
{ {
engine.Fill(groupParts); plateView.FillWithProgress(groupParts, bounds);
sw.Stop();
plateView.Status = $"Fill: {plate.Parts.Count} parts in {sw.ElapsedMilliseconds} ms";
return; return;
} }
@@ -202,10 +196,7 @@ namespace OpenNest.Actions
if (bestArea == Box.Empty) if (bestArea == Box.Empty)
return; return;
var before = plate.Parts.Count; plateView.FillWithProgress(groupParts, bestArea);
engine.Fill(groupParts, bestArea);
sw.Stop();
plateView.Status = $"Fill: {plate.Parts.Count - before} parts in {sw.ElapsedMilliseconds} ms";
} }
} }
} }

View File

@@ -2,14 +2,18 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using OpenNest.Actions; using OpenNest.Actions;
using OpenNest.CNC; using OpenNest.CNC;
using OpenNest.Collections; using OpenNest.Collections;
using OpenNest.Converters; using OpenNest.Converters;
using OpenNest.Forms;
using OpenNest.Geometry; using OpenNest.Geometry;
using OpenNest.Math; using OpenNest.Math;
using Action = OpenNest.Actions.Action; using Action = OpenNest.Actions.Action;
@@ -834,6 +838,50 @@ namespace OpenNest.Controls
return count; return count;
} }
public async void FillWithProgress(List<Part> groupParts, Box workArea)
{
var sw = Stopwatch.StartNew();
var cts = new CancellationTokenSource();
var progressForm = new NestProgressForm(cts, showPlateRow: false);
var progress = new Progress<NestProgress>(p =>
{
progressForm.UpdateProgress(p);
SetTemporaryParts(p.BestParts);
});
progressForm.Show(FindForm());
try
{
var engine = new NestEngine(Plate);
var parts = await Task.Run(() =>
engine.Fill(groupParts, workArea, progress, cts.Token));
if (parts.Count > 0)
{
AcceptTemporaryParts();
sw.Stop();
Status = $"Fill: {parts.Count} parts in {sw.ElapsedMilliseconds} ms";
}
else
{
ClearTemporaryParts();
}
progressForm.ShowCompleted();
}
catch (Exception)
{
ClearTemporaryParts();
}
finally
{
progressForm.Close();
cts.Dispose();
}
}
public void RemoveSelectedParts() public void RemoveSelectedParts()
{ {
foreach (var part in SelectedParts) foreach (var part in SelectedParts)