mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-05 10:11:35 -05:00
fix(ui): give console and MCP users a hint they can follow on outlined sheets
This commit is contained in:
1 parent
f31cd1c797
commit
e290254a18
3 files changed
+44
-10
No files matched your search
@@ -24,6 +24,9 @@ return NestConsole.Run(args);
|
||||
|
||||
static class NestConsole
|
||||
{
|
||||
private const string OutlinedSheetMessage =
|
||||
"Error: Fill strategies need a rectangular sheet. Use --autonest --engine Irregular.";
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
using var cancellation = new CancellationTokenSource();
|
||||
@@ -209,9 +212,9 @@ static class NestConsole
|
||||
ApplyTemplate(plate, options);
|
||||
ApplyOverrides(plate, options);
|
||||
|
||||
if (!options.AutoNest && PlateFillService.Refusal(plate) is { } refusal)
|
||||
if (!options.AutoNest && PlateFillService.Refusal(plate) != null)
|
||||
{
|
||||
Console.Error.WriteLine($"Error: {refusal} Use --autonest.");
|
||||
Console.Error.WriteLine(OutlinedSheetMessage);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,26 @@ public class McpPlateToolsTests : IDisposable
|
||||
Assert.Null(sessionOnly.GetPlate(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FillOnOutlinedSheetNamesTheMcpToolsThatCanNestIt()
|
||||
{
|
||||
var session = new NestSession { Nest = new Nest("fixture") };
|
||||
session.Nest.Drawings.Add(new Drawing("square", new Program()));
|
||||
var outline = new SheetOutline(new[]
|
||||
{
|
||||
new Vector(0, 0), new Vector(96, 0), new Vector(96, 24),
|
||||
new Vector(48, 24), new Vector(48, 48), new Vector(0, 48),
|
||||
});
|
||||
var plate = new Plate(10, 10) { Outline = outline };
|
||||
session.Nest.Plates.Add(plate);
|
||||
|
||||
Assert.Equal(
|
||||
"Error: Fill strategies need a rectangular sheet. Use autonest_plate or autonest_job "
|
||||
+ "with engine Irregular. Nothing committed.",
|
||||
new NestingTools(session).FillPlate(0, "square"));
|
||||
Assert.Empty(plate.Parts);
|
||||
}
|
||||
|
||||
private static string Delete(SetupTools tools, int index) => tools.DeletePlate(index);
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -68,8 +68,8 @@ namespace OpenNest.Mcp.Tools
|
||||
var strategy = ResolveStrategy(engine);
|
||||
if (strategy == null)
|
||||
return EngineError(engine);
|
||||
if (PlateFillService.Refusal(plate) is { } refusal)
|
||||
return $"Error: {refusal} Nothing committed.";
|
||||
if (OutlinedSheetRefusal(plate) is { } refusal)
|
||||
return refusal;
|
||||
|
||||
var countBefore = plate.Parts.Count;
|
||||
var item = new NestItem { Drawing = drawing, Quantity = quantity };
|
||||
@@ -125,8 +125,8 @@ namespace OpenNest.Mcp.Tools
|
||||
var strategy = ResolveStrategy(engine);
|
||||
if (strategy == null)
|
||||
return EngineError(engine);
|
||||
if (PlateFillService.Refusal(plate) is { } refusal)
|
||||
return $"Error: {refusal} Nothing committed.";
|
||||
if (OutlinedSheetRefusal(plate) is { } refusal)
|
||||
return refusal;
|
||||
|
||||
var countBefore = plate.Parts.Count;
|
||||
var item = new NestItem { Drawing = drawing, Quantity = quantity };
|
||||
@@ -179,8 +179,8 @@ namespace OpenNest.Mcp.Tools
|
||||
var strategy = ResolveStrategy(engine);
|
||||
if (strategy == null)
|
||||
return EngineError(engine);
|
||||
if (PlateFillService.Refusal(plate) is { } refusal)
|
||||
return $"Error: {refusal} Nothing committed.";
|
||||
if (OutlinedSheetRefusal(plate) is { } refusal)
|
||||
return refusal;
|
||||
|
||||
var finder = RemnantFinder.FromPlate(plate);
|
||||
var remnants = finder.FindRemnants();
|
||||
@@ -248,8 +248,8 @@ namespace OpenNest.Mcp.Tools
|
||||
var strategy = ResolveStrategy(engine);
|
||||
if (strategy == null)
|
||||
return EngineError(engine);
|
||||
if (PlateFillService.Refusal(plate) is { } refusal)
|
||||
return $"Error: {refusal} Nothing committed.";
|
||||
if (OutlinedSheetRefusal(plate) is { } refusal)
|
||||
return refusal;
|
||||
|
||||
var parsed = ParseItems(drawingNames, quantities);
|
||||
if (parsed.error != null)
|
||||
@@ -614,6 +614,17 @@ namespace OpenNest.Mcp.Tools
|
||||
/// </summary>
|
||||
private static string ResolveStrategy(string engine) => EngineNameResolver.Classify(engine).FillStrategy;
|
||||
|
||||
internal const string OutlinedSheetMessage =
|
||||
"Error: Fill strategies need a rectangular sheet. Use autonest_plate or autonest_job "
|
||||
+ "with engine Irregular. Nothing committed.";
|
||||
|
||||
/// <summary>
|
||||
/// The fill tools' refusal for an outlined sheet, naming the MCP tools that can nest it;
|
||||
/// null when the plate is rectangular.
|
||||
/// </summary>
|
||||
private static string OutlinedSheetRefusal(Plate plate) =>
|
||||
PlateFillService.Refusal(plate) == null ? null : OutlinedSheetMessage;
|
||||
|
||||
private static string EngineError(string engine)
|
||||
{
|
||||
var classified = EngineNameResolver.Classify(engine);
|
||||
|
||||
Reference in new issue
Block a user