From 21e4348ec3832d5105a82db0903aab72e007e297 Mon Sep 17 00:00:00 2001 From: DomCR Date: Thu, 11 Jan 2024 15:16:19 +0100 Subject: [PATCH 1/2] fix --- ACadSharp/Entities/Dimension.cs | 26 ++----------------- ACadSharp/Entities/DimensionOrdinate.cs | 22 ++++++++++++++++ .../DWG/DwgStreamReaders/DwgObjectReader.cs | 4 ++- .../DwgObjectWriter.Entities.cs | 4 ++- .../IO/Templates/CadDimensionTemplate.cs | 6 +++-- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/ACadSharp/Entities/Dimension.cs b/ACadSharp/Entities/Dimension.cs index c8dbd679..c10d9fd8 100644 --- a/ACadSharp/Entities/Dimension.cs +++ b/ACadSharp/Entities/Dimension.cs @@ -68,28 +68,6 @@ public DimensionType Flags } } - /// - /// Ordinate type. If true, ordinate is X-type else is ordinate is Y-type - /// - public bool IsOrdinateTypeX - { - get - { - return this._flags.HasFlag(DimensionType.OrdinateTypeX); - } - set - { - if (value) - { - this._flags |= DimensionType.OrdinateTypeX; - } - else - { - this._flags &= ~DimensionType.OrdinateTypeX; - } - } - } - /// /// Indicates if the dimension text has been positioned at a user-defined location rather than at the default location /// @@ -234,9 +212,9 @@ public DimensionStyle Style } } - private string _text; + protected DimensionType _flags; - private DimensionType _flags; + private string _text; private DimensionStyle _style = DimensionStyle.Default; diff --git a/ACadSharp/Entities/DimensionOrdinate.cs b/ACadSharp/Entities/DimensionOrdinate.cs index 71c0f400..2de8ad69 100644 --- a/ACadSharp/Entities/DimensionOrdinate.cs +++ b/ACadSharp/Entities/DimensionOrdinate.cs @@ -35,6 +35,28 @@ public class DimensionOrdinate : Dimension [DxfCodeValue(14, 24, 34)] public XYZ LeaderEndpoint { get; set; } + /// + /// Ordinate type. If true, ordinate is X-type else is ordinate is Y-type + /// + public bool IsOrdinateTypeX + { + get + { + return this._flags.HasFlag(DimensionType.OrdinateTypeX); + } + set + { + if (value) + { + this._flags |= DimensionType.OrdinateTypeX; + } + else + { + this._flags &= ~DimensionType.OrdinateTypeX; + } + } + } + public DimensionOrdinate() : base(DimensionType.Ordinate) { } } } diff --git a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs index c7b94e64..98258ad8 100644 --- a/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs +++ b/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs @@ -1734,6 +1734,9 @@ private CadTemplate readDimOrdinate() //14 - pt 3BD 14 See DXF documentation. dimension.LeaderEndpoint = this._objectReader.Read3BitDouble(); + byte flags = (this._objectReader.ReadByte()); + dimension.IsOrdinateTypeX = (flags & 0b01) != 0; + this.readCommonDimensionHandles(template); return template; @@ -1892,7 +1895,6 @@ private void readCommonDimensionData(CadDimensionTemplate template) byte flags = (this._objectReader.ReadByte()); dimension.IsTextUserDefinedLocation = (flags & 0b01) == 0; - dimension.IsOrdinateTypeX = (flags & 0b10) == 0; //User text TV 1 dimension.Text = this._textReader.ReadVariableText(); diff --git a/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs b/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs index 48b84894..2786673d 100644 --- a/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs +++ b/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Entities.cs @@ -279,7 +279,6 @@ private void writeCommonDimensionData(Dimension dimension) byte flags = 0; flags |= dimension.IsTextUserDefinedLocation ? (byte)0b00 : (byte)0b01; - flags |= dimension.IsOrdinateTypeX ? (byte)0b00 : (byte)0b10; this._writer.WriteByte(flags); @@ -416,6 +415,9 @@ private void writeDimensionOrdinate(DimensionOrdinate dimension) this._writer.Write3BitDouble(dimension.FeatureLocation); //14 - pt 3BD 14 See DXF documentation. this._writer.Write3BitDouble(dimension.LeaderEndpoint); + + byte flag = (byte)(dimension.IsOrdinateTypeX ? 1 : 0); + this._writer.WriteByte(flag); } private void writeEllipse(Ellipse ellipse) diff --git a/ACadSharp/IO/Templates/CadDimensionTemplate.cs b/ACadSharp/IO/Templates/CadDimensionTemplate.cs index f30759e9..a1de663f 100644 --- a/ACadSharp/IO/Templates/CadDimensionTemplate.cs +++ b/ACadSharp/IO/Templates/CadDimensionTemplate.cs @@ -46,7 +46,10 @@ public void SetDimensionFlags(DimensionType flags) { Dimension dimension = this.CadObject as Dimension; - dimension.IsOrdinateTypeX = flags.HasFlag(DimensionType.OrdinateTypeX); + if (dimension is DimensionOrdinate ordinate) + { + ordinate.IsOrdinateTypeX = flags.HasFlag(DimensionType.OrdinateTypeX); + } dimension.IsTextUserDefinedLocation = flags.HasFlag(DimensionType.TextUserDefinedLocation); } @@ -72,7 +75,6 @@ public void SetDimensionObject(Dimension dimensionAligned) dimensionAligned.TextMiddlePoint = dimension.TextMiddlePoint; dimensionAligned.InsertionPoint = dimension.InsertionPoint; dimensionAligned.Normal = dimension.Normal; - dimensionAligned.IsOrdinateTypeX = dimension.IsOrdinateTypeX; dimensionAligned.IsTextUserDefinedLocation = dimension.IsTextUserDefinedLocation; dimensionAligned.AttachmentPoint = dimension.AttachmentPoint; dimensionAligned.LineSpacingStyle = dimension.LineSpacingStyle; From e8bf2674c126818049a1318bb6f710821c924bb7 Mon Sep 17 00:00:00 2001 From: DomCR Date: Thu, 11 Jan 2024 15:21:32 +0100 Subject: [PATCH 2/2] test fix --- ACadSharp.Tests/Entities/DimensionTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACadSharp.Tests/Entities/DimensionTests.cs b/ACadSharp.Tests/Entities/DimensionTests.cs index 8aa855df..3a9bba33 100644 --- a/ACadSharp.Tests/Entities/DimensionTests.cs +++ b/ACadSharp.Tests/Entities/DimensionTests.cs @@ -17,7 +17,7 @@ public void DimensionTypeTest() [Fact] public void IsOrdinateTypeXTest() { - DimensionAligned aligned = new DimensionAligned(); + DimensionOrdinate aligned = new DimensionOrdinate(); Assert.False(aligned.Flags.HasFlag(DimensionType.OrdinateTypeX));