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

Commit

Permalink
[2021/09/18]
Browse files Browse the repository at this point in the history
* Leader entitities with less than two vertices will be deleted when loading a DXF file.
* (fixed) Changed the default DxfDocument comment to show that netDxf is licensed under MIT.
* (fixed) Possible out of range error for the LuPrec header variable when reading a DXF file. Out of range values will default to 4.
* (fixed) When writing a DXF file the codes for the dimension style overrides TolerancesLowerLimit and TolerancesUpperLimit were switched.
* (fixed) Error in the ShapeStyle when trying to get the a shape name from a specified number.
* (fixed) The default linetype will be given to a layer state if the specified one in the DXF is not found. This will affect linetypes that comes from externally referenced drawings.
* (fixed) Complex linetypes assigned to a layer were not properly initialized.
  • Loading branch information
haplokuon committed Sep 18, 2021
1 parent e1b64e9 commit 06e4a3f
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 117 deletions.
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

### [2021/09/18]
* Leader entitities with less than two vertices will be deleted when loading a DXF file.
* (fixed) Changed the default DxfDocument comment to show that netDxf is licensed under MIT.
* (fixed) Possible out of range error for the LuPrec header variable when reading a DXF file. Out of range values will default to 4.
* (fixed) When writing a DXF file the codes for the dimension style overrides TolerancesLowerLimit and TolerancesUpperLimit were switched.
* (fixed) Error in the ShapeStyle when trying to get the a shape name from a specified number.
* (fixed) The default linetype will be given to a layer state if the specified one in the DXF is not found. This will affect linetypes that comes from externally referenced drawings.
* (fixed) Complex linetypes assigned to a layer were not properly initialized.

### [2021/06/20]
* Loading AutoCad2000 (AC1015) or AutoCad2004 (AC1018) DXF files containing non-ASCII characters will work once again. Additionally the Net Standard 2.1 build requires a reference to the external library "System.Text.Encoding.CodePages".

Expand Down
2 changes: 1 addition & 1 deletion netDxf/Collections/Linetypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal override Linetype Add(Linetype linetype, bool assignHandle)
}
if (segment.Type == LinetypeSegmentType.Shape)
{
LinetypeShapeSegment shapeSegment = (LinetypeShapeSegment)segment;
LinetypeShapeSegment shapeSegment = (LinetypeShapeSegment) segment;
shapeSegment.Style = this.Owner.ShapeStyles.Add(shapeSegment.Style);
this.Owner.ShapeStyles.References[shapeSegment.Style.Name].Add(linetype);
if (!shapeSegment.Style.ContainsShapeName(shapeSegment.Name))
Expand Down
2 changes: 1 addition & 1 deletion netDxf/DxfDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal DxfDocument(HeaderVariables drawingVariables, bool createDefaultObjects
{
this.supportFolders = new SupportFolders(supportFolders);
this.buildDimensionBlocks = false;
this.comments = new List<string> { "DXF file generated by netDxf https://github.com/haplokuon/netDxf, Copyright(C) 2009-2021 Daniel Carvajal, Licensed under LGPL" };
this.comments = new List<string> { "DXF file generated by netDxf https://github.com/haplokuon/netDxf, Copyright(C) 2009-2021 Daniel Carvajal, Licensed under MIT" };
this.Owner = null;
this.drawingVariables = drawingVariables;
this.NumHandles = this.AssignHandle(0);
Expand Down
136 changes: 75 additions & 61 deletions netDxf/Entities/Leader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ protected virtual void OnDimensionStyleOverrideRemovedEvent(DimensionStyleOverri
private AciColor lineColor;
private double elevation;
private Vector2 offset;
private Vector2 direction;
private readonly DimensionStyleOverrideDictionary styleOverrides;

#endregion
Expand All @@ -124,6 +125,11 @@ public Leader(IEnumerable<Vector2> vertexes)
/// <param name="vertexes">List of leader vertexes in local coordinates.</param>
/// <param name="style">Leader style.</param>
public Leader(IEnumerable<Vector2> vertexes, DimensionStyle style)
: this(vertexes, style, false)
{
}

internal Leader(IEnumerable<Vector2> vertexes, DimensionStyle style, bool hasHookline)
: base(EntityType.Leader, DxfObjectCode.Leader)
{
if (vertexes == null)
Expand All @@ -138,13 +144,14 @@ public Leader(IEnumerable<Vector2> vertexes, DimensionStyle style)
}

this.style = style ?? throw new ArgumentNullException(nameof(style));
this.hasHookline = false;
this.hasHookline = hasHookline;
this.showArrowhead = true;
this.pathType = LeaderPathType.StraightLineSegments;
this.annotation = null;
this.lineColor = AciColor.ByLayer;
this.elevation = 0.0;
this.offset = Vector2.Zero;
this.direction = Vector2.UnitX;
this.styleOverrides = new DimensionStyleOverrideDictionary();
this.styleOverrides.BeforeAddItem += this.StyleOverrides_BeforeAddItem;
this.styleOverrides.AddItem += this.StyleOverrides_AddItem;
Expand Down Expand Up @@ -172,6 +179,8 @@ public Leader(string text, IEnumerable<Vector2> vertexes, DimensionStyle style)
: this(vertexes, style)
{
this.Annotation = this.BuildAnnotation(text);
this.CalculateAnnotationDirection();

}

/// <summary>
Expand Down Expand Up @@ -413,13 +422,65 @@ public Vector2 Offset
}

/// <summary>
/// Gets the leader annotation direction.
/// Gets or sets the leader annotation direction.
/// </summary>
public Vector2 Direction
{
get
get { return this.direction; }
set { this.direction = Vector2.Normalize(value); }
}

#endregion

#region public methods

/// <summary>
/// Updates the leader entity to reflect the latest changes made to its properties.
/// </summary>
/// <param name="resetAnnotationPosition">
/// If true the annotation position will be modified according to the position of the leader hook (last leader vertex),
/// otherwise the leader hook will be moved according to the actual annotation position.
/// </param>
/// <remarks>
/// This method should be manually called if the annotation position is modified, or the leader properties like Style, Annotation, TextVerticalPosition, and/or Offset.
/// </remarks>
public void Update(bool resetAnnotationPosition)
{
if (this.vertexes.Count < 2)
{
double angle = 0.0;
throw new Exception("The leader vertexes list requires at least two points.");
}

if (this.annotation == null)
{
return;
}

this.CalculateAnnotationDirection();

if (resetAnnotationPosition)
{
this.ResetAnnotationPosition();
}
else
{
this.ResetHookPosition();
}

if (this.hasHookline)
{
Vector2 vertex = this.CalculateHookLine();
this.vertexes[this.vertexes.Count - 2] = vertex;
}
}

#endregion

#region private methods

private void CalculateAnnotationDirection()
{
double angle = 0.0;

if (this.annotation != null)
{
Expand Down Expand Up @@ -460,56 +521,28 @@ public Vector2 Direction
throw new ArgumentException("Only MText, Text, Insert, and Tolerance entities are supported as a leader annotation.", nameof(this.annotation));
}
}
return Vector2.Rotate(Vector2.UnitX, angle * MathHelper.DegToRad);
}
this.direction = Vector2.Rotate(Vector2.UnitX, angle * MathHelper.DegToRad);
}

#endregion

#region public methods

/// <summary>
/// Updates the leader entity to reflect the latest changes made to its properties.
/// </summary>
/// <param name="resetAnnotationPosition">
/// If true the annotation position will be modified according to the position of the leader hook (last leader vertex),
/// otherwise the leader hook will be moved according to the actual annotation position.
/// </param>
/// <remarks>
/// This method should be manually called if the annotation position is modified, or the leader properties like Style, Annotation, TextVerticalPosition, and/or Offset.
/// </remarks>
public void Update(bool resetAnnotationPosition)
private Vector2 CalculateHookLine()
{
if (this.vertexes.Count < 2)
{
throw new Exception("The leader vertexes list requires at least two points.");
}
DimensionStyleOverride styleOverride;

if (this.annotation == null)
double dimScale = this.Style.DimScaleOverall;
if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.DimScaleOverall, out styleOverride))
{
return;
dimScale = (double) styleOverride.Value;
}

if (resetAnnotationPosition)
{
this.ResetAnnotationPosition();
}
else
double arrowSize = this.Style.ArrowSize;
if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.ArrowSize, out styleOverride))
{
this.ResetHookPosition();
arrowSize = (double) styleOverride.Value;
}

if (this.hasHookline)
{
Vector2 vertex = this.CalculateHookLine();
this.vertexes[this.vertexes.Count - 2] = vertex;
}
return this.Hook - this.Direction * arrowSize * dimScale;
}

#endregion

#region private methods

/// <summary>
/// Resets the leader hook position according to the annotation position.
/// </summary>
Expand Down Expand Up @@ -891,25 +924,6 @@ private Tolerance BuildAnnotation(ToleranceEntry tolerance)
};
}

private Vector2 CalculateHookLine()
{
DimensionStyleOverride styleOverride;

double dimScale = this.Style.DimScaleOverall;
if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.DimScaleOverall, out styleOverride))
{
dimScale = (double) styleOverride.Value;
}

double arrowSize = this.Style.ArrowSize;
if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.ArrowSize, out styleOverride))
{
arrowSize = (double) styleOverride.Value;
}

return this.Hook - this.Direction * arrowSize * dimScale;
}

#endregion

#region overrides
Expand Down
2 changes: 2 additions & 0 deletions netDxf/Entities/SplineVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public SplineVertex(Vector3 position)
public SplineVertex(Vector3 position, double weight)
{
if (weight <= 0)
{
throw new ArgumentOutOfRangeException(nameof(weight), weight, "The spline vertex weight must be greater than zero.");
}
this.position = position;
this.weight = weight;
}
Expand Down
Loading

0 comments on commit 06e4a3f

Please sign in to comment.