mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 07:19:24 -05:00
fix(mcp): keep machine, bed and common lines on save
save_nest rebuilt the nest without the loaded nest's machine, common-line usage and minimum remnant size, and re-adding plates reset their support bed. Building the nest moves to NestSession.Snapshot, which keeps them, so posting can share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
97c80b2c9b
commit
b21adf3226
2 files changed
+45
-24
No files matched your search
@@ -154,6 +154,47 @@ namespace OpenNest.Mcp
|
||||
return all;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A nest holding every drawing and plate in the session, with the loaded nest's header
|
||||
/// (material, thickness, units, defaults) or defaults when none is loaded. The drawings and
|
||||
/// plates are the session's own objects, not copies.
|
||||
/// </summary>
|
||||
public Nest Snapshot(string name)
|
||||
{
|
||||
name ??= Nest?.Name ?? "";
|
||||
var source = Nest;
|
||||
var nest = new Nest
|
||||
{
|
||||
Name = name,
|
||||
Customer = source?.Customer ?? "",
|
||||
Notes = source?.Notes ?? "",
|
||||
AssistGas = source?.AssistGas ?? "",
|
||||
Status = source?.Status ?? NestStatus.Quote,
|
||||
MadeBy = source?.MadeBy ?? "",
|
||||
Thickness = source?.Thickness ?? 0,
|
||||
Material = source?.Material ?? new Material(),
|
||||
Units = source?.Units ?? default,
|
||||
DateCreated = source?.DateCreated ?? default,
|
||||
DateLastModified = source?.DateLastModified ?? default,
|
||||
PlateDefaults = source?.PlateDefaults ?? new Nest.PlateSettings(),
|
||||
PlateOptions = source?.PlateOptions ?? new(),
|
||||
SalvageRate = source?.SalvageRate ?? 0.5,
|
||||
Machine = source?.Machine,
|
||||
CommonLineUsage = source?.CommonLineUsage ?? default,
|
||||
MinimumRemnantDimension = source?.MinimumRemnantDimension ?? Nest.DefaultMinimumRemnantDimension,
|
||||
};
|
||||
// Before the plates: adding a plate gives it the nest's bed, which must stay the loaded one.
|
||||
nest.SetSupportBed(source?.SupportBed);
|
||||
|
||||
foreach (var drawing in AllDrawings())
|
||||
nest.Drawings.Add(drawing);
|
||||
|
||||
foreach (var plate in AllPlates())
|
||||
nest.Plates.Add(plate);
|
||||
|
||||
return nest;
|
||||
}
|
||||
|
||||
public List<Drawing> AllDrawings()
|
||||
{
|
||||
var all = new List<Drawing>();
|
||||
|
||||
@@ -70,30 +70,7 @@ namespace OpenNest.Mcp.Tools
|
||||
[Description("Name for the nest (optional)")] string name = null
|
||||
)
|
||||
{
|
||||
var source = _session.Nest;
|
||||
var nest = new Nest
|
||||
{
|
||||
Name = name ?? (string.IsNullOrWhiteSpace(source?.Name) ? Path.GetFileNameWithoutExtension(path) : source.Name),
|
||||
Customer = source?.Customer ?? "",
|
||||
Notes = source?.Notes ?? "",
|
||||
AssistGas = source?.AssistGas ?? "",
|
||||
Status = source?.Status ?? NestStatus.Quote,
|
||||
MadeBy = source?.MadeBy ?? "",
|
||||
Thickness = source?.Thickness ?? 0,
|
||||
Material = source?.Material ?? new Material(),
|
||||
Units = source?.Units ?? default,
|
||||
DateCreated = source?.DateCreated ?? default,
|
||||
DateLastModified = source?.DateLastModified ?? default,
|
||||
PlateDefaults = source?.PlateDefaults ?? new Nest.PlateSettings(),
|
||||
PlateOptions = source?.PlateOptions ?? new(),
|
||||
SalvageRate = source?.SalvageRate ?? 0.5,
|
||||
};
|
||||
|
||||
foreach (var drawing in _session.AllDrawings())
|
||||
nest.Drawings.Add(drawing);
|
||||
|
||||
foreach (var plate in _session.AllPlates())
|
||||
nest.Plates.Add(plate);
|
||||
var nest = _session.Snapshot(name ?? DefaultName(path));
|
||||
|
||||
if (nest.Drawings.Count == 0)
|
||||
return "Error: no drawings in session to save";
|
||||
@@ -109,6 +86,9 @@ namespace OpenNest.Mcp.Tools
|
||||
return $"Saved nest to {path}\n Drawings: {nest.Drawings.Count}\n Plates: {nest.Plates.Count}";
|
||||
}
|
||||
|
||||
private string DefaultName(string path) =>
|
||||
string.IsNullOrWhiteSpace(_session.Nest?.Name) ? Path.GetFileNameWithoutExtension(path) : _session.Nest.Name;
|
||||
|
||||
[McpServerTool(Name = "import_dxf")]
|
||||
[Description("Import a DXF, DWG or SVG file as a new drawing. Returns drawing name and bounding box.")]
|
||||
public string ImportDxf(
|
||||
|
||||
Reference in new issue
Block a user