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

DomCR / ACadSharp / 17035283852

18 Aug 2025 08:28AM UTC coverage: 78.449% (+0.006%) from 78.443%
17035283852

push

github

web-flow
Merge pull request #739 from DomCR/issue-738_separator-culture-independent

issue-738_separator-culture-independent

6492 of 8996 branches covered (72.17%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 1 file covered. (100.0%)

65 existing lines in 1 file now uncovered.

25247 of 31462 relevant lines covered (80.25%)

105110.79 hits per line

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

83.64
/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 CSUtilities.Converters;
8
using System;
9
using System.Collections.Generic;
10
using System.Diagnostics;
11
using System.Linq;
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
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
1,056✔
23
                {
1,056✔
24
                        this._reader = reader;
1,056✔
25
                        this._builder = builder;
1,056✔
26
                }
1,056✔
27

28
                public abstract void Read();
29

30
                protected void readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out List<ulong> reactors)
31
                {
2,482✔
32
                        name = null;
2,482✔
33
                        handle = 0;
2,482✔
34
                        ownerHandle = null;
2,482✔
35
                        xdictHandle = null;
2,482✔
36
                        reactors = new List<ulong>();
2,482✔
37

38
                        if (this._reader.DxfCode == DxfCode.Start
2,482!
39
                                        || this._reader.DxfCode == DxfCode.Subclass)
2,482✔
40
                                this._reader.ReadNext();
×
41

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

74
                                this._reader.ReadNext();
7,372✔
75
                        }
7,372✔
76
                }
2,482✔
77

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

106
                                this._reader.ReadNext();
1,944✔
107
                        }
1,944✔
108
                }
648✔
109

110
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
111
                {
1,906,929✔
112
                        isExtendedData = false;
1,906,929✔
113

114
                        switch (this._reader.Code)
1,906,929✔
115
                        {
116
                                //Handle
117
                                case 5:
118
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
306,331✔
119
                                        break;
306,331✔
120
                                //Check with mapper
121
                                case 100:
122
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
214,977!
123
                                        {
3,328✔
124
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
3,328✔
125
                                        }
3,328✔
126
                                        break;
214,977✔
127
                                //Start of application - defined group
128
                                case 102:
129
                                        this.readDefinedGroups(template);
62,223✔
130
                                        break;
62,223✔
131
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
132
                                case 330:
133
                                        template.OwnerHandle = this._reader.ValueAsHandle;
163,765✔
134
                                        break;
163,765✔
135
                                case 1001:
136
                                        isExtendedData = true;
26,047✔
137
                                        this.readExtendedData(template.EDataTemplateByAppName);
26,047✔
138
                                        break;
26,047✔
139
                                default:
140
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
1,133,586✔
141
                                        break;
1,133,586✔
142
                        }
143
                }
1,906,929✔
144

145
                protected CadEntityTemplate readEntity()
146
                {
212,928✔
147
                        switch (this._reader.ValueAsString)
212,928✔
148
                        {
149
                                case DxfFileToken.EntityAttribute:
150
                                        return this.readEntityCodes<AttributeEntity>(new CadAttributeTemplate(new AttributeEntity()), this.readAttributeDefinition);
1,064✔
151
                                case DxfFileToken.EntityAttributeDefinition:
152
                                        return this.readEntityCodes<AttributeDefinition>(new CadAttributeTemplate(new AttributeDefinition()), this.readAttributeDefinition);
1,260✔
153
                                case DxfFileToken.EntityArc:
154
                                        return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), this.readArc);
770✔
155
                                case DxfFileToken.EntityCircle:
156
                                        return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), this.readEntitySubclassMap);
2,324✔
157
                                case DxfFileToken.EntityDimension:
158
                                        return this.readEntityCodes<Dimension>(new CadDimensionTemplate(), this.readDimension);
2,926✔
159
                                case DxfFileToken.Entity3DFace:
160
                                        return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), this.readEntitySubclassMap);
266✔
161
                                case DxfFileToken.EntityEllipse:
162
                                        return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), this.readEntitySubclassMap);
228✔
163
                                case DxfFileToken.EntityLeader:
164
                                        return this.readEntityCodes<Leader>(new CadLeaderTemplate(), this.readLeader);
228✔
165
                                case DxfFileToken.EntityLine:
166
                                        return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), this.readEntitySubclassMap);
67,004✔
167
                                case DxfFileToken.EntityLwPolyline:
168
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
4,764✔
169
                                case DxfFileToken.EntityMesh:
170
                                        return this.readEntityCodes<Mesh>(new CadMeshTemplate(), this.readMesh);
456✔
171
                                case DxfFileToken.EntityHatch:
172
                                        return this.readEntityCodes<Hatch>(new CadHatchTemplate(), this.readHatch);
1,824✔
173
                                case DxfFileToken.EntityInsert:
174
                                        return this.readEntityCodes<Insert>(new CadInsertTemplate(), this.readInsert);
6,060✔
175
                                case DxfFileToken.EntityMText:
176
                                        return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), this.readTextEntity);
7,836✔
177
                                case DxfFileToken.EntityMLine:
178
                                        return this.readEntityCodes<MLine>(new CadMLineTemplate(), this.readMLine);
684✔
179
                                case DxfFileToken.EntityPdfUnderlay:
180
                                        return this.readEntityCodes<PdfUnderlay>(new CadUnderlayTemplate<PdfUnderlayDefinition>(new PdfUnderlay()), this.readUnderlayEntity<PdfUnderlayDefinition>);
228✔
181
                                case DxfFileToken.EntityPoint:
182
                                        return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), this.readEntitySubclassMap);
10,164✔
183
                                case DxfFileToken.EntityPolyline:
184
                                        return this.readPolyline();
11,664✔
185
                                case DxfFileToken.EntityRay:
186
                                        return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), this.readEntitySubclassMap);
228✔
187
                                case DxfFileToken.EndSequence:
188
                                        return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), this.readEntitySubclassMap);
12,196✔
189
                                case DxfFileToken.EntitySolid:
190
                                        return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), this.readEntitySubclassMap);
15,458✔
191
                                case DxfFileToken.EntityTable:
192
                                        return this.readEntityCodes<TableEntity>(new CadTableEntityTemplate(), this.readTableEntity);
456✔
193
                                case DxfFileToken.EntityText:
194
                                        return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), this.readTextEntity);
15,282✔
195
                                case DxfFileToken.EntityTolerance:
196
                                        return this.readEntityCodes<Tolerance>(new CadToleranceTemplate(new Tolerance()), this.readTolerance);
684✔
197
                                case DxfFileToken.EntityVertex:
198
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
42,652✔
199
                                case DxfFileToken.EntityViewport:
200
                                        return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
1,396✔
201
                                case DxfFileToken.EntityShape:
202
                                        return this.readEntityCodes<Shape>(new CadShapeTemplate(new Shape()), this.readShape);
266✔
203
                                case DxfFileToken.EntitySpline:
204
                                        return this.readEntityCodes<Spline>(new CadSplineTemplate(), this.readSpline);
456✔
205
                                case DxfFileToken.EntityXline:
206
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
228✔
207
                                default:
208
                                        DxfMap map = DxfMap.Create<Entity>();
3,876✔
209
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
3,876✔
210
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
3,876✔
211
                                        {
3,672✔
212
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
3,672✔
213
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
3,672✔
214
                                        }
3,672✔
215
                                        else
216
                                        {
204✔
217
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
204✔
218
                                        }
204✔
219

220
                                        this._reader.ReadNext();
3,876✔
221

222
                                        do
223
                                        {
430,716✔
224
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
430,716✔
225
                                                {
45,156✔
226
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
45,156✔
227
                                                        if (isExtendedData)
45,156✔
228
                                                                continue;
180✔
229
                                                }
44,976✔
230

231
                                                this._reader.ReadNext();
430,536✔
232
                                        }
430,536✔
233
                                        while (this._reader.DxfCode != DxfCode.Start);
430,716✔
234

235
                                        return unknownEntityTemplate;
3,876✔
236
                        }
237
                }
212,928✔
238

239
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
240
                        where T : Entity
241
                {
209,126✔
242
                        this._reader.ReadNext();
209,126✔
243

244
                        DxfMap map = DxfMap.Create<T>();
209,126✔
245

246
                        while (this._reader.DxfCode != DxfCode.Start)
2,677,170✔
247
                        {
2,468,044✔
248
                                if (!readEntity(template, map))
2,468,044✔
249
                                {
1,081,028✔
250
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
1,081,028✔
251
                                        if (isExtendedData)
1,081,028✔
252
                                                continue;
13,034✔
253
                                }
1,067,994✔
254

255
                                if (this._reader.DxfCode != DxfCode.Start)
2,455,010✔
256
                                        this._reader.ReadNext();
2,454,936✔
257
                        }
2,455,010✔
258

259
                        return template;
209,126✔
260
                }
209,126✔
261

262
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
263
                {
1,201,066✔
264
                        isExtendedData = false;
1,201,066✔
265
                        switch (this._reader.Code)
1,201,066✔
266
                        {
267
                                case 6:
268
                                        template.LineTypeName = this._reader.ValueAsString;
28,856✔
269
                                        break;
28,856✔
270
                                case 8:
271
                                        template.LayerName = this._reader.ValueAsString;
227,736✔
272
                                        break;
227,736✔
273
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
274
                                case 67:
275
                                        break;
1,376✔
276
                                //Number of bytes Proxy entity graphics data
277
                                case 92:
278
                                case 160:
279
                                //Proxy entity graphics data
280
                                case 310:
281
                                        break;
58,630✔
282
                                case 347:
283
                                        template.MaterialHandle = this._reader.ValueAsHandle;
152✔
284
                                        break;
152✔
285
                                case 430:
286
                                        template.BookColorName = this._reader.ValueAsString;
190✔
287
                                        break;
190✔
288
                                default:
289
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
884,126✔
290
                                        {
735,744✔
291
                                                this.readCommonCodes(template, out isExtendedData, map);
735,744✔
292
                                        }
735,744✔
293
                                        break;
884,126✔
294
                        }
295
                }
1,201,066✔
296

297
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
298
                {
432✔
299
                        if (this._reader.DxfCode == DxfCode.Start)
432✔
300
                        {
216✔
301
                                return true;
216✔
302
                        }
303
                        else
304
                        {
216✔
305
                                return func.Invoke(template, map);
216✔
306
                        }
307
                }
432✔
308

309
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
310
                {
10,096✔
311
                        switch (this._reader.Code)
10,096✔
312
                        {
313
                                default:
314
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
10,096✔
315
                                        {
8,556✔
316
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
8,556✔
317
                                        }
318
                                        return true;
1,540✔
319
                        }
320
                }
10,096✔
321

322
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
323
                {
37,510✔
324
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
37,510✔
325
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
37,510✔
326

327
                        switch (this._reader.Code)
37,510!
328
                        {
329
                                case 44:
330
                                case 46:
331
                                        return true;
×
332
                                case 101:
333
                                        var att = tmp.CadObject as AttributeBase;
74✔
334
                                        att.MText = new MText();
74✔
335
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
74✔
336
                                        tmp.MTextTemplate = mtextTemplate;
74✔
337
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
74✔
338
                                        return true;
74✔
339
                                default:
340
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
37,436✔
341
                                        {
28,322✔
342
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
28,322✔
343
                                        }
344
                                        return true;
9,114✔
345
                        }
346
                }
37,510✔
347

348
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
349
                {
150,138✔
350
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
150,138!
351
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
150,138✔
352
                        TableEntity table = tmp.CadObject as TableEntity;
150,138✔
353

354
                        switch (this._reader.Code)
150,138✔
355
                        {
356
                                case 2:
357
                                        tmp.BlockName = this._reader.ValueAsString;
456✔
358
                                        return true;
456✔
359
                                case 342:
360
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
456✔
361
                                        return true;
456✔
362
                                case 343:
363
                                        tmp.BlockOwnerHandle = this._reader.ValueAsHandle;
456✔
364
                                        return true;
456✔
365
                                case 141:
366
                                        var row = new TableEntity.Row();
2,508✔
367
                                        row.Height = this._reader.ValueAsDouble;
2,508✔
368
                                        table.Rows.Add(row);
2,508✔
369
                                        return true;
2,508✔
370
                                case 142:
371
                                        var col = new TableEntity.Column();
1,824✔
372
                                        col.Width = this._reader.ValueAsDouble;
1,824✔
373
                                        table.Columns.Add(col);
1,824✔
374
                                        return true;
1,824✔
375
                                case 144:
376
                                        tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
456✔
377
                                        return true;
456✔
378
                                case 145:
379
                                        tmp.CurrentCell.Rotation = this._reader.ValueAsDouble;
9,348✔
380
                                        return true;
9,348✔
381
                                case 170:
382
                                        //Has data flag
383
                                        return true;
684✔
384
                                case 171:
385
                                        tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
9,348✔
386
                                        return true;
9,348✔
387
                                case 172:
388
                                        tmp.CurrentCell.FlagValue = this._reader.ValueAsInt;
9,348✔
389
                                        return true;
9,348✔
390
                                case 173:
391
                                        tmp.CurrentCell.MergedValue = this._reader.ValueAsInt;
9,348✔
392
                                        return true;
9,348✔
393
                                case 174:
394
                                        tmp.CurrentCell.Autofit = this._reader.ValueAsBool;
9,348✔
395
                                        return true;
9,348✔
396
                                case 175:
397
                                        tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
9,348✔
398
                                        return true;
9,348✔
399
                                case 176:
400
                                        tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
9,348✔
401
                                        return true;
9,348✔
402
                                case 178:
403
                                        tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
9,348✔
404
                                        return true;
9,348✔
405
                                case 179:
406
                                        //Unknown value
407
                                        return true;
456✔
408
                                case 301:
409
                                        var content = new TableEntity.CellContent();
6,232✔
410
                                        tmp.CurrentCell.Contents.Add(content);
6,232✔
411
                                        this.readCellValue(content);
6,232✔
412
                                        return true;
6,232✔
413
                                case 340:
414
                                        tmp.CurrentCellTemplate.BlockRecordHandle = this._reader.ValueAsHandle;
456✔
415
                                        return true;
456✔
416
                                default:
417
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
61,370✔
418
                                        {
59,774✔
419
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
59,774✔
420
                                        }
421
                                        return true;
1,596✔
422
                        }
423
                }
150,138✔
424

425
                private void readCellValue(TableEntity.CellContent content)
426
                {
6,232✔
427
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
6,232!
428
                        {
6,232✔
429
                                this._reader.ReadNext();
6,232✔
430
                        }
6,232✔
431
                        else
432
                        {
×
433
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
434
                        }
435

436
                        while (this._reader.Code != 304
40,736✔
437
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
40,736✔
438
                        {
34,504✔
439
                                switch (this._reader.Code)
34,504!
440
                                {
441
                                        case 1:
442
                                                content.Value.Text = this._reader.ValueAsString;
1,824✔
443
                                                break;
1,824✔
444
                                        case 2:
445
                                                content.Value.Text += this._reader.ValueAsString;
×
446
                                                break;
×
447
                                        case 11:
448
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
152✔
449
                                                break;
152✔
450
                                        case 21:
451
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
152✔
452
                                                break;
152✔
453
                                        case 31:
454
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
152✔
455
                                                break;
152✔
456
                                        case 302:
457
                                                //TODO: Fix this assignation to cell value
458
                                                content.Value.Value = this._reader.ValueAsString;
6,232✔
459
                                                break;
6,232✔
460
                                        case 90:
461
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
6,232✔
462
                                                break;
6,232✔
463
                                        case 91:
464
                                                content.Value.Value = this._reader.ValueAsInt;
152✔
465
                                                break;
152✔
466
                                        case 93:
467
                                                content.Value.Flags = this._reader.ValueAsInt;
6,232✔
468
                                                break;
6,232✔
469
                                        case 94:
470
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
6,232✔
471
                                                break;
6,232✔
472
                                        case 140:
473
                                                content.Value.Value = this._reader.ValueAsDouble;
608✔
474
                                                break;
608✔
475
                                        case 300:
476
                                                content.Value.Format = this._reader.ValueAsString;
6,232✔
477
                                                break;
6,232✔
478
                                        default:
479
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
304✔
480
                                                break;
304✔
481
                                }
482

483
                                this._reader.ReadNext();
34,504✔
484
                        }
34,504✔
485
                }
6,232✔
486

487
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
488
                {
320,366✔
489
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
320,366✔
490
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
320,366✔
491

492
                        switch (this._reader.Code)
320,366✔
493
                        {
494
                                //TODO: Implement multiline text def codes
495
                                case 1 or 3 when tmp.CadObject is MText mtext:
28,480✔
496
                                        mtext.Value += this._reader.ValueAsString;
10,874✔
497
                                        return true;
10,874✔
498
                                case 50 when tmp.CadObject is MText://Read only for MText
540✔
499
                                case 70:
500
                                case 74:
501
                                case 101:
502
                                        return true;
456✔
503
                                case 7:
504
                                        tmp.StyleName = this._reader.ValueAsString;
2,660✔
505
                                        return true;
2,660✔
506
                                default:
507
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
306,376✔
508
                        }
509
                }
320,366✔
510

511
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
512
                {
6,840✔
513
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,840✔
514

515
                        switch (this._reader.Code)
6,840✔
516
                        {
517
                                case 3:
518
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
684✔
519
                                        return true;
684✔
520
                                default:
521
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
6,156✔
522
                        }
523
                }
6,840✔
524

525
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
526
                {
76,532✔
527
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
76,532✔
528

529
                        switch (this._reader.Code)
76,532✔
530
                        {
531
                                case 2:
532
                                        tmp.BlockName = this._reader.ValueAsString;
2,926✔
533
                                        return true;
2,926✔
534
                                case 3:
535
                                        tmp.StyleName = this._reader.ValueAsString;
2,508✔
536
                                        return true;
2,508✔
537
                                case 50:
538
                                        var dim = new DimensionLinear();
266✔
539
                                        tmp.SetDimensionObject(dim);
266✔
540
                                        dim.Rotation = this._reader.ValueAsAngle;
266✔
541
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
266✔
542
                                        return true;
266✔
543
                                case 70:
544
                                        //Flags do not have set
545
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,926✔
546
                                        return true;
2,926✔
547
                                //Measurement - read only
548
                                case 42:
549
                                        return true;
2,508✔
550
                                //Undocumented codes
551
                                case 73:
552
                                case 74:
553
                                case 75:
554
                                case 90:
555
                                case 361:
556
                                        return true;
5,016✔
557
                                case 100:
558
                                        switch (this._reader.ValueAsString)
8,208✔
559
                                        {
560
                                                case DxfSubclassMarker.Dimension:
561
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,508✔
562
                                                case DxfSubclassMarker.AlignedDimension:
563
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,140✔
564
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,140✔
565
                                                        return true;
1,140✔
566
                                                case DxfSubclassMarker.DiametricDimension:
567
                                                        tmp.SetDimensionObject(new DimensionDiameter());
228✔
568
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
228✔
569
                                                        return true;
228✔
570
                                                case DxfSubclassMarker.Angular2LineDimension:
571
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
228✔
572
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
228✔
573
                                                        return true;
228✔
574
                                                case DxfSubclassMarker.Angular3PointDimension:
575
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
228✔
576
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
228✔
577
                                                        return true;
228✔
578
                                                case DxfSubclassMarker.RadialDimension:
579
                                                        tmp.SetDimensionObject(new DimensionRadius());
228✔
580
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
228✔
581
                                                        return true;
228✔
582
                                                case DxfSubclassMarker.OrdinateDimension:
583
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
456✔
584
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
456✔
585
                                                        return true;
456✔
586
                                                case DxfSubclassMarker.LinearDimension:
587
                                                        return true;
684✔
588
                                                default:
589
                                                        return false;
2,508✔
590
                                        }
591
                                default:
592
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
52,174✔
593
                        }
594
                }
76,532✔
595

596
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
597
                {
45,600✔
598
                        CadHatchTemplate tmp = template as CadHatchTemplate;
45,600✔
599
                        Hatch hatch = tmp.CadObject;
45,600✔
600

601
                        bool isFirstSeed = true;
45,600✔
602
                        XY seedPoint = new XY();
45,600✔
603

604
                        switch (this._reader.Code)
45,600!
605
                        {
606
                                case 2:
607
                                        hatch.Pattern.Name = this._reader.ValueAsString;
1,824✔
608
                                        return true;
1,824✔
609
                                case 10:
610
                                        seedPoint.X = this._reader.ValueAsDouble;
2,964✔
611
                                        return true;
2,964✔
612
                                case 20:
613
                                        if (!isFirstSeed)
3,648!
614
                                        {
×
615
                                                seedPoint.Y = this._reader.ValueAsDouble;
×
616
                                                hatch.SeedPoints.Add(seedPoint);
×
617
                                        }
×
618
                                        return true;
3,648✔
619
                                case 30:
620
                                        hatch.Elevation = this._reader.ValueAsDouble;
1,824✔
621
                                        isFirstSeed = false;
1,824✔
622
                                        return true;
1,824✔
623
                                case 53:
624
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
625
                                        return true;
×
626
                                //TODO: Check hatch undocumented codes
627
                                case 90:
628
                                        return true;
×
629
                                //Information about the hatch pattern
630
                                case 75:
631
                                        return true;
×
632
                                //Number of pattern definition lines
633
                                case 78:
634
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,368✔
635
                                        return true;
1,368✔
636
                                //Number of boundary paths (loops)
637
                                case 91:
638
                                        this.readLoops(tmp, this._reader.ValueAsInt);
1,824✔
639
                                        return true;
1,824✔
640
                                //Number of seed points
641
                                case 98:
642
                                        return true;
456✔
643
                                case 450:
644
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
380✔
645
                                        return true;
380✔
646
                                case 451:
647
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
380✔
648
                                        return true;
380✔
649
                                case 452:
650
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
380✔
651
                                        return true;
380✔
652
                                case 453:
653
                                        //Number of colors
654
                                        return true;
380✔
655
                                case 460:
656
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
380✔
657
                                        return true;
380✔
658
                                case 461:
659
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
380✔
660
                                        return true;
380✔
661
                                case 462:
662
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
380✔
663
                                        return true;
380✔
664
                                case 463:
665
                                        GradientColor gradient = new GradientColor();
760✔
666
                                        gradient.Value = this._reader.ValueAsDouble;
760✔
667
                                        hatch.GradientColor.Colors.Add(gradient);
760✔
668
                                        return true;
760✔
669
                                case 63:
670
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
760✔
671
                                        if (colorByIndex != null)
760✔
672
                                        {
760✔
673
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
760✔
674
                                        }
760✔
675
                                        return true;
760✔
676
                                case 421:
677
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
760✔
678
                                        if (colorByRgb != null)
760✔
679
                                        {
760✔
680
                                                //TODO: Hatch assign color by true color
681
                                                //TODO: Is always duplicated by 63, is it needed??
682
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
683
                                        }
760✔
684
                                        return true;
760✔
685
                                case 470:
686
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
380✔
687
                                        return true;
380✔
688
                                default:
689
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
26,372✔
690
                        }
691
                }
45,600✔
692

693
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
694
                {
65,246✔
695
                        CadInsertTemplate tmp = template as CadInsertTemplate;
65,246✔
696

697
                        switch (this._reader.Code)
65,246✔
698
                        {
699
                                case 2:
700
                                        tmp.BlockName = this._reader.ValueAsString;
6,060✔
701
                                        return true;
6,060✔
702
                                case 100:
703
                                        //AcDbEntity
704
                                        //AcDbBlockReference
705
                                        //AcDbMInsertBlock
706
                                        return true;
6,192✔
707
                                case 66:
708
                                        return true;
532✔
709
                                default:
710
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
52,462✔
711
                        }
712
                }
65,246✔
713

714
                private CadEntityTemplate readPolyline()
715
                {
11,664✔
716
                        CadPolyLineTemplate template = null;
11,664✔
717

718
                        if (this._builder.Version == ACadVersion.Unknown)
11,664!
719
                        {
×
720
                                var polyline = new Polyline2D();
×
721
                                template = new CadPolyLineTemplate(polyline);
×
722
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
×
723

724
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
×
725
                                {
×
726
                                        Vertex2D v = new Vertex2D();
×
727
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
×
728
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
×
729

730
                                        if (vertexTemplate.Vertex.Handle == 0)
×
731
                                        {
×
732
                                                template.PolyLine.Vertices.Add(vertexTemplate.Vertex);
×
733
                                        }
×
734
                                        else
735
                                        {
×
736
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
737
                                                this._builder.AddTemplate(vertexTemplate);
×
738
                                        }
×
739
                                }
×
740

741
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
×
742
                                {
×
743
                                        var seqend = new Seqend();
×
744
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
×
745
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
×
746

747
                                        template.PolyLine.Vertices.Seqend = seqend;
×
748
                                }
×
749
                        }
×
750
                        else
751
                        {
11,664✔
752
                                template = new CadPolyLineTemplate();
11,664✔
753
                                this.readEntityCodes<Entity>(template, this.readPolyline);
11,664✔
754
                        }
11,664✔
755

756
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
11,664✔
757
                        {
11,208✔
758
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
11,208✔
759
                                return null;
11,208✔
760
                        }
761

762
                        return template;
456✔
763
                }
11,664✔
764

765
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
766
                {
83,772✔
767
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
83,772✔
768

769
                        switch (this._reader.Code)
83,772✔
770
                        {
771
                                //DXF: always 0
772
                                //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)
773
                                case 10:
774
                                case 20:
775
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
776
                                case 66:
777
                                //Polygon mesh M vertex count (optional; default = 0)
778
                                case 71:
779
                                //Polygon mesh N vertex count(optional; default = 0)
780
                                case 72:
781
                                //Smooth surface M density(optional; default = 0)
782
                                case 73:
783
                                //Smooth surface N density (optional; default = 0)
784
                                case 74:
785
                                        return true;
35,524✔
786
                                case 100:
787
                                        switch (this._reader.ValueAsString)
912!
788
                                        {
789
                                                case DxfSubclassMarker.Polyline:
790
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
791
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
792
                                                        return true;
×
793
                                                case DxfSubclassMarker.Polyline3d:
794
                                                        tmp.SetPolyLineObject(new Polyline3D());
228✔
795
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
228✔
796
                                                        return true;
228✔
797
                                                case DxfSubclassMarker.PolyfaceMesh:
798
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
228✔
799
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
228✔
800
                                                        return true;
228✔
801
                                                default:
802
                                                        return false;
456✔
803
                                        }
804
                                default:
805
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
47,336✔
806
                        }
807
                }
83,772✔
808

809
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
810
                {
5,700✔
811
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,700✔
812

813
                        switch (this._reader.Code)
5,700✔
814
                        {
815
                                case 3:
816
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
228✔
817
                                        return true;
228✔
818
                                case 10:
819
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
912✔
820
                                        return true;
912✔
821
                                case 20:
822
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
912✔
823
                                        y.Y = this._reader.ValueAsDouble;
912✔
824
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
912✔
825
                                        return true;
912✔
826
                                case 30:
827
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
912✔
828
                                        z.Z = this._reader.ValueAsDouble;
912✔
829
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
912✔
830
                                        return true;
912✔
831
                                case 340:
832
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
228✔
833
                                        return true;
228✔
834
                                //Hook line flag - read only
835
                                case 75:
836
                                //Vertices count
837
                                case 76:
838
                                        return true;
456✔
839
                                default:
840
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,052✔
841
                        }
842
                }
5,700✔
843

844
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
845
                {
90,012✔
846
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
90,012✔
847

848
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
90,012✔
849

850
                        switch (this._reader.Code)
90,012!
851
                        {
852
                                case 10:
853
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
21,324✔
854
                                        return true;
21,324✔
855
                                case 20:
856
                                        if (last is not null)
21,324✔
857
                                        {
21,324✔
858
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
21,324✔
859
                                        }
21,324✔
860
                                        return true;
21,324✔
861
                                case 40:
862
                                        if (last is not null)
2,280✔
863
                                        {
2,280✔
864
                                                last.StartWidth = this._reader.ValueAsDouble;
2,280✔
865
                                        }
2,280✔
866
                                        return true;
2,280✔
867
                                case 41:
868
                                        if (last is not null)
2,280✔
869
                                        {
2,280✔
870
                                                last.EndWidth = this._reader.ValueAsDouble;
2,280✔
871
                                        }
2,280✔
872
                                        return true;
2,280✔
873
                                case 42:
874
                                        if (last is not null)
3,120✔
875
                                        {
3,120✔
876
                                                last.Bulge = this._reader.ValueAsDouble;
3,120✔
877
                                        }
3,120✔
878
                                        return true;
3,120✔
879
                                case 50:
880
                                        if (last is not null)
×
881
                                        {
×
882
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
883
                                        }
×
884
                                        return true;
×
885
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
886
                                case 66:
887
                                //Vertex count
888
                                case 90:
889
                                        return true;
4,764✔
890
                                case 91:
891
                                        if (last is not null)
×
892
                                        {
×
893
                                                last.Id = this._reader.ValueAsInt;
×
894
                                        }
×
895
                                        return true;
×
896
                                default:
897
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,920✔
898
                        }
899
                }
90,012✔
900

901
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
902
                {
40,128✔
903
                        CadMeshTemplate tmp = template as CadMeshTemplate;
40,128✔
904

905
                        switch (this._reader.Code)
40,128✔
906
                        {
907
                                case 100:
908
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
912✔
909
                                        {
456✔
910
                                                tmp.SubclassMarker = true;
456✔
911
                                        }
456✔
912
                                        return true;
912✔
913
                                //Count of sub-entity which property has been overridden
914
                                case 90:
915
                                        //TODO: process further entities
916
                                        return true;
456✔
917
                                case 92:
918
                                        if (!tmp.SubclassMarker)
684✔
919
                                        {
228✔
920
                                                return false;
228✔
921
                                        }
922

923
                                        int nvertices = this._reader.ValueAsInt;
456✔
924
                                        for (int i = 0; i < nvertices; i++)
58,368✔
925
                                        {
28,728✔
926
                                                this._reader.ReadNext();
28,728✔
927
                                                double x = this._reader.ValueAsDouble;
28,728✔
928
                                                this._reader.ReadNext();
28,728✔
929
                                                double y = this._reader.ValueAsDouble;
28,728✔
930
                                                this._reader.ReadNext();
28,728✔
931
                                                double z = this._reader.ValueAsDouble;
28,728✔
932
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
28,728✔
933
                                        }
28,728✔
934
                                        return true;
456✔
935
                                case 93:
936
                                        int size = this._reader.ValueAsInt;
456✔
937
                                        this._reader.ReadNext();
456✔
938

939
                                        int indexes = 0;
456✔
940
                                        for (int i = 0; i < size; i += indexes + 1)
62,928✔
941
                                        {
31,008✔
942
                                                indexes = this._reader.ValueAsInt;
31,008✔
943
                                                this._reader.ReadNext();
31,008✔
944

945
                                                int[] face = new int[indexes];
31,008✔
946
                                                for (int j = 0; j < indexes; j++)
299,136✔
947
                                                {
118,560✔
948
                                                        face[j] = this._reader.ValueAsInt;
118,560✔
949

950
                                                        if ((i + j + 2) < size)
118,560✔
951
                                                        {
118,104✔
952
                                                                this._reader.ReadNext();
118,104✔
953
                                                        }
118,104✔
954
                                                }
118,560✔
955

956
                                                tmp.CadObject.Faces.Add(face);
31,008✔
957
                                        }
31,008✔
958

959
                                        Debug.Assert(this._reader.Code == 90);
456✔
960

961
                                        return true;
456✔
962
                                case 94:
963
                                        int numEdges = this._reader.ValueAsInt;
456✔
964
                                        this._reader.ReadNext();
456✔
965
                                        for (int i = 0; i < numEdges; i++)
119,472✔
966
                                        {
59,280✔
967
                                                Mesh.Edge edge = new Mesh.Edge();
59,280✔
968

969
                                                edge.Start = this._reader.ValueAsInt;
59,280✔
970
                                                this._reader.ReadNext();
59,280✔
971
                                                edge.End = this._reader.ValueAsInt;
59,280✔
972

973
                                                if (i < numEdges - 1)
59,280✔
974
                                                {
58,824✔
975
                                                        this._reader.ReadNext();
58,824✔
976
                                                }
58,824✔
977

978
                                                tmp.CadObject.Edges.Add(edge);
59,280✔
979
                                        }
59,280✔
980

981
                                        Debug.Assert(this._reader.Code == 90);
456✔
982

983
                                        return true;
456✔
984
                                case 95:
985
                                        this._reader.ReadNext();
456✔
986
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
119,472✔
987
                                        {
59,280✔
988
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
59,280✔
989
                                                edge.Crease = this._reader.ValueAsDouble;
59,280✔
990

991
                                                tmp.CadObject.Edges[i] = edge;
59,280✔
992

993
                                                if (i < tmp.CadObject.Edges.Count - 1)
59,280✔
994
                                                {
58,824✔
995
                                                        this._reader.ReadNext();
58,824✔
996
                                                }
58,824✔
997
                                        }
59,280✔
998

999
                                        Debug.Assert(this._reader.Code == 140);
456✔
1000

1001
                                        return true;
456✔
1002
                                default:
1003
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
36,708✔
1004
                        }
1005
                }
40,128✔
1006

1007
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1008
                {
59,280✔
1009
                        CadMLineTemplate tmp = template as CadMLineTemplate;
59,280✔
1010

1011
                        switch (this._reader.Code)
59,280✔
1012
                        {
1013
                                // 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.
1014
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1015
                                case 2:
1016
                                        tmp.MLineStyleName = this._reader.ValueAsString;
684✔
1017
                                        return true;
684✔
1018
                                case 72:
1019
                                        tmp.NVertex = this._reader.ValueAsInt;
684✔
1020
                                        return true;
684✔
1021
                                case 73:
1022
                                        tmp.NElements = this._reader.ValueAsInt;
684✔
1023
                                        return true;
684✔
1024
                                case 340:
1025
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
684✔
1026
                                        return true;
684✔
1027
                                default:
1028
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
56,544✔
1029
                                        {
9,576✔
1030
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
9,576✔
1031
                                        }
1032
                                        return true;
46,968✔
1033
                        }
1034
                }
59,280✔
1035

1036
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1037
                {
2,546✔
1038
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,546✔
1039

1040
                        switch (this._reader.Code)
2,546✔
1041
                        {
1042
                                case 2:
1043
                                        tmp.ShapeFileName = this._reader.ValueAsString;
266✔
1044
                                        return true;
266✔
1045
                                default:
1046
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,280✔
1047
                        }
1048
                }
2,546✔
1049

1050
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1051
                {
15,960✔
1052
                        CadSplineTemplate tmp = template as CadSplineTemplate;
15,960✔
1053

1054
                        XYZ controlPoint;
1055
                        XYZ fitPoint;
1056

1057
                        switch (this._reader.Code)
15,960!
1058
                        {
1059
                                case 10:
1060
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,824✔
1061
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,824✔
1062
                                        return true;
1,824✔
1063
                                case 20:
1064
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1065
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,824✔
1066
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1067
                                        return true;
1,824✔
1068
                                case 30:
1069
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1070
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,824✔
1071
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1072
                                        return true;
1,824✔
1073
                                case 11:
UNCOV
1074
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
UNCOV
1075
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1076
                                        return true;
×
1077
                                case 21:
UNCOV
1078
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
UNCOV
1079
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
UNCOV
1080
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
UNCOV
1081
                                        return true;
×
1082
                                case 31:
UNCOV
1083
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
UNCOV
1084
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
UNCOV
1085
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
UNCOV
1086
                                        return true;
×
1087
                                case 40:
1088
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,648✔
1089
                                        return true;
3,648✔
1090
                                case 41:
UNCOV
1091
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
UNCOV
1092
                                        return true;
×
1093
                                case 72:
1094
                                case 73:
1095
                                case 74:
1096
                                        return true;
1,368✔
1097
                                default:
1098
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
5,472✔
1099
                        }
1100
                }
15,960✔
1101

1102
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1103
                        where T : PdfUnderlayDefinition
1104
                {
3,610✔
1105
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,610✔
1106

1107
                        switch (this._reader.Code)
3,610✔
1108
                        {
1109
                                case 340:
1110
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
228✔
1111
                                        return true;
228✔
1112
                                default:
1113
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,382✔
1114
                        }
1115
                }
3,610✔
1116

1117
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1118
                {
265,608✔
1119
                        CadVertexTemplate tmp = template as CadVertexTemplate;
265,608✔
1120

1121
                        switch (this._reader.Code)
265,608✔
1122
                        {
1123
                                //Polyface mesh vertex index
1124
                                case 71:
1125
                                case 72:
1126
                                case 73:
1127
                                case 74:
1128
                                        return true;
1,862✔
1129
                                case 100:
1130
                                        switch (this._reader.ValueAsString)
7,752!
1131
                                        {
1132
                                                case DxfSubclassMarker.Vertex:
1133
                                                        return true;
2,280✔
1134
                                                case DxfSubclassMarker.PolylineVertex:
UNCOV
1135
                                                        tmp.SetVertexObject(new Vertex2D());
×
UNCOV
1136
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
UNCOV
1137
                                                        return true;
×
1138
                                                case DxfSubclassMarker.Polyline3dVertex:
1139
                                                        tmp.SetVertexObject(new Vertex3D());
1,140✔
1140
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,140✔
1141
                                                        return true;
1,140✔
1142
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1143
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,140✔
1144
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,140✔
1145
                                                        return true;
1,140✔
1146
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1147
                                                        tmp.SetVertexObject(new VertexFaceRecord());
456✔
1148
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
456✔
1149
                                                        return true;
456✔
1150
                                                default:
1151
                                                        return false;
2,736✔
1152
                                        }
1153
                                default:
1154
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
255,994✔
1155
                        }
1156
                }
265,608✔
1157

1158
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1159
                {
76,296✔
1160
                        CadViewportTemplate tmp = template as CadViewportTemplate;
76,296✔
1161

1162
                        switch (this._reader.Code)
76,296!
1163
                        {
1164
                                //Undocumented
1165
                                case 67:
1166
                                case 68:
1167
                                        return true;
2,792✔
1168
                                case 69:
1169
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,396✔
1170
                                        return true;
1,396✔
1171
                                case 331:
UNCOV
1172
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
UNCOV
1173
                                        return true;
×
1174
                                case 348:
1175
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
880✔
1176
                                        return true;
880✔
1177
                                default:
1178
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
71,228✔
1179
                        }
1180
                }
76,296✔
1181

1182
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1183
                {
1,209,456✔
1184
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
1,209,456✔
1185

1186
                        switch (this._reader.Code)
1,209,456✔
1187
                        {
1188
                                default:
1189
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
1,209,456✔
1190
                        }
1191
                }
1,209,456✔
1192

1193
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1194
                {
38,365✔
1195
                        List<ExtendedDataRecord> records = new();
38,365✔
1196
                        edata.Add(this._reader.ValueAsString, records);
38,365✔
1197

1198
                        this._reader.ReadNext();
38,365✔
1199

1200
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
302,556✔
1201
                        {
276,319✔
1202
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
276,319✔
1203
                                {
12,128✔
1204
                                        this.readExtendedData(edata);
12,128✔
1205
                                        break;
12,128✔
1206
                                }
1207

1208
                                ExtendedDataRecord record = null;
264,191✔
1209
                                double x = 0;
264,191✔
1210
                                double y = 0;
264,191✔
1211
                                double z = 0;
264,191✔
1212

1213
                                switch (this._reader.DxfCode)
264,191✔
1214
                                {
1215
                                        case DxfCode.ExtendedDataAsciiString:
1216
                                        case DxfCode.ExtendedDataRegAppName:
1217
                                                record = new ExtendedDataString(this._reader.ValueAsString);
28,708✔
1218
                                                break;
28,708✔
1219
                                        case DxfCode.ExtendedDataControlString:
1220
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
15,056✔
1221
                                                break;
15,056✔
1222
                                        case DxfCode.ExtendedDataLayerName:
1223
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
266✔
1224
                                                {
252✔
1225
                                                        record = new ExtendedDataLayer(layer.Handle);
252✔
1226
                                                }
252✔
1227
                                                else
1228
                                                {
14✔
1229
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1230
                                                }
14✔
1231
                                                break;
266✔
1232
                                        case DxfCode.ExtendedDataBinaryChunk:
1233
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
76✔
1234
                                                break;
76✔
1235
                                        case DxfCode.ExtendedDataHandle:
1236
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,808✔
1237
                                                break;
2,808✔
1238
                                        case DxfCode.ExtendedDataXCoordinate:
1239
                                                x = this._reader.ValueAsDouble;
2,836✔
1240
                                                this._reader.ReadNext();
2,836✔
1241
                                                y = this._reader.ValueAsDouble;
2,836✔
1242
                                                this._reader.ReadNext();
2,836✔
1243
                                                z = this._reader.ValueAsDouble;
2,836✔
1244

1245
                                                record = new ExtendedDataCoordinate(
2,836✔
1246
                                                        new XYZ(
2,836✔
1247
                                                                x,
2,836✔
1248
                                                                y,
2,836✔
1249
                                                                z)
2,836✔
1250
                                                        );
2,836✔
1251
                                                break;
2,836✔
1252
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1253
                                                x = this._reader.ValueAsDouble;
1,368✔
1254
                                                this._reader.ReadNext();
1,368✔
1255
                                                y = this._reader.ValueAsDouble;
1,368✔
1256
                                                this._reader.ReadNext();
1,368✔
1257
                                                z = this._reader.ValueAsDouble;
1,368✔
1258

1259
                                                record = new ExtendedDataWorldCoordinate(
1,368✔
1260
                                                        new XYZ(
1,368✔
1261
                                                                x,
1,368✔
1262
                                                                y,
1,368✔
1263
                                                                z)
1,368✔
1264
                                                        );
1,368✔
1265
                                                break;
1,368✔
1266
                                        case DxfCode.ExtendedDataWorldXDisp:
1267
                                                x = this._reader.ValueAsDouble;
266✔
1268
                                                this._reader.ReadNext();
266✔
1269
                                                y = this._reader.ValueAsDouble;
266✔
1270
                                                this._reader.ReadNext();
266✔
1271
                                                z = this._reader.ValueAsDouble;
266✔
1272

1273
                                                record = new ExtendedDataDisplacement(
266✔
1274
                                                        new XYZ(
266✔
1275
                                                                x,
266✔
1276
                                                                y,
266✔
1277
                                                                z)
266✔
1278
                                                        );
266✔
1279
                                                break;
266✔
1280
                                        case DxfCode.ExtendedDataWorldXDir:
1281
                                                x = this._reader.ValueAsDouble;
266✔
1282
                                                this._reader.ReadNext();
266✔
1283
                                                y = this._reader.ValueAsDouble;
266✔
1284
                                                this._reader.ReadNext();
266✔
1285
                                                z = this._reader.ValueAsDouble;
266✔
1286

1287
                                                record = new ExtendedDataDirection(
266✔
1288
                                                        new XYZ(
266✔
1289
                                                                x,
266✔
1290
                                                                y,
266✔
1291
                                                                z)
266✔
1292
                                                        );
266✔
1293
                                                break;
266✔
1294
                                        case DxfCode.ExtendedDataReal:
1295
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
133,506✔
1296
                                                break;
133,506✔
1297
                                        case DxfCode.ExtendedDataDist:
1298
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
266✔
1299
                                                break;
266✔
1300
                                        case DxfCode.ExtendedDataScale:
1301
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
266✔
1302
                                                break;
266✔
1303
                                        case DxfCode.ExtendedDataInteger16:
1304
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
67,821✔
1305
                                                break;
67,821✔
1306
                                        case DxfCode.ExtendedDataInteger32:
1307
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
8,250✔
1308
                                                break;
8,250✔
1309
                                        default:
1310
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,432✔
1311
                                                break;
2,432✔
1312
                                }
1313

1314
                                if (record != null)
264,191✔
1315
                                {
261,745✔
1316
                                        records.Add(record);
261,745✔
1317
                                }
261,745✔
1318

1319
                                this._reader.ReadNext();
264,191✔
1320
                        }
264,191✔
1321
                }
38,365✔
1322

1323
                private void readPattern(HatchPattern pattern, int nlines)
1324
                {
1,368✔
1325
                        //Jump 78 code
1326
                        this._reader.ReadNext();
1,368✔
1327

1328
                        for (int i = 0; i < nlines; i++)
207,480✔
1329
                        {
102,372✔
1330
                                HatchPattern.Line line = new HatchPattern.Line();
102,372✔
1331
                                XY basePoint = new XY();
102,372✔
1332
                                XY offset = new XY();
102,372✔
1333

1334
                                bool end = false;
102,372✔
1335
                                HashSet<int> codes = new();
102,372✔
1336

1337
                                while (!end)
717,972✔
1338
                                {
716,604✔
1339
                                        if (codes.Contains(this._reader.Code))
716,604✔
1340
                                        {
101,004✔
1341
                                                break;
101,004✔
1342
                                        }
1343
                                        else
1344
                                        {
615,600✔
1345
                                                codes.Add(this._reader.Code);
615,600✔
1346
                                        }
615,600✔
1347

1348
                                        switch (this._reader.Code)
615,600!
1349
                                        {
1350
                                                case 53:
1351
                                                        line.Angle = this._reader.ValueAsAngle;
102,372✔
1352
                                                        break;
102,372✔
1353
                                                case 43:
1354
                                                        basePoint.X = this._reader.ValueAsDouble;
102,372✔
1355
                                                        break;
102,372✔
1356
                                                case 44:
1357
                                                        basePoint.Y = this._reader.ValueAsDouble;
102,372✔
1358
                                                        line.BasePoint = basePoint;
102,372✔
1359
                                                        break;
102,372✔
1360
                                                case 45:
1361
                                                        offset.X = this._reader.ValueAsDouble;
102,372✔
1362
                                                        line.Offset = offset;
102,372✔
1363
                                                        break;
102,372✔
1364
                                                case 46:
1365
                                                        offset.Y = this._reader.ValueAsDouble;
102,372✔
1366
                                                        line.Offset = offset;
102,372✔
1367
                                                        break;
102,372✔
1368
                                                //Number of dash length items
1369
                                                case 79:
1370
                                                        int ndash = this._reader.ValueAsInt;
102,372✔
1371
                                                        for (int j = 0; j < ndash; j++)
613,320✔
1372
                                                        {
204,288✔
1373
                                                                this._reader.ReadNext();
204,288✔
1374
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
204,288✔
1375
                                                        }
204,288✔
1376
                                                        break;
102,372✔
1377
                                                case 49:
UNCOV
1378
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
UNCOV
1379
                                                        break;
×
1380
                                                default:
1381
                                                        end = true;
1,368✔
1382
                                                        break;
1,368✔
1383
                                        }
1384
                                        this._reader.ReadNext();
615,600✔
1385
                                }
615,600✔
1386

1387
                                pattern.Lines.Add(line);
102,372✔
1388
                        }
102,372✔
1389
                }
1,368✔
1390

1391
                private void readLoops(CadHatchTemplate template, int count)
1392
                {
1,824✔
1393
                        if (this._reader.Code == 91)
1,824✔
1394
                                this._reader.ReadNext();
1,824✔
1395

1396
                        for (int i = 0; i < count; i++)
7,296✔
1397
                        {
1,824✔
1398
                                if (this._reader.Code != 92)
1,824!
UNCOV
1399
                                {
×
UNCOV
1400
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
UNCOV
1401
                                        break;
×
1402
                                }
1403

1404
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,824✔
1405
                                if (path != null)
1,824✔
1406
                                        template.PathTempaltes.Add(path);
1,824✔
1407
                        }
1,824✔
1408
                }
1,824✔
1409

1410
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1411
                {
1,824✔
1412
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,824✔
1413
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,824✔
1414
                        template.Path.Flags = flags;
1,824✔
1415

1416
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,824✔
1417
                        {
684✔
1418
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
684✔
1419
                                template.Path.Edges.Add(pl);
684✔
1420
                        }
684✔
1421
                        else
1422
                        {
1,140✔
1423
                                this._reader.ReadNext();
1,140✔
1424

1425
                                if (this._reader.Code != 93)
1,140!
UNCOV
1426
                                {
×
UNCOV
1427
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
UNCOV
1428
                                        return null;
×
1429
                                }
1430

1431
                                int edges = this._reader.ValueAsInt;
1,140✔
1432
                                this._reader.ReadNext();
1,140✔
1433

1434
                                for (int i = 0; i < edges; i++)
11,400✔
1435
                                {
4,560✔
1436
                                        var edge = this.readEdge();
4,560✔
1437
                                        if (edge != null)
4,560✔
1438
                                                template.Path.Edges.Add(edge);
4,560✔
1439
                                }
4,560✔
1440
                        }
1,140✔
1441

1442
                        bool end = false;
1,824✔
1443
                        while (!end)
7,068✔
1444
                        {
5,244✔
1445
                                switch (this._reader.Code)
5,244✔
1446
                                {
1447
                                        //Number of source boundary objects
1448
                                        case 97:
1449
                                                break;
1,824✔
1450
                                        case 330:
1451
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,596✔
1452
                                                break;
1,596✔
1453
                                        default:
1454
                                                end = true;
1,824✔
1455
                                                continue;
1,824✔
1456
                                }
1457

1458
                                this._reader.ReadNext();
3,420✔
1459
                        }
3,420✔
1460

1461
                        return template;
1,824✔
1462
                }
1,824✔
1463

1464
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1465
                {
684✔
1466
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
684✔
1467

1468
                        this._reader.ReadNext();
684✔
1469

1470
                        if (this._reader.Code != 72)
684!
UNCOV
1471
                        {
×
UNCOV
1472
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
UNCOV
1473
                                return null;
×
1474
                        }
1475

1476
                        //72
1477
                        bool hasBulge = this._reader.ValueAsBool;
684✔
1478
                        this._reader.ReadNext();
684✔
1479

1480
                        //73
1481
                        bool isClosed = this._reader.ValueAsBool;
684✔
1482
                        this._reader.ReadNext();
684✔
1483

1484
                        //93
1485
                        int nvertices = this._reader.ValueAsInt;
684✔
1486
                        this._reader.ReadNext();
684✔
1487

1488
                        for (int i = 0; i < nvertices; i++)
6,840✔
1489
                        {
2,736✔
1490
                                double bulge = 0.0;
2,736✔
1491

1492
                                //10
1493
                                double x = this._reader.ValueAsDouble;
2,736✔
1494
                                this._reader.ReadNext();
2,736✔
1495
                                //20
1496
                                double y = this._reader.ValueAsDouble;
2,736✔
1497
                                this._reader.ReadNext();
2,736✔
1498

1499
                                if (hasBulge)
2,736!
1500
                                {
×
1501
                                        //42
1502
                                        bulge = this._reader.ValueAsDouble;
×
UNCOV
1503
                                        this._reader.ReadNext();
×
UNCOV
1504
                                }
×
1505

1506
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,736✔
1507
                        }
2,736✔
1508

1509
                        return boundary;
684✔
1510
                }
684✔
1511

1512
                private Hatch.BoundaryPath.Edge readEdge()
1513
                {
4,560✔
1514
                        if (this._reader.Code != 72)
4,560!
UNCOV
1515
                        {
×
UNCOV
1516
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
UNCOV
1517
                                return null;
×
1518
                        }
1519

1520
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,560✔
1521
                        this._reader.ReadNext();
4,560✔
1522

1523
                        switch (type)
4,560!
1524
                        {
1525
                                case Hatch.BoundaryPath.EdgeType.Line:
1526
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,560✔
1527
                                        while (true)
22,800✔
1528
                                        {
22,800✔
1529
                                                switch (this._reader.Code)
22,800✔
1530
                                                {
1531
                                                        case 10:
1532
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,560✔
1533
                                                                break;
4,560✔
1534
                                                        case 20:
1535
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,560✔
1536
                                                                break;
4,560✔
1537
                                                        case 11:
1538
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,560✔
1539
                                                                break;
4,560✔
1540
                                                        case 21:
1541
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,560✔
1542
                                                                break;
4,560✔
1543
                                                        default:
1544
                                                                return line;
4,560✔
1545
                                                }
1546

1547
                                                this._reader.ReadNext();
18,240✔
1548
                                        }
18,240✔
1549
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1550
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1551
                                        while (true)
×
UNCOV
1552
                                        {
×
1553
                                                switch (this._reader.Code)
×
1554
                                                {
1555
                                                        case 10:
1556
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1557
                                                                break;
×
1558
                                                        case 20:
1559
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
UNCOV
1560
                                                                break;
×
1561
                                                        case 40:
1562
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1563
                                                                break;
×
1564
                                                        case 50:
1565
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1566
                                                                break;
×
1567
                                                        case 51:
1568
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
UNCOV
1569
                                                                break;
×
1570
                                                        case 73:
1571
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1572
                                                                break;
×
1573
                                                        default:
1574
                                                                return arc;
×
1575
                                                }
1576

1577
                                                this._reader.ReadNext();
×
1578
                                        }
×
1579
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1580
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1581
                                        while (true)
×
UNCOV
1582
                                        {
×
1583
                                                switch (this._reader.Code)
×
1584
                                                {
1585
                                                        case 10:
1586
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1587
                                                                break;
×
1588
                                                        case 20:
1589
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1590
                                                                break;
×
1591
                                                        case 11:
1592
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1593
                                                                break;
×
1594
                                                        case 21:
1595
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
UNCOV
1596
                                                                break;
×
1597
                                                        case 40:
1598
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1599
                                                                break;
×
1600
                                                        case 50:
1601
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1602
                                                                break;
×
1603
                                                        case 51:
1604
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
UNCOV
1605
                                                                break;
×
1606
                                                        case 73:
1607
                                                                ellipse.IsCounterclockwise = this._reader.ValueAsBool;
×
UNCOV
1608
                                                                break;
×
1609
                                                        default:
1610
                                                                return ellipse;
×
1611
                                                }
1612

UNCOV
1613
                                                this._reader.ReadNext();
×
1614
                                        }
×
1615
                                case Hatch.BoundaryPath.EdgeType.Spline:
UNCOV
1616
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1617
                                        int nKnots = 0;
×
1618
                                        int nCtrlPoints = 0;
×
1619
                                        int nFitPoints = 0;
×
1620

1621
                                        XYZ controlPoint = new XYZ();
×
1622
                                        XY fitPoint = new XY();
×
1623

1624
                                        while (true)
×
1625
                                        {
×
1626
                                                switch (this._reader.Code)
×
1627
                                                {
1628
                                                        case 10:
1629
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1630
                                                                break;
×
1631
                                                        case 20:
1632
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1633
                                                                spline.ControlPoints.Add(controlPoint);
×
UNCOV
1634
                                                                break;
×
1635
                                                        case 11:
1636
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
UNCOV
1637
                                                                break;
×
1638
                                                        case 21:
1639
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
UNCOV
1640
                                                                spline.FitPoints.Add(fitPoint);
×
1641
                                                                break;
×
1642
                                                        case 42:
UNCOV
1643
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
1644
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1645
                                                                break;
×
1646
                                                        case 12:
1647
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1648
                                                                break;
×
1649
                                                        case 22:
1650
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
1651
                                                                break;
×
1652
                                                        case 13:
1653
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1654
                                                                break;
×
1655
                                                        case 23:
1656
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1657
                                                                break;
×
1658
                                                        case 94:
1659
                                                                spline.Degree = this._reader.ValueAsInt;
×
1660
                                                                break;
×
1661
                                                        case 73:
1662
                                                                spline.Rational = this._reader.ValueAsBool;
×
1663
                                                                break;
×
1664
                                                        case 74:
1665
                                                                spline.Periodic = this._reader.ValueAsBool;
×
UNCOV
1666
                                                                break;
×
1667
                                                        case 95:
1668
                                                                nKnots = this._reader.ValueAsInt;
×
1669
                                                                break;
×
1670
                                                        case 96:
UNCOV
1671
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1672
                                                                break;
×
1673
                                                        case 97:
UNCOV
1674
                                                                nFitPoints = this._reader.ValueAsInt;
×
UNCOV
1675
                                                                break;
×
1676
                                                        case 40:
UNCOV
1677
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
UNCOV
1678
                                                                break;
×
1679
                                                        default:
UNCOV
1680
                                                                return spline;
×
1681
                                                }
1682

UNCOV
1683
                                                this._reader.ReadNext();
×
UNCOV
1684
                                        }
×
1685
                        }
1686

UNCOV
1687
                        return null;
×
1688
                }
4,560✔
1689

1690
                private void readDefinedGroups(CadTemplate template)
1691
                {
62,871✔
1692
                        this.readDefinedGroups(out ulong? xdict, out List<ulong> reactorsHandles);
62,871✔
1693

1694
                        template.XDictHandle = xdict;
62,871✔
1695
                        template.ReactorsHandles = reactorsHandles;
62,871✔
1696
                }
62,871✔
1697

1698
                private void readDefinedGroups(out ulong? xdictHandle, out List<ulong> reactors)
1699
                {
63,101✔
1700
                        xdictHandle = null;
63,101✔
1701
                        reactors = new List<ulong>();
63,101✔
1702

1703
                        switch (this._reader.ValueAsString)
63,101✔
1704
                        {
1705
                                case DxfFileToken.DictionaryToken:
1706
                                        this._reader.ReadNext();
12,097✔
1707
                                        xdictHandle = this._reader.ValueAsHandle;
12,097✔
1708
                                        this._reader.ReadNext();
12,097✔
1709
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
12,097✔
1710
                                        return;
12,097✔
1711
                                case DxfFileToken.ReactorsToken:
1712
                                        reactors = this.readReactors();
48,724✔
1713
                                        break;
48,724✔
1714
                                case DxfFileToken.BlkRefToken:
1715
                                default:
1716
                                        do
1717
                                        {
5,928✔
1718
                                                this._reader.ReadNext();
5,928✔
1719
                                        }
5,928✔
1720
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,928✔
1721
                                        return;
2,280✔
1722
                        }
1723
                }
63,101✔
1724

1725
                private List<ulong> readReactors()
1726
                {
48,724✔
1727
                        List<ulong> reactors = new List<ulong>();
48,724✔
1728

1729
                        this._reader.ReadNext();
48,724✔
1730

1731
                        while (this._reader.DxfCode != DxfCode.ControlString)
101,288✔
1732
                        {
52,564✔
1733
                                this._reader.ReadNext();
52,564✔
1734
                        }
52,564✔
1735

1736
                        return reactors;
48,724✔
1737
                }
48,724✔
1738

1739
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
1740
                {
5,006,500✔
1741
                        try
1742
                        {
5,006,500✔
1743
                                //Use this method only if the value is not a link between objects
1744
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
5,006,500✔
1745
                                {
1,894,223✔
1746
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
1,894,223✔
1747
                                        {
13,820✔
1748
                                                return true;
13,820✔
1749
                                        }
1750

1751
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
1,880,403!
1752
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
1,880,403✔
1753
                                        {
68,960✔
1754
                                                return false;
68,960✔
1755
                                        }
1756

1757
                                        object value = this._reader.Value;
1,811,443✔
1758

1759
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
1,811,443✔
1760
                                        {
9,258✔
1761
                                                value = MathHelper.DegToRad((double)value);
9,258✔
1762
                                        }
9,258✔
1763

1764
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
1,811,443✔
1765

1766
                                        return true;
1,811,443✔
1767
                                }
1768
                        }
3,112,277✔
UNCOV
1769
                        catch (Exception ex)
×
UNCOV
1770
                        {
×
UNCOV
1771
                                if (!this._builder.Configuration.Failsafe)
×
UNCOV
1772
                                {
×
UNCOV
1773
                                        throw ex;
×
1774
                                }
1775
                                else
UNCOV
1776
                                {
×
UNCOV
1777
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
UNCOV
1778
                                }
×
UNCOV
1779
                        }
×
1780

1781
                        return false;
3,112,277✔
1782
                }
5,006,500✔
1783
        }
1784
}
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