Skip to content

Commit

Permalink
dxf placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Dec 1, 2023
1 parent 65d1d9b commit 3e3b877
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
52 changes: 38 additions & 14 deletions ACadSharp.Tests/IO/DWG/DwgWriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public class DwgWriterSingleObjectTests : IOTestsBase
{
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();
Expand All @@ -29,14 +32,16 @@ public override string ToString()

public void Empty() { }

public void SinglePoint()
public void DefaultLayer()
{
this.Document.Entities.Add(new Point(XYZ.Zero));
this.Document.Layers.Add(new ACadSharp.Tables.Layer("default_layer"));
}

public void DefaultLayer()
public void SingleLine()
{
this.Document.Layers.Add(new ACadSharp.Tables.Layer("default_layer"));
Line line = new Line(XYZ.Zero, new XYZ(100, 100, 0));

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

public void SingleMText()
Expand All @@ -48,6 +53,11 @@ public void SingleMText()
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));
Expand All @@ -74,55 +84,69 @@ static DwgWriterSingleObjectTests()
}

Data.Add(new(nameof(SingleCaseGenerator.Empty)));
Data.Add(new(nameof(SingleCaseGenerator.SinglePoint)));
Data.Add(new(nameof(SingleCaseGenerator.SingleLine)));
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)
{
this.writeFile(data, ACadVersion.AC1018);
this.writeDwgFile(data, ACadVersion.AC1018);
}

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

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

[Theory()]
[MemberData(nameof(Data))]
public void WriteCasesAC1032(SingleCaseGenerator data)
{
this.writeFile(data, ACadVersion.AC1032);
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 writeFile(SingleCaseGenerator data, ACadVersion version)
private void writeDwgFile(SingleCaseGenerator data, ACadVersion version)
{
if (!TestVariables.RunDwgWriterSingleCases)
return;

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

data.Document.Header.Version = version;
DwgWriter.Write(this.getPath(data.Name, version), data.Document, this.onNotification);
DwgWriter.Write(path, data.Document, this.onNotification);

this.checkDwgDocumentInAutocad(path);
}

private string getPath(string name, ACadVersion version)
private string getPath(string name, string ext, ACadVersion version)
{
return Path.Combine(_singleCasesOutFolder, $"{name}_{version}.dwg");
return Path.Combine(_singleCasesOutFolder, $"{name}_{version}.{ext}");
}
}
}
11 changes: 11 additions & 0 deletions ACadSharp/Entities/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,16 @@ public class Line : Entity
/// Default constructor
/// </summary>
public Line() : base() { }

/// <summary>
/// Constructor with the start and end
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
public Line(XYZ start, XYZ end) : base()
{
this.StartPoint = start;
this.EndPoint = end;
}
}
}

0 comments on commit 3e3b877

Please sign in to comment.