mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-13 01:21:55 -04:00
104 lines
2.9 KiB
C#
104 lines
2.9 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace OpenNest.Mcp
|
|
{
|
|
public class NestSession
|
|
{
|
|
public Nest Nest { get; set; }
|
|
public List<Plate> Plates { get; } = new();
|
|
public List<Drawing> Drawings { get; } = new();
|
|
|
|
/// <summary>
|
|
/// Whole-job engine <c>autonest_plate</c> uses when a call does not pass an explicit
|
|
/// <c>engine</c> argument; fill tools default to the Fill strategy instead. Instance state
|
|
/// only — the process-global legacy registry is never read or written.
|
|
/// </summary>
|
|
public string DefaultEngineName { get; set; } = "Default";
|
|
|
|
public Plate GetPlate(int index)
|
|
{
|
|
if (index < 0)
|
|
return null;
|
|
|
|
if (Nest != null && index < Nest.Plates.Count)
|
|
return Nest.Plates[index];
|
|
|
|
var adjustedIndex = index - (Nest?.Plates.Count ?? 0);
|
|
if (adjustedIndex >= 0 && adjustedIndex < Plates.Count)
|
|
return Plates[adjustedIndex];
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>Remove only a genuinely unused sheet; loaded sheets precede appended sheets.</summary>
|
|
public bool TryDeleteEmptyPlate(int index, out string reason)
|
|
{
|
|
var plate = GetPlate(index);
|
|
if (plate == null)
|
|
{
|
|
reason = $"plate {index} not found";
|
|
return false;
|
|
}
|
|
|
|
if (plate.Parts.Count != 0)
|
|
{
|
|
reason = $"plate {index} is occupied";
|
|
return false;
|
|
}
|
|
|
|
if (plate.CutOffs.Count != 0)
|
|
{
|
|
reason = $"plate {index} has cutoff definitions";
|
|
return false;
|
|
}
|
|
|
|
var loadedCount = Nest?.Plates.Count ?? 0;
|
|
if (index < loadedCount)
|
|
Nest.Plates.RemoveAt(index);
|
|
else
|
|
Plates.RemoveAt(index - loadedCount);
|
|
|
|
reason = null;
|
|
return true;
|
|
}
|
|
|
|
public Drawing GetDrawing(string name)
|
|
{
|
|
if (Nest != null)
|
|
{
|
|
foreach (var d in Nest.Drawings)
|
|
{
|
|
if (d.Name == name)
|
|
return d;
|
|
}
|
|
}
|
|
|
|
foreach (var d in Drawings)
|
|
{
|
|
if (d.Name == name)
|
|
return d;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public List<Plate> AllPlates()
|
|
{
|
|
var all = new List<Plate>();
|
|
if (Nest != null)
|
|
all.AddRange(Nest.Plates);
|
|
all.AddRange(Plates);
|
|
return all;
|
|
}
|
|
|
|
public List<Drawing> AllDrawings()
|
|
{
|
|
var all = new List<Drawing>();
|
|
if (Nest != null)
|
|
all.AddRange(Nest.Drawings);
|
|
all.AddRange(Drawings);
|
|
return all;
|
|
}
|
|
}
|
|
}
|