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

DomCR / ACadSharp / 20912968148

12 Jan 2026 08:41AM UTC coverage: 77.095% (+0.006%) from 77.089%
20912968148

Pull #470

github

web-flow
Merge f13bb3d4e into 1db475088
Pull Request #470: Implement Polyline mesh

7929 of 11133 branches covered (71.22%)

Branch coverage included in aggregate %.

5 of 16 new or added lines in 3 files covered. (31.25%)

944 existing lines in 8 files now uncovered.

28863 of 36590 relevant lines covered (78.88%)

149587.47 hits per line

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

80.45
/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;
948✔
24
                protected string currentSubclass = null;
948✔
25

26
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
948✔
27
                {
948✔
28
                        this._reader = reader;
948✔
29
                        this._builder = builder;
948✔
30
                }
948✔
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,234✔
36
                        name = null;
2,234✔
37
                        handle = 0;
2,234✔
38
                        ownerHandle = null;
2,234✔
39
                        xdictHandle = null;
2,234✔
40
                        reactors = new HashSet<ulong>();
2,234✔
41

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

46
                        //Loop until the common data end
47
                        while (this._reader.DxfCode != DxfCode.Start
8,870✔
48
                                        && this._reader.DxfCode != DxfCode.Subclass)
8,870✔
49
                        {
6,636✔
50
                                switch (this._reader.Code)
6,636!
51
                                {
52
                                        //Table name
53
                                        case 2:
54
                                                name = this._reader.ValueAsString;
2,234✔
55
                                                break;
2,234✔
56
                                        //Handle
57
                                        case 5:
58
                                        case 105:
59
                                                handle = this._reader.ValueAsHandle;
1,962✔
60
                                                break;
1,962✔
61
                                        //Start of application - defined group
62
                                        case 102:
63
                                                this.readDefinedGroups(out xdictHandle, out reactors);
206✔
64
                                                break;
206✔
65
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
66
                                        case 330:
67
                                                ownerHandle = this._reader.ValueAsHandle;
1,962✔
68
                                                break;
1,962✔
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,636✔
79
                        }
6,636✔
80
                }
2,234✔
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
                {
785,537✔
116
                        isExtendedData = false;
785,537✔
117

118
                        switch (this._reader.Code)
785,537✔
119
                        {
120
                                //Handle
121
                                case 5:
122
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
295,211✔
123
                                        break;
295,211✔
124
                                //Check with mapper
125
                                case 100:
126
                                        this.currentSubclass = this._reader.ValueAsString;
202,217✔
127
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
202,217!
128
                                        {
1,672✔
129
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
1,672✔
130
                                        }
1,672✔
131
                                        break;
202,217✔
132
                                //Start of application - defined group
133
                                case 102:
134
                                        this.readDefinedGroups(template);
66,579✔
135
                                        break;
66,579✔
136
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
137
                                case 330:
138
                                        template.OwnerHandle = this._reader.ValueAsHandle;
165,255✔
139
                                        break;
165,255✔
140
                                case 1001:
141
                                        isExtendedData = true;
23,053✔
142
                                        this.readExtendedData(template.EDataTemplateByAppName);
23,053✔
143
                                        break;
23,053✔
144
                                default:
145
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
33,222✔
146
                                        break;
33,222✔
147
                        }
148
                }
785,537✔
149

150
                protected CadEntityTemplate readEntity()
151
                {
148,726✔
152
                        switch (this._reader.ValueAsString)
148,726!
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:
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,024✔
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,552✔
174
                                case DxfFileToken.EntityLwPolyline:
175
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
4,668✔
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,506✔
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:
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);
884✔
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:
210
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,448✔
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:
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
236
                                        {
×
237
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
×
238
                                        }
×
239

240
                                        this._reader.ReadNext();
×
241

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

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

255
                                        return unknownEntityTemplate;
×
256
                        }
257
                }
148,726✔
258

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

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

266
                        while (this._reader.DxfCode != DxfCode.Start)
2,639,324✔
267
                        {
2,444,636✔
268
                                if (!readEntity(template, map))
2,444,636✔
269
                                {
856,154✔
270
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
856,154✔
271
                                        if (isExtendedData)
856,154✔
272
                                                continue;
13,580✔
273
                                }
842,574✔
274

275
                                if (this.lockPointer)
2,431,056✔
276
                                {
2,856✔
277
                                        this.lockPointer = false;
2,856✔
278
                                        continue;
2,856✔
279
                                }
280

281
                                if (this._reader.DxfCode != DxfCode.Start)
2,428,200✔
282
                                        this._reader.ReadNext();
2,427,726✔
283
                        }
2,428,200✔
284

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

288
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
289
                {
923,400✔
290
                        isExtendedData = false;
923,400✔
291
                        switch (this._reader.Code)
923,400✔
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,130✔
298
                                        break;
211,130✔
299
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
300
                                case 67:
301
                                        break;
1,224✔
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]))
607,952✔
316
                                        {
473,804✔
317
                                                this.readCommonCodes(template, out isExtendedData, map);
473,804✔
318
                                        }
473,804✔
319
                                        break;
607,952✔
320
                        }
321
                }
923,400✔
322

323
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
324
                {
3,528✔
325
                        if (this._reader.DxfCode == DxfCode.Start)
3,528✔
326
                        {
448✔
327
                                return true;
448✔
328
                        }
329
                        else
330
                        {
3,080✔
331
                                return func.Invoke(template, map);
3,080✔
332
                        }
333
                }
3,528✔
334

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

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

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

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

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

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

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

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

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

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

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

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

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

653
                        switch (this._reader.Code)
291,430✔
654
                        {
655
                                //TODO: Implement multiline text def codes
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!
660
                                        double angle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
661
                                        mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
662
                                        return true;
×
663
                                case 70:
664
                                case 74:
665
                                case 101:
666
                                        return true;
408✔
667
                                case 7:
668
                                        tmp.StyleName = this._reader.ValueAsString;
2,856✔
669
                                        return true;
2,856✔
670
                                default:
671
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
278,476✔
672
                        }
673
                }
291,430✔
674

675
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
676
                {
6,120✔
677
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,120✔
678

679
                        switch (this._reader.Code)
6,120✔
680
                        {
681
                                case 3:
682
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
612✔
683
                                        return true;
612✔
684
                                default:
685
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,508✔
686
                        }
687
                }
6,120✔
688

689
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
690
                {
68,476✔
691
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
68,476✔
692

693
                        switch (this._reader.Code)
68,476✔
694
                        {
695
                                case 2:
696
                                        tmp.BlockName = this._reader.ValueAsString;
2,618✔
697
                                        return true;
2,618✔
698
                                case 3:
699
                                        tmp.StyleName = this._reader.ValueAsString;
2,244✔
700
                                        return true;
2,244✔
701
                                case 50:
702
                                        var dim = new DimensionLinear();
238✔
703
                                        tmp.SetDimensionObject(dim);
238✔
704
                                        dim.Rotation = this._reader.ValueAsAngle;
238✔
705
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
238✔
706
                                        return true;
238✔
707
                                case 70:
708
                                        //Flags do not have set
709
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,618✔
710
                                        return true;
2,618✔
711
                                //Measurement - read only
712
                                case 42:
713
                                        return true;
2,244✔
714
                                //Undocumented codes
715
                                case 73:
716
                                case 74:
717
                                case 75:
718
                                case 90:
719
                                case 361:
720
                                        return true;
4,488✔
721
                                case 100:
722
                                        switch (this._reader.ValueAsString)
7,344✔
723
                                        {
724
                                                case DxfSubclassMarker.Dimension:
725
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,244✔
726
                                                case DxfSubclassMarker.AlignedDimension:
727
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,020✔
728
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,020✔
729
                                                        return true;
1,020✔
730
                                                case DxfSubclassMarker.DiametricDimension:
731
                                                        tmp.SetDimensionObject(new DimensionDiameter());
204✔
732
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
204✔
733
                                                        return true;
204✔
734
                                                case DxfSubclassMarker.Angular2LineDimension:
735
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
204✔
736
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
204✔
737
                                                        return true;
204✔
738
                                                case DxfSubclassMarker.Angular3PointDimension:
739
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
204✔
740
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
204✔
741
                                                        return true;
204✔
742
                                                case DxfSubclassMarker.RadialDimension:
743
                                                        tmp.SetDimensionObject(new DimensionRadius());
204✔
744
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
204✔
745
                                                        return true;
204✔
746
                                                case DxfSubclassMarker.OrdinateDimension:
747
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
408✔
748
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
408✔
749
                                                        return true;
408✔
750
                                                case DxfSubclassMarker.LinearDimension:
751
                                                        return true;
612✔
752
                                                default:
753
                                                        return false;
2,244✔
754
                                        }
755
                                default:
756
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
46,682✔
757
                        }
758
                }
68,476✔
759

760
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
761
                {
43,656✔
762
                        CadHatchTemplate tmp = template as CadHatchTemplate;
43,656✔
763
                        Hatch hatch = tmp.CadObject;
43,656✔
764

765
                        XY seedPoint = new XY();
43,656✔
766

767
                        switch (this._reader.Code)
43,656!
768
                        {
769
                                case 2:
770
                                        hatch.Pattern.Name = this._reader.ValueAsString;
1,632✔
771
                                        return true;
1,632✔
772
                                case 10:
773
                                        seedPoint.X = this._reader.ValueAsDouble;
3,264✔
774
                                        hatch.SeedPoints.Add(seedPoint);
3,264✔
775
                                        return true;
3,264✔
776
                                case 20:
777
                                        seedPoint = hatch.SeedPoints.LastOrDefault();
3,264✔
778
                                        seedPoint.Y = this._reader.ValueAsDouble;
3,264✔
779
                                        hatch.SeedPoints[hatch.SeedPoints.Count - 1] = seedPoint;
3,264✔
780
                                        return true;
3,264✔
781
                                case 30:
782
                                        hatch.Elevation = this._reader.ValueAsDouble;
1,632✔
783
                                        return true;
1,632✔
784
                                case 53:
785
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
786
                                        return true;
×
787
                                //TODO: Check hatch undocumented codes
788
                                case 90:
789
                                        return true;
×
790
                                //Information about the hatch pattern
791
                                case 75:
792
                                        return true;
1,632✔
793
                                //Number of pattern definition lines
794
                                case 78:
795
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,224✔
796
                                        this.lockPointer = true;
1,224✔
797
                                        return true;
1,224✔
798
                                //Number of boundary paths (loops)
799
                                case 91:
800
                                        this.readLoops(tmp, this._reader.ValueAsInt);
1,632✔
801
                                        this.lockPointer = true;
1,632✔
802
                                        return true;
1,632✔
803
                                //Number of seed points
804
                                case 98:
805
                                        return true;
1,020✔
806
                                case 450:
807
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
340✔
808
                                        return true;
340✔
809
                                case 451:
810
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
340✔
811
                                        return true;
340✔
812
                                case 452:
813
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
340✔
814
                                        return true;
340✔
815
                                case 453:
816
                                        //Number of colors
817
                                        return true;
340✔
818
                                case 460:
819
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
340✔
820
                                        return true;
340✔
821
                                case 461:
822
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
340✔
823
                                        return true;
340✔
824
                                case 462:
825
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
340✔
826
                                        return true;
340✔
827
                                case 463:
828
                                        GradientColor gradient = new GradientColor();
680✔
829
                                        gradient.Value = this._reader.ValueAsDouble;
680✔
830
                                        hatch.GradientColor.Colors.Add(gradient);
680✔
831
                                        return true;
680✔
832
                                case 63:
833
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
680✔
834
                                        if (colorByIndex != null)
680✔
835
                                        {
680✔
836
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
680✔
837
                                        }
680✔
838
                                        return true;
680✔
839
                                case 421:
840
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
680✔
841
                                        if (colorByRgb != null)
680✔
842
                                        {
680✔
843
                                                //TODO: Hatch assign color by true color
844
                                                //TODO: Is always duplicated by 63, is it needed??
845
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
846
                                        }
680✔
847
                                        return true;
680✔
848
                                case 470:
849
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
340✔
850
                                        return true;
340✔
851
                                default:
852
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
23,596✔
853
                        }
854
                }
43,656✔
855

856
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
857
                {
58,880✔
858
                        CadInsertTemplate tmp = template as CadInsertTemplate;
58,880✔
859

860
                        switch (this._reader.Code)
58,880✔
861
                        {
862
                                case 2:
863
                                        tmp.BlockName = this._reader.ValueAsString;
5,506✔
864
                                        return true;
5,506✔
865
                                case 100:
866
                                        //AcDbEntity
867
                                        //AcDbBlockReference
868
                                        //AcDbMInsertBlock
869
                                        return true;
5,520✔
870
                                case 66:
871
                                        return true;
476✔
872
                                default:
873
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
47,378✔
874
                        }
875
                }
58,880✔
876

877
                private CadEntityTemplate readPolyline()
878
                {
10,444✔
879
                        CadPolyLineTemplate template = null;
10,444✔
880

881
                        if (this._builder.Version == ACadVersion.Unknown
10,444!
882
                                || this._builder.Version == ACadVersion.AC1009)
10,444✔
883
                        {
10,036✔
884
                                var polyline = new Polyline2D();
10,036✔
885
                                template = new CadPolyLineTemplate(polyline);
10,036✔
886
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,036✔
887

888
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
45,896!
889
                                {
35,860✔
890
                                        Vertex2D v = new Vertex2D();
35,860✔
891
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
35,860✔
892
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
35,860✔
893

894
                                        if (vertexTemplate.Vertex.Handle == 0)
35,860!
895
                                        {
×
896
                                                polyline.Vertices.Add(v);
×
897
                                        }
×
898
                                        else
899
                                        {
35,860✔
900
                                                template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
35,860✔
901
                                                this._builder.AddTemplate(vertexTemplate);
35,860✔
902
                                        }
35,860✔
903
                                }
35,860✔
904

905
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
20,072!
906
                                {
10,036✔
907
                                        var seqend = new Seqend();
10,036✔
908
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,036✔
909
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,036✔
910

911
                                        polyline.Vertices.Seqend = seqend;
10,036✔
912
                                }
10,036✔
913
                        }
10,036✔
914
                        else
915
                        {
408✔
916
                                template = new CadPolyLineTemplate();
408✔
917
                                this.readEntityCodes<Entity>(template, this.readPolyline);
408✔
918
                        }
408✔
919

920
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
10,444!
921
                        {
×
922
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
923
                                return null;
×
924
                        }
925

926
                        return template;
10,444✔
927
                }
10,444✔
928

929
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
930
                {
75,008✔
931
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
75,008✔
932

933
                        switch (this._reader.Code)
75,008✔
934
                        {
935
                                //DXF: always 0
936
                                //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)
937
                                case 10:
938
                                case 20:
939
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
940
                                case 66:
941
                                //Polygon mesh M vertex count (optional; default = 0)
942
                                case 71:
943
                                //Polygon mesh N vertex count(optional; default = 0)
944
                                case 72:
945
                                //Smooth surface M density(optional; default = 0)
946
                                case 73:
947
                                //Smooth surface N density (optional; default = 0)
948
                                case 74:
949
                                        return true;
31,808✔
950
                                case 100:
951
                                        switch (this._reader.ValueAsString)
816!
952
                                        {
953
                                                case DxfSubclassMarker.Polyline:
UNCOV
954
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
UNCOV
955
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
UNCOV
956
                                                        return true;
×
957
                                                case DxfSubclassMarker.Polyline3d:
958
                                                        tmp.SetPolyLineObject(new Polyline3D());
204✔
959
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
204✔
960
                                                        return true;
204✔
961
                                                case DxfSubclassMarker.PolyfaceMesh:
962
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
204✔
963
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
204✔
964
                                                        return true;
204✔
965
                                                case DxfSubclassMarker.PolygonMesh:
NEW
UNCOV
966
                                                        tmp.SetPolyLineObject(new PolygonMesh());
×
NEW
UNCOV
967
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
NEW
UNCOV
968
                                                        return true;
×
969
                                                default:
970
                                                        return false;
408✔
971
                                        }
972
                                default:
973
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
42,384✔
974
                        }
975
                }
75,008✔
976

977
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
978
                {
5,100✔
979
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
980

981
                        switch (this._reader.Code)
5,100✔
982
                        {
983
                                case 3:
984
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
204✔
985
                                        return true;
204✔
986
                                case 10:
987
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
816✔
988
                                        return true;
816✔
989
                                case 20:
990
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
991
                                        y.Y = this._reader.ValueAsDouble;
816✔
992
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
816✔
993
                                        return true;
816✔
994
                                case 30:
995
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
996
                                        z.Z = this._reader.ValueAsDouble;
816✔
997
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
816✔
998
                                        return true;
816✔
999
                                case 340:
1000
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
204✔
1001
                                        return true;
204✔
1002
                                //Hook line flag - read only
1003
                                case 75:
1004
                                //Vertices count
1005
                                case 76:
1006
                                        return true;
408✔
1007
                                default:
1008
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,836✔
1009
                        }
1010
                }
5,100✔
1011

1012
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1013
                {
87,012✔
1014
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
87,012✔
1015

1016
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
87,012✔
1017

1018
                        switch (this._reader.Code)
87,012!
1019
                        {
1020
                                case 10:
1021
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
20,700✔
1022
                                        return true;
20,700✔
1023
                                case 20:
1024
                                        if (last is not null)
20,700✔
1025
                                        {
20,700✔
1026
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
20,700✔
1027
                                        }
20,700✔
1028
                                        return true;
20,700✔
1029
                                case 40:
1030
                                        if (last is not null)
2,040✔
1031
                                        {
2,040✔
1032
                                                last.StartWidth = this._reader.ValueAsDouble;
2,040✔
1033
                                        }
2,040✔
1034
                                        return true;
2,040✔
1035
                                case 41:
1036
                                        if (last is not null)
2,040✔
1037
                                        {
2,040✔
1038
                                                last.EndWidth = this._reader.ValueAsDouble;
2,040✔
1039
                                        }
2,040✔
1040
                                        return true;
2,040✔
1041
                                case 42:
1042
                                        if (last is not null)
2,784✔
1043
                                        {
2,784✔
1044
                                                last.Bulge = this._reader.ValueAsDouble;
2,784✔
1045
                                        }
2,784✔
1046
                                        return true;
2,784✔
1047
                                case 50:
UNCOV
1048
                                        if (last is not null)
×
UNCOV
1049
                                        {
×
UNCOV
1050
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
1051
                                        }
×
1052
                                        return true;
×
1053
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1054
                                case 66:
1055
                                //Vertex count
1056
                                case 90:
1057
                                        return true;
4,668✔
1058
                                case 91:
UNCOV
1059
                                        if (last is not null)
×
UNCOV
1060
                                        {
×
UNCOV
1061
                                                last.Id = this._reader.ValueAsInt;
×
UNCOV
1062
                                        }
×
UNCOV
1063
                                        return true;
×
1064
                                default:
1065
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,080✔
1066
                        }
1067
                }
87,012✔
1068

1069
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1070
                {
35,904✔
1071
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
1072

1073
                        switch (this._reader.Code)
35,904✔
1074
                        {
1075
                                case 100:
1076
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
1077
                                        {
408✔
1078
                                                tmp.SubclassMarker = true;
408✔
1079
                                        }
408✔
1080
                                        return true;
816✔
1081
                                //Count of sub-entity which property has been overridden
1082
                                case 90:
1083
                                        //TODO: process further entities
1084
                                        return true;
408✔
1085
                                case 92:
1086
                                        if (!tmp.SubclassMarker)
612✔
1087
                                        {
204✔
1088
                                                return false;
204✔
1089
                                        }
1090

1091
                                        int nvertices = this._reader.ValueAsInt;
408✔
1092
                                        for (int i = 0; i < nvertices; i++)
52,224✔
1093
                                        {
25,704✔
1094
                                                this._reader.ReadNext();
25,704✔
1095
                                                double x = this._reader.ValueAsDouble;
25,704✔
1096
                                                this._reader.ReadNext();
25,704✔
1097
                                                double y = this._reader.ValueAsDouble;
25,704✔
1098
                                                this._reader.ReadNext();
25,704✔
1099
                                                double z = this._reader.ValueAsDouble;
25,704✔
1100
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
1101
                                        }
25,704✔
1102
                                        return true;
408✔
1103
                                case 93:
1104
                                        int size = this._reader.ValueAsInt;
408✔
1105
                                        this._reader.ReadNext();
408✔
1106

1107
                                        int indexes = 0;
408✔
1108
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
1109
                                        {
27,744✔
1110
                                                indexes = this._reader.ValueAsInt;
27,744✔
1111
                                                this._reader.ReadNext();
27,744✔
1112

1113
                                                int[] face = new int[indexes];
27,744✔
1114
                                                for (int j = 0; j < indexes; j++)
267,648✔
1115
                                                {
106,080✔
1116
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
1117

1118
                                                        if ((i + j + 2) < size)
106,080✔
1119
                                                        {
105,672✔
1120
                                                                this._reader.ReadNext();
105,672✔
1121
                                                        }
105,672✔
1122
                                                }
106,080✔
1123

1124
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1125
                                        }
27,744✔
1126

1127
                                        Debug.Assert(this._reader.Code == 90);
408✔
1128

1129
                                        return true;
408✔
1130
                                case 94:
1131
                                        int numEdges = this._reader.ValueAsInt;
408✔
1132
                                        this._reader.ReadNext();
408✔
1133
                                        for (int i = 0; i < numEdges; i++)
106,896✔
1134
                                        {
53,040✔
1135
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
1136

1137
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
1138
                                                this._reader.ReadNext();
53,040✔
1139
                                                edge.End = this._reader.ValueAsInt;
53,040✔
1140

1141
                                                if (i < numEdges - 1)
53,040✔
1142
                                                {
52,632✔
1143
                                                        this._reader.ReadNext();
52,632✔
1144
                                                }
52,632✔
1145

1146
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1147
                                        }
53,040✔
1148

1149
                                        Debug.Assert(this._reader.Code == 90);
408✔
1150

1151
                                        return true;
408✔
1152
                                case 95:
1153
                                        this._reader.ReadNext();
408✔
1154
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
1155
                                        {
53,040✔
1156
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
1157
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
1158

1159
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1160

1161
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
1162
                                                {
52,632✔
1163
                                                        this._reader.ReadNext();
52,632✔
1164
                                                }
52,632✔
1165
                                        }
53,040✔
1166

1167
                                        Debug.Assert(this._reader.Code == 140);
408✔
1168

1169
                                        return true;
408✔
1170
                                default:
1171
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1172
                        }
1173
                }
35,904✔
1174

1175
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1176
                {
53,040✔
1177
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1178

1179
                        switch (this._reader.Code)
53,040✔
1180
                        {
1181
                                // 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.
1182
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1183
                                case 2:
1184
                                        tmp.MLineStyleName = this._reader.ValueAsString;
612✔
1185
                                        return true;
612✔
1186
                                case 72:
1187
                                        tmp.NVertex = this._reader.ValueAsInt;
612✔
1188
                                        return true;
612✔
1189
                                case 73:
1190
                                        tmp.NElements = this._reader.ValueAsInt;
612✔
1191
                                        return true;
612✔
1192
                                case 340:
1193
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
612✔
1194
                                        return true;
612✔
1195
                                default:
1196
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
50,592✔
1197
                                        {
8,568✔
1198
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
8,568✔
1199
                                        }
1200
                                        return true;
42,024✔
1201
                        }
1202
                }
53,040✔
1203

1204
                private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1205
                {
144,024✔
1206
                        CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
144,024✔
1207

1208
                        switch (this._reader.Code)
144,024✔
1209
                        {
1210
                                case 270:
1211
                                        //f270 Version
1212
                                        return true;
1,530✔
1213
                                case 300:
1214
                                        this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,060✔
1215
                                        return true;
3,060✔
1216
                                case 340:
1217
                                        tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,060✔
1218
                                        return true;
3,060✔
1219
                                case 341:
1220
                                        tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,060✔
1221
                                        return true;
3,060✔
1222
                                case 343:
1223
                                        tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1224
                                        return true;
3,060✔
1225
                                default:
1226
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
130,254✔
1227
                        }
1228
                }
144,024✔
1229

1230
                private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1231
                {
3,060✔
1232
                        this._reader.ReadNext();
3,060✔
1233

1234
                        DxfMap map = DxfMap.Create<MultiLeaderObjectContextData>();
3,060✔
1235
                        var contextData = template.CadObject as MultiLeaderObjectContextData;
3,060✔
1236

1237
                        bool end = false;
3,060✔
1238
                        while (this._reader.DxfCode != DxfCode.Start)
171,360✔
1239
                        {
171,360✔
1240
                                switch (this._reader.Code)
171,360✔
1241
                                {
1242
                                        case 301 when this._reader.ValueAsString.Equals("}"):
3,060✔
1243
                                                end = true;
3,060✔
1244
                                                break;
3,060✔
1245
                                        case 302 when this._reader.ValueAsString.Equals("LEADER{"):
3,060✔
1246
                                                contextData.LeaderRoots.Add(this.readMultiLeaderLeader(template));
3,060✔
1247
                                                break;
3,060✔
1248
                                        case 340:
1249
                                                template.TextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1250
                                                break;
3,060✔
1251
                                        default:
1252
                                                if (!this.tryAssignCurrentValue(contextData, map.SubClasses[contextData.SubclassMarker]))
162,180!
UNCOV
1253
                                                {
×
UNCOV
1254
                                                        this._builder.Notify($"[AcDbMLeaderObjectContextData] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
UNCOV
1255
                                                }
×
1256
                                                break;
162,180✔
1257
                                }
1258

1259
                                if (end)
171,360✔
1260
                                {
3,060✔
1261
                                        break;
3,060✔
1262
                                }
1263

1264
                                this._reader.ReadNext();
168,300✔
1265
                        }
168,300✔
1266
                }
3,060✔
1267

1268
                private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1269
                {
3,060✔
1270
                        MultiLeaderObjectContextData.LeaderRoot root = new();
3,060✔
1271
                        var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,060✔
1272

1273
                        this._reader.ReadNext();
3,060✔
1274

1275
                        bool end = false;
3,060✔
1276
                        while (this._reader.DxfCode != DxfCode.Start)
38,250✔
1277
                        {
38,250✔
1278
                                switch (this._reader.Code)
38,250✔
1279
                                {
1280
                                        case 303 when this._reader.ValueAsString.Equals("}"):
3,060✔
1281
                                                end = true;
3,060✔
1282
                                                break;
3,060✔
1283
                                        case 304 when this._reader.ValueAsString.Equals("LEADER_LINE{"):
3,060✔
1284
                                                var lineTemplate = new LeaderLineTemplate();
3,060✔
1285
                                                template.LeaderLineTemplates.Add(lineTemplate);
3,060✔
1286
                                                root.Lines.Add(this.readMultiLeaderLine(lineTemplate));
3,060✔
1287
                                                break;
3,060✔
1288
                                        default:
1289
                                                if (!this.tryAssignCurrentValue(root, map))
32,130!
UNCOV
1290
                                                {
×
UNCOV
1291
                                                        this._builder.Notify($"[LeaderRoot] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
UNCOV
1292
                                                }
×
1293
                                                break;
32,130✔
1294
                                }
1295

1296
                                if (end)
38,250✔
1297
                                {
3,060✔
1298
                                        break;
3,060✔
1299
                                }
1300

1301
                                this._reader.ReadNext();
35,190✔
1302
                        }
35,190✔
1303

1304
                        return root;
3,060✔
1305
                }
3,060✔
1306

1307
                private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1308
                {
3,060✔
1309
                        MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,060✔
1310
                        var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,060✔
1311

1312
                        this._reader.ReadNext();
3,060✔
1313

1314
                        bool end = false;
3,060✔
1315
                        while (this._reader.DxfCode != DxfCode.Start)
15,300✔
1316
                        {
15,300✔
1317
                                switch (this._reader.Code)
15,300✔
1318
                                {
1319
                                        case 10:
1320
                                                XYZ pt = new XYZ(this._reader.ValueAsDouble, 0, 0);
3,060✔
1321
                                                line.Points.Add(pt);
3,060✔
1322
                                                break;
3,060✔
1323
                                        case 20:
1324
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1325
                                                pt.Y = this._reader.ValueAsDouble;
3,060✔
1326
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1327
                                                break;
3,060✔
1328
                                        case 30:
1329
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1330
                                                pt.Z = this._reader.ValueAsDouble;
3,060✔
1331
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1332
                                                break;
3,060✔
1333
                                        case 305 when this._reader.ValueAsString.Equals("}"):
3,060✔
1334
                                                end = true;
3,060✔
1335
                                                break;
3,060✔
1336
                                        default:
1337
                                                if (!this.tryAssignCurrentValue(line, map))
3,060!
UNCOV
1338
                                                {
×
UNCOV
1339
                                                        this._builder.Notify($"[LeaderLine] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
UNCOV
1340
                                                }
×
1341
                                                break;
3,060✔
1342
                                }
1343

1344
                                if (end)
15,300✔
1345
                                {
3,060✔
1346
                                        break;
3,060✔
1347
                                }
1348

1349
                                this._reader.ReadNext();
12,240✔
1350
                        }
12,240✔
1351

1352
                        return line;
3,060✔
1353
                }
3,060✔
1354

1355
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1356
                {
2,278✔
1357
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1358

1359
                        switch (this._reader.Code)
2,278✔
1360
                        {
1361
                                case 2:
1362
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1363
                                        return true;
238✔
1364
                                default:
1365
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1366
                        }
1367
                }
2,278✔
1368

1369
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1370
                {
12,036✔
1371
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,036✔
1372
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,036✔
1373

1374
                        switch (this._reader.Code)
12,036✔
1375
                        {
1376
                                case 91:
1377
                                        var nvertices = this._reader.ValueAsInt;
408✔
1378
                                        for (int i = 0; i < nvertices; i++)
3,672✔
1379
                                        {
1,428✔
1380
                                                this._reader.ReadNext();
1,428✔
1381
                                                var x = this._reader.ValueAsDouble;
1,428✔
1382
                                                this._reader.ReadNext();
1,428✔
1383
                                                var y = this._reader.ValueAsDouble;
1,428✔
1384

1385
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,428✔
1386
                                        }
1,428✔
1387

1388
                                        this._reader.ReadNext();
408✔
1389

1390
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
408✔
1391
                                case 340:
1392
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
408✔
1393
                                        return true;
408✔
1394
                                case 360:
1395
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
408✔
1396
                                        return true;
408✔
1397
                                default:
1398
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,812✔
1399
                        }
1400
                }
12,036✔
1401

1402
                private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1403
                {
×
UNCOV
1404
                        CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1405

1406
                        switch (this._reader.Code)
×
1407
                        {
1408
                                //End of data
1409
                                case 1:
1410
                                //Length of binary data
1411
                                case 90:
1412
                                //Undocumented
1413
                                case 73:
UNCOV
1414
                                        return true;
×
1415
                                case 310:
UNCOV
1416
                                        tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
UNCOV
1417
                                        return true;
×
1418
                                default:
UNCOV
1419
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1420
                        }
UNCOV
1421
                }
×
1422

1423
                private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1424
                {
288,776✔
1425
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
288,776✔
1426
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,776✔
1427
                        var geometry = template.CadObject as ModelerGeometry;
288,776✔
1428

1429
                        switch (this._reader.Code)
288,776✔
1430
                        {
1431
                                case 1:
1432
                                case 3:
1433
                                        geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
37,706✔
1434
                                        return true;
37,706✔
1435
                                case 2:
1436
                                        geometry.Guid = new Guid(this._reader.ValueAsString);
204✔
1437
                                        return true;
204✔
1438
                                case 290:
1439
                                        return true;
204✔
1440
                                default:
1441
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
250,662✔
1442
                        }
1443
                }
288,776✔
1444

1445
                private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1446
                {
34,884✔
1447
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
34,884✔
1448

1449
                        switch (this._reader.Code)
34,884✔
1450
                        {
1451
                                case 350:
1452
                                        tmp.HistoryHandle = this._reader.ValueAsHandle;
272✔
1453
                                        return true;
272✔
1454
                                default:
1455
                                        return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
34,612✔
1456
                        }
1457
                }
34,884✔
1458

1459
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1460
                {
14,280✔
1461
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1462

1463
                        XYZ controlPoint;
1464
                        XYZ fitPoint;
1465

1466
                        switch (this._reader.Code)
14,280!
1467
                        {
1468
                                case 10:
1469
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,632✔
1470
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,632✔
1471
                                        return true;
1,632✔
1472
                                case 20:
1473
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1474
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,632✔
1475
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1476
                                        return true;
1,632✔
1477
                                case 30:
1478
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1479
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,632✔
1480
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1481
                                        return true;
1,632✔
1482
                                case 11:
UNCOV
1483
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1484
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1485
                                        return true;
×
1486
                                case 21:
1487
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
UNCOV
1488
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
UNCOV
1489
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
UNCOV
1490
                                        return true;
×
1491
                                case 31:
1492
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1493
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
UNCOV
1494
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
UNCOV
1495
                                        return true;
×
1496
                                case 40:
1497
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,264✔
1498
                                        return true;
3,264✔
1499
                                case 41:
UNCOV
1500
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
UNCOV
1501
                                        return true;
×
1502
                                case 72:
1503
                                case 73:
1504
                                case 74:
1505
                                        return true;
1,224✔
1506
                                default:
1507
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,896✔
1508
                        }
1509
                }
14,280✔
1510

1511
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1512
                        where T : PdfUnderlayDefinition
1513
                {
3,230✔
1514
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,230✔
1515

1516
                        switch (this._reader.Code)
3,230✔
1517
                        {
1518
                                case 340:
1519
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
204✔
1520
                                        return true;
204✔
1521
                                default:
1522
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,026✔
1523
                        }
1524
                }
3,230✔
1525

1526
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1527
                {
238,252✔
1528
                        CadVertexTemplate tmp = template as CadVertexTemplate;
238,252✔
1529

1530
                        switch (this._reader.Code)
238,252✔
1531
                        {
1532
                                case 100:
1533
                                        switch (this._reader.ValueAsString)
6,936!
1534
                                        {
1535
                                                case DxfSubclassMarker.Vertex:
1536
                                                        return true;
2,040✔
1537
                                                case DxfSubclassMarker.PolylineVertex:
UNCOV
1538
                                                        tmp.SetVertexObject(new Vertex2D());
×
UNCOV
1539
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
UNCOV
1540
                                                        return true;
×
1541
                                                case DxfSubclassMarker.Polyline3dVertex:
1542
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1543
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1544
                                                        return true;
1,020✔
1545
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1546
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1547
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1548
                                                        return true;
1,020✔
1549
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1550
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1551
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1552
                                                        return true;
408✔
1553
                                                case DxfSubclassMarker.PolygonMeshVertex:
NEW
UNCOV
1554
                                                        tmp.SetVertexObject(new PolygonMeshVertex());
×
NEW
UNCOV
1555
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
NEW
UNCOV
1556
                                                        return true;
×
1557
                                                default:
1558
                                                        return false;
2,448✔
1559
                                        }
1560
                                default:
1561
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
231,316✔
1562
                        }
1563
                }
238,252✔
1564

1565
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1566
                {
67,976✔
1567
                        CadViewportTemplate tmp = template as CadViewportTemplate;
67,976✔
1568

1569
                        switch (this._reader.Code)
67,976!
1570
                        {
1571
                                //Undocumented
1572
                                case 67:
1573
                                case 68:
1574
                                        return true;
2,488✔
1575
                                case 69:
1576
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,244✔
1577
                                        return true;
1,244✔
1578
                                case 331:
UNCOV
1579
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
UNCOV
1580
                                        return true;
×
1581
                                case 348:
1582
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1583
                                        return true;
784✔
1584
                                default:
1585
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
63,460✔
1586
                        }
1587
                }
67,976✔
1588

1589
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1590
                {
805,460✔
1591
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
805,460✔
1592

1593
                        switch (this._reader.Code)
805,460✔
1594
                        {
1595
                                default:
1596
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
805,460✔
1597
                        }
1598
                }
805,460✔
1599

1600
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1601
                {
34,090✔
1602
                        List<ExtendedDataRecord> records = new();
34,090✔
1603
                        edata.Add(this._reader.ValueAsString, records);
34,090✔
1604

1605
                        this._reader.ReadNext();
34,090✔
1606

1607
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,315✔
1608
                        {
256,077✔
1609
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,077✔
1610
                                {
10,852✔
1611
                                        this.readExtendedData(edata);
10,852✔
1612
                                        break;
10,852✔
1613
                                }
1614

1615
                                ExtendedDataRecord record = null;
245,225✔
1616
                                double x = 0;
245,225✔
1617
                                double y = 0;
245,225✔
1618
                                double z = 0;
245,225✔
1619

1620
                                switch (this._reader.DxfCode)
245,225✔
1621
                                {
1622
                                        case DxfCode.ExtendedDataAsciiString:
1623
                                        case DxfCode.ExtendedDataRegAppName:
1624
                                                record = new ExtendedDataString(this._reader.ValueAsString);
23,485✔
1625
                                                break;
23,485✔
1626
                                        case DxfCode.ExtendedDataControlString:
1627
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,472✔
1628
                                                break;
13,472✔
1629
                                        case DxfCode.ExtendedDataLayerName:
1630
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1631
                                                {
224✔
1632
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1633
                                                }
224✔
1634
                                                else
1635
                                                {
14✔
1636
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1637
                                                }
14✔
1638
                                                break;
238✔
1639
                                        case DxfCode.ExtendedDataBinaryChunk:
1640
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1641
                                                break;
68✔
1642
                                        case DxfCode.ExtendedDataHandle:
1643
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,508✔
1644
                                                break;
2,508✔
1645
                                        case DxfCode.ExtendedDataXCoordinate:
1646
                                                x = this._reader.ValueAsDouble;
2,540✔
1647
                                                this._reader.ReadNext();
2,540✔
1648
                                                y = this._reader.ValueAsDouble;
2,540✔
1649
                                                this._reader.ReadNext();
2,540✔
1650
                                                z = this._reader.ValueAsDouble;
2,540✔
1651

1652
                                                record = new ExtendedDataCoordinate(
2,540✔
1653
                                                        new XYZ(
2,540✔
1654
                                                                x,
2,540✔
1655
                                                                y,
2,540✔
1656
                                                                z)
2,540✔
1657
                                                        );
2,540✔
1658
                                                break;
2,540✔
1659
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1660
                                                x = this._reader.ValueAsDouble;
1,224✔
1661
                                                this._reader.ReadNext();
1,224✔
1662
                                                y = this._reader.ValueAsDouble;
1,224✔
1663
                                                this._reader.ReadNext();
1,224✔
1664
                                                z = this._reader.ValueAsDouble;
1,224✔
1665

1666
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1667
                                                        new XYZ(
1,224✔
1668
                                                                x,
1,224✔
1669
                                                                y,
1,224✔
1670
                                                                z)
1,224✔
1671
                                                        );
1,224✔
1672
                                                break;
1,224✔
1673
                                        case DxfCode.ExtendedDataWorldXDisp:
1674
                                                x = this._reader.ValueAsDouble;
238✔
1675
                                                this._reader.ReadNext();
238✔
1676
                                                y = this._reader.ValueAsDouble;
238✔
1677
                                                this._reader.ReadNext();
238✔
1678
                                                z = this._reader.ValueAsDouble;
238✔
1679

1680
                                                record = new ExtendedDataDisplacement(
238✔
1681
                                                        new XYZ(
238✔
1682
                                                                x,
238✔
1683
                                                                y,
238✔
1684
                                                                z)
238✔
1685
                                                        );
238✔
1686
                                                break;
238✔
1687
                                        case DxfCode.ExtendedDataWorldXDir:
1688
                                                x = this._reader.ValueAsDouble;
238✔
1689
                                                this._reader.ReadNext();
238✔
1690
                                                y = this._reader.ValueAsDouble;
238✔
1691
                                                this._reader.ReadNext();
238✔
1692
                                                z = this._reader.ValueAsDouble;
238✔
1693

1694
                                                record = new ExtendedDataDirection(
238✔
1695
                                                        new XYZ(
238✔
1696
                                                                x,
238✔
1697
                                                                y,
238✔
1698
                                                                z)
238✔
1699
                                                        );
238✔
1700
                                                break;
238✔
1701
                                        case DxfCode.ExtendedDataReal:
1702
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
119,446✔
1703
                                                break;
119,446✔
1704
                                        case DxfCode.ExtendedDataDist:
1705
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1706
                                                break;
238✔
1707
                                        case DxfCode.ExtendedDataScale:
1708
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1709
                                                break;
238✔
1710
                                        case DxfCode.ExtendedDataInteger16:
1711
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
69,609✔
1712
                                                break;
69,609✔
1713
                                        case DxfCode.ExtendedDataInteger32:
1714
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
9,507✔
1715
                                                break;
9,507✔
1716
                                        default:
1717
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1718
                                                break;
2,176✔
1719
                                }
1720

1721
                                if (record != null)
245,225✔
1722
                                {
243,035✔
1723
                                        records.Add(record);
243,035✔
1724
                                }
243,035✔
1725

1726
                                this._reader.ReadNext();
245,225✔
1727
                        }
245,225✔
1728
                }
34,090✔
1729

1730
                private void readPattern(HatchPattern pattern, int nlines)
1731
                {
1,224✔
1732
                        //Jump 78 code
1733
                        this._reader.ReadNext();
1,224✔
1734

1735
                        for (int i = 0; i < nlines; i++)
185,640✔
1736
                        {
91,596✔
1737
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1738
                                XY basePoint = new XY();
91,596✔
1739
                                XY offset = new XY();
91,596✔
1740

1741
                                bool end = false;
91,596✔
1742
                                HashSet<int> codes = new();
91,596✔
1743

1744
                                while (!end)
642,396✔
1745
                                {
641,172✔
1746
                                        if (codes.Contains(this._reader.Code))
641,172✔
1747
                                        {
90,372✔
1748
                                                break;
90,372✔
1749
                                        }
1750
                                        else
1751
                                        {
550,800✔
1752
                                                codes.Add(this._reader.Code);
550,800✔
1753
                                        }
550,800✔
1754

1755
                                        switch (this._reader.Code)
550,800!
1756
                                        {
1757
                                                case 53:
1758
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1759
                                                        break;
91,596✔
1760
                                                case 43:
1761
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1762
                                                        break;
91,596✔
1763
                                                case 44:
1764
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1765
                                                        line.BasePoint = basePoint;
91,596✔
1766
                                                        break;
91,596✔
1767
                                                case 45:
1768
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1769
                                                        line.Offset = offset;
91,596✔
1770
                                                        break;
91,596✔
1771
                                                case 46:
1772
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1773
                                                        line.Offset = offset;
91,596✔
1774
                                                        break;
91,596✔
1775
                                                //Number of dash length items
1776
                                                case 79:
1777
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1778
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1779
                                                        {
182,784✔
1780
                                                                this._reader.ReadNext();
182,784✔
1781
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1782
                                                        }
182,784✔
1783
                                                        break;
91,596✔
1784
                                                case 49:
UNCOV
1785
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
UNCOV
1786
                                                        break;
×
1787
                                                default:
1788
                                                        end = true;
1,224✔
1789
                                                        break;
1,224✔
1790
                                        }
1791
                                        this._reader.ReadNext();
550,800✔
1792
                                }
550,800✔
1793

1794
                                pattern.Lines.Add(line);
91,596✔
1795
                        }
91,596✔
1796
                }
1,224✔
1797

1798
                private void readLoops(CadHatchTemplate template, int count)
1799
                {
1,632✔
1800
                        if (this._reader.Code == 91)
1,632✔
1801
                                this._reader.ReadNext();
1,632✔
1802

1803
                        for (int i = 0; i < count; i++)
6,528✔
1804
                        {
1,632✔
1805
                                if (this._reader.Code != 92)
1,632!
UNCOV
1806
                                {
×
UNCOV
1807
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
UNCOV
1808
                                        break;
×
1809
                                }
1810

1811
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1812
                                if (path != null)
1,632✔
1813
                                        template.PathTemplates.Add(path);
1,632✔
1814
                        }
1,632✔
1815
                }
1,632✔
1816

1817
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1818
                {
1,632✔
1819
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1820
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1821
                        template.Path.Flags = flags;
1,632✔
1822

1823
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1824
                        {
612✔
1825
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1826
                                template.Path.Edges.Add(pl);
612✔
1827
                        }
612✔
1828
                        else
1829
                        {
1,020✔
1830
                                this._reader.ReadNext();
1,020✔
1831

1832
                                if (this._reader.Code != 93)
1,020!
UNCOV
1833
                                {
×
UNCOV
1834
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
UNCOV
1835
                                        return null;
×
1836
                                }
1837

1838
                                int edges = this._reader.ValueAsInt;
1,020✔
1839
                                this._reader.ReadNext();
1,020✔
1840

1841
                                for (int i = 0; i < edges; i++)
10,200✔
1842
                                {
4,080✔
1843
                                        var edge = this.readEdge();
4,080✔
1844
                                        if (edge != null)
4,080✔
1845
                                                template.Path.Edges.Add(edge);
4,080✔
1846
                                }
4,080✔
1847
                        }
1,020✔
1848

1849
                        bool end = false;
1,632✔
1850
                        while (!end)
6,324✔
1851
                        {
4,692✔
1852
                                switch (this._reader.Code)
4,692✔
1853
                                {
1854
                                        //Number of source boundary objects
1855
                                        case 97:
1856
                                                break;
1,632✔
1857
                                        case 330:
1858
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1859
                                                break;
1,428✔
1860
                                        default:
1861
                                                end = true;
1,632✔
1862
                                                continue;
1,632✔
1863
                                }
1864

1865
                                this._reader.ReadNext();
3,060✔
1866
                        }
3,060✔
1867

1868
                        return template;
1,632✔
1869
                }
1,632✔
1870

1871
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1872
                {
612✔
1873
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
1874

1875
                        this._reader.ReadNext();
612✔
1876

1877
                        if (this._reader.Code != 72)
612!
UNCOV
1878
                        {
×
UNCOV
1879
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
UNCOV
1880
                                return null;
×
1881
                        }
1882

1883
                        //72
1884
                        bool hasBulge = this._reader.ValueAsBool;
612✔
1885
                        this._reader.ReadNext();
612✔
1886

1887
                        //73
1888
                        bool isClosed = this._reader.ValueAsBool;
612✔
1889
                        this._reader.ReadNext();
612✔
1890

1891
                        //93
1892
                        int nvertices = this._reader.ValueAsInt;
612✔
1893
                        this._reader.ReadNext();
612✔
1894

1895
                        for (int i = 0; i < nvertices; i++)
6,120✔
1896
                        {
2,448✔
1897
                                double bulge = 0.0;
2,448✔
1898

1899
                                //10
1900
                                double x = this._reader.ValueAsDouble;
2,448✔
1901
                                this._reader.ReadNext();
2,448✔
1902
                                //20
1903
                                double y = this._reader.ValueAsDouble;
2,448✔
1904
                                this._reader.ReadNext();
2,448✔
1905

1906
                                if (hasBulge)
2,448!
UNCOV
1907
                                {
×
1908
                                        //42
UNCOV
1909
                                        bulge = this._reader.ValueAsDouble;
×
UNCOV
1910
                                        this._reader.ReadNext();
×
UNCOV
1911
                                }
×
1912

1913
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
1914
                        }
2,448✔
1915

1916
                        return boundary;
612✔
1917
                }
612✔
1918

1919
                private Hatch.BoundaryPath.Edge readEdge()
1920
                {
4,080✔
1921
                        if (this._reader.Code != 72)
4,080!
UNCOV
1922
                        {
×
UNCOV
1923
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
UNCOV
1924
                                return null;
×
1925
                        }
1926

1927
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
1928
                        this._reader.ReadNext();
4,080✔
1929

1930
                        switch (type)
4,080!
1931
                        {
1932
                                case Hatch.BoundaryPath.EdgeType.Line:
1933
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,080✔
1934
                                        while (true)
20,400✔
1935
                                        {
20,400✔
1936
                                                switch (this._reader.Code)
20,400✔
1937
                                                {
1938
                                                        case 10:
1939
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,080✔
1940
                                                                break;
4,080✔
1941
                                                        case 20:
1942
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,080✔
1943
                                                                break;
4,080✔
1944
                                                        case 11:
1945
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,080✔
1946
                                                                break;
4,080✔
1947
                                                        case 21:
1948
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,080✔
1949
                                                                break;
4,080✔
1950
                                                        default:
1951
                                                                return line;
4,080✔
1952
                                                }
1953

1954
                                                this._reader.ReadNext();
16,320✔
1955
                                        }
16,320✔
1956
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
UNCOV
1957
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1958
                                        while (true)
×
1959
                                        {
×
UNCOV
1960
                                                switch (this._reader.Code)
×
1961
                                                {
1962
                                                        case 10:
UNCOV
1963
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1964
                                                                break;
×
1965
                                                        case 20:
UNCOV
1966
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1967
                                                                break;
×
1968
                                                        case 40:
UNCOV
1969
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1970
                                                                break;
×
1971
                                                        case 50:
UNCOV
1972
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1973
                                                                break;
×
1974
                                                        case 51:
UNCOV
1975
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1976
                                                                break;
×
1977
                                                        case 73:
UNCOV
1978
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1979
                                                                break;
×
1980
                                                        default:
1981
                                                                return arc;
×
1982
                                                }
1983

UNCOV
1984
                                                this._reader.ReadNext();
×
1985
                                        }
×
1986
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
UNCOV
1987
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1988
                                        while (true)
×
1989
                                        {
×
UNCOV
1990
                                                switch (this._reader.Code)
×
1991
                                                {
1992
                                                        case 10:
UNCOV
1993
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1994
                                                                break;
×
1995
                                                        case 20:
UNCOV
1996
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1997
                                                                break;
×
1998
                                                        case 11:
UNCOV
1999
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2000
                                                                break;
×
2001
                                                        case 21:
UNCOV
2002
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2003
                                                                break;
×
2004
                                                        case 40:
UNCOV
2005
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
2006
                                                                break;
×
2007
                                                        case 50:
UNCOV
2008
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
2009
                                                                break;
×
2010
                                                        case 51:
UNCOV
2011
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
2012
                                                                break;
×
2013
                                                        case 73:
UNCOV
2014
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
2015
                                                                break;
×
2016
                                                        default:
2017
                                                                return ellipse;
×
2018
                                                }
2019

2020
                                                this._reader.ReadNext();
×
2021
                                        }
×
2022
                                case Hatch.BoundaryPath.EdgeType.Spline:
2023
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
2024
                                        int nKnots = 0;
×
2025
                                        int nCtrlPoints = 0;
×
UNCOV
2026
                                        int nFitPoints = 0;
×
2027

2028
                                        XYZ controlPoint = new XYZ();
×
2029
                                        XY fitPoint = new XY();
×
2030

2031
                                        while (true)
×
2032
                                        {
×
2033
                                                switch (this._reader.Code)
×
2034
                                                {
2035
                                                        case 10:
2036
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
UNCOV
2037
                                                                break;
×
2038
                                                        case 20:
2039
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
2040
                                                                spline.ControlPoints.Add(controlPoint);
×
UNCOV
2041
                                                                break;
×
2042
                                                        case 11:
2043
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
2044
                                                                break;
×
2045
                                                        case 21:
2046
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
2047
                                                                spline.FitPoints.Add(fitPoint);
×
UNCOV
2048
                                                                break;
×
2049
                                                        case 42:
2050
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
UNCOV
2051
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
2052
                                                                break;
×
2053
                                                        case 12:
UNCOV
2054
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
2055
                                                                break;
×
2056
                                                        case 22:
UNCOV
2057
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
2058
                                                                break;
×
2059
                                                        case 13:
UNCOV
2060
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
2061
                                                                break;
×
2062
                                                        case 23:
UNCOV
2063
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
2064
                                                                break;
×
2065
                                                        case 94:
UNCOV
2066
                                                                spline.Degree = this._reader.ValueAsInt;
×
2067
                                                                break;
×
2068
                                                        case 73:
UNCOV
2069
                                                                spline.IsRational = this._reader.ValueAsBool;
×
2070
                                                                break;
×
2071
                                                        case 74:
UNCOV
2072
                                                                spline.IsPeriodic = this._reader.ValueAsBool;
×
2073
                                                                break;
×
2074
                                                        case 95:
UNCOV
2075
                                                                nKnots = this._reader.ValueAsInt;
×
2076
                                                                break;
×
2077
                                                        case 96:
UNCOV
2078
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
2079
                                                                break;
×
2080
                                                        case 97:
UNCOV
2081
                                                                nFitPoints = this._reader.ValueAsInt;
×
2082
                                                                break;
×
2083
                                                        case 40:
UNCOV
2084
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
UNCOV
2085
                                                                break;
×
2086
                                                        default:
UNCOV
2087
                                                                return spline;
×
2088
                                                }
2089

UNCOV
2090
                                                this._reader.ReadNext();
×
UNCOV
2091
                                        }
×
2092
                        }
2093

UNCOV
2094
                        return null;
×
2095
                }
4,080✔
2096

2097
                private void readDefinedGroups(CadTemplate template)
2098
                {
67,155✔
2099
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
67,155✔
2100

2101
                        template.XDictHandle = xdict;
67,155✔
2102
                        template.ReactorsHandles.UnionWith(reactorsHandles);
67,155✔
2103
                }
67,155✔
2104

2105
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2106
                {
67,361✔
2107
                        xdictHandle = null;
67,361✔
2108
                        reactors = new HashSet<ulong>();
67,361✔
2109

2110
                        switch (this._reader.ValueAsString)
67,361✔
2111
                        {
2112
                                case DxfFileToken.DictionaryToken:
2113
                                        this._reader.ReadNext();
10,027✔
2114
                                        xdictHandle = this._reader.ValueAsHandle;
10,027✔
2115
                                        this._reader.ReadNext();
10,027✔
2116
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,027✔
2117
                                        return;
10,027✔
2118
                                case DxfFileToken.ReactorsToken:
2119
                                        reactors = this.readReactors();
55,294✔
2120
                                        break;
55,294✔
2121
                                case DxfFileToken.BlkRefToken:
2122
                                default:
2123
                                        do
2124
                                        {
5,304✔
2125
                                                this._reader.ReadNext();
5,304✔
2126
                                        }
5,304✔
2127
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,304✔
2128
                                        return;
2,040✔
2129
                        }
2130
                }
67,361✔
2131

2132
                private HashSet<ulong> readReactors()
2133
                {
55,294✔
2134
                        HashSet<ulong> reactors = new();
55,294✔
2135

2136
                        this._reader.ReadNext();
55,294✔
2137

2138
                        while (this._reader.DxfCode != DxfCode.ControlString)
117,092✔
2139
                        {
61,798✔
2140
                                reactors.Add(this._reader.ValueAsHandle);
61,798✔
2141

2142
                                this._reader.ReadNext();
61,798✔
2143
                        }
61,798✔
2144

2145
                        return reactors;
55,294✔
2146
                }
55,294✔
2147

2148
                protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2149
                {
4,135,967✔
2150
                        try
2151
                        {
4,135,967✔
2152
                                //Use this method only if the value is not a link between objects
2153
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,135,967✔
2154
                                {
2,218,488✔
2155
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,218,488✔
2156
                                        {
12,570✔
2157
                                                return true;
12,570✔
2158
                                        }
2159

2160
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,205,918✔
2161
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,205,918✔
2162
                                        {
14,704✔
2163
                                                return false;
14,704✔
2164
                                        }
2165

2166
                                        object value = this._reader.Value;
2,191,214✔
2167

2168
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,191,214✔
2169
                                        {
24,794✔
2170
                                                value = MathHelper.DegToRad((double)value);
24,794✔
2171
                                        }
24,794✔
2172

2173
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,191,214✔
2174

2175
                                        return true;
2,191,214✔
2176
                                }
2177
                        }
1,917,479✔
2178
                        catch (Exception ex)
×
2179
                        {
×
2180
                                if (!this._builder.Configuration.Failsafe)
×
UNCOV
2181
                                {
×
UNCOV
2182
                                        throw ex;
×
2183
                                }
2184
                                else
UNCOV
2185
                                {
×
UNCOV
2186
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
UNCOV
2187
                                }
×
UNCOV
2188
                        }
×
2189

2190
                        return false;
1,917,479✔
2191
                }
4,135,967✔
2192
        }
2193
}
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