Build PepApi image / build-and-push (push) Successful in 45s
DrawLoop previously drew every entity onto the single loop layer, so scribe/display marks were indistinguishable from cuts in the exported DXF. Non-cut entity types now get their own layer, and ProgramReader now parses the SCRIBE marker into EntityType.Scribe so scribed moves route to their own layer instead of falling through as untyped cuts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
126 lines
4.9 KiB
C#
126 lines
4.9 KiB
C#
using PepLib.Codes;
|
|
using PepLib.Enums;
|
|
using PepLib.Geometry;
|
|
using PepLib.IO;
|
|
using PepLib.Models;
|
|
using Xunit;
|
|
|
|
namespace PepLib.Core.Tests.IO;
|
|
|
|
public class DrawingDxfExporterTests
|
|
{
|
|
[Fact]
|
|
public void Export_RectangularLoop_ProducesFourLines()
|
|
{
|
|
// Arrange: a square 10x10 in incremental mode
|
|
var drawing = new Drawing();
|
|
drawing.Info = new DrawingInfo { Name = "TEST" };
|
|
var loop = new Loop { Name = "TEST.loop-000" };
|
|
// Mode defaults to Incremental in Loop constructor
|
|
loop.Add(new RapidMove(new Vector(0, 0))); // position at (0,0)
|
|
loop.Add(new LinearMove(new Vector(10, 0))); // → (10,0)
|
|
loop.Add(new LinearMove(new Vector(0, 10))); // → (10,10)
|
|
loop.Add(new LinearMove(new Vector(-10, 0))); // → (0,10)
|
|
loop.Add(new LinearMove(new Vector(0, -10))); // → (0,0)
|
|
drawing.Loops.Add(loop);
|
|
|
|
// Act
|
|
using var stream = DrawingDxfExporter.Export(drawing);
|
|
|
|
// Assert: stream is non-empty and contains 4 line entities
|
|
Assert.True(stream.Length > 0);
|
|
|
|
stream.Position = 0;
|
|
using var reader = new ACadSharp.IO.DxfReader(stream);
|
|
var doc = reader.Read();
|
|
var lines = doc.Entities.OfType<ACadSharp.Entities.Line>().ToList();
|
|
var arcs = doc.Entities.OfType<ACadSharp.Entities.Arc>().ToList();
|
|
Assert.Equal(4, lines.Count);
|
|
Assert.Empty(arcs);
|
|
}
|
|
|
|
[Fact]
|
|
public void Export_LoopWithArc_ProducesLineAndArc()
|
|
{
|
|
var drawing = new Drawing();
|
|
drawing.Info = new DrawingInfo { Name = "TEST" };
|
|
var loop = new Loop { Name = "TEST.loop-000" };
|
|
loop.Add(new RapidMove(new Vector(5, 0))); // start at (5,0)
|
|
loop.Add(new LinearMove(new Vector(5, 0))); // → (10,0)
|
|
loop.Add(new CircularMove(new Vector(-5, 5), new Vector(-5, 0), RotationType.CCW)); // arc: end=(5,5), center=(5,0)
|
|
drawing.Loops.Add(loop);
|
|
|
|
using var stream = DrawingDxfExporter.Export(drawing);
|
|
|
|
stream.Position = 0;
|
|
using var reader = new ACadSharp.IO.DxfReader(stream);
|
|
var doc = reader.Read();
|
|
var lines = doc.Entities.OfType<ACadSharp.Entities.Line>().ToList();
|
|
var arcs = doc.Entities.OfType<ACadSharp.Entities.Arc>().ToList();
|
|
Assert.Single(lines);
|
|
Assert.Single(arcs);
|
|
var arc = doc.Entities.OfType<ACadSharp.Entities.Arc>().Single();
|
|
// Angles must be in degrees (0..360), not radians (0..6.28)
|
|
Assert.InRange(arc.StartAngle, 0, 360);
|
|
Assert.InRange(arc.EndAngle, 0, 360);
|
|
}
|
|
|
|
[Fact]
|
|
public void Export_NonCutLinearMove_IsDrawnOnDedicatedLayerInsteadOfDropped()
|
|
{
|
|
var drawing = new Drawing();
|
|
drawing.Info = new DrawingInfo { Name = "TEST" };
|
|
var loop = new Loop { Name = "TEST.loop-000" };
|
|
loop.Add(new RapidMove(new Vector(0, 0)));
|
|
loop.Add(new LinearMove(new Vector(10, 0)) { Type = EntityType.InternalLeadin });
|
|
drawing.Loops.Add(loop);
|
|
|
|
using var stream = DrawingDxfExporter.Export(drawing);
|
|
|
|
stream.Position = 0;
|
|
using var reader = new ACadSharp.IO.DxfReader(stream);
|
|
var doc = reader.Read();
|
|
var line = doc.Entities.OfType<ACadSharp.Entities.Line>().Single();
|
|
Assert.Equal("InternalLeadin", line.Layer.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void Export_NonCutCircularMove_IsDrawnOnDedicatedLayerInsteadOfCutLayer()
|
|
{
|
|
var drawing = new Drawing();
|
|
drawing.Info = new DrawingInfo { Name = "TEST" };
|
|
var loop = new Loop { Name = "TEST.loop-000" };
|
|
loop.Add(new RapidMove(new Vector(5, 0)));
|
|
loop.Add(new CircularMove(new Vector(-5, 5), new Vector(-5, 0), RotationType.CCW) { Type = EntityType.ExternalLeadout });
|
|
drawing.Loops.Add(loop);
|
|
|
|
using var stream = DrawingDxfExporter.Export(drawing);
|
|
|
|
stream.Position = 0;
|
|
using var reader = new ACadSharp.IO.DxfReader(stream);
|
|
var doc = reader.Read();
|
|
var arc = doc.Entities.OfType<ACadSharp.Entities.Arc>().Single();
|
|
Assert.Equal("ExternalLeadout", arc.Layer.Name);
|
|
Assert.NotEqual("TEST.loop-000", arc.Layer.Name);
|
|
}
|
|
|
|
[Fact]
|
|
public void Export_CutLinearMove_StaysOnLoopNamedLayer()
|
|
{
|
|
var drawing = new Drawing();
|
|
drawing.Info = new DrawingInfo { Name = "TEST" };
|
|
var loop = new Loop { Name = "TEST.loop-000" };
|
|
loop.Add(new RapidMove(new Vector(0, 0)));
|
|
loop.Add(new LinearMove(new Vector(10, 0)));
|
|
drawing.Loops.Add(loop);
|
|
|
|
using var stream = DrawingDxfExporter.Export(drawing);
|
|
|
|
stream.Position = 0;
|
|
using var reader = new ACadSharp.IO.DxfReader(stream);
|
|
var doc = reader.Read();
|
|
var line = doc.Entities.OfType<ACadSharp.Entities.Line>().Single();
|
|
Assert.Equal("TEST.loop-000", line.Layer.Name);
|
|
}
|
|
}
|