Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions src/ACadSharp.Tests/IO/DXF/DxfSurfaceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using ACadSharp.Entities;
using ACadSharp.IO;
using System.IO;
using System.Linq;
using System.Text;
using Xunit;

namespace ACadSharp.Tests.IO.DXF;

public class DxfSurfaceTests
Comment thread
DomCR marked this conversation as resolved.
Outdated
{
[Fact]
public void ReadGenericSurface()
{
CadDocument doc = readDxf(surfaceDxf("SURFACE", "AcDbSurface"));

Surface surface = Assert.IsType<Surface>(doc.Entities.Single());
Assert.Equal(6, surface.UIsolines);
Assert.Equal(7, surface.VIsolines);
Assert.Equal(SatHeader + "\n" + SatBody, surface.GetAcisText());
}

[Fact]
public void ReadPlaneSurface()
{
CadDocument doc = readDxf(surfaceDxf("PLANESURFACE", "AcDbSurface", "AcDbPlaneSurface"));

PlaneSurface surface = Assert.IsType<PlaneSurface>(doc.Entities.Single());
Assert.Equal(6, surface.UIsolines);
Assert.Equal(7, surface.VIsolines);
Assert.Equal(SatHeader + "\n" + SatBody, surface.GetAcisText());
}

[Fact]
public void ReadExtrudedSurface()
{
CadDocument doc = readDxf(surfaceDxf("EXTRUDEDSURFACE", "AcDbSurface", "AcDbExtrudedSurface"));

ExtrudedSurface surface = Assert.IsType<ExtrudedSurface>(doc.Entities.Single());
Assert.Equal(6, surface.UIsolines);
Assert.Equal(7, surface.VIsolines);
Assert.Equal(SatHeader + "\n" + SatBody, surface.GetAcisText());
}

[Fact]
public void ReadLoftedSurface()
{
CadDocument doc = readDxf(surfaceDxf("LOFTEDSURFACE", "AcDbSurface", "AcDbLoftedSurface"));

Assert.IsType<LoftedSurface>(doc.Entities.Single());
}

[Fact]
public void ReadRevolvedSurface()
{
CadDocument doc = readDxf(surfaceDxf("REVOLVEDSURFACE", "AcDbSurface", "AcDbRevolvedSurface"));

Assert.IsType<RevolvedSurface>(doc.Entities.Single());
}

[Fact]
public void ReadSweptSurface()
{
CadDocument doc = readDxf(surfaceDxf("SWEPTSURFACE", "AcDbSurface", "AcDbSweptSurface"));

Assert.IsType<SweptSurface>(doc.Entities.Single());
}

[Fact]
public void ReadNurbSurface()
{
CadDocument doc = readDxf(surfaceDxf("NURBSURFACE", "AcDbSurface", "AcDbNurbSurface"));

Assert.IsType<NurbSurface>(doc.Entities.Single());
}

private const string SatHeader = "400 0 1 0";

private const string SatBody = "body $-1 $1 $-1 $-1 #";

//A minimal entities section with one surface entity: the modeler geometry
//codes (70, 1, 3) carry the SAT text, the AcDbSurface codes 71 and 72 the
//isoline counts, followed by the empty subclass of the derived surface.
private static string surfaceDxf(string name, params string[] subclasses)
{
StringBuilder dxf = new StringBuilder();
void add(string code, string value)
{
dxf.Append(code).Append('\n').Append(value).Append('\n');
}

add("0", "SECTION");
add("2", "ENTITIES");
add("0", name);
add("5", "A1");
add("100", "AcDbEntity");
add("8", "0");
add("100", "AcDbModelerGeometry");
add("70", "1");
add("1", SatHeader);
add("1", SatBody);

foreach (string subclass in subclasses)
{
add("100", subclass);

if (subclass == "AcDbSurface")
{
add("71", "6");
add("72", "7");
}
}

add("0", "ENDSEC");
add("0", "EOF");

return dxf.ToString();
}

private static CadDocument readDxf(string dxf)
{
using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(dxf)))
using (DxfReader reader = new DxfReader(stream))
{
return reader.Read();
}
}
}
22 changes: 22 additions & 0 deletions src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ static WriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.XData)));
Data.Add(new(nameof(SingleCaseGenerator.XRef)));
Data.Add(new(nameof(SingleCaseGenerator.SPlineCreation)));
Data.Add(new(nameof(SingleCaseGenerator.SurfaceEntities)));
Data.Add(new(nameof(SingleCaseGenerator.TextAlignment)));
Data.Add(new(nameof(SingleCaseGenerator.InvalidEntities)));
Data.Add(new(nameof(SingleCaseGenerator.CreateXRecords)));
Expand Down Expand Up @@ -2676,6 +2677,27 @@ public void SPlineCreation()
};
}

public void SurfaceEntities()
{
Line line = new Line(XYZ.Zero, new XYZ(10, 10, 0));
this.Document.Entities.Add(line);

//Surfaces are not written yet, the writers skip them
this.Document.Entities.Add(new Surface());
this.Document.Entities.Add(new ExtrudedSurface());
this.Document.Entities.Add(new LoftedSurface());
this.Document.Entities.Add(new NurbSurface());
this.Document.Entities.Add(new PlaneSurface());
this.Document.Entities.Add(new RevolvedSurface());
this.Document.Entities.Add(new SweptSurface());

this.AssertRoundtrip = (doc) =>
{
Assert.NotNull(doc.GetCadObject<Line>(line.Handle));
Assert.Empty(doc.Entities.OfType<Surface>());
};
}

public void TextAlignment()
{
XYZ insert = new XYZ(0, 0, 0);
Expand Down
12 changes: 12 additions & 0 deletions src/ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public static class DxfFileToken

public const string EntityEllipse = "ELLIPSE";

public const string EntityExtrudedSurface = "EXTRUDEDSURFACE";

public const string EntityHatch = "HATCH";

public const string EntityHelix = "HELIX";
Expand All @@ -82,6 +84,8 @@ public static class DxfFileToken

public const string EntityLine = "LINE";

public const string EntityLoftedSurface = "LOFTEDSURFACE";

public const string EntityLwPolyline = "LWPOLYLINE";

public const string EntityMesh = "MESH";
Expand All @@ -92,12 +96,16 @@ public static class DxfFileToken

public const string EntityMultiLeader = "MULTILEADER";

public const string EntityNurbSurface = "NURBSURFACE";

public const string EntityOle2Frame = "OLE2FRAME";

public const string EntityOleFrame = "OLEFRAME";

public const string EntityPdfUnderlay = "PDFUNDERLAY";

public const string EntityPlaneSurface = "PLANESURFACE";

public const string EntityPoint = "POINT";

public const string EntityPolyFaceMesh = "PFACE";
Expand All @@ -110,6 +118,8 @@ public static class DxfFileToken

public const string EntityRegion = "REGION";

public const string EntityRevolvedSurface = "REVOLVEDSURFACE";

public const string EntitySection = "SECTION";

public const string EntitySeqend = "SEQEND";
Expand All @@ -124,6 +134,8 @@ public static class DxfFileToken

public const string EntitySurface = "SURFACE";

public const string EntitySweptSurface = "SWEPTSURFACE";

public const string EntityTable = "ACAD_TABLE";

public const string EntityText = "TEXT";
Expand Down
14 changes: 14 additions & 0 deletions src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public static class DxfSubclassMarker

public const string EvalGraphExpr = "AcDbEvalExpr";

public const string ExtrudedSurface = "AcDbExtrudedSurface";

public const string Face3d = "AcDbFace";

public const string Field = "AcDbField";
Expand Down Expand Up @@ -182,6 +184,8 @@ public static class DxfSubclassMarker

public const string LinkedTableData = "AcDbLinkedTableData";

public const string LoftedSurface = "AcDbLoftedSurface";

public const string LwPolyline = "AcDbPolyline";

public const string Material = "AcDbMaterial";
Expand All @@ -206,6 +210,8 @@ public static class DxfSubclassMarker

public const string MultiLeaderObjectContextData = "AcDbMLeaderObjectContextData";

public const string NurbSurface = "AcDbNurbSurface";

public const string ObjectContextData = "AcDbObjectContextData";

public const string Ole2Frame = "AcDbOle2Frame";
Expand All @@ -220,6 +226,8 @@ public static class DxfSubclassMarker

public const string PdfReference = "AcDbPdfReference";

public const string PlaneSurface = "AcDbPlaneSurface";

public const string PlotSettings = "AcDbPlotSettings";

public const string Point = "AcDbPoint";
Expand Down Expand Up @@ -258,6 +266,8 @@ public static class DxfSubclassMarker

public const string Ray = "AcDbRay";

public const string RevolvedSurface = "AcDbRevolvedSurface";

public const string Scale = "AcDbScale";

public const string Shape = "AcDbShape";
Expand All @@ -272,6 +282,10 @@ public static class DxfSubclassMarker

public const string Spline = "AcDbSpline";

public const string Surface = "AcDbSurface";

public const string SweptSurface = "AcDbSweptSurface";

public const string Table = "AcDbSymbolTable";

public const string TableContent = "AcDbTableContent";
Expand Down
37 changes: 37 additions & 0 deletions src/ACadSharp/Entities/ExtrudedSurface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ACadSharp.Attributes;
using ACadSharp.Classes;

namespace ACadSharp.Entities;

/// <summary>
/// Represents an <see cref="ExtrudedSurface"/> entity.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.EntityExtrudedSurface"/> <br/>
/// Dxf class name <see cref="DxfSubclassMarker.ExtrudedSurface"/>
/// </remarks>
[DxfName(DxfFileToken.EntityExtrudedSurface)]
[DxfSubClass(DxfSubclassMarker.ExtrudedSurface)]
public class ExtrudedSurface : Surface
{
/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityExtrudedSurface;

/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.ExtrudedSurface;

/// <inheritdoc/>
public override DxfClass GetDxfClass()
{
return new DxfClass
{
CppClassName = DxfSubclassMarker.ExtrudedSurface,
DwgVersion = (ACadVersion)26,
DxfName = DxfFileToken.EntityExtrudedSurface,
ItemClassId = 498,
MaintenanceVersion = 0,
ProxyFlags = ProxyFlags.None,
WasZombie = false,
};
}
}
37 changes: 37 additions & 0 deletions src/ACadSharp/Entities/LoftedSurface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ACadSharp.Attributes;
using ACadSharp.Classes;

namespace ACadSharp.Entities;

/// <summary>
/// Represents a <see cref="LoftedSurface"/> entity.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.EntityLoftedSurface"/> <br/>
/// Dxf class name <see cref="DxfSubclassMarker.LoftedSurface"/>
/// </remarks>
[DxfName(DxfFileToken.EntityLoftedSurface)]
[DxfSubClass(DxfSubclassMarker.LoftedSurface)]
public class LoftedSurface : Surface
{
/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityLoftedSurface;

/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.LoftedSurface;

/// <inheritdoc/>
public override DxfClass GetDxfClass()
{
return new DxfClass
{
CppClassName = DxfSubclassMarker.LoftedSurface,
DwgVersion = (ACadVersion)26,
DxfName = DxfFileToken.EntityLoftedSurface,
ItemClassId = 498,
MaintenanceVersion = 0,
ProxyFlags = ProxyFlags.None,
WasZombie = false,
};
}
}
37 changes: 37 additions & 0 deletions src/ACadSharp/Entities/NurbSurface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using ACadSharp.Attributes;
using ACadSharp.Classes;

namespace ACadSharp.Entities;

/// <summary>
/// Represents a <see cref="NurbSurface"/> entity.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.EntityNurbSurface"/> <br/>
/// Dxf class name <see cref="DxfSubclassMarker.NurbSurface"/>
/// </remarks>
[DxfName(DxfFileToken.EntityNurbSurface)]
[DxfSubClass(DxfSubclassMarker.NurbSurface)]
public class NurbSurface : Surface
{
/// <inheritdoc/>
public override string ObjectName => DxfFileToken.EntityNurbSurface;

/// <inheritdoc/>
public override string SubclassMarker => DxfSubclassMarker.NurbSurface;

/// <inheritdoc/>
public override DxfClass GetDxfClass()
{
return new DxfClass
{
CppClassName = DxfSubclassMarker.NurbSurface,
DwgVersion = (ACadVersion)26,
DxfName = DxfFileToken.EntityNurbSurface,
ItemClassId = 498,
MaintenanceVersion = 0,
ProxyFlags = (ProxyFlags)4095,
WasZombie = false,
};
}
}
Loading
Loading