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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

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

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

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

UNCOV
45
                                this._contrast = value;
×
UNCOV
46
                        }
×
47
                }
48

49
                /// <summary>
50
                /// The AcDbUnderlayDefinition object.
51
                /// </summary>
52
                [DxfCodeValue(DxfReferenceType.Handle, 340)]
53
                public T Definition
54
                {
UNCOV
55
                        get { return this._definition; }
×
56
                        set
UNCOV
57
                        {
×
UNCOV
58
                                if (value == null)
×
59
                                {
×
60
                                        throw new ArgumentNullException(nameof(value));
×
61
                                }
62

UNCOV
63
                                if (this.Document != null)
×
UNCOV
64
                                {
×
UNCOV
65
                                        this._definition = updateCollection(value, this.getDocumentCollection(this.Document));
×
UNCOV
66
                                }
×
67
                                else
UNCOV
68
                                {
×
UNCOV
69
                                        this._definition = value;
×
UNCOV
70
                                }
×
UNCOV
71
                        }
×
72
                }
73

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

UNCOV
92
                                this._fade = value;
×
UNCOV
93
                        }
×
94
                }
95

96
                /// <summary>
97
                /// Underlay display options.
98
                /// </summary>
99
                [DxfCodeValue(280)]
UNCOV
100
                public UnderlayDisplayFlags Flags { get; set; } = UnderlayDisplayFlags.Default;
×
101

102
                /// <summary>
103
                /// Insertion point(in WCS).
104
                /// </summary>
105
                [DxfCodeValue(10, 20, 30)]
UNCOV
106
                public XYZ InsertPoint { get; set; }
×
107

108
                /// <summary>
109
                /// Specifies the three-dimensional normal unit vector for the object.
110
                /// </summary>
111
                [DxfCodeValue(210, 220, 230)]
UNCOV
112
                public XYZ Normal { get; set; } = XYZ.AxisZ;
×
113

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

123
                /// <inheritdoc/>
UNCOV
124
                public override string SubclassMarker => DxfSubclassMarker.Underlay;
×
125

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

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

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

UNCOV
189
                private byte _contrast = 100;
×
190

191
                private T _definition;
192

UNCOV
193
                private byte _fade = 0;
×
194

UNCOV
195
                private double _xscale = 1;
×
196

UNCOV
197
                private double _yscale = 1;
×
198

UNCOV
199
                private double _zscale = 1;
×
200

201
                /// <summary>
202
                /// Initializes a new instance of the <see cref="UnderlayEntity{T}" /> class.
203
                /// </summary>
204
                /// <param name="definition"></param>
UNCOV
205
                public UnderlayEntity(T definition)
×
UNCOV
206
                {
×
UNCOV
207
                        this.Definition = definition;
×
UNCOV
208
                }
×
209

UNCOV
210
                internal UnderlayEntity()
×
UNCOV
211
                {
×
UNCOV
212
                }
×
213

214
                /// <inheritdoc/>
215
                public override void ApplyTransform(Transform transform)
216
                {
×
217
                        XYZ newPosition = transform.ApplyTransform(this.InsertPoint);
×
218
                        XYZ newNormal = this.transformNormal(transform, Normal);
×
219

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

222
                        List<XY> uv = applyRotation(
×
223
                                new[]
×
224
                                {
×
225
                                        XY.AxisX, XY.AxisY
×
226
                                },
×
227
                                this.Rotation);
×
228

229
                        XYZ v;
230
                        v = transOW * new XYZ(uv[0].X, uv[0].Y, 0.0);
×
231
                        v = transformation * v;
×
232
                        v = transWO * v;
×
233
                        XY newUvector = new XY(v.X, v.Y);
×
234

235
                        v = transOW * new XYZ(uv[1].X, uv[1].Y, 0.0);
×
236
                        v = transformation * v;
×
237
                        v = transWO * v;
×
238
                        XY newVvector = new XY(v.X, v.Y);
×
239

240
                        int sign = Math.Sign(transformation.M00 * transformation.M11 * transformation.M22) < 0 ? -1 : 1;
×
241

242
                        double newRotation = (sign * newUvector).GetAngle();
×
243

244
                        this.InsertPoint = newPosition;
×
245
                        this.Normal = newNormal;
×
246
                        this.Rotation = newRotation;
×
247
                        this.XScale = transform.Scale.X * this.XScale;
×
248
                        this.YScale = transform.Scale.Y * this.YScale;
×
249
                        this.ZScale = transform.Scale.Z * this.ZScale;
×
250
                }
×
251

252
                /// <inheritdoc/>
253
                public override CadObject Clone()
UNCOV
254
                {
×
UNCOV
255
                        UnderlayEntity<T> clone = (UnderlayEntity<T>)base.Clone();
×
256

UNCOV
257
                        clone.Definition = this.Definition?.CloneTyped();
×
UNCOV
258
                        clone.ClipBoundaryVertices = new List<XY>(this.ClipBoundaryVertices);
×
259

UNCOV
260
                        return clone;
×
UNCOV
261
                }
×
262

263
                /// <inheritdoc/>
264
                public override BoundingBox GetBoundingBox()
265
                {
×
266
                        return BoundingBox.Null;
×
267
                }
×
268

269
                internal override void AssignDocument(CadDocument doc)
UNCOV
270
                {
×
UNCOV
271
                        base.AssignDocument(doc);
×
272

UNCOV
273
                        this._definition = updateCollection(this.Definition, getDocumentCollection(doc));
×
274

UNCOV
275
                        this.Document.PdfDefinitions.OnRemove += this.imageDefinitionsOnRemove;
×
UNCOV
276
                }
×
277

278
                internal override void UnassignDocument()
UNCOV
279
                {
×
UNCOV
280
                        this.Document.ImageDefinitions.OnRemove -= this.imageDefinitionsOnRemove;
×
281

UNCOV
282
                        base.UnassignDocument();
×
283

UNCOV
284
                        this.Definition = (T)this.Definition?.Clone();
×
UNCOV
285
                }
×
286

287
                protected abstract ObjectDictionaryCollection<T> getDocumentCollection(CadDocument document);
288

289
                private void imageDefinitionsOnRemove(object sender, CollectionChangedEventArgs e)
290
                {
×
291
                        if (e.Item.Equals(this.Definition))
×
292
                        {
×
293
                                this.Definition = null;
×
294
                        }
×
295
                }
×
296
        }
297
}
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