feat: serialize/deserialize cut-off definitions in nest file format

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-22 19:40:01 -04:00
parent d58a446eac
commit 2f19f47a85
4 changed files with 164 additions and 2 deletions
+10
View File
@@ -62,6 +62,7 @@ namespace OpenNest.IO
public MaterialDto Material { get; init; } = new();
public SpacingDto EdgeSpacing { get; init; } = new();
public List<PartDto> Parts { get; init; } = new();
public List<CutOffDto> CutOffs { get; init; } = new();
}
public record PartDto
@@ -72,6 +73,15 @@ namespace OpenNest.IO
public double Rotation { get; init; }
}
public record CutOffDto
{
public double X { get; init; }
public double Y { get; init; }
public string Axis { get; init; } = "vertical";
public double? StartLimit { get; init; }
public double? EndLimit { get; init; }
}
public record SizeDto
{
public double Width { get; init; }
+19
View File
@@ -197,6 +197,25 @@ namespace OpenNest.IO
plate.Parts.Add(part);
}
// Cut-offs
if (p.CutOffs != null)
{
foreach (var cutoffDto in p.CutOffs)
{
var axis = cutoffDto.Axis?.ToLowerInvariant() == "horizontal"
? CutOffAxis.Horizontal
: CutOffAxis.Vertical;
var cutoff = new CutOff(new Vector(cutoffDto.X, cutoffDto.Y), axis)
{
StartLimit = cutoffDto.StartLimit,
EndLimit = cutoffDto.EndLimit
};
plate.CutOffs.Add(cutoff);
}
plate.RegenerateCutOffs(new CutOffSettings());
}
nest.Plates.Add(plate);
}
+16 -2
View File
@@ -152,7 +152,7 @@ namespace OpenNest.IO
{
var plate = nest.Plates[i];
var parts = new List<PartDto>();
foreach (var part in plate.Parts)
foreach (var part in plate.Parts.Where(p => !p.BaseDrawing.IsCutOff))
{
var match = drawingDict.Where(dwg => dwg.Value == part.BaseDrawing).FirstOrDefault();
parts.Add(new PartDto
@@ -164,6 +164,19 @@ namespace OpenNest.IO
});
}
var cutoffs = new List<CutOffDto>();
foreach (var cutoff in plate.CutOffs)
{
cutoffs.Add(new CutOffDto
{
X = cutoff.Position.X,
Y = cutoff.Position.Y,
Axis = cutoff.Axis == CutOffAxis.Vertical ? "vertical" : "horizontal",
StartLimit = cutoff.StartLimit,
EndLimit = cutoff.EndLimit
});
}
list.Add(new PlateDto
{
Id = i + 1,
@@ -185,7 +198,8 @@ namespace OpenNest.IO
Right = plate.EdgeSpacing.Right,
Bottom = plate.EdgeSpacing.Bottom
},
Parts = parts
Parts = parts,
CutOffs = cutoffs
});
}
return list;