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

DomCR / ACadSharp / 27678770105

17 Jun 2026 09:18AM UTC coverage: 77.197% (+0.1%) from 77.1%
27678770105

Pull #1085

github

web-flow
Merge 6ff541abd into 46a1e0346
Pull Request #1085: Add TableEntity DXF round-trip (cells, alignment, merges, flow direction)

8897 of 12516 branches covered (71.09%)

Branch coverage included in aggregate %.

221 of 244 new or added lines in 4 files covered. (90.57%)

31969 of 40421 relevant lines covered (79.09%)

155619.22 hits per line

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

80.44
/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,018✔
26
        protected string currentSubclass = null;
1,018✔
27

28
        public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
1,018✔
29
        {
1,018✔
30
                this._reader = reader;
1,018✔
31
                this._builder = builder;
1,018✔
32
        }
1,018✔
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,394✔
38
                name = null;
2,394✔
39
                handle = 0;
2,394✔
40
                ownerHandle = null;
2,394✔
41
                xdictHandle = null;
2,394✔
42
                reactors = new HashSet<ulong>();
2,394✔
43

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

48
                //Loop until the common data end
49
                while (this._reader.DxfCode != DxfCode.Start
9,510✔
50
                                && this._reader.DxfCode != DxfCode.Subclass)
9,510✔
51
                {
7,116✔
52
                        switch (this._reader.Code)
7,116!
53
                        {
54
                                //Table name
55
                                case 2:
56
                                        name = this._reader.ValueAsString;
2,394✔
57
                                        break;
2,394✔
58
                                //Handle
59
                                case 5:
60
                                case 105:
61
                                        handle = this._reader.ValueAsHandle;
2,106✔
62
                                        break;
2,106✔
63
                                //Start of application - defined group
64
                                case 102:
65
                                        this.readDefinedGroups(out xdictHandle, out reactors);
222✔
66
                                        break;
222✔
67
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
68
                                case 330:
69
                                        ownerHandle = this._reader.ValueAsHandle;
2,106✔
70
                                        break;
2,106✔
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,116✔
81
                }
7,116✔
82
        }
2,394✔
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
        {
837,563✔
118
                isExtendedData = false;
837,563✔
119

120
                switch (this._reader.Code)
837,563✔
121
                {
122
                        //Handle
123
                        case 5:
124
                                template.CadObject.Handle = this._reader.ValueAsHandle;
315,968✔
125
                                break;
315,968✔
126
                        //Check with mapper
127
                        case 100:
128
                                this.currentSubclass = this._reader.ValueAsString;
217,844✔
129
                                if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
217,844!
130
                                {
948✔
131
                                        this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
948✔
132
                                }
948✔
133
                                break;
217,844✔
134
                        //Start of application - defined group
135
                        case 102:
136
                                this.readDefinedGroups(template);
71,878✔
137
                                break;
71,878✔
138
                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
139
                        case 330:
140
                                template.OwnerHandle = this._reader.ValueAsHandle;
178,675✔
141
                                break;
178,675✔
142
                        case 1001:
143
                                isExtendedData = true;
24,741✔
144
                                this.readExtendedData(template.EDataTemplateByAppName);
24,741✔
145
                                break;
24,741✔
146
                        default:
147
                                this._builder.Notify($"[{this.currentSubclass}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
28,457✔
148
                                break;
28,457✔
149
                }
150
        }
837,563✔
151

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

249
                                this._reader.ReadNext();
×
250

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

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

264
                                return unknownEntityTemplate;
×
265
                }
266
        }
154,951✔
267

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

273
                DxfMap map = DxfMap.Create<T>();
206,745✔
274

275
                while (this._reader.DxfCode != DxfCode.Start)
2,799,516✔
276
                {
2,592,771✔
277
                        if (!readEntity(template, map))
2,592,771✔
278
                        {
905,273✔
279
                                this.readCommonEntityCodes(template, out bool isExtendedData, map);
905,273✔
280
                                if (isExtendedData)
905,273✔
281
                                        continue;
14,478✔
282
                        }
890,795✔
283

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

290
                        if (this._reader.DxfCode != DxfCode.Start)
2,575,125✔
291
                                this._reader.ReadNext();
2,574,623✔
292
                }
2,575,125✔
293

294
                return template;
206,745✔
295
        }
206,745✔
296

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

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

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

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

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

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

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

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

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

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

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

615
        protected CadValueTemplate readCadValue(CadValue value)
616
        {
9,848✔
617
                this._reader.ReadNext();
9,848✔
618

619
                CadValueTemplate template = new(value);
9,848✔
620
                var map = DxfClassMap.Create(value.GetType(), "CadValue");
9,848✔
621

622
                while (this._reader.Code != 304)
65,384✔
623
                {
55,536✔
624
                        switch (this._reader.Code)
55,536!
625
                        {
626
                                case 1:
627
                                        value.SetValue(this._reader.ValueAsString);
3,496✔
628
                                        break;
3,496✔
629
                                case 2:
630
                                        value.SetValue((value.Value as string) + this._reader.ValueAsString);
×
631
                                        break;
×
632
                                case 11:
633
                                        XYZ xyz = new XYZ();
280✔
634
                                        xyz.X = this._reader.ValueAsDouble;
280✔
635
                                        value.SetValue(xyz);
280✔
636
                                        break;
280✔
637
                                case 21:
638
                                        {
280✔
639
                                                IVector v = value.Value as IVector;
280✔
640
                                                v[1] = this._reader.ValueAsDouble;
280✔
641
                                                value.SetValue(v);
280✔
642
                                        }
280✔
643
                                        break;
280✔
644
                                case 31:
645
                                        {
280✔
646
                                                IVector v = value.Value as IVector;
280✔
647
                                                v = v.Convert<XYZ>();
280✔
648
                                                v[2] = this._reader.ValueAsDouble;
280✔
649
                                                value.SetValue(v);
280✔
650
                                        }
280✔
651
                                        break;
280✔
652
                                case 90:
653
                                        value.ValueType = (CadValueType)this._reader.ValueAsInt;
9,848✔
654
                                        break;
9,848✔
655
                                case 91:
656
                                        value.SetValue(this._reader.ValueAsInt);
280✔
657
                                        break;
280✔
658
                                case 93:
659
                                        value.Flags = this._reader.ValueAsInt;
9,848✔
660
                                        break;
9,848✔
661
                                case 140:
662
                                        value.SetValue(this._reader.ValueAsDouble);
1,120✔
663
                                        break;
1,120✔
664
                                case 330:
665
                                        template.ValueHandle = this._reader.ValueAsHandle;
×
666
                                        break;
×
667
                                default:
668
                                        if (!this.tryAssignCurrentValue(value, map))
30,104✔
669
                                        {
560✔
670
                                                this._builder.Notify($"Unhandled dxf code {this._reader.Code} value {this._reader.ValueAsString} at {nameof(readCadValue)} method.", NotificationType.None);
560✔
671
                                        }
560✔
672
                                        break;
30,104✔
673
                        }
674

675
                        this._reader.ReadNext();
55,536✔
676
                }
55,536✔
677

678
                return template;
9,848✔
679
        }
9,848✔
680

681
        private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
682
        {
306,634✔
683
                string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
306,634✔
684
                CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
306,634✔
685

686
                switch (this._reader.Code)
306,634✔
687
                {
688
                        case 1 or 3 when tmp.CadObject is MText mtext:
27,506✔
689
                                mtext.Value += this._reader.ValueAsString;
10,282✔
690
                                return true;
10,282✔
691
                        case 50 when tmp.CadObject is MText mtext://Read only for MText
510!
692
                                double angle = this._reader.ValueAsAngle;
×
693
                                mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
694
                                return true;
×
695
                        case 7:
696
                                tmp.StyleName = this._reader.ValueAsString;
3,024✔
697
                                return true;
3,024✔
698
                        case 101 when tmp.CadObject is MText mtext:
144✔
699
                                this.readColumnData(mtext);
144✔
700
                                this.lockPointer = true;
144✔
701
                                return true;
144✔
702
                        default:
703
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
293,184✔
704
                }
705
        }
306,634✔
706

707
        private void readColumnData(MText mtext)
708
        {
144✔
709
                this._reader.ReadNext();
144✔
710
                while (this._reader.DxfCode != DxfCode.Start)
2,736✔
711
                {
2,592✔
712
                        switch (this._reader.Code)
2,592!
713
                        {
714
                                //Element count?
715
                                case 70:
716
                                        break;
144✔
717
                                case 71:
718
                                        mtext.ColumnData.ColumnType = (ColumnType)this._reader.ValueAsShort;
144✔
719
                                        break;
144✔
720
                                case 72:
721
                                        mtext.ColumnData.ColumnCount = this._reader.ValueAsInt;
144✔
722
                                        break;
144✔
723
                                //X - axis dir 3BD 10
724
                                case 10:
725
                                case 20:
726
                                case 30:
727
                                //Insertion point 3BD 11
728
                                case 11:
729
                                case 21:
730
                                case 31:
731
                                //Rect width BD 40
732
                                case 40:
733
                                //Rect height BD 41
734
                                case 41:
735
                                //Extents width BD 42
736
                                case 42:
737
                                //Extents height BD 43
738
                                case 43:
739
                                        break;
1,440✔
740
                                case 44:
741
                                        mtext.ColumnData.Width = this._reader.ValueAsDouble;
144✔
742
                                        break;
144✔
743
                                case 45:
744
                                        mtext.ColumnData.Gutter = this._reader.ValueAsDouble;
144✔
745
                                        break;
144✔
746
                                case 46:
747
                                        mtext.ColumnData.Heights.Add(this._reader.ValueAsDouble);
144✔
748
                                        break;
144✔
749
                                case 73:
750
                                        mtext.ColumnData.AutoHeight = this._reader.ValueAsBool;
144✔
751
                                        break;
144✔
752
                                case 74:
753
                                        mtext.ColumnData.FlowReversed = this._reader.ValueAsBool;
144✔
754
                                        break;
144✔
755
                                default:
756
                                        this._builder.Notify($"[MText.ColumnData] unkown dxf code {this._reader.Code}.", NotificationType.None);
×
757
                                        break;
×
758
                        }
759

760
                        this._reader.ReadNext();
2,592✔
761
                }
2,592✔
762
        }
144✔
763

764
        private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
765
        {
6,480✔
766
                CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,480✔
767

768
                switch (this._reader.Code)
6,480✔
769
                {
770
                        case 3:
771
                                tmp.DimensionStyleName = this._reader.ValueAsString;
648✔
772
                                return true;
648✔
773
                        default:
774
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,832✔
775
                }
776
        }
6,480✔
777

778
        private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
779
        {
72,504✔
780
                CadDimensionTemplate tmp = template as CadDimensionTemplate;
72,504✔
781

782
                switch (this._reader.Code)
72,504✔
783
                {
784
                        case 2:
785
                                tmp.BlockName = this._reader.ValueAsString;
2,772✔
786
                                return true;
2,772✔
787
                        case 3:
788
                                tmp.StyleName = this._reader.ValueAsString;
2,376✔
789
                                return true;
2,376✔
790
                        case 50:
791
                                if (tmp.CadObject is not DimensionLinear dim)
252✔
792
                                {
216✔
793
                                        dim = new DimensionLinear();
216✔
794
                                        tmp.SetDimensionObject(dim);
216✔
795
                                }
216✔
796
                                dim.Rotation = this._reader.ValueAsAngle;
252✔
797
                                map.SubClasses.TryAdd(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
252✔
798
                                return true;
252✔
799
                        case 70:
800
                                //Flags do not have set
801
                                tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,772✔
802

803
                                if (tmp.CadObject is CadDimensionTemplate.DimensionPlaceholder placeholder && this._builder.Version < ACadVersion.AC1012)
2,772!
804
                                {
396✔
805
                                        switch (placeholder.Flags)
396!
806
                                        {
807
                                                case DimensionType.Linear:
808
                                                        tmp.SetDimensionObject(new DimensionLinear());
108✔
809
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.AlignedDimension, DxfClassMap.Create<DimensionAligned>());
108✔
810
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
108✔
811
                                                        break;
108✔
812
                                                case DimensionType.Aligned:
813
                                                        tmp.SetDimensionObject(new DimensionAligned());
72✔
814
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.AlignedDimension, DxfClassMap.Create<DimensionAligned>());
72✔
815
                                                        break;
72✔
816
                                                case DimensionType.Angular:
817
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
36✔
818
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.Angular2LineDimension, DxfClassMap.Create<DimensionAngular2Line>());
36✔
819
                                                        break;
36✔
820
                                                case DimensionType.Diameter:
821
                                                        tmp.SetDimensionObject(new DimensionDiameter());
×
822
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.DiametricDimension, DxfClassMap.Create<DimensionDiameter>());
×
823
                                                        break;
×
824
                                                case DimensionType.Radius:
825
                                                        tmp.SetDimensionObject(new DimensionRadius());
36✔
826
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.RadialDimension, DxfClassMap.Create<DimensionRadius>());
36✔
827
                                                        break;
36✔
828
                                                case DimensionType.Angular3Point:
829
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
36✔
830
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.Angular3PointDimension, DxfClassMap.Create<DimensionAngular3Pt>());
36✔
831
                                                        break;
36✔
832
                                                case DimensionType.Ordinate:
833
                                                case DimensionType.OrdinateTypeX:
834
                                                case DimensionType.Ordinate | DimensionType.OrdinateTypeX:
835
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
72✔
836
                                                        map.SubClasses.TryAdd(DxfSubclassMarker.OrdinateDimension, DxfClassMap.Create<DimensionOrdinate>());
72✔
837
                                                        break;
72✔
838
                                                case DimensionType.BlockReference:
839
                                                case DimensionType.TextUserDefinedLocation:
840
                                                default:
841
                                                        break;
36✔
842
                                        }
843
                                }
396✔
844
                                return true;
2,772✔
845
                        //Measurement - read only
846
                        case 42:
847
                                return true;
2,376✔
848
                        //Undocumented codes
849
                        case 73:
850
                        case 74:
851
                        case 75:
852
                        case 90:
853
                        case 361:
854
                                return true;
4,752✔
855
                        case 100:
856
                                switch (this._reader.ValueAsString)
7,776✔
857
                                {
858
                                        case DxfSubclassMarker.Dimension:
859
                                                return true;
2,376✔
860
                                        case DxfSubclassMarker.AlignedDimension:
861
                                                tmp.SetDimensionObject(new DimensionAligned());
1,080✔
862
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,080✔
863
                                                return true;
1,080✔
864
                                        case DxfSubclassMarker.DiametricDimension:
865
                                                tmp.SetDimensionObject(new DimensionDiameter());
216✔
866
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
216✔
867
                                                return true;
216✔
868
                                        case DxfSubclassMarker.Angular2LineDimension:
869
                                                tmp.SetDimensionObject(new DimensionAngular2Line());
216✔
870
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
216✔
871
                                                return true;
216✔
872
                                        case DxfSubclassMarker.Angular3PointDimension:
873
                                                tmp.SetDimensionObject(new DimensionAngular3Pt());
216✔
874
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
216✔
875
                                                return true;
216✔
876
                                        case DxfSubclassMarker.RadialDimension:
877
                                                tmp.SetDimensionObject(new DimensionRadius());
216✔
878
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
216✔
879
                                                return true;
216✔
880
                                        case DxfSubclassMarker.OrdinateDimension:
881
                                                tmp.SetDimensionObject(new DimensionOrdinate());
432✔
882
                                                map.SubClasses.TryAdd(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
432✔
883
                                                return true;
432✔
884
                                        case DxfSubclassMarker.LinearDimension:
885
                                                tmp.SetDimensionObject(new DimensionLinear());
648✔
886
                                                map.SubClasses.TryAdd(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
648✔
887
                                                return true;
648✔
888
                                        default:
889
                                                return false;
2,376✔
890
                                }
891
                        default:
892
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
49,428✔
893
                }
894
        }
72,504✔
895

896
        protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
897
        {
46,224✔
898
                CadHatchTemplate tmp = template as CadHatchTemplate;
46,224✔
899
                Hatch hatch = tmp.CadObject;
46,224✔
900

901
                XY seedPoint = new XY();
46,224✔
902

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

992
        private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
993
        {
62,601✔
994
                CadInsertTemplate tmp = template as CadInsertTemplate;
62,601✔
995

996
                switch (this._reader.Code)
62,601✔
997
                {
998
                        case 2:
999
                                tmp.BlockName = this._reader.ValueAsString;
5,853✔
1000
                                return true;
5,853✔
1001
                        case 100:
1002
                                //AcDbEntity
1003
                                //AcDbBlockReference
1004
                                //AcDbMInsertBlock
1005
                                return true;
5,882✔
1006
                        case 66:
1007
                                return true;
504✔
1008
                        default:
1009
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
50,362✔
1010
                }
1011
        }
62,601✔
1012

1013
        private CadEntityTemplate readPolyline()
1014
        {
11,092✔
1015
                if (this._builder.Version == ACadVersion.Unknown
11,092!
1016
                        || this._builder.Version == ACadVersion.AC1009)
11,092✔
1017
                {
10,660✔
1018
                        return this.readLegacyPolyline();
10,660✔
1019
                }
1020

1021
                CadPolyLineTemplate template = null;
432✔
1022
                template = new CadPolyLineTemplate();
432✔
1023
                this.readEntityCodes<Entity>(template, this.readPolyline);
432✔
1024

1025
                if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
432!
1026
                {
×
1027
                        this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
1028
                        return null;
×
1029
                }
1030

1031
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
3,024!
1032
                {
2,592✔
1033
                        var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,592✔
1034

1035
                        if (vertexTemplate.OwnerHandle == null)
2,592!
1036
                        {
×
1037
                                vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
1038
                        }
×
1039

1040
                        template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,592✔
1041
                        _builder.AddTemplate(vertexTemplate);
2,592✔
1042
                }
2,592✔
1043

1044
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
864!
1045
                {
432✔
1046
                        var seqend = new Seqend();
432✔
1047
                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
432✔
1048
                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
432✔
1049

1050
                        if (seqendTemplate.OwnerHandle == null)
432!
1051
                        {
×
1052
                                seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
1053
                        }
×
1054

1055
                        template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
432✔
1056
                        _builder.AddTemplate(seqendTemplate);
432✔
1057
                }
432✔
1058

1059
                return template;
432✔
1060
        }
11,092✔
1061

1062
        private CadEntityTemplate readLegacyPolyline()
1063
        {
10,660✔
1064
                var polyline = new Polyline2D();
10,660✔
1065
                CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,660✔
1066
                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,660✔
1067

1068
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
48,700!
1069
                {
38,040✔
1070
                        Vertex2D v = new Vertex2D();
38,040✔
1071
                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
38,040✔
1072
                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
38,040✔
1073

1074
                        if (vertexTemplate.Vertex.Handle == 0)
38,040!
1075
                        {
×
1076
                                polyline.Vertices.Add(v);
×
1077
                        }
×
1078
                        else
1079
                        {
38,040✔
1080
                                template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
38,040✔
1081
                                this._builder.AddTemplate(vertexTemplate);
38,040✔
1082
                        }
38,040✔
1083
                }
38,040✔
1084

1085
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
21,320!
1086
                {
10,660✔
1087
                        var seqend = new Seqend();
10,660✔
1088
                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,660✔
1089
                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,660✔
1090

1091
                        polyline.Vertices.Seqend = seqend;
10,660✔
1092
                }
10,660✔
1093

1094
                return template;
10,660✔
1095
        }
10,660✔
1096

1097
        private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1098
        {
79,656✔
1099
                CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
79,656✔
1100

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

1137
        private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1138
        {
5,400✔
1139
                CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,400✔
1140

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

1172
        private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1173
        {
92,547✔
1174
                CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
92,547✔
1175

1176
                LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
92,547✔
1177

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

1229
        private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1230
        {
38,016✔
1231
                CadMeshTemplate tmp = template as CadMeshTemplate;
38,016✔
1232

1233
                switch (this._reader.Code)
38,016✔
1234
                {
1235
                        case 100:
1236
                                if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
864✔
1237
                                {
432✔
1238
                                        tmp.SubclassMarker = true;
432✔
1239
                                }
432✔
1240
                                return true;
864✔
1241
                        //Count of sub-entity which property has been overridden
1242
                        case 90:
1243
                                //TODO: process further entities
1244
                                return true;
432✔
1245
                        case 92:
1246
                                if (!tmp.SubclassMarker)
648✔
1247
                                {
216✔
1248
                                        return false;
216✔
1249
                                }
1250

1251
                                int nvertices = this._reader.ValueAsInt;
432✔
1252
                                for (int i = 0; i < nvertices; i++)
55,296✔
1253
                                {
27,216✔
1254
                                        this._reader.ReadNext();
27,216✔
1255
                                        double x = this._reader.ValueAsDouble;
27,216✔
1256
                                        this._reader.ReadNext();
27,216✔
1257
                                        double y = this._reader.ValueAsDouble;
27,216✔
1258
                                        this._reader.ReadNext();
27,216✔
1259
                                        double z = this._reader.ValueAsDouble;
27,216✔
1260
                                        tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
27,216✔
1261
                                }
27,216✔
1262
                                return true;
432✔
1263
                        case 93:
1264
                                int size = this._reader.ValueAsInt;
432✔
1265
                                this._reader.ReadNext();
432✔
1266

1267
                                int indexes = 0;
432✔
1268
                                for (int i = 0; i < size; i += indexes + 1)
59,616✔
1269
                                {
29,376✔
1270
                                        indexes = this._reader.ValueAsInt;
29,376✔
1271
                                        this._reader.ReadNext();
29,376✔
1272

1273
                                        int[] face = new int[indexes];
29,376✔
1274
                                        for (int j = 0; j < indexes; j++)
283,392✔
1275
                                        {
112,320✔
1276
                                                face[j] = this._reader.ValueAsInt;
112,320✔
1277

1278
                                                if ((i + j + 2) < size)
112,320✔
1279
                                                {
111,888✔
1280
                                                        this._reader.ReadNext();
111,888✔
1281
                                                }
111,888✔
1282
                                        }
112,320✔
1283

1284
                                        tmp.CadObject.Faces.Add(face);
29,376✔
1285
                                }
29,376✔
1286

1287
                                return true;
432✔
1288
                        case 94:
1289
                                int numEdges = this._reader.ValueAsInt;
432✔
1290
                                this._reader.ReadNext();
432✔
1291
                                for (int i = 0; i < numEdges; i++)
113,184✔
1292
                                {
56,160✔
1293
                                        Mesh.Edge edge = new Mesh.Edge();
56,160✔
1294

1295
                                        edge.Start = this._reader.ValueAsInt;
56,160✔
1296
                                        this._reader.ReadNext();
56,160✔
1297
                                        edge.End = this._reader.ValueAsInt;
56,160✔
1298

1299
                                        if (i < numEdges - 1)
56,160✔
1300
                                        {
55,728✔
1301
                                                this._reader.ReadNext();
55,728✔
1302
                                        }
55,728✔
1303

1304
                                        tmp.CadObject.Edges.Add(edge);
56,160✔
1305
                                }
56,160✔
1306

1307
                                return true;
432✔
1308
                        case 95:
1309
                                this._reader.ReadNext();
432✔
1310
                                for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
113,184✔
1311
                                {
56,160✔
1312
                                        Mesh.Edge edge = tmp.CadObject.Edges[i];
56,160✔
1313
                                        edge.Crease = this._reader.ValueAsDouble;
56,160✔
1314

1315
                                        tmp.CadObject.Edges[i] = edge;
56,160✔
1316

1317
                                        if (i < tmp.CadObject.Edges.Count - 1)
56,160✔
1318
                                        {
55,728✔
1319
                                                this._reader.ReadNext();
55,728✔
1320
                                        }
55,728✔
1321
                                }
56,160✔
1322

1323
                                return true;
432✔
1324
                        default:
1325
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,776✔
1326
                }
1327
        }
38,016✔
1328

1329
        private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1330
        {
56,160✔
1331
                CadMLineTemplate tmp = template as CadMLineTemplate;
56,160✔
1332

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

1358
        private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1359
        {
152,496✔
1360
                CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
152,496✔
1361

1362
                switch (this._reader.Code)
152,496✔
1363
                {
1364
                        case 270:
1365
                                //f270 Version
1366
                                return true;
1,620✔
1367
                        case 300:
1368
                                this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,240✔
1369
                                return true;
3,240✔
1370
                        case 340:
1371
                                tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,240✔
1372
                                return true;
3,240✔
1373
                        case 341:
1374
                                tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,240✔
1375
                                return true;
3,240✔
1376
                        case 343:
1377
                                tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,240✔
1378
                                return true;
3,240✔
1379
                        default:
1380
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
137,916✔
1381
                }
1382
        }
152,496✔
1383

1384
        private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1385
        {
3,240✔
1386
                this._reader.ReadNext();
3,240✔
1387

1388
                var map = DxfClassMap.Create<MultiLeaderObjectContextData>();
3,240✔
1389
                var contextData = template.CadObject as MultiLeaderObjectContextData;
3,240✔
1390

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

1413
                        if (end)
181,440✔
1414
                        {
3,240✔
1415
                                break;
3,240✔
1416
                        }
1417

1418
                        this._reader.ReadNext();
178,200✔
1419
                }
178,200✔
1420
        }
3,240✔
1421

1422
        private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1423
        {
3,240✔
1424
                MultiLeaderObjectContextData.LeaderRoot root = new();
3,240✔
1425
                var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,240✔
1426

1427
                this._reader.ReadNext();
3,240✔
1428

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

1450
                        if (end)
40,500✔
1451
                        {
3,240✔
1452
                                break;
3,240✔
1453
                        }
1454

1455
                        this._reader.ReadNext();
37,260✔
1456
                }
37,260✔
1457

1458
                return root;
3,240✔
1459
        }
3,240✔
1460

1461
        private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1462
        {
3,240✔
1463
                MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,240✔
1464
                var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,240✔
1465

1466
                this._reader.ReadNext();
3,240✔
1467

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

1498
                        if (end)
16,200✔
1499
                        {
3,240✔
1500
                                break;
3,240✔
1501
                        }
1502

1503
                        this._reader.ReadNext();
12,960✔
1504
                }
12,960✔
1505

1506
                return line;
3,240✔
1507
        }
3,240✔
1508

1509
        private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1510
        {
2,412✔
1511
                CadShapeTemplate tmp = template as CadShapeTemplate;
2,412✔
1512

1513
                switch (this._reader.Code)
2,412✔
1514
                {
1515
                        case 2:
1516
                                tmp.ShapeFileName = this._reader.ValueAsString;
252✔
1517
                                return true;
252✔
1518
                        default:
1519
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,160✔
1520
                }
1521
        }
2,412✔
1522

1523
        private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1524
        {
12,744✔
1525
                CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,744✔
1526
                CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,744✔
1527

1528
                switch (this._reader.Code)
12,744✔
1529
                {
1530
                        case 91:
1531
                                var nvertices = this._reader.ValueAsInt;
432✔
1532
                                for (int i = 0; i < nvertices; i++)
3,888✔
1533
                                {
1,512✔
1534
                                        this._reader.ReadNext();
1,512✔
1535
                                        var x = this._reader.ValueAsDouble;
1,512✔
1536
                                        this._reader.ReadNext();
1,512✔
1537
                                        var y = this._reader.ValueAsDouble;
1,512✔
1538

1539
                                        wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,512✔
1540
                                }
1,512✔
1541

1542
                                this._reader.ReadNext();
432✔
1543

1544
                                return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
432✔
1545
                        case 340:
1546
                                tmp.ImgDefHandle = this._reader.ValueAsHandle;
432✔
1547
                                return true;
432✔
1548
                        case 360:
1549
                                tmp.ImgReactorHandle = this._reader.ValueAsHandle;
432✔
1550
                                return true;
432✔
1551
                        default:
1552
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
11,448✔
1553
                }
1554
        }
12,744✔
1555

1556
        private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1557
        {
×
1558
                CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1559

1560
                switch (this._reader.Code)
×
1561
                {
1562
                        //End of data
1563
                        case 1:
1564
                        //Length of binary data
1565
                        case 90:
1566
                        //Undocumented
1567
                        case 73:
1568
                                return true;
×
1569
                        case 310:
1570
                                tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
1571
                                return true;
×
1572
                        default:
1573
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1574
                }
1575
        }
×
1576

1577
        private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1578
        {
306,654✔
1579
                CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
306,654✔
1580
                string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
306,654✔
1581
                var geometry = template.CadObject as ModelerGeometry;
306,654✔
1582

1583
                switch (this._reader.Code)
306,654✔
1584
                {
1585
                        case 1:
1586
                        case 3:
1587
                                geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
39,924✔
1588
                                return true;
39,924✔
1589
                        case 2:
1590
                                geometry.Guid = new Guid(this._reader.ValueAsString);
216✔
1591
                                return true;
216✔
1592
                        case 290:
1593
                                return true;
216✔
1594
                        default:
1595
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
266,298✔
1596
                }
1597
        }
306,654✔
1598

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

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

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

1617
                XYZ controlPoint;
1618
                XYZ fitPoint;
1619

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

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

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

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

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

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

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

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

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

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

1759
                this._reader.ReadNext();
36,447✔
1760

1761
                while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
296,790✔
1762
                {
271,853✔
1763
                        if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
271,853✔
1764
                        {
11,510✔
1765
                                this.readExtendedData(edata);
11,510✔
1766
                                break;
11,510✔
1767
                        }
1768

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

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

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

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

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

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

1875
                        if (record != null)
260,343✔
1876
                        {
258,025✔
1877
                                records.Add(record);
258,025✔
1878
                        }
258,025✔
1879

1880
                        this._reader.ReadNext();
260,343✔
1881
                }
260,343✔
1882
        }
36,447✔
1883

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2082
                return boundary;
648✔
2083
        }
648✔
2084

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

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

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

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

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

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

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

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

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

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

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

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

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

2279
                switch (this._reader.ValueAsString)
72,712✔
2280
                {
2281
                        case DxfFileToken.DictionaryToken:
2282
                                this._reader.ReadNext();
10,689✔
2283
                                xdictHandle = this._reader.ValueAsHandle;
10,689✔
2284
                                this._reader.ReadNext();
10,689✔
2285
                                Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,689✔
2286
                                return;
10,689✔
2287
                        case DxfFileToken.ReactorsToken:
2288
                                reactors = this.readReactors();
59,850✔
2289
                                break;
59,850✔
2290
                        case DxfFileToken.BlkRefToken:
2291
                        default:
2292
                                do
2293
                                {
5,642✔
2294
                                        this._reader.ReadNext();
5,642✔
2295
                                }
5,642✔
2296
                                while (this._reader.DxfCode != DxfCode.ControlString);
5,642✔
2297
                                return;
2,173✔
2298
                }
2299
        }
72,712✔
2300

2301
        private HashSet<ulong> readReactors()
2302
        {
59,850✔
2303
                HashSet<ulong> reactors = new();
59,850✔
2304

2305
                this._reader.ReadNext();
59,850✔
2306

2307
                while (this._reader.DxfCode != DxfCode.ControlString)
126,600✔
2308
                {
66,750✔
2309
                        reactors.Add(this._reader.ValueAsHandle);
66,750✔
2310

2311
                        this._reader.ReadNext();
66,750✔
2312
                }
66,750✔
2313

2314
                return reactors;
59,850✔
2315
        }
59,850✔
2316

2317
        protected bool tryAssignCurrentValue(object cadObject, DxfMap map)
2318
        {
13,794✔
2319
                if (string.IsNullOrEmpty(this.currentSubclass))
13,794✔
2320
                {
1,236✔
2321
                        return false;
1,236✔
2322
                }
2323

2324
                if (map.SubClasses.TryGetValue(this.currentSubclass, out var subClass))
12,558!
2325
                {
12,558✔
2326
                        return this.tryAssignCurrentValue(cadObject, subClass);
12,558✔
2327
                }
2328
                else
2329
                {
×
2330
                        return false;
×
2331
                }
2332
        }
13,794✔
2333

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

2346
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,338,097✔
2347
                                        || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,338,097✔
2348
                                {
17,358✔
2349
                                        return false;
17,358✔
2350
                                }
2351

2352
                                object value = this._reader.Value;
2,320,739✔
2353

2354
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,320,739✔
2355
                                {
26,323✔
2356
                                        value = MathHelper.DegToRad((double)value);
26,323✔
2357
                                }
26,323✔
2358

2359
                                dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,320,739✔
2360

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

2376
                return false;
2,126,150✔
2377
        }
4,477,971✔
2378
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc