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

DomCR / ACadSharp / 22018280625

14 Feb 2026 01:30PM UTC coverage: 77.356% (-0.1%) from 77.463%
22018280625

Pull #978

github

web-flow
Merge cd1c403d2 into 4609c0caf
Pull Request #978: issue-976 context data

8148 of 11392 branches covered (71.52%)

Branch coverage included in aggregate %.

28 of 90 new or added lines in 6 files covered. (31.11%)

722 existing lines in 9 files now uncovered.

29481 of 37252 relevant lines covered (79.14%)

151138.57 hits per line

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

80.46
/src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
1
using ACadSharp.Entities;
2
using ACadSharp.IO.Templates;
3
using ACadSharp.Objects;
4
using ACadSharp.Tables;
5
using ACadSharp.XData;
6
using CSMath;
7
using System;
8
using System.Collections.Generic;
9
using System.Diagnostics;
10
using System.Linq;
11
using static ACadSharp.IO.Templates.CadMLeaderAnnotContextTemplate;
12

13
namespace ACadSharp.IO.DXF
14
{
15
        internal abstract class DxfSectionReaderBase
16
        {
17
                public delegate bool ReadEntityDelegate<T>(CadEntityTemplate template, DxfMap map, string subclass = null) where T : Entity;
18

19
                protected readonly IDxfStreamReader _reader;
20
                protected readonly DxfDocumentBuilder _builder;
21

22
                //Avoid to move the reader to the next line
23
                protected bool lockPointer = false;
960✔
24
                protected string currentSubclass = null;
960✔
25

26
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
960✔
27
                {
960✔
28
                        this._reader = reader;
960✔
29
                        this._builder = builder;
960✔
30
                }
960✔
31

32
                public abstract void Read();
33

34
                protected void readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out HashSet<ulong> reactors)
35
                {
2,261✔
36
                        name = null;
2,261✔
37
                        handle = 0;
2,261✔
38
                        ownerHandle = null;
2,261✔
39
                        xdictHandle = null;
2,261✔
40
                        reactors = new HashSet<ulong>();
2,261✔
41

42
                        if (this._reader.DxfCode == DxfCode.Start
2,261!
43
                                        || this._reader.DxfCode == DxfCode.Subclass)
2,261✔
44
                                this._reader.ReadNext();
×
45

46
                        //Loop until the common data end
47
                        while (this._reader.DxfCode != DxfCode.Start
8,981✔
48
                                        && this._reader.DxfCode != DxfCode.Subclass)
8,981✔
49
                        {
6,720✔
50
                                switch (this._reader.Code)
6,720!
51
                                {
52
                                        //Table name
53
                                        case 2:
54
                                                name = this._reader.ValueAsString;
2,261✔
55
                                                break;
2,261✔
56
                                        //Handle
57
                                        case 5:
58
                                        case 105:
59
                                                handle = this._reader.ValueAsHandle;
1,989✔
60
                                                break;
1,989✔
61
                                        //Start of application - defined group
62
                                        case 102:
63
                                                this.readDefinedGroups(out xdictHandle, out reactors);
209✔
64
                                                break;
209✔
65
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
66
                                        case 330:
67
                                                ownerHandle = this._reader.ValueAsHandle;
1,989✔
68
                                                break;
1,989✔
69
                                        case 71:
70
                                        //Number of entries for dimension style table
71
                                        case 340:
72
                                        //Dimension table has the handles of the styles at the begining
73
                                        default:
74
                                                this._builder.Notify($"Unhandled dxf code {this._reader.Code} at line {this._reader.Position}.");
272✔
75
                                                break;
272✔
76
                                }
77

78
                                this._reader.ReadNext();
6,720✔
79
                        }
6,720✔
80
                }
2,261✔
81

82
                [Obsolete("Only needed for SortEntitiesTable but it should be removed")]
83
                protected void readCommonObjectData(CadTemplate template)
84
                {
576✔
85
                        while (this._reader.DxfCode != DxfCode.Subclass)
2,304✔
86
                        {
1,728✔
87
                                switch (this._reader.Code)
1,728!
88
                                {
89
                                        //object name
90
                                        case 0:
91
                                                Debug.Assert(template.CadObject.ObjectName == this._reader.ValueAsString);
×
92
                                                break;
×
93
                                        //Handle
94
                                        case 5:
95
                                                template.CadObject.Handle = this._reader.ValueAsHandle;
576✔
96
                                                break;
576✔
97
                                        //Start of application - defined group
98
                                        case 102:
99
                                                this.readDefinedGroups(template);
576✔
100
                                                break;
576✔
101
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
102
                                        case 330:
103
                                                template.OwnerHandle = this._reader.ValueAsHandle;
576✔
104
                                                break;
576✔
105
                                        default:
106
                                                this._builder.Notify($"Unhandled dxf code {this._reader.Code} at line {this._reader.Position}.", NotificationType.None);
×
107
                                                break;
×
108
                                }
109

110
                                this._reader.ReadNext();
1,728✔
111
                        }
1,728✔
112
                }
576✔
113

114
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
115
                {
792,663✔
116
                        isExtendedData = false;
792,663✔
117

118
                        switch (this._reader.Code)
792,663✔
119
                        {
120
                                //Handle
121
                                case 5:
122
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
297,377✔
123
                                        break;
297,377✔
124
                                //Check with mapper
125
                                case 100:
126
                                        this.currentSubclass = this._reader.ValueAsString;
206,600✔
127
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
206,600!
128
                                        {
1,136✔
129
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
1,136✔
130
                                        }
1,136✔
131
                                        break;
206,600✔
132
                                //Start of application - defined group
133
                                case 102:
134
                                        this.readDefinedGroups(template);
67,151✔
135
                                        break;
67,151✔
136
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
137
                                case 330:
138
                                        template.OwnerHandle = this._reader.ValueAsHandle;
167,390✔
139
                                        break;
167,390✔
140
                                case 1001:
141
                                        isExtendedData = true;
23,175✔
142
                                        this.readExtendedData(template.EDataTemplateByAppName);
23,175✔
143
                                        break;
23,175✔
144
                                default:
145
                                        this._builder.Notify($"[{this.currentSubclass}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
30,970✔
146
                                        break;
30,970✔
147
                        }
148
                }
792,663✔
149

150
                protected CadEntityTemplate readEntity()
151
                {
145,967✔
152
                        switch (this._reader.ValueAsString)
145,967!
153
                        {
154
                                case DxfFileToken.EntityAttribute:
155
                                        return this.readEntityCodes<AttributeEntity>(new CadAttributeTemplate(new AttributeEntity()), this.readAttributeDefinition);
952✔
156
                                case DxfFileToken.EntityAttributeDefinition:
157
                                        return this.readEntityCodes<AttributeDefinition>(new CadAttributeTemplate(new AttributeDefinition()), this.readAttributeDefinition);
1,120✔
158
                                case DxfFileToken.EntityArc:
159
                                        return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), this.readArc);
686✔
160
                                case DxfFileToken.EntityBody:
UNCOV
161
                                        return this.readEntityCodes<CadBody>(new CadEntityTemplate<CadBody>(), this.readEntitySubclassMap);
×
162
                                case DxfFileToken.EntityCircle:
163
                                        return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), this.readCircle);
3,044✔
164
                                case DxfFileToken.EntityDimension:
165
                                        return this.readEntityCodes<Dimension>(new CadDimensionTemplate(), this.readDimension);
2,618✔
166
                                case DxfFileToken.Entity3DFace:
167
                                        return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), this.readEntitySubclassMap);
238✔
168
                                case DxfFileToken.EntityEllipse:
169
                                        return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), this.readEntitySubclassMap);
204✔
170
                                case DxfFileToken.EntityLeader:
171
                                        return this.readEntityCodes<Leader>(new CadLeaderTemplate(), this.readLeader);
204✔
172
                                case DxfFileToken.EntityLine:
173
                                        return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), this.readEntitySubclassMap);
61,596✔
174
                                case DxfFileToken.EntityLwPolyline:
175
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
4,690✔
176
                                case DxfFileToken.EntityMesh:
177
                                        return this.readEntityCodes<Mesh>(new CadMeshTemplate(), this.readMesh);
408✔
178
                                case DxfFileToken.EntityHatch:
179
                                        return this.readEntityCodes<Hatch>(new CadHatchTemplate(), this.readHatch);
1,632✔
180
                                case DxfFileToken.EntityInsert:
181
                                        return this.readEntityCodes<Insert>(new CadInsertTemplate(), this.readInsert);
5,517✔
182
                                case DxfFileToken.EntityMText:
183
                                        return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), this.readTextEntity);
6,972✔
184
                                case DxfFileToken.EntityMLine:
185
                                        return this.readEntityCodes<MLine>(new CadMLineTemplate(), this.readMLine);
612✔
186
                                case DxfFileToken.EntityMultiLeader:
187
                                        return this.readEntityCodes<MultiLeader>(new CadMLeaderTemplate(), this.readMLeader);
3,060✔
188
                                case DxfFileToken.EntityPdfUnderlay:
189
                                        return this.readEntityCodes<PdfUnderlay>(new CadUnderlayTemplate<PdfUnderlayDefinition>(new PdfUnderlay()), this.readUnderlayEntity<PdfUnderlayDefinition>);
204✔
190
                                case DxfFileToken.EntityPoint:
191
                                        return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), this.readEntitySubclassMap);
9,044✔
192
                                case DxfFileToken.EntityPolyline:
193
                                        return this.readPolyline();
10,444✔
194
                                case DxfFileToken.EntityOle2Frame:
UNCOV
195
                                        return this.readEntityCodes<Ole2Frame>(new CadOle2FrameTemplate(), this.readOle2Frame);
×
196
                                case DxfFileToken.EntityRay:
197
                                        return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), this.readEntitySubclassMap);
204✔
198
                                case DxfFileToken.EndSequence:
199
                                        return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), this.readEntitySubclassMap);
476✔
200
                                case DxfFileToken.EntityTrace:
201
                                case DxfFileToken.EntitySolid:
202
                                        return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), this.readModelerGeometry);
13,742✔
203
                                case DxfFileToken.EntityTable:
204
                                        return this.readEntityCodes<TableEntity>(new CadTableEntityTemplate(), this.readTableEntity);
408✔
205
                                case DxfFileToken.EntityText:
206
                                        return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), this.readTextEntity);
14,166✔
207
                                case DxfFileToken.EntityTolerance:
208
                                        return this.readEntityCodes<Tolerance>(new CadToleranceTemplate(new Tolerance()), this.readTolerance);
612✔
209
                                case DxfFileToken.EntityVertex:
UNCOV
210
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
×
211
                                case DxfFileToken.EntityViewport:
212
                                        return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
1,244✔
213
                                case DxfFileToken.EntityShape:
214
                                        return this.readEntityCodes<Shape>(new CadShapeTemplate(new Shape()), this.readShape);
238✔
215
                                case DxfFileToken.EntitySpline:
216
                                        return this.readEntityCodes<Spline>(new CadSplineTemplate(), this.readSpline);
408✔
217
                                case DxfFileToken.Entity3DSolid:
218
                                        return this.readEntityCodes<Solid3D>(new CadSolid3DTemplate(), this.readSolid3d);
408✔
219
                                case DxfFileToken.EntityRegion:
220
                                        return this.readEntityCodes<Region>(new CadEntityTemplate<Region>(), this.readModelerGeometry);
204✔
221
                                case DxfFileToken.EntityImage:
222
                                        return this.readEntityCodes<RasterImage>(new CadWipeoutBaseTemplate(new RasterImage()), this.readWipeoutBase);
204✔
223
                                case DxfFileToken.EntityWipeout:
224
                                        return this.readEntityCodes<Wipeout>(new CadWipeoutBaseTemplate(new Wipeout()), this.readWipeoutBase);
204✔
225
                                case DxfFileToken.EntityXline:
226
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
204✔
227
                                default:
UNCOV
228
                                        DxfMap map = DxfMap.Create<Entity>();
×
229
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
×
230
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
×
231
                                        {
×
232
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
×
233
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
×
234
                                        }
×
235
                                        else
UNCOV
236
                                        {
×
237
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
×
238
                                        }
×
239

UNCOV
240
                                        this._reader.ReadNext();
×
241

242
                                        do
UNCOV
243
                                        {
×
244
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
×
245
                                                {
×
246
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
×
247
                                                        if (isExtendedData)
×
248
                                                                continue;
×
249
                                                }
×
250

UNCOV
251
                                                this._reader.ReadNext();
×
252
                                        }
×
253
                                        while (this._reader.DxfCode != DxfCode.Start);
×
254

UNCOV
255
                                        return unknownEntityTemplate;
×
256
                        }
257
                }
145,967✔
258

259
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
260
                        where T : Entity
261
                {
194,785✔
262
                        this._reader.ReadNext();
194,785✔
263

264
                        DxfMap map = DxfMap.Create<T>();
194,785✔
265

266
                        while (this._reader.DxfCode != DxfCode.Start)
2,638,239✔
267
                        {
2,443,454✔
268
                                if (!readEntity(template, map))
2,443,454✔
269
                                {
857,232✔
270
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
857,232✔
271
                                        if (isExtendedData)
857,232✔
272
                                                continue;
13,666✔
273
                                }
843,566✔
274

275
                                if (this.lockPointer)
2,429,788✔
276
                                {
2,992✔
277
                                        this.lockPointer = false;
2,992✔
278
                                        continue;
2,992✔
279
                                }
280

281
                                if (this._reader.DxfCode != DxfCode.Start)
2,426,796✔
282
                                        this._reader.ReadNext();
2,426,322✔
283
                        }
2,426,796✔
284

285
                        return template;
194,785✔
286
                }
194,785✔
287

288
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
289
                {
924,757✔
290
                        isExtendedData = false;
924,757✔
291
                        switch (this._reader.Code)
924,757✔
292
                        {
293
                                case 6:
294
                                        template.LineTypeName = this._reader.ValueAsString;
25,676✔
295
                                        break;
25,676✔
296
                                case 8:
297
                                        template.LayerName = this._reader.ValueAsString;
211,285✔
298
                                        break;
211,285✔
299
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
300
                                case 67:
301
                                        break;
1,236✔
302
                                //Number of bytes Proxy entity graphics data
303
                                case 92:
304
                                case 160:
305
                                //Proxy entity graphics data
306
                                case 310:
307
                                        break;
76,568✔
308
                                case 347:
309
                                        template.MaterialHandle = this._reader.ValueAsHandle;
680✔
310
                                        break;
680✔
311
                                case 430:
312
                                        template.BookColorName = this._reader.ValueAsString;
170✔
313
                                        break;
170✔
314
                                default:
315
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
609,142✔
316
                                        {
474,944✔
317
                                                this.readCommonCodes(template, out isExtendedData, map);
474,944✔
318
                                        }
474,944✔
319
                                        break;
609,142✔
320
                        }
321
                }
924,757✔
322

323
                [Obsolete("use lockpointer instead")]
324
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
325
                {
2,900✔
326
                        if (this._reader.DxfCode == DxfCode.Start)
2,900!
UNCOV
327
                        {
×
328
                                return true;
×
329
                        }
330
                        else
331
                        {
2,900✔
332
                                return func.Invoke(template, map);
2,900✔
333
                        }
334
                }
2,900✔
335

336
                protected bool checkEntityEnd(CadEntityTemplate template, DxfMap map, string subclass, Func<CadEntityTemplate, DxfMap, string, bool> func)
337
                {
408✔
338
                        if (this._reader.DxfCode == DxfCode.Start)
408!
339
                        {
408✔
340
                                return true;
408✔
341
                        }
342
                        else
UNCOV
343
                        {
×
344
                                return func.Invoke(template, map, subclass);
×
345
                        }
346
                }
408✔
347

348
                private bool readCircle(CadEntityTemplate template, DxfMap map, string subclass = null)
349
                {
35,945✔
350
                        Circle circle = template.CadObject as Circle;
35,945✔
351

352
                        switch (this._reader.Code)
35,945✔
353
                        {
354
                                case 40:
355
                                        double radius = this._reader.ValueAsDouble;
3,730✔
356
                                        if (radius <= 0)
3,730!
UNCOV
357
                                        {
×
358
                                                circle.Radius = MathHelper.Epsilon;
×
359
                                        }
×
360
                                        else
361
                                        {
3,730✔
362
                                                circle.Radius = radius;
3,730✔
363
                                        }
3,730✔
364
                                        return true;
3,730✔
365
                                default:
366
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Circle]);
32,215✔
367
                        }
368
                }
35,945✔
369

370
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
371
                {
8,992✔
372
                        switch (this._reader.Code)
8,992✔
373
                        {
374
                                default:
375
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
8,992✔
376
                                        {
7,620✔
377
                                                return this.readCircle(template, map, DxfSubclassMarker.Circle);
7,620✔
378
                                        }
379
                                        return true;
1,372✔
380
                        }
381
                }
8,992✔
382

383
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
384
                {
33,438✔
385
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
33,438✔
386
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
33,438✔
387

388
                        switch (this._reader.Code)
33,438!
389
                        {
390
                                case 44:
391
                                case 46:
UNCOV
392
                                        return true;
×
393
                                case 101:
394
                                        var att = tmp.CadObject as AttributeBase;
66✔
395
                                        att.MText = new MText();
66✔
396
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
66✔
397
                                        tmp.MTextTemplate = mtextTemplate;
66✔
398
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
66✔
399
                                        return true;
66✔
400
                                default:
401
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
33,372✔
402
                                        {
25,250✔
403
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
25,250✔
404
                                        }
405
                                        return true;
8,122✔
406
                        }
407
                }
33,438✔
408

409
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
410
                {
134,334✔
411
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
134,334!
412
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
134,334✔
413
                        TableEntity table = tmp.CadObject as TableEntity;
134,334✔
414

415
                        switch (this._reader.Code)
134,334!
416
                        {
417
                                case 1:
418
                                        TableEntity.CellContent content;
419
                                        if (tmp.CurrentCell.Content == null)
2,652!
420
                                        {
2,652✔
421
                                                content = new TableEntity.CellContent();
2,652✔
422
                                                content.Value.ValueType = TableEntity.CellValueType.String;
2,652✔
423
                                                tmp.CurrentCell.Contents.Add(content);
2,652✔
424
                                        }
2,652✔
425
                                        else
UNCOV
426
                                        {
×
427
                                                content = tmp.CurrentCell.Content;
×
428
                                        }
×
429

430
                                        if (content.Value.Value == null)
2,652!
431
                                        {
2,652✔
432
                                                content.Value.Value = this._reader.ValueAsString;
2,652✔
433
                                        }
2,652✔
434
                                        else
UNCOV
435
                                        {
×
436
                                                string str = content.Value.Value as string;
×
437
                                                str += this._reader.ValueAsString;
×
438
                                                content.Value.Value = str;
×
439
                                        }
×
440
                                        return true;
2,652✔
441
                                case 2:
442
                                        if (this.currentSubclass.Equals(DxfSubclassMarker.TableEntity, StringComparison.OrdinalIgnoreCase))
408!
UNCOV
443
                                        {
×
444
                                                content = tmp.CurrentCell.Content;
×
445
                                                if (content.Value.Value == null)
×
446
                                                {
×
447
                                                        content.Value.Value = this._reader.ValueAsString;
×
448
                                                }
×
449
                                                else
UNCOV
450
                                                {
×
451
                                                        string str = content.Value.Value as string;
×
452
                                                        str += this._reader.ValueAsString;
×
453
                                                        content.Value.Value = str;
×
454
                                                }
×
455
                                        }
×
456
                                        else
457
                                        {
408✔
458
                                                tmp.BlockName = this._reader.ValueAsString;
408✔
459
                                        }
408✔
460
                                        return true;
408✔
461
                                //Border overrides:
462
                                case 177:
463
                                        //Cell override flag value (before AutoCAD 2007)
464
                                        return true;
2,788✔
465
                                case 279:
466
                                        //Lineweight for the top border of the cell; override applied at the cell level
467
                                        tmp.CurrentCell.StyleOverride.TopBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
1,428✔
468
                                        return true;
1,428✔
469
                                case 275:
470
                                        //Lineweight for the right border of the cell; override applied at the cell level
471
                                        tmp.CurrentCell.StyleOverride.RightBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
408✔
472
                                        return true;
408✔
473
                                case 276:
474
                                        //Lineweight for the bottom border of the cell; override applied at the cell level
UNCOV
475
                                        tmp.CurrentCell.StyleOverride.BottomBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
×
476
                                        return true;
×
477
                                case 278:
478
                                        //Lineweight for the left border of the cell; override applied at the cell level
479
                                        tmp.CurrentCell.StyleOverride.LeftBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
1,224✔
480
                                        return true;
1,224✔
481
                                case 69:
482
                                        //True color value for the top border of the cell; override applied at the cell level
483
                                        tmp.CurrentCell.StyleOverride.TopBorder.Color = new Color(this._reader.ValueAsShort);
1,428✔
484
                                        return true;
1,428✔
485
                                case 65:
486
                                        //True color value for the right border of the cell; override applied at the cell level
487
                                        tmp.CurrentCell.StyleOverride.RightBorder.Color = new Color(this._reader.ValueAsShort);
408✔
488
                                        return true;
408✔
489
                                case 66:
490
                                        //True color value for the bottom border of the cell; override applied at the cell level
UNCOV
491
                                        tmp.CurrentCell.StyleOverride.BottomBorder.Color = new Color(this._reader.ValueAsShort);
×
492
                                        return true;
×
493
                                case 68:
494
                                        //True color value for the left border of the cell; override applied at the cell level
495
                                        tmp.CurrentCell.StyleOverride.LeftBorder.Color = new Color(this._reader.ValueAsShort);
1,224✔
496
                                        return true;
1,224✔
497
                                case 40:
498
                                        tmp.HorizontalMargin = this._reader.ValueAsDouble;
204✔
499
                                        return true;
204✔
500
                                case 63:
501
                                        tmp.CurrentCell.StyleOverride.BackgroundColor = new Color(this._reader.ValueAsShort);
204✔
502
                                        return true;
204✔
503
                                case 64:
504
                                        tmp.CurrentCell.StyleOverride.ContentColor = new Color(this._reader.ValueAsShort);
204✔
505
                                        return true;
204✔
506
                                case 140:
507
                                        if (tmp.CurrentCellTemplate != null)
4,896✔
508
                                        {
4,284✔
509
                                                tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
4,284✔
510
                                        }
4,284✔
511
                                        return true;
4,896✔
512
                                case 283:
513
                                        tmp.CurrentCell.StyleOverride.IsFillColorOn = this._reader.ValueAsBool;
204✔
514
                                        return true;
204✔
515
                                case 342:
516
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
408✔
517
                                        return true;
408✔
518
                                case 343:
519
                                        tmp.BlockOwnerHandle = this._reader.ValueAsHandle;
408✔
520
                                        return true;
408✔
521
                                case 141:
522
                                        var row = new TableEntity.Row();
2,244✔
523
                                        row.Height = this._reader.ValueAsDouble;
2,244✔
524
                                        table.Rows.Add(row);
2,244✔
525
                                        return true;
2,244✔
526
                                case 142:
527
                                        var col = new TableEntity.Column();
1,632✔
528
                                        col.Width = this._reader.ValueAsDouble;
1,632✔
529
                                        table.Columns.Add(col);
1,632✔
530
                                        return true;
1,632✔
531
                                case 144:
532
                                        tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
408✔
533
                                        return true;
408✔
534
                                case 145:
535
                                        tmp.CurrentCell.Rotation = this._reader.ValueAsDouble;
8,364✔
536
                                        return true;
8,364✔
537
                                case 170:
538
                                        //Has data flag
539
                                        return true;
612✔
540
                                case 171:
541
                                        tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
8,364✔
542
                                        return true;
8,364✔
543
                                case 172:
544
                                        tmp.CurrentCell.EdgeFlags = this._reader.ValueAsShort;
8,364✔
545
                                        return true;
8,364✔
546
                                case 173:
547
                                        tmp.CurrentCell.MergedValue = this._reader.ValueAsShort;
8,364✔
548
                                        return true;
8,364✔
549
                                case 174:
550
                                        tmp.CurrentCell.AutoFit = this._reader.ValueAsBool;
8,364✔
551
                                        return true;
8,364✔
552
                                case 175:
553
                                        tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
8,364✔
554
                                        return true;
8,364✔
555
                                case 176:
556
                                        tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
8,364✔
557
                                        return true;
8,364✔
558
                                case 178:
559
                                        tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
8,364✔
560
                                        return true;
8,364✔
561
                                case 179:
562
                                        //Unknown value
563
                                        return true;
408✔
564
                                case 301:
565
                                        content = new TableEntity.CellContent();
5,576✔
566
                                        tmp.CurrentCell.Contents.Add(content);
5,576✔
567
                                        this.readCellValue(content);
5,576✔
568
                                        return true;
5,576✔
569
                                case 340:
570
                                        tmp.CurrentCellTemplate.ValueHandle = this._reader.ValueAsHandle;
408✔
571
                                        return true;
408✔
572
                                default:
573
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
37,638✔
574
                                        {
36,210✔
575
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
36,210✔
576
                                        }
577
                                        return true;
1,428✔
578
                        }
579
                }
134,334✔
580

581
                private void readCellValue(TableEntity.CellContent content)
582
                {
5,576✔
583
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
5,576!
584
                        {
5,576✔
585
                                this._reader.ReadNext();
5,576✔
586
                        }
5,576✔
587
                        else
UNCOV
588
                        {
×
589
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
590
                        }
591

592
                        while (this._reader.Code != 304
36,448✔
593
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
36,448✔
594
                        {
30,872✔
595
                                switch (this._reader.Code)
30,872!
596
                                {
597
                                        case 1:
598
                                                content.Value.Text = this._reader.ValueAsString;
1,632✔
599
                                                break;
1,632✔
600
                                        case 2:
UNCOV
601
                                                content.Value.Text += this._reader.ValueAsString;
×
602
                                                break;
×
603
                                        case 11:
604
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
136✔
605
                                                break;
136✔
606
                                        case 21:
607
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
136✔
608
                                                break;
136✔
609
                                        case 31:
610
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
136✔
611
                                                break;
136✔
612
                                        case 302:
613
                                                //TODO: Fix this assignation to cell value
614
                                                content.Value.Value = this._reader.ValueAsString;
5,576✔
615
                                                break;
5,576✔
616
                                        case 90:
617
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
5,576✔
618
                                                break;
5,576✔
619
                                        case 91:
620
                                                content.Value.Value = this._reader.ValueAsInt;
136✔
621
                                                break;
136✔
622
                                        case 92:
623
                                                //Extended cell flags (from AutoCAD 2007)
624
                                                break;
136✔
625
                                        case 93:
626
                                                content.Value.Flags = this._reader.ValueAsInt;
5,576✔
627
                                                break;
5,576✔
628
                                        case 94:
629
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
5,576✔
630
                                                break;
5,576✔
631
                                        case 140:
632
                                                content.Value.Value = this._reader.ValueAsDouble;
544✔
633
                                                break;
544✔
634
                                        case 300:
635
                                                content.Value.Format = this._reader.ValueAsString;
5,576✔
636
                                                break;
5,576✔
637
                                        case 310:
638
                                                //Data for proxy entity graphics (multiple lines; 256-character maximum per line)
639
                                                break;
136✔
640
                                        default:
UNCOV
641
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
642
                                                break;
×
643
                                }
644

645
                                this._reader.ReadNext();
30,872✔
646
                        }
30,872✔
647
                }
5,576✔
648

649
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
650
                {
288,982✔
651
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,982✔
652
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
288,982✔
653

654
                        switch (this._reader.Code)
288,982✔
655
                        {
656
                                case 1 or 3 when tmp.CadObject is MText mtext:
25,928✔
657
                                        mtext.Value += this._reader.ValueAsString;
9,690✔
658
                                        return true;
9,690✔
659
                                case 50 when tmp.CadObject is MText mtext://Read only for MText
480!
UNCOV
660
                                        double angle = this._reader.ValueAsAngle;
×
661
                                        mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
662
                                        return true;
×
663
                                case 7:
664
                                        tmp.StyleName = this._reader.ValueAsString;
2,856✔
665
                                        return true;
2,856✔
666
                                case 101 when tmp.CadObject is MText mtext:
136✔
667
                                        this.readColumnData(mtext);
136✔
668
                                        this.lockPointer = true;
136✔
669
                                        return true;
136✔
670
                                default:
671
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
276,300✔
672
                        }
673
                }
288,982✔
674

675
                private void readColumnData(MText mtext)
676
                {
136✔
677
                        this._reader.ReadNext();
136✔
678
                        while (this._reader.DxfCode != DxfCode.Start)
2,584✔
679
                        {
2,448✔
680
                                switch (this._reader.Code)
2,448✔
681
                                {
682
                                        //Element count?
683
                                        case 70:
684
                                                break;
136✔
685
                                        case 71:
686
                                                mtext.ColumnData.ColumnType = (ColumnType)this._reader.ValueAsShort;
136✔
687
                                                break;
136✔
688
                                        case 72:
689
                                                mtext.ColumnData.ColumnCount = this._reader.ValueAsInt;
136✔
690
                                                break;
136✔
691
                                        //X - axis dir 3BD 10
692
                                        case 10:
693
                                        case 20:
694
                                        case 30:
695
                                        //Insertion point 3BD 11
696
                                        case 11:
697
                                        case 21:
698
                                        case 31:
699
                                        //Rect width BD 40
700
                                        case 40:
701
                                        //Rect height BD 41
702
                                        case 41:
703
                                        //Extents width BD 42
704
                                        case 42:
705
                                        //Extents height BD 43
706
                                        case 43:
707
                                                break;
1,360✔
708
                                        case 44:
709
                                                mtext.ColumnData.Width = this._reader.ValueAsDouble;
136✔
710
                                                break;
136✔
711
                                        case 45:
712
                                                mtext.ColumnData.Gutter = this._reader.ValueAsDouble;
136✔
713
                                                break;
136✔
714
                                        case 73:
715
                                                mtext.ColumnData.AutoHeight = this._reader.ValueAsBool;
136✔
716
                                                break;
136✔
717
                                        case 74:
718
                                                mtext.ColumnData.FlowReversed = this._reader.ValueAsBool;
136✔
719
                                                break;
136✔
720
                                        default:
721
                                                this._builder.Notify($"[MText.ColumnData] unkown dxf code {this._reader.Code}.", NotificationType.None);
136✔
722
                                                break;
136✔
723
                                }
724

725
                                this._reader.ReadNext();
2,448✔
726
                        }
2,448✔
727
                }
136✔
728

729
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
730
                {
6,120✔
731
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,120✔
732

733
                        switch (this._reader.Code)
6,120✔
734
                        {
735
                                case 3:
736
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
612✔
737
                                        return true;
612✔
738
                                default:
739
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,508✔
740
                        }
741
                }
6,120✔
742

743
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
744
                {
68,476✔
745
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
68,476✔
746

747
                        switch (this._reader.Code)
68,476✔
748
                        {
749
                                case 2:
750
                                        tmp.BlockName = this._reader.ValueAsString;
2,618✔
751
                                        return true;
2,618✔
752
                                case 3:
753
                                        tmp.StyleName = this._reader.ValueAsString;
2,244✔
754
                                        return true;
2,244✔
755
                                case 50:
756
                                        var dim = new DimensionLinear();
238✔
757
                                        tmp.SetDimensionObject(dim);
238✔
758
                                        dim.Rotation = this._reader.ValueAsAngle;
238✔
759
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
238✔
760
                                        return true;
238✔
761
                                case 70:
762
                                        //Flags do not have set
763
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,618✔
764
                                        return true;
2,618✔
765
                                //Measurement - read only
766
                                case 42:
767
                                        return true;
2,244✔
768
                                //Undocumented codes
769
                                case 73:
770
                                case 74:
771
                                case 75:
772
                                case 90:
773
                                case 361:
774
                                        return true;
4,488✔
775
                                case 100:
776
                                        switch (this._reader.ValueAsString)
7,344✔
777
                                        {
778
                                                case DxfSubclassMarker.Dimension:
779
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,244✔
780
                                                case DxfSubclassMarker.AlignedDimension:
781
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,020✔
782
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,020✔
783
                                                        return true;
1,020✔
784
                                                case DxfSubclassMarker.DiametricDimension:
785
                                                        tmp.SetDimensionObject(new DimensionDiameter());
204✔
786
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
204✔
787
                                                        return true;
204✔
788
                                                case DxfSubclassMarker.Angular2LineDimension:
789
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
204✔
790
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
204✔
791
                                                        return true;
204✔
792
                                                case DxfSubclassMarker.Angular3PointDimension:
793
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
204✔
794
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
204✔
795
                                                        return true;
204✔
796
                                                case DxfSubclassMarker.RadialDimension:
797
                                                        tmp.SetDimensionObject(new DimensionRadius());
204✔
798
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
204✔
799
                                                        return true;
204✔
800
                                                case DxfSubclassMarker.OrdinateDimension:
801
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
408✔
802
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
408✔
803
                                                        return true;
408✔
804
                                                case DxfSubclassMarker.LinearDimension:
805
                                                        return true;
612✔
806
                                                default:
807
                                                        return false;
2,244✔
808
                                        }
809
                                default:
810
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
46,682✔
811
                        }
812
                }
68,476✔
813

814
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
815
                {
43,656✔
816
                        CadHatchTemplate tmp = template as CadHatchTemplate;
43,656✔
817
                        Hatch hatch = tmp.CadObject;
43,656✔
818

819
                        XY seedPoint = new XY();
43,656✔
820

821
                        switch (this._reader.Code)
43,656!
822
                        {
823
                                case 2:
824
                                        hatch.Pattern.Name = this._reader.ValueAsString;
1,632✔
825
                                        return true;
1,632✔
826
                                case 10:
827
                                        seedPoint.X = this._reader.ValueAsDouble;
3,264✔
828
                                        hatch.SeedPoints.Add(seedPoint);
3,264✔
829
                                        return true;
3,264✔
830
                                case 20:
831
                                        seedPoint = hatch.SeedPoints.LastOrDefault();
3,264✔
832
                                        seedPoint.Y = this._reader.ValueAsDouble;
3,264✔
833
                                        hatch.SeedPoints[hatch.SeedPoints.Count - 1] = seedPoint;
3,264✔
834
                                        return true;
3,264✔
835
                                case 30:
836
                                        hatch.Elevation = this._reader.ValueAsDouble;
1,632✔
837
                                        return true;
1,632✔
838
                                case 53:
UNCOV
839
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
840
                                        return true;
×
841
                                //TODO: Check hatch undocumented codes
842
                                case 90:
UNCOV
843
                                        return true;
×
844
                                //Information about the hatch pattern
845
                                case 75:
846
                                        return true;
1,632✔
847
                                //Number of pattern definition lines
848
                                case 78:
849
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,224✔
850
                                        this.lockPointer = true;
1,224✔
851
                                        return true;
1,224✔
852
                                //Number of boundary paths (loops)
853
                                case 91:
854
                                        this.readLoops(tmp, this._reader.ValueAsInt);
1,632✔
855
                                        this.lockPointer = true;
1,632✔
856
                                        return true;
1,632✔
857
                                //Number of seed points
858
                                case 98:
859
                                        return true;
1,020✔
860
                                case 450:
861
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
340✔
862
                                        return true;
340✔
863
                                case 451:
864
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
340✔
865
                                        return true;
340✔
866
                                case 452:
867
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
340✔
868
                                        return true;
340✔
869
                                case 453:
870
                                        //Number of colors
871
                                        return true;
340✔
872
                                case 460:
873
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
340✔
874
                                        return true;
340✔
875
                                case 461:
876
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
340✔
877
                                        return true;
340✔
878
                                case 462:
879
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
340✔
880
                                        return true;
340✔
881
                                case 463:
882
                                        GradientColor gradient = new GradientColor();
680✔
883
                                        gradient.Value = this._reader.ValueAsDouble;
680✔
884
                                        hatch.GradientColor.Colors.Add(gradient);
680✔
885
                                        return true;
680✔
886
                                case 63:
887
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
680✔
888
                                        if (colorByIndex != null)
680✔
889
                                        {
680✔
890
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
680✔
891
                                        }
680✔
892
                                        return true;
680✔
893
                                case 421:
894
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
680✔
895
                                        if (colorByRgb != null)
680✔
896
                                        {
680✔
897
                                                //TODO: Hatch assign color by true color
898
                                                //TODO: Is always duplicated by 63, is it needed??
899
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
900
                                        }
680✔
901
                                        return true;
680✔
902
                                case 470:
903
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
340✔
904
                                        return true;
340✔
905
                                default:
906
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
23,596✔
907
                        }
908
                }
43,656✔
909

910
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
911
                {
59,000✔
912
                        CadInsertTemplate tmp = template as CadInsertTemplate;
59,000✔
913

914
                        switch (this._reader.Code)
59,000✔
915
                        {
916
                                case 2:
917
                                        tmp.BlockName = this._reader.ValueAsString;
5,517✔
918
                                        return true;
5,517✔
919
                                case 100:
920
                                        //AcDbEntity
921
                                        //AcDbBlockReference
922
                                        //AcDbMInsertBlock
923
                                        return true;
5,542✔
924
                                case 66:
925
                                        return true;
476✔
926
                                default:
927
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
47,465✔
928
                        }
929
                }
59,000✔
930

931
                private CadEntityTemplate readPolyline()
932
                {
10,444✔
933
                        if (this._builder.Version == ACadVersion.Unknown
10,444!
934
                                || this._builder.Version == ACadVersion.AC1009)
10,444✔
935
                        {
10,036✔
936
                                return this.readLegacyPolyline();
10,036✔
937
                        }
938

939
                        CadPolyLineTemplate template = null;
408✔
940
                        template = new CadPolyLineTemplate();
408✔
941
                        this.readEntityCodes<Entity>(template, this.readPolyline);
408✔
942

943
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
408!
UNCOV
944
                        {
×
945
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
946
                                return null;
×
947
                        }
948

949
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
2,856!
950
                        {
2,448✔
951
                                var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,448✔
952

953
                                if (vertexTemplate.OwnerHandle == null)
2,448!
UNCOV
954
                                {
×
955
                                        vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
956
                                }
×
957

958
                                template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,448✔
959
                                _builder.AddTemplate(vertexTemplate);
2,448✔
960
                        }
2,448✔
961

962
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
816!
963
                        {
408✔
964
                                var seqend = new Seqend();
408✔
965
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
408✔
966
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
408✔
967

968
                                if (seqendTemplate.OwnerHandle == null)
408!
UNCOV
969
                                {
×
970
                                        seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
971
                                }
×
972

973
                                template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
408✔
974
                                _builder.AddTemplate(seqendTemplate);
408✔
975
                        }
408✔
976

977
                        return template;
408✔
978
                }
10,444✔
979

980
                private CadEntityTemplate readLegacyPolyline()
981
                {
10,036✔
982
                        var polyline = new Polyline2D();
10,036✔
983
                        CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,036✔
984
                        this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,036✔
985

986
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
45,896!
987
                        {
35,860✔
988
                                Vertex2D v = new Vertex2D();
35,860✔
989
                                CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
35,860✔
990
                                this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
35,860✔
991

992
                                if (vertexTemplate.Vertex.Handle == 0)
35,860!
UNCOV
993
                                {
×
994
                                        polyline.Vertices.Add(v);
×
995
                                }
×
996
                                else
997
                                {
35,860✔
998
                                        template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
35,860✔
999
                                        this._builder.AddTemplate(vertexTemplate);
35,860✔
1000
                                }
35,860✔
1001
                        }
35,860✔
1002

1003
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
20,072!
1004
                        {
10,036✔
1005
                                var seqend = new Seqend();
10,036✔
1006
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,036✔
1007
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,036✔
1008

1009
                                polyline.Vertices.Seqend = seqend;
10,036✔
1010
                        }
10,036✔
1011

1012
                        return template;
10,036✔
1013
                }
10,036✔
1014

1015
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1016
                {
75,008✔
1017
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
75,008✔
1018

1019
                        switch (this._reader.Code)
75,008✔
1020
                        {
1021
                                //DXF: always 0
1022
                                //APP: a “dummy” point; the X and Y values are always 0, and the Z value is the polyline's elevation (in OCS when 2D, WCS when 3D)
1023
                                case 10:
1024
                                case 20:
1025
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1026
                                case 66:
1027
                                        return true;
31,332✔
1028
                                case 100:
1029
                                        switch (this._reader.ValueAsString)
816!
1030
                                        {
1031
                                                case DxfSubclassMarker.Polyline:
UNCOV
1032
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
1033
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
1034
                                                        return true;
×
1035
                                                case DxfSubclassMarker.Polyline3d:
1036
                                                        tmp.SetPolyLineObject(new Polyline3D());
204✔
1037
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
204✔
1038
                                                        return true;
204✔
1039
                                                case DxfSubclassMarker.PolyfaceMesh:
1040
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
204✔
1041
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
204✔
1042
                                                        return true;
204✔
1043
                                                case DxfSubclassMarker.PolygonMesh:
UNCOV
1044
                                                        tmp.SetPolyLineObject(new PolygonMesh());
×
1045
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
1046
                                                        return true;
×
1047
                                                default:
1048
                                                        return false;
408✔
1049
                                        }
1050
                                default:
1051
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
42,860✔
1052
                        }
1053
                }
75,008✔
1054

1055
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1056
                {
5,100✔
1057
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
1058

1059
                        switch (this._reader.Code)
5,100✔
1060
                        {
1061
                                case 3:
1062
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
204✔
1063
                                        return true;
204✔
1064
                                case 10:
1065
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
816✔
1066
                                        return true;
816✔
1067
                                case 20:
1068
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1069
                                        y.Y = this._reader.ValueAsDouble;
816✔
1070
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
816✔
1071
                                        return true;
816✔
1072
                                case 30:
1073
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1074
                                        z.Z = this._reader.ValueAsDouble;
816✔
1075
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
816✔
1076
                                        return true;
816✔
1077
                                case 340:
1078
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
204✔
1079
                                        return true;
204✔
1080
                                //Hook line flag - read only
1081
                                case 75:
1082
                                //Vertices count
1083
                                case 76:
1084
                                        return true;
408✔
1085
                                default:
1086
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,836✔
1087
                        }
1088
                }
5,100✔
1089

1090
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1091
                {
87,399✔
1092
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
87,399✔
1093

1094
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
87,399✔
1095

1096
                        switch (this._reader.Code)
87,399!
1097
                        {
1098
                                case 10:
1099
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
20,788✔
1100
                                        return true;
20,788✔
1101
                                case 20:
1102
                                        if (last is not null)
20,788✔
1103
                                        {
20,788✔
1104
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
20,788✔
1105
                                        }
20,788✔
1106
                                        return true;
20,788✔
1107
                                case 40:
1108
                                        if (last is not null)
2,040✔
1109
                                        {
2,040✔
1110
                                                last.StartWidth = this._reader.ValueAsDouble;
2,040✔
1111
                                        }
2,040✔
1112
                                        return true;
2,040✔
1113
                                case 41:
1114
                                        if (last is not null)
2,040✔
1115
                                        {
2,040✔
1116
                                                last.EndWidth = this._reader.ValueAsDouble;
2,040✔
1117
                                        }
2,040✔
1118
                                        return true;
2,040✔
1119
                                case 42:
1120
                                        if (last is not null)
2,784✔
1121
                                        {
2,784✔
1122
                                                last.Bulge = this._reader.ValueAsDouble;
2,784✔
1123
                                        }
2,784✔
1124
                                        return true;
2,784✔
1125
                                case 50:
UNCOV
1126
                                        if (last is not null)
×
1127
                                        {
×
1128
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
1129
                                        }
×
1130
                                        return true;
×
1131
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1132
                                case 66:
1133
                                //Vertex count
1134
                                case 90:
1135
                                        return true;
4,690✔
1136
                                case 91:
UNCOV
1137
                                        if (last is not null)
×
1138
                                        {
×
1139
                                                last.Id = this._reader.ValueAsInt;
×
1140
                                        }
×
1141
                                        return true;
×
1142
                                default:
1143
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,269✔
1144
                        }
1145
                }
87,399✔
1146

1147
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1148
                {
35,904✔
1149
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
1150

1151
                        switch (this._reader.Code)
35,904✔
1152
                        {
1153
                                case 100:
1154
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
1155
                                        {
408✔
1156
                                                tmp.SubclassMarker = true;
408✔
1157
                                        }
408✔
1158
                                        return true;
816✔
1159
                                //Count of sub-entity which property has been overridden
1160
                                case 90:
1161
                                        //TODO: process further entities
1162
                                        return true;
408✔
1163
                                case 92:
1164
                                        if (!tmp.SubclassMarker)
612✔
1165
                                        {
204✔
1166
                                                return false;
204✔
1167
                                        }
1168

1169
                                        int nvertices = this._reader.ValueAsInt;
408✔
1170
                                        for (int i = 0; i < nvertices; i++)
52,224✔
1171
                                        {
25,704✔
1172
                                                this._reader.ReadNext();
25,704✔
1173
                                                double x = this._reader.ValueAsDouble;
25,704✔
1174
                                                this._reader.ReadNext();
25,704✔
1175
                                                double y = this._reader.ValueAsDouble;
25,704✔
1176
                                                this._reader.ReadNext();
25,704✔
1177
                                                double z = this._reader.ValueAsDouble;
25,704✔
1178
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
1179
                                        }
25,704✔
1180
                                        return true;
408✔
1181
                                case 93:
1182
                                        int size = this._reader.ValueAsInt;
408✔
1183
                                        this._reader.ReadNext();
408✔
1184

1185
                                        int indexes = 0;
408✔
1186
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
1187
                                        {
27,744✔
1188
                                                indexes = this._reader.ValueAsInt;
27,744✔
1189
                                                this._reader.ReadNext();
27,744✔
1190

1191
                                                int[] face = new int[indexes];
27,744✔
1192
                                                for (int j = 0; j < indexes; j++)
267,648✔
1193
                                                {
106,080✔
1194
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
1195

1196
                                                        if ((i + j + 2) < size)
106,080✔
1197
                                                        {
105,672✔
1198
                                                                this._reader.ReadNext();
105,672✔
1199
                                                        }
105,672✔
1200
                                                }
106,080✔
1201

1202
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1203
                                        }
27,744✔
1204

1205
                                        Debug.Assert(this._reader.Code == 90);
408✔
1206

1207
                                        return true;
408✔
1208
                                case 94:
1209
                                        int numEdges = this._reader.ValueAsInt;
408✔
1210
                                        this._reader.ReadNext();
408✔
1211
                                        for (int i = 0; i < numEdges; i++)
106,896✔
1212
                                        {
53,040✔
1213
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
1214

1215
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
1216
                                                this._reader.ReadNext();
53,040✔
1217
                                                edge.End = this._reader.ValueAsInt;
53,040✔
1218

1219
                                                if (i < numEdges - 1)
53,040✔
1220
                                                {
52,632✔
1221
                                                        this._reader.ReadNext();
52,632✔
1222
                                                }
52,632✔
1223

1224
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1225
                                        }
53,040✔
1226

1227
                                        Debug.Assert(this._reader.Code == 90);
408✔
1228

1229
                                        return true;
408✔
1230
                                case 95:
1231
                                        this._reader.ReadNext();
408✔
1232
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
1233
                                        {
53,040✔
1234
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
1235
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
1236

1237
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1238

1239
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
1240
                                                {
52,632✔
1241
                                                        this._reader.ReadNext();
52,632✔
1242
                                                }
52,632✔
1243
                                        }
53,040✔
1244

1245
                                        Debug.Assert(this._reader.Code == 140);
408✔
1246

1247
                                        return true;
408✔
1248
                                default:
1249
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1250
                        }
1251
                }
35,904✔
1252

1253
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1254
                {
53,040✔
1255
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1256

1257
                        switch (this._reader.Code)
53,040✔
1258
                        {
1259
                                // String of up to 32 characters. The name of the style used for this mline. An entry for this style must exist in the MLINESTYLE dictionary.
1260
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1261
                                case 2:
1262
                                        tmp.MLineStyleName = this._reader.ValueAsString;
612✔
1263
                                        return true;
612✔
1264
                                case 72:
1265
                                        tmp.NVertex = this._reader.ValueAsInt;
612✔
1266
                                        return true;
612✔
1267
                                case 73:
1268
                                        tmp.NElements = this._reader.ValueAsInt;
612✔
1269
                                        return true;
612✔
1270
                                case 340:
1271
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
612✔
1272
                                        return true;
612✔
1273
                                default:
1274
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
50,592✔
1275
                                        {
8,568✔
1276
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
8,568✔
1277
                                        }
1278
                                        return true;
42,024✔
1279
                        }
1280
                }
53,040✔
1281

1282
                private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1283
                {
144,024✔
1284
                        CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
144,024✔
1285

1286
                        switch (this._reader.Code)
144,024✔
1287
                        {
1288
                                case 270:
1289
                                        //f270 Version
1290
                                        return true;
1,530✔
1291
                                case 300:
1292
                                        this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,060✔
1293
                                        return true;
3,060✔
1294
                                case 340:
1295
                                        tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,060✔
1296
                                        return true;
3,060✔
1297
                                case 341:
1298
                                        tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,060✔
1299
                                        return true;
3,060✔
1300
                                case 343:
1301
                                        tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1302
                                        return true;
3,060✔
1303
                                default:
1304
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
130,254✔
1305
                        }
1306
                }
144,024✔
1307

1308
                private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1309
                {
3,060✔
1310
                        this._reader.ReadNext();
3,060✔
1311

1312
                        DxfMap map = DxfMap.Create<MultiLeaderObjectContextData>();
3,060✔
1313
                        var contextData = template.CadObject as MultiLeaderObjectContextData;
3,060✔
1314

1315
                        bool end = false;
3,060✔
1316
                        while (this._reader.DxfCode != DxfCode.Start)
171,360✔
1317
                        {
171,360✔
1318
                                switch (this._reader.Code)
171,360✔
1319
                                {
1320
                                        case 301 when this._reader.ValueAsString.Equals("}"):
3,060✔
1321
                                                end = true;
3,060✔
1322
                                                break;
3,060✔
1323
                                        case 302 when this._reader.ValueAsString.Equals("LEADER{"):
3,060✔
1324
                                                contextData.LeaderRoots.Add(this.readMultiLeaderLeader(template));
3,060✔
1325
                                                break;
3,060✔
1326
                                        case 340:
1327
                                                template.TextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1328
                                                break;
3,060✔
1329
                                        default:
1330
                                                if (!this.tryAssignCurrentValue(contextData, map.SubClasses[contextData.SubclassMarker]))
162,180!
1331
                                                {
×
1332
                                                        this._builder.Notify($"[AcDbMLeaderObjectContextData] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1333
                                                }
×
1334
                                                break;
162,180✔
1335
                                }
1336

1337
                                if (end)
171,360✔
1338
                                {
3,060✔
1339
                                        break;
3,060✔
1340
                                }
1341

1342
                                this._reader.ReadNext();
168,300✔
1343
                        }
168,300✔
1344
                }
3,060✔
1345

1346
                private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1347
                {
3,060✔
1348
                        MultiLeaderObjectContextData.LeaderRoot root = new();
3,060✔
1349
                        var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,060✔
1350

1351
                        this._reader.ReadNext();
3,060✔
1352

1353
                        bool end = false;
3,060✔
1354
                        while (this._reader.DxfCode != DxfCode.Start)
38,250✔
1355
                        {
38,250✔
1356
                                switch (this._reader.Code)
38,250✔
1357
                                {
1358
                                        case 303 when this._reader.ValueAsString.Equals("}"):
3,060✔
1359
                                                end = true;
3,060✔
1360
                                                break;
3,060✔
1361
                                        case 304 when this._reader.ValueAsString.Equals("LEADER_LINE{"):
3,060✔
1362
                                                var lineTemplate = new LeaderLineTemplate();
3,060✔
1363
                                                template.LeaderLineTemplates.Add(lineTemplate);
3,060✔
1364
                                                root.Lines.Add(this.readMultiLeaderLine(lineTemplate));
3,060✔
1365
                                                break;
3,060✔
1366
                                        default:
1367
                                                if (!this.tryAssignCurrentValue(root, map))
32,130!
UNCOV
1368
                                                {
×
1369
                                                        this._builder.Notify($"[LeaderRoot] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1370
                                                }
×
1371
                                                break;
32,130✔
1372
                                }
1373

1374
                                if (end)
38,250✔
1375
                                {
3,060✔
1376
                                        break;
3,060✔
1377
                                }
1378

1379
                                this._reader.ReadNext();
35,190✔
1380
                        }
35,190✔
1381

1382
                        return root;
3,060✔
1383
                }
3,060✔
1384

1385
                private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1386
                {
3,060✔
1387
                        MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,060✔
1388
                        var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,060✔
1389

1390
                        this._reader.ReadNext();
3,060✔
1391

1392
                        bool end = false;
3,060✔
1393
                        while (this._reader.DxfCode != DxfCode.Start)
15,300✔
1394
                        {
15,300✔
1395
                                switch (this._reader.Code)
15,300✔
1396
                                {
1397
                                        case 10:
1398
                                                XYZ pt = new XYZ(this._reader.ValueAsDouble, 0, 0);
3,060✔
1399
                                                line.Points.Add(pt);
3,060✔
1400
                                                break;
3,060✔
1401
                                        case 20:
1402
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1403
                                                pt.Y = this._reader.ValueAsDouble;
3,060✔
1404
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1405
                                                break;
3,060✔
1406
                                        case 30:
1407
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1408
                                                pt.Z = this._reader.ValueAsDouble;
3,060✔
1409
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1410
                                                break;
3,060✔
1411
                                        case 305 when this._reader.ValueAsString.Equals("}"):
3,060✔
1412
                                                end = true;
3,060✔
1413
                                                break;
3,060✔
1414
                                        default:
1415
                                                if (!this.tryAssignCurrentValue(line, map))
3,060!
UNCOV
1416
                                                {
×
1417
                                                        this._builder.Notify($"[LeaderLine] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1418
                                                }
×
1419
                                                break;
3,060✔
1420
                                }
1421

1422
                                if (end)
15,300✔
1423
                                {
3,060✔
1424
                                        break;
3,060✔
1425
                                }
1426

1427
                                this._reader.ReadNext();
12,240✔
1428
                        }
12,240✔
1429

1430
                        return line;
3,060✔
1431
                }
3,060✔
1432

1433
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1434
                {
2,278✔
1435
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1436

1437
                        switch (this._reader.Code)
2,278✔
1438
                        {
1439
                                case 2:
1440
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1441
                                        return true;
238✔
1442
                                default:
1443
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1444
                        }
1445
                }
2,278✔
1446

1447
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1448
                {
12,036✔
1449
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,036✔
1450
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,036✔
1451

1452
                        switch (this._reader.Code)
12,036✔
1453
                        {
1454
                                case 91:
1455
                                        var nvertices = this._reader.ValueAsInt;
408✔
1456
                                        for (int i = 0; i < nvertices; i++)
3,672✔
1457
                                        {
1,428✔
1458
                                                this._reader.ReadNext();
1,428✔
1459
                                                var x = this._reader.ValueAsDouble;
1,428✔
1460
                                                this._reader.ReadNext();
1,428✔
1461
                                                var y = this._reader.ValueAsDouble;
1,428✔
1462

1463
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,428✔
1464
                                        }
1,428✔
1465

1466
                                        this._reader.ReadNext();
408✔
1467

1468
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
408✔
1469
                                case 340:
1470
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
408✔
1471
                                        return true;
408✔
1472
                                case 360:
1473
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
408✔
1474
                                        return true;
408✔
1475
                                default:
1476
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,812✔
1477
                        }
1478
                }
12,036✔
1479

1480
                private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1481
                {
×
1482
                        CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1483

UNCOV
1484
                        switch (this._reader.Code)
×
1485
                        {
1486
                                //End of data
1487
                                case 1:
1488
                                //Length of binary data
1489
                                case 90:
1490
                                //Undocumented
1491
                                case 73:
UNCOV
1492
                                        return true;
×
1493
                                case 310:
UNCOV
1494
                                        tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
1495
                                        return true;
×
1496
                                default:
UNCOV
1497
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1498
                        }
UNCOV
1499
                }
×
1500

1501
                private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1502
                {
288,776✔
1503
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
288,776✔
1504
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,776✔
1505
                        var geometry = template.CadObject as ModelerGeometry;
288,776✔
1506

1507
                        switch (this._reader.Code)
288,776✔
1508
                        {
1509
                                case 1:
1510
                                case 3:
1511
                                        geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
37,706✔
1512
                                        return true;
37,706✔
1513
                                case 2:
1514
                                        geometry.Guid = new Guid(this._reader.ValueAsString);
204✔
1515
                                        return true;
204✔
1516
                                case 290:
1517
                                        return true;
204✔
1518
                                default:
1519
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
250,662✔
1520
                        }
1521
                }
288,776✔
1522

1523
                private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1524
                {
34,884✔
1525
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
34,884✔
1526

1527
                        switch (this._reader.Code)
34,884✔
1528
                        {
1529
                                case 350:
1530
                                        tmp.HistoryHandle = this._reader.ValueAsHandle;
272✔
1531
                                        return true;
272✔
1532
                                default:
1533
                                        return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
34,612✔
1534
                        }
1535
                }
34,884✔
1536

1537
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1538
                {
14,280✔
1539
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1540

1541
                        XYZ controlPoint;
1542
                        XYZ fitPoint;
1543

1544
                        switch (this._reader.Code)
14,280!
1545
                        {
1546
                                case 10:
1547
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,632✔
1548
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,632✔
1549
                                        return true;
1,632✔
1550
                                case 20:
1551
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1552
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,632✔
1553
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1554
                                        return true;
1,632✔
1555
                                case 30:
1556
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1557
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,632✔
1558
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1559
                                        return true;
1,632✔
1560
                                case 11:
UNCOV
1561
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1562
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1563
                                        return true;
×
1564
                                case 21:
UNCOV
1565
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1566
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1567
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1568
                                        return true;
×
1569
                                case 31:
UNCOV
1570
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1571
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1572
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1573
                                        return true;
×
1574
                                case 40:
1575
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,264✔
1576
                                        return true;
3,264✔
1577
                                case 41:
UNCOV
1578
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1579
                                        return true;
×
1580
                                case 72:
1581
                                case 73:
1582
                                case 74:
1583
                                        return true;
1,224✔
1584
                                default:
1585
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,896✔
1586
                        }
1587
                }
14,280✔
1588

1589
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1590
                        where T : PdfUnderlayDefinition
1591
                {
3,230✔
1592
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,230✔
1593

1594
                        switch (this._reader.Code)
3,230✔
1595
                        {
1596
                                case 340:
1597
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
204✔
1598
                                        return true;
204✔
1599
                                default:
1600
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,026✔
1601
                        }
1602
                }
3,230✔
1603

1604
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1605
                {
238,252✔
1606
                        CadVertexTemplate tmp = template as CadVertexTemplate;
238,252✔
1607

1608
                        switch (this._reader.Code)
238,252✔
1609
                        {
1610
                                case 100:
1611
                                        switch (this._reader.ValueAsString)
6,936!
1612
                                        {
1613
                                                case DxfSubclassMarker.Vertex:
1614
                                                        return true;
2,040✔
1615
                                                case DxfSubclassMarker.PolylineVertex:
UNCOV
1616
                                                        tmp.SetVertexObject(new Vertex2D());
×
1617
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1618
                                                        return true;
×
1619
                                                case DxfSubclassMarker.Polyline3dVertex:
1620
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1621
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1622
                                                        return true;
1,020✔
1623
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1624
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1625
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1626
                                                        return true;
1,020✔
1627
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1628
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1629
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1630
                                                        return true;
408✔
1631
                                                case DxfSubclassMarker.PolygonMeshVertex:
UNCOV
1632
                                                        tmp.SetVertexObject(new PolygonMeshVertex());
×
1633
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1634
                                                        return true;
×
1635
                                                default:
1636
                                                        return false;
2,448✔
1637
                                        }
1638
                                default:
1639
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
231,316✔
1640
                        }
1641
                }
238,252✔
1642

1643
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1644
                {
67,976✔
1645
                        CadViewportTemplate tmp = template as CadViewportTemplate;
67,976✔
1646

1647
                        switch (this._reader.Code)
67,976!
1648
                        {
1649
                                //Undocumented
1650
                                case 67:
1651
                                case 68:
1652
                                        return true;
2,488✔
1653
                                case 69:
1654
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,244✔
1655
                                        return true;
1,244✔
1656
                                case 331:
UNCOV
1657
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1658
                                        return true;
×
1659
                                case 348:
1660
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1661
                                        return true;
784✔
1662
                                default:
1663
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
63,460✔
1664
                        }
1665
                }
67,976✔
1666

1667
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1668
                {
806,016✔
1669
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
806,016✔
1670

1671
                        switch (this._reader.Code)
806,016✔
1672
                        {
1673
                                default:
1674
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
806,016✔
1675
                        }
1676
                }
806,016✔
1677

1678
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1679
                {
34,227✔
1680
                        List<ExtendedDataRecord> records = new();
34,227✔
1681
                        edata.Add(this._reader.ValueAsString, records);
34,227✔
1682

1683
                        this._reader.ReadNext();
34,227✔
1684

1685
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,832✔
1686
                        {
256,472✔
1687
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,472✔
1688
                                {
10,867✔
1689
                                        this.readExtendedData(edata);
10,867✔
1690
                                        break;
10,867✔
1691
                                }
1692

1693
                                ExtendedDataRecord record = null;
245,605✔
1694
                                double x = 0;
245,605✔
1695
                                double y = 0;
245,605✔
1696
                                double z = 0;
245,605✔
1697

1698
                                switch (this._reader.DxfCode)
245,605✔
1699
                                {
1700
                                        case DxfCode.ExtendedDataAsciiString:
1701
                                        case DxfCode.ExtendedDataRegAppName:
1702
                                                record = new ExtendedDataString(this._reader.ValueAsString);
23,506✔
1703
                                                break;
23,506✔
1704
                                        case DxfCode.ExtendedDataControlString:
1705
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,484✔
1706
                                                break;
13,484✔
1707
                                        case DxfCode.ExtendedDataLayerName:
1708
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1709
                                                {
224✔
1710
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1711
                                                }
224✔
1712
                                                else
1713
                                                {
14✔
1714
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1715
                                                }
14✔
1716
                                                break;
238✔
1717
                                        case DxfCode.ExtendedDataBinaryChunk:
1718
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1719
                                                break;
68✔
1720
                                        case DxfCode.ExtendedDataHandle:
1721
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,611✔
1722
                                                break;
2,611✔
1723
                                        case DxfCode.ExtendedDataXCoordinate:
1724
                                                x = this._reader.ValueAsDouble;
2,541✔
1725
                                                this._reader.ReadNext();
2,541✔
1726
                                                y = this._reader.ValueAsDouble;
2,541✔
1727
                                                this._reader.ReadNext();
2,541✔
1728
                                                z = this._reader.ValueAsDouble;
2,541✔
1729

1730
                                                record = new ExtendedDataCoordinate(
2,541✔
1731
                                                        new XYZ(
2,541✔
1732
                                                                x,
2,541✔
1733
                                                                y,
2,541✔
1734
                                                                z)
2,541✔
1735
                                                        );
2,541✔
1736
                                                break;
2,541✔
1737
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1738
                                                x = this._reader.ValueAsDouble;
1,224✔
1739
                                                this._reader.ReadNext();
1,224✔
1740
                                                y = this._reader.ValueAsDouble;
1,224✔
1741
                                                this._reader.ReadNext();
1,224✔
1742
                                                z = this._reader.ValueAsDouble;
1,224✔
1743

1744
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1745
                                                        new XYZ(
1,224✔
1746
                                                                x,
1,224✔
1747
                                                                y,
1,224✔
1748
                                                                z)
1,224✔
1749
                                                        );
1,224✔
1750
                                                break;
1,224✔
1751
                                        case DxfCode.ExtendedDataWorldXDisp:
1752
                                                x = this._reader.ValueAsDouble;
238✔
1753
                                                this._reader.ReadNext();
238✔
1754
                                                y = this._reader.ValueAsDouble;
238✔
1755
                                                this._reader.ReadNext();
238✔
1756
                                                z = this._reader.ValueAsDouble;
238✔
1757

1758
                                                record = new ExtendedDataDisplacement(
238✔
1759
                                                        new XYZ(
238✔
1760
                                                                x,
238✔
1761
                                                                y,
238✔
1762
                                                                z)
238✔
1763
                                                        );
238✔
1764
                                                break;
238✔
1765
                                        case DxfCode.ExtendedDataWorldXDir:
1766
                                                x = this._reader.ValueAsDouble;
238✔
1767
                                                this._reader.ReadNext();
238✔
1768
                                                y = this._reader.ValueAsDouble;
238✔
1769
                                                this._reader.ReadNext();
238✔
1770
                                                z = this._reader.ValueAsDouble;
238✔
1771

1772
                                                record = new ExtendedDataDirection(
238✔
1773
                                                        new XYZ(
238✔
1774
                                                                x,
238✔
1775
                                                                y,
238✔
1776
                                                                z)
238✔
1777
                                                        );
238✔
1778
                                                break;
238✔
1779
                                        case DxfCode.ExtendedDataReal:
1780
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
119,449✔
1781
                                                break;
119,449✔
1782
                                        case DxfCode.ExtendedDataDist:
1783
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1784
                                                break;
238✔
1785
                                        case DxfCode.ExtendedDataScale:
1786
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1787
                                                break;
238✔
1788
                                        case DxfCode.ExtendedDataInteger16:
1789
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
69,751✔
1790
                                                break;
69,751✔
1791
                                        case DxfCode.ExtendedDataInteger32:
1792
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
9,605✔
1793
                                                break;
9,605✔
1794
                                        default:
1795
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1796
                                                break;
2,176✔
1797
                                }
1798

1799
                                if (record != null)
245,605✔
1800
                                {
243,415✔
1801
                                        records.Add(record);
243,415✔
1802
                                }
243,415✔
1803

1804
                                this._reader.ReadNext();
245,605✔
1805
                        }
245,605✔
1806
                }
34,227✔
1807

1808
                private void readPattern(HatchPattern pattern, int nlines)
1809
                {
1,224✔
1810
                        //Jump 78 code
1811
                        this._reader.ReadNext();
1,224✔
1812

1813
                        for (int i = 0; i < nlines; i++)
185,640✔
1814
                        {
91,596✔
1815
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1816
                                XY basePoint = new XY();
91,596✔
1817
                                XY offset = new XY();
91,596✔
1818

1819
                                bool end = false;
91,596✔
1820
                                HashSet<int> codes = new();
91,596✔
1821

1822
                                while (!end)
642,396✔
1823
                                {
641,172✔
1824
                                        if (codes.Contains(this._reader.Code))
641,172✔
1825
                                        {
90,372✔
1826
                                                break;
90,372✔
1827
                                        }
1828
                                        else
1829
                                        {
550,800✔
1830
                                                codes.Add(this._reader.Code);
550,800✔
1831
                                        }
550,800✔
1832

1833
                                        switch (this._reader.Code)
550,800!
1834
                                        {
1835
                                                case 53:
1836
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1837
                                                        break;
91,596✔
1838
                                                case 43:
1839
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1840
                                                        break;
91,596✔
1841
                                                case 44:
1842
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1843
                                                        line.BasePoint = basePoint;
91,596✔
1844
                                                        break;
91,596✔
1845
                                                case 45:
1846
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1847
                                                        line.Offset = offset;
91,596✔
1848
                                                        break;
91,596✔
1849
                                                case 46:
1850
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1851
                                                        line.Offset = offset;
91,596✔
1852
                                                        break;
91,596✔
1853
                                                //Number of dash length items
1854
                                                case 79:
1855
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1856
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1857
                                                        {
182,784✔
1858
                                                                this._reader.ReadNext();
182,784✔
1859
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1860
                                                        }
182,784✔
1861
                                                        break;
91,596✔
1862
                                                case 49:
UNCOV
1863
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1864
                                                        break;
×
1865
                                                default:
1866
                                                        end = true;
1,224✔
1867
                                                        break;
1,224✔
1868
                                        }
1869
                                        this._reader.ReadNext();
550,800✔
1870
                                }
550,800✔
1871

1872
                                pattern.Lines.Add(line);
91,596✔
1873
                        }
91,596✔
1874
                }
1,224✔
1875

1876
                private void readLoops(CadHatchTemplate template, int count)
1877
                {
1,632✔
1878
                        if (this._reader.Code == 91)
1,632✔
1879
                                this._reader.ReadNext();
1,632✔
1880

1881
                        for (int i = 0; i < count; i++)
6,528✔
1882
                        {
1,632✔
1883
                                if (this._reader.Code != 92)
1,632!
UNCOV
1884
                                {
×
1885
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1886
                                        break;
×
1887
                                }
1888

1889
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1890
                                if (path != null)
1,632✔
1891
                                        template.PathTemplates.Add(path);
1,632✔
1892
                        }
1,632✔
1893
                }
1,632✔
1894

1895
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1896
                {
1,632✔
1897
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1898
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1899
                        template.Path.Flags = flags;
1,632✔
1900

1901
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1902
                        {
612✔
1903
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1904
                                template.Path.Edges.Add(pl);
612✔
1905
                        }
612✔
1906
                        else
1907
                        {
1,020✔
1908
                                this._reader.ReadNext();
1,020✔
1909

1910
                                if (this._reader.Code != 93)
1,020!
UNCOV
1911
                                {
×
1912
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1913
                                        return null;
×
1914
                                }
1915

1916
                                int edges = this._reader.ValueAsInt;
1,020✔
1917
                                this._reader.ReadNext();
1,020✔
1918

1919
                                for (int i = 0; i < edges; i++)
10,200✔
1920
                                {
4,080✔
1921
                                        var edge = this.readEdge();
4,080✔
1922
                                        if (edge != null)
4,080✔
1923
                                                template.Path.Edges.Add(edge);
4,080✔
1924
                                }
4,080✔
1925
                        }
1,020✔
1926

1927
                        bool end = false;
1,632✔
1928
                        while (!end)
6,324✔
1929
                        {
4,692✔
1930
                                switch (this._reader.Code)
4,692✔
1931
                                {
1932
                                        //Number of source boundary objects
1933
                                        case 97:
1934
                                                break;
1,632✔
1935
                                        case 330:
1936
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1937
                                                break;
1,428✔
1938
                                        default:
1939
                                                end = true;
1,632✔
1940
                                                continue;
1,632✔
1941
                                }
1942

1943
                                this._reader.ReadNext();
3,060✔
1944
                        }
3,060✔
1945

1946
                        return template;
1,632✔
1947
                }
1,632✔
1948

1949
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1950
                {
612✔
1951
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
1952

1953
                        this._reader.ReadNext();
612✔
1954

1955
                        if (this._reader.Code != 72)
612!
UNCOV
1956
                        {
×
1957
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1958
                                return null;
×
1959
                        }
1960

1961
                        //72
1962
                        bool hasBulge = this._reader.ValueAsBool;
612✔
1963
                        this._reader.ReadNext();
612✔
1964

1965
                        //73
1966
                        bool isClosed = this._reader.ValueAsBool;
612✔
1967
                        this._reader.ReadNext();
612✔
1968

1969
                        //93
1970
                        int nvertices = this._reader.ValueAsInt;
612✔
1971
                        this._reader.ReadNext();
612✔
1972

1973
                        for (int i = 0; i < nvertices; i++)
6,120✔
1974
                        {
2,448✔
1975
                                double bulge = 0.0;
2,448✔
1976

1977
                                //10
1978
                                double x = this._reader.ValueAsDouble;
2,448✔
1979
                                this._reader.ReadNext();
2,448✔
1980
                                //20
1981
                                double y = this._reader.ValueAsDouble;
2,448✔
1982
                                this._reader.ReadNext();
2,448✔
1983

1984
                                if (hasBulge)
2,448!
UNCOV
1985
                                {
×
1986
                                        //42
UNCOV
1987
                                        bulge = this._reader.ValueAsDouble;
×
1988
                                        this._reader.ReadNext();
×
1989
                                }
×
1990

1991
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
1992
                        }
2,448✔
1993

1994
                        return boundary;
612✔
1995
                }
612✔
1996

1997
                private Hatch.BoundaryPath.Edge readEdge()
1998
                {
4,080✔
1999
                        if (this._reader.Code != 72)
4,080!
UNCOV
2000
                        {
×
2001
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
2002
                                return null;
×
2003
                        }
2004

2005
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
2006
                        this._reader.ReadNext();
4,080✔
2007

2008
                        switch (type)
4,080!
2009
                        {
2010
                                case Hatch.BoundaryPath.EdgeType.Line:
2011
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,080✔
2012
                                        while (true)
20,400✔
2013
                                        {
20,400✔
2014
                                                switch (this._reader.Code)
20,400✔
2015
                                                {
2016
                                                        case 10:
2017
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,080✔
2018
                                                                break;
4,080✔
2019
                                                        case 20:
2020
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,080✔
2021
                                                                break;
4,080✔
2022
                                                        case 11:
2023
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,080✔
2024
                                                                break;
4,080✔
2025
                                                        case 21:
2026
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,080✔
2027
                                                                break;
4,080✔
2028
                                                        default:
2029
                                                                return line;
4,080✔
2030
                                                }
2031

2032
                                                this._reader.ReadNext();
16,320✔
2033
                                        }
16,320✔
2034
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
UNCOV
2035
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
2036
                                        while (true)
×
2037
                                        {
×
2038
                                                switch (this._reader.Code)
×
2039
                                                {
2040
                                                        case 10:
UNCOV
2041
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
2042
                                                                break;
×
2043
                                                        case 20:
UNCOV
2044
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
2045
                                                                break;
×
2046
                                                        case 40:
UNCOV
2047
                                                                arc.Radius = this._reader.ValueAsDouble;
×
2048
                                                                break;
×
2049
                                                        case 50:
UNCOV
2050
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
2051
                                                                break;
×
2052
                                                        case 51:
UNCOV
2053
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
2054
                                                                break;
×
2055
                                                        case 73:
UNCOV
2056
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
2057
                                                                break;
×
2058
                                                        default:
UNCOV
2059
                                                                return arc;
×
2060
                                                }
2061

UNCOV
2062
                                                this._reader.ReadNext();
×
2063
                                        }
×
2064
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
UNCOV
2065
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
2066
                                        while (true)
×
2067
                                        {
×
2068
                                                switch (this._reader.Code)
×
2069
                                                {
2070
                                                        case 10:
UNCOV
2071
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2072
                                                                break;
×
2073
                                                        case 20:
UNCOV
2074
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2075
                                                                break;
×
2076
                                                        case 11:
UNCOV
2077
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2078
                                                                break;
×
2079
                                                        case 21:
UNCOV
2080
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2081
                                                                break;
×
2082
                                                        case 40:
UNCOV
2083
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
2084
                                                                break;
×
2085
                                                        case 50:
UNCOV
2086
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
2087
                                                                break;
×
2088
                                                        case 51:
UNCOV
2089
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
2090
                                                                break;
×
2091
                                                        case 73:
UNCOV
2092
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
2093
                                                                break;
×
2094
                                                        default:
UNCOV
2095
                                                                return ellipse;
×
2096
                                                }
2097

UNCOV
2098
                                                this._reader.ReadNext();
×
2099
                                        }
×
2100
                                case Hatch.BoundaryPath.EdgeType.Spline:
UNCOV
2101
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
2102
                                        int nKnots = 0;
×
2103
                                        int nCtrlPoints = 0;
×
2104
                                        int nFitPoints = 0;
×
2105

UNCOV
2106
                                        XYZ controlPoint = new XYZ();
×
2107
                                        XY fitPoint = new XY();
×
2108

UNCOV
2109
                                        while (true)
×
2110
                                        {
×
2111
                                                switch (this._reader.Code)
×
2112
                                                {
2113
                                                        case 10:
UNCOV
2114
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
2115
                                                                break;
×
2116
                                                        case 20:
UNCOV
2117
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
2118
                                                                spline.ControlPoints.Add(controlPoint);
×
2119
                                                                break;
×
2120
                                                        case 11:
UNCOV
2121
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
2122
                                                                break;
×
2123
                                                        case 21:
UNCOV
2124
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
2125
                                                                spline.FitPoints.Add(fitPoint);
×
2126
                                                                break;
×
2127
                                                        case 42:
UNCOV
2128
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
2129
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
2130
                                                                break;
×
2131
                                                        case 12:
UNCOV
2132
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
2133
                                                                break;
×
2134
                                                        case 22:
UNCOV
2135
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
2136
                                                                break;
×
2137
                                                        case 13:
UNCOV
2138
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
2139
                                                                break;
×
2140
                                                        case 23:
UNCOV
2141
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
2142
                                                                break;
×
2143
                                                        case 94:
UNCOV
2144
                                                                spline.Degree = this._reader.ValueAsInt;
×
2145
                                                                break;
×
2146
                                                        case 73:
UNCOV
2147
                                                                spline.IsRational = this._reader.ValueAsBool;
×
2148
                                                                break;
×
2149
                                                        case 74:
UNCOV
2150
                                                                spline.IsPeriodic = this._reader.ValueAsBool;
×
2151
                                                                break;
×
2152
                                                        case 95:
UNCOV
2153
                                                                nKnots = this._reader.ValueAsInt;
×
2154
                                                                break;
×
2155
                                                        case 96:
UNCOV
2156
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
2157
                                                                break;
×
2158
                                                        case 97:
UNCOV
2159
                                                                nFitPoints = this._reader.ValueAsInt;
×
2160
                                                                break;
×
2161
                                                        case 40:
UNCOV
2162
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
2163
                                                                break;
×
2164
                                                        default:
UNCOV
2165
                                                                return spline;
×
2166
                                                }
2167

UNCOV
2168
                                                this._reader.ReadNext();
×
2169
                                        }
×
2170
                        }
2171

UNCOV
2172
                        return null;
×
2173
                }
4,080✔
2174

2175
                private void readDefinedGroups(CadTemplate template)
2176
                {
67,727✔
2177
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
67,727✔
2178

2179
                        if (xdict.HasValue)
67,727✔
2180
                        {
9,871✔
2181
                                template.XDictHandle = xdict;
9,871✔
2182
                        }
9,871✔
2183
                        template.ReactorsHandles.UnionWith(reactorsHandles);
67,727✔
2184
                }
67,727✔
2185

2186
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2187
                {
67,936✔
2188
                        xdictHandle = null;
67,936✔
2189
                        reactors = new HashSet<ulong>();
67,936✔
2190

2191
                        switch (this._reader.ValueAsString)
67,936✔
2192
                        {
2193
                                case DxfFileToken.DictionaryToken:
2194
                                        this._reader.ReadNext();
10,080✔
2195
                                        xdictHandle = this._reader.ValueAsHandle;
10,080✔
2196
                                        this._reader.ReadNext();
10,080✔
2197
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,080✔
2198
                                        return;
10,080✔
2199
                                case DxfFileToken.ReactorsToken:
2200
                                        reactors = this.readReactors();
55,805✔
2201
                                        break;
55,805✔
2202
                                case DxfFileToken.BlkRefToken:
2203
                                default:
2204
                                        do
2205
                                        {
5,326✔
2206
                                                this._reader.ReadNext();
5,326✔
2207
                                        }
5,326✔
2208
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,326✔
2209
                                        return;
2,051✔
2210
                        }
2211
                }
67,936✔
2212

2213
                private HashSet<ulong> readReactors()
2214
                {
55,805✔
2215
                        HashSet<ulong> reactors = new();
55,805✔
2216

2217
                        this._reader.ReadNext();
55,805✔
2218

2219
                        while (this._reader.DxfCode != DxfCode.ControlString)
118,114✔
2220
                        {
62,309✔
2221
                                reactors.Add(this._reader.ValueAsHandle);
62,309✔
2222

2223
                                this._reader.ReadNext();
62,309✔
2224
                        }
62,309✔
2225

2226
                        return reactors;
55,805✔
2227
                }
55,805✔
2228

2229
                protected bool tryAssignCurrentValue(object cadObject, DxfMap map)
2230
                {
59✔
2231
                        if (string.IsNullOrEmpty(this.currentSubclass))
59✔
2232
                        {
6✔
2233
                                return false;
6✔
2234
                        }
2235

2236
                        if (map.SubClasses.TryGetValue(this.currentSubclass, out var subClass))
53!
2237
                        {
53✔
2238
                                return this.tryAssignCurrentValue(cadObject, subClass);
53✔
2239
                        }
2240
                        else
UNCOV
2241
                        {
×
2242
                                return false;
×
2243
                        }
2244
                }
59✔
2245

2246
                protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2247
                {
4,191,843✔
2248
                        try
2249
                        {
4,191,843✔
2250
                                //Use this method only if the value is not a link between objects
2251
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,191,843✔
2252
                                {
2,231,465✔
2253
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,231,465✔
2254
                                        {
12,767✔
2255
                                                return true;
12,767✔
2256
                                        }
2257

2258
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,218,698✔
2259
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,218,698✔
2260
                                        {
14,969✔
2261
                                                return false;
14,969✔
2262
                                        }
2263

2264
                                        object value = this._reader.Value;
2,203,729✔
2265

2266
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,203,729✔
2267
                                        {
24,820✔
2268
                                                value = MathHelper.DegToRad((double)value);
24,820✔
2269
                                        }
24,820✔
2270

2271
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,203,729✔
2272

2273
                                        return true;
2,203,729✔
2274
                                }
2275
                        }
1,960,378✔
UNCOV
2276
                        catch (Exception ex)
×
2277
                        {
×
2278
                                if (!this._builder.Configuration.Failsafe)
×
2279
                                {
×
2280
                                        throw ex;
×
2281
                                }
2282
                                else
UNCOV
2283
                                {
×
2284
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2285
                                }
×
2286
                        }
×
2287

2288
                        return false;
1,960,378✔
2289
                }
4,191,843✔
2290
        }
2291
}
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