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

DomCR / ACadSharp / 16259479108

14 Jul 2025 06:17AM UTC coverage: 75.075% (+0.02%) from 75.059%
16259479108

push

github

web-flow
Merge pull request #708 from DomCR/issue-703_seqend-assign-dxfreader

issue 703

5863 of 8587 branches covered (68.28%)

Branch coverage included in aggregate %.

3 of 4 new or added lines in 2 files covered. (75.0%)

3 existing lines in 2 files now uncovered.

23296 of 30253 relevant lines covered (77.0%)

81507.2 hits per line

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

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

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

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

21
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
1,056✔
22
                {
1,056✔
23
                        this._reader = reader;
1,056✔
24
                        this._builder = builder;
1,056✔
25
                }
1,056✔
26

27
                public abstract void Read();
28

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

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

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

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

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

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

109
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
110
                {
1,900,351✔
111
                        isExtendedData = false;
1,900,351✔
112

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

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

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

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

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

234
                                        return unknownEntityTemplate;
3,876✔
235
                        }
236
                }
212,362✔
237

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

243
                        DxfMap map = DxfMap.Create<T>();
208,560✔
244

245
                        while (this._reader.DxfCode != DxfCode.Start)
2,668,656✔
246
                        {
2,460,096✔
247
                                if (!readEntity(template, map))
2,460,096✔
248
                                {
1,077,354✔
249
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
1,077,354✔
250
                                        if (isExtendedData)
1,077,354✔
251
                                                continue;
13,034✔
252
                                }
1,064,320✔
253

254
                                if (this._reader.DxfCode != DxfCode.Start)
2,447,062✔
255
                                        this._reader.ReadNext();
2,446,988✔
256
                        }
2,447,062✔
257

258
                        return template;
208,560✔
259
                }
208,560✔
260

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

692
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
693
                {
61,484✔
694
                        CadInsertTemplate tmp = template as CadInsertTemplate;
61,484✔
695

696
                        switch (this._reader.Code)
61,484✔
697
                        {
698
                                case 2:
699
                                        tmp.BlockName = this._reader.ValueAsString;
5,794✔
700
                                        return true;
5,794✔
701
                                case 100:
702
                                        //AcDbEntity
703
                                        //AcDbBlockReference
704
                                        //AcDbMInsertBlock
705
                                        return true;
5,736✔
706
                                case 66:
707
                                        return true;
532✔
708
                                default:
709
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
49,422✔
710
                        }
711
                }
61,484✔
712

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1053
                        XYZ controlPoint;
1054

1055
                        switch (this._reader.Code)
15,960!
1056
                        {
1057
                                case 10:
1058
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,824✔
1059
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,824✔
1060
                                        return true;
1,824✔
1061
                                case 20:
1062
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1063
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,824✔
1064
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1065
                                        return true;
1,824✔
1066
                                case 30:
1067
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1068
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,824✔
1069
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1070
                                        return true;
1,824✔
1071
                                case 40:
1072
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,648✔
1073
                                        return true;
3,648✔
1074
                                case 41:
1075
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1076
                                        return true;
×
1077
                                case 72:
1078
                                case 73:
1079
                                case 74:
1080
                                        return true;
1,368✔
1081
                                default:
1082
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
5,472✔
1083
                        }
1084
                }
15,960✔
1085

1086
                private bool readUnderlayEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
1087
                {
×
1088
                        CadPdfUnderlayTemplate tmp = template as CadPdfUnderlayTemplate;
×
1089

1090
                        switch (this._reader.Code)
×
1091
                        {
1092
                                case 340:
1093
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
×
1094
                                        return true;
×
1095
                                default:
1096
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1097
                        }
1098
                }
×
1099

1100
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1101
                {
265,608✔
1102
                        CadVertexTemplate tmp = template as CadVertexTemplate;
265,608✔
1103

1104
                        switch (this._reader.Code)
265,608✔
1105
                        {
1106
                                //Polyface mesh vertex index
1107
                                case 71:
1108
                                case 72:
1109
                                case 73:
1110
                                case 74:
1111
                                        return true;
1,862✔
1112
                                case 100:
1113
                                        switch (this._reader.ValueAsString)
7,752!
1114
                                        {
1115
                                                case DxfSubclassMarker.Vertex:
1116
                                                        return true;
2,280✔
1117
                                                case DxfSubclassMarker.PolylineVertex:
1118
                                                        tmp.SetVertexObject(new Vertex2D());
×
1119
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1120
                                                        return true;
×
1121
                                                case DxfSubclassMarker.Polyline3dVertex:
1122
                                                        tmp.SetVertexObject(new Vertex3D());
1,140✔
1123
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,140✔
1124
                                                        return true;
1,140✔
1125
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1126
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,140✔
1127
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,140✔
1128
                                                        return true;
1,140✔
1129
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1130
                                                        tmp.SetVertexObject(new VertexFaceRecord());
456✔
1131
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
456✔
1132
                                                        return true;
456✔
1133
                                                default:
1134
                                                        return false;
2,736✔
1135
                                        }
1136
                                default:
1137
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
255,994✔
1138
                        }
1139
                }
265,608✔
1140

1141
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1142
                {
76,296✔
1143
                        CadViewportTemplate tmp = template as CadViewportTemplate;
76,296✔
1144

1145
                        switch (this._reader.Code)
76,296!
1146
                        {
1147
                                //Undocumented
1148
                                case 67:
1149
                                case 68:
1150
                                        return true;
2,792✔
1151
                                case 69:
1152
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,396✔
1153
                                        return true;
1,396✔
1154
                                case 331:
1155
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1156
                                        return true;
×
1157
                                case 348:
1158
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
880✔
1159
                                        return true;
880✔
1160
                                default:
1161
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
71,228✔
1162
                        }
1163
                }
76,296✔
1164

1165
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1166
                {
1,209,456✔
1167
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
1,209,456✔
1168

1169
                        switch (this._reader.Code)
1,209,456✔
1170
                        {
1171
                                default:
1172
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
1,209,456✔
1173
                        }
1174
                }
1,209,456✔
1175

1176
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1177
                {
38,384✔
1178
                        List<ExtendedDataRecord> records = new();
38,384✔
1179
                        edata.Add(this._reader.ValueAsString, records);
38,384✔
1180

1181
                        this._reader.ReadNext();
38,384✔
1182

1183
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
302,613✔
1184
                        {
276,357✔
1185
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
276,357✔
1186
                                {
12,128✔
1187
                                        this.readExtendedData(edata);
12,128✔
1188
                                        break;
12,128✔
1189
                                }
1190

1191
                                ExtendedDataRecord record = null;
264,229✔
1192
                                double x = 0;
264,229✔
1193
                                double y = 0;
264,229✔
1194
                                double z = 0;
264,229✔
1195

1196
                                switch (this._reader.DxfCode)
264,229✔
1197
                                {
1198
                                        case DxfCode.ExtendedDataAsciiString:
1199
                                        case DxfCode.ExtendedDataRegAppName:
1200
                                                record = new ExtendedDataString(this._reader.ValueAsString);
28,727✔
1201
                                                break;
28,727✔
1202
                                        case DxfCode.ExtendedDataControlString:
1203
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
15,056✔
1204
                                                break;
15,056✔
1205
                                        case DxfCode.ExtendedDataLayerName:
1206
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
266✔
1207
                                                {
252✔
1208
                                                        record = new ExtendedDataLayer(layer.Handle);
252✔
1209
                                                }
252✔
1210
                                                else
1211
                                                {
14✔
1212
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1213
                                                }
14✔
1214
                                                break;
266✔
1215
                                        case DxfCode.ExtendedDataBinaryChunk:
1216
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
76✔
1217
                                                break;
76✔
1218
                                        case DxfCode.ExtendedDataHandle:
1219
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,808✔
1220
                                                break;
2,808✔
1221
                                        case DxfCode.ExtendedDataXCoordinate:
1222
                                                x = this._reader.ValueAsDouble;
2,836✔
1223
                                                this._reader.ReadNext();
2,836✔
1224
                                                y = this._reader.ValueAsDouble;
2,836✔
1225
                                                this._reader.ReadNext();
2,836✔
1226
                                                z = this._reader.ValueAsDouble;
2,836✔
1227

1228
                                                record = new ExtendedDataCoordinate(
2,836✔
1229
                                                        new XYZ(
2,836✔
1230
                                                                x,
2,836✔
1231
                                                                y,
2,836✔
1232
                                                                z)
2,836✔
1233
                                                        );
2,836✔
1234
                                                break;
2,836✔
1235
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1236
                                                x = this._reader.ValueAsDouble;
1,368✔
1237
                                                this._reader.ReadNext();
1,368✔
1238
                                                y = this._reader.ValueAsDouble;
1,368✔
1239
                                                this._reader.ReadNext();
1,368✔
1240
                                                z = this._reader.ValueAsDouble;
1,368✔
1241

1242
                                                record = new ExtendedDataWorldCoordinate(
1,368✔
1243
                                                        new XYZ(
1,368✔
1244
                                                                x,
1,368✔
1245
                                                                y,
1,368✔
1246
                                                                z)
1,368✔
1247
                                                        );
1,368✔
1248
                                                break;
1,368✔
1249
                                        case DxfCode.ExtendedDataWorldXDisp:
1250
                                                x = this._reader.ValueAsDouble;
266✔
1251
                                                this._reader.ReadNext();
266✔
1252
                                                y = this._reader.ValueAsDouble;
266✔
1253
                                                this._reader.ReadNext();
266✔
1254
                                                z = this._reader.ValueAsDouble;
266✔
1255

1256
                                                record = new ExtendedDataDisplacement(
266✔
1257
                                                        new XYZ(
266✔
1258
                                                                x,
266✔
1259
                                                                y,
266✔
1260
                                                                z)
266✔
1261
                                                        );
266✔
1262
                                                break;
266✔
1263
                                        case DxfCode.ExtendedDataWorldXDir:
1264
                                                x = this._reader.ValueAsDouble;
266✔
1265
                                                this._reader.ReadNext();
266✔
1266
                                                y = this._reader.ValueAsDouble;
266✔
1267
                                                this._reader.ReadNext();
266✔
1268
                                                z = this._reader.ValueAsDouble;
266✔
1269

1270
                                                record = new ExtendedDataDirection(
266✔
1271
                                                        new XYZ(
266✔
1272
                                                                x,
266✔
1273
                                                                y,
266✔
1274
                                                                z)
266✔
1275
                                                        );
266✔
1276
                                                break;
266✔
1277
                                        case DxfCode.ExtendedDataReal:
1278
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
133,506✔
1279
                                                break;
133,506✔
1280
                                        case DxfCode.ExtendedDataDist:
1281
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
266✔
1282
                                                break;
266✔
1283
                                        case DxfCode.ExtendedDataScale:
1284
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
266✔
1285
                                                break;
266✔
1286
                                        case DxfCode.ExtendedDataInteger16:
1287
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
67,821✔
1288
                                                break;
67,821✔
1289
                                        case DxfCode.ExtendedDataInteger32:
1290
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
8,269✔
1291
                                                break;
8,269✔
1292
                                        default:
1293
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,432✔
1294
                                                break;
2,432✔
1295
                                }
1296

1297
                                if (record != null)
264,229✔
1298
                                {
261,783✔
1299
                                        records.Add(record);
261,783✔
1300
                                }
261,783✔
1301

1302
                                this._reader.ReadNext();
264,229✔
1303
                        }
264,229✔
1304
                }
38,384✔
1305

1306
                private void readPattern(HatchPattern pattern, int nlines)
1307
                {
1,368✔
1308
                        //Jump 78 code
1309
                        this._reader.ReadNext();
1,368✔
1310

1311
                        for (int i = 0; i < nlines; i++)
207,480✔
1312
                        {
102,372✔
1313
                                HatchPattern.Line line = new HatchPattern.Line();
102,372✔
1314
                                XY basePoint = new XY();
102,372✔
1315
                                XY offset = new XY();
102,372✔
1316

1317
                                bool end = false;
102,372✔
1318
                                HashSet<int> codes = new();
102,372✔
1319

1320
                                while (!end)
717,972✔
1321
                                {
716,604✔
1322
                                        if (codes.Contains(this._reader.Code))
716,604✔
1323
                                        {
101,004✔
1324
                                                break;
101,004✔
1325
                                        }
1326
                                        else
1327
                                        {
615,600✔
1328
                                                codes.Add(this._reader.Code);
615,600✔
1329
                                        }
615,600✔
1330

1331
                                        switch (this._reader.Code)
615,600!
1332
                                        {
1333
                                                case 53:
1334
                                                        line.Angle = this._reader.ValueAsAngle;
102,372✔
1335
                                                        break;
102,372✔
1336
                                                case 43:
1337
                                                        basePoint.X = this._reader.ValueAsDouble;
102,372✔
1338
                                                        break;
102,372✔
1339
                                                case 44:
1340
                                                        basePoint.Y = this._reader.ValueAsDouble;
102,372✔
1341
                                                        line.BasePoint = basePoint;
102,372✔
1342
                                                        break;
102,372✔
1343
                                                case 45:
1344
                                                        offset.X = this._reader.ValueAsDouble;
102,372✔
1345
                                                        line.Offset = offset;
102,372✔
1346
                                                        break;
102,372✔
1347
                                                case 46:
1348
                                                        offset.Y = this._reader.ValueAsDouble;
102,372✔
1349
                                                        line.Offset = offset;
102,372✔
1350
                                                        break;
102,372✔
1351
                                                //Number of dash length items
1352
                                                case 79:
1353
                                                        int ndash = this._reader.ValueAsInt;
102,372✔
1354
                                                        for (int j = 0; j < ndash; j++)
613,320✔
1355
                                                        {
204,288✔
1356
                                                                this._reader.ReadNext();
204,288✔
1357
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
204,288✔
1358
                                                        }
204,288✔
1359
                                                        break;
102,372✔
1360
                                                case 49:
1361
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1362
                                                        break;
×
1363
                                                default:
1364
                                                        end = true;
1,368✔
1365
                                                        break;
1,368✔
1366
                                        }
1367
                                        this._reader.ReadNext();
615,600✔
1368
                                }
615,600✔
1369

1370
                                pattern.Lines.Add(line);
102,372✔
1371
                        }
102,372✔
1372
                }
1,368✔
1373

1374
                private void readLoops(CadHatchTemplate template, int count)
1375
                {
1,824✔
1376
                        if (this._reader.Code == 91)
1,824✔
1377
                                this._reader.ReadNext();
1,824✔
1378

1379
                        for (int i = 0; i < count; i++)
7,296✔
1380
                        {
1,824✔
1381
                                if (this._reader.Code != 92)
1,824!
1382
                                {
×
1383
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1384
                                        break;
×
1385
                                }
1386

1387
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,824✔
1388
                                if (path != null)
1,824✔
1389
                                        template.PathTempaltes.Add(path);
1,824✔
1390
                        }
1,824✔
1391
                }
1,824✔
1392

1393
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1394
                {
1,824✔
1395
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,824✔
1396
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,824✔
1397
                        template.Path.Flags = flags;
1,824✔
1398

1399
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,824✔
1400
                        {
684✔
1401
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
684✔
1402
                                template.Path.Edges.Add(pl);
684✔
1403
                        }
684✔
1404
                        else
1405
                        {
1,140✔
1406
                                this._reader.ReadNext();
1,140✔
1407

1408
                                if (this._reader.Code != 93)
1,140!
1409
                                {
×
1410
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1411
                                        return null;
×
1412
                                }
1413

1414
                                int edges = this._reader.ValueAsInt;
1,140✔
1415
                                this._reader.ReadNext();
1,140✔
1416

1417
                                for (int i = 0; i < edges; i++)
11,400✔
1418
                                {
4,560✔
1419
                                        var edge = this.readEdge();
4,560✔
1420
                                        if (edge != null)
4,560✔
1421
                                                template.Path.Edges.Add(edge);
4,560✔
1422
                                }
4,560✔
1423
                        }
1,140✔
1424

1425
                        bool end = false;
1,824✔
1426
                        while (!end)
7,068✔
1427
                        {
5,244✔
1428
                                switch (this._reader.Code)
5,244✔
1429
                                {
1430
                                        //Number of source boundary objects
1431
                                        case 97:
1432
                                                break;
1,824✔
1433
                                        case 330:
1434
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,596✔
1435
                                                break;
1,596✔
1436
                                        default:
1437
                                                end = true;
1,824✔
1438
                                                continue;
1,824✔
1439
                                }
1440

1441
                                this._reader.ReadNext();
3,420✔
1442
                        }
3,420✔
1443

1444
                        return template;
1,824✔
1445
                }
1,824✔
1446

1447
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1448
                {
684✔
1449
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
684✔
1450

1451
                        this._reader.ReadNext();
684✔
1452

1453
                        if (this._reader.Code != 72)
684!
1454
                        {
×
1455
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1456
                                return null;
×
1457
                        }
1458

1459
                        //72
1460
                        bool hasBulge = this._reader.ValueAsBool;
684✔
1461
                        this._reader.ReadNext();
684✔
1462

1463
                        //73
1464
                        bool isClosed = this._reader.ValueAsBool;
684✔
1465
                        this._reader.ReadNext();
684✔
1466

1467
                        //93
1468
                        int nvertices = this._reader.ValueAsInt;
684✔
1469
                        this._reader.ReadNext();
684✔
1470

1471
                        for (int i = 0; i < nvertices; i++)
6,840✔
1472
                        {
2,736✔
1473
                                double bulge = 0.0;
2,736✔
1474

1475
                                //10
1476
                                double x = this._reader.ValueAsDouble;
2,736✔
1477
                                this._reader.ReadNext();
2,736✔
1478
                                //20
1479
                                double y = this._reader.ValueAsDouble;
2,736✔
1480
                                this._reader.ReadNext();
2,736✔
1481

1482
                                if (hasBulge)
2,736!
1483
                                {
×
1484
                                        //42
1485
                                        bulge = this._reader.ValueAsDouble;
×
1486
                                        this._reader.ReadNext();
×
1487
                                }
×
1488

1489
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,736✔
1490
                        }
2,736✔
1491

1492
                        return boundary;
684✔
1493
                }
684✔
1494

1495
                private Hatch.BoundaryPath.Edge readEdge()
1496
                {
4,560✔
1497
                        if (this._reader.Code != 72)
4,560!
1498
                        {
×
1499
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1500
                                return null;
×
1501
                        }
1502

1503
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,560✔
1504
                        this._reader.ReadNext();
4,560✔
1505

1506
                        switch (type)
4,560!
1507
                        {
1508
                                case Hatch.BoundaryPath.EdgeType.Line:
1509
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,560✔
1510
                                        while (true)
22,800✔
1511
                                        {
22,800✔
1512
                                                switch (this._reader.Code)
22,800✔
1513
                                                {
1514
                                                        case 10:
1515
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,560✔
1516
                                                                break;
4,560✔
1517
                                                        case 20:
1518
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,560✔
1519
                                                                break;
4,560✔
1520
                                                        case 11:
1521
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,560✔
1522
                                                                break;
4,560✔
1523
                                                        case 21:
1524
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,560✔
1525
                                                                break;
4,560✔
1526
                                                        default:
1527
                                                                return line;
4,560✔
1528
                                                }
1529

1530
                                                this._reader.ReadNext();
18,240✔
1531
                                        }
18,240✔
1532
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1533
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1534
                                        while (true)
×
1535
                                        {
×
1536
                                                switch (this._reader.Code)
×
1537
                                                {
1538
                                                        case 10:
1539
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1540
                                                                break;
×
1541
                                                        case 20:
1542
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1543
                                                                break;
×
1544
                                                        case 40:
1545
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1546
                                                                break;
×
1547
                                                        case 50:
1548
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1549
                                                                break;
×
1550
                                                        case 51:
1551
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1552
                                                                break;
×
1553
                                                        case 73:
1554
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1555
                                                                break;
×
1556
                                                        default:
1557
                                                                return arc;
×
1558
                                                }
1559

1560
                                                this._reader.ReadNext();
×
1561
                                        }
×
1562
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1563
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1564
                                        while (true)
×
1565
                                        {
×
1566
                                                switch (this._reader.Code)
×
1567
                                                {
1568
                                                        case 10:
1569
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1570
                                                                break;
×
1571
                                                        case 20:
1572
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1573
                                                                break;
×
1574
                                                        case 11:
1575
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1576
                                                                break;
×
1577
                                                        case 21:
1578
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1579
                                                                break;
×
1580
                                                        case 40:
1581
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1582
                                                                break;
×
1583
                                                        case 50:
1584
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1585
                                                                break;
×
1586
                                                        case 51:
1587
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
1588
                                                                break;
×
1589
                                                        case 73:
1590
                                                                ellipse.IsCounterclockwise = this._reader.ValueAsBool;
×
1591
                                                                break;
×
1592
                                                        default:
1593
                                                                return ellipse;
×
1594
                                                }
1595

1596
                                                this._reader.ReadNext();
×
1597
                                        }
×
1598
                                case Hatch.BoundaryPath.EdgeType.Spline:
1599
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1600
                                        int nKnots = 0;
×
1601
                                        int nCtrlPoints = 0;
×
1602
                                        int nFitPoints = 0;
×
1603

1604
                                        XYZ controlPoint = new XYZ();
×
1605
                                        XY fitPoint = new XY();
×
1606

1607
                                        while (true)
×
1608
                                        {
×
1609
                                                switch (this._reader.Code)
×
1610
                                                {
1611
                                                        case 10:
1612
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1613
                                                                break;
×
1614
                                                        case 20:
1615
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1616
                                                                spline.ControlPoints.Add(controlPoint);
×
1617
                                                                break;
×
1618
                                                        case 11:
1619
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
1620
                                                                break;
×
1621
                                                        case 21:
1622
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
1623
                                                                spline.FitPoints.Add(fitPoint);
×
1624
                                                                break;
×
1625
                                                        case 42:
1626
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
1627
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1628
                                                                break;
×
1629
                                                        case 12:
1630
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1631
                                                                break;
×
1632
                                                        case 22:
1633
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
1634
                                                                break;
×
1635
                                                        case 13:
1636
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1637
                                                                break;
×
1638
                                                        case 23:
1639
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1640
                                                                break;
×
1641
                                                        case 94:
1642
                                                                spline.Degree = this._reader.ValueAsInt;
×
1643
                                                                break;
×
1644
                                                        case 73:
1645
                                                                spline.Rational = this._reader.ValueAsBool;
×
1646
                                                                break;
×
1647
                                                        case 74:
1648
                                                                spline.Periodic = this._reader.ValueAsBool;
×
1649
                                                                break;
×
1650
                                                        case 95:
1651
                                                                nKnots = this._reader.ValueAsInt;
×
1652
                                                                break;
×
1653
                                                        case 96:
1654
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1655
                                                                break;
×
1656
                                                        case 97:
1657
                                                                nFitPoints = this._reader.ValueAsInt;
×
1658
                                                                break;
×
1659
                                                        case 40:
1660
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
1661
                                                                break;
×
1662
                                                        default:
1663
                                                                return spline;
×
1664
                                                }
1665

1666
                                                this._reader.ReadNext();
×
1667
                                        }
×
1668
                        }
1669

1670
                        return null;
×
1671
                }
4,560✔
1672

1673
                private void readDefinedGroups(CadTemplate template)
1674
                {
61,749✔
1675
                        this.readDefinedGroups(out ulong? xdict, out List<ulong> reactorsHandles);
61,749✔
1676

1677
                        template.XDictHandle = xdict;
61,749✔
1678
                        template.ReactorsHandles = reactorsHandles;
61,749✔
1679
                }
61,749✔
1680

1681
                private void readDefinedGroups(out ulong? xdictHandle, out List<ulong> reactors)
1682
                {
61,979✔
1683
                        xdictHandle = null;
61,979✔
1684
                        reactors = new List<ulong>();
61,979✔
1685

1686
                        switch (this._reader.ValueAsString)
61,979✔
1687
                        {
1688
                                case DxfFileToken.DictionaryToken:
1689
                                        this._reader.ReadNext();
11,869✔
1690
                                        xdictHandle = this._reader.ValueAsHandle;
11,869✔
1691
                                        this._reader.ReadNext();
11,869✔
1692
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
11,869✔
1693
                                        return;
11,869✔
1694
                                case DxfFileToken.ReactorsToken:
1695
                                        reactors = this.readReactors();
47,830✔
1696
                                        break;
47,830✔
1697
                                case DxfFileToken.BlkRefToken:
1698
                                default:
1699
                                        do
1700
                                        {
5,700✔
1701
                                                this._reader.ReadNext();
5,700✔
1702
                                        }
5,700✔
1703
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,700✔
1704
                                        return;
2,280✔
1705
                        }
1706
                }
61,979✔
1707

1708
                private List<ulong> readReactors()
1709
                {
47,830✔
1710
                        List<ulong> reactors = new List<ulong>();
47,830✔
1711

1712
                        this._reader.ReadNext();
47,830✔
1713

1714
                        while (this._reader.DxfCode != DxfCode.ControlString)
99,284✔
1715
                        {
51,454✔
1716
                                this._reader.ReadNext();
51,454✔
1717
                        }
51,454✔
1718

1719
                        return reactors;
47,830✔
1720
                }
47,830✔
1721

1722
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
1723
                {
4,987,882✔
1724
                        try
1725
                        {
4,987,882✔
1726
                                //Use this method only if the value is not a link between objects
1727
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,987,882✔
1728
                                {
1,886,685✔
1729
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
1,886,685✔
1730
                                        {
13,604✔
1731
                                                return true;
13,604✔
1732
                                        }
1733

1734
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
1,873,081!
1735
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
1,873,081✔
1736
                                        {
68,960✔
1737
                                                return false;
68,960✔
1738
                                        }
1739

1740
                                        object value = this._reader.Value;
1,804,121✔
1741

1742
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
1,804,121✔
1743
                                        {
9,258✔
1744
                                                value = MathHelper.DegToRad((double)value);
9,258✔
1745
                                        }
9,258✔
1746

1747
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
1,804,121✔
1748

1749
                                        return true;
1,804,121✔
1750
                                }
1751
                        }
3,101,197✔
1752
                        catch (Exception ex)
×
1753
                        {
×
1754
                                if (!this._builder.Configuration.Failsafe)
×
1755
                                {
×
1756
                                        throw ex;
×
1757
                                }
1758
                                else
1759
                                {
×
1760
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
1761
                                }
×
1762
                        }
×
1763

1764
                        return false;
3,101,197✔
1765
                }
4,987,882✔
1766
        }
1767
}
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