• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 16379028536

18 Jul 2025 07:45PM UTC coverage: 74.905% (-0.1%) from 75.043%
16379028536

Pull #715

github

web-flow
Merge 9090edde3 into 402a39408
Pull Request #715: Issue 712 pdfunderlay writer

5876 of 8627 branches covered (68.11%)

Branch coverage included in aggregate %.

118 of 209 new or added lines in 14 files covered. (56.46%)

14 existing lines in 3 files now uncovered.

23420 of 30484 relevant lines covered (76.83%)

80920.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.83
/src/ACadSharp/Entities/UnderlayEntity.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Objects;
3
using CSMath;
4
using System;
5
using System.Collections.Generic;
6

7
namespace ACadSharp.Entities
8
{
9
        /// <summary>
10
        /// Common base class for all underlay entities, like <see cref="PdfUnderlay" />.
11
        /// </summary>
12
        [DxfSubClass(null, true)]
13
        public abstract class UnderlayEntity : Entity
14
        {
15
                /// <summary>
16
                /// 2d points in OCS/ECS.
17
                /// </summary>
18
                /// <remarks>
19
                /// If only two, then they are the lower left and upper right corner points of a clip rectangle. <br/>
20
                /// If more than two, then they are the vertices of a clipping polygon.
21
                /// </remarks>
22
                [DxfCollectionCodeValue(11, 21)]
23
                public List<XY> ClipBoundaryVertices { get; set; } = new List<XY>();
6✔
24

25
                /// <summary>
26
                /// Contrast
27
                /// </summary>
28
                /// <remarks>
29
                /// 0-100; default = 50
30
                /// </remarks>
31
                [DxfCodeValue(281)]
32
                public byte Contrast
33
                {
34
                        get { return this._contrast; }
×
35
                        set
36
                        {
5✔
37
                                if (value < 0 || value > 100)
5!
38
                                {
2✔
39
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
2✔
40
                                }
41

42
                                this._contrast = value;
3✔
43
                        }
3✔
44
                }
45

46
                /// <summary>
47
                /// The AcDbUnderlayDefinition object.
48
                /// </summary>
49
                [DxfCodeValue(DxfReferenceType.Handle, 340)]
50
                public PdfUnderlayDefinition Definition
51
                {
52
                        get { return this._definition; }
12✔
53
                        set
54
                        {
3✔
55
                                if (value == null)
3!
56
                                {
3✔
57
                                        return;
3✔
58
                                }
59

NEW
60
                                if (this.Document != null)
×
NEW
61
                                {
×
NEW
62
                                        this._definition = this.updateCollection(value, this.Document.PdfDefinitions);
×
NEW
63
                                }
×
64
                                else
NEW
65
                                {
×
NEW
66
                                        this._definition = value;
×
NEW
67
                                }
×
68
                        }
3✔
69
                }
70

71
                /// <summary>
72
                /// Fade
73
                /// </summary>
74
                /// <value>
75
                /// Range: 0 - 100 <br/>
76
                /// Default: 0
77
                /// </value>
78
                [DxfCodeValue(282)]
79
                public byte Fade
80
                {
81
                        get { return this._fade; }
×
82
                        set
83
                        {
5✔
84
                                if (value < 0 || value > 100)
5!
85
                                {
2✔
86
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
2✔
87
                                }
88

89
                                this._fade = value;
3✔
90
                        }
3✔
91
                }
92

93
                /// <summary>
94
                /// Underlay display options.
95
                /// </summary>
96
                [DxfCodeValue(280)]
97
                public UnderlayDisplayFlags Flags { get; set; } = UnderlayDisplayFlags.Default;
6✔
98

99
                /// <summary>
100
                /// Insertion point(in WCS)
101
                /// </summary>
102
                [DxfCodeValue(10, 20, 30)]
103
                public XYZ InsertPoint { get; set; }
5✔
104

105
                /// <summary>
106
                /// Specifies the three-dimensional normal unit vector for the object.
107
                /// </summary>
108
                [DxfCodeValue(210, 220, 230)]
109
                public XYZ Normal { get; set; } = XYZ.AxisZ;
11✔
110

111
                /// <summary>
112
                /// Specifies the rotation angle for the object.
113
                /// </summary>
114
                /// <value>
115
                /// The rotation angle in radians.
116
                /// </value>
117
                [DxfCodeValue(DxfReferenceType.IsAngle, 50)]
118
                public double Rotation { get; set; } = 0.0;
11✔
119

120
                /// <inheritdoc/>
121
                public override string SubclassMarker => DxfSubclassMarker.Underlay;
2✔
122

123
                /// <summary>
124
                /// X scale factor.
125
                /// </summary>
126
                [DxfCodeValue(41)]
127
                public double XScale
128
                {
129
                        get
130
                        {
×
131
                                return this._xscale;
×
132
                        }
×
133
                        set
134
                        {
5✔
135
                                if (value.Equals(0))
5!
136
                                {
×
137
                                        string name = nameof(this.XScale);
×
138
                                        throw new ArgumentOutOfRangeException(name, value, $"{name} value must be none zero.");
×
139
                                }
140
                                this._xscale = value;
5✔
141
                        }
5✔
142
                }
143

144
                /// <summary>
145
                /// Y scale factor.
146
                /// </summary>
147
                [DxfCodeValue(42)]
148
                public double YScale
149
                {
150
                        get
151
                        {
×
152
                                return this._yscale;
×
153
                        }
×
154
                        set
155
                        {
5✔
156
                                if (value.Equals(0))
5!
157
                                {
×
158
                                        string name = nameof(this.YScale);
×
159
                                        throw new ArgumentOutOfRangeException(name, value, $"{name} value must be none zero.");
×
160
                                }
161
                                this._yscale = value;
5✔
162
                        }
5✔
163
                }
164

165
                /// <summary>
166
                /// Z scale factor.
167
                /// </summary>
168
                [DxfCodeValue(43)]
169
                public double ZScale
170
                {
171
                        get
172
                        {
×
173
                                return this._zscale;
×
174
                        }
×
175
                        set
176
                        {
5✔
177
                                if (value.Equals(0))
5!
178
                                {
×
179
                                        string name = nameof(this.ZScale);
×
180
                                        throw new ArgumentOutOfRangeException(name, value, $"{name} value must be none zero.");
×
181
                                }
182
                                this._zscale = value;
5✔
183
                        }
5✔
184
                }
185

186
                private byte _contrast = 100;
6✔
187

188
                private PdfUnderlayDefinition _definition;
189

190
                private byte _fade = 0;
6✔
191

192
                private double _xscale = 1;
6✔
193

194
                private double _yscale = 1;
6✔
195

196
                private double _zscale = 1;
6✔
197

198
                /// <inheritdoc/>
199
                public override void ApplyTransform(Transform transform)
200
                {
×
201
                        XYZ newPosition = transform.ApplyTransform(this.InsertPoint);
×
202
                        XYZ newNormal = this.transformNormal(transform, Normal);
×
203

204
                        var transformation = getWorldMatrix(transform, newNormal, this.Normal, out Matrix3 transOW, out Matrix3 transWO);
×
205

206
                        List<XY> uv = applyRotation(
×
207
                                new[]
×
208
                                {
×
209
                                        XY.AxisX, XY.AxisY
×
210
                                },
×
211
                                this.Rotation);
×
212

213
                        XYZ v;
214
                        v = transOW * new XYZ(uv[0].X, uv[0].Y, 0.0);
×
215
                        v = transformation * v;
×
216
                        v = transWO * v;
×
217
                        XY newUvector = new XY(v.X, v.Y);
×
218

219
                        v = transOW * new XYZ(uv[1].X, uv[1].Y, 0.0);
×
220
                        v = transformation * v;
×
221
                        v = transWO * v;
×
222
                        XY newVvector = new XY(v.X, v.Y);
×
223

224
                        int sign = Math.Sign(transformation.m00 * transformation.m11 * transformation.m22) < 0 ? -1 : 1;
×
225

226
                        double newRotation = (sign * newUvector).GetAngle();
×
227

228
                        this.InsertPoint = newPosition;
×
229
                        this.Normal = newNormal;
×
230
                        this.Rotation = newRotation;
×
231
                        this.XScale = transform.Scale.X * this.XScale;
×
232
                        this.YScale = transform.Scale.Y * this.YScale;
×
233
                        this.ZScale = transform.Scale.Z * this.ZScale;
×
234
                }
×
235

236
                public override CadObject Clone()
237
                {
3✔
238
                        UnderlayEntity clone = (UnderlayEntity)base.Clone();
3✔
239

240
                        clone.Definition = (PdfUnderlayDefinition)this.Definition?.Clone();
3!
241

242
                        return clone;
3✔
243
                }
3✔
244

245
                /// <inheritdoc/>
246
                public override BoundingBox GetBoundingBox()
247
                {
1✔
248
                        return BoundingBox.Null;
1✔
249
                }
1✔
250

251
                internal override void AssignDocument(CadDocument doc)
252
                {
1✔
253
                        base.AssignDocument(doc);
1✔
254

255
                        this._definition = this.updateCollection(this.Definition, doc.PdfDefinitions);
1✔
256

257
                        this.Document.PdfDefinitions.OnRemove += this.imageDefinitionsOnRemove;
1✔
258
                }
1✔
259

260
                internal override void UnassignDocument()
NEW
261
                {
×
NEW
262
                        this.Document.ImageDefinitions.OnRemove -= this.imageDefinitionsOnRemove;
×
263

NEW
264
                        base.UnassignDocument();
×
265

NEW
266
                        this.Definition = (PdfUnderlayDefinition)this.Definition?.Clone();
×
NEW
267
                }
×
268

269
                private void imageDefinitionsOnRemove(object sender, CollectionChangedEventArgs e)
NEW
270
                {
×
NEW
271
                        if (e.Item.Equals(this.Definition))
×
NEW
272
                        {
×
NEW
273
                                this.Definition = null;
×
NEW
274
                        }
×
NEW
275
                }
×
276
        }
277
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc