Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table entries clone fix #459

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ACadSharp.Tests/Tables/BlockRecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using ACadSharp.Tables;
using ACadSharp.Tests.Common;
using System;
using System.Linq;
using Xunit;

namespace ACadSharp.Tests.Tables
Expand Down
22 changes: 22 additions & 0 deletions src/ACadSharp.Tests/Tables/LayerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ACadSharp.Tables;
using ACadSharp.Tests.Common;
using Xunit;

namespace ACadSharp.Tests.Tables
{
public class LayerTests
{
[Fact]
public void CloneTest()
{
Layer layer = new Layer("my_layer");
layer.Color = new Color(23, 200, 200);

Layer clone = (Layer)layer.Clone();

CadObjectTestUtils.AssertTableEntryClone(layer, clone);

Assert.Equal(layer.Color, clone.Color);
}
}
}
11 changes: 0 additions & 11 deletions src/ACadSharp.Tests/Tables/TableEntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ public void Clone(Type entryType)
CadObjectTestUtils.AssertTableEntryClone(entry, clone);
}

[Theory]
[MemberData(nameof(TableEntryTypes))]
public void CloneUnattachEvent(Type t)
{
TableEntry entry = TableEntryFactory.Create(t);

TableEntry clone = (TableEntry)entry.Clone();

CadObjectTestUtils.AssertTableEntryClone(entry, clone);
}

[Fact()]
public void ChangeName()
{
Expand Down
3 changes: 2 additions & 1 deletion src/ACadSharp/Tables/AppId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public class AppId : TableEntry

internal AppId() : base() { }

/// <inheritdoc/>
public AppId(string name) : base(name)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException(nameof(name), "App id must have a name.");
throw new ArgumentNullException(nameof(name), "Application id must have a name.");
}
}
}
14 changes: 8 additions & 6 deletions src/ACadSharp/Tables/DimensionStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public class DimensionStyle : TableEntry
public short ToleranceDecimalPlaces { get; set; } = 2;

/// <summary>
/// Gets or sets the units format for alternate units of all dimension substyles
/// Gets or sets the units format for alternate units of all dimension sub-styles
/// except Angular
/// (see DIMALTU System Variable).
/// </summary>
Expand Down Expand Up @@ -665,8 +665,8 @@ public double TextHeight
/// Positive values of <i>LinearScaleFactor</i> are applied to dimensions in both model space and
/// paper space; negative values are applied to paper space only.
/// </para><para>
/// <i>LinearScaleFactor</i> applies primarily to nonassociative dimensions (DIMASSOC set 0 or 1).
/// For nonassociative dimensions in paper space, <i>LinearScaleFactor</i> must be set individually
/// <i>LinearScaleFactor</i> applies primarily to non-associative dimensions (DIMASSOC set 0 or 1).
/// For non-associative dimensions in paper space, <i>LinearScaleFactor</i> must be set individually
/// for each layout viewport to accommodate viewport scaling.
/// </para><para>
/// <i>LinearScaleFactor</i> has no effect on angular dimensions, and is not applied to the values held in
Expand Down Expand Up @@ -813,7 +813,7 @@ public double TextHeight
public TextDirection TextDirection { get; set; } = TextDirection.LeftToRight;

/// <summary>
/// Assigns lineweight to dimension lines
/// Assigns line weight to dimension lines
/// (see DIMLWD System Variable).
/// </summary>
/// <value>
Expand All @@ -824,7 +824,7 @@ public double TextHeight
public LineweightType DimensionLineWeight { get; set; } = LineweightType.ByBlock;

/// <summary>
/// Assigns lineweight to extension lines
/// Assigns line weight to extension lines
/// (see DIMLWE System Variable).
/// </summary>
/// <value>
Expand Down Expand Up @@ -960,12 +960,14 @@ public DimensionStyle(string name) : base(name) { }
/// <inheritdoc/>
public override CadObject Clone()
{
DimensionStyle clone = new DimensionStyle(this.Name);
DimensionStyle clone = (DimensionStyle)base.Clone();

clone.Style = (TextStyle)this.Style?.Clone();
clone.LeaderArrow = (BlockRecord)this.LeaderArrow?.Clone();
clone.ArrowBlock = (BlockRecord)this.ArrowBlock?.Clone();
clone.DimArrow1 = (BlockRecord)this.DimArrow1?.Clone();
clone.DimArrow2 = (BlockRecord)this.DimArrow2?.Clone();

return clone;
}

Expand Down
4 changes: 3 additions & 1 deletion src/ACadSharp/Tables/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ public Layer(string name) : base(name) { }
/// <inheritdoc/>
public override CadObject Clone()
{
Layer clone = new Layer(this.Name);
Layer clone = (Layer)base.Clone();

clone.LineType = (LineType)this.LineType.Clone();
clone.Material = (Material)(this.Material?.Clone());

return clone;
}

Expand Down
22 changes: 14 additions & 8 deletions src/ACadSharp/Tables/LineType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace ACadSharp.Tables
{
/// <summary>
/// Represents a <see cref="LineType"/> entry
/// Represents a <see cref="LineType"/> entry.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.TableLinetype"/> <br/>
Expand Down Expand Up @@ -38,13 +38,13 @@ public partial class LineType : TableEntry
public override string SubclassMarker => DxfSubclassMarker.Linetype;

/// <summary>
/// Descriptive text for linetype
/// Descriptive text for line type.
/// </summary>
[DxfCodeValue(3)]
public string Description { get; set; }

/// <summary>
/// Total pattern length
/// Total pattern length.
/// </summary>
[DxfCodeValue(40)]
public double PatternLen
Expand All @@ -56,16 +56,16 @@ public double PatternLen
}

/// <summary>
/// Alignment code
/// Alignment code.
/// </summary>
/// <value>
/// value is always 65, the ASCII code for A
/// value is always 65, the ASCII code for A.
/// </value>
[DxfCodeValue(72)]
public char Alignment { get; internal set; } = 'A';

/// <summary>
/// Linetype Segments
/// LineType Segments
/// </summary>
[DxfCodeValue(DxfReferenceType.Count, 73)]
public IEnumerable<Segment> Segments { get { return this._segments; } }
Expand All @@ -80,12 +80,18 @@ public double PatternLen

internal LineType() : base() { }

/// <inheritdoc/>
public LineType(string name) : base(name) { }

/// <summary>
/// Add a segment to this line type.
/// </summary>
/// <param name="segment"></param>
/// <exception cref="ArgumentException"></exception>
public void AddSegment(Segment segment)
{
if (segment.LineType != null)
throw new ArgumentException($"Segment has already a Linetype: {segment.LineType.Name}");
throw new ArgumentException($"Segment has already a LineType: {segment.LineType.Name}");

segment.LineType = this;
this._segments.Add(segment);
Expand All @@ -94,7 +100,7 @@ public void AddSegment(Segment segment)
/// <inheritdoc/>
public override CadObject Clone()
{
LineType clone = new LineType(this.Name);
LineType clone = (LineType)base.Clone();

clone._segments.Clear();
foreach (var segment in this._segments)
Expand Down
8 changes: 8 additions & 0 deletions src/ACadSharp/Tables/TableEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace ACadSharp.Tables
[DxfSubClass(DxfSubclassMarker.TableRecord, true)]
public abstract class TableEntry : CadObject, INamedCadObject
{
/// <summary>
/// Event occurs when the <see cref="TableEntry.Name"/> changes.
/// </summary>
public event EventHandler<OnNameChangedArgs> OnNameChanged;

/// <inheritdoc/>
Expand Down Expand Up @@ -40,6 +43,11 @@ public virtual string Name

internal TableEntry() { }

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="name">Name for the entry, must be unique is added to a <see cref="CadDocument"/>.</param>
/// <exception cref="ArgumentNullException"></exception>
public TableEntry(string name)
{
if (string.IsNullOrEmpty(name))
Expand Down
9 changes: 5 additions & 4 deletions src/ACadSharp/Tables/TextStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ACadSharp.Tables
{
/// <summary>
/// Represents a <see cref="TextStyle"/> entry
/// Represents a <see cref="TextStyle"/> entry.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.TableStyle"/> <br/>
Expand Down Expand Up @@ -66,7 +66,7 @@ public override string Name
public string Filename { get; set; } = string.Empty;

/// <summary>
/// Bigfont file name, blank if none.
/// Big-font file name, blank if none.
/// </summary>
[DxfCodeValue(4)]
public string BigFontFilename { get; set; }
Expand Down Expand Up @@ -105,18 +105,19 @@ public override string Name
public TextMirrorFlag MirrorFlag { get; set; } = TextMirrorFlag.None;

/// <summary>
/// A long value which contains a truetype font’s pitch and family, character set, and italic and bold flags
/// A long value which contains a true-type font’s pitch and family, character set, and italic and bold flags
/// </summary>
[DxfCodeValue(DxfReferenceType.Optional, 1071)]
public FontFlags TrueType { get; set; } = FontFlags.Regular;

/// <summary>
/// Flag that indicates wheater this <see cref="TextStyle"/> is linked to a Shape file
/// Flag that indicates weather this <see cref="TextStyle"/> is linked to a Shape file
/// </summary>
public bool IsShapeFile { get { return this.Flags.HasFlag(StyleFlags.IsShape); } }

internal TextStyle() : base() { }

/// <inheritdoc/>
public TextStyle(string name) : base(name) { }
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/ACadSharp/Tables/UCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ACadSharp.Tables
{
/// <summary>
/// Represents a <see cref="UCS"/> entry
/// Represents a <see cref="UCS"/> entry.
/// </summary>
/// <remarks>
/// Object name <see cref="DxfFileToken.TableUcs"/> <br/>
Expand All @@ -24,43 +24,44 @@ public class UCS : TableEntry
public override string SubclassMarker => DxfSubclassMarker.Ucs;

/// <summary>
/// Origin (in WCS)
/// Origin (in WCS).
/// </summary>
[DxfCodeValue(10, 20, 30)]
public XYZ Origin { get; set; } = XYZ.Zero;

/// <summary>
/// X-axis direction (in WCS)
/// X-axis direction (in WCS).
/// </summary>
[DxfCodeValue(11, 21, 31)]
public XYZ XAxis { get; set; } = XYZ.AxisX;

/// <summary>
/// Y-axis direction(in WCS)
/// Y-axis direction(in WCS).
/// </summary>
[DxfCodeValue(12, 22, 32)]
public XYZ YAxis { get; set; } = XYZ.AxisY;

/// <summary>
/// Orthographic type
/// Orthographic type.
/// </summary>
[DxfCodeValue(71)]
public OrthographicType OrthographicType { get; set; }

/// <summary>
/// Always 0
/// Always 0.
/// </summary>
[DxfCodeValue(79)]
public OrthographicType OrthographicViewType { get; set; }

/// <summary>
/// Elevation
/// Elevation.
/// </summary>
[DxfCodeValue(146)]
public double Elevation { get; set; }

internal UCS() : base() { }

/// <inheritdoc/>
public UCS(string name) : base(name) { }
}
}
Loading
Loading