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

DomCR / ACadSharp / 16398608965

20 Jul 2025 09:50AM UTC coverage: 74.718% (-0.3%) from 75.043%
16398608965

Pull #715

github

web-flow
Merge 7702a1e13 into 402a39408
Pull Request #715: Issue 712 pdfunderlay writer

5873 of 8639 branches covered (67.98%)

Branch coverage included in aggregate %.

111 of 253 new or added lines in 18 files covered. (43.87%)

40 existing lines in 3 files now uncovered.

23382 of 30515 relevant lines covered (76.62%)

80843.38 hits per line

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

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

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

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

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

28
                public abstract void Read();
29

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1054
                        XYZ controlPoint;
1055

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

1087
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1088
                        where T : PdfUnderlayDefinition
1089
                {
×
NEW
1090
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
×
1091

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1494
                        return boundary;
684✔
1495
                }
684✔
1496

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

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

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

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

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

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

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

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

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

1672
                        return null;
×
1673
                }
4,560✔
1674

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

1679
                        template.XDictHandle = xdict;
61,941✔
1680
                        template.ReactorsHandles = reactorsHandles;
61,941✔
1681
                }
61,941✔
1682

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

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

1710
                private List<ulong> readReactors()
1711
                {
48,022✔
1712
                        List<ulong> reactors = new List<ulong>();
48,022✔
1713

1714
                        this._reader.ReadNext();
48,022✔
1715

1716
                        while (this._reader.DxfCode != DxfCode.ControlString)
99,668✔
1717
                        {
51,646✔
1718
                                this._reader.ReadNext();
51,646✔
1719
                        }
51,646✔
1720

1721
                        return reactors;
48,022✔
1722
                }
48,022✔
1723

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

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

1742
                                        object value = this._reader.Value;
1,804,769✔
1743

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

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

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

1766
                        return false;
3,102,313✔
1767
                }
4,989,646✔
1768
        }
1769
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc