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

DomCR / ACadSharp / 23797067415

31 Mar 2026 12:23PM UTC coverage: 76.825% (+0.04%) from 76.79%
23797067415

Pull #1015

github

web-flow
Merge 6ef7b9433 into 62e373b60
Pull Request #1015: Improve DXF DIMENSION handling and refactor builder logic

8403 of 11878 branches covered (70.74%)

Branch coverage included in aggregate %.

313 of 357 new or added lines in 5 files covered. (87.68%)

7 existing lines in 4 files now uncovered.

30171 of 38332 relevant lines covered (78.71%)

149220.89 hits per line

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

80.63
/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 System;
8
using System.Collections.Generic;
9
using System.Diagnostics;
10
using System.Linq;
11
using static ACadSharp.IO.Templates.CadMLeaderAnnotContextTemplate;
12
using static ACadSharp.IO.Templates.CadTableEntityTemplate;
13

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

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

23
                //Avoid to move the reader to the next line
24
                protected bool lockPointer = false;
960✔
25
                protected string currentSubclass = null;
960✔
26

27
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
960✔
28
                {
960✔
29
                        this._reader = reader;
960✔
30
                        this._builder = builder;
960✔
31
                }
960✔
32

33
                public abstract void Read();
34

35
                protected void readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out HashSet<ulong> reactors)
36
                {
2,261✔
37
                        name = null;
2,261✔
38
                        handle = 0;
2,261✔
39
                        ownerHandle = null;
2,261✔
40
                        xdictHandle = null;
2,261✔
41
                        reactors = new HashSet<ulong>();
2,261✔
42

43
                        if (this._reader.DxfCode == DxfCode.Start
2,261!
44
                                        || this._reader.DxfCode == DxfCode.Subclass)
2,261✔
45
                                this._reader.ReadNext();
×
46

47
                        //Loop until the common data end
48
                        while (this._reader.DxfCode != DxfCode.Start
8,981✔
49
                                        && this._reader.DxfCode != DxfCode.Subclass)
8,981✔
50
                        {
6,720✔
51
                                switch (this._reader.Code)
6,720!
52
                                {
53
                                        //Table name
54
                                        case 2:
55
                                                name = this._reader.ValueAsString;
2,261✔
56
                                                break;
2,261✔
57
                                        //Handle
58
                                        case 5:
59
                                        case 105:
60
                                                handle = this._reader.ValueAsHandle;
1,989✔
61
                                                break;
1,989✔
62
                                        //Start of application - defined group
63
                                        case 102:
64
                                                this.readDefinedGroups(out xdictHandle, out reactors);
209✔
65
                                                break;
209✔
66
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
67
                                        case 330:
68
                                                ownerHandle = this._reader.ValueAsHandle;
1,989✔
69
                                                break;
1,989✔
70
                                        case 71:
71
                                        //Number of entries for dimension style table
72
                                        case 340:
73
                                        //Dimension table has the handles of the styles at the begining
74
                                        default:
75
                                                this._builder.Notify($"Unhandled dxf code {this._reader.Code} at line {this._reader.Position}.");
272✔
76
                                                break;
272✔
77
                                }
78

79
                                this._reader.ReadNext();
6,720✔
80
                        }
6,720✔
81
                }
2,261✔
82

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

111
                                this._reader.ReadNext();
1,728✔
112
                        }
1,728✔
113
                }
576✔
114

115
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
116
                {
792,368✔
117
                        isExtendedData = false;
792,368✔
118

119
                        switch (this._reader.Code)
792,368✔
120
                        {
121
                                //Handle
122
                                case 5:
123
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
297,881✔
124
                                        break;
297,881✔
125
                                //Check with mapper
126
                                case 100:
127
                                        this.currentSubclass = this._reader.ValueAsString;
207,104✔
128
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
207,104!
129
                                        {
1,064✔
130
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
1,064✔
131
                                        }
1,064✔
132
                                        break;
207,104✔
133
                                //Start of application - defined group
134
                                case 102:
135
                                        this.readDefinedGroups(template);
67,655✔
136
                                        break;
67,655✔
137
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
138
                                case 330:
139
                                        template.OwnerHandle = this._reader.ValueAsHandle;
168,629✔
140
                                        break;
168,629✔
141
                                case 1001:
142
                                        isExtendedData = true;
23,175✔
143
                                        this.readExtendedData(template.EDataTemplateByAppName);
23,175✔
144
                                        break;
23,175✔
145
                                default:
146
                                        this._builder.Notify($"[{this.currentSubclass}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
27,924✔
147
                                        break;
27,924✔
148
                        }
149
                }
792,368✔
150

151
                protected CadEntityTemplate readEntity()
152
                {
145,967✔
153
                        this.currentSubclass = string.Empty;
145,967✔
154
                        switch (this._reader.ValueAsString)
145,967!
155
                        {
156
                                case DxfFileToken.EntityAttribute:
157
                                        return this.readEntityCodes<AttributeEntity>(new CadAttributeTemplate(new AttributeEntity()), this.readAttributeDefinition);
952✔
158
                                case DxfFileToken.EntityAttributeDefinition:
159
                                        return this.readEntityCodes<AttributeDefinition>(new CadAttributeTemplate(new AttributeDefinition()), this.readAttributeDefinition);
1,120✔
160
                                case DxfFileToken.EntityArc:
161
                                        return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), this.readArc);
686✔
162
                                case DxfFileToken.EntityBody:
163
                                        return this.readEntityCodes<CadBody>(new CadEntityTemplate<CadBody>(), this.readEntitySubclassMap);
×
164
                                case DxfFileToken.EntityCircle:
165
                                        return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), this.readCircle);
3,044✔
166
                                case DxfFileToken.EntityDimension:
167
                                        var dimTemplate = this.readEntityCodes<Dimension>(new CadDimensionTemplate(), this.readDimension);
2,618✔
168
                                        if (dimTemplate.CadObject is CadDimensionTemplate.DimensionPlaceholder)
2,618✔
169
                                        {
34✔
170
                                                this._builder.Notify($"[{DxfFileToken.EntityDimension}] No subtype found, object discarded.", NotificationType.Warning);
34✔
171
                                                return null;
34✔
172
                                        }
173
                                        return dimTemplate;
2,584✔
174
                                case DxfFileToken.Entity3DFace:
175
                                        return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), this.readEntitySubclassMap);
238✔
176
                                case DxfFileToken.EntityEllipse:
177
                                        return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), this.readEntitySubclassMap);
204✔
178
                                case DxfFileToken.EntityLeader:
179
                                        return this.readEntityCodes<Leader>(new CadLeaderTemplate(), this.readLeader);
204✔
180
                                case DxfFileToken.EntityLine:
181
                                        return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), this.readEntitySubclassMap);
61,596✔
182
                                case DxfFileToken.EntityLwPolyline:
183
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
4,690✔
184
                                case DxfFileToken.EntityMesh:
185
                                        return this.readEntityCodes<Mesh>(new CadMeshTemplate(), this.readMesh);
408✔
186
                                case DxfFileToken.EntityHatch:
187
                                        return this.readEntityCodes<Hatch>(new CadHatchTemplate(), this.readHatch);
1,632✔
188
                                case DxfFileToken.EntityInsert:
189
                                        return this.readEntityCodes<Insert>(new CadInsertTemplate(), this.readInsert);
5,517✔
190
                                case DxfFileToken.EntityMText:
191
                                        return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), this.readTextEntity);
6,972✔
192
                                case DxfFileToken.EntityMLine:
193
                                        return this.readEntityCodes<MLine>(new CadMLineTemplate(), this.readMLine);
612✔
194
                                case DxfFileToken.EntityMultiLeader:
195
                                        return this.readEntityCodes<MultiLeader>(new CadMLeaderTemplate(), this.readMLeader);
3,060✔
196
                                case DxfFileToken.EntityPdfUnderlay:
197
                                        return this.readEntityCodes<PdfUnderlay>(new CadUnderlayTemplate<PdfUnderlayDefinition>(new PdfUnderlay()), this.readUnderlayEntity<PdfUnderlayDefinition>);
204✔
198
                                case DxfFileToken.EntityPoint:
199
                                        return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), this.readEntitySubclassMap);
9,044✔
200
                                case DxfFileToken.EntityPolyline:
201
                                        return this.readPolyline();
10,444✔
202
                                case DxfFileToken.EntityOle2Frame:
203
                                        return this.readEntityCodes<Ole2Frame>(new CadOle2FrameTemplate(), this.readOle2Frame);
×
204
                                case DxfFileToken.EntityRay:
205
                                        return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), this.readEntitySubclassMap);
204✔
206
                                case DxfFileToken.EndSequence:
207
                                        return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), this.readEntitySubclassMap);
476✔
208
                                case DxfFileToken.EntityTrace:
209
                                case DxfFileToken.EntitySolid:
210
                                        return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), this.readModelerGeometry);
13,742✔
211
                                case DxfFileToken.EntityTable:
212
                                        return this.readEntityCodes<TableEntity>(new CadTableEntityTemplate(), this.readTableEntity);
408✔
213
                                case DxfFileToken.EntityText:
214
                                        return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), this.readTextEntity);
14,166✔
215
                                case DxfFileToken.EntityTolerance:
216
                                        return this.readEntityCodes<Tolerance>(new CadToleranceTemplate(new Tolerance()), this.readTolerance);
612✔
217
                                case DxfFileToken.EntityVertex:
218
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
×
219
                                case DxfFileToken.EntityViewport:
220
                                        return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
1,244✔
221
                                case DxfFileToken.EntityShape:
222
                                        return this.readEntityCodes<Shape>(new CadShapeTemplate(new Shape()), this.readShape);
238✔
223
                                case DxfFileToken.EntitySpline:
224
                                        return this.readEntityCodes<Spline>(new CadSplineTemplate(), this.readSpline);
408✔
225
                                case DxfFileToken.Entity3DSolid:
226
                                        return this.readEntityCodes<Solid3D>(new CadSolid3DTemplate(), this.readSolid3d);
408✔
227
                                case DxfFileToken.EntityRegion:
228
                                        return this.readEntityCodes<Region>(new CadEntityTemplate<Region>(), this.readModelerGeometry);
204✔
229
                                case DxfFileToken.EntityImage:
230
                                        return this.readEntityCodes<RasterImage>(new CadWipeoutBaseTemplate(new RasterImage()), this.readWipeoutBase);
204✔
231
                                case DxfFileToken.EntityWipeout:
232
                                        return this.readEntityCodes<Wipeout>(new CadWipeoutBaseTemplate(new Wipeout()), this.readWipeoutBase);
204✔
233
                                case DxfFileToken.EntityXline:
234
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
204✔
235
                                default:
236
                                        DxfMap map = DxfMap.Create<Entity>();
×
237
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
×
238
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
×
239
                                        {
×
240
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
×
241
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
×
242
                                        }
×
243
                                        else
244
                                        {
×
245
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
×
246
                                        }
×
247

248
                                        this._reader.ReadNext();
×
249

250
                                        do
251
                                        {
×
252
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
×
253
                                                {
×
254
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
×
255
                                                        if (isExtendedData)
×
256
                                                                continue;
×
257
                                                }
×
258

259
                                                this._reader.ReadNext();
×
260
                                        }
×
261
                                        while (this._reader.DxfCode != DxfCode.Start);
×
262

263
                                        return unknownEntityTemplate;
×
264
                        }
265
                }
145,967✔
266

267
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
268
                        where T : Entity
269
                {
194,785✔
270
                        this._reader.ReadNext();
194,785✔
271

272
                        DxfMap map = DxfMap.Create<T>();
194,785✔
273

274
                        while (this._reader.DxfCode != DxfCode.Start)
2,638,239✔
275
                        {
2,443,454✔
276
                                if (!readEntity(template, map))
2,443,454✔
277
                                {
855,362✔
278
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
855,362✔
279
                                        if (isExtendedData)
855,362✔
280
                                                continue;
13,666✔
281
                                }
841,696✔
282

283
                                if (this.lockPointer)
2,429,788✔
284
                                {
2,992✔
285
                                        this.lockPointer = false;
2,992✔
286
                                        continue;
2,992✔
287
                                }
288

289
                                if (this._reader.DxfCode != DxfCode.Start)
2,426,796✔
290
                                        this._reader.ReadNext();
2,426,322✔
291
                        }
2,426,796✔
292

293
                        return template;
194,785✔
294
                }
194,785✔
295

296
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
297
                {
922,887✔
298
                        isExtendedData = false;
922,887✔
299
                        switch (this._reader.Code)
922,887✔
300
                        {
301
                                case 6:
302
                                        template.LineTypeName = this._reader.ValueAsString;
25,676✔
303
                                        break;
25,676✔
304
                                case 8:
305
                                        template.LayerName = this._reader.ValueAsString;
211,285✔
306
                                        break;
211,285✔
307
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
308
                                case 67:
309
                                        break;
1,236✔
310
                                //Number of bytes Proxy entity graphics data
311
                                case 92:
312
                                case 160:
313
                                //Proxy entity graphics data
314
                                case 310:
315
                                        break;
76,568✔
316
                                case 347:
317
                                        template.MaterialHandle = this._reader.ValueAsHandle;
680✔
318
                                        break;
680✔
319
                                case 430:
320
                                        template.BookColorName = this._reader.ValueAsString;
170✔
321
                                        break;
170✔
322
                                default:
323
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
607,272✔
324
                                        {
473,074✔
325
                                                this.readCommonCodes(template, out isExtendedData, map);
473,074✔
326
                                        }
473,074✔
327
                                        break;
607,272✔
328
                        }
329
                }
922,887✔
330

331
                [Obsolete("use lockpointer instead")]
332
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
333
                {
2,900✔
334
                        if (this._reader.DxfCode == DxfCode.Start)
2,900!
335
                        {
×
336
                                return true;
×
337
                        }
338
                        else
339
                        {
2,900✔
340
                                return func.Invoke(template, map);
2,900✔
341
                        }
342
                }
2,900✔
343

344
                protected bool checkEntityEnd(CadEntityTemplate template, DxfMap map, string subclass, Func<CadEntityTemplate, DxfMap, string, bool> func)
345
                {
408✔
346
                        if (this._reader.DxfCode == DxfCode.Start)
408!
347
                        {
408✔
348
                                return true;
408✔
349
                        }
350
                        else
351
                        {
×
352
                                return func.Invoke(template, map, subclass);
×
353
                        }
354
                }
408✔
355

356
                private bool readCircle(CadEntityTemplate template, DxfMap map, string subclass = null)
357
                {
35,945✔
358
                        Circle circle = template.CadObject as Circle;
35,945✔
359

360
                        switch (this._reader.Code)
35,945✔
361
                        {
362
                                case 40:
363
                                        double radius = this._reader.ValueAsDouble;
3,730✔
364
                                        if (radius <= 0)
3,730!
365
                                        {
×
366
                                                circle.Radius = MathHelper.Epsilon;
×
367
                                        }
×
368
                                        else
369
                                        {
3,730✔
370
                                                circle.Radius = radius;
3,730✔
371
                                        }
3,730✔
372
                                        return true;
3,730✔
373
                                default:
374
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Circle]);
32,215✔
375
                        }
376
                }
35,945✔
377

378
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
379
                {
8,992✔
380
                        switch (this._reader.Code)
8,992✔
381
                        {
382
                                default:
383
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
8,992✔
384
                                        {
7,620✔
385
                                                return this.readCircle(template, map, DxfSubclassMarker.Circle);
7,620✔
386
                                        }
387
                                        return true;
1,372✔
388
                        }
389
                }
8,992✔
390

391
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
392
                {
33,438✔
393
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
33,438✔
394
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
33,438✔
395

396
                        switch (this._reader.Code)
33,438!
397
                        {
398
                                case 44:
399
                                case 46:
400
                                        return true;
×
401
                                case 101:
402
                                        var att = tmp.CadObject as AttributeBase;
66✔
403
                                        att.MText = new MText();
66✔
404
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
66✔
405
                                        tmp.MTextTemplate = mtextTemplate;
66✔
406
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
66✔
407
                                        return true;
66✔
408
                                default:
409
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
33,372✔
410
                                        {
25,250✔
411
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
25,250✔
412
                                        }
413
                                        return true;
8,122✔
414
                        }
415
                }
33,438✔
416

417
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
418
                {
134,334✔
419
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
134,334!
420
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
134,334✔
421
                        TableEntity table = tmp.CadObject as TableEntity;
134,334✔
422

423
                        switch (this._reader.Code)
134,334!
424
                        {
425
                                case 1:
426
                                        TableEntity.CellContent content;
427
                                        if (tmp.CurrentCell.Content == null)
2,652!
428
                                        {
2,652✔
429
                                                content = new TableEntity.CellContent();
2,652✔
430
                                                content.CadValue.ValueType = CadValueType.String;
2,652✔
431
                                                tmp.CurrentCell.Contents.Add(content);
2,652✔
432
                                        }
2,652✔
433
                                        else
434
                                        {
×
435
                                                content = tmp.CurrentCell.Content;
×
436
                                        }
×
437

438
                                        if (content.CadValue.Value == null)
2,652!
439
                                        {
2,652✔
440
                                                content.CadValue.SetValue(this._reader.ValueAsString, CadValueType.String);
2,652✔
441
                                        }
2,652✔
442
                                        else
443
                                        {
×
444
                                                string str = content.CadValue.Value as string;
×
445
                                                str += this._reader.ValueAsString;
×
446
                                                content.CadValue.SetValue(str, CadValueType.String);
×
447
                                        }
×
448
                                        return true;
2,652✔
449
                                case 2:
450
                                        if (this.currentSubclass.Equals(DxfSubclassMarker.TableEntity, StringComparison.OrdinalIgnoreCase))
408!
451
                                        {
×
452
                                                content = tmp.CurrentCell.Content;
×
453
                                                if (content.CadValue.Value == null)
×
454
                                                {
×
455
                                                        content.CadValue.SetValue(this._reader.ValueAsString, CadValueType.String);
×
456
                                                }
×
457
                                                else
458
                                                {
×
459
                                                        string str = content.CadValue.Value as string;
×
460
                                                        str += this._reader.ValueAsString;
×
461
                                                        content.CadValue.SetValue(str, CadValueType.String);
×
462
                                                }
×
463
                                        }
×
464
                                        else
465
                                        {
408✔
466
                                                tmp.BlockName = this._reader.ValueAsString;
408✔
467
                                        }
408✔
468
                                        return true;
408✔
469
                                //Border overrides:
470
                                case 177:
471
                                        //Cell override flag value (before AutoCAD 2007)
472
                                        return true;
2,788✔
473
                                case 279:
474
                                        //Lineweight for the top border of the cell; override applied at the cell level
475
                                        tmp.CurrentCell.StyleOverride.TopBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
1,428✔
476
                                        return true;
1,428✔
477
                                case 275:
478
                                        //Lineweight for the right border of the cell; override applied at the cell level
479
                                        tmp.CurrentCell.StyleOverride.RightBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
408✔
480
                                        return true;
408✔
481
                                case 276:
482
                                        //Lineweight for the bottom border of the cell; override applied at the cell level
483
                                        tmp.CurrentCell.StyleOverride.BottomBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
×
484
                                        return true;
×
485
                                case 278:
486
                                        //Lineweight for the left border of the cell; override applied at the cell level
487
                                        tmp.CurrentCell.StyleOverride.LeftBorder.LineWeight = (LineWeightType)this._reader.ValueAsShort;
1,224✔
488
                                        return true;
1,224✔
489
                                case 69:
490
                                        //True color value for the top border of the cell; override applied at the cell level
491
                                        tmp.CurrentCell.StyleOverride.TopBorder.Color = new Color(this._reader.ValueAsShort);
1,428✔
492
                                        return true;
1,428✔
493
                                case 65:
494
                                        //True color value for the right border of the cell; override applied at the cell level
495
                                        tmp.CurrentCell.StyleOverride.RightBorder.Color = new Color(this._reader.ValueAsShort);
408✔
496
                                        return true;
408✔
497
                                case 66:
498
                                        //True color value for the bottom border of the cell; override applied at the cell level
499
                                        tmp.CurrentCell.StyleOverride.BottomBorder.Color = new Color(this._reader.ValueAsShort);
×
500
                                        return true;
×
501
                                case 68:
502
                                        //True color value for the left border of the cell; override applied at the cell level
503
                                        tmp.CurrentCell.StyleOverride.LeftBorder.Color = new Color(this._reader.ValueAsShort);
1,224✔
504
                                        return true;
1,224✔
505
                                case 40:
506
                                        tmp.HorizontalMargin = this._reader.ValueAsDouble;
204✔
507
                                        return true;
204✔
508
                                case 63:
509
                                        tmp.CurrentCell.StyleOverride.BackgroundColor = new Color(this._reader.ValueAsShort);
204✔
510
                                        return true;
204✔
511
                                case 64:
512
                                        tmp.CurrentCell.StyleOverride.ContentColor = new Color(this._reader.ValueAsShort);
204✔
513
                                        return true;
204✔
514
                                case 140:
515
                                        if (tmp.CurrentCellTemplate != null)
4,896✔
516
                                        {
4,284✔
517
                                                tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
4,284✔
518
                                        }
4,284✔
519
                                        return true;
4,896✔
520
                                case 283:
521
                                        tmp.CurrentCell.StyleOverride.IsFillColorOn = this._reader.ValueAsBool;
204✔
522
                                        return true;
204✔
523
                                case 342:
524
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
408✔
525
                                        return true;
408✔
526
                                case 343:
527
                                        tmp.BlockOwnerHandle = this._reader.ValueAsHandle;
408✔
528
                                        return true;
408✔
529
                                case 141:
530
                                        var row = new TableEntity.Row();
2,244✔
531
                                        row.Height = this._reader.ValueAsDouble;
2,244✔
532
                                        table.Rows.Add(row);
2,244✔
533
                                        return true;
2,244✔
534
                                case 142:
535
                                        var col = new TableEntity.Column();
1,632✔
536
                                        col.Width = this._reader.ValueAsDouble;
1,632✔
537
                                        table.Columns.Add(col);
1,632✔
538
                                        return true;
1,632✔
539
                                case 144:
540
                                        tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
408✔
541
                                        return true;
408✔
542
                                case 145:
543
                                        tmp.CurrentCell.Rotation = this._reader.ValueAsDouble;
8,364✔
544
                                        return true;
8,364✔
545
                                case 170:
546
                                        //Has data flag
547
                                        return true;
612✔
548
                                case 171:
549
                                        tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
8,364✔
550
                                        return true;
8,364✔
551
                                case 172:
552
                                        tmp.CurrentCell.EdgeFlags = this._reader.ValueAsShort;
8,364✔
553
                                        return true;
8,364✔
554
                                case 173:
555
                                        tmp.CurrentCell.MergedValue = this._reader.ValueAsShort;
8,364✔
556
                                        return true;
8,364✔
557
                                case 174:
558
                                        tmp.CurrentCell.AutoFit = this._reader.ValueAsBool;
8,364✔
559
                                        return true;
8,364✔
560
                                case 175:
561
                                        tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
8,364✔
562
                                        return true;
8,364✔
563
                                case 176:
564
                                        tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
8,364✔
565
                                        return true;
8,364✔
566
                                case 178:
567
                                        tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
8,364✔
568
                                        return true;
8,364✔
569
                                case 179:
570
                                        //Unknown value
571
                                        return true;
408✔
572
                                case 301:
573
                                        content = new TableEntity.CellContent();
5,576✔
574
                                        var contentTemplate = new CadTableCellContentTemplate(content);
5,576✔
575
                                        tmp.CurrentCell.Contents.Add(content);
5,576✔
576
                                        var valTemplate = readCadValue(content.CadValue);
5,576✔
577
                                        contentTemplate.CadValueTemplate = valTemplate;
5,576✔
578
                                        return true;
5,576✔
579
                                case 340:
580
                                        tmp.CurrentCellTemplate.ValueHandle = this._reader.ValueAsHandle;
408✔
581
                                        return true;
408✔
582
                                default:
583
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
37,638✔
584
                                        {
36,210✔
585
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
36,210✔
586
                                        }
587
                                        return true;
1,428✔
588
                        }
589
                }
134,334✔
590

591
                protected CadValueTemplate readCadValue(CadValue value)
592
                {
9,288✔
593
                        this._reader.ReadNext();
9,288✔
594

595
                        CadValueTemplate template = new(value);
9,288✔
596
                        var map = DxfClassMap.Create(value.GetType(), "CadValue");
9,288✔
597

598
                        while (this._reader.Code != 304)
61,664✔
599
                        {
52,376✔
600
                                switch (this._reader.Code)
52,376!
601
                                {
602
                                        case 1:
603
                                                value.SetValue(this._reader.ValueAsString);
3,296✔
604
                                                break;
3,296✔
605
                                        case 2:
606
                                                value.SetValue((value.Value as string) + this._reader.ValueAsString);
×
607
                                                break;
×
608
                                        case 11:
609
                                                XYZ xyz = new XYZ();
264✔
610
                                                xyz.X = this._reader.ValueAsDouble;
264✔
611
                                                value.SetValue(xyz);
264✔
612
                                                break;
264✔
613
                                        case 21:
614
                                                {
264✔
615
                                                        IVector v = value.Value as IVector;
264✔
616
                                                        v[1] = this._reader.ValueAsDouble;
264✔
617
                                                        value.SetValue(v);
264✔
618
                                                }
264✔
619
                                                break;
264✔
620
                                        case 31:
621
                                                {
264✔
622
                                                        IVector v = value.Value as IVector;
264✔
623
                                                        v = v.Convert<XYZ>();
264✔
624
                                                        v[2] = this._reader.ValueAsDouble;
264✔
625
                                                        value.SetValue(v);
264✔
626
                                                }
264✔
627
                                                break;
264✔
628
                                        case 91:
629
                                                value.SetValue(this._reader.ValueAsInt);
264✔
630
                                                break;
264✔
631
                                        case 140:
632
                                                value.SetValue(this._reader.ValueAsDouble);
1,056✔
633
                                                break;
1,056✔
634
                                        case 330:
635
                                                template.ValueHandle = this._reader.ValueAsHandle;
×
636
                                                break;
×
637
                                        default:
638
                                                if (!this.tryAssignCurrentValue(value, map))
46,968✔
639
                                                {
528✔
640
                                                        this._builder.Notify($"Unhandled dxf code {this._reader.Code} value {this._reader.ValueAsString} at {nameof(readCadValue)} method.", NotificationType.None);
528✔
641
                                                }
528✔
642
                                                break;
46,968✔
643
                                }
644

645
                                this._reader.ReadNext();
52,376✔
646
                        }
52,376✔
647

648
                        return template;
9,288✔
649
                }
9,288✔
650

651
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
652
                {
288,982✔
653
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,982✔
654
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
288,982✔
655

656
                        switch (this._reader.Code)
288,982✔
657
                        {
658
                                case 1 or 3 when tmp.CadObject is MText mtext:
25,928✔
659
                                        mtext.Value += this._reader.ValueAsString;
9,690✔
660
                                        return true;
9,690✔
661
                                case 50 when tmp.CadObject is MText mtext://Read only for MText
480!
662
                                        double angle = this._reader.ValueAsAngle;
×
663
                                        mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
664
                                        return true;
×
665
                                case 7:
666
                                        tmp.StyleName = this._reader.ValueAsString;
2,856✔
667
                                        return true;
2,856✔
668
                                case 101 when tmp.CadObject is MText mtext:
136✔
669
                                        this.readColumnData(mtext);
136✔
670
                                        this.lockPointer = true;
136✔
671
                                        return true;
136✔
672
                                default:
673
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
276,300✔
674
                        }
675
                }
288,982✔
676

677
                private void readColumnData(MText mtext)
678
                {
136✔
679
                        this._reader.ReadNext();
136✔
680
                        while (this._reader.DxfCode != DxfCode.Start)
2,584✔
681
                        {
2,448✔
682
                                switch (this._reader.Code)
2,448!
683
                                {
684
                                        //Element count?
685
                                        case 70:
686
                                                break;
136✔
687
                                        case 71:
688
                                                mtext.ColumnData.ColumnType = (ColumnType)this._reader.ValueAsShort;
136✔
689
                                                break;
136✔
690
                                        case 72:
691
                                                mtext.ColumnData.ColumnCount = this._reader.ValueAsInt;
136✔
692
                                                break;
136✔
693
                                        //X - axis dir 3BD 10
694
                                        case 10:
695
                                        case 20:
696
                                        case 30:
697
                                        //Insertion point 3BD 11
698
                                        case 11:
699
                                        case 21:
700
                                        case 31:
701
                                        //Rect width BD 40
702
                                        case 40:
703
                                        //Rect height BD 41
704
                                        case 41:
705
                                        //Extents width BD 42
706
                                        case 42:
707
                                        //Extents height BD 43
708
                                        case 43:
709
                                                break;
1,360✔
710
                                        case 44:
711
                                                mtext.ColumnData.Width = this._reader.ValueAsDouble;
136✔
712
                                                break;
136✔
713
                                        case 45:
714
                                                mtext.ColumnData.Gutter = this._reader.ValueAsDouble;
136✔
715
                                                break;
136✔
716
                                        case 46:
717
                                                mtext.ColumnData.Heights.Add(this._reader.ValueAsDouble);
136✔
718
                                                break;
136✔
719
                                        case 73:
720
                                                mtext.ColumnData.AutoHeight = this._reader.ValueAsBool;
136✔
721
                                                break;
136✔
722
                                        case 74:
723
                                                mtext.ColumnData.FlowReversed = this._reader.ValueAsBool;
136✔
724
                                                break;
136✔
725
                                        default:
726
                                                this._builder.Notify($"[MText.ColumnData] unkown dxf code {this._reader.Code}.", NotificationType.None);
×
727
                                                break;
×
728
                                }
729

730
                                this._reader.ReadNext();
2,448✔
731
                        }
2,448✔
732
                }
136✔
733

734
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
735
                {
6,120✔
736
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,120✔
737

738
                        switch (this._reader.Code)
6,120✔
739
                        {
740
                                case 3:
741
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
612✔
742
                                        return true;
612✔
743
                                default:
744
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,508✔
745
                        }
746
                }
6,120✔
747

748
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
749
                {
68,476✔
750
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
68,476✔
751

752
                        switch (this._reader.Code)
68,476✔
753
                        {
754
                                case 2:
755
                                        tmp.BlockName = this._reader.ValueAsString;
2,618✔
756
                                        return true;
2,618✔
757
                                case 3:
758
                                        tmp.StyleName = this._reader.ValueAsString;
2,244✔
759
                                        return true;
2,244✔
760
                                case 50:
761
                                        var dim = new DimensionLinear();
238✔
762
                                        tmp.SetDimensionObject(dim);
238✔
763
                                        dim.Rotation = this._reader.ValueAsAngle;
238✔
764
                                        if (!map.SubClasses.ContainsKey(DxfSubclassMarker.LinearDimension))
238✔
765
                                        {
204✔
766
                                                map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
204✔
767
                                        }
204✔
768
                                        return true;
238✔
769
                                case 70:
770
                                        //Flags do not have set
771
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,618✔
772

773
                                        if (tmp.CadObject is CadDimensionTemplate.DimensionPlaceholder placeholder && this._builder.Version < ACadVersion.AC1012)
2,618!
774
                                        {
374✔
775
                                                switch (placeholder.Flags)
374!
776
                                                {
777
                                                        case DimensionType.Linear:
778
                                                                tmp.SetDimensionObject(new DimensionLinear());
102✔
779
                                                                map.SubClasses.Add(DxfSubclassMarker.AlignedDimension, DxfClassMap.Create<DimensionAligned>());
102✔
780
                                                                map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
102✔
781
                                                                break;
102✔
782
                                                        case DimensionType.Aligned:
783
                                                                tmp.SetDimensionObject(new DimensionAligned());
68✔
784
                                                                map.SubClasses.Add(DxfSubclassMarker.AlignedDimension, DxfClassMap.Create<DimensionAligned>());
68✔
785
                                                                break;
68✔
786
                                                        case DimensionType.Angular:
787
                                                                tmp.SetDimensionObject(new DimensionAngular2Line());
34✔
788
                                                                map.SubClasses.Add(DxfSubclassMarker.Angular2LineDimension, DxfClassMap.Create<DimensionAngular2Line>());
34✔
789
                                                                break;
34✔
790
                                                        case DimensionType.Diameter:
NEW
791
                                                                tmp.SetDimensionObject(new DimensionDiameter());
×
NEW
792
                                                                map.SubClasses.Add(DxfSubclassMarker.DiametricDimension, DxfClassMap.Create<DimensionDiameter>());
×
NEW
793
                                                                break;
×
794
                                                        case DimensionType.Radius:
795
                                                                tmp.SetDimensionObject(new DimensionRadius());
34✔
796
                                                                map.SubClasses.Add(DxfSubclassMarker.RadialDimension, DxfClassMap.Create<DimensionRadius>());
34✔
797
                                                                break;
34✔
798
                                                        case DimensionType.Angular3Point:
799
                                                                tmp.SetDimensionObject(new DimensionAngular3Pt());
34✔
800
                                                                map.SubClasses.Add(DxfSubclassMarker.Angular3PointDimension, DxfClassMap.Create<DimensionAngular3Pt>());
34✔
801
                                                                break;
34✔
802
                                                        case DimensionType.Ordinate:
803
                                                        case DimensionType.OrdinateTypeX:
804
                                                        case DimensionType.Ordinate | DimensionType.OrdinateTypeX:
805
                                                                tmp.SetDimensionObject(new DimensionOrdinate());
68✔
806
                                                                map.SubClasses.Add(DxfSubclassMarker.OrdinateDimension, DxfClassMap.Create<DimensionOrdinate>());
68✔
807
                                                                break;
68✔
808
                                                        case DimensionType.BlockReference:
809
                                                        case DimensionType.TextUserDefinedLocation:
810
                                                        default:
811
                                                                break;
34✔
812
                                                }
813
                                        }
374✔
814
                                        return true;
2,618✔
815
                                //Measurement - read only
816
                                case 42:
817
                                        return true;
2,244✔
818
                                //Undocumented codes
819
                                case 73:
820
                                case 74:
821
                                case 75:
822
                                case 90:
823
                                case 361:
824
                                        return true;
4,488✔
825
                                case 100:
826
                                        switch (this._reader.ValueAsString)
7,344✔
827
                                        {
828
                                                case DxfSubclassMarker.Dimension:
829
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,244✔
830
                                                case DxfSubclassMarker.AlignedDimension:
831
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,020✔
832
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,020✔
833
                                                        return true;
1,020✔
834
                                                case DxfSubclassMarker.DiametricDimension:
835
                                                        tmp.SetDimensionObject(new DimensionDiameter());
204✔
836
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
204✔
837
                                                        return true;
204✔
838
                                                case DxfSubclassMarker.Angular2LineDimension:
839
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
204✔
840
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
204✔
841
                                                        return true;
204✔
842
                                                case DxfSubclassMarker.Angular3PointDimension:
843
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
204✔
844
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
204✔
845
                                                        return true;
204✔
846
                                                case DxfSubclassMarker.RadialDimension:
847
                                                        tmp.SetDimensionObject(new DimensionRadius());
204✔
848
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
204✔
849
                                                        return true;
204✔
850
                                                case DxfSubclassMarker.OrdinateDimension:
851
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
408✔
852
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
408✔
853
                                                        return true;
408✔
854
                                                case DxfSubclassMarker.LinearDimension:
855
                                                        return true;
612✔
856
                                                default:
857
                                                        return false;
2,244✔
858
                                        }
859
                                default:
860
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
46,682✔
861
                        }
862
                }
68,476✔
863

864
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
865
                {
43,656✔
866
                        CadHatchTemplate tmp = template as CadHatchTemplate;
43,656✔
867
                        Hatch hatch = tmp.CadObject;
43,656✔
868

869
                        XY seedPoint = new XY();
43,656✔
870

871
                        switch (this._reader.Code)
43,656!
872
                        {
873
                                case 2:
874
                                        hatch.Pattern.Name = this._reader.ValueAsString;
1,632✔
875
                                        return true;
1,632✔
876
                                case 10:
877
                                        seedPoint.X = this._reader.ValueAsDouble;
3,264✔
878
                                        hatch.SeedPoints.Add(seedPoint);
3,264✔
879
                                        return true;
3,264✔
880
                                case 20:
881
                                        seedPoint = hatch.SeedPoints.LastOrDefault();
3,264✔
882
                                        seedPoint.Y = this._reader.ValueAsDouble;
3,264✔
883
                                        hatch.SeedPoints[hatch.SeedPoints.Count - 1] = seedPoint;
3,264✔
884
                                        return true;
3,264✔
885
                                case 30:
886
                                        hatch.Elevation = this._reader.ValueAsDouble;
1,632✔
887
                                        return true;
1,632✔
888
                                case 53:
889
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
890
                                        return true;
×
891
                                //TODO: Check hatch undocumented codes
892
                                case 90:
893
                                        return true;
×
894
                                //Information about the hatch pattern
895
                                case 75:
896
                                        return true;
1,632✔
897
                                //Number of pattern definition lines
898
                                case 78:
899
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,224✔
900
                                        this.lockPointer = true;
1,224✔
901
                                        return true;
1,224✔
902
                                //Number of boundary paths (loops)
903
                                case 91:
904
                                        this.readLoops(tmp, this._reader.ValueAsInt);
1,632✔
905
                                        this.lockPointer = true;
1,632✔
906
                                        return true;
1,632✔
907
                                //Number of seed points
908
                                case 98:
909
                                        return true;
1,020✔
910
                                case 450:
911
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
340✔
912
                                        return true;
340✔
913
                                case 451:
914
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
340✔
915
                                        return true;
340✔
916
                                case 452:
917
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
340✔
918
                                        return true;
340✔
919
                                case 453:
920
                                        //Number of colors
921
                                        return true;
340✔
922
                                case 460:
923
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
340✔
924
                                        return true;
340✔
925
                                case 461:
926
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
340✔
927
                                        return true;
340✔
928
                                case 462:
929
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
340✔
930
                                        return true;
340✔
931
                                case 463:
932
                                        GradientColor gradient = new GradientColor();
680✔
933
                                        gradient.Value = this._reader.ValueAsDouble;
680✔
934
                                        hatch.GradientColor.Colors.Add(gradient);
680✔
935
                                        return true;
680✔
936
                                case 63:
937
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
680✔
938
                                        if (colorByIndex != null)
680✔
939
                                        {
680✔
940
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
680✔
941
                                        }
680✔
942
                                        return true;
680✔
943
                                case 421:
944
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
680✔
945
                                        if (colorByRgb != null)
680✔
946
                                        {
680✔
947
                                                //TODO: Hatch assign color by true color
948
                                                //TODO: Is always duplicated by 63, is it needed??
949
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
950
                                        }
680✔
951
                                        return true;
680✔
952
                                case 470:
953
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
340✔
954
                                        return true;
340✔
955
                                default:
956
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
23,596✔
957
                        }
958
                }
43,656✔
959

960
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
961
                {
59,000✔
962
                        CadInsertTemplate tmp = template as CadInsertTemplate;
59,000✔
963

964
                        switch (this._reader.Code)
59,000✔
965
                        {
966
                                case 2:
967
                                        tmp.BlockName = this._reader.ValueAsString;
5,517✔
968
                                        return true;
5,517✔
969
                                case 100:
970
                                        //AcDbEntity
971
                                        //AcDbBlockReference
972
                                        //AcDbMInsertBlock
973
                                        return true;
5,542✔
974
                                case 66:
975
                                        return true;
476✔
976
                                default:
977
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
47,465✔
978
                        }
979
                }
59,000✔
980

981
                private CadEntityTemplate readPolyline()
982
                {
10,444✔
983
                        if (this._builder.Version == ACadVersion.Unknown
10,444!
984
                                || this._builder.Version == ACadVersion.AC1009)
10,444✔
985
                        {
10,036✔
986
                                return this.readLegacyPolyline();
10,036✔
987
                        }
988

989
                        CadPolyLineTemplate template = null;
408✔
990
                        template = new CadPolyLineTemplate();
408✔
991
                        this.readEntityCodes<Entity>(template, this.readPolyline);
408✔
992

993
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
408!
994
                        {
×
995
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
996
                                return null;
×
997
                        }
998

999
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
2,856!
1000
                        {
2,448✔
1001
                                var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,448✔
1002

1003
                                if (vertexTemplate.OwnerHandle == null)
2,448!
1004
                                {
×
1005
                                        vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
1006
                                }
×
1007

1008
                                template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,448✔
1009
                                _builder.AddTemplate(vertexTemplate);
2,448✔
1010
                        }
2,448✔
1011

1012
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
816!
1013
                        {
408✔
1014
                                var seqend = new Seqend();
408✔
1015
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
408✔
1016
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
408✔
1017

1018
                                if (seqendTemplate.OwnerHandle == null)
408!
1019
                                {
×
1020
                                        seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
1021
                                }
×
1022

1023
                                template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
408✔
1024
                                _builder.AddTemplate(seqendTemplate);
408✔
1025
                        }
408✔
1026

1027
                        return template;
408✔
1028
                }
10,444✔
1029

1030
                private CadEntityTemplate readLegacyPolyline()
1031
                {
10,036✔
1032
                        var polyline = new Polyline2D();
10,036✔
1033
                        CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,036✔
1034
                        this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,036✔
1035

1036
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
45,896!
1037
                        {
35,860✔
1038
                                Vertex2D v = new Vertex2D();
35,860✔
1039
                                CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
35,860✔
1040
                                this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
35,860✔
1041

1042
                                if (vertexTemplate.Vertex.Handle == 0)
35,860!
1043
                                {
×
1044
                                        polyline.Vertices.Add(v);
×
1045
                                }
×
1046
                                else
1047
                                {
35,860✔
1048
                                        template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
35,860✔
1049
                                        this._builder.AddTemplate(vertexTemplate);
35,860✔
1050
                                }
35,860✔
1051
                        }
35,860✔
1052

1053
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
20,072!
1054
                        {
10,036✔
1055
                                var seqend = new Seqend();
10,036✔
1056
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,036✔
1057
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,036✔
1058

1059
                                polyline.Vertices.Seqend = seqend;
10,036✔
1060
                        }
10,036✔
1061

1062
                        return template;
10,036✔
1063
                }
10,036✔
1064

1065
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1066
                {
75,008✔
1067
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
75,008✔
1068

1069
                        switch (this._reader.Code)
75,008✔
1070
                        {
1071
                                //DXF: always 0
1072
                                //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)
1073
                                case 10:
1074
                                case 20:
1075
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1076
                                case 66:
1077
                                        return true;
31,332✔
1078
                                case 100:
1079
                                        switch (this._reader.ValueAsString)
816!
1080
                                        {
1081
                                                case DxfSubclassMarker.Polyline:
1082
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
1083
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
1084
                                                        return true;
×
1085
                                                case DxfSubclassMarker.Polyline3d:
1086
                                                        tmp.SetPolyLineObject(new Polyline3D());
204✔
1087
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
204✔
1088
                                                        return true;
204✔
1089
                                                case DxfSubclassMarker.PolyfaceMesh:
1090
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
204✔
1091
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
204✔
1092
                                                        return true;
204✔
1093
                                                case DxfSubclassMarker.PolygonMesh:
1094
                                                        tmp.SetPolyLineObject(new PolygonMesh());
×
1095
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
1096
                                                        return true;
×
1097
                                                default:
1098
                                                        return false;
408✔
1099
                                        }
1100
                                default:
1101
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
42,860✔
1102
                        }
1103
                }
75,008✔
1104

1105
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1106
                {
5,100✔
1107
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
1108

1109
                        switch (this._reader.Code)
5,100✔
1110
                        {
1111
                                case 3:
1112
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
204✔
1113
                                        return true;
204✔
1114
                                case 10:
1115
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
816✔
1116
                                        return true;
816✔
1117
                                case 20:
1118
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1119
                                        y.Y = this._reader.ValueAsDouble;
816✔
1120
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
816✔
1121
                                        return true;
816✔
1122
                                case 30:
1123
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1124
                                        z.Z = this._reader.ValueAsDouble;
816✔
1125
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
816✔
1126
                                        return true;
816✔
1127
                                case 340:
1128
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
204✔
1129
                                        return true;
204✔
1130
                                //Hook line flag - read only
1131
                                case 75:
1132
                                //Vertices count
1133
                                case 76:
1134
                                        return true;
408✔
1135
                                default:
1136
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,836✔
1137
                        }
1138
                }
5,100✔
1139

1140
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1141
                {
87,399✔
1142
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
87,399✔
1143

1144
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
87,399✔
1145

1146
                        switch (this._reader.Code)
87,399!
1147
                        {
1148
                                case 10:
1149
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
20,788✔
1150
                                        return true;
20,788✔
1151
                                case 20:
1152
                                        if (last is not null)
20,788✔
1153
                                        {
20,788✔
1154
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
20,788✔
1155
                                        }
20,788✔
1156
                                        return true;
20,788✔
1157
                                case 40:
1158
                                        if (last is not null)
2,040✔
1159
                                        {
2,040✔
1160
                                                last.StartWidth = this._reader.ValueAsDouble;
2,040✔
1161
                                        }
2,040✔
1162
                                        return true;
2,040✔
1163
                                case 41:
1164
                                        if (last is not null)
2,040✔
1165
                                        {
2,040✔
1166
                                                last.EndWidth = this._reader.ValueAsDouble;
2,040✔
1167
                                        }
2,040✔
1168
                                        return true;
2,040✔
1169
                                case 42:
1170
                                        if (last is not null)
2,784✔
1171
                                        {
2,784✔
1172
                                                last.Bulge = this._reader.ValueAsDouble;
2,784✔
1173
                                        }
2,784✔
1174
                                        return true;
2,784✔
1175
                                case 50:
1176
                                        if (last is not null)
×
1177
                                        {
×
1178
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
1179
                                        }
×
1180
                                        return true;
×
1181
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1182
                                case 66:
1183
                                //Vertex count
1184
                                case 90:
1185
                                        return true;
4,690✔
1186
                                case 91:
1187
                                        if (last is not null)
×
1188
                                        {
×
1189
                                                last.Id = this._reader.ValueAsInt;
×
1190
                                        }
×
1191
                                        return true;
×
1192
                                default:
1193
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,269✔
1194
                        }
1195
                }
87,399✔
1196

1197
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1198
                {
35,904✔
1199
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
1200

1201
                        switch (this._reader.Code)
35,904✔
1202
                        {
1203
                                case 100:
1204
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
1205
                                        {
408✔
1206
                                                tmp.SubclassMarker = true;
408✔
1207
                                        }
408✔
1208
                                        return true;
816✔
1209
                                //Count of sub-entity which property has been overridden
1210
                                case 90:
1211
                                        //TODO: process further entities
1212
                                        return true;
408✔
1213
                                case 92:
1214
                                        if (!tmp.SubclassMarker)
612✔
1215
                                        {
204✔
1216
                                                return false;
204✔
1217
                                        }
1218

1219
                                        int nvertices = this._reader.ValueAsInt;
408✔
1220
                                        for (int i = 0; i < nvertices; i++)
52,224✔
1221
                                        {
25,704✔
1222
                                                this._reader.ReadNext();
25,704✔
1223
                                                double x = this._reader.ValueAsDouble;
25,704✔
1224
                                                this._reader.ReadNext();
25,704✔
1225
                                                double y = this._reader.ValueAsDouble;
25,704✔
1226
                                                this._reader.ReadNext();
25,704✔
1227
                                                double z = this._reader.ValueAsDouble;
25,704✔
1228
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
1229
                                        }
25,704✔
1230
                                        return true;
408✔
1231
                                case 93:
1232
                                        int size = this._reader.ValueAsInt;
408✔
1233
                                        this._reader.ReadNext();
408✔
1234

1235
                                        int indexes = 0;
408✔
1236
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
1237
                                        {
27,744✔
1238
                                                indexes = this._reader.ValueAsInt;
27,744✔
1239
                                                this._reader.ReadNext();
27,744✔
1240

1241
                                                int[] face = new int[indexes];
27,744✔
1242
                                                for (int j = 0; j < indexes; j++)
267,648✔
1243
                                                {
106,080✔
1244
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
1245

1246
                                                        if ((i + j + 2) < size)
106,080✔
1247
                                                        {
105,672✔
1248
                                                                this._reader.ReadNext();
105,672✔
1249
                                                        }
105,672✔
1250
                                                }
106,080✔
1251

1252
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1253
                                        }
27,744✔
1254

1255
                                        Debug.Assert(this._reader.Code == 90);
408✔
1256

1257
                                        return true;
408✔
1258
                                case 94:
1259
                                        int numEdges = this._reader.ValueAsInt;
408✔
1260
                                        this._reader.ReadNext();
408✔
1261
                                        for (int i = 0; i < numEdges; i++)
106,896✔
1262
                                        {
53,040✔
1263
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
1264

1265
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
1266
                                                this._reader.ReadNext();
53,040✔
1267
                                                edge.End = this._reader.ValueAsInt;
53,040✔
1268

1269
                                                if (i < numEdges - 1)
53,040✔
1270
                                                {
52,632✔
1271
                                                        this._reader.ReadNext();
52,632✔
1272
                                                }
52,632✔
1273

1274
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1275
                                        }
53,040✔
1276

1277
                                        Debug.Assert(this._reader.Code == 90);
408✔
1278

1279
                                        return true;
408✔
1280
                                case 95:
1281
                                        this._reader.ReadNext();
408✔
1282
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
1283
                                        {
53,040✔
1284
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
1285
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
1286

1287
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1288

1289
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
1290
                                                {
52,632✔
1291
                                                        this._reader.ReadNext();
52,632✔
1292
                                                }
52,632✔
1293
                                        }
53,040✔
1294

1295
                                        Debug.Assert(this._reader.Code == 140);
408✔
1296

1297
                                        return true;
408✔
1298
                                default:
1299
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1300
                        }
1301
                }
35,904✔
1302

1303
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1304
                {
53,040✔
1305
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1306

1307
                        switch (this._reader.Code)
53,040✔
1308
                        {
1309
                                // 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.
1310
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1311
                                case 2:
1312
                                        tmp.MLineStyleName = this._reader.ValueAsString;
612✔
1313
                                        return true;
612✔
1314
                                case 72:
1315
                                        tmp.NVertex = this._reader.ValueAsInt;
612✔
1316
                                        return true;
612✔
1317
                                case 73:
1318
                                        tmp.NElements = this._reader.ValueAsInt;
612✔
1319
                                        return true;
612✔
1320
                                case 340:
1321
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
612✔
1322
                                        return true;
612✔
1323
                                default:
1324
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
50,592✔
1325
                                        {
8,568✔
1326
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
8,568✔
1327
                                        }
1328
                                        return true;
42,024✔
1329
                        }
1330
                }
53,040✔
1331

1332
                private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1333
                {
144,024✔
1334
                        CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
144,024✔
1335

1336
                        switch (this._reader.Code)
144,024✔
1337
                        {
1338
                                case 270:
1339
                                        //f270 Version
1340
                                        return true;
1,530✔
1341
                                case 300:
1342
                                        this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,060✔
1343
                                        return true;
3,060✔
1344
                                case 340:
1345
                                        tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,060✔
1346
                                        return true;
3,060✔
1347
                                case 341:
1348
                                        tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,060✔
1349
                                        return true;
3,060✔
1350
                                case 343:
1351
                                        tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1352
                                        return true;
3,060✔
1353
                                default:
1354
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
130,254✔
1355
                        }
1356
                }
144,024✔
1357

1358
                private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1359
                {
3,060✔
1360
                        this._reader.ReadNext();
3,060✔
1361

1362
                        var map = DxfClassMap.Create<MultiLeaderObjectContextData>();
3,060✔
1363
                        var contextData = template.CadObject as MultiLeaderObjectContextData;
3,060✔
1364

1365
                        bool end = false;
3,060✔
1366
                        while (this._reader.DxfCode != DxfCode.Start)
171,360✔
1367
                        {
171,360✔
1368
                                switch (this._reader.Code)
171,360✔
1369
                                {
1370
                                        case 301 when this._reader.ValueAsString.Equals("}"):
3,060✔
1371
                                                end = true;
3,060✔
1372
                                                break;
3,060✔
1373
                                        case 302 when this._reader.ValueAsString.Equals("LEADER{"):
3,060✔
1374
                                                contextData.LeaderRoots.Add(this.readMultiLeaderLeader(template));
3,060✔
1375
                                                break;
3,060✔
1376
                                        case 340:
1377
                                                template.TextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1378
                                                break;
3,060✔
1379
                                        default:
1380
                                                if (!this.tryAssignCurrentValue(contextData, map))
162,180!
1381
                                                {
×
1382
                                                        this._builder.Notify($"[AcDbMLeaderObjectContextData] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1383
                                                }
×
1384
                                                break;
162,180✔
1385
                                }
1386

1387
                                if (end)
171,360✔
1388
                                {
3,060✔
1389
                                        break;
3,060✔
1390
                                }
1391

1392
                                this._reader.ReadNext();
168,300✔
1393
                        }
168,300✔
1394
                }
3,060✔
1395

1396
                private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1397
                {
3,060✔
1398
                        MultiLeaderObjectContextData.LeaderRoot root = new();
3,060✔
1399
                        var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,060✔
1400

1401
                        this._reader.ReadNext();
3,060✔
1402

1403
                        bool end = false;
3,060✔
1404
                        while (this._reader.DxfCode != DxfCode.Start)
38,250✔
1405
                        {
38,250✔
1406
                                switch (this._reader.Code)
38,250✔
1407
                                {
1408
                                        case 303 when this._reader.ValueAsString.Equals("}"):
3,060✔
1409
                                                end = true;
3,060✔
1410
                                                break;
3,060✔
1411
                                        case 304 when this._reader.ValueAsString.Equals("LEADER_LINE{"):
3,060✔
1412
                                                var lineTemplate = new LeaderLineTemplate();
3,060✔
1413
                                                template.LeaderLineTemplates.Add(lineTemplate);
3,060✔
1414
                                                root.Lines.Add(this.readMultiLeaderLine(lineTemplate));
3,060✔
1415
                                                break;
3,060✔
1416
                                        default:
1417
                                                if (!this.tryAssignCurrentValue(root, map))
32,130!
1418
                                                {
×
1419
                                                        this._builder.Notify($"[LeaderRoot] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1420
                                                }
×
1421
                                                break;
32,130✔
1422
                                }
1423

1424
                                if (end)
38,250✔
1425
                                {
3,060✔
1426
                                        break;
3,060✔
1427
                                }
1428

1429
                                this._reader.ReadNext();
35,190✔
1430
                        }
35,190✔
1431

1432
                        return root;
3,060✔
1433
                }
3,060✔
1434

1435
                private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1436
                {
3,060✔
1437
                        MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,060✔
1438
                        var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,060✔
1439

1440
                        this._reader.ReadNext();
3,060✔
1441

1442
                        bool end = false;
3,060✔
1443
                        while (this._reader.DxfCode != DxfCode.Start)
15,300✔
1444
                        {
15,300✔
1445
                                switch (this._reader.Code)
15,300✔
1446
                                {
1447
                                        case 10:
1448
                                                XYZ pt = new XYZ(this._reader.ValueAsDouble, 0, 0);
3,060✔
1449
                                                line.Points.Add(pt);
3,060✔
1450
                                                break;
3,060✔
1451
                                        case 20:
1452
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1453
                                                pt.Y = this._reader.ValueAsDouble;
3,060✔
1454
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1455
                                                break;
3,060✔
1456
                                        case 30:
1457
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1458
                                                pt.Z = this._reader.ValueAsDouble;
3,060✔
1459
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1460
                                                break;
3,060✔
1461
                                        case 305 when this._reader.ValueAsString.Equals("}"):
3,060✔
1462
                                                end = true;
3,060✔
1463
                                                break;
3,060✔
1464
                                        default:
1465
                                                if (!this.tryAssignCurrentValue(line, map))
3,060!
1466
                                                {
×
1467
                                                        this._builder.Notify($"[LeaderLine] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1468
                                                }
×
1469
                                                break;
3,060✔
1470
                                }
1471

1472
                                if (end)
15,300✔
1473
                                {
3,060✔
1474
                                        break;
3,060✔
1475
                                }
1476

1477
                                this._reader.ReadNext();
12,240✔
1478
                        }
12,240✔
1479

1480
                        return line;
3,060✔
1481
                }
3,060✔
1482

1483
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1484
                {
2,278✔
1485
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1486

1487
                        switch (this._reader.Code)
2,278✔
1488
                        {
1489
                                case 2:
1490
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1491
                                        return true;
238✔
1492
                                default:
1493
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1494
                        }
1495
                }
2,278✔
1496

1497
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1498
                {
12,036✔
1499
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,036✔
1500
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,036✔
1501

1502
                        switch (this._reader.Code)
12,036✔
1503
                        {
1504
                                case 91:
1505
                                        var nvertices = this._reader.ValueAsInt;
408✔
1506
                                        for (int i = 0; i < nvertices; i++)
3,672✔
1507
                                        {
1,428✔
1508
                                                this._reader.ReadNext();
1,428✔
1509
                                                var x = this._reader.ValueAsDouble;
1,428✔
1510
                                                this._reader.ReadNext();
1,428✔
1511
                                                var y = this._reader.ValueAsDouble;
1,428✔
1512

1513
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,428✔
1514
                                        }
1,428✔
1515

1516
                                        this._reader.ReadNext();
408✔
1517

1518
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
408✔
1519
                                case 340:
1520
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
408✔
1521
                                        return true;
408✔
1522
                                case 360:
1523
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
408✔
1524
                                        return true;
408✔
1525
                                default:
1526
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,812✔
1527
                        }
1528
                }
12,036✔
1529

1530
                private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1531
                {
×
1532
                        CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1533

1534
                        switch (this._reader.Code)
×
1535
                        {
1536
                                //End of data
1537
                                case 1:
1538
                                //Length of binary data
1539
                                case 90:
1540
                                //Undocumented
1541
                                case 73:
1542
                                        return true;
×
1543
                                case 310:
1544
                                        tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
1545
                                        return true;
×
1546
                                default:
1547
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1548
                        }
1549
                }
×
1550

1551
                private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1552
                {
288,776✔
1553
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
288,776✔
1554
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,776✔
1555
                        var geometry = template.CadObject as ModelerGeometry;
288,776✔
1556

1557
                        switch (this._reader.Code)
288,776✔
1558
                        {
1559
                                case 1:
1560
                                case 3:
1561
                                        geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
37,706✔
1562
                                        return true;
37,706✔
1563
                                case 2:
1564
                                        geometry.Guid = new Guid(this._reader.ValueAsString);
204✔
1565
                                        return true;
204✔
1566
                                case 290:
1567
                                        return true;
204✔
1568
                                default:
1569
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
250,662✔
1570
                        }
1571
                }
288,776✔
1572

1573
                private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1574
                {
34,884✔
1575
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
34,884✔
1576

1577
                        switch (this._reader.Code)
34,884✔
1578
                        {
1579
                                case 350:
1580
                                        tmp.HistoryHandle = this._reader.ValueAsHandle;
272✔
1581
                                        return true;
272✔
1582
                                default:
1583
                                        return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
34,612✔
1584
                        }
1585
                }
34,884✔
1586

1587
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1588
                {
14,280✔
1589
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1590

1591
                        XYZ controlPoint;
1592
                        XYZ fitPoint;
1593

1594
                        switch (this._reader.Code)
14,280!
1595
                        {
1596
                                case 10:
1597
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,632✔
1598
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,632✔
1599
                                        return true;
1,632✔
1600
                                case 20:
1601
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1602
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,632✔
1603
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1604
                                        return true;
1,632✔
1605
                                case 30:
1606
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1607
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,632✔
1608
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1609
                                        return true;
1,632✔
1610
                                case 11:
1611
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1612
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1613
                                        return true;
×
1614
                                case 21:
1615
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1616
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1617
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1618
                                        return true;
×
1619
                                case 31:
1620
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1621
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1622
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1623
                                        return true;
×
1624
                                case 40:
1625
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,264✔
1626
                                        return true;
3,264✔
1627
                                case 41:
1628
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1629
                                        return true;
×
1630
                                case 72:
1631
                                case 73:
1632
                                case 74:
1633
                                        return true;
1,224✔
1634
                                default:
1635
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,896✔
1636
                        }
1637
                }
14,280✔
1638

1639
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1640
                        where T : PdfUnderlayDefinition
1641
                {
3,230✔
1642
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,230✔
1643

1644
                        switch (this._reader.Code)
3,230✔
1645
                        {
1646
                                case 340:
1647
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
204✔
1648
                                        return true;
204✔
1649
                                default:
1650
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,026✔
1651
                        }
1652
                }
3,230✔
1653

1654
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1655
                {
238,252✔
1656
                        CadVertexTemplate tmp = template as CadVertexTemplate;
238,252✔
1657

1658
                        switch (this._reader.Code)
238,252✔
1659
                        {
1660
                                case 100:
1661
                                        switch (this._reader.ValueAsString)
6,936!
1662
                                        {
1663
                                                case DxfSubclassMarker.Vertex:
1664
                                                        return true;
2,040✔
1665
                                                case DxfSubclassMarker.PolylineVertex:
1666
                                                        tmp.SetVertexObject(new Vertex2D());
×
1667
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1668
                                                        return true;
×
1669
                                                case DxfSubclassMarker.Polyline3dVertex:
1670
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1671
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1672
                                                        return true;
1,020✔
1673
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1674
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1675
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1676
                                                        return true;
1,020✔
1677
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1678
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1679
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1680
                                                        return true;
408✔
1681
                                                case DxfSubclassMarker.PolygonMeshVertex:
1682
                                                        tmp.SetVertexObject(new PolygonMeshVertex());
×
1683
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1684
                                                        return true;
×
1685
                                                default:
1686
                                                        return false;
2,448✔
1687
                                        }
1688
                                default:
1689
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
231,316✔
1690
                        }
1691
                }
238,252✔
1692

1693
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1694
                {
67,976✔
1695
                        CadViewportTemplate tmp = template as CadViewportTemplate;
67,976✔
1696

1697
                        switch (this._reader.Code)
67,976!
1698
                        {
1699
                                //Undocumented
1700
                                case 67:
1701
                                case 68:
1702
                                        return true;
2,488✔
1703
                                case 69:
1704
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,244✔
1705
                                        return true;
1,244✔
1706
                                case 331:
1707
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1708
                                        return true;
×
1709
                                case 348:
1710
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1711
                                        return true;
784✔
1712
                                default:
1713
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
63,460✔
1714
                        }
1715
                }
67,976✔
1716

1717
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1718
                {
806,016✔
1719
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
806,016✔
1720

1721
                        switch (this._reader.Code)
806,016✔
1722
                        {
1723
                                default:
1724
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
806,016✔
1725
                        }
1726
                }
806,016✔
1727

1728
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1729
                {
34,227✔
1730
                        List<ExtendedDataRecord> records = new();
34,227✔
1731
                        edata.Add(this._reader.ValueAsString, records);
34,227✔
1732

1733
                        this._reader.ReadNext();
34,227✔
1734

1735
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,832✔
1736
                        {
256,472✔
1737
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,472✔
1738
                                {
10,867✔
1739
                                        this.readExtendedData(edata);
10,867✔
1740
                                        break;
10,867✔
1741
                                }
1742

1743
                                ExtendedDataRecord record = null;
245,605✔
1744
                                double x = 0;
245,605✔
1745
                                double y = 0;
245,605✔
1746
                                double z = 0;
245,605✔
1747

1748
                                switch (this._reader.DxfCode)
245,605✔
1749
                                {
1750
                                        case DxfCode.ExtendedDataAsciiString:
1751
                                        case DxfCode.ExtendedDataRegAppName:
1752
                                                record = new ExtendedDataString(this._reader.ValueAsString);
23,506✔
1753
                                                break;
23,506✔
1754
                                        case DxfCode.ExtendedDataControlString:
1755
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,484✔
1756
                                                break;
13,484✔
1757
                                        case DxfCode.ExtendedDataLayerName:
1758
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1759
                                                {
224✔
1760
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1761
                                                }
224✔
1762
                                                else
1763
                                                {
14✔
1764
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1765
                                                }
14✔
1766
                                                break;
238✔
1767
                                        case DxfCode.ExtendedDataBinaryChunk:
1768
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1769
                                                break;
68✔
1770
                                        case DxfCode.ExtendedDataHandle:
1771
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,611✔
1772
                                                break;
2,611✔
1773
                                        case DxfCode.ExtendedDataXCoordinate:
1774
                                                x = this._reader.ValueAsDouble;
2,541✔
1775
                                                this._reader.ReadNext();
2,541✔
1776
                                                y = this._reader.ValueAsDouble;
2,541✔
1777
                                                this._reader.ReadNext();
2,541✔
1778
                                                z = this._reader.ValueAsDouble;
2,541✔
1779

1780
                                                record = new ExtendedDataCoordinate(
2,541✔
1781
                                                        new XYZ(
2,541✔
1782
                                                                x,
2,541✔
1783
                                                                y,
2,541✔
1784
                                                                z)
2,541✔
1785
                                                        );
2,541✔
1786
                                                break;
2,541✔
1787
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1788
                                                x = this._reader.ValueAsDouble;
1,224✔
1789
                                                this._reader.ReadNext();
1,224✔
1790
                                                y = this._reader.ValueAsDouble;
1,224✔
1791
                                                this._reader.ReadNext();
1,224✔
1792
                                                z = this._reader.ValueAsDouble;
1,224✔
1793

1794
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1795
                                                        new XYZ(
1,224✔
1796
                                                                x,
1,224✔
1797
                                                                y,
1,224✔
1798
                                                                z)
1,224✔
1799
                                                        );
1,224✔
1800
                                                break;
1,224✔
1801
                                        case DxfCode.ExtendedDataWorldXDisp:
1802
                                                x = this._reader.ValueAsDouble;
238✔
1803
                                                this._reader.ReadNext();
238✔
1804
                                                y = this._reader.ValueAsDouble;
238✔
1805
                                                this._reader.ReadNext();
238✔
1806
                                                z = this._reader.ValueAsDouble;
238✔
1807

1808
                                                record = new ExtendedDataDisplacement(
238✔
1809
                                                        new XYZ(
238✔
1810
                                                                x,
238✔
1811
                                                                y,
238✔
1812
                                                                z)
238✔
1813
                                                        );
238✔
1814
                                                break;
238✔
1815
                                        case DxfCode.ExtendedDataWorldXDir:
1816
                                                x = this._reader.ValueAsDouble;
238✔
1817
                                                this._reader.ReadNext();
238✔
1818
                                                y = this._reader.ValueAsDouble;
238✔
1819
                                                this._reader.ReadNext();
238✔
1820
                                                z = this._reader.ValueAsDouble;
238✔
1821

1822
                                                record = new ExtendedDataDirection(
238✔
1823
                                                        new XYZ(
238✔
1824
                                                                x,
238✔
1825
                                                                y,
238✔
1826
                                                                z)
238✔
1827
                                                        );
238✔
1828
                                                break;
238✔
1829
                                        case DxfCode.ExtendedDataReal:
1830
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
119,449✔
1831
                                                break;
119,449✔
1832
                                        case DxfCode.ExtendedDataDist:
1833
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1834
                                                break;
238✔
1835
                                        case DxfCode.ExtendedDataScale:
1836
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1837
                                                break;
238✔
1838
                                        case DxfCode.ExtendedDataInteger16:
1839
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
69,751✔
1840
                                                break;
69,751✔
1841
                                        case DxfCode.ExtendedDataInteger32:
1842
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
9,605✔
1843
                                                break;
9,605✔
1844
                                        default:
1845
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1846
                                                break;
2,176✔
1847
                                }
1848

1849
                                if (record != null)
245,605✔
1850
                                {
243,415✔
1851
                                        records.Add(record);
243,415✔
1852
                                }
243,415✔
1853

1854
                                this._reader.ReadNext();
245,605✔
1855
                        }
245,605✔
1856
                }
34,227✔
1857

1858
                private void readPattern(HatchPattern pattern, int nlines)
1859
                {
1,224✔
1860
                        //Jump 78 code
1861
                        this._reader.ReadNext();
1,224✔
1862

1863
                        for (int i = 0; i < nlines; i++)
185,640✔
1864
                        {
91,596✔
1865
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1866
                                XY basePoint = new XY();
91,596✔
1867
                                XY offset = new XY();
91,596✔
1868

1869
                                bool end = false;
91,596✔
1870
                                HashSet<int> codes = new();
91,596✔
1871

1872
                                while (!end)
642,396✔
1873
                                {
641,172✔
1874
                                        if (codes.Contains(this._reader.Code))
641,172✔
1875
                                        {
90,372✔
1876
                                                break;
90,372✔
1877
                                        }
1878
                                        else
1879
                                        {
550,800✔
1880
                                                codes.Add(this._reader.Code);
550,800✔
1881
                                        }
550,800✔
1882

1883
                                        switch (this._reader.Code)
550,800!
1884
                                        {
1885
                                                case 53:
1886
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1887
                                                        break;
91,596✔
1888
                                                case 43:
1889
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1890
                                                        break;
91,596✔
1891
                                                case 44:
1892
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1893
                                                        line.BasePoint = basePoint;
91,596✔
1894
                                                        break;
91,596✔
1895
                                                case 45:
1896
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1897
                                                        line.Offset = offset;
91,596✔
1898
                                                        break;
91,596✔
1899
                                                case 46:
1900
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1901
                                                        line.Offset = offset;
91,596✔
1902
                                                        break;
91,596✔
1903
                                                //Number of dash length items
1904
                                                case 79:
1905
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1906
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1907
                                                        {
182,784✔
1908
                                                                this._reader.ReadNext();
182,784✔
1909
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1910
                                                        }
182,784✔
1911
                                                        break;
91,596✔
1912
                                                case 49:
1913
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1914
                                                        break;
×
1915
                                                default:
1916
                                                        end = true;
1,224✔
1917
                                                        break;
1,224✔
1918
                                        }
1919
                                        this._reader.ReadNext();
550,800✔
1920
                                }
550,800✔
1921

1922
                                pattern.Lines.Add(line);
91,596✔
1923
                        }
91,596✔
1924
                }
1,224✔
1925

1926
                private void readLoops(CadHatchTemplate template, int count)
1927
                {
1,632✔
1928
                        if (this._reader.Code == 91)
1,632✔
1929
                                this._reader.ReadNext();
1,632✔
1930

1931
                        for (int i = 0; i < count; i++)
6,528✔
1932
                        {
1,632✔
1933
                                if (this._reader.Code != 92)
1,632!
1934
                                {
×
1935
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1936
                                        break;
×
1937
                                }
1938

1939
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1940
                                if (path != null)
1,632✔
1941
                                        template.PathTemplates.Add(path);
1,632✔
1942
                        }
1,632✔
1943
                }
1,632✔
1944

1945
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1946
                {
1,632✔
1947
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1948
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1949
                        template.Path.Flags = flags;
1,632✔
1950

1951
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1952
                        {
612✔
1953
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1954
                                template.Path.Edges.Add(pl);
612✔
1955
                        }
612✔
1956
                        else
1957
                        {
1,020✔
1958
                                this._reader.ReadNext();
1,020✔
1959

1960
                                if (this._reader.Code != 93)
1,020!
1961
                                {
×
1962
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1963
                                        return null;
×
1964
                                }
1965

1966
                                int edges = this._reader.ValueAsInt;
1,020✔
1967
                                this._reader.ReadNext();
1,020✔
1968

1969
                                for (int i = 0; i < edges; i++)
10,200✔
1970
                                {
4,080✔
1971
                                        var edge = this.readEdge();
4,080✔
1972
                                        if (edge != null)
4,080✔
1973
                                                template.Path.Edges.Add(edge);
4,080✔
1974
                                }
4,080✔
1975
                        }
1,020✔
1976

1977
                        bool end = false;
1,632✔
1978
                        while (!end)
6,324✔
1979
                        {
4,692✔
1980
                                switch (this._reader.Code)
4,692✔
1981
                                {
1982
                                        //Number of source boundary objects
1983
                                        case 97:
1984
                                                break;
1,632✔
1985
                                        case 330:
1986
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1987
                                                break;
1,428✔
1988
                                        default:
1989
                                                end = true;
1,632✔
1990
                                                continue;
1,632✔
1991
                                }
1992

1993
                                this._reader.ReadNext();
3,060✔
1994
                        }
3,060✔
1995

1996
                        return template;
1,632✔
1997
                }
1,632✔
1998

1999
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
2000
                {
612✔
2001
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
2002

2003
                        this._reader.ReadNext();
612✔
2004

2005
                        if (this._reader.Code != 72)
612!
2006
                        {
×
2007
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
2008
                                return null;
×
2009
                        }
2010

2011
                        bool end = false;
612✔
2012
                        bool hasBulge = false;
612✔
2013
                        while (!end)
3,060✔
2014
                        {
2,448✔
2015
                                switch (this._reader.Code)
2,448✔
2016
                                {
2017
                                        case 72:
2018
                                                hasBulge = this._reader.ValueAsBool;
612✔
2019
                                                break;
612✔
2020
                                        case 73:
2021
                                                boundary.IsClosed = this._reader.ValueAsBool;
612✔
2022
                                                break;
612✔
2023
                                        case 93:
2024
                                                int nvertices = this._reader.ValueAsInt;
612✔
2025
                                                this._reader.ReadNext();
612✔
2026

2027
                                                for (int i = 0; i < nvertices; i++)
6,120✔
2028
                                                {
2,448✔
2029
                                                        double bulge = 0.0;
2,448✔
2030

2031
                                                        //10
2032
                                                        double x = this._reader.ValueAsDouble;
2,448✔
2033
                                                        this._reader.ReadNext();
2,448✔
2034
                                                        //20
2035
                                                        double y = this._reader.ValueAsDouble;
2,448✔
2036
                                                        this._reader.ReadNext();
2,448✔
2037

2038
                                                        if (hasBulge)
2,448!
2039
                                                        {
×
2040
                                                                //42
2041
                                                                bulge = this._reader.ValueAsDouble;
×
2042
                                                                this._reader.ReadNext();
×
2043
                                                        }
×
2044

2045
                                                        boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
2046
                                                }
2,448✔
2047
                                                continue;
612✔
2048
                                        default:
2049
                                                end = true;
612✔
2050
                                                continue;
612✔
2051
                                }
2052

2053
                                this._reader.ReadNext();
1,224✔
2054
                        }
1,224✔
2055

2056
                        return boundary;
612✔
2057
                }
612✔
2058

2059
                private Hatch.BoundaryPath.Edge readEdge()
2060
                {
4,080✔
2061
                        if (this._reader.Code != 72)
4,080!
2062
                        {
×
2063
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
2064
                                return null;
×
2065
                        }
2066

2067
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
2068
                        this._reader.ReadNext();
4,080✔
2069

2070
                        switch (type)
4,080!
2071
                        {
2072
                                case Hatch.BoundaryPath.EdgeType.Line:
2073
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,080✔
2074
                                        while (true)
20,400✔
2075
                                        {
20,400✔
2076
                                                switch (this._reader.Code)
20,400✔
2077
                                                {
2078
                                                        case 10:
2079
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,080✔
2080
                                                                break;
4,080✔
2081
                                                        case 20:
2082
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,080✔
2083
                                                                break;
4,080✔
2084
                                                        case 11:
2085
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,080✔
2086
                                                                break;
4,080✔
2087
                                                        case 21:
2088
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,080✔
2089
                                                                break;
4,080✔
2090
                                                        default:
2091
                                                                return line;
4,080✔
2092
                                                }
2093

2094
                                                this._reader.ReadNext();
16,320✔
2095
                                        }
16,320✔
2096
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
2097
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
2098
                                        while (true)
×
2099
                                        {
×
2100
                                                switch (this._reader.Code)
×
2101
                                                {
2102
                                                        case 10:
2103
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
2104
                                                                break;
×
2105
                                                        case 20:
2106
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
2107
                                                                break;
×
2108
                                                        case 40:
2109
                                                                arc.Radius = this._reader.ValueAsDouble;
×
2110
                                                                break;
×
2111
                                                        case 50:
2112
                                                                arc.StartAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2113
                                                                break;
×
2114
                                                        case 51:
2115
                                                                arc.EndAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2116
                                                                break;
×
2117
                                                        case 73:
2118
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
2119
                                                                break;
×
2120
                                                        default:
2121
                                                                return arc;
×
2122
                                                }
2123

2124
                                                this._reader.ReadNext();
×
2125
                                        }
×
2126
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
2127
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
2128
                                        while (true)
×
2129
                                        {
×
2130
                                                switch (this._reader.Code)
×
2131
                                                {
2132
                                                        case 10:
2133
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2134
                                                                break;
×
2135
                                                        case 20:
2136
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2137
                                                                break;
×
2138
                                                        case 11:
2139
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2140
                                                                break;
×
2141
                                                        case 21:
2142
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2143
                                                                break;
×
2144
                                                        case 40:
2145
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
2146
                                                                break;
×
2147
                                                        case 50:
2148
                                                                ellipse.StartAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2149
                                                                break;
×
2150
                                                        case 51:
2151
                                                                ellipse.EndAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2152
                                                                break;
×
2153
                                                        case 73:
2154
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
2155
                                                                break;
×
2156
                                                        default:
2157
                                                                return ellipse;
×
2158
                                                }
2159

2160
                                                this._reader.ReadNext();
×
2161
                                        }
×
2162
                                case Hatch.BoundaryPath.EdgeType.Spline:
2163
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
2164
                                        int nKnots = 0;
×
2165
                                        int nCtrlPoints = 0;
×
2166
                                        int nFitPoints = 0;
×
2167

2168
                                        XYZ controlPoint = new XYZ();
×
2169
                                        XY fitPoint = new XY();
×
2170

2171
                                        while (true)
×
2172
                                        {
×
2173
                                                switch (this._reader.Code)
×
2174
                                                {
2175
                                                        case 10:
2176
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
2177
                                                                break;
×
2178
                                                        case 20:
2179
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
2180
                                                                spline.ControlPoints.Add(controlPoint);
×
2181
                                                                break;
×
2182
                                                        case 11:
2183
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
2184
                                                                break;
×
2185
                                                        case 21:
2186
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
2187
                                                                spline.FitPoints.Add(fitPoint);
×
2188
                                                                break;
×
2189
                                                        case 42:
2190
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
2191
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
2192
                                                                break;
×
2193
                                                        case 12:
2194
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
2195
                                                                break;
×
2196
                                                        case 22:
2197
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
2198
                                                                break;
×
2199
                                                        case 13:
2200
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
2201
                                                                break;
×
2202
                                                        case 23:
2203
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
2204
                                                                break;
×
2205
                                                        case 94:
2206
                                                                spline.Degree = this._reader.ValueAsInt;
×
2207
                                                                break;
×
2208
                                                        case 73:
2209
                                                                spline.IsRational = this._reader.ValueAsBool;
×
2210
                                                                break;
×
2211
                                                        case 74:
2212
                                                                spline.IsPeriodic = this._reader.ValueAsBool;
×
2213
                                                                break;
×
2214
                                                        case 95:
2215
                                                                nKnots = this._reader.ValueAsInt;
×
2216
                                                                break;
×
2217
                                                        case 96:
2218
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
2219
                                                                break;
×
2220
                                                        case 97:
2221
                                                                nFitPoints = this._reader.ValueAsInt;
×
2222
                                                                break;
×
2223
                                                        case 40:
2224
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
2225
                                                                break;
×
2226
                                                        default:
2227
                                                                return spline;
×
2228
                                                }
2229

2230
                                                this._reader.ReadNext();
×
2231
                                        }
×
2232
                        }
2233

2234
                        return null;
×
2235
                }
4,080✔
2236

2237
                private void readDefinedGroups(CadTemplate template)
2238
                {
68,231✔
2239
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
68,231✔
2240

2241
                        if (xdict.HasValue)
68,231✔
2242
                        {
9,871✔
2243
                                template.XDictHandle = xdict;
9,871✔
2244
                        }
9,871✔
2245
                        template.ReactorsHandles.UnionWith(reactorsHandles);
68,231✔
2246
                }
68,231✔
2247

2248
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2249
                {
68,440✔
2250
                        xdictHandle = null;
68,440✔
2251
                        reactors = new HashSet<ulong>();
68,440✔
2252

2253
                        switch (this._reader.ValueAsString)
68,440✔
2254
                        {
2255
                                case DxfFileToken.DictionaryToken:
2256
                                        this._reader.ReadNext();
10,080✔
2257
                                        xdictHandle = this._reader.ValueAsHandle;
10,080✔
2258
                                        this._reader.ReadNext();
10,080✔
2259
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,080✔
2260
                                        return;
10,080✔
2261
                                case DxfFileToken.ReactorsToken:
2262
                                        reactors = this.readReactors();
56,309✔
2263
                                        break;
56,309✔
2264
                                case DxfFileToken.BlkRefToken:
2265
                                default:
2266
                                        do
2267
                                        {
5,326✔
2268
                                                this._reader.ReadNext();
5,326✔
2269
                                        }
5,326✔
2270
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,326✔
2271
                                        return;
2,051✔
2272
                        }
2273
                }
68,440✔
2274

2275
                private HashSet<ulong> readReactors()
2276
                {
56,309✔
2277
                        HashSet<ulong> reactors = new();
56,309✔
2278

2279
                        this._reader.ReadNext();
56,309✔
2280

2281
                        while (this._reader.DxfCode != DxfCode.ControlString)
119,122✔
2282
                        {
62,813✔
2283
                                reactors.Add(this._reader.ValueAsHandle);
62,813✔
2284

2285
                                this._reader.ReadNext();
62,813✔
2286
                        }
62,813✔
2287

2288
                        return reactors;
56,309✔
2289
                }
56,309✔
2290

2291
                protected bool tryAssignCurrentValue(object cadObject, DxfMap map)
2292
                {
59✔
2293
                        if (string.IsNullOrEmpty(this.currentSubclass))
59✔
2294
                        {
6✔
2295
                                return false;
6✔
2296
                        }
2297

2298
                        if (map.SubClasses.TryGetValue(this.currentSubclass, out var subClass))
53!
2299
                        {
53✔
2300
                                return this.tryAssignCurrentValue(cadObject, subClass);
53✔
2301
                        }
2302
                        else
2303
                        {
×
2304
                                return false;
×
2305
                        }
2306
                }
59✔
2307

2308
                protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2309
                {
4,222,363✔
2310
                        try
2311
                        {
4,222,363✔
2312
                                //Use this method only if the value is not a link between objects
2313
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,222,363✔
2314
                                {
2,229,254✔
2315
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,229,254✔
2316
                                        {
12,971✔
2317
                                                return true;
12,971✔
2318
                                        }
2319

2320
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,216,283✔
2321
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,216,283✔
2322
                                        {
16,352✔
2323
                                                return false;
16,352✔
2324
                                        }
2325

2326
                                        object value = this._reader.Value;
2,199,931✔
2327

2328
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,199,931✔
2329
                                        {
24,820✔
2330
                                                value = MathHelper.DegToRad((double)value);
24,820✔
2331
                                        }
24,820✔
2332

2333
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,199,931✔
2334

2335
                                        return true;
2,199,931✔
2336
                                }
2337
                        }
1,993,109✔
2338
                        catch (Exception ex)
×
2339
                        {
×
2340
                                if (!this._builder.Configuration.Failsafe)
×
2341
                                {
×
2342
                                        throw ex;
×
2343
                                }
2344
                                else
2345
                                {
×
2346
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2347
                                }
×
2348
                        }
×
2349

2350
                        return false;
1,993,109✔
2351
                }
4,222,363✔
2352
        }
2353
}
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