mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-10 07:34:14 -04:00
93 lines
3.7 KiB
C#
93 lines
3.7 KiB
C#
using System.ComponentModel;
|
|
using System.Text;
|
|
using ModelContextProtocol.Server;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Mcp.Tools
|
|
{
|
|
[McpServerToolType]
|
|
public class SetupTools
|
|
{
|
|
private readonly NestSession _session;
|
|
|
|
public SetupTools(NestSession session)
|
|
{
|
|
_session = session;
|
|
}
|
|
|
|
[McpServerTool(Name = "create_plate")]
|
|
[Description(
|
|
"Create a new plate with the given dimensions and spacing. Returns plate index and work area."
|
|
)]
|
|
public string CreatePlate(
|
|
[Description("Plate width")] double width,
|
|
[Description("Plate length")] double length,
|
|
[Description("Spacing between parts (default 0)")] double partSpacing = 0,
|
|
[Description("Edge spacing on all sides (default 0)")] double edgeSpacing = 0,
|
|
[Description(
|
|
"Quadrant 1-4 (default 1). 1=TopRight, 2=TopLeft, 3=BottomLeft, 4=BottomRight"
|
|
)]
|
|
int quadrant = 1,
|
|
[Description("Material name (optional)")] string material = null
|
|
)
|
|
{
|
|
var plate = new Plate(width, length);
|
|
plate.PartSpacing = partSpacing;
|
|
plate.EdgeSpacing = new Spacing(edgeSpacing, edgeSpacing);
|
|
plate.Quadrant = quadrant;
|
|
plate.Quantity = 1;
|
|
|
|
if (!string.IsNullOrEmpty(material) && _session.Nest != null)
|
|
_session.Nest.Material = new Material(material);
|
|
|
|
_session.Plates.Add(plate);
|
|
|
|
var allPlates = _session.AllPlates();
|
|
var index = allPlates.Count - 1;
|
|
var work = plate.WorkArea();
|
|
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine($"Created plate {index}: {plate.Size.Width:F1} x {plate.Size.Length:F1}");
|
|
sb.AppendLine($" Quadrant: {plate.Quadrant}");
|
|
sb.AppendLine($" Part spacing: {plate.PartSpacing:F2}");
|
|
sb.AppendLine(
|
|
$" Edge spacing: L={plate.EdgeSpacing.Left:F2} B={plate.EdgeSpacing.Bottom:F2} R={plate.EdgeSpacing.Right:F2} T={plate.EdgeSpacing.Top:F2}"
|
|
);
|
|
sb.AppendLine($" Work area: {work.Width:F1} x {work.Length:F1}");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
[McpServerTool(Name = "delete_plate")]
|
|
[Description("Delete an empty plate without parts or cutoff definitions. Later plate indices shift down by one.")]
|
|
public string DeletePlate([Description("Index of the empty plate to delete")] int plateIndex)
|
|
{
|
|
var oldCount = _session.AllPlates().Count;
|
|
if (!_session.TryDeleteEmptyPlate(plateIndex, out var reason))
|
|
return $"Error: {reason}; no plates changed";
|
|
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine($"Deleted plate {plateIndex}. Plates: {oldCount} -> {oldCount - 1}.");
|
|
for (var oldIndex = plateIndex + 1; oldIndex < oldCount; oldIndex++)
|
|
sb.AppendLine($" {oldIndex} -> {oldIndex - 1}");
|
|
sb.AppendLine("Use get_plate_info with the new indices before further operations.");
|
|
return sb.ToString();
|
|
}
|
|
|
|
[McpServerTool(Name = "clear_plate")]
|
|
[Description("Remove all parts from a plate. Returns how many parts were removed.")]
|
|
public string ClearPlate([Description("Index of the plate to clear")] int plateIndex)
|
|
{
|
|
var plate = _session.GetPlate(plateIndex);
|
|
|
|
if (plate == null)
|
|
return $"Error: plate {plateIndex} not found";
|
|
|
|
var count = plate.Parts.Count;
|
|
plate.Parts.Clear();
|
|
|
|
return $"Cleared plate {plateIndex}: removed {count} parts";
|
|
}
|
|
}
|
|
}
|