Skip to content

Commit

Permalink
Merge pull request #516 from DomCR/issue-515_net-framework-fix
Browse files Browse the repository at this point in the history
Issue 515 net framework fix
  • Loading branch information
DomCR authored Dec 26, 2024
2 parents 41c47b7 + f1515dc commit d2df0c8
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 27 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
}
}
2 changes: 1 addition & 1 deletion src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ private CadTemplate readBlockVisibilityParameter()
for (int i = 0; i < totalEntitiesCount; i++)
{
var handle = this.handleReference();
template.TotalEntityHandles.Add(handle, null);
template.EntityHandles.Add(handle);
}

// DXF 92 Sub blocks count (no property)
Expand Down
36 changes: 21 additions & 15 deletions src/ACadSharp/IO/Templates/BlockVisibilityParameterTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@
using ACadSharp.Entities;
using ACadSharp.Objects;

namespace ACadSharp.IO.Templates {
namespace ACadSharp.IO.Templates
{

internal class BlockVisibilityParameterTemplate : CadTemplate<BlockVisibilityParameter> {
internal class BlockVisibilityParameterTemplate : CadTemplate<BlockVisibilityParameter>
{

public BlockVisibilityParameterTemplate(BlockVisibilityParameter cadObject)
: base(cadObject) {
: base(cadObject)
{
}

public IDictionary<ulong, Entity> TotalEntityHandles { get; } = new Dictionary<ulong, Entity>();
public List<ulong> EntityHandles { get; } = new ();

public IDictionary<BlockVisibilityParameter.SubBlock, IList<ulong>> SubBlockHandles { get; } = new Dictionary<BlockVisibilityParameter.SubBlock, IList<ulong>>();

public override void Build(CadDocumentBuilder builder) {
public override void Build(CadDocumentBuilder builder)
{
base.Build(builder);

foreach (var cadObjectHandle in this.TotalEntityHandles) {
ulong handle = cadObjectHandle.Key;
if (builder.TryGetCadObject(handle, out Entity entity)) {
this.TotalEntityHandles[handle] = entity;
foreach (var handle in this.EntityHandles)
{
if (builder.TryGetCadObject(handle, out Entity entity))
{
this.CadObject.Entities.Add(entity);
}
}

foreach (var subGroup in this.CadObject.SubBlocks) {
if (this.SubBlockHandles.TryGetValue(subGroup, out IList<ulong> subBlockHandles)) {
foreach (ulong handle in subBlockHandles) {
if (this.TotalEntityHandles.TryGetValue(handle, out Entity entity)) {
foreach (var subGroup in this.CadObject.SubBlocks)
{
if (this.SubBlockHandles.TryGetValue(subGroup, out IList<ulong> subBlockHandles))
{
foreach (ulong handle in subBlockHandles)
{
if (builder.TryGetCadObject(handle, out Entity entity))
{
subGroup.Entities.Add(entity);
}
else if (builder.TryGetCadObject(handle, out Entity entityX)) {
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ACadSharp/MathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace ACadSharp
{
[Obsolete("Use CSMath.MathHelper instead.")]
public static class MathUtils
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/CSUtilities

0 comments on commit d2df0c8

Please sign in to comment.