feat: add DrawingDxfExporter to convert PEP Drawing to DXF stream
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="ACadSharp" Version="3.1.32" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PepLib.Core\PepLib.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user