Skip to content

Commit

Permalink
Merge pull request #247 from DomCR/issue-236-dimension-flags
Browse files Browse the repository at this point in the history
Dimension Flags
  • Loading branch information
DomCR authored Jan 12, 2024
2 parents 9aa2fba + e8bf267 commit d1244c7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ACadSharp.Tests/Entities/DimensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
26 changes: 2 additions & 24 deletions ACadSharp/Entities/Dimension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,6 @@ public DimensionType Flags
}
}

/// <summary>
/// Ordinate type. If true, ordinate is X-type else is ordinate is Y-type
/// </summary>
public bool IsOrdinateTypeX
{
get
{
return this._flags.HasFlag(DimensionType.OrdinateTypeX);
}
set
{
if (value)
{
this._flags |= DimensionType.OrdinateTypeX;
}
else
{
this._flags &= ~DimensionType.OrdinateTypeX;
}
}
}

/// <summary>
/// Indicates if the dimension text has been positioned at a user-defined location rather than at the default location
/// </summary>
Expand Down Expand Up @@ -234,9 +212,9 @@ public DimensionStyle Style
}
}

private string _text;
protected DimensionType _flags;

private DimensionType _flags;
private string _text;

private DimensionStyle _style = DimensionStyle.Default;

Expand Down
22 changes: 22 additions & 0 deletions ACadSharp/Entities/DimensionOrdinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ public class DimensionOrdinate : Dimension
[DxfCodeValue(14, 24, 34)]
public XYZ LeaderEndpoint { get; set; }

/// <summary>
/// Ordinate type. If true, ordinate is X-type else is ordinate is Y-type
/// </summary>
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) { }
}
}
4 changes: 3 additions & 1 deletion ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,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;
Expand Down Expand Up @@ -1888,7 +1891,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions ACadSharp/IO/Templates/CadDimensionTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down

0 comments on commit d1244c7

Please sign in to comment.