refactor: standardize fill strategy progress reporting via FillContext
Strategies and fillers previously called NestEngineBase.ReportProgress directly, each constructing ProgressReport structs with phase, plate number, and work area manually. Some strategies (RectBestFit) reported nothing at all. This made progress updates inconsistent and flakey. Add FillContext.ReportProgress(parts, description) as the single standard method for intermediate progress. RunPipeline sets ActivePhase before each strategy, and the context handles common fields. Lower-level fillers (PairFiller, FillExtents, StripeFiller) now accept an Action<List<Part>, string> callback instead of raw IProgress, removing their coupling to NestEngineBase and ProgressReport. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -24,8 +24,8 @@ namespace OpenNest.Engine.Strategies
|
||||
|
||||
return FillHelpers.BestOverAngles(context, angles,
|
||||
angle => filler.Fill(context.Item.Drawing, angle,
|
||||
context.PlateNumber, context.Token, context.Progress),
|
||||
NestPhase.Extents, "Extents");
|
||||
context.Token, context.ReportProgress),
|
||||
"Extents");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,26 @@ namespace OpenNest.Engine.Strategies
|
||||
/// <summary>For progress reporting only; comparisons use Policy.Comparer.</summary>
|
||||
public FillScore CurrentBestScore { get; set; }
|
||||
public NestPhase WinnerPhase { get; set; }
|
||||
public NestPhase ActivePhase { get; set; }
|
||||
public List<PhaseResult> PhaseResults { get; } = new();
|
||||
public List<AngleResult> AngleResults { get; } = new();
|
||||
|
||||
public Dictionary<string, object> SharedState { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Standard progress reporting for strategies and fillers. Reports intermediate
|
||||
/// results using the current ActivePhase, PlateNumber, and WorkArea.
|
||||
/// </summary>
|
||||
public void ReportProgress(List<Part> parts, string description)
|
||||
{
|
||||
NestEngineBase.ReportProgress(Progress, new ProgressReport
|
||||
{
|
||||
Phase = ActivePhase,
|
||||
PlateNumber = PlateNumber,
|
||||
Parts = parts,
|
||||
WorkArea = WorkArea,
|
||||
Description = description,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,13 +113,12 @@ namespace OpenNest.Engine.Strategies
|
||||
/// <summary>
|
||||
/// Sweeps a list of angles, calling fillAtAngle for each, and returns
|
||||
/// the best result according to the context's comparer. Handles
|
||||
/// cancellation and progress reporting.
|
||||
/// cancellation and progress reporting via context.ReportProgress.
|
||||
/// </summary>
|
||||
public static List<Part> BestOverAngles(
|
||||
FillContext context,
|
||||
IReadOnlyList<double> angles,
|
||||
Func<double, List<Part>> fillAtAngle,
|
||||
NestPhase phase,
|
||||
string phaseLabel)
|
||||
{
|
||||
var workArea = context.WorkArea;
|
||||
@@ -140,14 +139,8 @@ namespace OpenNest.Engine.Strategies
|
||||
best = result;
|
||||
}
|
||||
|
||||
NestEngineBase.ReportProgress(context.Progress, new ProgressReport
|
||||
{
|
||||
Phase = phase,
|
||||
PlateNumber = context.PlateNumber,
|
||||
Parts = best,
|
||||
WorkArea = workArea,
|
||||
Description = $"{phaseLabel}: {i + 1}/{angles.Count} angles, {angleDeg:F0}° best = {best?.Count ?? 0} parts",
|
||||
});
|
||||
context.ReportProgress(best,
|
||||
$"{phaseLabel}: {i + 1}/{angles.Count} angles, {angleDeg:F0}° best = {best?.Count ?? 0} parts");
|
||||
}
|
||||
|
||||
return best ?? new List<Part>();
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenNest.Engine.Strategies
|
||||
|
||||
return result;
|
||||
},
|
||||
NestPhase.Linear, "Linear");
|
||||
"Linear");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenNest.Engine.Strategies
|
||||
var dedup = GridDedup.GetOrCreate(context.SharedState);
|
||||
var filler = new PairFiller(context.Plate, comparer, dedup);
|
||||
var result = filler.Fill(context.Item, context.WorkArea,
|
||||
context.PlateNumber, context.Token, context.Progress);
|
||||
context.Token, context.ReportProgress);
|
||||
|
||||
context.SharedState["BestFits"] = result.BestFits;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user