Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
DomCR committed Dec 30, 2024
2 parents db74549 + f0cbe70 commit af0d65d
Show file tree
Hide file tree
Showing 35 changed files with 515 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
uses: coverallsapp/github-action@v2
with:
github-token: ${{ github.token }}
files: src/ACadSharp.Tests/TestResults/coverage.info src/CSUtilities/CSUtilities.Tests/TestResults/coverage.info src/CSUtilities/CSMath.Tests/TestResults/coverage.info
files: src/ACadSharp.Tests/TestResults/coverage.net6.0.info src/CSUtilities/CSUtilities.Tests/TestResults/coverage.info src/CSUtilities/CSMath.Tests/TestResults/coverage.info
2 changes: 1 addition & 1 deletion src/ACadSharp.Tests/ACadSharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net48</TargetFrameworks>

<!-- Enable the MSTest runner, this is an opt-in feature -->
<EnableMSTestRunner>true</EnableMSTestRunner>
Expand Down
4 changes: 4 additions & 0 deletions src/ACadSharp.Tests/Common/DocumentIntegrity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void AssertBlockRecords(CadDocument doc)

public void AssertDocumentContent(CadDocument doc)
{
#if !NETFRAMEWORK
this._document = doc;
CadDocumentTree tree = System.Text.Json.JsonSerializer.Deserialize<CadDocumentTree>(
File.ReadAllText(Path.Combine(_folder, $"{doc.Header.Version}_tree.json"))
Expand All @@ -105,17 +106,20 @@ public void AssertDocumentContent(CadDocument doc)
this.assertTableContent(doc.UCSs, tree.UCSsTable);
this.assertTableContent(doc.Views, tree.ViewsTable);
this.assertTableContent(doc.VPorts, tree.VPortsTable);
#endif
}

public void AssertDocumentTree(CadDocument doc)
{
#if !NETFRAMEWORK
this._document = doc;
CadDocumentTree tree = System.Text.Json.JsonSerializer.Deserialize<CadDocumentTree>(
File.ReadAllText(Path.Combine(_folder, $"{doc.Header.Version}_tree.json"))
);

this.assertTableTree(doc.BlockRecords, tree.BlocksTable);
this.assertTableTree(doc.Layers, tree.LayersTable);
#endif
}

private void assertTable<T>(CadDocument doc, Table<T> table)
Expand Down
30 changes: 23 additions & 7 deletions src/ACadSharp.Tests/Entities/ArcTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@ public void CreateFromBulgeTest()

XY center = MathUtils.GetCenter(start, end, bulge, out double radius);

#if NETFRAMEWORK
center = MathHelper.FixZero(center);
#endif

Assert.Equal(XY.Zero, center);
Assert.Equal(1, radius);
Assert.Equal(1, radius, TestVariables.DecimalPrecision);

Arc arc = Arc.CreateFromBulge(start, end, bulge);

#if NETFRAMEWORK
arc.Center = MathHelper.FixZero(arc.Center);
#endif

Assert.Equal(XYZ.Zero, arc.Center);
Assert.Equal(1, arc.Radius);
Assert.Equal(0, arc.StartAngle);
Assert.Equal(Math.PI / 2, arc.EndAngle);
Assert.Equal(1, arc.Radius, TestVariables.DecimalPrecision);
Assert.Equal(0, arc.StartAngle, TestVariables.DecimalPrecision);
Assert.Equal(Math.PI / 2, arc.EndAngle, TestVariables.DecimalPrecision);
}

[Fact]
Expand All @@ -52,14 +60,22 @@ public void GetCenter()

XY center = MathUtils.GetCenter(start, end, bulge);

#if NETFRAMEWORK
center = MathHelper.FixZero(center);
#endif

Assert.Equal(XY.Zero, center);

Arc arc = Arc.CreateFromBulge(start, end, bulge);

#if NETFRAMEWORK
arc.Center = MathHelper.FixZero(arc.Center);
#endif

Assert.Equal(XYZ.Zero, arc.Center);
Assert.Equal(1, arc.Radius);
Assert.Equal(0, arc.StartAngle);
Assert.Equal(Math.PI / 2, arc.EndAngle);
Assert.Equal(1, arc.Radius, TestVariables.DecimalPrecision);
Assert.Equal(0, arc.StartAngle, TestVariables.DecimalPrecision);
Assert.Equal(Math.PI / 2, arc.EndAngle, TestVariables.DecimalPrecision);
}

[Fact]
Expand Down
4 changes: 3 additions & 1 deletion src/ACadSharp.Tests/IO/DXF/DxfReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public override void AssertDocumentTree(FileModel test)
doc = reader.Read();
}

if(doc.Header.Version < ACadVersion.AC1012)
if (doc.Header.Version < ACadVersion.AC1012)
{
//Older version do not keep the handles for tables and other objects like block_records
return;
Expand All @@ -135,6 +135,7 @@ public override void AssertDocumentTree(FileModel test)
this._docIntegrity.AssertDocumentTree(doc);
}

#if !NETFRAMEWORK
[Theory]
[MemberData(nameof(DxfAsciiFiles))]
[MemberData(nameof(DxfBinaryFiles))]
Expand All @@ -161,5 +162,6 @@ public void IsBinaryTest(FileModel test)
}
}
}
#endif
}
}
26 changes: 26 additions & 0 deletions src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ACadSharp.Entities;
using ACadSharp.Objects;
using ACadSharp.Tables;
using ACadSharp.XData;
using CSMath;
using CSUtilities.Extensions;
using System;
Expand Down Expand Up @@ -468,6 +469,30 @@ public void AddBlockWithAttributes()
this.Document.Entities.Add(insert);
}

public void XData()
{
AppId app = new AppId("my_app");
Layer layer = new Layer("my_layer");
this.Document.AppIds.Add(app);
this.Document.Layers.Add(layer);

Line line = new Line(XYZ.Zero, new XYZ(100, 100, 0));

List<ExtendedDataRecord> records = new();
records.Add(new ExtendedDataControlString(false));
records.Add(new ExtendedDataInteger16(5));
records.Add(new ExtendedDataInteger32(33));
records.Add(new ExtendedDataString("my extended data string"));
records.Add(new ExtendedDataHandle(5));
records.Add(new ExtendedDataLayer(layer.Handle));
records.Add(new ExtendedDataBinaryChunk(new byte[] { 1, 2, 3, 4 }));
records.Add(new ExtendedDataControlString(true));

line.ExtendedData.Add(app, records);

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

public void Deserialize(IXunitSerializationInfo info)
{
this.Name = info.GetValue<string>(nameof(this.Name));
Expand Down Expand Up @@ -525,6 +550,7 @@ static WriterSingleObjectTests()
Data.Add(new(nameof(SingleCaseGenerator.AddCustomScale)));
Data.Add(new(nameof(SingleCaseGenerator.AddCustomBookColor)));
Data.Add(new(nameof(SingleCaseGenerator.Dimensions)));
Data.Add(new(nameof(SingleCaseGenerator.XData)));
}

protected string getPath(string name, string ext, ACadVersion version)
Expand Down
2 changes: 1 addition & 1 deletion src/ACadSharp/ACadSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<PackageOutputPath>../nupkg</PackageOutputPath>
</PropertyGroup>

Expand Down
8 changes: 6 additions & 2 deletions src/ACadSharp/CadObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ACadSharp.Objects.Collections;
using ACadSharp.Tables;
using ACadSharp.Tables.Collections;
using ACadSharp.XData;
using System;
using ACadSharp.XData;
using System.Collections.Generic;
Expand Down Expand Up @@ -72,7 +73,7 @@ internal set
/// <summary>
/// Extended data attached to this object
/// </summary>
public ExtendedDataDictionary ExtendedData { get; } = new ExtendedDataDictionary();
public ExtendedDataDictionary ExtendedData { get; }

/// <summary>
/// Document where this element belongs
Expand All @@ -88,7 +89,10 @@ public CadDocument Document
/// <summary>
/// Default constructor.
/// </summary>
public CadObject() { }
public CadObject()
{
this.ExtendedData = new ExtendedDataDictionary(this);
}

/// <summary>
/// Creates the extended dictionary if null.
Expand Down
72 changes: 48 additions & 24 deletions src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,17 +545,17 @@ private void readExtendedData(CadTemplate template)
long endPos = this._objectReader.Position + size;

//template.ExtendedData
ExtendedData edata = this.readExtendedDataRecords(endPos);
List<ExtendedDataRecord> edata = this.readExtendedDataRecords(endPos);

template.EDataTemplate.Add(appHandle, edata);

size = this._objectReader.ReadBitShort();
}
}

private ExtendedData readExtendedDataRecords(long endPos)
private List<ExtendedDataRecord> readExtendedDataRecords(long endPos)
{
ExtendedData data = new ExtendedData();
List<ExtendedDataRecord> records = new List<ExtendedDataRecord>();

while (this._objectReader.Position < endPos)
{
Expand All @@ -567,18 +567,18 @@ private ExtendedData readExtendedDataRecords(long endPos)
switch (dxfCode)
{
//0 (1000) String.
case DxfCode.ExtendedDataAsciiString:
//R13-R2004: 1st byte of value is the length N; this is followed by a 2-byte short indicating the codepage, followed by N single-byte characters.
//R2007 +: 2 - byte length N, followed by N Unicode characters(2 bytes each).
case DxfCode.ExtendedDataAsciiString:
case DxfCode.ExtendedDataRegAppName:
//1 (1001) This one seems to be invalid; can't even use as a string inside braces.
//This would be a registered application that this data relates to, but we've already had that above,
//so it would be redundant or irrelevant here.
record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadTextUnicode());
record = new ExtendedDataString(this._objectReader.ReadTextUnicode());
break;
case DxfCode.ExtendedDataControlString:
//2 (1002) A '{' or '}'; 1 byte; ASCII 0 means '{', ASCII 1 means '}'
record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadByte());
record = new ExtendedDataControlString(this._objectReader.ReadByte() == 1);
break;
case DxfCode.ExtendedDataLayerName:
//3 (1003) A layer table reference. The value is the handle of the layer;
Expand All @@ -587,11 +587,11 @@ private ExtendedData readExtendedDataRecords(long endPos)
//Even layer 0 is referred to by handle here.
byte[] arr = this._objectReader.ReadBytes(8);
ulong handle = BigEndianConverter.Instance.ToUInt64(arr);
record = new ExtendedDataRecord(dxfCode, handle);
record = new ExtendedDataLayer(handle);
break;
case DxfCode.ExtendedDataBinaryChunk:
//4 (1004) Binary chunk. The first byte of the value is a char giving the length; the bytes follow.
record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadBytes(this._objectReader.ReadByte()));
record = new ExtendedDataBinaryChunk(this._objectReader.ReadBytes(this._objectReader.ReadByte()));
break;
case DxfCode.ExtendedDataHandle:
//5 (1005) An entity handle reference.
Expand All @@ -600,22 +600,42 @@ private ExtendedData readExtendedDataRecords(long endPos)
//(There's no length specifier this time.)
arr = this._objectReader.ReadBytes(8);
handle = BigEndianConverter.Instance.ToUInt64(arr);
record = new ExtendedDataRecord(dxfCode, handle);
record = new ExtendedDataHandle(handle);
break;
//10 - 13 (1010 - 1013)
case DxfCode.ExtendedDataXCoordinate:
//Points; 24 bytes(XYZ)-- 3 doubles
record = new ExtendedDataCoordinate(
new XYZ(
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble()
)
);
break;
case DxfCode.ExtendedDataWorldXCoordinate:
case DxfCode.ExtendedDataWorldYCoordinate:
case DxfCode.ExtendedDataWorldZCoordinate:
//Points; 24 bytes(XYZ)-- 3 doubles
record = new ExtendedDataWorldCoordinate(
new XYZ(
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble()
)
);
break;
case DxfCode.ExtendedDataWorldXDisp:
case DxfCode.ExtendedDataWorldYDisp:
case DxfCode.ExtendedDataWorldZDisp:
//Points; 24 bytes(XYZ)-- 3 doubles
record = new ExtendedDataDisplacement(
new XYZ(
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble()
)
);
break;
case DxfCode.ExtendedDataWorldXDir:
case DxfCode.ExtendedDataWorldYDir:
case DxfCode.ExtendedDataWorldZDir:
//Points; 24 bytes(XYZ)-- 3 doubles
record = new ExtendedDataRecord(
dxfCode,
record = new ExtendedDataDirection(
new XYZ(
this._objectReader.ReadDouble(),
this._objectReader.ReadDouble(),
Expand All @@ -624,30 +644,34 @@ private ExtendedData readExtendedDataRecords(long endPos)
);
break;
//40 - 42 (1040 - 1042)
//Reals; 8 bytes(double)
case DxfCode.ExtendedDataReal:
record = new ExtendedDataReal(this._objectReader.ReadDouble());
break;
case DxfCode.ExtendedDataDist:
record = new ExtendedDataDistance(this._objectReader.ReadDouble());
break;
case DxfCode.ExtendedDataScale:
//Reals; 8 bytes(double)
record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadDouble());
record = new ExtendedDataScale(this._objectReader.ReadDouble());
break;
//70(1070) A short int; 2 bytes
case DxfCode.ExtendedDataInteger16:
record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadShort());
record = new ExtendedDataInteger16(this._objectReader.ReadShort());
break;
//71(1071) A long int; 4 bytes
case DxfCode.ExtendedDataInteger32:
record = new ExtendedDataRecord(dxfCode, this._objectReader.ReadRawLong());
record = new ExtendedDataInteger32((int)this._objectReader.ReadRawLong());
break;
default:
this._objectReader.ReadBytes((int)(endPos - this._objectReader.Position));
this._builder.Notify($"Unknown code for extended data: {dxfCode}", NotificationType.Warning);
return data;
return records;
}

data.Data.Add(record);
records.Add(record);
}

return data;
return records;
}

// Add the reactors to the template.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void WriteShiftValue()

public void WriteBytes(byte[] bytes, int offset, int length)
{
throw new NotImplementedException();
this.Main.WriteBytes(bytes, offset, length);
}

public void WriteEnColor(Color color, Transparency transparency, bool isBookColor)
Expand Down
Loading

0 comments on commit af0d65d

Please sign in to comment.