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

DomCR / ACadSharp / 30613400426

31 Jul 2026 07:36AM UTC coverage: 75.789% (-0.02%) from 75.805%
30613400426

push

github

web-flow
Merge pull request #1164 from simonedd/add-arc-dimension-entity

Add DimensionArc entity with DWG and DXF read/write support

9191 of 13117 branches covered (70.07%)

Branch coverage included in aggregate %.

68 of 112 new or added lines in 6 files covered. (60.71%)

32997 of 42548 relevant lines covered (77.55%)

152286.8 hits per line

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

80.42
/src/ACadSharp/IO/DXF/DxfStreamReader/DxfSectionReaderBase.cs
1
using ACadSharp.Entities;
2
using ACadSharp.IO.Templates;
3
using ACadSharp.Objects;
4
using ACadSharp.Tables;
5
using ACadSharp.XData;
6
using CSMath;
7
using CSUtilities.Extensions;
8
using System;
9
using System.Collections.Generic;
10
using System.Diagnostics;
11
using System.Linq;
12
using static ACadSharp.IO.Templates.CadMLeaderAnnotContextTemplate;
13
using static ACadSharp.IO.Templates.CadTableEntityTemplate;
14

15
namespace ACadSharp.IO.DXF.DxfStreamReader;
16

17
internal abstract class DxfSectionReaderBase
18
{
19
        public delegate bool ReadEntityDelegate<T>(CadEntityTemplate template, DxfMap map, string subclass = null) where T : Entity;
20

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

24
        //Avoid to move the reader to the next line
25
        protected bool lockPointer = false;
1,100✔
26
        protected string currentSubclass = null;
1,100✔
27

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

34
        public abstract void Read();
35

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

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

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

80
                        this._reader.ReadNext();
7,144✔
81
                }
7,144✔
82
        }
2,403✔
83

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

112
                        this._reader.ReadNext();
1,836✔
113
                }
1,836✔
114
        }
612✔
115

116
        protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
117
        {
841,960✔
118
                isExtendedData = false;
841,960✔
119

120
                switch (this._reader.Code)
841,960✔
121
                {
122
                        //Handle
123
                        case 5:
124
                                template.CadObject.Handle = this._reader.ValueAsHandle;
316,807✔
125
                                break;
316,807✔
126
                        //Check with mapper
127
                        case 100:
128
                                this.currentSubclass = this._reader.ValueAsString;
218,686✔
129
                                if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
218,686!
130
                                {
924✔
131
                                        this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
924✔
132
                                }
924✔
133
                                break;
218,686✔
134
                        //Start of application - defined group
135
                        case 102:
136
                                this.readDefinedGroups(template);
72,194✔
137
                                break;
72,194✔
138
                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
139
                        case 330:
140
                                template.OwnerHandle = this._reader.ValueAsHandle;
179,504✔
141
                                break;
179,504✔
142
                        case 1001:
143
                                isExtendedData = true;
24,767✔
144
                                this.readExtendedData(template.EDataTemplateByAppName);
24,767✔
145
                                break;
24,767✔
146
                        default:
147
                                this._builder.Notify($"[{this.currentSubclass}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
30,002✔
148
                                break;
30,002✔
149
                }
150
        }
841,960✔
151

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

250
                                this._reader.ReadNext();
×
251

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

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

265
                                return unknownEntityTemplate;
×
266
                }
267
        }
154,967✔
268

269
        protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
270
                where T : Entity
271
        {
206,761✔
272
                this._reader.ReadNext();
206,761✔
273

274
                DxfMap map = DxfMap.Create<T>();
206,761✔
275

276
                while (this._reader.DxfCode != DxfCode.Start)
2,799,745✔
277
                {
2,592,984✔
278
                        if (!readEntity(template, map))
2,592,984✔
279
                        {
905,931✔
280
                                this.readCommonEntityCodes(template, out bool isExtendedData, map);
905,931✔
281
                                if (isExtendedData)
905,931✔
282
                                        continue;
14,487✔
283
                        }
891,444✔
284

285
                        if (this.lockPointer)
2,578,497✔
286
                        {
3,168✔
287
                                this.lockPointer = false;
3,168✔
288
                                continue;
3,168✔
289
                        }
290

291
                        if (this._reader.DxfCode != DxfCode.Start)
2,575,329✔
292
                                this._reader.ReadNext();
2,574,827✔
293
                }
2,575,329✔
294

295
                return template;
206,761✔
296
        }
206,761✔
297

298
        protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
299
        {
977,819✔
300
                isExtendedData = false;
977,819✔
301
                switch (this._reader.Code)
977,819✔
302
                {
303
                        case 6:
304
                                template.LineTypeName = this._reader.ValueAsString;
27,278✔
305
                                break;
27,278✔
306
                        case 8:
307
                                template.LayerName = this._reader.ValueAsString;
224,319✔
308
                                break;
224,319✔
309
                        //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
310
                        case 67:
311
                                break;
1,344✔
312
                        //Number of bytes Proxy entity graphics data
313
                        case 92:
314
                        case 160:
315
                        //Proxy entity graphics data
316
                        case 310:
317
                                break;
81,072✔
318
                        case 347:
319
                                template.MaterialHandle = this._reader.ValueAsHandle;
720✔
320
                                break;
720✔
321
                        case 430:
322
                                template.BookColorName = this._reader.ValueAsString;
180✔
323
                                break;
180✔
324
                        default:
325
                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
642,906✔
326
                                {
501,504✔
327
                                        this.readCommonCodes(template, out isExtendedData, map);
501,504✔
328
                                }
501,504✔
329
                                break;
642,906✔
330
                }
331
        }
977,819✔
332

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

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

358
        private bool readCircle(CadEntityTemplate template, DxfMap map, string subclass = null)
359
        {
38,125✔
360
                Circle circle = template.CadObject as Circle;
38,125✔
361

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

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

393
        private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
394
        {
35,474✔
395
                DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
35,474✔
396
                CadAttributeTemplate tmp = template as CadAttributeTemplate;
35,474✔
397

398
                switch (this._reader.Code)
35,474!
399
                {
400
                        case 44:
401
                        case 46:
402
                                return true;
×
403
                        case 101:
404
                                var att = tmp.CadObject as AttributeBase;
70✔
405
                                att.MText = new MText();
70✔
406
                                CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
70✔
407
                                tmp.MTextTemplate = mtextTemplate;
70✔
408
                                this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
70✔
409
                                return true;
70✔
410
                        default:
411
                                if (!this.tryAssignCurrentValue(template.CadObject, emap))
35,404✔
412
                                {
26,786✔
413
                                        return this.readTextEntity(template, map, DxfSubclassMarker.Text);
26,786✔
414
                                }
415
                                return true;
8,618✔
416
                }
417
        }
35,474✔
418

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

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

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

593
        protected CadValueTemplate readCadValue(CadValue value)
594
        {
9,848✔
595
                this._reader.ReadNext();
9,848✔
596

597
                CadValueTemplate template = new(value);
9,848✔
598
                var map = DxfClassMap.Create(value.GetType(), "CadValue");
9,848✔
599

600
                while (this._reader.Code != 304)
65,384✔
601
                {
55,536✔
602
                        switch (this._reader.Code)
55,536!
603
                        {
604
                                case 1:
605
                                        value.SetValue(this._reader.ValueAsString);
3,496✔
606
                                        break;
3,496✔
607
                                case 2:
608
                                        value.SetValue((value.Value as string) + this._reader.ValueAsString);
×
609
                                        break;
×
610
                                case 11:
611
                                        XYZ xyz = new XYZ();
280✔
612
                                        xyz.X = this._reader.ValueAsDouble;
280✔
613
                                        value.SetValue(xyz);
280✔
614
                                        break;
280✔
615
                                case 21:
616
                                        {
280✔
617
                                                IVector v = value.Value as IVector;
280✔
618
                                                v[1] = this._reader.ValueAsDouble;
280✔
619
                                                value.SetValue(v);
280✔
620
                                        }
280✔
621
                                        break;
280✔
622
                                case 31:
623
                                        {
280✔
624
                                                IVector v = value.Value as IVector;
280✔
625
                                                v = v.Convert<XYZ>();
280✔
626
                                                v[2] = this._reader.ValueAsDouble;
280✔
627
                                                value.SetValue(v);
280✔
628
                                        }
280✔
629
                                        break;
280✔
630
                                case 90:
631
                                        value.ValueType = (CadValueType)this._reader.ValueAsInt;
9,848✔
632
                                        break;
9,848✔
633
                                case 91:
634
                                        value.SetValue(this._reader.ValueAsInt);
280✔
635
                                        break;
280✔
636
                                case 93:
637
                                        value.Flags = this._reader.ValueAsInt;
9,848✔
638
                                        break;
9,848✔
639
                                case 140:
640
                                        value.SetValue(this._reader.ValueAsDouble);
1,120✔
641
                                        break;
1,120✔
642
                                case 330:
643
                                        template.ValueHandle = this._reader.ValueAsHandle;
×
644
                                        break;
×
645
                                default:
646
                                        if (!this.tryAssignCurrentValue(value, map))
30,104✔
647
                                        {
560✔
648
                                                this._builder.Notify($"Unhandled dxf code {this._reader.Code} value {this._reader.ValueAsString} at {nameof(readCadValue)} method.", NotificationType.None);
560✔
649
                                        }
560✔
650
                                        break;
30,104✔
651
                        }
652

653
                        this._reader.ReadNext();
55,536✔
654
                }
55,536✔
655

656
                return template;
9,848✔
657
        }
9,848✔
658

659
        private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
660
        {
306,634✔
661
                string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
306,634✔
662
                CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
306,634✔
663

664
                switch (this._reader.Code)
306,634✔
665
                {
666
                        case 1 or 3 when tmp.CadObject is MText mtext:
27,506✔
667
                                mtext.Value += this._reader.ValueAsString;
10,282✔
668
                                return true;
10,282✔
669
                        case 50 when tmp.CadObject is MText mtext://Read only for MText
510!
670
                                double angle = this._reader.ValueAsAngle;
×
671
                                mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
672
                                return true;
×
673
                        case 7:
674
                                tmp.StyleName = this._reader.ValueAsString;
3,024✔
675
                                return true;
3,024✔
676
                        case 101 when tmp.CadObject is MText mtext:
144✔
677
                                this.readColumnData(mtext);
144✔
678
                                this.lockPointer = true;
144✔
679
                                return true;
144✔
680
                        default:
681
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
293,184✔
682
                }
683
        }
306,634✔
684

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

738
                        this._reader.ReadNext();
2,592✔
739
                }
2,592✔
740
        }
144✔
741

742
        private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
743
        {
6,480✔
744
                CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,480✔
745

746
                switch (this._reader.Code)
6,480✔
747
                {
748
                        case 3:
749
                                tmp.DimensionStyleName = this._reader.ValueAsString;
648✔
750
                                return true;
648✔
751
                        default:
752
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,832✔
753
                }
754
        }
6,480✔
755

756
        private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
757
        {
72,504✔
758
                CadDimensionTemplate tmp = template as CadDimensionTemplate;
72,504✔
759

760
                switch (this._reader.Code)
72,504✔
761
                {
762
                        case 2:
763
                                tmp.BlockName = this._reader.ValueAsString;
2,772✔
764
                                return true;
2,772✔
765
                        case 3:
766
                                tmp.StyleName = this._reader.ValueAsString;
2,376✔
767
                                return true;
2,376✔
768
                        case 50:
769
                                if (tmp.CadObject is not DimensionLinear dim)
252✔
770
                                {
216✔
771
                                        dim = new DimensionLinear();
216✔
772
                                        tmp.SetDimensionObject(dim);
216✔
773
                                }
216✔
774
                                dim.Rotation = this._reader.ValueAsAngle;
252✔
775
                                map.SubClasses.TryAdd(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
252✔
776
                                return true;
252✔
777
                        case 70 when tmp.CadObject is DimensionArc arc && this.currentSubclass == DxfSubclassMarker.ArcDimension:
2,772!
NEW
778
                                arc.IsPartial = this._reader.ValueAsBool;
×
NEW
779
                                return true;
×
780
                        case 70:
781
                                //Flags do not have set
782
                                tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,772✔
783

784
                                if (tmp.CadObject is CadDimensionTemplate.DimensionPlaceholder placeholder && this._builder.Version < ACadVersion.AC1012)
2,772!
785
                                {
396✔
786
                                        switch (placeholder.Flags)
396!
787
                                        {
788
                                                case DimensionType.Linear:
789
                                                        tmp.SetDimensionObject(new DimensionLinear());
108✔
790
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.AlignedDimension, DxfClassMap.Create<DimensionAligned>());
108✔
791
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
108✔
792
                                                        break;
108✔
793
                                                case DimensionType.Aligned:
794
                                                        tmp.SetDimensionObject(new DimensionAligned());
72✔
795
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.AlignedDimension, DxfClassMap.Create<DimensionAligned>());
72✔
796
                                                        break;
72✔
797
                                                case DimensionType.Angular:
798
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
36✔
799
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.Angular2LineDimension, DxfClassMap.Create<DimensionAngular2Line>());
36✔
800
                                                        break;
36✔
801
                                                case DimensionType.Diameter:
802
                                                        tmp.SetDimensionObject(new DimensionDiameter());
×
803
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.DiametricDimension, DxfClassMap.Create<DimensionDiameter>());
×
804
                                                        break;
×
805
                                                case DimensionType.Radius:
806
                                                        tmp.SetDimensionObject(new DimensionRadius());
36✔
807
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.RadialDimension, DxfClassMap.Create<DimensionRadius>());
36✔
808
                                                        break;
36✔
809
                                                case DimensionType.Angular3Point:
810
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
36✔
811
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.Angular3PointDimension, DxfClassMap.Create<DimensionAngular3Pt>());
36✔
812
                                                        break;
36✔
813
                                                case DimensionType.Ordinate:
814
                                                case DimensionType.OrdinateTypeX:
815
                                                case DimensionType.Ordinate | DimensionType.OrdinateTypeX:
816
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
72✔
817
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.OrdinateDimension, DxfClassMap.Create<DimensionOrdinate>());
72✔
818
                                                        break;
72✔
819
                                                case DimensionType.BlockReference:
820
                                                case DimensionType.TextUserDefinedLocation:
821
                                                default:
822
                                                        break;
36✔
823
                                        }
824
                                }
396✔
825
                                return true;
2,772✔
826
                        //Measurement - read only
827
                        case 42:
828
                                return true;
2,376✔
829
                        //Undocumented codes
830
                        case 73:
831
                        case 74:
832
                        case 75:
833
                        case 90:
834
                        case 361:
835
                                return true;
4,752✔
836
                        case 100:
837
                                this.currentSubclass = this._reader.ValueAsString;
7,776✔
838
                                switch (this._reader.ValueAsString)
7,776!
839
                                {
840
                                        case DxfSubclassMarker.Dimension:
841
                                                return true;
2,376✔
842
                                        case DxfSubclassMarker.AlignedDimension:
843
                                                tmp.SetDimensionObject(new DimensionAligned());
1,080✔
844
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,080✔
845
                                                return true;
1,080✔
846
                                        case DxfSubclassMarker.DiametricDimension:
847
                                                tmp.SetDimensionObject(new DimensionDiameter());
216✔
848
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
216✔
849
                                                return true;
216✔
850
                                        case DxfSubclassMarker.Angular2LineDimension:
851
                                                tmp.SetDimensionObject(new DimensionAngular2Line());
216✔
852
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
216✔
853
                                                return true;
216✔
854
                                        case DxfSubclassMarker.Angular3PointDimension:
855
                                                tmp.SetDimensionObject(new DimensionAngular3Pt());
216✔
856
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
216✔
857
                                                return true;
216✔
858
                                        case DxfSubclassMarker.ArcDimension:
NEW
859
                                                tmp.SetDimensionObject(new DimensionArc());
×
NEW
860
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionArc>());
×
NEW
861
                                                return true;
×
862
                                        case DxfSubclassMarker.RadialDimension:
863
                                                tmp.SetDimensionObject(new DimensionRadius());
216✔
864
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
216✔
865
                                                return true;
216✔
866
                                        case DxfSubclassMarker.OrdinateDimension:
867
                                                tmp.SetDimensionObject(new DimensionOrdinate());
432✔
868
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
432✔
869
                                                return true;
432✔
870
                                        case DxfSubclassMarker.LinearDimension:
871
                                                tmp.SetDimensionObject(new DimensionLinear());
648✔
872
                                                map.SubClasses.TryAdd(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
648✔
873
                                                return true;
648✔
874
                                        default:
875
                                                return false;
2,376✔
876
                                }
877
                        default:
878
                                if (string.IsNullOrEmpty(this.currentSubclass))
49,428✔
879
                                {
2,772✔
880
                                        //Pre R13 files do not have the subclass markers
881
                                        this.currentSubclass = tmp.CadObject.SubclassMarker;
2,772✔
882
                                }
2,772✔
883

884
                                return this.tryAssignCurrentValue(template.CadObject, map);
49,428✔
885
                }
886
        }
72,504✔
887

888
        protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
889
        {
46,224✔
890
                CadHatchTemplate tmp = template as CadHatchTemplate;
46,224✔
891
                Hatch hatch = tmp.CadObject;
46,224✔
892

893
                XY seedPoint = new XY();
46,224✔
894

895
                switch (this._reader.Code)
46,224!
896
                {
897
                        case 2:
898
                                hatch.Pattern.Name = this._reader.ValueAsString;
1,728✔
899
                                return true;
1,728✔
900
                        case 10:
901
                                seedPoint.X = this._reader.ValueAsDouble;
3,456✔
902
                                hatch.SeedPoints.Add(seedPoint);
3,456✔
903
                                return true;
3,456✔
904
                        case 20:
905
                                seedPoint = hatch.SeedPoints.LastOrDefault();
3,456✔
906
                                seedPoint.Y = this._reader.ValueAsDouble;
3,456✔
907
                                hatch.SeedPoints[hatch.SeedPoints.Count - 1] = seedPoint;
3,456✔
908
                                return true;
3,456✔
909
                        case 30:
910
                                hatch.Elevation = this._reader.ValueAsDouble;
1,728✔
911
                                return true;
1,728✔
912
                        case 53:
913
                                hatch.PatternAngle = this._reader.ValueAsAngle;
×
914
                                return true;
×
915
                        //TODO: Check hatch undocumented codes
916
                        case 90:
917
                                return true;
×
918
                        //Information about the hatch pattern
919
                        case 75:
920
                                return true;
1,728✔
921
                        //Number of pattern definition lines
922
                        case 78:
923
                                this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,296✔
924
                                this.lockPointer = true;
1,296✔
925
                                return true;
1,296✔
926
                        //Number of boundary paths (loops)
927
                        case 91:
928
                                this.readLoops(tmp, this._reader.ValueAsInt);
1,728✔
929
                                this.lockPointer = true;
1,728✔
930
                                return true;
1,728✔
931
                        //Number of seed points
932
                        case 98:
933
                                return true;
1,080✔
934
                        case 450:
935
                                hatch.GradientColor.Enabled = this._reader.ValueAsBool;
360✔
936
                                return true;
360✔
937
                        case 451:
938
                                hatch.GradientColor.Reserved = this._reader.ValueAsInt;
360✔
939
                                return true;
360✔
940
                        case 452:
941
                                hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
360✔
942
                                return true;
360✔
943
                        case 453:
944
                                //Number of colors
945
                                return true;
360✔
946
                        case 460:
947
                                hatch.GradientColor.Angle = this._reader.ValueAsDouble;
360✔
948
                                return true;
360✔
949
                        case 461:
950
                                hatch.GradientColor.Shift = this._reader.ValueAsDouble;
360✔
951
                                return true;
360✔
952
                        case 462:
953
                                hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
360✔
954
                                return true;
360✔
955
                        case 463:
956
                                GradientColor gradient = new GradientColor();
720✔
957
                                gradient.Value = this._reader.ValueAsDouble;
720✔
958
                                hatch.GradientColor.Colors.Add(gradient);
720✔
959
                                return true;
720✔
960
                        case 63:
961
                                GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
720✔
962
                                if (colorByIndex != null)
720✔
963
                                {
720✔
964
                                        colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
720✔
965
                                }
720✔
966
                                return true;
720✔
967
                        case 421:
968
                                GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
720✔
969
                                if (colorByRgb != null)
720✔
970
                                {
720✔
971
                                        //TODO: Hatch assign color by true color
972
                                        //TODO: Is always duplicated by 63, is it needed??
973
                                        //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
974
                                }
720✔
975
                                return true;
720✔
976
                        case 470:
977
                                hatch.GradientColor.Name = this._reader.ValueAsString;
360✔
978
                                return true;
360✔
979
                        default:
980
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
24,984✔
981
                }
982
        }
46,224✔
983

984
        private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
985
        {
62,641✔
986
                CadInsertTemplate tmp = template as CadInsertTemplate;
62,641✔
987

988
                switch (this._reader.Code)
62,641✔
989
                {
990
                        case 2:
991
                                tmp.BlockName = this._reader.ValueAsString;
5,857✔
992
                                return true;
5,857✔
993
                        case 100:
994
                                //AcDbEntity
995
                                //AcDbBlockReference
996
                                //AcDbMInsertBlock
997
                                return true;
5,890✔
998
                        case 66:
999
                                return true;
504✔
1000
                        default:
1001
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
50,390✔
1002
                }
1003
        }
62,641✔
1004

1005
        private CadEntityTemplate readPolyline()
1006
        {
11,092✔
1007
                if (this._builder.Version == ACadVersion.Unknown
11,092!
1008
                        || this._builder.Version == ACadVersion.AC1009)
11,092✔
1009
                {
10,660✔
1010
                        return this.readLegacyPolyline();
10,660✔
1011
                }
1012

1013
                CadPolyLineTemplate template = null;
432✔
1014
                template = new CadPolyLineTemplate();
432✔
1015
                this.readEntityCodes<Entity>(template, this.readPolyline);
432✔
1016

1017
                if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
432!
1018
                {
×
1019
                        this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
1020
                        return null;
×
1021
                }
1022

1023
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
3,024!
1024
                {
2,592✔
1025
                        var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,592✔
1026

1027
                        if (vertexTemplate.OwnerHandle == null)
2,592!
1028
                        {
×
1029
                                vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
1030
                        }
×
1031

1032
                        template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,592✔
1033
                        _builder.AddTemplate(vertexTemplate);
2,592✔
1034
                }
2,592✔
1035

1036
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
864!
1037
                {
432✔
1038
                        var seqend = new Seqend();
432✔
1039
                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
432✔
1040
                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
432✔
1041

1042
                        if (seqendTemplate.OwnerHandle == null)
432!
1043
                        {
×
1044
                                seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
1045
                        }
×
1046

1047
                        template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
432✔
1048
                        _builder.AddTemplate(seqendTemplate);
432✔
1049
                }
432✔
1050

1051
                return template;
432✔
1052
        }
11,092✔
1053

1054
        private CadEntityTemplate readLegacyPolyline()
1055
        {
10,660✔
1056
                var polyline = new Polyline2D();
10,660✔
1057
                CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,660✔
1058
                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,660✔
1059

1060
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
48,700!
1061
                {
38,040✔
1062
                        Vertex2D v = new Vertex2D();
38,040✔
1063
                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
38,040✔
1064
                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
38,040✔
1065

1066
                        if (vertexTemplate.Vertex.Handle == 0)
38,040!
1067
                        {
×
1068
                                polyline.Vertices.Add(v);
×
1069
                        }
×
1070
                        else
1071
                        {
38,040✔
1072
                                template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
38,040✔
1073
                                this._builder.AddTemplate(vertexTemplate);
38,040✔
1074
                        }
38,040✔
1075
                }
38,040✔
1076

1077
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
21,320!
1078
                {
10,660✔
1079
                        var seqend = new Seqend();
10,660✔
1080
                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,660✔
1081
                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,660✔
1082

1083
                        polyline.Vertices.Seqend = seqend;
10,660✔
1084
                }
10,660✔
1085

1086
                return template;
10,660✔
1087
        }
10,660✔
1088

1089
        private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1090
        {
79,656✔
1091
                CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
79,656✔
1092

1093
                switch (this._reader.Code)
79,656✔
1094
                {
1095
                        //DXF: always 0
1096
                        //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)
1097
                        case 10:
1098
                        case 20:
1099
                        //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1100
                        case 66:
1101
                                return true;
33,276✔
1102
                        case 100:
1103
                                switch (this._reader.ValueAsString)
864!
1104
                                {
1105
                                        case DxfSubclassMarker.Polyline:
1106
                                                tmp.SetPolyLineObject(new Polyline2D());
×
1107
                                                map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
1108
                                                return true;
×
1109
                                        case DxfSubclassMarker.Polyline3d:
1110
                                                tmp.SetPolyLineObject(new Polyline3D());
216✔
1111
                                                map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
216✔
1112
                                                return true;
216✔
1113
                                        case DxfSubclassMarker.PolyfaceMesh:
1114
                                                tmp.SetPolyLineObject(new PolyfaceMesh());
216✔
1115
                                                map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
216✔
1116
                                                return true;
216✔
1117
                                        case DxfSubclassMarker.PolygonMesh:
1118
                                                tmp.SetPolyLineObject(new PolygonMesh());
×
1119
                                                map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
1120
                                                return true;
×
1121
                                        default:
1122
                                                return false;
432✔
1123
                                }
1124
                        default:
1125
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
45,516✔
1126
                }
1127
        }
79,656✔
1128

1129
        private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1130
        {
5,400✔
1131
                CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,400✔
1132

1133
                switch (this._reader.Code)
5,400✔
1134
                {
1135
                        case 3:
1136
                                tmp.DIMSTYLEName = this._reader.ValueAsString;
216✔
1137
                                return true;
216✔
1138
                        case 10:
1139
                                tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
864✔
1140
                                return true;
864✔
1141
                        case 20:
1142
                                XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
864✔
1143
                                y.Y = this._reader.ValueAsDouble;
864✔
1144
                                tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
864✔
1145
                                return true;
864✔
1146
                        case 30:
1147
                                XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
864✔
1148
                                z.Z = this._reader.ValueAsDouble;
864✔
1149
                                tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
864✔
1150
                                return true;
864✔
1151
                        case 340:
1152
                                tmp.AnnotationHandle = this._reader.ValueAsHandle;
216✔
1153
                                return true;
216✔
1154
                        //Hook line flag - read only
1155
                        case 75:
1156
                        //Vertices count
1157
                        case 76:
1158
                                return true;
432✔
1159
                        default:
1160
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,944✔
1161
                }
1162
        }
5,400✔
1163

1164
        private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1165
        {
92,700✔
1166
                CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
92,700✔
1167

1168
                LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
92,700✔
1169

1170
                switch (this._reader.Code)
92,700!
1171
                {
1172
                        case 10:
1173
                                tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
22,048✔
1174
                                return true;
22,048✔
1175
                        case 20:
1176
                                if (last is not null)
22,048✔
1177
                                {
22,048✔
1178
                                        last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
22,048✔
1179
                                }
22,048✔
1180
                                return true;
22,048✔
1181
                        case 40:
1182
                                if (last is not null)
2,160✔
1183
                                {
2,160✔
1184
                                        last.StartWidth = this._reader.ValueAsDouble;
2,160✔
1185
                                }
2,160✔
1186
                                return true;
2,160✔
1187
                        case 41:
1188
                                if (last is not null)
2,160✔
1189
                                {
2,160✔
1190
                                        last.EndWidth = this._reader.ValueAsDouble;
2,160✔
1191
                                }
2,160✔
1192
                                return true;
2,160✔
1193
                        case 42:
1194
                                if (last is not null)
2,952✔
1195
                                {
2,952✔
1196
                                        last.Bulge = this._reader.ValueAsDouble;
2,952✔
1197
                                }
2,952✔
1198
                                return true;
2,952✔
1199
                        case 50:
1200
                                if (last is not null)
×
1201
                                {
×
1202
                                        last.CurveTangent = this._reader.ValueAsDouble;
×
1203
                                }
×
1204
                                return true;
×
1205
                        //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1206
                        case 66:
1207
                        //Vertex count
1208
                        case 90:
1209
                                return true;
4,975✔
1210
                        case 91:
1211
                                if (last is not null)
×
1212
                                {
×
1213
                                        last.Id = this._reader.ValueAsInt;
×
1214
                                }
×
1215
                                return true;
×
1216
                        default:
1217
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
36,357✔
1218
                }
1219
        }
92,700✔
1220

1221
        private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1222
        {
38,016✔
1223
                CadMeshTemplate tmp = template as CadMeshTemplate;
38,016✔
1224

1225
                switch (this._reader.Code)
38,016✔
1226
                {
1227
                        case 100:
1228
                                if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
864✔
1229
                                {
432✔
1230
                                        tmp.SubclassMarker = true;
432✔
1231
                                }
432✔
1232
                                return true;
864✔
1233
                        //Count of sub-entity which property has been overridden
1234
                        case 90:
1235
                                //TODO: process further entities
1236
                                return true;
432✔
1237
                        case 92:
1238
                                if (!tmp.SubclassMarker)
648✔
1239
                                {
216✔
1240
                                        return false;
216✔
1241
                                }
1242

1243
                                int nvertices = this._reader.ValueAsInt;
432✔
1244
                                for (int i = 0; i < nvertices; i++)
55,296✔
1245
                                {
27,216✔
1246
                                        this._reader.ReadNext();
27,216✔
1247
                                        double x = this._reader.ValueAsDouble;
27,216✔
1248
                                        this._reader.ReadNext();
27,216✔
1249
                                        double y = this._reader.ValueAsDouble;
27,216✔
1250
                                        this._reader.ReadNext();
27,216✔
1251
                                        double z = this._reader.ValueAsDouble;
27,216✔
1252
                                        tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
27,216✔
1253
                                }
27,216✔
1254
                                return true;
432✔
1255
                        case 93:
1256
                                int size = this._reader.ValueAsInt;
432✔
1257
                                this._reader.ReadNext();
432✔
1258

1259
                                int indexes = 0;
432✔
1260
                                for (int i = 0; i < size; i += indexes + 1)
59,616✔
1261
                                {
29,376✔
1262
                                        indexes = this._reader.ValueAsInt;
29,376✔
1263
                                        this._reader.ReadNext();
29,376✔
1264

1265
                                        int[] face = new int[indexes];
29,376✔
1266
                                        for (int j = 0; j < indexes; j++)
283,392✔
1267
                                        {
112,320✔
1268
                                                face[j] = this._reader.ValueAsInt;
112,320✔
1269

1270
                                                if ((i + j + 2) < size)
112,320✔
1271
                                                {
111,888✔
1272
                                                        this._reader.ReadNext();
111,888✔
1273
                                                }
111,888✔
1274
                                        }
112,320✔
1275

1276
                                        tmp.CadObject.Faces.Add(face);
29,376✔
1277
                                }
29,376✔
1278

1279
                                return true;
432✔
1280
                        case 94:
1281
                                int numEdges = this._reader.ValueAsInt;
432✔
1282
                                this._reader.ReadNext();
432✔
1283
                                for (int i = 0; i < numEdges; i++)
113,184✔
1284
                                {
56,160✔
1285
                                        Mesh.Edge edge = new Mesh.Edge();
56,160✔
1286

1287
                                        edge.Start = this._reader.ValueAsInt;
56,160✔
1288
                                        this._reader.ReadNext();
56,160✔
1289
                                        edge.End = this._reader.ValueAsInt;
56,160✔
1290

1291
                                        if (i < numEdges - 1)
56,160✔
1292
                                        {
55,728✔
1293
                                                this._reader.ReadNext();
55,728✔
1294
                                        }
55,728✔
1295

1296
                                        tmp.CadObject.Edges.Add(edge);
56,160✔
1297
                                }
56,160✔
1298

1299
                                return true;
432✔
1300
                        case 95:
1301
                                this._reader.ReadNext();
432✔
1302
                                for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
113,184✔
1303
                                {
56,160✔
1304
                                        Mesh.Edge edge = tmp.CadObject.Edges[i];
56,160✔
1305
                                        edge.Crease = this._reader.ValueAsDouble;
56,160✔
1306

1307
                                        tmp.CadObject.Edges[i] = edge;
56,160✔
1308

1309
                                        if (i < tmp.CadObject.Edges.Count - 1)
56,160✔
1310
                                        {
55,728✔
1311
                                                this._reader.ReadNext();
55,728✔
1312
                                        }
55,728✔
1313
                                }
56,160✔
1314

1315
                                return true;
432✔
1316
                        default:
1317
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,776✔
1318
                }
1319
        }
38,016✔
1320

1321
        private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1322
        {
56,160✔
1323
                CadMLineTemplate tmp = template as CadMLineTemplate;
56,160✔
1324

1325
                switch (this._reader.Code)
56,160✔
1326
                {
1327
                        // 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.
1328
                        // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1329
                        case 2:
1330
                                tmp.MLineStyleName = this._reader.ValueAsString;
648✔
1331
                                return true;
648✔
1332
                        case 72:
1333
                                tmp.NVertex = this._reader.ValueAsInt;
648✔
1334
                                return true;
648✔
1335
                        case 73:
1336
                                tmp.NElements = this._reader.ValueAsInt;
648✔
1337
                                return true;
648✔
1338
                        case 340:
1339
                                tmp.MLineStyleHandle = this._reader.ValueAsHandle;
648✔
1340
                                return true;
648✔
1341
                        default:
1342
                                if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
53,568✔
1343
                                {
9,072✔
1344
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
9,072✔
1345
                                }
1346
                                return true;
44,496✔
1347
                }
1348
        }
56,160✔
1349

1350
        private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1351
        {
152,496✔
1352
                CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
152,496✔
1353

1354
                switch (this._reader.Code)
152,496✔
1355
                {
1356
                        case 270:
1357
                                //f270 Version
1358
                                return true;
1,620✔
1359
                        case 300:
1360
                                this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,240✔
1361
                                return true;
3,240✔
1362
                        case 340:
1363
                                tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,240✔
1364
                                return true;
3,240✔
1365
                        case 341:
1366
                                tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,240✔
1367
                                return true;
3,240✔
1368
                        case 343:
1369
                                tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,240✔
1370
                                return true;
3,240✔
1371
                        default:
1372
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
137,916✔
1373
                }
1374
        }
152,496✔
1375

1376
        private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1377
        {
3,240✔
1378
                this._reader.ReadNext();
3,240✔
1379

1380
                var map = DxfClassMap.Create<MultiLeaderObjectContextData>();
3,240✔
1381
                var contextData = template.CadObject as MultiLeaderObjectContextData;
3,240✔
1382

1383
                bool end = false;
3,240✔
1384
                while (this._reader.DxfCode != DxfCode.Start)
181,440✔
1385
                {
181,440✔
1386
                        switch (this._reader.Code)
181,440✔
1387
                        {
1388
                                case 301 when this._reader.ValueAsString.Equals("}"):
3,240✔
1389
                                        end = true;
3,240✔
1390
                                        break;
3,240✔
1391
                                case 302 when this._reader.ValueAsString.Equals("LEADER{"):
3,240✔
1392
                                        contextData.LeaderRoots.Add(this.readMultiLeaderLeader(template));
3,240✔
1393
                                        break;
3,240✔
1394
                                case 340:
1395
                                        template.TextStyleHandle = this._reader.ValueAsHandle;
3,240✔
1396
                                        break;
3,240✔
1397
                                default:
1398
                                        if (!this.tryAssignCurrentValue(contextData, map))
171,720!
1399
                                        {
×
1400
                                                this._builder.Notify($"[AcDbMLeaderObjectContextData] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1401
                                        }
×
1402
                                        break;
171,720✔
1403
                        }
1404

1405
                        if (end)
181,440✔
1406
                        {
3,240✔
1407
                                break;
3,240✔
1408
                        }
1409

1410
                        this._reader.ReadNext();
178,200✔
1411
                }
178,200✔
1412
        }
3,240✔
1413

1414
        private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1415
        {
3,240✔
1416
                MultiLeaderObjectContextData.LeaderRoot root = new();
3,240✔
1417
                var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,240✔
1418

1419
                this._reader.ReadNext();
3,240✔
1420

1421
                bool end = false;
3,240✔
1422
                while (this._reader.DxfCode != DxfCode.Start)
40,500✔
1423
                {
40,500✔
1424
                        switch (this._reader.Code)
40,500✔
1425
                        {
1426
                                case 303 when this._reader.ValueAsString.Equals("}"):
3,240✔
1427
                                        end = true;
3,240✔
1428
                                        break;
3,240✔
1429
                                case 304 when this._reader.ValueAsString.Equals("LEADER_LINE{"):
3,240✔
1430
                                        var lineTemplate = new LeaderLineTemplate();
3,240✔
1431
                                        template.LeaderLineTemplates.Add(lineTemplate);
3,240✔
1432
                                        root.Lines.Add(this.readMultiLeaderLine(lineTemplate));
3,240✔
1433
                                        break;
3,240✔
1434
                                default:
1435
                                        if (!this.tryAssignCurrentValue(root, map))
34,020!
1436
                                        {
×
1437
                                                this._builder.Notify($"[LeaderRoot] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1438
                                        }
×
1439
                                        break;
34,020✔
1440
                        }
1441

1442
                        if (end)
40,500✔
1443
                        {
3,240✔
1444
                                break;
3,240✔
1445
                        }
1446

1447
                        this._reader.ReadNext();
37,260✔
1448
                }
37,260✔
1449

1450
                return root;
3,240✔
1451
        }
3,240✔
1452

1453
        private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1454
        {
3,240✔
1455
                MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,240✔
1456
                var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,240✔
1457

1458
                this._reader.ReadNext();
3,240✔
1459

1460
                bool end = false;
3,240✔
1461
                while (this._reader.DxfCode != DxfCode.Start)
16,200✔
1462
                {
16,200✔
1463
                        switch (this._reader.Code)
16,200✔
1464
                        {
1465
                                case 10:
1466
                                        XYZ pt = new XYZ(this._reader.ValueAsDouble, 0, 0);
3,240✔
1467
                                        line.Points.Add(pt);
3,240✔
1468
                                        break;
3,240✔
1469
                                case 20:
1470
                                        pt = line.Points[line.Points.Count - 1];
3,240✔
1471
                                        pt.Y = this._reader.ValueAsDouble;
3,240✔
1472
                                        line.Points[line.Points.Count - 1] = pt;
3,240✔
1473
                                        break;
3,240✔
1474
                                case 30:
1475
                                        pt = line.Points[line.Points.Count - 1];
3,240✔
1476
                                        pt.Z = this._reader.ValueAsDouble;
3,240✔
1477
                                        line.Points[line.Points.Count - 1] = pt;
3,240✔
1478
                                        break;
3,240✔
1479
                                case 305 when this._reader.ValueAsString.Equals("}"):
3,240✔
1480
                                        end = true;
3,240✔
1481
                                        break;
3,240✔
1482
                                default:
1483
                                        if (!this.tryAssignCurrentValue(line, map))
3,240!
1484
                                        {
×
1485
                                                this._builder.Notify($"[LeaderLine] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1486
                                        }
×
1487
                                        break;
3,240✔
1488
                        }
1489

1490
                        if (end)
16,200✔
1491
                        {
3,240✔
1492
                                break;
3,240✔
1493
                        }
1494

1495
                        this._reader.ReadNext();
12,960✔
1496
                }
12,960✔
1497

1498
                return line;
3,240✔
1499
        }
3,240✔
1500

1501
        private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1502
        {
2,412✔
1503
                CadShapeTemplate tmp = template as CadShapeTemplate;
2,412✔
1504

1505
                switch (this._reader.Code)
2,412✔
1506
                {
1507
                        case 2:
1508
                                tmp.ShapeFileName = this._reader.ValueAsString;
252✔
1509
                                return true;
252✔
1510
                        default:
1511
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,160✔
1512
                }
1513
        }
2,412✔
1514

1515
        private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1516
        {
12,744✔
1517
                CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,744✔
1518
                CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,744✔
1519

1520
                switch (this._reader.Code)
12,744✔
1521
                {
1522
                        case 91:
1523
                                var nvertices = this._reader.ValueAsInt;
432✔
1524
                                for (int i = 0; i < nvertices; i++)
3,888✔
1525
                                {
1,512✔
1526
                                        this._reader.ReadNext();
1,512✔
1527
                                        var x = this._reader.ValueAsDouble;
1,512✔
1528
                                        this._reader.ReadNext();
1,512✔
1529
                                        var y = this._reader.ValueAsDouble;
1,512✔
1530

1531
                                        wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,512✔
1532
                                }
1,512✔
1533

1534
                                this._reader.ReadNext();
432✔
1535

1536
                                return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
432✔
1537
                        case 340:
1538
                                tmp.ImgDefHandle = this._reader.ValueAsHandle;
432✔
1539
                                return true;
432✔
1540
                        case 360:
1541
                                tmp.ImgReactorHandle = this._reader.ValueAsHandle;
432✔
1542
                                return true;
432✔
1543
                        default:
1544
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
11,448✔
1545
                }
1546
        }
12,744✔
1547

1548
        private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1549
        {
×
1550
                CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1551

1552
                switch (this._reader.Code)
×
1553
                {
1554
                        //End of data
1555
                        case 1:
1556
                        //Length of binary data
1557
                        case 90:
1558
                        //Undocumented
1559
                        case 73:
1560
                                return true;
×
1561
                        case 310:
1562
                                tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
1563
                                return true;
×
1564
                        default:
1565
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1566
                }
1567
        }
×
1568

1569
        private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1570
        {
306,674✔
1571
                CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
306,674✔
1572
                string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
306,674✔
1573
                var geometry = template.CadObject as ModelerGeometry;
306,674✔
1574

1575
                switch (this._reader.Code)
306,674✔
1576
                {
1577
                        case 1:
1578
                                //New SAT line: decoded into the template accumulator, raw into
1579
                                //ProprietaryData to preserve the previous behavior.
1580
                                (template as IAcisDataTemplate)?.AppendAcisLine(this._reader.ValueAsString);
39,928!
1581
                                geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
39,928✔
1582
                                return true;
39,928✔
1583
                        case 3:
1584
                                //Continuation of the previous SAT line.
1585
                                (template as IAcisDataTemplate)?.AppendAcisContinuation(this._reader.ValueAsString);
1!
1586
                                geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
1✔
1587
                                return true;
1✔
1588
                        case 2:
1589
                                geometry.Guid = new Guid(this._reader.ValueAsString);
216✔
1590
                                return true;
216✔
1591
                        case 290:
1592
                                return true;
216✔
1593
                        default:
1594
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
266,313✔
1595
                }
1596
        }
306,674✔
1597

1598
        private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1599
        {
36,936✔
1600
                CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
36,936✔
1601

1602
                switch (this._reader.Code)
36,936✔
1603
                {
1604
                        case 350:
1605
                                tmp.HistoryHandle = this._reader.ValueAsHandle;
288✔
1606
                                return true;
288✔
1607
                        default:
1608
                                return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
36,648✔
1609
                }
1610
        }
36,936✔
1611

1612
        private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1613
        {
15,120✔
1614
                CadSplineTemplate tmp = template as CadSplineTemplate;
15,120✔
1615

1616
                XYZ controlPoint;
1617
                XYZ fitPoint;
1618

1619
                switch (this._reader.Code)
15,120!
1620
                {
1621
                        case 10:
1622
                                controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,728✔
1623
                                tmp.CadObject.ControlPoints.Add(controlPoint);
1,728✔
1624
                                return true;
1,728✔
1625
                        case 20:
1626
                                controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,728✔
1627
                                controlPoint.Y = this._reader.ValueAsDouble;
1,728✔
1628
                                tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,728✔
1629
                                return true;
1,728✔
1630
                        case 30:
1631
                                controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,728✔
1632
                                controlPoint.Z = this._reader.ValueAsDouble;
1,728✔
1633
                                tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,728✔
1634
                                return true;
1,728✔
1635
                        case 11:
1636
                                fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1637
                                tmp.CadObject.FitPoints.Add(fitPoint);
×
1638
                                return true;
×
1639
                        case 21:
1640
                                fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1641
                                fitPoint.Y = this._reader.ValueAsDouble;
×
1642
                                tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1643
                                return true;
×
1644
                        case 31:
1645
                                fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1646
                                fitPoint.Z = this._reader.ValueAsDouble;
×
1647
                                tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1648
                                return true;
×
1649
                        case 40:
1650
                                tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,456✔
1651
                                return true;
3,456✔
1652
                        case 41:
1653
                                tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1654
                                return true;
×
1655
                        case 72:
1656
                        case 73:
1657
                        case 74:
1658
                                return true;
1,296✔
1659
                        default:
1660
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
5,184✔
1661
                }
1662
        }
15,120✔
1663

1664
        private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1665
                where T : PdfUnderlayDefinition
1666
        {
3,420✔
1667
                CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,420✔
1668

1669
                switch (this._reader.Code)
3,420✔
1670
                {
1671
                        case 340:
1672
                                tmp.DefinitionHandle = this._reader.ValueAsHandle;
216✔
1673
                                return true;
216✔
1674
                        default:
1675
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,204✔
1676
                }
1677
        }
3,420✔
1678

1679
        private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1680
        {
252,690✔
1681
                CadVertexTemplate tmp = template as CadVertexTemplate;
252,690✔
1682

1683
                switch (this._reader.Code)
252,690✔
1684
                {
1685
                        case 100:
1686
                                switch (this._reader.ValueAsString)
7,344!
1687
                                {
1688
                                        case DxfSubclassMarker.Vertex:
1689
                                                return true;
2,160✔
1690
                                        case DxfSubclassMarker.PolylineVertex:
1691
                                                tmp.SetVertexObject(new Vertex2D());
×
1692
                                                map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1693
                                                return true;
×
1694
                                        case DxfSubclassMarker.Polyline3dVertex:
1695
                                                tmp.SetVertexObject(new Vertex3D());
1,080✔
1696
                                                map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,080✔
1697
                                                return true;
1,080✔
1698
                                        case DxfSubclassMarker.PolyfaceMeshVertex:
1699
                                                tmp.SetVertexObject(new VertexFaceMesh());
1,080✔
1700
                                                map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,080✔
1701
                                                return true;
1,080✔
1702
                                        case DxfSubclassMarker.PolyfaceMeshFace:
1703
                                                tmp.SetVertexObject(new VertexFaceRecord());
432✔
1704
                                                map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
432✔
1705
                                                return true;
432✔
1706
                                        case DxfSubclassMarker.PolygonMeshVertex:
1707
                                                tmp.SetVertexObject(new PolygonMeshVertex());
×
1708
                                                map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1709
                                                return true;
×
1710
                                        default:
1711
                                                return false;
2,592✔
1712
                                }
1713
                        default:
1714
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
245,346✔
1715
                }
1716
        }
252,690✔
1717

1718
        private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1719
        {
72,724✔
1720
                CadViewportTemplate tmp = template as CadViewportTemplate;
72,724✔
1721

1722
                switch (this._reader.Code)
72,724!
1723
                {
1724
                        //Undocumented
1725
                        case 67:
1726
                        case 68:
1727
                                return true;
2,664✔
1728
                        case 69:
1729
                                tmp.ViewportId = this._reader.ValueAsShort;
1,332✔
1730
                                return true;
1,332✔
1731
                        case 331:
1732
                                tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1733
                                return true;
×
1734
                        case 348:
1735
                                tmp.VisualStyleHandle = this._reader.ValueAsHandle;
832✔
1736
                                return true;
832✔
1737
                        default:
1738
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
67,896✔
1739
                }
1740
        }
72,724✔
1741

1742
        private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1743
        {
855,836✔
1744
                string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
855,836✔
1745

1746
                switch (this._reader.Code)
855,836✔
1747
                {
1748
                        default:
1749
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
855,836✔
1750
                }
1751
        }
855,836✔
1752

1753
        protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1754
        {
36,478✔
1755
                List<ExtendedDataRecord> records = new();
36,478✔
1756
                edata.Add(this._reader.ValueAsString, records);
36,478✔
1757

1758
                this._reader.ReadNext();
36,478✔
1759

1760
                while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
296,896✔
1761
                {
271,933✔
1762
                        if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
271,933✔
1763
                        {
11,515✔
1764
                                this.readExtendedData(edata);
11,515✔
1765
                                break;
11,515✔
1766
                        }
1767

1768
                        ExtendedDataRecord record = null;
260,418✔
1769
                        double x = 0;
260,418✔
1770
                        double y = 0;
260,418✔
1771
                        double z = 0;
260,418✔
1772

1773
                        switch (this._reader.DxfCode)
260,418✔
1774
                        {
1775
                                case DxfCode.ExtendedDataAsciiString:
1776
                                case DxfCode.ExtendedDataRegAppName:
1777
                                        record = new ExtendedDataString(this._reader.ValueAsString);
24,929✔
1778
                                        break;
24,929✔
1779
                                case DxfCode.ExtendedDataControlString:
1780
                                        record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
14,284✔
1781
                                        break;
14,284✔
1782
                                case DxfCode.ExtendedDataLayerName:
1783
                                        if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
252✔
1784
                                        {
238✔
1785
                                                record = new ExtendedDataLayer(layer.Handle);
238✔
1786
                                        }
238✔
1787
                                        else
1788
                                        {
14✔
1789
                                                this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1790
                                        }
14✔
1791
                                        break;
252✔
1792
                                case DxfCode.ExtendedDataBinaryChunk:
1793
                                        record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
72✔
1794
                                        break;
72✔
1795
                                case DxfCode.ExtendedDataHandle:
1796
                                        record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,781✔
1797
                                        break;
2,781✔
1798
                                case DxfCode.ExtendedDataXCoordinate:
1799
                                        x = this._reader.ValueAsDouble;
2,873✔
1800
                                        this._reader.ReadNext();
2,873✔
1801
                                        y = this._reader.ValueAsDouble;
2,873✔
1802
                                        this._reader.ReadNext();
2,873✔
1803
                                        z = this._reader.ValueAsDouble;
2,873✔
1804

1805
                                        record = new ExtendedDataCoordinate(
2,873✔
1806
                                                new XYZ(
2,873✔
1807
                                                        x,
2,873✔
1808
                                                        y,
2,873✔
1809
                                                        z)
2,873✔
1810
                                                );
2,873✔
1811
                                        break;
2,873✔
1812
                                case DxfCode.ExtendedDataWorldXCoordinate:
1813
                                        x = this._reader.ValueAsDouble;
1,296✔
1814
                                        this._reader.ReadNext();
1,296✔
1815
                                        y = this._reader.ValueAsDouble;
1,296✔
1816
                                        this._reader.ReadNext();
1,296✔
1817
                                        z = this._reader.ValueAsDouble;
1,296✔
1818

1819
                                        record = new ExtendedDataWorldCoordinate(
1,296✔
1820
                                                new XYZ(
1,296✔
1821
                                                        x,
1,296✔
1822
                                                        y,
1,296✔
1823
                                                        z)
1,296✔
1824
                                                );
1,296✔
1825
                                        break;
1,296✔
1826
                                case DxfCode.ExtendedDataWorldXDisp:
1827
                                        x = this._reader.ValueAsDouble;
252✔
1828
                                        this._reader.ReadNext();
252✔
1829
                                        y = this._reader.ValueAsDouble;
252✔
1830
                                        this._reader.ReadNext();
252✔
1831
                                        z = this._reader.ValueAsDouble;
252✔
1832

1833
                                        record = new ExtendedDataDisplacement(
252✔
1834
                                                new XYZ(
252✔
1835
                                                        x,
252✔
1836
                                                        y,
252✔
1837
                                                        z)
252✔
1838
                                                );
252✔
1839
                                        break;
252✔
1840
                                case DxfCode.ExtendedDataWorldXDir:
1841
                                        x = this._reader.ValueAsDouble;
252✔
1842
                                        this._reader.ReadNext();
252✔
1843
                                        y = this._reader.ValueAsDouble;
252✔
1844
                                        this._reader.ReadNext();
252✔
1845
                                        z = this._reader.ValueAsDouble;
252✔
1846

1847
                                        record = new ExtendedDataDirection(
252✔
1848
                                                new XYZ(
252✔
1849
                                                        x,
252✔
1850
                                                        y,
252✔
1851
                                                        z)
252✔
1852
                                                );
252✔
1853
                                        break;
252✔
1854
                                case DxfCode.ExtendedDataReal:
1855
                                        record = new ExtendedDataReal(this._reader.ValueAsDouble);
126,481✔
1856
                                        break;
126,481✔
1857
                                case DxfCode.ExtendedDataDist:
1858
                                        record = new ExtendedDataDistance(this._reader.ValueAsDouble);
252✔
1859
                                        break;
252✔
1860
                                case DxfCode.ExtendedDataScale:
1861
                                        record = new ExtendedDataScale(this._reader.ValueAsDouble);
252✔
1862
                                        break;
252✔
1863
                                case DxfCode.ExtendedDataInteger16:
1864
                                        record = new ExtendedDataInteger16(this._reader.ValueAsShort);
73,945✔
1865
                                        break;
73,945✔
1866
                                case DxfCode.ExtendedDataInteger32:
1867
                                        record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
10,193✔
1868
                                        break;
10,193✔
1869
                                default:
1870
                                        this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,304✔
1871
                                        break;
2,304✔
1872
                        }
1873

1874
                        if (record != null)
260,418✔
1875
                        {
258,100✔
1876
                                records.Add(record);
258,100✔
1877
                        }
258,100✔
1878

1879
                        this._reader.ReadNext();
260,418✔
1880
                }
260,418✔
1881
        }
36,478✔
1882

1883
        private void readPattern(HatchPattern pattern, int nlines)
1884
        {
1,296✔
1885
                //Jump 78 code
1886
                this._reader.ReadNext();
1,296✔
1887

1888
                for (int i = 0; i < nlines; i++)
196,560✔
1889
                {
96,984✔
1890
                        HatchPattern.Line line = new HatchPattern.Line();
96,984✔
1891
                        XY basePoint = new XY();
96,984✔
1892
                        XY offset = new XY();
96,984✔
1893

1894
                        bool end = false;
96,984✔
1895
                        HashSet<int> codes = new();
96,984✔
1896

1897
                        while (!end)
680,184✔
1898
                        {
678,888✔
1899
                                if (codes.Contains(this._reader.Code))
678,888✔
1900
                                {
95,688✔
1901
                                        break;
95,688✔
1902
                                }
1903
                                else
1904
                                {
583,200✔
1905
                                        codes.Add(this._reader.Code);
583,200✔
1906
                                }
583,200✔
1907

1908
                                switch (this._reader.Code)
583,200!
1909
                                {
1910
                                        case 53:
1911
                                                line.Angle = this._reader.ValueAsAngle;
96,984✔
1912
                                                break;
96,984✔
1913
                                        case 43:
1914
                                                basePoint.X = this._reader.ValueAsDouble;
96,984✔
1915
                                                break;
96,984✔
1916
                                        case 44:
1917
                                                basePoint.Y = this._reader.ValueAsDouble;
96,984✔
1918
                                                line.BasePoint = basePoint;
96,984✔
1919
                                                break;
96,984✔
1920
                                        case 45:
1921
                                                offset.X = this._reader.ValueAsDouble;
96,984✔
1922
                                                line.Offset = offset;
96,984✔
1923
                                                break;
96,984✔
1924
                                        case 46:
1925
                                                offset.Y = this._reader.ValueAsDouble;
96,984✔
1926
                                                line.Offset = offset;
96,984✔
1927
                                                break;
96,984✔
1928
                                        //Number of dash length items
1929
                                        case 79:
1930
                                                int ndash = this._reader.ValueAsInt;
96,984✔
1931
                                                for (int j = 0; j < ndash; j++)
581,040✔
1932
                                                {
193,536✔
1933
                                                        this._reader.ReadNext();
193,536✔
1934
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
193,536✔
1935
                                                }
193,536✔
1936
                                                break;
96,984✔
1937
                                        case 49:
1938
                                                line.DashLengths.Add(this._reader.ValueAsDouble);
×
1939
                                                break;
×
1940
                                        default:
1941
                                                end = true;
1,296✔
1942
                                                break;
1,296✔
1943
                                }
1944
                                this._reader.ReadNext();
583,200✔
1945
                        }
583,200✔
1946

1947
                        pattern.Lines.Add(line);
96,984✔
1948
                }
96,984✔
1949
        }
1,296✔
1950

1951
        private void readLoops(CadHatchTemplate template, int count)
1952
        {
1,728✔
1953
                if (this._reader.Code == 91)
1,728✔
1954
                        this._reader.ReadNext();
1,728✔
1955

1956
                for (int i = 0; i < count; i++)
6,912✔
1957
                {
1,728✔
1958
                        if (this._reader.Code != 92)
1,728!
1959
                        {
×
1960
                                this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1961
                                break;
×
1962
                        }
1963

1964
                        CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,728✔
1965
                        if (path != null)
1,728✔
1966
                                template.PathTemplates.Add(path);
1,728✔
1967
                }
1,728✔
1968
        }
1,728✔
1969

1970
        private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1971
        {
1,728✔
1972
                CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,728✔
1973
                var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,728✔
1974
                template.Path.Flags = flags;
1,728✔
1975

1976
                if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,728✔
1977
                {
648✔
1978
                        Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
648✔
1979
                        template.Path.Edges.Add(pl);
648✔
1980
                }
648✔
1981
                else
1982
                {
1,080✔
1983
                        this._reader.ReadNext();
1,080✔
1984

1985
                        if (this._reader.Code != 93)
1,080!
1986
                        {
×
1987
                                this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1988
                                return null;
×
1989
                        }
1990

1991
                        int edges = this._reader.ValueAsInt;
1,080✔
1992
                        this._reader.ReadNext();
1,080✔
1993

1994
                        for (int i = 0; i < edges; i++)
10,800✔
1995
                        {
4,320✔
1996
                                var edge = this.readEdge();
4,320✔
1997
                                if (edge != null)
4,320✔
1998
                                        template.Path.Edges.Add(edge);
4,320✔
1999
                        }
4,320✔
2000
                }
1,080✔
2001

2002
                bool end = false;
1,728✔
2003
                while (!end)
6,696✔
2004
                {
4,968✔
2005
                        switch (this._reader.Code)
4,968✔
2006
                        {
2007
                                //Number of source boundary objects
2008
                                case 97:
2009
                                        break;
1,728✔
2010
                                case 330:
2011
                                        template.Handles.Add(this._reader.ValueAsHandle);
1,512✔
2012
                                        break;
1,512✔
2013
                                default:
2014
                                        end = true;
1,728✔
2015
                                        continue;
1,728✔
2016
                        }
2017

2018
                        this._reader.ReadNext();
3,240✔
2019
                }
3,240✔
2020

2021
                return template;
1,728✔
2022
        }
1,728✔
2023

2024
        private Hatch.BoundaryPath.Polyline readPolylineBoundary()
2025
        {
648✔
2026
                Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
648✔
2027

2028
                this._reader.ReadNext();
648✔
2029

2030
                if (this._reader.Code != 72)
648!
2031
                {
×
2032
                        this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
2033
                        return null;
×
2034
                }
2035

2036
                bool end = false;
648✔
2037
                bool hasBulge = false;
648✔
2038
                while (!end)
3,240✔
2039
                {
2,592✔
2040
                        switch (this._reader.Code)
2,592✔
2041
                        {
2042
                                case 72:
2043
                                        hasBulge = this._reader.ValueAsBool;
648✔
2044
                                        break;
648✔
2045
                                case 73:
2046
                                        boundary.IsClosed = this._reader.ValueAsBool;
648✔
2047
                                        break;
648✔
2048
                                case 93:
2049
                                        int nvertices = this._reader.ValueAsInt;
648✔
2050
                                        this._reader.ReadNext();
648✔
2051

2052
                                        for (int i = 0; i < nvertices; i++)
6,480✔
2053
                                        {
2,592✔
2054
                                                double bulge = 0.0;
2,592✔
2055

2056
                                                //10
2057
                                                double x = this._reader.ValueAsDouble;
2,592✔
2058
                                                this._reader.ReadNext();
2,592✔
2059
                                                //20
2060
                                                double y = this._reader.ValueAsDouble;
2,592✔
2061
                                                this._reader.ReadNext();
2,592✔
2062

2063
                                                if (hasBulge)
2,592!
2064
                                                {
×
2065
                                                        //42
2066
                                                        bulge = this._reader.ValueAsDouble;
×
2067
                                                        this._reader.ReadNext();
×
2068
                                                }
×
2069

2070
                                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,592✔
2071
                                        }
2,592✔
2072
                                        continue;
648✔
2073
                                default:
2074
                                        end = true;
648✔
2075
                                        continue;
648✔
2076
                        }
2077

2078
                        this._reader.ReadNext();
1,296✔
2079
                }
1,296✔
2080

2081
                return boundary;
648✔
2082
        }
648✔
2083

2084
        private Hatch.BoundaryPath.Edge readEdge()
2085
        {
4,320✔
2086
                if (this._reader.Code != 72)
4,320!
2087
                {
×
2088
                        this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
2089
                        return null;
×
2090
                }
2091

2092
                Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,320✔
2093
                this._reader.ReadNext();
4,320✔
2094

2095
                switch (type)
4,320!
2096
                {
2097
                        case Hatch.BoundaryPath.EdgeType.Line:
2098
                                Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,320✔
2099
                                while (true)
21,600✔
2100
                                {
21,600✔
2101
                                        switch (this._reader.Code)
21,600✔
2102
                                        {
2103
                                                case 10:
2104
                                                        line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,320✔
2105
                                                        break;
4,320✔
2106
                                                case 20:
2107
                                                        line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,320✔
2108
                                                        break;
4,320✔
2109
                                                case 11:
2110
                                                        line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,320✔
2111
                                                        break;
4,320✔
2112
                                                case 21:
2113
                                                        line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,320✔
2114
                                                        break;
4,320✔
2115
                                                default:
2116
                                                        return line;
4,320✔
2117
                                        }
2118

2119
                                        this._reader.ReadNext();
17,280✔
2120
                                }
17,280✔
2121
                        case Hatch.BoundaryPath.EdgeType.CircularArc:
2122
                                Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
2123
                                while (true)
×
2124
                                {
×
2125
                                        switch (this._reader.Code)
×
2126
                                        {
2127
                                                case 10:
2128
                                                        arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
2129
                                                        break;
×
2130
                                                case 20:
2131
                                                        arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
2132
                                                        break;
×
2133
                                                case 40:
2134
                                                        arc.Radius = this._reader.ValueAsDouble;
×
2135
                                                        break;
×
2136
                                                case 50:
2137
                                                        arc.StartAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2138
                                                        break;
×
2139
                                                case 51:
2140
                                                        arc.EndAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2141
                                                        break;
×
2142
                                                case 73:
2143
                                                        arc.CounterClockWise = this._reader.ValueAsBool;
×
2144
                                                        break;
×
2145
                                                default:
2146
                                                        return arc;
×
2147
                                        }
2148

2149
                                        this._reader.ReadNext();
×
2150
                                }
×
2151
                        case Hatch.BoundaryPath.EdgeType.EllipticArc:
2152
                                Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
2153
                                while (true)
×
2154
                                {
×
2155
                                        switch (this._reader.Code)
×
2156
                                        {
2157
                                                case 10:
2158
                                                        ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2159
                                                        break;
×
2160
                                                case 20:
2161
                                                        ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2162
                                                        break;
×
2163
                                                case 11:
2164
                                                        ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.MajorAxisEndPoint.Y);
×
2165
                                                        break;
×
2166
                                                case 21:
2167
                                                        ellipse.MajorAxisEndPoint = new XY(ellipse.MajorAxisEndPoint.X, this._reader.ValueAsDouble);
×
2168
                                                        break;
×
2169
                                                case 40:
2170
                                                        ellipse.RadiusRatio = this._reader.ValueAsDouble;
×
2171
                                                        break;
×
2172
                                                case 50:
2173
                                                        ellipse.StartAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2174
                                                        break;
×
2175
                                                case 51:
2176
                                                        ellipse.EndAngle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
2177
                                                        break;
×
2178
                                                case 73:
2179
                                                        ellipse.CounterClockWise = this._reader.ValueAsBool;
×
2180
                                                        break;
×
2181
                                                default:
2182
                                                        return ellipse;
×
2183
                                        }
2184

2185
                                        this._reader.ReadNext();
×
2186
                                }
×
2187
                        case Hatch.BoundaryPath.EdgeType.Spline:
2188
                                Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
2189
                                int nKnots = 0;
×
2190
                                int nCtrlPoints = 0;
×
2191
                                int nFitPoints = 0;
×
2192

2193
                                XYZ controlPoint = new XYZ();
×
2194
                                XY fitPoint = new XY();
×
2195

2196
                                while (true)
×
2197
                                {
×
2198
                                        switch (this._reader.Code)
×
2199
                                        {
2200
                                                case 10:
2201
                                                        controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
2202
                                                        break;
×
2203
                                                case 20:
2204
                                                        controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
2205
                                                        spline.ControlPoints.Add(controlPoint);
×
2206
                                                        break;
×
2207
                                                case 11:
2208
                                                        fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
2209
                                                        break;
×
2210
                                                case 21:
2211
                                                        fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
2212
                                                        spline.FitPoints.Add(fitPoint);
×
2213
                                                        break;
×
2214
                                                case 42:
2215
                                                        var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
2216
                                                        spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
2217
                                                        break;
×
2218
                                                case 12:
2219
                                                        spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
2220
                                                        break;
×
2221
                                                case 22:
2222
                                                        spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
2223
                                                        break;
×
2224
                                                case 13:
2225
                                                        spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
2226
                                                        break;
×
2227
                                                case 23:
2228
                                                        spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
2229
                                                        break;
×
2230
                                                case 94:
2231
                                                        spline.Degree = this._reader.ValueAsInt;
×
2232
                                                        break;
×
2233
                                                case 73:
2234
                                                        spline.IsRational = this._reader.ValueAsBool;
×
2235
                                                        break;
×
2236
                                                case 74:
2237
                                                        spline.IsPeriodic = this._reader.ValueAsBool;
×
2238
                                                        break;
×
2239
                                                case 95:
2240
                                                        nKnots = this._reader.ValueAsInt;
×
2241
                                                        break;
×
2242
                                                case 96:
2243
                                                        nCtrlPoints = this._reader.ValueAsInt;
×
2244
                                                        break;
×
2245
                                                case 97:
2246
                                                        nFitPoints = this._reader.ValueAsInt;
×
2247
                                                        break;
×
2248
                                                case 40:
2249
                                                        spline.Knots.Add(this._reader.ValueAsDouble);
×
2250
                                                        break;
×
2251
                                                default:
2252
                                                        return spline;
×
2253
                                        }
2254

2255
                                        this._reader.ReadNext();
×
2256
                                }
×
2257
                }
2258

2259
                return null;
×
2260
        }
4,320✔
2261

2262
        private void readDefinedGroups(CadTemplate template)
2263
        {
72,806✔
2264
                this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
72,806✔
2265

2266
                if (xdict.HasValue)
72,806✔
2267
                {
10,487✔
2268
                        template.XDictHandle = xdict;
10,487✔
2269
                }
10,487✔
2270
                template.ReactorsHandles.UnionWith(reactorsHandles);
72,806✔
2271
        }
72,806✔
2272

2273
        private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2274
        {
73,029✔
2275
                xdictHandle = null;
73,029✔
2276
                reactors = new HashSet<ulong>();
73,029✔
2277

2278
                switch (this._reader.ValueAsString)
73,029✔
2279
                {
2280
                        case DxfFileToken.DictionaryToken:
2281
                                this._reader.ReadNext();
10,710✔
2282
                                xdictHandle = this._reader.ValueAsHandle;
10,710✔
2283
                                this._reader.ReadNext();
10,710✔
2284
                                Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,710✔
2285
                                return;
10,710✔
2286
                        case DxfFileToken.ReactorsToken:
2287
                                reactors = this.readReactors();
60,142✔
2288
                                break;
60,142✔
2289
                        case DxfFileToken.BlkRefToken:
2290
                        default:
2291
                                do
2292
                                {
5,650✔
2293
                                        this._reader.ReadNext();
5,650✔
2294
                                }
5,650✔
2295
                                while (this._reader.DxfCode != DxfCode.ControlString);
5,650✔
2296
                                return;
2,177✔
2297
                }
2298
        }
73,029✔
2299

2300
        private HashSet<ulong> readReactors()
2301
        {
60,142✔
2302
                HashSet<ulong> reactors = new();
60,142✔
2303

2304
                this._reader.ReadNext();
60,142✔
2305

2306
                while (this._reader.DxfCode != DxfCode.ControlString)
127,184✔
2307
                {
67,042✔
2308
                        reactors.Add(this._reader.ValueAsHandle);
67,042✔
2309

2310
                        this._reader.ReadNext();
67,042✔
2311
                }
67,042✔
2312

2313
                return reactors;
60,142✔
2314
        }
60,142✔
2315

2316
        protected bool tryAssignCurrentValue(object cadObject, DxfMap map)
2317
        {
60,603✔
2318
                if (string.IsNullOrEmpty(this.currentSubclass))
60,603✔
2319
                {
1,242✔
2320
                        return false;
1,242✔
2321
                }
2322

2323
                if (map.SubClasses.TryGetValue(this.currentSubclass, out var subClass))
59,361!
2324
                {
59,361✔
2325
                        return this.tryAssignCurrentValue(cadObject, subClass);
59,361✔
2326
                }
2327
                else
2328
                {
×
2329
                        return false;
×
2330
                }
2331
        }
60,603✔
2332

2333
        protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2334
        {
4,481,155✔
2335
                try
2336
                {
4,481,155✔
2337
                        //Use this method only if the value is not a link between objects
2338
                        if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,481,155✔
2339
                        {
2,352,211✔
2340
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,352,211✔
2341
                                {
13,738✔
2342
                                        return true;
13,738✔
2343
                                }
2344

2345
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,338,473✔
2346
                                        || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,338,473✔
2347
                                {
19,741✔
2348
                                        return false;
19,741✔
2349
                                }
2350

2351
                                object value = this._reader.Value;
2,318,732✔
2352

2353
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,318,732✔
2354
                                {
26,368✔
2355
                                        value = MathHelper.DegToRad((double)value);
26,368✔
2356
                                }
26,368✔
2357

2358
                                dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,318,732✔
2359

2360
                                return true;
2,318,732✔
2361
                        }
2362
                }
2,128,944✔
2363
                catch (Exception ex)
×
2364
                {
×
2365
                        if (!this._builder.Configuration.Failsafe)
×
2366
                        {
×
2367
                                throw ex;
×
2368
                        }
2369
                        else
2370
                        {
×
2371
                                this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2372
                        }
×
2373
                }
×
2374

2375
                return false;
2,128,944✔
2376
        }
4,481,155✔
2377
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc