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

DomCR / ACadSharp / 26631700798

29 May 2026 10:17AM UTC coverage: 76.999% (+0.007%) from 76.992%
26631700798

push

github

web-flow
Merge pull request #1101 from DomCR/issue/1093_dxf-dimension-type-fix

Issue-1093 Refactor dimension handling and update submodule

8620 of 12149 branches covered (70.95%)

Branch coverage included in aggregate %.

83 of 90 new or added lines in 4 files covered. (92.22%)

2 existing lines in 2 files now uncovered.

31119 of 39461 relevant lines covered (78.86%)

157384.04 hits per line

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

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

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

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

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

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

152
        protected CadEntityTemplate readEntity()
153
        {
154,947✔
154
                this.currentSubclass = string.Empty;
154,947✔
155
                switch (this._reader.ValueAsString)
154,947!
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,226✔
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,851✔
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,947✔
267

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

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

275
                while (this._reader.DxfCode != DxfCode.Start)
2,799,473✔
276
                {
2,592,732✔
277
                        if (!readEntity(template, map))
2,592,732✔
278
                        {
905,254✔
279
                                this.readCommonEntityCodes(template, out bool isExtendedData, map);
905,254✔
280
                                if (isExtendedData)
905,254✔
281
                                        continue;
14,476✔
282
                        }
890,778✔
283

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

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

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

297
        protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
298
        {
976,981✔
299
                isExtendedData = false;
976,981✔
300
                switch (this._reader.Code)
976,981✔
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,265✔
307
                                break;
224,265✔
308
                        //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
309
                        case 67:
310
                                break;
1,336✔
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,130✔
325
                                {
499,540✔
326
                                        this.readCommonCodes(template, out isExtendedData, map);
499,540✔
327
                                }
499,540✔
328
                                break;
642,130✔
329
                }
330
        }
976,981✔
331

332
        [Obsolete("use lockpointer instead")]
333
        protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
334
        {
3,080✔
335
                if (this._reader.DxfCode == DxfCode.Start)
3,080!
336
                {
×
337
                        return true;
×
338
                }
339
                else
340
                {
3,080✔
341
                        return func.Invoke(template, map);
3,080✔
342
                }
343
        }
3,080✔
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,105✔
359
                Circle circle = template.CadObject as Circle;
38,105✔
360

361
                switch (this._reader.Code)
38,105✔
362
                {
363
                        case 40:
364
                                double radius = this._reader.ValueAsDouble;
3,954✔
365
                                if (radius <= 0)
3,954!
366
                                {
×
367
                                        circle.Radius = MathHelper.Epsilon;
×
368
                                }
×
369
                                else
370
                                {
3,954✔
371
                                        circle.Radius = radius;
3,954✔
372
                                }
3,954✔
373
                                return true;
3,954✔
374
                        default:
375
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Circle]);
34,151✔
376
                }
377
        }
38,105✔
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
                                //Has data flag
548
                                return true;
648✔
549
                        case 171:
550
                                tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
8,856✔
551
                                return true;
8,856✔
552
                        case 172:
553
                                tmp.CurrentCell.EdgeFlags = this._reader.ValueAsShort;
8,856✔
554
                                return true;
8,856✔
555
                        case 173:
556
                                tmp.CurrentCell.MergedValue = this._reader.ValueAsShort;
8,856✔
557
                                return true;
8,856✔
558
                        case 174:
559
                                tmp.CurrentCell.AutoFit = this._reader.ValueAsBool;
8,856✔
560
                                return true;
8,856✔
561
                        case 175:
562
                                tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
8,856✔
563
                                return true;
8,856✔
564
                        case 176:
565
                                tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
8,856✔
566
                                return true;
8,856✔
567
                        case 178:
568
                                tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
8,856✔
569
                                return true;
8,856✔
570
                        case 179:
571
                                //Unknown value
572
                                return true;
432✔
573
                        case 301:
574
                                content = new TableEntity.CellContent();
5,904✔
575
                                var contentTemplate = new CadTableCellContentTemplate(content);
5,904✔
576
                                tmp.CurrentCell.Contents.Add(content);
5,904✔
577
                                var valTemplate = readCadValue(content.CadValue);
5,904✔
578
                                contentTemplate.CadValueTemplate = valTemplate;
5,904✔
579
                                return true;
5,904✔
580
                        case 340:
581
                                tmp.CurrentCellTemplate.ValueHandle = this._reader.ValueAsHandle;
432✔
582
                                return true;
432✔
583
                        default:
584
                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
39,852✔
585
                                {
38,340✔
586
                                        return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
38,340✔
587
                                }
588
                                return true;
1,512✔
589
                }
590
        }
142,236✔
591

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

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

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

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

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

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

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

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

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

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

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

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

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

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

873
        protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
874
        {
46,224✔
875
                CadHatchTemplate tmp = template as CadHatchTemplate;
46,224✔
876
                Hatch hatch = tmp.CadObject;
46,224✔
877

878
                XY seedPoint = new XY();
46,224✔
879

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

969
        private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
970
        {
62,582✔
971
                CadInsertTemplate tmp = template as CadInsertTemplate;
62,582✔
972

973
                switch (this._reader.Code)
62,582✔
974
                {
975
                        case 2:
976
                                tmp.BlockName = this._reader.ValueAsString;
5,851✔
977
                                return true;
5,851✔
978
                        case 100:
979
                                //AcDbEntity
980
                                //AcDbBlockReference
981
                                //AcDbMInsertBlock
982
                                return true;
5,878✔
983
                        case 66:
984
                                return true;
504✔
985
                        default:
986
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
50,349✔
987
                }
988
        }
62,582✔
989

990
        private CadEntityTemplate readPolyline()
991
        {
11,092✔
992
                if (this._builder.Version == ACadVersion.Unknown
11,092!
993
                        || this._builder.Version == ACadVersion.AC1009)
11,092✔
994
                {
10,660✔
995
                        return this.readLegacyPolyline();
10,660✔
996
                }
997

998
                CadPolyLineTemplate template = null;
432✔
999
                template = new CadPolyLineTemplate();
432✔
1000
                this.readEntityCodes<Entity>(template, this.readPolyline);
432✔
1001

1002
                if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
432!
1003
                {
×
1004
                        this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
1005
                        return null;
×
1006
                }
1007

1008
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
3,024!
1009
                {
2,592✔
1010
                        var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,592✔
1011

1012
                        if (vertexTemplate.OwnerHandle == null)
2,592!
1013
                        {
×
1014
                                vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
1015
                        }
×
1016

1017
                        template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,592✔
1018
                        _builder.AddTemplate(vertexTemplate);
2,592✔
1019
                }
2,592✔
1020

1021
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
864!
1022
                {
432✔
1023
                        var seqend = new Seqend();
432✔
1024
                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
432✔
1025
                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
432✔
1026

1027
                        if (seqendTemplate.OwnerHandle == null)
432!
1028
                        {
×
1029
                                seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
1030
                        }
×
1031

1032
                        template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
432✔
1033
                        _builder.AddTemplate(seqendTemplate);
432✔
1034
                }
432✔
1035

1036
                return template;
432✔
1037
        }
11,092✔
1038

1039
        private CadEntityTemplate readLegacyPolyline()
1040
        {
10,660✔
1041
                var polyline = new Polyline2D();
10,660✔
1042
                CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,660✔
1043
                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,660✔
1044

1045
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
48,700!
1046
                {
38,040✔
1047
                        Vertex2D v = new Vertex2D();
38,040✔
1048
                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
38,040✔
1049
                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
38,040✔
1050

1051
                        if (vertexTemplate.Vertex.Handle == 0)
38,040!
1052
                        {
×
1053
                                polyline.Vertices.Add(v);
×
1054
                        }
×
1055
                        else
1056
                        {
38,040✔
1057
                                template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
38,040✔
1058
                                this._builder.AddTemplate(vertexTemplate);
38,040✔
1059
                        }
38,040✔
1060
                }
38,040✔
1061

1062
                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
21,320!
1063
                {
10,660✔
1064
                        var seqend = new Seqend();
10,660✔
1065
                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,660✔
1066
                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,660✔
1067

1068
                        polyline.Vertices.Seqend = seqend;
10,660✔
1069
                }
10,660✔
1070

1071
                return template;
10,660✔
1072
        }
10,660✔
1073

1074
        private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1075
        {
79,656✔
1076
                CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
79,656✔
1077

1078
                switch (this._reader.Code)
79,656✔
1079
                {
1080
                        //DXF: always 0
1081
                        //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)
1082
                        case 10:
1083
                        case 20:
1084
                        //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1085
                        case 66:
1086
                                return true;
33,276✔
1087
                        case 100:
1088
                                switch (this._reader.ValueAsString)
864!
1089
                                {
1090
                                        case DxfSubclassMarker.Polyline:
1091
                                                tmp.SetPolyLineObject(new Polyline2D());
×
1092
                                                map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
1093
                                                return true;
×
1094
                                        case DxfSubclassMarker.Polyline3d:
1095
                                                tmp.SetPolyLineObject(new Polyline3D());
216✔
1096
                                                map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
216✔
1097
                                                return true;
216✔
1098
                                        case DxfSubclassMarker.PolyfaceMesh:
1099
                                                tmp.SetPolyLineObject(new PolyfaceMesh());
216✔
1100
                                                map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
216✔
1101
                                                return true;
216✔
1102
                                        case DxfSubclassMarker.PolygonMesh:
1103
                                                tmp.SetPolyLineObject(new PolygonMesh());
×
1104
                                                map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
1105
                                                return true;
×
1106
                                        default:
1107
                                                return false;
432✔
1108
                                }
1109
                        default:
1110
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
45,516✔
1111
                }
1112
        }
79,656✔
1113

1114
        private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1115
        {
5,400✔
1116
                CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,400✔
1117

1118
                switch (this._reader.Code)
5,400✔
1119
                {
1120
                        case 3:
1121
                                tmp.DIMSTYLEName = this._reader.ValueAsString;
216✔
1122
                                return true;
216✔
1123
                        case 10:
1124
                                tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
864✔
1125
                                return true;
864✔
1126
                        case 20:
1127
                                XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
864✔
1128
                                y.Y = this._reader.ValueAsDouble;
864✔
1129
                                tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
864✔
1130
                                return true;
864✔
1131
                        case 30:
1132
                                XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
864✔
1133
                                z.Z = this._reader.ValueAsDouble;
864✔
1134
                                tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
864✔
1135
                                return true;
864✔
1136
                        case 340:
1137
                                tmp.AnnotationHandle = this._reader.ValueAsHandle;
216✔
1138
                                return true;
216✔
1139
                        //Hook line flag - read only
1140
                        case 75:
1141
                        //Vertices count
1142
                        case 76:
1143
                                return true;
432✔
1144
                        default:
1145
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,944✔
1146
                }
1147
        }
5,400✔
1148

1149
        private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1150
        {
92,547✔
1151
                CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
92,547✔
1152

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

1155
                switch (this._reader.Code)
92,547!
1156
                {
1157
                        case 10:
1158
                                tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
22,012✔
1159
                                return true;
22,012✔
1160
                        case 20:
1161
                                if (last is not null)
22,012✔
1162
                                {
22,012✔
1163
                                        last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
22,012✔
1164
                                }
22,012✔
1165
                                return true;
22,012✔
1166
                        case 40:
1167
                                if (last is not null)
2,160✔
1168
                                {
2,160✔
1169
                                        last.StartWidth = this._reader.ValueAsDouble;
2,160✔
1170
                                }
2,160✔
1171
                                return true;
2,160✔
1172
                        case 41:
1173
                                if (last is not null)
2,160✔
1174
                                {
2,160✔
1175
                                        last.EndWidth = this._reader.ValueAsDouble;
2,160✔
1176
                                }
2,160✔
1177
                                return true;
2,160✔
1178
                        case 42:
1179
                                if (last is not null)
2,952✔
1180
                                {
2,952✔
1181
                                        last.Bulge = this._reader.ValueAsDouble;
2,952✔
1182
                                }
2,952✔
1183
                                return true;
2,952✔
1184
                        case 50:
1185
                                if (last is not null)
×
1186
                                {
×
1187
                                        last.CurveTangent = this._reader.ValueAsDouble;
×
1188
                                }
×
1189
                                return true;
×
1190
                        //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1191
                        case 66:
1192
                        //Vertex count
1193
                        case 90:
1194
                                return true;
4,966✔
1195
                        case 91:
1196
                                if (last is not null)
×
1197
                                {
×
1198
                                        last.Id = this._reader.ValueAsInt;
×
1199
                                }
×
1200
                                return true;
×
1201
                        default:
1202
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
36,285✔
1203
                }
1204
        }
92,547✔
1205

1206
        private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1207
        {
38,016✔
1208
                CadMeshTemplate tmp = template as CadMeshTemplate;
38,016✔
1209

1210
                switch (this._reader.Code)
38,016✔
1211
                {
1212
                        case 100:
1213
                                if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
864✔
1214
                                {
432✔
1215
                                        tmp.SubclassMarker = true;
432✔
1216
                                }
432✔
1217
                                return true;
864✔
1218
                        //Count of sub-entity which property has been overridden
1219
                        case 90:
1220
                                //TODO: process further entities
1221
                                return true;
432✔
1222
                        case 92:
1223
                                if (!tmp.SubclassMarker)
648✔
1224
                                {
216✔
1225
                                        return false;
216✔
1226
                                }
1227

1228
                                int nvertices = this._reader.ValueAsInt;
432✔
1229
                                for (int i = 0; i < nvertices; i++)
55,296✔
1230
                                {
27,216✔
1231
                                        this._reader.ReadNext();
27,216✔
1232
                                        double x = this._reader.ValueAsDouble;
27,216✔
1233
                                        this._reader.ReadNext();
27,216✔
1234
                                        double y = this._reader.ValueAsDouble;
27,216✔
1235
                                        this._reader.ReadNext();
27,216✔
1236
                                        double z = this._reader.ValueAsDouble;
27,216✔
1237
                                        tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
27,216✔
1238
                                }
27,216✔
1239
                                return true;
432✔
1240
                        case 93:
1241
                                int size = this._reader.ValueAsInt;
432✔
1242
                                this._reader.ReadNext();
432✔
1243

1244
                                int indexes = 0;
432✔
1245
                                for (int i = 0; i < size; i += indexes + 1)
59,616✔
1246
                                {
29,376✔
1247
                                        indexes = this._reader.ValueAsInt;
29,376✔
1248
                                        this._reader.ReadNext();
29,376✔
1249

1250
                                        int[] face = new int[indexes];
29,376✔
1251
                                        for (int j = 0; j < indexes; j++)
283,392✔
1252
                                        {
112,320✔
1253
                                                face[j] = this._reader.ValueAsInt;
112,320✔
1254

1255
                                                if ((i + j + 2) < size)
112,320✔
1256
                                                {
111,888✔
1257
                                                        this._reader.ReadNext();
111,888✔
1258
                                                }
111,888✔
1259
                                        }
112,320✔
1260

1261
                                        tmp.CadObject.Faces.Add(face);
29,376✔
1262
                                }
29,376✔
1263

1264
                                return true;
432✔
1265
                        case 94:
1266
                                int numEdges = this._reader.ValueAsInt;
432✔
1267
                                this._reader.ReadNext();
432✔
1268
                                for (int i = 0; i < numEdges; i++)
113,184✔
1269
                                {
56,160✔
1270
                                        Mesh.Edge edge = new Mesh.Edge();
56,160✔
1271

1272
                                        edge.Start = this._reader.ValueAsInt;
56,160✔
1273
                                        this._reader.ReadNext();
56,160✔
1274
                                        edge.End = this._reader.ValueAsInt;
56,160✔
1275

1276
                                        if (i < numEdges - 1)
56,160✔
1277
                                        {
55,728✔
1278
                                                this._reader.ReadNext();
55,728✔
1279
                                        }
55,728✔
1280

1281
                                        tmp.CadObject.Edges.Add(edge);
56,160✔
1282
                                }
56,160✔
1283

1284
                                return true;
432✔
1285
                        case 95:
1286
                                this._reader.ReadNext();
432✔
1287
                                for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
113,184✔
1288
                                {
56,160✔
1289
                                        Mesh.Edge edge = tmp.CadObject.Edges[i];
56,160✔
1290
                                        edge.Crease = this._reader.ValueAsDouble;
56,160✔
1291

1292
                                        tmp.CadObject.Edges[i] = edge;
56,160✔
1293

1294
                                        if (i < tmp.CadObject.Edges.Count - 1)
56,160✔
1295
                                        {
55,728✔
1296
                                                this._reader.ReadNext();
55,728✔
1297
                                        }
55,728✔
1298
                                }
56,160✔
1299

1300
                                return true;
432✔
1301
                        default:
1302
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,776✔
1303
                }
1304
        }
38,016✔
1305

1306
        private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1307
        {
56,160✔
1308
                CadMLineTemplate tmp = template as CadMLineTemplate;
56,160✔
1309

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

1335
        private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1336
        {
152,496✔
1337
                CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
152,496✔
1338

1339
                switch (this._reader.Code)
152,496✔
1340
                {
1341
                        case 270:
1342
                                //f270 Version
1343
                                return true;
1,620✔
1344
                        case 300:
1345
                                this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,240✔
1346
                                return true;
3,240✔
1347
                        case 340:
1348
                                tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,240✔
1349
                                return true;
3,240✔
1350
                        case 341:
1351
                                tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,240✔
1352
                                return true;
3,240✔
1353
                        case 343:
1354
                                tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,240✔
1355
                                return true;
3,240✔
1356
                        default:
1357
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
137,916✔
1358
                }
1359
        }
152,496✔
1360

1361
        private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1362
        {
3,240✔
1363
                this._reader.ReadNext();
3,240✔
1364

1365
                var map = DxfClassMap.Create<MultiLeaderObjectContextData>();
3,240✔
1366
                var contextData = template.CadObject as MultiLeaderObjectContextData;
3,240✔
1367

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

1390
                        if (end)
181,440✔
1391
                        {
3,240✔
1392
                                break;
3,240✔
1393
                        }
1394

1395
                        this._reader.ReadNext();
178,200✔
1396
                }
178,200✔
1397
        }
3,240✔
1398

1399
        private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1400
        {
3,240✔
1401
                MultiLeaderObjectContextData.LeaderRoot root = new();
3,240✔
1402
                var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,240✔
1403

1404
                this._reader.ReadNext();
3,240✔
1405

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

1427
                        if (end)
40,500✔
1428
                        {
3,240✔
1429
                                break;
3,240✔
1430
                        }
1431

1432
                        this._reader.ReadNext();
37,260✔
1433
                }
37,260✔
1434

1435
                return root;
3,240✔
1436
        }
3,240✔
1437

1438
        private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1439
        {
3,240✔
1440
                MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,240✔
1441
                var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,240✔
1442

1443
                this._reader.ReadNext();
3,240✔
1444

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

1475
                        if (end)
16,200✔
1476
                        {
3,240✔
1477
                                break;
3,240✔
1478
                        }
1479

1480
                        this._reader.ReadNext();
12,960✔
1481
                }
12,960✔
1482

1483
                return line;
3,240✔
1484
        }
3,240✔
1485

1486
        private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1487
        {
2,412✔
1488
                CadShapeTemplate tmp = template as CadShapeTemplate;
2,412✔
1489

1490
                switch (this._reader.Code)
2,412✔
1491
                {
1492
                        case 2:
1493
                                tmp.ShapeFileName = this._reader.ValueAsString;
252✔
1494
                                return true;
252✔
1495
                        default:
1496
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,160✔
1497
                }
1498
        }
2,412✔
1499

1500
        private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1501
        {
12,744✔
1502
                CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,744✔
1503
                CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,744✔
1504

1505
                switch (this._reader.Code)
12,744✔
1506
                {
1507
                        case 91:
1508
                                var nvertices = this._reader.ValueAsInt;
432✔
1509
                                for (int i = 0; i < nvertices; i++)
3,888✔
1510
                                {
1,512✔
1511
                                        this._reader.ReadNext();
1,512✔
1512
                                        var x = this._reader.ValueAsDouble;
1,512✔
1513
                                        this._reader.ReadNext();
1,512✔
1514
                                        var y = this._reader.ValueAsDouble;
1,512✔
1515

1516
                                        wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,512✔
1517
                                }
1,512✔
1518

1519
                                this._reader.ReadNext();
432✔
1520

1521
                                return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
432✔
1522
                        case 340:
1523
                                tmp.ImgDefHandle = this._reader.ValueAsHandle;
432✔
1524
                                return true;
432✔
1525
                        case 360:
1526
                                tmp.ImgReactorHandle = this._reader.ValueAsHandle;
432✔
1527
                                return true;
432✔
1528
                        default:
1529
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
11,448✔
1530
                }
1531
        }
12,744✔
1532

1533
        private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1534
        {
×
1535
                CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1536

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

1554
        private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1555
        {
306,654✔
1556
                CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
306,654✔
1557
                string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
306,654✔
1558
                var geometry = template.CadObject as ModelerGeometry;
306,654✔
1559

1560
                switch (this._reader.Code)
306,654✔
1561
                {
1562
                        case 1:
1563
                        case 3:
1564
                                geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
39,924✔
1565
                                return true;
39,924✔
1566
                        case 2:
1567
                                geometry.Guid = new Guid(this._reader.ValueAsString);
216✔
1568
                                return true;
216✔
1569
                        case 290:
1570
                                return true;
216✔
1571
                        default:
1572
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
266,298✔
1573
                }
1574
        }
306,654✔
1575

1576
        private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1577
        {
36,936✔
1578
                CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
36,936✔
1579

1580
                switch (this._reader.Code)
36,936✔
1581
                {
1582
                        case 350:
1583
                                tmp.HistoryHandle = this._reader.ValueAsHandle;
288✔
1584
                                return true;
288✔
1585
                        default:
1586
                                return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
36,648✔
1587
                }
1588
        }
36,936✔
1589

1590
        private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1591
        {
15,120✔
1592
                CadSplineTemplate tmp = template as CadSplineTemplate;
15,120✔
1593

1594
                XYZ controlPoint;
1595
                XYZ fitPoint;
1596

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

1642
        private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1643
                where T : PdfUnderlayDefinition
1644
        {
3,420✔
1645
                CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,420✔
1646

1647
                switch (this._reader.Code)
3,420✔
1648
                {
1649
                        case 340:
1650
                                tmp.DefinitionHandle = this._reader.ValueAsHandle;
216✔
1651
                                return true;
216✔
1652
                        default:
1653
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,204✔
1654
                }
1655
        }
3,420✔
1656

1657
        private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1658
        {
252,690✔
1659
                CadVertexTemplate tmp = template as CadVertexTemplate;
252,690✔
1660

1661
                switch (this._reader.Code)
252,690✔
1662
                {
1663
                        case 100:
1664
                                switch (this._reader.ValueAsString)
7,344!
1665
                                {
1666
                                        case DxfSubclassMarker.Vertex:
1667
                                                return true;
2,160✔
1668
                                        case DxfSubclassMarker.PolylineVertex:
1669
                                                tmp.SetVertexObject(new Vertex2D());
×
1670
                                                map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1671
                                                return true;
×
1672
                                        case DxfSubclassMarker.Polyline3dVertex:
1673
                                                tmp.SetVertexObject(new Vertex3D());
1,080✔
1674
                                                map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,080✔
1675
                                                return true;
1,080✔
1676
                                        case DxfSubclassMarker.PolyfaceMeshVertex:
1677
                                                tmp.SetVertexObject(new VertexFaceMesh());
1,080✔
1678
                                                map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,080✔
1679
                                                return true;
1,080✔
1680
                                        case DxfSubclassMarker.PolyfaceMeshFace:
1681
                                                tmp.SetVertexObject(new VertexFaceRecord());
432✔
1682
                                                map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
432✔
1683
                                                return true;
432✔
1684
                                        case DxfSubclassMarker.PolygonMeshVertex:
1685
                                                tmp.SetVertexObject(new PolygonMeshVertex());
×
1686
                                                map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1687
                                                return true;
×
1688
                                        default:
1689
                                                return false;
2,592✔
1690
                                }
1691
                        default:
1692
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
245,346✔
1693
                }
1694
        }
252,690✔
1695

1696
        private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1697
        {
72,724✔
1698
                CadViewportTemplate tmp = template as CadViewportTemplate;
72,724✔
1699

1700
                switch (this._reader.Code)
72,724!
1701
                {
1702
                        //Undocumented
1703
                        case 67:
1704
                        case 68:
1705
                                return true;
2,664✔
1706
                        case 69:
1707
                                tmp.ViewportId = this._reader.ValueAsShort;
1,332✔
1708
                                return true;
1,332✔
1709
                        case 331:
1710
                                tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1711
                                return true;
×
1712
                        case 348:
1713
                                tmp.VisualStyleHandle = this._reader.ValueAsHandle;
832✔
1714
                                return true;
832✔
1715
                        default:
1716
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
67,896✔
1717
                }
1718
        }
72,724✔
1719

1720
        private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1721
        {
855,836✔
1722
                string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
855,836✔
1723

1724
                switch (this._reader.Code)
855,836✔
1725
                {
1726
                        default:
1727
                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
855,836✔
1728
                }
1729
        }
855,836✔
1730

1731
        protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1732
        {
36,252✔
1733
                List<ExtendedDataRecord> records = new();
36,252✔
1734
                edata.Add(this._reader.ValueAsString, records);
36,252✔
1735

1736
                this._reader.ReadNext();
36,252✔
1737

1738
                while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
296,377✔
1739
                {
271,630✔
1740
                        if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
271,630✔
1741
                        {
11,505✔
1742
                                this.readExtendedData(edata);
11,505✔
1743
                                break;
11,505✔
1744
                        }
1745

1746
                        ExtendedDataRecord record = null;
260,125✔
1747
                        double x = 0;
260,125✔
1748
                        double y = 0;
260,125✔
1749
                        double z = 0;
260,125✔
1750

1751
                        switch (this._reader.DxfCode)
260,125✔
1752
                        {
1753
                                case DxfCode.ExtendedDataAsciiString:
1754
                                case DxfCode.ExtendedDataRegAppName:
1755
                                        record = new ExtendedDataString(this._reader.ValueAsString);
24,915✔
1756
                                        break;
24,915✔
1757
                                case DxfCode.ExtendedDataControlString:
1758
                                        record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
14,276✔
1759
                                        break;
14,276✔
1760
                                case DxfCode.ExtendedDataLayerName:
1761
                                        if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
252✔
1762
                                        {
238✔
1763
                                                record = new ExtendedDataLayer(layer.Handle);
238✔
1764
                                        }
238✔
1765
                                        else
1766
                                        {
14✔
1767
                                                this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1768
                                        }
14✔
1769
                                        break;
252✔
1770
                                case DxfCode.ExtendedDataBinaryChunk:
1771
                                        record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
72✔
1772
                                        break;
72✔
1773
                                case DxfCode.ExtendedDataHandle:
1774
                                        record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,761✔
1775
                                        break;
2,761✔
1776
                                case DxfCode.ExtendedDataXCoordinate:
1777
                                        x = this._reader.ValueAsDouble;
2,689✔
1778
                                        this._reader.ReadNext();
2,689✔
1779
                                        y = this._reader.ValueAsDouble;
2,689✔
1780
                                        this._reader.ReadNext();
2,689✔
1781
                                        z = this._reader.ValueAsDouble;
2,689✔
1782

1783
                                        record = new ExtendedDataCoordinate(
2,689✔
1784
                                                new XYZ(
2,689✔
1785
                                                        x,
2,689✔
1786
                                                        y,
2,689✔
1787
                                                        z)
2,689✔
1788
                                                );
2,689✔
1789
                                        break;
2,689✔
1790
                                case DxfCode.ExtendedDataWorldXCoordinate:
1791
                                        x = this._reader.ValueAsDouble;
1,296✔
1792
                                        this._reader.ReadNext();
1,296✔
1793
                                        y = this._reader.ValueAsDouble;
1,296✔
1794
                                        this._reader.ReadNext();
1,296✔
1795
                                        z = this._reader.ValueAsDouble;
1,296✔
1796

1797
                                        record = new ExtendedDataWorldCoordinate(
1,296✔
1798
                                                new XYZ(
1,296✔
1799
                                                        x,
1,296✔
1800
                                                        y,
1,296✔
1801
                                                        z)
1,296✔
1802
                                                );
1,296✔
1803
                                        break;
1,296✔
1804
                                case DxfCode.ExtendedDataWorldXDisp:
1805
                                        x = this._reader.ValueAsDouble;
252✔
1806
                                        this._reader.ReadNext();
252✔
1807
                                        y = this._reader.ValueAsDouble;
252✔
1808
                                        this._reader.ReadNext();
252✔
1809
                                        z = this._reader.ValueAsDouble;
252✔
1810

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

1825
                                        record = new ExtendedDataDirection(
252✔
1826
                                                new XYZ(
252✔
1827
                                                        x,
252✔
1828
                                                        y,
252✔
1829
                                                        z)
252✔
1830
                                                );
252✔
1831
                                        break;
252✔
1832
                                case DxfCode.ExtendedDataReal:
1833
                                        record = new ExtendedDataReal(this._reader.ValueAsDouble);
126,479✔
1834
                                        break;
126,479✔
1835
                                case DxfCode.ExtendedDataDist:
1836
                                        record = new ExtendedDataDistance(this._reader.ValueAsDouble);
252✔
1837
                                        break;
252✔
1838
                                case DxfCode.ExtendedDataScale:
1839
                                        record = new ExtendedDataScale(this._reader.ValueAsDouble);
252✔
1840
                                        break;
252✔
1841
                                case DxfCode.ExtendedDataInteger16:
1842
                                        record = new ExtendedDataInteger16(this._reader.ValueAsShort);
73,899✔
1843
                                        break;
73,899✔
1844
                                case DxfCode.ExtendedDataInteger32:
1845
                                        record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
10,174✔
1846
                                        break;
10,174✔
1847
                                default:
1848
                                        this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,304✔
1849
                                        break;
2,304✔
1850
                        }
1851

1852
                        if (record != null)
260,125✔
1853
                        {
257,807✔
1854
                                records.Add(record);
257,807✔
1855
                        }
257,807✔
1856

1857
                        this._reader.ReadNext();
260,125✔
1858
                }
260,125✔
1859
        }
36,252✔
1860

1861
        private void readPattern(HatchPattern pattern, int nlines)
1862
        {
1,296✔
1863
                //Jump 78 code
1864
                this._reader.ReadNext();
1,296✔
1865

1866
                for (int i = 0; i < nlines; i++)
196,560✔
1867
                {
96,984✔
1868
                        HatchPattern.Line line = new HatchPattern.Line();
96,984✔
1869
                        XY basePoint = new XY();
96,984✔
1870
                        XY offset = new XY();
96,984✔
1871

1872
                        bool end = false;
96,984✔
1873
                        HashSet<int> codes = new();
96,984✔
1874

1875
                        while (!end)
680,184✔
1876
                        {
678,888✔
1877
                                if (codes.Contains(this._reader.Code))
678,888✔
1878
                                {
95,688✔
1879
                                        break;
95,688✔
1880
                                }
1881
                                else
1882
                                {
583,200✔
1883
                                        codes.Add(this._reader.Code);
583,200✔
1884
                                }
583,200✔
1885

1886
                                switch (this._reader.Code)
583,200!
1887
                                {
1888
                                        case 53:
1889
                                                line.Angle = this._reader.ValueAsAngle;
96,984✔
1890
                                                break;
96,984✔
1891
                                        case 43:
1892
                                                basePoint.X = this._reader.ValueAsDouble;
96,984✔
1893
                                                break;
96,984✔
1894
                                        case 44:
1895
                                                basePoint.Y = this._reader.ValueAsDouble;
96,984✔
1896
                                                line.BasePoint = basePoint;
96,984✔
1897
                                                break;
96,984✔
1898
                                        case 45:
1899
                                                offset.X = this._reader.ValueAsDouble;
96,984✔
1900
                                                line.Offset = offset;
96,984✔
1901
                                                break;
96,984✔
1902
                                        case 46:
1903
                                                offset.Y = this._reader.ValueAsDouble;
96,984✔
1904
                                                line.Offset = offset;
96,984✔
1905
                                                break;
96,984✔
1906
                                        //Number of dash length items
1907
                                        case 79:
1908
                                                int ndash = this._reader.ValueAsInt;
96,984✔
1909
                                                for (int j = 0; j < ndash; j++)
581,040✔
1910
                                                {
193,536✔
1911
                                                        this._reader.ReadNext();
193,536✔
1912
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
193,536✔
1913
                                                }
193,536✔
1914
                                                break;
96,984✔
1915
                                        case 49:
1916
                                                line.DashLengths.Add(this._reader.ValueAsDouble);
×
1917
                                                break;
×
1918
                                        default:
1919
                                                end = true;
1,296✔
1920
                                                break;
1,296✔
1921
                                }
1922
                                this._reader.ReadNext();
583,200✔
1923
                        }
583,200✔
1924

1925
                        pattern.Lines.Add(line);
96,984✔
1926
                }
96,984✔
1927
        }
1,296✔
1928

1929
        private void readLoops(CadHatchTemplate template, int count)
1930
        {
1,728✔
1931
                if (this._reader.Code == 91)
1,728✔
1932
                        this._reader.ReadNext();
1,728✔
1933

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

1942
                        CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,728✔
1943
                        if (path != null)
1,728✔
1944
                                template.PathTemplates.Add(path);
1,728✔
1945
                }
1,728✔
1946
        }
1,728✔
1947

1948
        private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1949
        {
1,728✔
1950
                CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,728✔
1951
                var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,728✔
1952
                template.Path.Flags = flags;
1,728✔
1953

1954
                if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,728✔
1955
                {
648✔
1956
                        Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
648✔
1957
                        template.Path.Edges.Add(pl);
648✔
1958
                }
648✔
1959
                else
1960
                {
1,080✔
1961
                        this._reader.ReadNext();
1,080✔
1962

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

1969
                        int edges = this._reader.ValueAsInt;
1,080✔
1970
                        this._reader.ReadNext();
1,080✔
1971

1972
                        for (int i = 0; i < edges; i++)
10,800✔
1973
                        {
4,320✔
1974
                                var edge = this.readEdge();
4,320✔
1975
                                if (edge != null)
4,320✔
1976
                                        template.Path.Edges.Add(edge);
4,320✔
1977
                        }
4,320✔
1978
                }
1,080✔
1979

1980
                bool end = false;
1,728✔
1981
                while (!end)
6,696✔
1982
                {
4,968✔
1983
                        switch (this._reader.Code)
4,968✔
1984
                        {
1985
                                //Number of source boundary objects
1986
                                case 97:
1987
                                        break;
1,728✔
1988
                                case 330:
1989
                                        template.Handles.Add(this._reader.ValueAsHandle);
1,512✔
1990
                                        break;
1,512✔
1991
                                default:
1992
                                        end = true;
1,728✔
1993
                                        continue;
1,728✔
1994
                        }
1995

1996
                        this._reader.ReadNext();
3,240✔
1997
                }
3,240✔
1998

1999
                return template;
1,728✔
2000
        }
1,728✔
2001

2002
        private Hatch.BoundaryPath.Polyline readPolylineBoundary()
2003
        {
648✔
2004
                Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
648✔
2005

2006
                this._reader.ReadNext();
648✔
2007

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

2014
                bool end = false;
648✔
2015
                bool hasBulge = false;
648✔
2016
                while (!end)
3,240✔
2017
                {
2,592✔
2018
                        switch (this._reader.Code)
2,592✔
2019
                        {
2020
                                case 72:
2021
                                        hasBulge = this._reader.ValueAsBool;
648✔
2022
                                        break;
648✔
2023
                                case 73:
2024
                                        boundary.IsClosed = this._reader.ValueAsBool;
648✔
2025
                                        break;
648✔
2026
                                case 93:
2027
                                        int nvertices = this._reader.ValueAsInt;
648✔
2028
                                        this._reader.ReadNext();
648✔
2029

2030
                                        for (int i = 0; i < nvertices; i++)
6,480✔
2031
                                        {
2,592✔
2032
                                                double bulge = 0.0;
2,592✔
2033

2034
                                                //10
2035
                                                double x = this._reader.ValueAsDouble;
2,592✔
2036
                                                this._reader.ReadNext();
2,592✔
2037
                                                //20
2038
                                                double y = this._reader.ValueAsDouble;
2,592✔
2039
                                                this._reader.ReadNext();
2,592✔
2040

2041
                                                if (hasBulge)
2,592!
2042
                                                {
×
2043
                                                        //42
2044
                                                        bulge = this._reader.ValueAsDouble;
×
2045
                                                        this._reader.ReadNext();
×
2046
                                                }
×
2047

2048
                                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,592✔
2049
                                        }
2,592✔
2050
                                        continue;
648✔
2051
                                default:
2052
                                        end = true;
648✔
2053
                                        continue;
648✔
2054
                        }
2055

2056
                        this._reader.ReadNext();
1,296✔
2057
                }
1,296✔
2058

2059
                return boundary;
648✔
2060
        }
648✔
2061

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

2070
                Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,320✔
2071
                this._reader.ReadNext();
4,320✔
2072

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

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

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

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

2171
                                XYZ controlPoint = new XYZ();
×
2172
                                XY fitPoint = new XY();
×
2173

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

2233
                                        this._reader.ReadNext();
×
2234
                                }
×
2235
                }
2236

2237
                return null;
×
2238
        }
4,320✔
2239

2240
        private void readDefinedGroups(CadTemplate template)
2241
        {
72,392✔
2242
                this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
72,392✔
2243

2244
                if (xdict.HasValue)
72,392✔
2245
                {
10,457✔
2246
                        template.XDictHandle = xdict;
10,457✔
2247
                }
10,457✔
2248
                template.ReactorsHandles.UnionWith(reactorsHandles);
72,392✔
2249
        }
72,392✔
2250

2251
        private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2252
        {
72,613✔
2253
                xdictHandle = null;
72,613✔
2254
                reactors = new HashSet<ulong>();
72,613✔
2255

2256
                switch (this._reader.ValueAsString)
72,613✔
2257
                {
2258
                        case DxfFileToken.DictionaryToken:
2259
                                this._reader.ReadNext();
10,678✔
2260
                                xdictHandle = this._reader.ValueAsHandle;
10,678✔
2261
                                this._reader.ReadNext();
10,678✔
2262
                                Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,678✔
2263
                                return;
10,678✔
2264
                        case DxfFileToken.ReactorsToken:
2265
                                reactors = this.readReactors();
59,764✔
2266
                                break;
59,764✔
2267
                        case DxfFileToken.BlkRefToken:
2268
                        default:
2269
                                do
2270
                                {
5,638✔
2271
                                        this._reader.ReadNext();
5,638✔
2272
                                }
5,638✔
2273
                                while (this._reader.DxfCode != DxfCode.ControlString);
5,638✔
2274
                                return;
2,171✔
2275
                }
2276
        }
72,613✔
2277

2278
        private HashSet<ulong> readReactors()
2279
        {
59,764✔
2280
                HashSet<ulong> reactors = new();
59,764✔
2281

2282
                this._reader.ReadNext();
59,764✔
2283

2284
                while (this._reader.DxfCode != DxfCode.ControlString)
126,428✔
2285
                {
66,664✔
2286
                        reactors.Add(this._reader.ValueAsHandle);
66,664✔
2287

2288
                        this._reader.ReadNext();
66,664✔
2289
                }
66,664✔
2290

2291
                return reactors;
59,764✔
2292
        }
59,764✔
2293

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

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

2311
        protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2312
        {
4,453,417✔
2313
                try
2314
                {
4,453,417✔
2315
                        //Use this method only if the value is not a link between objects
2316
                        if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,453,417✔
2317
                        {
2,344,626✔
2318
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,344,626✔
2319
                                {
13,723✔
2320
                                        return true;
13,723✔
2321
                                }
2322

2323
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,330,903✔
2324
                                        || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,330,903✔
2325
                                {
17,354✔
2326
                                        return false;
17,354✔
2327
                                }
2328

2329
                                object value = this._reader.Value;
2,313,549✔
2330

2331
                                if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,313,549✔
2332
                                {
26,314✔
2333
                                        value = MathHelper.DegToRad((double)value);
26,314✔
2334
                                }
26,314✔
2335

2336
                                dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,313,549✔
2337

2338
                                return true;
2,313,549✔
2339
                        }
2340
                }
2,108,791✔
2341
                catch (Exception ex)
×
2342
                {
×
2343
                        if (!this._builder.Configuration.Failsafe)
×
2344
                        {
×
2345
                                throw ex;
×
2346
                        }
2347
                        else
2348
                        {
×
2349
                                this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2350
                        }
×
2351
                }
×
2352

2353
                return false;
2,108,791✔
2354
        }
4,453,417✔
2355
}
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