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

DomCR / ACadSharp / 13075286726

31 Jan 2025 03:02PM UTC coverage: 76.172% (-0.05%) from 76.226%
13075286726

Pull #546

github

web-flow
Merge 63345678f into da8587f47
Pull Request #546: Issue 529 geodata

5344 of 7740 branches covered (69.04%)

Branch coverage included in aggregate %.

37 of 94 new or added lines in 5 files covered. (39.36%)

213 existing lines in 3 files now uncovered.

21339 of 27290 relevant lines covered (78.19%)

39476.62 hits per line

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

83.13
/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)
692✔
22
                {
692✔
23
                        this._reader = reader;
692✔
24
                        this._builder = builder;
692✔
25
                }
692✔
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
                {
1,643✔
31
                        name = null;
1,643✔
32
                        handle = 0;
1,643✔
33
                        ownerHandle = null;
1,643✔
34
                        xdictHandle = null;
1,643✔
35
                        reactors = new List<ulong>();
1,643✔
36

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

41
                        //Loop until the common data end
42
                        while (this._reader.DxfCode != DxfCode.Start
6,547✔
43
                                        && this._reader.DxfCode != DxfCode.Subclass)
6,547✔
44
                        {
4,904✔
45
                                switch (this._reader.Code)
4,904!
46
                                {
47
                                        //Table name
48
                                        case 2:
49
                                                name = this._reader.ValueAsString;
1,643✔
50
                                                break;
1,643✔
51
                                        //Handle
52
                                        case 5:
53
                                        case 105:
54
                                                handle = this._reader.ValueAsHandle;
1,467✔
55
                                                break;
1,467✔
56
                                        //Start of application - defined group
57
                                        case 102:
58
                                                this.readDefinedGroups(out xdictHandle, out reactors);
151✔
59
                                                break;
151✔
60
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
61
                                        case 330:
62
                                                ownerHandle = this._reader.ValueAsHandle;
1,467✔
63
                                                break;
1,467✔
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}.");
176✔
70
                                                break;
176✔
71
                                }
72

73
                                this._reader.ReadNext();
4,904✔
74
                        }
4,904✔
75
                }
1,643✔
76

77
                [Obsolete("Only needed for SortEntitiesTable but it should be removed")]
78
                protected void readCommonObjectData(CadTemplate template)
79
                {
246✔
80
                        while (this._reader.DxfCode != DxfCode.Subclass)
984✔
81
                        {
738✔
82
                                switch (this._reader.Code)
738!
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;
246✔
91
                                                break;
246✔
92
                                        //Start of application - defined group
93
                                        case 102:
94
                                                this.readDefinedGroups(template);
246✔
95
                                                break;
246✔
96
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
97
                                        case 330:
98
                                                template.OwnerHandle = this._reader.ValueAsHandle;
246✔
99
                                                break;
246✔
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();
738✔
106
                        }
738✔
107
                }
246✔
108

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

113
                        switch (this._reader.Code)
775,383✔
114
                        {
115
                                //Handle
116
                                case 5:
117
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
120,993✔
118
                                        break;
120,993✔
119
                                //Check with mapper
120
                                case 100:
121
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
85,952!
122
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
744✔
123
                                        break;
85,952✔
124
                                //Start of application - defined group
125
                                case 102:
126
                                        this.readDefinedGroups(template);
30,207✔
127
                                        break;
30,207✔
128
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
129
                                case 330:
130
                                        template.OwnerHandle = this._reader.ValueAsHandle;
68,338✔
131
                                        break;
68,338✔
132
                                case 1001:
133
                                        isExtendedData = true;
9,663✔
134
                                        this.readExtendedData(template.EDataTemplateByAppName);
9,663✔
135
                                        break;
9,663✔
136
                                default:
137
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
460,230✔
138
                                        break;
460,230✔
139
                        }
140
                }
775,383✔
141

142
                protected CadEntityTemplate readEntity()
143
                {
78,094✔
144
                        switch (this._reader.ValueAsString)
78,094!
145
                        {
146
                                case DxfFileToken.EntityAttribute:
147
                                        return this.readEntityCodes<AttributeEntity>(new CadAttributeTemplate(new AttributeEntity()), this.readAttributeDefinition);
616✔
148
                                case DxfFileToken.EntityAttributeDefinition:
149
                                        return this.readEntityCodes<AttributeDefinition>(new CadAttributeTemplate(new AttributeDefinition()), this.readAttributeDefinition);
700✔
150
                                case DxfFileToken.EntityArc:
151
                                        return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), this.readArc);
434✔
152
                                case DxfFileToken.EntityCircle:
153
                                        return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), this.readEntitySubclassMap);
626✔
154
                                case DxfFileToken.EntityDimension:
155
                                        return this.readEntityCodes<Dimension>(new CadDimensionTemplate(), this.readDimension);
1,232✔
156
                                case DxfFileToken.Entity3DFace:
157
                                        return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), this.readEntitySubclassMap);
154✔
158
                                case DxfFileToken.EntityEllipse:
159
                                        return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), this.readEntitySubclassMap);
132✔
160
                                case DxfFileToken.EntityLeader:
161
                                        return this.readEntityCodes<Leader>(new CadLeaderTemplate(), this.readLeader);
132✔
162
                                case DxfFileToken.EntityLine:
163
                                        return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), this.readEntitySubclassMap);
14,462✔
164
                                case DxfFileToken.EntityLwPolyline:
165
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
1,448✔
166
                                case DxfFileToken.EntityMesh:
167
                                        return this.readEntityCodes<Mesh>(new CadMeshTemplate(), this.readMesh);
264✔
168
                                case DxfFileToken.EntityHatch:
169
                                        return this.readEntityCodes<Hatch>(new CadHatchTemplate(), this.readHatch);
548✔
170
                                case DxfFileToken.EntityInsert:
171
                                        return this.readEntityCodes<Insert>(new CadInsertTemplate(), this.readInsert);
1,382✔
172
                                case DxfFileToken.EntityMText:
173
                                        return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), this.readTextEntity);
2,592✔
174
                                case DxfFileToken.EntityMLine:
175
                                        return this.readEntityCodes<MLine>(new CadMLineTemplate(), this.readMLine);
396✔
176
                                case DxfFileToken.EntityPdfUnderlay:
177
                                        return this.readEntityCodes<PdfUnderlay>(new CadPdfUnderlayTemplate(), this.readUnderlayEntity);
×
178
                                case DxfFileToken.EntityPoint:
179
                                        return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), this.readEntitySubclassMap);
4,424✔
180
                                case DxfFileToken.EntityPolyline:
181
                                        return this.readPolyline();
5,852✔
182
                                case DxfFileToken.EntityRay:
183
                                        return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), this.readEntitySubclassMap);
132✔
184
                                case DxfFileToken.EndSequence:
185
                                        return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), this.readEntitySubclassMap);
6,160✔
186
                                case DxfFileToken.EntitySolid:
187
                                        return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), this.readEntitySubclassMap);
7,754✔
188
                                case DxfFileToken.EntityTable:
189
                                        return this.readEntityCodes<TableEntity>(new CadTableEntityTemplate(), this.readTableEntity);
133✔
190
                                case DxfFileToken.EntityText:
191
                                        return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), this.readTextEntity);
4,405✔
192
                                case DxfFileToken.EntityTolerance:
193
                                        return this.readEntityCodes<Tolerance>(new CadToleranceTemplate(new Tolerance()), this.readTolerance);
396✔
194
                                case DxfFileToken.EntityVertex:
195
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
22,008✔
196
                                case DxfFileToken.EntityViewport:
197
                                        return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
788✔
198
                                case DxfFileToken.EntityShape:
199
                                        return this.readEntityCodes<Shape>(new CadShapeTemplate(new Shape()), this.readShape);
132✔
200
                                case DxfFileToken.EntitySpline:
201
                                        return this.readEntityCodes<Spline>(new CadSplineTemplate(), this.readSpline);
264✔
202
                                case DxfFileToken.EntityXline:
203
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
132✔
204
                                default:
205
                                        DxfMap map = DxfMap.Create<Entity>();
396✔
206
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
396✔
207
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
396✔
208
                                        {
360✔
209
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
360✔
210
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
360✔
211
                                        }
360✔
212
                                        else
213
                                        {
36✔
214
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
36✔
215
                                        }
36✔
216

217
                                        this._reader.ReadNext();
396✔
218

219
                                        do
220
                                        {
25,448✔
221
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
25,448✔
222
                                                {
2,308✔
223
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
2,308✔
224
                                                        if (isExtendedData)
2,308✔
225
                                                                continue;
6✔
226
                                                }
2,302✔
227

228
                                                this._reader.ReadNext();
25,442✔
229
                                        }
25,442✔
230
                                        while (this._reader.DxfCode != DxfCode.Start);
25,448✔
231

232
                                        return unknownEntityTemplate;
396✔
233
                        }
234
                }
78,094✔
235

236
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
237
                        where T : Entity
238
                {
77,740✔
239
                        this._reader.ReadNext();
77,740✔
240

241
                        DxfMap map = DxfMap.Create<T>();
77,740✔
242

243
                        while (this._reader.DxfCode != DxfCode.Start)
1,004,144✔
244
                        {
926,404✔
245
                                if (!readEntity(template, map))
926,404✔
246
                                {
420,721✔
247
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
420,721✔
248
                                        if (isExtendedData)
420,721✔
249
                                                continue;
3,244✔
250
                                }
417,477✔
251

252
                                if (this._reader.DxfCode != DxfCode.Start)
923,160✔
253
                                        this._reader.ReadNext();
923,118✔
254
                        }
923,160✔
255

256
                        return template;
77,740✔
257
                }
77,740✔
258

259
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
260
                {
444,778✔
261
                        isExtendedData = false;
444,778✔
262
                        switch (this._reader.Code)
444,778✔
263
                        {
264
                                case 6:
265
                                        template.LineTypeName = this._reader.ValueAsString;
11,379✔
266
                                        break;
11,379✔
267
                                case 8:
268
                                        template.LayerName = this._reader.ValueAsString;
83,528✔
269
                                        break;
83,528✔
270
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
271
                                case 67:
272
                                        break;
836✔
273
                                //Number of bytes Proxy entity graphics data
274
                                case 92:
275
                                case 160:
276
                                //Proxy entity graphics data
277
                                case 310:
278
                                        break;
24,950✔
279
                                case 347:
280
                                        template.MaterialHandle = this._reader.ValueAsHandle;
88✔
281
                                        break;
88✔
282
                                case 430:
283
                                        template.BookColorName = this._reader.ValueAsString;
8✔
284
                                        break;
8✔
285
                                default:
286
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
323,989✔
287
                                        {
288,672✔
288
                                                this.readCommonCodes(template, out isExtendedData, map);
288,672✔
289
                                        }
288,672✔
290
                                        break;
323,989✔
291
                        }
292
                }
444,778✔
293

294
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
295
                {
5,680✔
296
                        switch (this._reader.Code)
5,680✔
297
                        {
298
                                default:
299
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
5,680✔
300
                                        {
4,812✔
301
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
4,812✔
302
                                        }
303
                                        return true;
868✔
304
                        }
305
                }
5,680✔
306

307
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
308
                {
21,222✔
309
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
21,222✔
310
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
21,222✔
311

312
                        switch (this._reader.Code)
21,222!
313
                        {
314
                                case 44:
315
                                case 46:
UNCOV
316
                                        return true;
×
317
                                case 101:
318
                                        var att = tmp.CadObject as AttributeBase;
42✔
319
                                        att.MText = new MText();
42✔
320
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
42✔
321
                                        tmp.MTextTemplate = mtextTemplate;
42✔
322
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
42✔
323
                                        return true;
42✔
324
                                default:
325
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
21,180✔
326
                                        {
16,034✔
327
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
16,034✔
328
                                        }
329
                                        return true;
5,146✔
330
                        }
331
                }
21,222✔
332

333
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
334
                {
47,195✔
335
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
47,195!
336
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
47,195✔
337
                        TableEntity table = tmp.CadObject as TableEntity;
47,195✔
338

339
                        switch (this._reader.Code)
47,195✔
340
                        {
341
                                case 2:
342
                                        tmp.BlockName = this._reader.ValueAsString;
133✔
343
                                        return true;
133✔
344
                                case 342:
345
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
133✔
346
                                        return true;
133✔
347
                                case 343:
348
                                        tmp.BlockOwnerHandle = this._reader.ValueAsHandle;
133✔
349
                                        return true;
133✔
350
                                case 141:
351
                                        var row = new TableEntity.Row();
928✔
352
                                        row.Height = this._reader.ValueAsDouble;
928✔
353
                                        table.Rows.Add(row);
928✔
354
                                        return true;
928✔
355
                                case 142:
356
                                        var col = new TableEntity.Column();
401✔
357
                                        col.Width = this._reader.ValueAsDouble;
401✔
358
                                        table.Columns.Add(col);
401✔
359
                                        return true;
401✔
360
                                case 144:
361
                                        tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
2✔
362
                                        return true;
2✔
363
                                case 145:
364
                                        tmp.CurrentCell.Rotation = this._reader.ValueAsDouble;
2,792✔
365
                                        return true;
2,792✔
366
                                case 170:
367
                                        //Has data flag
368
                                        return true;
134✔
369
                                case 171:
370
                                        tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
2,792✔
371
                                        return true;
2,792✔
372
                                case 172:
373
                                        tmp.CurrentCell.FlagValue = this._reader.ValueAsInt;
2,792✔
374
                                        return true;
2,792✔
375
                                case 173:
376
                                        tmp.CurrentCell.MergedValue = this._reader.ValueAsInt;
2,792✔
377
                                        return true;
2,792✔
378
                                case 174:
379
                                        tmp.CurrentCell.Autofit = this._reader.ValueAsBool;
2,792✔
380
                                        return true;
2,792✔
381
                                case 175:
382
                                        tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
2,792✔
383
                                        return true;
2,792✔
384
                                case 176:
385
                                        tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
2,792✔
386
                                        return true;
2,792✔
387
                                case 178:
388
                                        tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
2,792✔
389
                                        return true;
2,792✔
390
                                case 179:
391
                                        //Unknown value
392
                                        return true;
2✔
393
                                case 301:
394
                                        var content = new TableEntity.CellContent();
1,868✔
395
                                        tmp.CurrentCell.Contents.Add(content);
1,868✔
396
                                        this.readCellValue(content);
1,868✔
397
                                        return true;
1,868✔
398
                                case 340:
399
                                        tmp.CurrentCellTemplate.BlockRecordHandle = this._reader.ValueAsHandle;
2✔
400
                                        return true;
2✔
401
                                default:
402
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
21,123✔
403
                                        {
20,592✔
404
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
20,592✔
405
                                        }
406
                                        return true;
531✔
407
                        }
408
                }
47,195✔
409

410
                private void readCellValue(TableEntity.CellContent content)
411
                {
1,868✔
412
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
1,868!
413
                        {
1,868✔
414
                                this._reader.ReadNext();
1,868✔
415
                        }
1,868✔
416
                        else
UNCOV
417
                        {
×
UNCOV
418
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
419
                        }
420

421
                        while (this._reader.Code != 304
11,926✔
422
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
11,926✔
423
                        {
10,058✔
424
                                switch (this._reader.Code)
10,058!
425
                                {
426
                                        case 1:
427
                                                content.Value.Text = this._reader.ValueAsString;
708✔
428
                                                break;
708✔
429
                                        case 2:
430
                                                content.Value.Text += this._reader.ValueAsString;
×
UNCOV
431
                                                break;
×
432
                                        case 11:
433
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
1✔
434
                                                break;
1✔
435
                                        case 21:
436
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
1✔
437
                                                break;
1✔
438
                                        case 31:
439
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
1✔
440
                                                break;
1✔
441
                                        case 302:
442
                                                //TODO: Fix this assignation to cell value
443
                                                content.Value.Value = this._reader.ValueAsString;
1,868✔
444
                                                break;
1,868✔
445
                                        case 90:
446
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
1,868✔
447
                                                break;
1,868✔
448
                                        case 91:
449
                                                content.Value.Value = this._reader.ValueAsInt;
1✔
450
                                                break;
1✔
451
                                        case 93:
452
                                                content.Value.Flags = this._reader.ValueAsInt;
1,868✔
453
                                                break;
1,868✔
454
                                        case 94:
455
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
1,868✔
456
                                                break;
1,868✔
457
                                        case 140:
458
                                                content.Value.Value = this._reader.ValueAsDouble;
4✔
459
                                                break;
4✔
460
                                        case 300:
461
                                                content.Value.Format = this._reader.ValueAsString;
1,868✔
462
                                                break;
1,868✔
463
                                        default:
464
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
2✔
465
                                                break;
2✔
466
                                }
467

468
                                this._reader.ReadNext();
10,058✔
469
                        }
10,058✔
470
                }
1,868✔
471

472
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
473
                {
104,706✔
474
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
104,706✔
475
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
104,706✔
476

477
                        switch (this._reader.Code)
104,706✔
478
                        {
479
                                //TODO: Implement multiline text def codes
480
                                case 1 or 3 when tmp.CadObject is MText mtext:
10,071✔
481
                                        mtext.Value += this._reader.ValueAsString;
4,350✔
482
                                        return true;
4,350✔
483
                                case 70:
484
                                case 74:
485
                                case 101:
486
                                        return true;
264✔
487
                                case 7:
488
                                        tmp.StyleName = this._reader.ValueAsString;
616✔
489
                                        return true;
616✔
490
                                default:
491
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
99,476✔
492
                        }
493
                }
104,706✔
494

495
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
496
                {
3,960✔
497
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
3,960✔
498

499
                        switch (this._reader.Code)
3,960✔
500
                        {
501
                                case 3:
502
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
396✔
503
                                        return true;
396✔
504
                                default:
505
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
3,564✔
506
                        }
507
                }
3,960✔
508

509
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
510
                {
31,834✔
511
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
31,834✔
512

513
                        switch (this._reader.Code)
31,834✔
514
                        {
515
                                case 2:
516
                                        tmp.BlockName = this._reader.ValueAsString;
1,232✔
517
                                        return true;
1,232✔
518
                                case 3:
519
                                        tmp.StyleName = this._reader.ValueAsString;
1,056✔
520
                                        return true;
1,056✔
521
                                case 50:
522
                                        var dim = new DimensionLinear();
154✔
523
                                        tmp.SetDimensionObject(dim);
154✔
524
                                        dim.Rotation = CSMath.MathHelper.DegToRad(this._reader.ValueAsDouble);
154✔
525
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
154✔
526
                                        return true;
154✔
527
                                case 70:
528
                                        //Flags do not have set
529
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
1,232✔
530
                                        return true;
1,232✔
531
                                //Measurement - read only
532
                                case 42:
533
                                        return true;
1,056✔
534
                                //Undocumented codes
535
                                case 73:
536
                                case 74:
537
                                case 75:
538
                                case 90:
539
                                case 361:
540
                                        return true;
2,112✔
541
                                case 100:
542
                                        switch (this._reader.ValueAsString)
3,300✔
543
                                        {
544
                                                case DxfSubclassMarker.Dimension:
545
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
1,056✔
546
                                                case DxfSubclassMarker.AlignedDimension:
547
                                                        tmp.SetDimensionObject(new DimensionAligned());
264✔
548
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
264✔
549
                                                        return true;
264✔
550
                                                case DxfSubclassMarker.DiametricDimension:
551
                                                        tmp.SetDimensionObject(new DimensionDiameter());
132✔
552
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
132✔
553
                                                        return true;
132✔
554
                                                case DxfSubclassMarker.Angular2LineDimension:
555
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
132✔
556
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
132✔
557
                                                        return true;
132✔
558
                                                case DxfSubclassMarker.Angular3PointDimension:
559
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
132✔
560
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
132✔
561
                                                        return true;
132✔
562
                                                case DxfSubclassMarker.RadialDimension:
563
                                                        tmp.SetDimensionObject(new DimensionRadius());
132✔
564
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
132✔
565
                                                        return true;
132✔
566
                                                case DxfSubclassMarker.OrdinateDimension:
567
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
264✔
568
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
264✔
569
                                                        return true;
264✔
570
                                                case DxfSubclassMarker.LinearDimension:
571
                                                        return true;
132✔
572
                                                default:
573
                                                        return false;
1,056✔
574
                                        }
575
                                default:
576
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
21,692✔
577
                        }
578
                }
31,834✔
579

580
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
581
                {
14,716✔
582
                        CadHatchTemplate tmp = template as CadHatchTemplate;
14,716✔
583
                        Hatch hatch = tmp.CadObject;
14,716✔
584

585
                        bool isFirstSeed = true;
14,716✔
586
                        XY seedPoint = new XY();
14,716✔
587

588
                        switch (this._reader.Code)
14,716!
589
                        {
590
                                case 2:
591
                                        hatch.Pattern.Name = this._reader.ValueAsString;
548✔
592
                                        return true;
548✔
593
                                case 10:
594
                                        seedPoint.X = this._reader.ValueAsDouble;
827✔
595
                                        return true;
827✔
596
                                case 20:
597
                                        if (!isFirstSeed)
1,096!
UNCOV
598
                                        {
×
UNCOV
599
                                                seedPoint.Y = this._reader.ValueAsDouble;
×
UNCOV
600
                                                hatch.SeedPoints.Add(seedPoint);
×
UNCOV
601
                                        }
×
602
                                        return true;
1,096✔
603
                                case 30:
604
                                        hatch.Elevation = this._reader.ValueAsDouble;
548✔
605
                                        isFirstSeed = false;
548✔
606
                                        return true;
548✔
607
                                case 53:
UNCOV
608
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
UNCOV
609
                                        return true;
×
610
                                //Number of dash length items
611
                                case 79:
612
                                        return true;
×
613
                                //TODO: Check hatch undocumented codes
614
                                case 90:
UNCOV
615
                                        return true;
×
616
                                //Information about the hatch pattern
617
                                case 75:
UNCOV
618
                                        return true;
×
619
                                //Number of pattern definition lines
620
                                case 78:
621
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
284✔
622
                                        return true;
284✔
623
                                //Number of boundary paths (loops)
624
                                case 91:
625
                                        this.readLoops(tmp, this._reader.ValueAsInt);
548✔
626
                                        return true;
548✔
627
                                //Number of seed points
628
                                case 98:
629
                                        return true;
264✔
630
                                case 450:
631
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
220✔
632
                                        return true;
220✔
633
                                case 451:
634
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
220✔
635
                                        return true;
220✔
636
                                case 452:
637
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
220✔
638
                                        return true;
220✔
639
                                case 453:
640
                                        //Number of colors
641
                                        return true;
220✔
642
                                case 460:
643
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
220✔
644
                                        return true;
220✔
645
                                case 461:
646
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
220✔
647
                                        return true;
220✔
648
                                case 462:
649
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
220✔
650
                                        return true;
220✔
651
                                case 463:
652
                                        GradientColor gradient = new GradientColor();
440✔
653
                                        gradient.Value = this._reader.ValueAsDouble;
440✔
654
                                        hatch.GradientColor.Colors.Add(gradient);
440✔
655
                                        return true;
440✔
656
                                case 63:
657
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
440✔
658
                                        if (colorByIndex != null)
440✔
659
                                        {
440✔
660
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
440✔
661
                                        }
440✔
662
                                        return true;
440✔
663
                                case 421:
664
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
440✔
665
                                        if (colorByRgb != null)
440✔
666
                                        {
440✔
667
                                                //TODO: Hatch assign color by true color
668
                                                //TODO: Is always duplicated by 63, is it needed??
669
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
670
                                        }
440✔
671
                                        return true;
440✔
672
                                case 470:
673
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
220✔
674
                                        return true;
220✔
675
                                default:
676
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
7,521✔
677
                        }
678
                }
14,716✔
679

680
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
681
                {
13,973✔
682
                        CadInsertTemplate tmp = template as CadInsertTemplate;
13,973✔
683

684
                        switch (this._reader.Code)
13,973✔
685
                        {
686
                                case 2:
687
                                        tmp.BlockName = this._reader.ValueAsString;
1,382✔
688
                                        return true;
1,382✔
689
                                case 66:
690
                                        return true;
308✔
691
                                default:
692
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
12,283✔
693
                        }
694
                }
13,973✔
695

696
                private CadEntityTemplate readPolyline()
697
                {
5,852✔
698
                        CadPolyLineTemplate template = null;
5,852✔
699

700
                        if (this._builder.Version == ACadVersion.Unknown)
5,852!
UNCOV
701
                        {
×
UNCOV
702
                                var polyline = new Polyline2D();
×
UNCOV
703
                                template = new CadPolyLineTemplate(polyline);
×
UNCOV
704
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
×
705

UNCOV
706
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
×
UNCOV
707
                                {
×
UNCOV
708
                                        Vertex2D v = new Vertex2D();
×
UNCOV
709
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
×
710
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
×
711

712
                                        if (vertexTemplate.Vertex.Handle == 0)
×
713
                                        {
×
UNCOV
714
                                                template.PolyLine.Vertices.Add(vertexTemplate.Vertex);
×
715
                                        }
×
716
                                        else
717
                                        {
×
718
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
719
                                                this._builder.AddTemplate(vertexTemplate);
×
UNCOV
720
                                        }
×
721
                                }
×
722

723
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
×
724
                                {
×
UNCOV
725
                                        var seqend = new Seqend();
×
726
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
×
727
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
×
728

729
                                        this._builder.AddTemplate(seqendTemplate);
×
730

UNCOV
731
                                        template.SeqendHandle = seqend.Handle;
×
732
                                }
×
733
                        }
×
734
                        else
735
                        {
5,852✔
736
                                template = new CadPolyLineTemplate();
5,852✔
737
                                this.readEntityCodes<Entity>(template, this.readPolyline);
5,852✔
738
                        }
5,852✔
739

740
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
5,852✔
741
                        {
5,588✔
742
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
5,588✔
743
                                return null;
5,588✔
744
                        }
745

746
                        return template;
264✔
747
                }
5,852✔
748

749
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
750
                {
42,126✔
751
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
42,126✔
752

753
                        switch (this._reader.Code)
42,126✔
754
                        {
755
                                //DXF: always 0
756
                                //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)
757
                                case 10:
758
                                case 20:
759
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
760
                                case 66:
761
                                //Polygon mesh M vertex count (optional; default = 0)
762
                                case 71:
763
                                //Polygon mesh N vertex count(optional; default = 0)
764
                                case 72:
765
                                //Smooth surface M density(optional; default = 0)
766
                                case 73:
767
                                //Smooth surface N density (optional; default = 0)
768
                                case 74:
769
                                        return true;
17,864✔
770
                                case 100:
771
                                        switch (this._reader.ValueAsString)
528!
772
                                        {
773
                                                case DxfSubclassMarker.Polyline:
UNCOV
774
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
UNCOV
775
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
UNCOV
776
                                                        return true;
×
777
                                                case DxfSubclassMarker.Polyline3d:
778
                                                        tmp.SetPolyLineObject(new Polyline3D());
132✔
779
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
132✔
780
                                                        return true;
132✔
781
                                                case DxfSubclassMarker.PolyfaceMesh:
782
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
132✔
783
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
132✔
784
                                                        return true;
132✔
785
                                                default:
786
                                                        return false;
264✔
787
                                        }
788
                                default:
789
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
23,734✔
790
                        }
791
                }
42,126✔
792

793
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
794
                {
3,300✔
795
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
3,300✔
796

797
                        switch (this._reader.Code)
3,300✔
798
                        {
799
                                case 3:
800
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
132✔
801
                                        return true;
132✔
802
                                case 10:
803
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
528✔
804
                                        return true;
528✔
805
                                case 20:
806
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
528✔
807
                                        y.Y = this._reader.ValueAsDouble;
528✔
808
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
528✔
809
                                        return true;
528✔
810
                                case 30:
811
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
528✔
812
                                        z.Z = this._reader.ValueAsDouble;
528✔
813
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
528✔
814
                                        return true;
528✔
815
                                case 340:
816
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
132✔
817
                                        return true;
132✔
818
                                //Vertices count
819
                                case 76:
820
                                        return true;
132✔
821
                                default:
822
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,320✔
823
                        }
824
                }
3,300✔
825

826
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
827
                {
30,719✔
828
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
30,719✔
829

830
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
30,719✔
831

832
                        switch (this._reader.Code)
30,719!
833
                        {
834
                                case 10:
835
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
7,100✔
836
                                        return true;
7,100✔
837
                                case 20:
838
                                        if (last is not null)
7,100✔
839
                                        {
7,100✔
840
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
7,100✔
841
                                        }
7,100✔
842
                                        return true;
7,100✔
843
                                case 40:
844
                                        if (last is not null)
1,320✔
845
                                        {
1,320✔
846
                                                last.StartWidth = this._reader.ValueAsDouble;
1,320✔
847
                                        }
1,320✔
848
                                        return true;
1,320✔
849
                                case 41:
850
                                        if (last is not null)
1,320✔
851
                                        {
1,320✔
852
                                                last.EndWidth = this._reader.ValueAsDouble;
1,320✔
853
                                        }
1,320✔
854
                                        return true;
1,320✔
855
                                case 42:
856
                                        if (last is not null)
1,776✔
857
                                        {
1,776✔
858
                                                last.Bulge = this._reader.ValueAsDouble;
1,776✔
859
                                        }
1,776✔
860
                                        return true;
1,776✔
861
                                case 50:
UNCOV
862
                                        if (last is not null)
×
UNCOV
863
                                        {
×
UNCOV
864
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
UNCOV
865
                                        }
×
UNCOV
866
                                        return true;
×
867
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
868
                                case 66:
869
                                //Vertex count
870
                                case 90:
871
                                        return true;
1,448✔
872
                                case 91:
873
                                        if (last is not null)
×
874
                                        {
×
875
                                                last.Id = this._reader.ValueAsInt;
×
UNCOV
876
                                        }
×
UNCOV
877
                                        return true;
×
878
                                default:
879
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,655✔
880
                        }
881
                }
30,719✔
882

883
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
884
                {
23,232✔
885
                        CadMeshTemplate tmp = template as CadMeshTemplate;
23,232✔
886

887
                        switch (this._reader.Code)
23,232✔
888
                        {
889
                                case 100:
890
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
528✔
891
                                        {
264✔
892
                                                tmp.SubclassMarker = true;
264✔
893
                                        }
264✔
894
                                        return true;
528✔
895
                                //Count of sub-entity which property has been overridden
896
                                case 90:
897
                                        //TODO: process further entities
898
                                        return true;
264✔
899
                                case 92:
900
                                        if (!tmp.SubclassMarker)
396✔
901
                                        {
132✔
902
                                                return false;
132✔
903
                                        }
904

905
                                        int nvertices = this._reader.ValueAsInt;
264✔
906
                                        for (int i = 0; i < nvertices; i++)
33,792✔
907
                                        {
16,632✔
908
                                                this._reader.ReadNext();
16,632✔
909
                                                double x = this._reader.ValueAsDouble;
16,632✔
910
                                                this._reader.ReadNext();
16,632✔
911
                                                double y = this._reader.ValueAsDouble;
16,632✔
912
                                                this._reader.ReadNext();
16,632✔
913
                                                double z = this._reader.ValueAsDouble;
16,632✔
914
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
16,632✔
915
                                        }
16,632✔
916
                                        return true;
264✔
917
                                case 93:
918
                                        int size = this._reader.ValueAsInt;
264✔
919
                                        this._reader.ReadNext();
264✔
920

921
                                        int indexes = 0;
264✔
922
                                        for (int i = 0; i < size; i += indexes + 1)
36,432✔
923
                                        {
17,952✔
924
                                                indexes = this._reader.ValueAsInt;
17,952✔
925
                                                this._reader.ReadNext();
17,952✔
926

927
                                                int[] face = new int[indexes];
17,952✔
928
                                                for (int j = 0; j < indexes; j++)
173,184✔
929
                                                {
68,640✔
930
                                                        face[j] = this._reader.ValueAsInt;
68,640✔
931

932
                                                        if ((i + j + 2) < size)
68,640✔
933
                                                        {
68,376✔
934
                                                                this._reader.ReadNext();
68,376✔
935
                                                        }
68,376✔
936
                                                }
68,640✔
937

938
                                                tmp.CadObject.Faces.Add(face);
17,952✔
939
                                        }
17,952✔
940

941
                                        Debug.Assert(this._reader.Code == 90);
264✔
942

943
                                        return true;
264✔
944
                                case 94:
945
                                        int numEdges = this._reader.ValueAsInt;
264✔
946
                                        this._reader.ReadNext();
264✔
947
                                        for (int i = 0; i < numEdges; i++)
69,168✔
948
                                        {
34,320✔
949
                                                Mesh.Edge edge = new Mesh.Edge();
34,320✔
950

951
                                                edge.Start = this._reader.ValueAsInt;
34,320✔
952
                                                this._reader.ReadNext();
34,320✔
953
                                                edge.End = this._reader.ValueAsInt;
34,320✔
954

955
                                                if (i < numEdges - 1)
34,320✔
956
                                                {
34,056✔
957
                                                        this._reader.ReadNext();
34,056✔
958
                                                }
34,056✔
959

960
                                                tmp.CadObject.Edges.Add(edge);
34,320✔
961
                                        }
34,320✔
962

963
                                        Debug.Assert(this._reader.Code == 90);
264✔
964

965
                                        return true;
264✔
966
                                case 95:
967
                                        this._reader.ReadNext();
264✔
968
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
69,168✔
969
                                        {
34,320✔
970
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
34,320✔
971
                                                edge.Crease = this._reader.ValueAsDouble;
34,320✔
972

973
                                                tmp.CadObject.Edges[i] = edge;
34,320✔
974

975
                                                if (i < tmp.CadObject.Edges.Count - 1)
34,320✔
976
                                                {
34,056✔
977
                                                        this._reader.ReadNext();
34,056✔
978
                                                }
34,056✔
979
                                        }
34,320✔
980

981
                                        Debug.Assert(this._reader.Code == 140);
264✔
982

983
                                        return true;
264✔
984
                                default:
985
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
21,252✔
986
                        }
987
                }
23,232✔
988

989
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
990
                {
34,320✔
991
                        CadMLineTemplate tmp = template as CadMLineTemplate;
34,320✔
992

993
                        switch (this._reader.Code)
34,320✔
994
                        {
995
                                // 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.
996
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
997
                                case 2:
998
                                        tmp.MLineStyleName = this._reader.ValueAsString;
396✔
999
                                        return true;
396✔
1000
                                case 72:
1001
                                        tmp.NVertex = this._reader.ValueAsInt;
396✔
1002
                                        return true;
396✔
1003
                                case 73:
1004
                                        tmp.NElements = this._reader.ValueAsInt;
396✔
1005
                                        return true;
396✔
1006
                                case 340:
1007
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
396✔
1008
                                        return true;
396✔
1009
                                default:
1010
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
32,736✔
1011
                                        {
5,544✔
1012
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
5,544✔
1013
                                        }
1014
                                        return true;
27,192✔
1015
                        }
1016
                }
34,320✔
1017

1018
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1019
                {
1,320✔
1020
                        CadShapeTemplate tmp = template as CadShapeTemplate;
1,320✔
1021

1022
                        switch (this._reader.Code)
1,320✔
1023
                        {
1024
                                case 2:
1025
                                        tmp.ShapeFileName = this._reader.ValueAsString;
132✔
1026
                                        return true;
132✔
1027
                                default:
1028
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,188✔
1029
                        }
1030
                }
1,320✔
1031

1032
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1033
                {
9,240✔
1034
                        CadSplineTemplate tmp = template as CadSplineTemplate;
9,240✔
1035

1036
                        XYZ controlPoint;
1037

1038
                        switch (this._reader.Code)
9,240!
1039
                        {
1040
                                case 10:
1041
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,056✔
1042
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,056✔
1043
                                        return true;
1,056✔
1044
                                case 20:
1045
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,056✔
1046
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,056✔
1047
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,056✔
1048
                                        return true;
1,056✔
1049
                                case 30:
1050
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,056✔
1051
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,056✔
1052
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,056✔
1053
                                        return true;
1,056✔
1054
                                case 40:
1055
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
2,112✔
1056
                                        return true;
2,112✔
1057
                                case 41:
UNCOV
1058
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
UNCOV
1059
                                        return true;
×
1060
                                case 72:
1061
                                case 73:
1062
                                case 74:
1063
                                        return true;
792✔
1064
                                default:
1065
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,168✔
1066
                        }
1067
                }
9,240✔
1068

1069
                private bool readUnderlayEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1070
                {
×
UNCOV
1071
                        CadPdfUnderlayTemplate tmp = template as CadPdfUnderlayTemplate;
×
1072

UNCOV
1073
                        switch (this._reader.Code)
×
1074
                        {
1075
                                case 340:
UNCOV
1076
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
×
UNCOV
1077
                                        return true;
×
1078
                                default:
1079
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1080
                        }
UNCOV
1081
                }
×
1082

1083
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1084
                {
138,544✔
1085
                        CadVertexTemplate tmp = template as CadVertexTemplate;
138,544✔
1086

1087
                        switch (this._reader.Code)
138,544✔
1088
                        {
1089
                                //Polyface mesh vertex index
1090
                                case 71:
1091
                                case 72:
1092
                                case 73:
1093
                                case 74:
1094
                                        return true;
1,078✔
1095
                                case 100:
1096
                                        switch (this._reader.ValueAsString)
4,488!
1097
                                        {
1098
                                                case DxfSubclassMarker.Vertex:
1099
                                                        return true;
1,320✔
1100
                                                case DxfSubclassMarker.PolylineVertex:
UNCOV
1101
                                                        tmp.SetVertexObject(new Vertex2D());
×
UNCOV
1102
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
UNCOV
1103
                                                        return true;
×
1104
                                                case DxfSubclassMarker.Polyline3dVertex:
1105
                                                        tmp.SetVertexObject(new Vertex3D());
660✔
1106
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
660✔
1107
                                                        return true;
660✔
1108
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1109
                                                        tmp.SetVertexObject(new VertexFaceMesh());
660✔
1110
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
660✔
1111
                                                        return true;
660✔
1112
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1113
                                                        tmp.SetVertexObject(new VertexFaceRecord());
264✔
1114
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
264✔
1115
                                                        return true;
264✔
1116
                                                default:
1117
                                                        return false;
1,584✔
1118
                                        }
1119
                                default:
1120
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
132,978✔
1121
                        }
1122
                }
138,544✔
1123

1124
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1125
                {
43,016✔
1126
                        CadViewportTemplate tmp = template as CadViewportTemplate;
43,016✔
1127

1128
                        switch (this._reader.Code)
43,016!
1129
                        {
1130
                                //Undocumented
1131
                                case 67:
1132
                                case 68:
1133
                                        return true;
1,576✔
1134
                                case 69:
1135
                                        tmp.ViewportId = this._reader.ValueAsShort;
788✔
1136
                                        return true;
788✔
1137
                                case 331:
UNCOV
1138
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
UNCOV
1139
                                        return true;
×
1140
                                case 348:
1141
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
496✔
1142
                                        return true;
496✔
1143
                                default:
1144
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
40,156✔
1145
                        }
1146
                }
43,016✔
1147

1148
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1149
                {
398,739✔
1150
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
398,739✔
1151

1152
                        switch (this._reader.Code)
398,739✔
1153
                        {
1154
                                default:
1155
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
398,739✔
1156
                        }
1157
                }
398,739✔
1158

1159
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1160
                {
14,031✔
1161
                        List<ExtendedDataRecord> records = new();
14,031✔
1162
                        edata.Add(this._reader.ValueAsString, records);
14,031✔
1163

1164
                        this._reader.ReadNext();
14,031✔
1165

1166
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
65,798✔
1167
                        {
56,006✔
1168
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
56,006✔
1169
                                {
4,239✔
1170
                                        this.readExtendedData(edata);
4,239✔
1171
                                        break;
4,239✔
1172
                                }
1173

1174
                                ExtendedDataRecord record = null;
51,767✔
1175
                                double x = 0;
51,767✔
1176
                                double y = 0;
51,767✔
1177
                                double z = 0;
51,767✔
1178

1179
                                switch (this._reader.DxfCode)
51,767✔
1180
                                {
1181
                                        case DxfCode.ExtendedDataAsciiString:
1182
                                        case DxfCode.ExtendedDataRegAppName:
1183
                                                record = new ExtendedDataString(this._reader.ValueAsString);
13,108✔
1184
                                                break;
13,108✔
1185
                                        case DxfCode.ExtendedDataControlString:
1186
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
3,764✔
1187
                                                break;
3,764✔
1188
                                        case DxfCode.ExtendedDataLayerName:
1189
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
1!
1190
                                                {
1✔
1191
                                                        record = new ExtendedDataLayer(layer.Handle);
1✔
1192
                                                }
1✔
1193
                                                else
UNCOV
1194
                                                {
×
UNCOV
1195
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
×
UNCOV
1196
                                                }
×
1197
                                                break;
1✔
1198
                                        case DxfCode.ExtendedDataBinaryChunk:
1199
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
2✔
1200
                                                break;
2✔
1201
                                        case DxfCode.ExtendedDataHandle:
1202
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
466✔
1203
                                                break;
466✔
1204
                                        case DxfCode.ExtendedDataXCoordinate:
1205
                                                x = this._reader.ValueAsDouble;
727✔
1206
                                                this._reader.ReadNext();
727✔
1207
                                                y = this._reader.ValueAsDouble;
727✔
1208
                                                this._reader.ReadNext();
727✔
1209
                                                z = this._reader.ValueAsDouble;
727✔
1210

1211
                                                record = new ExtendedDataCoordinate(
727✔
1212
                                                        new XYZ(
727✔
1213
                                                                x,
727✔
1214
                                                                y,
727✔
1215
                                                                z)
727✔
1216
                                                        );
727✔
1217
                                                break;
727✔
1218
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1219
                                                x = this._reader.ValueAsDouble;
309✔
1220
                                                this._reader.ReadNext();
309✔
1221
                                                y = this._reader.ValueAsDouble;
309✔
1222
                                                this._reader.ReadNext();
309✔
1223
                                                z = this._reader.ValueAsDouble;
309✔
1224

1225
                                                record = new ExtendedDataWorldCoordinate(
309✔
1226
                                                        new XYZ(
309✔
1227
                                                                x,
309✔
1228
                                                                y,
309✔
1229
                                                                z)
309✔
1230
                                                        );
309✔
1231
                                                break;
309✔
1232
                                        case DxfCode.ExtendedDataWorldXDisp:
1233
                                                x = this._reader.ValueAsDouble;
1✔
1234
                                                this._reader.ReadNext();
1✔
1235
                                                y = this._reader.ValueAsDouble;
1✔
1236
                                                this._reader.ReadNext();
1✔
1237
                                                z = this._reader.ValueAsDouble;
1✔
1238

1239
                                                record = new ExtendedDataDisplacement(
1✔
1240
                                                        new XYZ(
1✔
1241
                                                                x,
1✔
1242
                                                                y,
1✔
1243
                                                                z)
1✔
1244
                                                        );
1✔
1245
                                                break;
1✔
1246
                                        case DxfCode.ExtendedDataWorldXDir:
1247
                                                x = this._reader.ValueAsDouble;
1✔
1248
                                                this._reader.ReadNext();
1✔
1249
                                                y = this._reader.ValueAsDouble;
1✔
1250
                                                this._reader.ReadNext();
1✔
1251
                                                z = this._reader.ValueAsDouble;
1✔
1252

1253
                                                record = new ExtendedDataDirection(
1✔
1254
                                                        new XYZ(
1✔
1255
                                                                x,
1✔
1256
                                                                y,
1✔
1257
                                                                z)
1✔
1258
                                                        );
1✔
1259
                                                break;
1✔
1260
                                        case DxfCode.ExtendedDataReal:
1261
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
7,664✔
1262
                                                break;
7,664✔
1263
                                        case DxfCode.ExtendedDataDist:
1264
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
1✔
1265
                                                break;
1✔
1266
                                        case DxfCode.ExtendedDataScale:
1267
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
1✔
1268
                                                break;
1✔
1269
                                        case DxfCode.ExtendedDataInteger16:
1270
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
21,869✔
1271
                                                break;
21,869✔
1272
                                        case DxfCode.ExtendedDataInteger32:
1273
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
3,237✔
1274
                                                break;
3,237✔
1275
                                        default:
1276
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
616✔
1277
                                                break;
616✔
1278
                                }
1279

1280
                                if (record != null)
51,767✔
1281
                                {
51,151✔
1282
                                        records.Add(record);
51,151✔
1283
                                }
51,151✔
1284

1285
                                this._reader.ReadNext();
51,767✔
1286
                        }
51,767✔
1287
                }
14,031✔
1288

1289
                private void readPattern(HatchPattern pattern, int nlines)
1290
                {
284✔
1291
                        //Jump 78 code
1292
                        this._reader.ReadNext();
284✔
1293

1294
                        for (int i = 0; i < nlines; i++)
8,868✔
1295
                        {
4,150✔
1296
                                HatchPattern.Line line = new HatchPattern.Line();
4,150✔
1297
                                XY basePoint = new XY();
4,150✔
1298
                                XY offset = new XY();
4,150✔
1299

1300
                                bool end = false;
4,150✔
1301
                                HashSet<int> codes = new();
4,150✔
1302

1303
                                while (!end)
29,334✔
1304
                                {
29,050✔
1305
                                        if (codes.Contains(this._reader.Code))
29,050✔
1306
                                        {
3,866✔
1307
                                                break;
3,866✔
1308
                                        }
1309
                                        else
1310
                                        {
25,184✔
1311
                                                codes.Add(this._reader.Code);
25,184✔
1312
                                        }
25,184✔
1313

1314
                                        switch (this._reader.Code)
25,184!
1315
                                        {
1316
                                                case 53:
1317
                                                        line.Angle = this._reader.ValueAsAngle;
4,150✔
1318
                                                        break;
4,150✔
1319
                                                case 43:
1320
                                                        basePoint.X = this._reader.ValueAsDouble;
4,150✔
1321
                                                        break;
4,150✔
1322
                                                case 44:
1323
                                                        basePoint.Y = this._reader.ValueAsDouble;
4,150✔
1324
                                                        line.BasePoint = basePoint;
4,150✔
1325
                                                        break;
4,150✔
1326
                                                case 45:
1327
                                                        offset.X = this._reader.ValueAsDouble;
4,150✔
1328
                                                        line.Offset = offset;
4,150✔
1329
                                                        break;
4,150✔
1330
                                                case 46:
1331
                                                        offset.Y = this._reader.ValueAsDouble;
4,150✔
1332
                                                        line.Offset = offset;
4,150✔
1333
                                                        break;
4,150✔
1334
                                                //Number of dash length items
1335
                                                case 79:
1336
                                                        int ndash = this._reader.ValueAsInt;
4,150✔
1337
                                                        for (int j = 0; j < ndash; j++)
24,372✔
1338
                                                        {
8,036✔
1339
                                                                this._reader.ReadNext();
8,036✔
1340
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
8,036✔
1341
                                                        }
8,036✔
1342
                                                        break;
4,150✔
1343
                                                case 49:
UNCOV
1344
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
UNCOV
1345
                                                        break;
×
1346
                                                default:
1347
                                                        end = true;
284✔
1348
                                                        break;
284✔
1349
                                        }
1350
                                        this._reader.ReadNext();
25,184✔
1351
                                }
25,184✔
1352

1353
                                pattern.Lines.Add(line);
4,150✔
1354
                        }
4,150✔
1355
                }
284✔
1356

1357
                private void readLoops(CadHatchTemplate template, int count)
1358
                {
548✔
1359
                        if (this._reader.Code == 91)
548✔
1360
                                this._reader.ReadNext();
548✔
1361

1362
                        for (int i = 0; i < count; i++)
2,192✔
1363
                        {
548✔
1364
                                if (this._reader.Code != 92)
548!
UNCOV
1365
                                {
×
UNCOV
1366
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
UNCOV
1367
                                        break;
×
1368
                                }
1369

1370
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
548✔
1371
                                if (path != null)
548✔
1372
                                        template.PathTempaltes.Add(path);
548✔
1373
                        }
548✔
1374
                }
548✔
1375

1376
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1377
                {
548✔
1378
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
548✔
1379
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
548✔
1380
                        template.Path.Flags = flags;
548✔
1381

1382
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
548✔
1383
                        {
15✔
1384
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
15✔
1385
                                template.Path.Edges.Add(pl);
15✔
1386
                        }
15✔
1387
                        else
1388
                        {
533✔
1389
                                this._reader.ReadNext();
533✔
1390

1391
                                if (this._reader.Code != 93)
533!
UNCOV
1392
                                {
×
UNCOV
1393
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
UNCOV
1394
                                        return null;
×
1395
                                }
1396

1397
                                int edges = this._reader.ValueAsInt;
533✔
1398
                                this._reader.ReadNext();
533✔
1399

1400
                                for (int i = 0; i < edges; i++)
5,330✔
1401
                                {
2,132✔
1402
                                        var edge = this.readEdge();
2,132✔
1403
                                        if (edge != null)
2,132✔
1404
                                                template.Path.Edges.Add(edge);
2,132✔
1405
                                }
2,132✔
1406
                        }
533✔
1407

1408
                        bool end = false;
548✔
1409
                        while (!end)
2,187✔
1410
                        {
1,639✔
1411
                                switch (this._reader.Code)
1,639✔
1412
                                {
1413
                                        //Number of source boundary objects
1414
                                        case 97:
1415
                                                break;
548✔
1416
                                        case 330:
1417
                                                template.Handles.Add(this._reader.ValueAsHandle);
543✔
1418
                                                break;
543✔
1419
                                        default:
1420
                                                end = true;
548✔
1421
                                                continue;
548✔
1422
                                }
1423

1424
                                this._reader.ReadNext();
1,091✔
1425
                        }
1,091✔
1426

1427
                        return template;
548✔
1428
                }
548✔
1429

1430
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1431
                {
15✔
1432
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
15✔
1433

1434
                        this._reader.ReadNext();
15✔
1435

1436
                        if (this._reader.Code != 72)
15!
UNCOV
1437
                        {
×
UNCOV
1438
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
UNCOV
1439
                                return null;
×
1440
                        }
1441

1442
                        //72
1443
                        bool hasBulge = this._reader.ValueAsBool;
15✔
1444
                        this._reader.ReadNext();
15✔
1445

1446
                        //73
1447
                        bool isClosed = this._reader.ValueAsBool;
15✔
1448
                        this._reader.ReadNext();
15✔
1449

1450
                        //93
1451
                        int nvertices = this._reader.ValueAsInt;
15✔
1452
                        this._reader.ReadNext();
15✔
1453

1454
                        for (int i = 0; i < nvertices; i++)
150✔
1455
                        {
60✔
1456
                                double bulge = 0.0;
60✔
1457

1458
                                //10
1459
                                double x = this._reader.ValueAsDouble;
60✔
1460
                                this._reader.ReadNext();
60✔
1461
                                //20
1462
                                double y = this._reader.ValueAsDouble;
60✔
1463
                                this._reader.ReadNext();
60✔
1464

1465
                                if (hasBulge)
60!
UNCOV
1466
                                {
×
1467
                                        //42
UNCOV
1468
                                        bulge = this._reader.ValueAsDouble;
×
UNCOV
1469
                                        this._reader.ReadNext();
×
UNCOV
1470
                                }
×
1471

1472
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
60✔
1473
                        }
60✔
1474

1475
                        return boundary;
15✔
1476
                }
15✔
1477

1478
                private Hatch.BoundaryPath.Edge readEdge()
1479
                {
2,132✔
1480
                        if (this._reader.Code != 72)
2,132!
UNCOV
1481
                        {
×
UNCOV
1482
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
UNCOV
1483
                                return null;
×
1484
                        }
1485

1486
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
2,132✔
1487
                        this._reader.ReadNext();
2,132✔
1488

1489
                        switch (type)
2,132!
1490
                        {
1491
                                case Hatch.BoundaryPath.EdgeType.Line:
1492
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
2,132✔
1493
                                        while (true)
10,660✔
1494
                                        {
10,660✔
1495
                                                switch (this._reader.Code)
10,660✔
1496
                                                {
1497
                                                        case 10:
1498
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
2,132✔
1499
                                                                break;
2,132✔
1500
                                                        case 20:
1501
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
2,132✔
1502
                                                                break;
2,132✔
1503
                                                        case 11:
1504
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
2,132✔
1505
                                                                break;
2,132✔
1506
                                                        case 21:
1507
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
2,132✔
1508
                                                                break;
2,132✔
1509
                                                        default:
1510
                                                                return line;
2,132✔
1511
                                                }
1512

1513
                                                this._reader.ReadNext();
8,528✔
1514
                                        }
8,528✔
1515
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
UNCOV
1516
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
UNCOV
1517
                                        while (true)
×
UNCOV
1518
                                        {
×
UNCOV
1519
                                                switch (this._reader.Code)
×
1520
                                                {
1521
                                                        case 10:
UNCOV
1522
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
UNCOV
1523
                                                                break;
×
1524
                                                        case 20:
1525
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1526
                                                                break;
×
1527
                                                        case 40:
1528
                                                                arc.Radius = this._reader.ValueAsDouble;
×
UNCOV
1529
                                                                break;
×
1530
                                                        case 50:
1531
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1532
                                                                break;
×
1533
                                                        case 51:
1534
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1535
                                                                break;
×
1536
                                                        case 73:
1537
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1538
                                                                break;
×
1539
                                                        default:
1540
                                                                return arc;
×
1541
                                                }
1542

1543
                                                this._reader.ReadNext();
×
1544
                                        }
×
1545
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1546
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1547
                                        while (true)
×
UNCOV
1548
                                        {
×
1549
                                                switch (this._reader.Code)
×
1550
                                                {
1551
                                                        case 10:
1552
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1553
                                                                break;
×
1554
                                                        case 20:
1555
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1556
                                                                break;
×
1557
                                                        case 11:
1558
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
UNCOV
1559
                                                                break;
×
1560
                                                        case 21:
1561
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1562
                                                                break;
×
1563
                                                        case 40:
1564
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1565
                                                                break;
×
1566
                                                        case 50:
1567
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1568
                                                                break;
×
1569
                                                        case 51:
1570
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
1571
                                                                break;
×
1572
                                                        case 73:
1573
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
1574
                                                                break;
×
1575
                                                        default:
1576
                                                                return ellipse;
×
1577
                                                }
1578

1579
                                                this._reader.ReadNext();
×
1580
                                        }
×
1581
                                case Hatch.BoundaryPath.EdgeType.Spline:
1582
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1583
                                        int nKnots = 0;
×
UNCOV
1584
                                        int nCtrlPoints = 0;
×
1585
                                        int nFitPoints = 0;
×
1586

UNCOV
1587
                                        XYZ controlPoint = new XYZ();
×
1588
                                        XY fitPoint = new XY();
×
1589

UNCOV
1590
                                        while (true)
×
1591
                                        {
×
1592
                                                switch (this._reader.Code)
×
1593
                                                {
1594
                                                        case 10:
UNCOV
1595
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1596
                                                                break;
×
1597
                                                        case 20:
UNCOV
1598
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1599
                                                                spline.ControlPoints.Add(controlPoint);
×
1600
                                                                break;
×
1601
                                                        case 11:
UNCOV
1602
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
UNCOV
1603
                                                                break;
×
1604
                                                        case 21:
1605
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
UNCOV
1606
                                                                spline.FitPoints.Add(fitPoint);
×
1607
                                                                break;
×
1608
                                                        case 42:
1609
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
UNCOV
1610
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1611
                                                                break;
×
1612
                                                        case 12:
UNCOV
1613
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1614
                                                                break;
×
1615
                                                        case 22:
1616
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
UNCOV
1617
                                                                break;
×
1618
                                                        case 13:
1619
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1620
                                                                break;
×
1621
                                                        case 23:
1622
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1623
                                                                break;
×
1624
                                                        case 94:
1625
                                                                spline.Degree = this._reader.ValueAsInt;
×
1626
                                                                break;
×
1627
                                                        case 73:
1628
                                                                spline.Rational = this._reader.ValueAsBool;
×
1629
                                                                break;
×
1630
                                                        case 74:
1631
                                                                spline.Periodic = this._reader.ValueAsBool;
×
1632
                                                                break;
×
1633
                                                        case 95:
1634
                                                                nKnots = this._reader.ValueAsInt;
×
1635
                                                                break;
×
1636
                                                        case 96:
1637
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1638
                                                                break;
×
1639
                                                        case 97:
1640
                                                                nFitPoints = this._reader.ValueAsInt;
×
1641
                                                                break;
×
1642
                                                        case 40:
1643
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
1644
                                                                break;
×
1645
                                                        default:
1646
                                                                return spline;
×
1647
                                                }
1648

1649
                                                this._reader.ReadNext();
×
1650
                                        }
×
1651
                        }
1652

1653
                        return null;
×
1654
                }
2,132✔
1655

1656
                private void readDefinedGroups(CadTemplate template)
1657
                {
30,453✔
1658
                        this.readDefinedGroups(out ulong? xdict, out List<ulong> reactorsHandles);
30,453✔
1659

1660
                        template.XDictHandle = xdict;
30,453✔
1661
                        template.ReactorsHandles = reactorsHandles;
30,453✔
1662
                }
30,453✔
1663

1664
                private void readDefinedGroups(out ulong? xdictHandle, out List<ulong> reactors)
1665
                {
30,604✔
1666
                        xdictHandle = null;
30,604✔
1667
                        reactors = new List<ulong>();
30,604✔
1668

1669
                        switch (this._reader.ValueAsString)
30,604✔
1670
                        {
1671
                                case DxfFileToken.DictionaryToken:
1672
                                        this._reader.ReadNext();
5,773✔
1673
                                        xdictHandle = this._reader.ValueAsHandle;
5,773✔
1674
                                        this._reader.ReadNext();
5,773✔
1675
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
5,773✔
1676
                                        return;
5,773✔
1677
                                case DxfFileToken.ReactorsToken:
1678
                                        reactors = this.readReactors();
24,298✔
1679
                                        break;
24,298✔
1680
                                case DxfFileToken.BlkRefToken:
1681
                                default:
1682
                                        do
1683
                                        {
1,332✔
1684
                                                this._reader.ReadNext();
1,332✔
1685
                                        }
1,332✔
1686
                                        while (this._reader.DxfCode != DxfCode.ControlString);
1,332✔
1687
                                        return;
533✔
1688
                        }
1689
                }
30,604✔
1690

1691
                private List<ulong> readReactors()
1692
                {
24,298✔
1693
                        List<ulong> reactors = new List<ulong>();
24,298✔
1694

1695
                        this._reader.ReadNext();
24,298✔
1696

1697
                        while (this._reader.DxfCode != DxfCode.ControlString)
50,358✔
1698
                        {
26,060✔
1699
                                this._reader.ReadNext();
26,060✔
1700
                        }
26,060✔
1701

1702
                        return reactors;
24,298✔
1703
                }
24,298✔
1704

1705
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
1706
                {
1,979,873✔
1707
                        try
1708
                        {
1,979,873✔
1709
                                //Use this method only if the value is not a link between objects
1710
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
1,979,873✔
1711
                                {
736,859✔
1712
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
736,859✔
1713
                                        {
4,068✔
1714
                                                return true;
4,068✔
1715
                                        }
1716

1717
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
732,791!
1718
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
732,791✔
1719
                                        {
34,180✔
1720
                                                return false;
34,180✔
1721
                                        }
1722

1723
                                        object value = this._reader.Value;
698,611✔
1724

1725
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
698,611✔
1726
                                        {
4,433✔
1727
                                                value = (double)value * MathUtils.DegToRadFactor;
4,433✔
1728
                                        }
4,433✔
1729

1730
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
698,611✔
1731

1732
                                        return true;
698,611✔
1733
                                }
1734
                        }
1,243,014✔
UNCOV
1735
                        catch (Exception ex)
×
1736
                        {
×
UNCOV
1737
                                if (!this._builder.Configuration.Failsafe)
×
UNCOV
1738
                                {
×
UNCOV
1739
                                        throw ex;
×
1740
                                }
1741
                                else
UNCOV
1742
                                {
×
UNCOV
1743
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
1744
                                }
×
1745
                        }
×
1746

1747
                        return false;
1,243,014✔
1748
                }
1,979,873✔
1749
        }
1750
}
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

© 2025 Coveralls, Inc