Skip to content

Commit 2aaad73

Browse files
authored
Merge pull request DomCR#648 from DomCR/issue-530_MText-rotation
MText rotation fix
2 parents 12bc8de + 88b80f5 commit 2aaad73

File tree

3 files changed

+128
-105
lines changed

3 files changed

+128
-105
lines changed

src/ACadSharp.Tests/IO/WriterSingleObjectTests.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
using System.Collections.Generic;
1010
using System.IO;
1111
using System.Linq;
12-
using System.Security.Cryptography;
1312
using Xunit;
1413
using Xunit.Abstractions;
15-
using static System.Net.Mime.MediaTypeNames;
1614

1715
namespace ACadSharp.Tests.IO
1816
{
@@ -44,6 +42,7 @@ static WriterSingleObjectTests()
4442
Data.Add(new(nameof(SingleCaseGenerator.DefaultLayer)));
4543
Data.Add(new(nameof(SingleCaseGenerator.LayerTrueColor)));
4644
Data.Add(new(nameof(SingleCaseGenerator.SingleMText)));
45+
Data.Add(new(nameof(SingleCaseGenerator.SingleMTextRotation)));
4746
Data.Add(new(nameof(SingleCaseGenerator.SingleMTextSpecialCharacter)));
4847
Data.Add(new(nameof(SingleCaseGenerator.TextWithChineseCharacters)));
4948
Data.Add(new(nameof(SingleCaseGenerator.TextAlignment)));
@@ -695,6 +694,22 @@ public void SingleMTextMultiline()
695694
this.Document.Entities.Add(mtext);
696695
}
697696

697+
public void SingleMTextRotation()
698+
{
699+
MText mtext = new MText();
700+
mtext.Value = "HELLO I'm a rotated MTEXT";
701+
mtext.AlignmentPoint = new XYZ(Math.PI / 4, Math.PI / 4, 0);
702+
703+
this.Document.Entities.Add(mtext);
704+
705+
mtext = new MText();
706+
mtext.Value = "normal changed";
707+
mtext.AlignmentPoint = new XYZ(Math.PI / 4, Math.PI / 4, 0);
708+
mtext.Normal = XYZ.AxisX;
709+
710+
this.Document.Entities.Add(mtext);
711+
}
712+
698713
public void SingleMTextSpecialCharacter()
699714
{
700715
MText mtext = new MText();

src/ACadSharp/ACadSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PropertyGroup>
1818
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
20-
<Version>1.1.17</Version>
20+
<Version>1.1.18</Version>
2121
<PackageOutputPath>../nupkg</PackageOutputPath>
2222
</PropertyGroup>
2323

src/ACadSharp/Entities/MText.cs

Lines changed: 110 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,49 @@ namespace ACadSharp.Entities
1818
public partial class MText : Entity, IText
1919
{
2020
/// <inheritdoc/>
21-
public override ObjectType ObjectType => ObjectType.MTEXT;
21+
[DxfCodeValue(11, 21, 31)]
22+
public XYZ AlignmentPoint { get; set; } = XYZ.AxisX;
2223

23-
/// <inheritdoc/>
24-
public override string ObjectName => DxfFileToken.EntityMText;
24+
/// <summary>
25+
/// Attachment point
26+
/// </summary>
27+
[DxfCodeValue(71)]
28+
public AttachmentPointType AttachmentPoint { get; set; } = AttachmentPointType.TopLeft;
2529

26-
/// <inheritdoc/>
27-
public override string SubclassMarker => DxfSubclassMarker.MText;
30+
/// <summary>
31+
/// Background fill color
32+
/// </summary>
33+
/// <remarks>
34+
/// Color to use for background fill when group code 90 is 1.
35+
/// </remarks>
36+
[DxfCodeValue(63, 420, 430)]
37+
public Color BackgroundColor { get; set; }
2838

2939
/// <summary>
30-
/// A 3D WCS coordinate representing the insertion or origin point.
40+
/// Background fill setting
3141
/// </summary>
32-
[DxfCodeValue(10, 20, 30)]
33-
public XYZ InsertPoint { get; set; } = XYZ.Zero;
42+
[DxfCodeValue(90)]
43+
public BackgroundFillFlags BackgroundFillFlags { get; set; } = BackgroundFillFlags.None;
3444

3545
/// <summary>
36-
/// Specifies the three-dimensional normal unit vector for the object.
46+
/// Determines how much border there is around the text.
3747
/// </summary>
38-
[DxfCodeValue(210, 220, 230)]
39-
public XYZ Normal { get; set; } = XYZ.AxisZ;
48+
[DxfCodeValue(45)]
49+
public double BackgroundScale { get; set; } = 1.5;
50+
51+
/// <summary>
52+
/// Transparency of background fill color
53+
/// </summary>
54+
[DxfCodeValue(441)]
55+
public Transparency BackgroundTransparency { get; set; }
56+
57+
public TextColumn Column { get; set; } = new TextColumn();
58+
59+
/// <summary>
60+
/// Drawing direction
61+
/// </summary>
62+
[DxfCodeValue(72)]
63+
public DrawingDirectionType DrawingDirection { get; set; } = DrawingDirectionType.LeftToRight;
4064

4165
/// <inheritdoc/>
4266
[DxfCodeValue(40)]
@@ -53,10 +77,49 @@ public double Height
5377
}
5478

5579
/// <summary>
56-
/// Reference rectangle width.
80+
/// Horizontal width of the characters that make up the mtext entity.
81+
/// This value will always be equal to or less than the value of group code 41
5782
/// </summary>
58-
[DxfCodeValue(41)]
59-
public double RectangleWidth { get; set; }
83+
/// <remarks>
84+
/// read-only, ignored if supplied
85+
/// </remarks>
86+
[DxfCodeValue(DxfReferenceType.Ignored, 42)]
87+
public double HorizontalWidth { get; set; } = 0.9;
88+
89+
/// <summary>
90+
/// A 3D WCS coordinate representing the insertion or origin point.
91+
/// </summary>
92+
[DxfCodeValue(10, 20, 30)]
93+
public XYZ InsertPoint { get; set; } = XYZ.Zero;
94+
95+
public bool IsAnnotative { get; set; } = false;
96+
97+
/// <summary>
98+
/// Mtext line spacing factor.
99+
/// </summary>
100+
/// <remarks>
101+
/// Percentage of default (3-on-5) line spacing to be applied.Valid values range from 0.25 to 4.00
102+
/// </remarks>
103+
[DxfCodeValue(44)]
104+
public double LineSpacing { get; set; } = 1.0;
105+
106+
/// <summary>
107+
/// Mtext line spacing style.
108+
/// </summary>
109+
[DxfCodeValue(73)]
110+
public LineSpacingStyleType LineSpacingStyle { get; set; }
111+
112+
/// <summary>
113+
/// Specifies the three-dimensional normal unit vector for the object.
114+
/// </summary>
115+
[DxfCodeValue(210, 220, 230)]
116+
public XYZ Normal { get; set; } = XYZ.AxisZ;
117+
118+
/// <inheritdoc/>
119+
public override string ObjectName => DxfFileToken.EntityMText;
120+
121+
/// <inheritdoc/>
122+
public override ObjectType ObjectType => ObjectType.MTEXT;
60123

61124
/// <summary>
62125
/// Reference rectangle height.
@@ -65,20 +128,28 @@ public double Height
65128
public double RectangleHeight { get; set; }
66129

67130
/// <summary>
68-
/// Attachment point
131+
/// Reference rectangle width.
69132
/// </summary>
70-
[DxfCodeValue(71)]
71-
public AttachmentPointType AttachmentPoint { get; set; } = AttachmentPointType.TopLeft;
133+
[DxfCodeValue(41)]
134+
public double RectangleWidth { get; set; }
72135

73136
/// <summary>
74-
/// Drawing direction
137+
/// Specifies the rotation angle for the object.
75138
/// </summary>
76-
[DxfCodeValue(72)]
77-
public DrawingDirectionType DrawingDirection { get; set; } = DrawingDirectionType.LeftToRight;
78-
79-
/// <inheritdoc/>
80-
[DxfCodeValue(1)]
81-
public string Value { get; set; } = string.Empty;
139+
/// <remarks>
140+
/// The rotation is only valid if the <see cref="Normal"/> is set to the Z axis.
141+
/// </remarks>
142+
/// <value>
143+
/// The rotation angle in radians.
144+
/// </value>
145+
[DxfCodeValue(DxfReferenceType.IsAngle | DxfReferenceType.Ignored, 50)]
146+
public double Rotation
147+
{
148+
get
149+
{
150+
return new XY(this.AlignmentPoint.X, this.AlignmentPoint.Y).GetAngle();
151+
}
152+
}
82153

83154
/// <inheritdoc/>
84155
[DxfCodeValue(DxfReferenceType.Name | DxfReferenceType.Optional, 7)]
@@ -104,18 +175,11 @@ public TextStyle Style
104175
}
105176

106177
/// <inheritdoc/>
107-
[DxfCodeValue(11, 21, 31)]
108-
public XYZ AlignmentPoint { get; set; } = XYZ.AxisX;
178+
public override string SubclassMarker => DxfSubclassMarker.MText;
109179

110-
/// <summary>
111-
/// Horizontal width of the characters that make up the mtext entity.
112-
/// This value will always be equal to or less than the value of group code 41
113-
/// </summary>
114-
/// <remarks>
115-
/// read-only, ignored if supplied
116-
/// </remarks>
117-
[DxfCodeValue(DxfReferenceType.Ignored, 42)]
118-
public double HorizontalWidth { get; set; } = 0.9;
180+
/// <inheritdoc/>
181+
[DxfCodeValue(1)]
182+
public string Value { get; set; } = string.Empty;
119183

120184
/// <summary>
121185
/// Vertical height of the mtext entity
@@ -126,61 +190,6 @@ public TextStyle Style
126190
[DxfCodeValue(DxfReferenceType.Ignored, 43)]
127191
public double VerticalHeight { get; set; } = 0.2;
128192

129-
/// <summary>
130-
/// Specifies the rotation angle for the object.
131-
/// </summary>
132-
/// <value>
133-
/// The rotation angle in radians.
134-
/// </value>
135-
[DxfCodeValue(DxfReferenceType.IsAngle, 50)]
136-
public double Rotation { get; set; } = 0.0;
137-
138-
/// <summary>
139-
/// Mtext line spacing style.
140-
/// </summary>
141-
[DxfCodeValue(73)]
142-
public LineSpacingStyleType LineSpacingStyle { get; set; }
143-
144-
/// <summary>
145-
/// Mtext line spacing factor.
146-
/// </summary>
147-
/// <remarks>
148-
/// Percentage of default (3-on-5) line spacing to be applied.Valid values range from 0.25 to 4.00
149-
/// </remarks>
150-
[DxfCodeValue(44)]
151-
public double LineSpacing { get; set; } = 1.0;
152-
153-
/// <summary>
154-
/// Background fill setting
155-
/// </summary>
156-
[DxfCodeValue(90)]
157-
public BackgroundFillFlags BackgroundFillFlags { get; set; } = BackgroundFillFlags.None;
158-
159-
/// <summary>
160-
/// Determines how much border there is around the text.
161-
/// </summary>
162-
[DxfCodeValue(45)]
163-
public double BackgroundScale { get; set; } = 1.5;
164-
165-
/// <summary>
166-
/// Background fill color
167-
/// </summary>
168-
/// <remarks>
169-
/// Color to use for background fill when group code 90 is 1.
170-
/// </remarks>
171-
[DxfCodeValue(63, 420, 430)]
172-
public Color BackgroundColor { get; set; }
173-
174-
/// <summary>
175-
/// Transparency of background fill color
176-
/// </summary>
177-
[DxfCodeValue(441)]
178-
public Transparency BackgroundTransparency { get; set; }
179-
180-
public TextColumn Column { get; set; } = new TextColumn();
181-
182-
public bool IsAnnotative { get; set; } = false;
183-
184193
private double _height = 1.0;
185194

186195
private TextStyle _style = TextStyle.Default;
@@ -280,11 +289,21 @@ public override void ApplyTransform(Transform transform)
280289

281290
this.InsertPoint = newInsert;
282291
this.Normal = newNormal;
283-
this.Rotation = newRotation;
284292
this.Height = newHeight;
285293
this.RectangleWidth *= scale;
286294
}
287295

296+
/// <inheritdoc/>
297+
public override CadObject Clone()
298+
{
299+
MText clone = (MText)base.Clone();
300+
301+
clone.Style = (TextStyle)(this.Style?.Clone());
302+
clone.Column = this.Column?.Clone();
303+
304+
return clone;
305+
}
306+
288307
/// <inheritdoc/>
289308
public override BoundingBox GetBoundingBox()
290309
{
@@ -303,17 +322,6 @@ public string[] GetTextLines()
303322
);
304323
}
305324

306-
/// <inheritdoc/>
307-
public override CadObject Clone()
308-
{
309-
MText clone = (MText)base.Clone();
310-
311-
clone.Style = (TextStyle)(this.Style?.Clone());
312-
clone.Column = this.Column?.Clone();
313-
314-
return clone;
315-
}
316-
317325
internal override void AssignDocument(CadDocument doc)
318326
{
319327
base.AssignDocument(doc);

0 commit comments

Comments
 (0)