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

DomCR / ACadSharp / 24786287371

22 Apr 2026 03:12PM UTC coverage: 77.123% (+0.05%) from 77.076%
24786287371

Pull #1041

github

web-flow
Merge 1c7a96bd4 into 98bd2e4f4
Pull Request #1041: issue-1035 Add progress reporting to CAD file reading process

8457 of 11919 branches covered (70.95%)

Branch coverage included in aggregate %.

332 of 385 new or added lines in 12 files covered. (86.23%)

8 existing lines in 3 files now uncovered.

30460 of 38542 relevant lines covered (79.03%)

153328.92 hits per line

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

80.47
/src/ACadSharp/Entities/Entity.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Objects;
3
using ACadSharp.Tables;
4
using CSMath;
5
using System;
6
using System.Collections.Generic;
7

8
namespace ACadSharp.Entities;
9

10
/// <summary>
11
/// The standard class for a basic CAD entity or a graphical object.
12
/// </summary>
13
[DxfSubClass(DxfSubclassMarker.Entity)]
14
public abstract class Entity : CadObject, IEntity
15
{
16
        /// <summary>
17
        /// Book color for this entity.
18
        /// </summary>
19
        [DxfCodeValue(DxfReferenceType.Name, 430)]
20
        public BookColor BookColor
21
        {
22
                get { return this._bookColor; }
71,649✔
23
                set
24
                {
282✔
25
                        if (this.Document != null)
282✔
26
                        {
260✔
27
                                this._bookColor = updateCollection(value, this.Document.Colors);
260✔
28
                        }
260✔
29
                        else
30
                        {
22✔
31
                                this._bookColor = value;
22✔
32
                        }
22✔
33
                }
282✔
34
        }
35

36
        /// <inheritdoc/>
37
        [DxfCodeValue(62, 420)]
38
        public Color Color { get; set; } = Color.ByLayer;
2,175,045✔
39

40
        /// <inheritdoc/>
41
        [DxfCodeValue(60)]
42
        public bool IsInvisible { get; set; } = false;
2,076,726✔
43

44
        /// <inheritdoc/>
45
        [DxfCodeValue(DxfReferenceType.Name, 8)]
46
        public virtual Layer Layer
47
        {
48
                get { return this._layer; }
4,215,231✔
49
                set
50
                {
826,071✔
51
                        if (value == null)
826,071!
UNCOV
52
                        {
×
NEW
53
                                throw new ArgumentNullException(nameof(value));
×
54
                        }
55

56
                        this._layer = updateCollection(value, this.Document?.Layers);
826,071✔
57
                }
826,071✔
58
        }
59

60
        /// <inheritdoc/>
61
        [DxfCodeValue(DxfReferenceType.Name, 6)]
62
        public virtual LineType LineType
63
        {
64
                get { return this._lineType; }
4,215,084✔
65
                set
66
                {
635,586✔
67
                        if (value == null)
635,586!
UNCOV
68
                        {
×
NEW
69
                                throw new ArgumentNullException(nameof(value));
×
70
                        }
71

72
                        this._lineType = updateCollection(value, this.Document?.LineTypes);
635,586✔
73
                }
635,586✔
74
        }
75

76
        /// <inheritdoc/>
77
        [DxfCodeValue(48)]
78
        public double LineTypeScale { get; set; } = 1.0;
2,077,040✔
79

80
        /// <inheritdoc/>
81
        [DxfCodeValue(370)]
82
        public LineWeightType LineWeight { get; set; } = LineWeightType.ByLayer;
2,085,090✔
83

84
        /// <inheritdoc/>
85
        [DxfCodeValue(DxfReferenceType.Handle, 347)]
86
        public Material Material { get; set; }
1,114,302✔
87

88
        /// <inheritdoc/>
89
        public override string SubclassMarker => DxfSubclassMarker.Entity;
32,840✔
90

91
        /// <inheritdoc/>
92
        [DxfCodeValue(440)]
93
        public Transparency Transparency { get; set; } = Transparency.ByLayer;
2,087,079✔
94

95
        private BookColor _bookColor = null;
872,195✔
96

97
        private Layer _layer = Layer.Default;
872,195✔
98

99
        private LineType _lineType = LineType.ByLayer;
872,195✔
100

101
        /// <inheritdoc/>
102
        public Entity() : base() { }
2,616,585✔
103

104
        /// <summary>
105
        /// Apply a rotation to this entity.
106
        /// </summary>
107
        /// <param name="axis"></param>
108
        /// <param name="rotation">The angle to rotate around the given axis, in radians.</param>
109
        public void ApplyRotation(XYZ axis, double rotation)
110
        {
11✔
111
                Transform transform = Transform.CreateRotation(axis, rotation);
11✔
112
                this.ApplyTransform(transform);
11✔
113
        }
11✔
114

115
        /// <summary>
116
        /// Apply a scaling transformation to this entity.
117
        /// </summary>
118
        /// <param name="scale"></param>
119
        public void ApplyScaling(XYZ scale)
NEW
120
        {
×
NEW
121
                Transform transform = Transform.CreateScaling(scale);
×
NEW
122
                this.ApplyTransform(transform);
×
NEW
123
        }
×
124

125
        /// <summary>
126
        /// Apply a scaling transformation to this entity.
127
        /// </summary>
128
        /// <param name="scale"></param>
129
        /// <param name="origin"></param>
130
        public void ApplyScaling(XYZ scale, XYZ origin)
NEW
131
        {
×
NEW
132
                Transform transform = Transform.CreateScaling(scale, origin);
×
NEW
133
                this.ApplyTransform(transform);
×
NEW
134
        }
×
135

136
        /// <inheritdoc/>
137
        public abstract void ApplyTransform(Transform transform);
138

139
        /// <summary>
140
        /// Apply a translation to this entity.
141
        /// </summary>
142
        /// <param name="translation"></param>
143
        public void ApplyTranslation(XYZ translation)
144
        {
1✔
145
                Transform transform = Transform.CreateTranslation(translation);
1✔
146
                this.ApplyTransform(transform);
1✔
147
        }
1✔
148

149
        /// <inheritdoc/>
150
        public override CadObject Clone()
151
        {
7,991✔
152
                Entity clone = (Entity)base.Clone();
7,991✔
153

154
                clone.Layer = (Layer)this.Layer.Clone();
7,991✔
155
                clone.LineType = (LineType)this.LineType.Clone();
7,991✔
156
                clone.Material = (Material)this.Material?.Clone();
7,991!
157

158
                return clone;
7,991✔
159
        }
7,991✔
160

161
        /// <inheritdoc/>
162
        public Color GetActiveColor()
163
        {
399✔
164
                Color color;
165
                if (this.Color.IsByLayer)
399✔
166
                {
208✔
167
                        color = this.Layer.Color;
208✔
168
                }
208✔
169
                else if (this.Color.IsByBlock && this.Owner is BlockRecord record)
191✔
170
                {
119✔
171
                        color = record.BlockEntity.Color;
119✔
172
                }
119✔
173
                else
174
                {
72✔
175
                        color = this.Color;
72✔
176
                }
72✔
177

178
                return color;
399✔
179
        }
399✔
180

181
        /// <inheritdoc/>
182
        public LineType GetActiveLineType()
183
        {
316✔
184
                if (this.LineType.Name.Equals(LineType.ByLayerName, StringComparison.InvariantCultureIgnoreCase))
316✔
185
                {
235✔
186
                        return this.Layer.LineType;
235✔
187
                }
188
                else if (this.LineType.Name.Equals(LineType.ByBlockName, StringComparison.InvariantCultureIgnoreCase)
81✔
189
                        && this.Owner is BlockRecord record)
81✔
190
                {
23✔
191
                        return record.BlockEntity.LineType;
23✔
192
                }
193

194
                return this.LineType;
58✔
195
        }
316✔
196

197
        /// <inheritdoc/>
198
        public LineWeightType GetActiveLineWeightType()
199
        {
407✔
200
                switch (this.LineWeight)
407✔
201
                {
202
                        case LineWeightType.ByLayer:
203
                                return this.Layer.LineWeight;
298✔
204
                        case LineWeightType.ByBlock:
205
                                if (this.Owner is BlockRecord record)
48!
206
                                {
48✔
207
                                        return record.BlockEntity.GetActiveLineWeightType();
48✔
208
                                }
209
                                else
NEW
210
                                {
×
NEW
211
                                        return this.LineWeight;
×
212
                                }
213
                        default:
214
                                return this.LineWeight;
61✔
215
                }
216
        }
407✔
217

218
        /// <inheritdoc/>
219
        public abstract BoundingBox GetBoundingBox();
220

221
        /// <inheritdoc/>
222
        public void MatchProperties(IEntity entity)
223
        {
549,160✔
224
                if (entity is null)
549,160!
NEW
225
                {
×
NEW
226
                        throw new ArgumentNullException(nameof(entity));
×
227
                }
228

229
                if (entity.Handle == 0 || this.Document != entity.Document)
549,160✔
230
                {
548,036✔
231
                        this.Layer = (Layer)entity.Layer.Clone();
548,036✔
232
                        this.LineType = (LineType)entity.LineType.Clone();
548,036✔
233
                        this.Material = (Material)entity.Material?.Clone();
548,036!
234
                }
548,036✔
235
                else
236
                {
1,124✔
237
                        this.Layer = entity.Layer;
1,124✔
238
                        this.LineType = entity.LineType;
1,124✔
239
                        this.Material = entity.Material;
1,124✔
240
                }
1,124✔
241

242
                this.Color = entity.Color;
549,160✔
243
                this.LineWeight = entity.LineWeight;
549,160✔
244
                this.LineTypeScale = entity.LineTypeScale;
549,160✔
245
                this.IsInvisible = entity.IsInvisible;
549,160✔
246
                this.Transparency = entity.Transparency;
549,160✔
247
        }
549,160✔
248

249
        internal override void AssignDocument(CadDocument doc)
250
        {
812,928✔
251
                base.AssignDocument(doc);
812,928✔
252

253
                this._layer = CadObject.updateCollection(this.Layer, doc.Layers);
812,928✔
254
                this._lineType = CadObject.updateCollection(this.LineType, doc.LineTypes);
812,928✔
255

256
                doc.Layers.OnRemove += this.tableOnRemove;
812,928✔
257
                doc.LineTypes.OnRemove += this.tableOnRemove;
812,928✔
258
        }
812,928✔
259

260
        internal override void UnassignDocument()
261
        {
4,358✔
262
                this.Document.Layers.OnRemove -= this.tableOnRemove;
4,358✔
263
                this.Document.LineTypes.OnRemove -= this.tableOnRemove;
4,358✔
264

265
                base.UnassignDocument();
4,358✔
266

267
                this.Layer = (Layer)this.Layer.Clone();
4,358✔
268
                this.LineType = (LineType)this.LineType.Clone();
4,358✔
269
        }
4,358✔
270

271
        protected List<XY> applyRotation(IEnumerable<XY> points, double rotation)
272
        {
1,427✔
273
                if (points == null)
1,427!
UNCOV
274
                {
×
NEW
275
                        throw new ArgumentNullException(nameof(points));
×
276
                }
277

278
                if (MathHelper.IsZero(rotation))
1,427!
279
                {
1,427✔
280
                        return new List<XY>(points);
1,427✔
281
                }
282

NEW
283
                double sin = Math.Sin(rotation);
×
NEW
284
                double cos = Math.Cos(rotation);
×
285

286
                List<XY> transPoints;
287

NEW
288
                transPoints = new List<XY>();
×
NEW
289
                foreach (XY p in points)
×
290
                {
×
NEW
291
                        transPoints.Add(new XY(p.X * cos - p.Y * sin, p.X * sin + p.Y * cos));
×
292
                }
×
NEW
293
                return transPoints;
×
294
        }
1,427✔
295

296
        protected XYZ applyWorldMatrix(XYZ xyz, Transform transform, Matrix3 transOW, Matrix3 transWO)
NEW
297
        {
×
NEW
298
                XYZ v = transOW * xyz;
×
NEW
299
                v = transform.ApplyTransform(v);
×
NEW
300
                v = transWO * v;
×
NEW
301
                return v;
×
NEW
302
        }
×
303

304
        protected Matrix3 getWorldMatrix(Transform transform, XYZ normal, XYZ newNormal, out Matrix3 transOW, out Matrix3 transWO)
305
        {
1,437✔
306
                transOW = Matrix3.ArbitraryAxis(normal);
1,437✔
307
                transWO = Matrix3.ArbitraryAxis(newNormal).Transpose();
1,437✔
308
                return new Matrix3(transform.Matrix);
1,437✔
309
        }
1,437✔
310

311
        protected virtual void tableOnRemove(object sender, CollectionChangedEventArgs e)
312
        {
51✔
313
                if (e.Item.Equals(this.Layer))
51✔
314
                {
1✔
315
                        this.Layer = this.Document.Layers[Layer.DefaultName];
1✔
316
                }
1✔
317

318
                if (e.Item.Equals(this.LineType))
51✔
319
                {
1✔
320
                        this.LineType = this.Document.LineTypes[LineType.ByLayerName];
1✔
321
                }
1✔
322
        }
51✔
323

324
        protected XYZ transformNormal(Transform transform, XYZ normal)
325
        {
1,439✔
326
                return transform.ApplyRotation(normal).Normalize();
1,439✔
327
        }
1,439✔
328
}
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