Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TABLE Entity implementation #314

Merged
merged 31 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Binary file added samples/table_samples/table_AC1032.dwg
Binary file not shown.
18,932 changes: 18,932 additions & 0 deletions samples/table_samples/table_AC1032.dxf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ACadSharp.Tests/IO/ColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ColorTests(ITestOutputHelper output) : base(output)

[Theory]
[MemberData(nameof(ColorSamplesFilePaths))]
public void ColorDwg(FileModel test)
public void BasicColorTest(FileModel test)
{
bool isDxf = Path.GetExtension(test.FileName).Equals(".dxf");
CadDocument doc = this.readDocument(test);
Expand Down
22 changes: 19 additions & 3 deletions src/ACadSharp.Tests/IO/IOTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,32 @@ protected bool isSupportedVersion(ACadVersion version)
}
}

protected CadDocument readDocument(FileModel test)
protected CadDocument readDocument(FileModel test, CadReaderConfiguration configuration = null)
{
CadDocument doc;
if (Path.GetExtension(test.FileName).Equals(".dxf"))
{
doc = DxfReader.Read(test.Path, this.onNotification);
using (DxfReader dxfReader = new DxfReader(test.Path, this.onNotification))
{
if (configuration != null)
{
dxfReader.Configuration = (DxfReaderConfiguration)configuration;
}

doc = dxfReader.Read();
}
}
else
{
doc = DwgReader.Read(test.Path, this.onNotification);
using (DwgReader dxfReader = new DwgReader(test.Path, this.onNotification))
{
if (configuration != null)
{
dxfReader.Configuration = (DwgReaderConfiguration)configuration;
}

doc = dxfReader.Read();
}
}

return doc;
Expand Down
4 changes: 0 additions & 4 deletions src/ACadSharp.Tests/IO/LocalSampleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public void ReadUserDwg(FileModel test)
return;

CadDocument doc = DwgReader.Read(test.Path, this._dwgConfiguration, this.onNotification);

var trees = doc.Entities.Where(e => e is Insert insert
&& insert.Block.Name == "TREE_1"
&& e.Layer.Name.Equals("VEGETATION", System.StringComparison.OrdinalIgnoreCase));
}

[Theory]
Expand Down
65 changes: 65 additions & 0 deletions src/ACadSharp.Tests/IO/TableEntityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Xunit;
using Xunit.Abstractions;
using ACadSharp.Tests.TestModels;
using ACadSharp.Entities;
using System.Linq;
using ACadSharp.Tables;
using ACadSharp.IO;

namespace ACadSharp.Tests.IO
{
public class TableEntityTests : IOTestsBase
{
public static TheoryData<FileModel> TableSamplesFilePaths { get; } = new();

static TableEntityTests()
{
loadSamples("table_samples", "*", TableSamplesFilePaths);
}

public TableEntityTests(ITestOutputHelper output) : base(output)
{
}

[Theory]
[MemberData(nameof(TableSamplesFilePaths))]
public void ReadTableEntity(FileModel test)
{
CadReaderConfiguration configuration;

if (test.IsDxf)
{
configuration = new DxfReaderConfiguration();
}
else
{
configuration = new DwgReaderConfiguration();
}

configuration.KeepUnknownNonGraphicalObjects = true;

CadDocument doc = this.readDocument(test, configuration);

TableEntity table = (TableEntity)doc.Entities.First();

BlockRecord record = table.Block;

Assert.NotNull(record);
Assert.Equal("*T1", record.Name);

Assert.Equal(5, table.Columns.Count);
foreach (var column in table.Columns)
{
Assert.Equal(2.5, column.Width);
}

Assert.Equal(4, table.Rows.Count);
//First row
TableEntity.Cell titleCell = table.GetCell(0, 0);
Assert.False(titleCell.HasMultipleContent);
Assert.Equal("Hello this is a title", titleCell.Content.Value.Value);

TableEntity.Cell next = table.GetCell(0, 1);
}
}
}
2 changes: 2 additions & 0 deletions src/ACadSharp.Tests/TestModels/FileModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class FileModel : IXunitSerializable

public string Path { get; set; }

public bool IsDxf { get { return System.IO.Path.GetExtension(this.Path) == ".dxf"; } }

public FileModel()
{
this.FileName = string.Empty;
Expand Down
3 changes: 2 additions & 1 deletion src/ACadSharp/DxfFileToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static class DxfFileToken
public const string Entity3DFace = "3DFACE";
public const string Entity3DSolid = "3DSOLID";
public const string EntityProxyEntity = "ACAD_PROXY_ENTITY";
public const string EntityTable = "ACAD_TABLE";
public const string EntityArc = "ARC";
public const string EntityAttributeDefinition = "ATTDEF";
public const string EntityAttribute = "ATTRIB";
Expand Down Expand Up @@ -92,7 +93,6 @@ public static class DxfFileToken
public const string EntitySpline = "SPLINE";
public const string EntitySun = "SUN";
public const string EntitySurface = "SURFACE";
public const string EntityTable = "TABLE";
public const string EntityText = "TEXT";
public const string EntityTolerance = "TOLERANCE";
public const string EntityTrace = "TRACE";
Expand Down Expand Up @@ -128,6 +128,7 @@ public static class DxfFileToken
public const string ObjectMLeaderContextData = "CONTEXT_DATA";
public const string ObjectEvalGraph = "ACAD_EVALUATION_GRAPH";
public const string ObjectBlockVisibilityParameter = "BLOCKVISIBILITYPARAMETER";
public const string ObjectTableContent = "TABLECONTENT";

#endregion
}
Expand Down
2 changes: 2 additions & 0 deletions src/ACadSharp/DxfSubclassMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static class DxfSubclassMarker
public const string PolyfaceMeshFace = "AcDbFaceRecord";
public const string Shape = "AcDbShape";
public const string Solid = "AcDbTrace";
public const string TableEntity = "AcDbTable";
public const string Trace = "AcDbTrace";
public const string Text = "AcDbText";
public const string Tolerance = "AcDbFcf";
Expand Down Expand Up @@ -85,5 +86,6 @@ public static class DxfSubclassMarker
public const string EvalGraph = "AcDbEvalGraph";
public const string BlockVisibilityParameter = "AcDbBlockVisibilityParameter";
public const string DbColor = "AcDbColor";
public const string TableContent = "AcDbTableContent";
}
}
18 changes: 9 additions & 9 deletions src/ACadSharp/Entities/Insert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override ObjectType ObjectType
public override string SubclassMarker => DxfSubclassMarker.Insert;

/// <summary>
/// Gets the insert block definition
/// Gets the insert block definition.
/// </summary>
[DxfCodeValue(DxfReferenceType.Name, 2)]
public BlockRecord Block { get; internal set; }
Expand All @@ -53,19 +53,19 @@ public override ObjectType ObjectType
public XYZ InsertPoint { get; set; } = XYZ.Zero;

/// <summary>
/// X scale factor
/// X scale factor.
/// </summary>
[DxfCodeValue(41)]
public double XScale { get; set; } = 1;

/// <summary>
/// Y scale factor
/// Y scale factor.
/// </summary>
[DxfCodeValue(42)]
public double YScale { get; set; } = 1;

/// <summary>
/// Z scale factor
/// Z scale factor.
/// </summary>
[DxfCodeValue(43)]
public double ZScale { get; set; } = 1;
Expand All @@ -88,25 +88,25 @@ public override ObjectType ObjectType
/// <summary>
/// Column count
/// </summary>
[DxfCodeValue(70)]
[DxfCodeValue(DxfReferenceType.Optional, 70)]
public ushort ColumnCount { get; set; } = 1;

/// <summary>
/// Row count
/// </summary>
[DxfCodeValue(71)]
[DxfCodeValue(DxfReferenceType.Optional, 71)]
public ushort RowCount { get; set; } = 1;

/// <summary>
/// Column spacing
/// </summary>
[DxfCodeValue(44)]
[DxfCodeValue(DxfReferenceType.Optional, 44)]
public double ColumnSpacing { get; set; } = 0;

/// <summary>
/// Row spacing
/// </summary>
[DxfCodeValue(45)]
[DxfCodeValue(DxfReferenceType.Optional, 45)]
public double RowSpacing { get; set; } = 0;

/// <summary>
Expand Down Expand Up @@ -185,7 +185,7 @@ public override CadObject Clone()
{
Insert clone = (Insert)base.Clone();

clone.Block = (BlockRecord)this.Block.Clone();
clone.Block = (BlockRecord)this.Block?.Clone();

clone.Attributes = new SeqendCollection<AttributeEntity>(clone);
foreach (var att in this.Attributes)
Expand Down
17 changes: 17 additions & 0 deletions src/ACadSharp/Entities/TableEntity.BorderType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace ACadSharp.Entities
{
public partial class TableEntity
{
public enum BorderType : short
{
/// <summary>
/// Single border line.
/// </summary>
Single = 1,
/// <summary>
/// Double border line.
/// </summary>
Double = 2
}
}
}
22 changes: 22 additions & 0 deletions src/ACadSharp/Entities/TableEntity.BreakData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using CSMath;
using System.Collections.Generic;

namespace ACadSharp.Entities
{
public partial class TableEntity
{
internal class BreakData
{
internal struct BreakHeight
{
public XYZ Position { get; internal set; }
public double Height { get; internal set; }
}

public BreakOptionFlags Flags { get; internal set; }
public BreakFlowDirection FlowDirection { get; internal set; }
public double BreakSpacing { get; internal set; }
public List<BreakHeight> Heights { get; internal set; } = new List<BreakHeight>();
}
}
}
21 changes: 21 additions & 0 deletions src/ACadSharp/Entities/TableEntity.BreakFlowDirection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace ACadSharp.Entities
{
public partial class TableEntity
{
public enum BreakFlowDirection
{
/// <summary>
/// Right
/// </summary>
Right = 1,
/// <summary>
/// Vertical
/// </summary>
Vertical = 2,
/// <summary>
/// Left
/// </summary>
Left = 4
}
}
}
34 changes: 34 additions & 0 deletions src/ACadSharp/Entities/TableEntity.BreakOptionFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace ACadSharp.Entities
{
public partial class TableEntity
{
[System.Flags]
public enum BreakOptionFlags
{
/// <summary>
/// None
/// </summary>
None = 0,
/// <summary>
/// Enable breaks
/// </summary>
EnableBreaks = 1,
/// <summary>
/// Repeat top labels
/// </summary>
RepeatTopLabels = 2,
/// <summary>
/// Repeat bottom labels
/// </summary>
RepeatBottomLabels = 4,
/// <summary>
/// Allow manual positions
/// </summary>
AllowManualPositions = 8,
/// <summary>
/// Allow manual heights
/// </summary>
AllowManualHeights = 16
}
}
}
14 changes: 14 additions & 0 deletions src/ACadSharp/Entities/TableEntity.BreakRowRange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using CSMath;

namespace ACadSharp.Entities
{
public partial class TableEntity
{
internal class BreakRowRange
{
public XYZ Position { get; internal set; }
public int StartRowIndex { get; internal set; }
public int EndRowIndex { get; internal set; }
}
}
}
Loading