Skip to content

Commit

Permalink
Merge pull request #253 from DomCR/Tolerance-text-format-fix
Browse files Browse the repository at this point in the history
Tolerance text format fix
  • Loading branch information
DomCR authored Jan 26, 2024
2 parents 0c3d598 + bb233c8 commit 34d244a
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 147 deletions.
129 changes: 3 additions & 126 deletions ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
@@ -1,124 +1,14 @@
using ACadSharp.Entities;
using ACadSharp.IO;
using ACadSharp.Tables;
using CSMath;
using ACadSharp.IO;
using System.IO;
using Xunit;
using Xunit.Abstractions;

namespace ACadSharp.Tests.IO.DWG
{
public class DwgWriterSingleObjectTests : IOTestsBase
public class DwgWriterSingleObjectTests : WriterSingleObjectTests
{
public class SingleCaseGenerator : IXunitSerializable
{
private const string _dxfExt = "dxf";
private const string _dwgExt = "dwg";

public string Name { get; private set; }

public CadDocument Document { get; private set; } = new CadDocument();

public SingleCaseGenerator() { }

public SingleCaseGenerator(string name)
{
this.Name = name;
}

public override string ToString()
{
return this.Name;
}

public void Empty() { }

public void DefaultLayer()
{
this.Document.Layers.Add(new Layer("default_layer"));
}

public void EntityColorByLayer()
{
Layer layer = new Layer("Test");
layer.Color = new Color(25);
this.Document.Layers.Add(layer);

Circle c = new Circle();
c.Center = new XYZ(0, 0, 0);
c.Radius = 10;
c.Layer = layer;
c.Color = Color.ByLayer;

this.Document.Entities.Add(c);
}

public void EntityColorTrueColor()
{
Circle c = new Circle();
c.Center = new XYZ(0, 0, 0);
c.Radius = 10;
c.Color = Color.FromTrueColor(1151726);

this.Document.Entities.Add(c);
}


public void SingleLine()
{
Line line = new Line(XYZ.Zero, new XYZ(100, 100, 0));

this.Document.Entities.Add(line);
}

public void SingleMText()
{
MText mtext = new MText();

mtext.Value = "HELLO I'm an MTEXT";

this.Document.Entities.Add(mtext);
}

public void SinglePoint()
{
this.Document.Entities.Add(new Point(XYZ.Zero));
}

public void Deserialize(IXunitSerializationInfo info)
{
this.Name = info.GetValue<string>(nameof(this.Name));
this.GetType().GetMethod(this.Name).Invoke(this, null);
}

public void Serialize(IXunitSerializationInfo info)
{
info.AddValue(nameof(this.Name), this.Name);
}
}

public static readonly TheoryData<SingleCaseGenerator> Data;

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

static DwgWriterSingleObjectTests()
{
Data = new();
if (!TestVariables.RunDwgWriterSingleCases)
{
Data.Add(new(nameof(SingleCaseGenerator.Empty)));
return;
}

Data.Add(new(nameof(SingleCaseGenerator.Empty)));
Data.Add(new(nameof(SingleCaseGenerator.SingleLine)));
Data.Add(new(nameof(SingleCaseGenerator.EntityColorByLayer)));
Data.Add(new(nameof(SingleCaseGenerator.EntityColorTrueColor)));
Data.Add(new(nameof(SingleCaseGenerator.DefaultLayer)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMText)));
Data.Add(new(nameof(SingleCaseGenerator.SinglePoint)));
}

[Theory()]
[MemberData(nameof(Data))]
public void WriteCasesAC1018(SingleCaseGenerator data)
Expand All @@ -133,7 +23,7 @@ public void WriteCasesAC1024(SingleCaseGenerator data)
this.writeDwgFile(data, ACadVersion.AC1024);
}

[Theory()]
[Theory(Skip = "AC1027 not stable")]
[MemberData(nameof(Data))]
public void WriteCasesAC1027(SingleCaseGenerator data)
{
Expand All @@ -147,19 +37,6 @@ public void WriteCasesAC1032(SingleCaseGenerator data)
this.writeDwgFile(data, ACadVersion.AC1032);
}

private void writeDxfFile(SingleCaseGenerator data, ACadVersion version)
{
if (!TestVariables.RunDwgWriterSingleCases)
return;

string path = this.getPath(data.Name, "dxf", version);

data.Document.Header.Version = version;
DxfWriter.Write(path, data.Document, false, this.onNotification);

this.checkDxfDocumentInAutocad(path);
}

private void writeDwgFile(SingleCaseGenerator data, ACadVersion version)
{
if (!TestVariables.RunDwgWriterSingleCases)
Expand Down
65 changes: 65 additions & 0 deletions ACadSharp.Tests/IO/DXF/DxfWriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using ACadSharp.IO;
using System.IO;
using Xunit;
using Xunit.Abstractions;

namespace ACadSharp.Tests.IO.DXF
{
public class DxfWriterSingleObjectTests : WriterSingleObjectTests
{
public DxfWriterSingleObjectTests(ITestOutputHelper output) : base(output) { }

[Theory()]
[MemberData(nameof(Data))]
public void WriteCasesAC1018(SingleCaseGenerator data)
{
this.writeDxfFile(data, ACadVersion.AC1018);
}

[Theory()]
[MemberData(nameof(Data))]
public void WriteCasesAC1021(SingleCaseGenerator data)
{
this.writeDxfFile(data, ACadVersion.AC1021);
}

[Theory()]
[MemberData(nameof(Data))]
public void WriteCasesAC1024(SingleCaseGenerator data)
{
this.writeDxfFile(data, ACadVersion.AC1024);
}

[Theory()]
[MemberData(nameof(Data))]
public void WriteCasesAC1027(SingleCaseGenerator data)
{
this.writeDxfFile(data, ACadVersion.AC1027);
}

[Theory()]
[MemberData(nameof(Data))]
public void WriteCasesAC1032(SingleCaseGenerator data)
{
this.writeDxfFile(data, ACadVersion.AC1032);
}

private void writeDxfFile(SingleCaseGenerator data, ACadVersion version)
{
if (!TestVariables.RunDwgWriterSingleCases)
return;

string path = this.getPath(data.Name, "dxf", version);

data.Document.Header.Version = version;
DxfWriter.Write(path, data.Document, false, this.onNotification);

this.checkDxfDocumentInAutocad(path);
}

private string getPath(string name, string ext, ACadVersion version)
{
return Path.Combine(_singleCasesOutFolder, $"{name}_{version}.{ext}");
}
}
}
137 changes: 137 additions & 0 deletions ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using ACadSharp.Entities;
using ACadSharp.Tables;
using CSMath;
using Xunit;
using Xunit.Abstractions;

namespace ACadSharp.Tests.IO
{
public abstract class WriterSingleObjectTests : IOTestsBase
{
public class SingleCaseGenerator : IXunitSerializable
{
public string Name { get; private set; }

public CadDocument Document { get; private set; } = new CadDocument();

public SingleCaseGenerator() { }

public SingleCaseGenerator(string name)
{
this.Name = name;
}

public override string ToString()
{
return this.Name;
}

public void Empty() { }

public void DefaultLayer()
{
this.Document.Layers.Add(new Layer("default_layer"));
}

public void EntityColorByLayer()
{
Layer layer = new Layer("Test");
layer.Color = new Color(25);
this.Document.Layers.Add(layer);

Circle c = new Circle();
c.Center = new XYZ(0, 0, 0);
c.Radius = 10;
c.Layer = layer;
c.Color = Color.ByLayer;

this.Document.Entities.Add(c);
}

public void EntityColorTrueColor()
{
Circle c = new Circle();
c.Center = new XYZ(0, 0, 0);
c.Radius = 10;
c.Color = Color.FromTrueColor(1151726);

this.Document.Entities.Add(c);
}


public void SingleLine()
{
Line line = new Line(XYZ.Zero, new XYZ(100, 100, 0));

this.Document.Entities.Add(line);
}

public void SingleMText()
{
MText mtext = new MText();

mtext.Value = "HELLO I'm an MTEXT";

this.Document.Entities.Add(mtext);
}

public void SingleMTextSpecialCharacter()
{
MText mtext = new MText();

mtext.Value = "∅45,6";

this.Document.Entities.Add(mtext);
}

public void SingleMTextMultiline()
{
MText mtext = new MText();

mtext.Value = "HELLO I'm an MTEXT\n and I have multiple lines";

this.Document.Entities.Add(mtext);
}

public void SinglePoint()
{
this.Document.Entities.Add(new Point(XYZ.Zero));
}

public void Deserialize(IXunitSerializationInfo info)
{
this.Name = info.GetValue<string>(nameof(this.Name));
this.GetType().GetMethod(this.Name).Invoke(this, null);
}

public void Serialize(IXunitSerializationInfo info)
{
info.AddValue(nameof(this.Name), this.Name);
}
}

public static readonly TheoryData<SingleCaseGenerator> Data;

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

static WriterSingleObjectTests()
{
Data = new();
if (!TestVariables.RunDwgWriterSingleCases)
{
Data.Add(new(nameof(SingleCaseGenerator.Empty)));
return;
}

Data.Add(new(nameof(SingleCaseGenerator.Empty)));
Data.Add(new(nameof(SingleCaseGenerator.SingleLine)));
Data.Add(new(nameof(SingleCaseGenerator.EntityColorByLayer)));
Data.Add(new(nameof(SingleCaseGenerator.EntityColorTrueColor)));
Data.Add(new(nameof(SingleCaseGenerator.DefaultLayer)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMText)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMTextSpecialCharacter)));
Data.Add(new(nameof(SingleCaseGenerator.SingleMTextMultiline)));
Data.Add(new(nameof(SingleCaseGenerator.SinglePoint)));
}
}
}
2 changes: 2 additions & 0 deletions ACadSharp/CadUtils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using CSUtilities.Text;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace ACadSharp
{
Expand Down
1 change: 0 additions & 1 deletion ACadSharp/Entities/MText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using ACadSharp.Tables;
using CSMath;
using System;
using System.Collections.Generic;

namespace ACadSharp.Entities
{
Expand Down
11 changes: 0 additions & 11 deletions ACadSharp/IClonable.cs

This file was deleted.

Loading

0 comments on commit 34d244a

Please sign in to comment.