Skip to content

Commit

Permalink
Merge pull request #307 from DomCR/MultiLeader-DwgReader-pre2010
Browse files Browse the repository at this point in the history
MultiLeader dwg reader pre2010
  • Loading branch information
DomCR authored Mar 12, 2024
2 parents a69a406 + e48f2cc commit 8e2ab5b
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 254 deletions.
41 changes: 29 additions & 12 deletions ACadSharp.Tests/IO/MultiLeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,36 @@ namespace ACadSharp.Tests.IO
{
public class MultiLeaderTests : IOTestsBase
{
public static TheoryData<string> MultiLeaderFilePaths { get; }

static MultiLeaderTests()
{
MultiLeaderFilePaths = new TheoryData<string>();
foreach (string p in Directory.GetFiles(Path.Combine($"{samplesFolder}", "multileader"), $"*.dwg"))
{
MultiLeaderFilePaths.Add(Path.GetFileName(p));
}
}

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

[Fact]
public void MultiLeaderDwg()
[Theory]
[MemberData(nameof(MultiLeaderFilePaths))]
public void MultiLeaderDwg(string path)
{
string inPath = Path.Combine($"{samplesFolder}", "multileader", "sample_MLeader_AC1032.dwg");
CadDocument doc = DwgReader.Read(inPath);
path = Path.Combine($"{samplesFolder}", "multileader", path);

CadDocument doc = DwgReader.Read(path);

// There are 14 multileaders in DWG file
Assert.Equal(14, doc.Entities.Count);

List<Entity> entities = new List<Entity>(doc.Entities);

MultiLeader multiLeader;

multiLeader = (MultiLeader)entities[0];
Assert.Equal(@"MULTILEADER TEST", multiLeader.ContextData.TextLabel);
Assert.Equal(TextAttachmentPointType.Left, multiLeader.TextAttachmentPoint);
Expand Down Expand Up @@ -130,13 +143,17 @@ public void MultiLeaderDwg()
Assert.Equal(8, multiLeader.LandingDistance);
Assert.Equal(TextAttachmentDirectionType.Horizontal, multiLeader.TextAttachmentDirection);

multiLeader = (MultiLeader)entities[13];
Assert.Equal(@"MULTILEADER TEST", multiLeader.ContextData.TextLabel);
Assert.Equal(TextAttachmentPointType.Left, multiLeader.TextAttachmentPoint);
Assert.Equal(TextAttachmentType.TopOfTopLine, multiLeader.TextLeftAttachment);
Assert.False(multiLeader.TextFrame);
Assert.Equal(8, multiLeader.LandingDistance);
Assert.Equal(TextAttachmentDirectionType.Vertical, multiLeader.TextAttachmentDirection);
if (doc.Header.Version > ACadVersion.AC1021)
{
//For some reason this entity is not compatible for versions before AC1021
multiLeader = (MultiLeader)entities[13];
Assert.Equal(@"MULTILEADER TEST", multiLeader.ContextData.TextLabel);
Assert.Equal(TextAttachmentPointType.Left, multiLeader.TextAttachmentPoint);
Assert.Equal(TextAttachmentType.TopOfTopLine, multiLeader.TextLeftAttachment);
Assert.False(multiLeader.TextFrame);
Assert.Equal(8, multiLeader.LandingDistance);
Assert.Equal(TextAttachmentDirectionType.Vertical, multiLeader.TextAttachmentDirection);
}
}
}
}
3 changes: 2 additions & 1 deletion ACadSharp/Entities/MultiLeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class ArrowheadAssociation {
/// <summary>
///
/// </summary>
public class BlockAttribute {
public class BlockAttribute
{
/// <summary>
/// Block Attribute Id
/// </summary>
Expand Down
27 changes: 16 additions & 11 deletions ACadSharp/IO/DWG/DwgSectionIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ internal abstract class DwgSectionIO
/// </summary>
protected bool R2004Pre;
/// <summary>
/// Pre-2007 Only
/// </summary>
protected bool R2007Pre;
/// <summary>
/// R2004+
/// </summary>
protected bool R2004Plus;
Expand All @@ -49,17 +53,18 @@ internal abstract class DwgSectionIO

public DwgSectionIO(ACadVersion version)
{
_version = version;
this._version = version;

R13_14Only = version == ACadVersion.AC1014 || version == ACadVersion.AC1012;
R13_15Only = version >= ACadVersion.AC1012 && version <= ACadVersion.AC1015;
R2000Plus = version >= ACadVersion.AC1015;
R2004Pre = version < ACadVersion.AC1018;
R2004Plus = version >= ACadVersion.AC1018;
R2007Plus = version >= ACadVersion.AC1021;
R2010Plus = version >= ACadVersion.AC1024;
R2013Plus = version >= ACadVersion.AC1027;
R2018Plus = version >= ACadVersion.AC1032;
this.R13_14Only = version == ACadVersion.AC1014 || version == ACadVersion.AC1012;
this.R13_15Only = version >= ACadVersion.AC1012 && version <= ACadVersion.AC1015;
this.R2000Plus = version >= ACadVersion.AC1015;
this.R2004Pre = version < ACadVersion.AC1018;
this.R2007Pre = version <= ACadVersion.AC1021;
this.R2004Plus = version >= ACadVersion.AC1018;
this.R2007Plus = version >= ACadVersion.AC1021;
this.R2010Plus = version >= ACadVersion.AC1024;
this.R2013Plus = version >= ACadVersion.AC1027;
this.R2018Plus = version >= ACadVersion.AC1032;
}

public static bool CheckSentinel(byte[] actual, byte[] expected)
Expand All @@ -83,7 +88,7 @@ protected void checkSentinel(IDwgStreamReader sreader, byte[] expected)
var sn = sreader.ReadSentinel();

if (!CheckSentinel(sn, expected))
this.notify($"Invalid section sentinel found in {SectionName}", NotificationType.Warning);
this.notify($"Invalid section sentinel found in {this.SectionName}", NotificationType.Warning);
}

protected void notify(string message, NotificationType type, Exception ex = null)
Expand Down
Loading

0 comments on commit 8e2ab5b

Please sign in to comment.