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

DomCR / ACadSharp / 14681310655

26 Apr 2025 12:39PM UTC coverage: 75.03% (-0.3%) from 75.291%
14681310655

Pull #621

github

web-flow
Merge 0f6659c50 into 8aaeba1a6
Pull Request #621: 20250402 nka multileader clone bugfix

5704 of 8369 branches covered (68.16%)

Branch coverage included in aggregate %.

189 of 325 new or added lines in 7 files covered. (58.15%)

341 existing lines in 15 files now uncovered.

22779 of 29593 relevant lines covered (76.97%)

82229.57 hits per line

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

83.56
/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 70:
498
                                case 74:
499
                                case 101:
500
                                        return true;
456✔
501
                                case 7:
502
                                        tmp.StyleName = this._reader.ValueAsString;
2,660✔
503
                                        return true;
2,660✔
504
                                default:
505
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
305,800✔
506
                        }
507
                }
319,790✔
508

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

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

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

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

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

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

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

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

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

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

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

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

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

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

745
                                        this._builder.AddTemplate(seqendTemplate);
×
746

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1011
                        switch (this._reader.Code)
59,280✔
1012
                        {
1013
                                // String of up to 32 characters. The name of the style used for this mline. An entry for this style must exist in the MLINESTYLE dictionary.
1014
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1015
                                case 2:
1016
                                        tmp.MLineStyleName = this._reader.ValueAsString;
684✔
1017
                                        return true;
684✔
1018
                                case 72:
1019
                                        tmp.NVertex = this._reader.ValueAsInt;
684✔
1020
                                        return true;
684✔
1021
                                case 73:
1022
                                        tmp.NElements = this._reader.ValueAsInt;
684✔
1023
                                        return true;
684✔
1024
                                case 340:
1025
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
684✔
1026
                                        return true;
684✔
1027
                                default:
1028
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
56,544✔
1029
                                        {
9,576✔
1030
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
9,576✔
1031
                                        }
1032
                                        return true;
46,968✔
1033
                        }
1034
                }
59,280✔
1035

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

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

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

1054
                        XYZ controlPoint;
1055

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1493
                        return boundary;
684✔
1494
                }
684✔
1495

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

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

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

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

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

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

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

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

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

UNCOV
1671
                        return null;
×
1672
                }
4,560✔
1673

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

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

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

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

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

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

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

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

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

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

1741
                                        object value = this._reader.Value;
1,804,073✔
1742

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

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

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

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