feat: replace XML nest file format with JSON (v2)
Replace three separate XML metadata files (info, drawing-info, plate-info) and per-plate G-code placement files with a single nest.json inside the ZIP archive. Programs remain as G-code text under a programs/ folder. This eliminates ~400 lines of hand-written XML read/write code and fragile ID-based dictionary linking. Now uses System.Text.Json with DTO records for clean serialization. Also adds Priority and Constraints fields to drawing serialization (previously omitted). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace OpenNest.IO
|
||||
{
|
||||
public static class NestFormat
|
||||
{
|
||||
public static readonly JsonSerializerOptions JsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
public record NestDto
|
||||
{
|
||||
public int Version { get; init; } = 2;
|
||||
public string Name { get; init; } = "";
|
||||
public string Units { get; init; } = "Inches";
|
||||
public string Customer { get; init; } = "";
|
||||
public string DateCreated { get; init; } = "";
|
||||
public string DateLastModified { get; init; } = "";
|
||||
public string Notes { get; init; } = "";
|
||||
public PlateDefaultsDto PlateDefaults { get; init; } = new();
|
||||
public List<DrawingDto> Drawings { get; init; } = new();
|
||||
public List<PlateDto> Plates { get; init; } = new();
|
||||
}
|
||||
|
||||
public record PlateDefaultsDto
|
||||
{
|
||||
public SizeDto Size { get; init; } = new();
|
||||
public double Thickness { get; init; }
|
||||
public int Quadrant { get; init; } = 1;
|
||||
public double PartSpacing { get; init; }
|
||||
public MaterialDto Material { get; init; } = new();
|
||||
public SpacingDto EdgeSpacing { get; init; } = new();
|
||||
}
|
||||
|
||||
public record DrawingDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public string Name { get; init; } = "";
|
||||
public string Customer { get; init; } = "";
|
||||
public ColorDto Color { get; init; } = new();
|
||||
public QuantityDto Quantity { get; init; } = new();
|
||||
public int Priority { get; init; }
|
||||
public ConstraintsDto Constraints { get; init; } = new();
|
||||
public MaterialDto Material { get; init; } = new();
|
||||
public SourceDto Source { get; init; } = new();
|
||||
}
|
||||
|
||||
public record PlateDto
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public SizeDto Size { get; init; } = new();
|
||||
public double Thickness { get; init; }
|
||||
public int Quadrant { get; init; } = 1;
|
||||
public int Quantity { get; init; } = 1;
|
||||
public double PartSpacing { get; init; }
|
||||
public MaterialDto Material { get; init; } = new();
|
||||
public SpacingDto EdgeSpacing { get; init; } = new();
|
||||
public List<PartDto> Parts { get; init; } = new();
|
||||
}
|
||||
|
||||
public record PartDto
|
||||
{
|
||||
public int DrawingId { get; init; }
|
||||
public double X { get; init; }
|
||||
public double Y { get; init; }
|
||||
public double Rotation { get; init; }
|
||||
}
|
||||
|
||||
public record SizeDto
|
||||
{
|
||||
public double Width { get; init; }
|
||||
public double Height { get; init; }
|
||||
}
|
||||
|
||||
public record MaterialDto
|
||||
{
|
||||
public string Name { get; init; } = "";
|
||||
public string Grade { get; init; } = "";
|
||||
public double Density { get; init; }
|
||||
}
|
||||
|
||||
public record SpacingDto
|
||||
{
|
||||
public double Left { get; init; }
|
||||
public double Top { get; init; }
|
||||
public double Right { get; init; }
|
||||
public double Bottom { get; init; }
|
||||
}
|
||||
|
||||
public record ColorDto
|
||||
{
|
||||
public int A { get; init; } = 255;
|
||||
public int R { get; init; }
|
||||
public int G { get; init; }
|
||||
public int B { get; init; }
|
||||
}
|
||||
|
||||
public record QuantityDto
|
||||
{
|
||||
public int Required { get; init; }
|
||||
}
|
||||
|
||||
public record ConstraintsDto
|
||||
{
|
||||
public double StepAngle { get; init; }
|
||||
public double StartAngle { get; init; }
|
||||
public double EndAngle { get; init; }
|
||||
public bool Allow180Equivalent { get; init; }
|
||||
}
|
||||
|
||||
public record SourceDto
|
||||
{
|
||||
public string Path { get; init; } = "";
|
||||
public OffsetDto Offset { get; init; } = new();
|
||||
}
|
||||
|
||||
public record OffsetDto
|
||||
{
|
||||
public double X { get; init; }
|
||||
public double Y { get; init; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user