Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
[2022/11/01]
Browse files Browse the repository at this point in the history
* Workaround for bad DXF files that contain polyface with invalid geometry, they will be removed.
* Workaround for bad DXF files that contains entities without handles. This may derive in unexpected side effects.
* Workaround for bad DXF files lacking BLOCK_RECORD tables for the defined blocks. The default block record values will be given what may have other side effects.
* Workaround for possible duplicate layers in layer states properties when reading a DXF.
* The Ellipse SetAxis method will automatically assign the larger axis value as the major axis and the lower as the minor axis.
* Added NET 6.0 as a target framework.
* Updated netDxf solution for Visual Studio 2022. The solution file is still usable by Visual Studio 2019 but it does not support NET 6.0.
  • Loading branch information
haplokuon committed Nov 1, 2022
1 parent 7bff33a commit 922fb00
Show file tree
Hide file tree
Showing 24 changed files with 1,738 additions and 1,643 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public static void Main()
Are contained in the source code.
Well, at the moment they are just tests for the work in progress.
## Dependencies and distribution
Multitarget project, predefined frameworks for Net Framework 4.5, Net Standard 2.1, Net Core 3.1, and NET 5.0.
Multitarget project, predefined frameworks for Net Framework 4.5, Net Standard 2.1, Net Core 3.1, NET 5.0, and NET 6.0.
Additionally the Net Standard 2.1 build requires a reference to the external library "System.Text.Encoding.CodePages".
## Compiling
Visual Studio 2019.
Visual Studio 2022. The solution file is still usable by Visual Studio 2019 but it does not support NET 6.0.
## Development Status
See [changelog.txt](https://github.com/haplokuon/netDxf/blob/master/doc/Changelog.txt) or the [wiki page](https://github.com/haplokuon/netDxf/wiki) for information on the latest changes.
## Supported DXF entities
Expand All @@ -51,7 +51,7 @@ See [changelog.txt](https://github.com/haplokuon/netDxf/blob/master/doc/Changelo
* Ellipse
* Hatch (including Gradient patterns)
* Image
* Insert (block references and attributes)
* Insert (block references and attributes, dynamic blocks are not supported)
* Leader
* Line
* LwPolyline (light weight polyline)
Expand Down
2,565 changes: 1,162 additions & 1,403 deletions TestDxfDocument/Program.cs

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions TestDxfDocument/TestDxfDocument.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Authors />
<Company />
<Product />
Expand All @@ -12,14 +12,17 @@
<DocumentationFile></DocumentationFile>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<DefineConstants>TRACE</DefineConstants>
<NoWarn>1701;1702</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
<NoWarn>1701;1702;CA1416</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions doc/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## Change history

### [2022/11/01]
* Workaround for bad DXF files that contain polyface with invalid geometry, they will be removed.
* Workaround for bad DXF files that contains entities without handles. This may derive in unexpected side effects.
* Workaround for bad DXF files lacking BLOCK_RECORD tables for the defined blocks. The default block record values will be given what may have other side effects.
* Workaround for possible duplicate layers in layer states properties when reading a DXF.
* The Ellipse SetAxis method will automatically assign the larger axis value as the major axis and the lower as the minor axis.
* Added NET 6.0 as a target framework.
* Updated netDxf solution for Visual Studio 2022. The solution file is still usable by Visual Studio 2019 but it does not support NET 6.0.

### [2022/05/27]
* Added the Matrix3.Reflection method that builds a reflection matrix for a mirror plane that passes through the origin. See sample ReflectionMatrix().
* Added the Matrix4.Reflection method that builds a reflection matrix for a mirror plane that passes through an arbitrary point. See sample ReflectionMatrix().
Expand Down
4 changes: 2 additions & 2 deletions netDxf.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "netDxf", "netDxf\netDxf.csproj", "{AB0B1738-826F-41BF-ACD0-92BB9421B48B}"
EndProject
Expand Down
11 changes: 10 additions & 1 deletion netDxf/Blocks/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,22 @@ public AttributeDefinitionDictionary AttributeDefinitions
get { return this.attributes; }
}

/// <summary>
/// Gets the owner of the actual DXF object.
/// </summary>
public new BlockRecord Owner
{
get { return (BlockRecord) base.Owner; }
internal set { base.Owner = value; }
}

/// <summary>
/// Gets the block record associated with this block.
/// </summary>
/// <remarks>It returns the same object as the owner property.</remarks>
public BlockRecord Record
{
get { return (BlockRecord) this.Owner; }
get { return this.Owner; }
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion netDxf/Collections/DrawingEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public bool Remove(EntityObject entity)
{
return false;
}

// if an entity belongs to a document always has a handle
Debug.Assert(entity.Handle != null, "The entity has no handle.");

Expand Down
6 changes: 1 addition & 5 deletions netDxf/Collections/TableObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ protected TableObjects(DxfDocument document, string codeName, string handle)
/// <remarks>Table object names are case insensitive.</remarks>
public T this[string name]
{
get
{
T item;
return this.list.TryGetValue(name, out item) ? item : null;
}
get { return this.list.TryGetValue(name, out T item) ? item : null; }
}

/// <summary>
Expand Down
66 changes: 32 additions & 34 deletions netDxf/Entities/Ellipse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ public Ellipse()
/// <param name="center">Ellipse <see cref="Vector2">center</see> in object coordinates.</param>
/// <param name="majorAxis">Ellipse major axis.</param>
/// <param name="minorAxis">Ellipse minor axis.</param>
/// <remarks>The center Z coordinate represents the elevation of the arc along the normal.</remarks>
/// <remarks>
/// The center Z coordinate represents the elevation of the ellipse along the normal.
/// The major axis is always measured along the ellipse local X axis,
/// while the minor axis is along the local Y axis.
/// </remarks>
public Ellipse(Vector2 center, double majorAxis, double minorAxis)
: this(new Vector3(center.X, center.Y, 0.0), majorAxis, minorAxis)
{
Expand All @@ -229,7 +233,11 @@ public Ellipse(Vector2 center, double majorAxis, double minorAxis)
/// <param name="center">Ellipse <see cref="Vector3">center</see> in object coordinates.</param>
/// <param name="majorAxis">Ellipse major axis.</param>
/// <param name="minorAxis">Ellipse minor axis.</param>
/// <remarks>The center Z coordinate represents the elevation of the arc along the normal.</remarks>
/// <remarks>
/// The center Z coordinate represents the elevation of the ellipse along the normal.
/// The major axis is always measured along the ellipse local X axis,
/// while the minor axis is along the local Y axis.
/// </remarks>
public Ellipse(Vector3 center, double majorAxis, double minorAxis)
: base(EntityType.Ellipse, DxfObjectCode.Ellipse)
{
Expand Down Expand Up @@ -274,35 +282,19 @@ public Vector3 Center
/// <summary>
/// Gets or sets the ellipse mayor axis.
/// </summary>
/// <remarks>The MajorAxis value must be positive and greater than the MinorAxis.</remarks>
/// <remarks>The major axis is always measured along the ellipse local X axis.</remarks>
public double MajorAxis
{
get { return this.majorAxis; }
//set
//{
// if (value <= 0)
// {
// throw new ArgumentOutOfRangeException(nameof(value), value, "The major axis value must be greater than zero.");
// }
// this.majorAxis = value;
//}
}

/// <summary>
/// Gets or sets the ellipse minor axis.
/// </summary>
/// <remarks>The MinorAxis value must be positive and smaller than the MajorAxis.</remarks>
/// <remarks>The minor axis is always measured along the ellipse local Y axis.</remarks>
public double MinorAxis
{
get { return this.minorAxis; }
//set
//{
// if (value <= 0)
// {
// throw new ArgumentOutOfRangeException(nameof(value), value, "The minor axis value must be greater than zero.");
// }
// this.minorAxis = value;
//}
}

/// <summary>
Expand Down Expand Up @@ -357,29 +349,35 @@ public bool IsFullEllipse
#region public methods

/// <summary>
/// Sets the ellipse major and minor axis.
/// Sets the ellipse major and minor axis from the two parameters.
/// </summary>
/// <param name="major">Ellipse major axis.</param>
/// <param name="minor">Ellipse minor axis.</param>
public void SetAxis(double major, double minor)
/// <param name="axis1">Ellipse axis.</param>
/// <param name="axis2">Ellipse axis.</param>
/// <remarks>
/// It is not required that axis1 is greater than axis2. The larger value will be assigned as major axis and the lower as minor axis.
/// </remarks>
public void SetAxis(double axis1, double axis2)
{
if (major <= 0)
if (axis1 <= 0)
{
throw new ArgumentOutOfRangeException(nameof(major), major, "The major axis value must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(axis1), axis1, "The axis value must be greater than zero.");
}

if (minor <= 0)
if (axis2 <= 0)
{
throw new ArgumentOutOfRangeException(nameof(minor), minor, "The minor axis value must be greater than zero.");
throw new ArgumentOutOfRangeException(nameof(axis2), axis2, "The axis value must be greater than zero.");
}

if ( minor > major)
if (axis2 > axis1)
{
throw new ArgumentException("The ellipse major axis must be greater than the minor axis.");
this.majorAxis = axis2;
this.minorAxis = axis1;
}
else
{
this.majorAxis = axis1;
this.minorAxis = axis2;
}

this.majorAxis = major;
this.minorAxis = minor;
}

/// <summary>
Expand Down Expand Up @@ -581,7 +579,7 @@ public override void TransformBy(Matrix3 transformation, Vector3 translation)
axis2 = MathHelper.IsZero(axis2) ? MathHelper.Epsilon : axis2;

this.Center = transformation * this.Center + translation;
this.SetAxis(axis2, axis1);
this.SetAxis(axis1, axis2);
this.Rotation = newRotation * MathHelper.RadToDeg;
this.Normal = newNormal;
}
Expand Down
3 changes: 1 addition & 2 deletions netDxf/Entities/HatchGradientPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public bool Centered

private AciColor Color2FromTint(double value)
{
double h, s, l;
AciColor.ToHsl(this.color1, out h, out s, out l);
AciColor.ToHsl(this.color1, out double h, out double s, out double _);
return AciColor.FromHsl(h, s, value);
}

Expand Down
6 changes: 3 additions & 3 deletions netDxf/Entities/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public short Brightness
get { return this.brightness; }
set
{
if (value < 0 && value > 100)
if (value < 0 || value > 100)
{
throw new ArgumentOutOfRangeException(nameof(value), value, "Accepted brightness values range from 0 to 100.");
}
Expand All @@ -292,7 +292,7 @@ public short Contrast
get { return this.contrast; }
set
{
if (value < 0 && value > 100)
if (value < 0 || value > 100)
{
throw new ArgumentOutOfRangeException(nameof(value), value, "Accepted contrast values range from 0 to 100.");
}
Expand All @@ -308,7 +308,7 @@ public short Fade
get { return this.fade; }
set
{
if (value < 0 && value > 100)
if (value < 0 || value > 100)
{
throw new ArgumentOutOfRangeException(nameof(value), value, "Accepted fade values range from 0 to 100.");
}
Expand Down
2 changes: 1 addition & 1 deletion netDxf/Entities/Leader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ private void ResetAnnotationPosition()

position = hook + this.offset + Vector2.Rotate(textOffset, mText.Rotation * MathHelper.DegToRad);

mText.Position = MathHelper.Transform(position, Normal, this.elevation);
mText.Position = MathHelper.Transform(position, this.Normal, this.elevation);
mText.Height = textHeight * dimScale;
mText.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor;
break;
Expand Down
4 changes: 2 additions & 2 deletions netDxf/Entities/PolyfaceMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public PolyfaceMesh(IEnumerable<Vector3> vertexes, IEnumerable<short[]> faces)

if (faces == null)
{
throw new ArgumentNullException(nameof(vertexes));
throw new ArgumentNullException(nameof(faces));
}

int numFaces = faces.Count();
Expand Down Expand Up @@ -125,7 +125,7 @@ public PolyfaceMesh(IEnumerable<Vector3> vertexes, IEnumerable<PolyfaceMeshFace>

if (faces == null)
{
throw new ArgumentNullException(nameof(vertexes));
throw new ArgumentNullException(nameof(faces));
}

this.faces = faces.ToArray();
Expand Down
9 changes: 1 addition & 8 deletions netDxf/Header/HeaderVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -684,14 +684,7 @@ public TimeSpan TdinDwg
public UCS CurrentUCS
{
get { return this.currentUCS; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
this.currentUCS = value;
}
set { this.currentUCS = value ?? throw new ArgumentNullException(nameof(value)); }
}

#endregion
Expand Down
Loading

0 comments on commit 922fb00

Please sign in to comment.