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

DomCR / ACadSharp / 23437382283

23 Mar 2026 12:30PM UTC coverage: 76.778% (+0.2%) from 76.575%
23437382283

push

github

web-flow
Merge pull request #1005 from DomCR/issue/999-remove-cellvalue

Issue-999 remove cellvalue

8366 of 11838 branches covered (70.67%)

Branch coverage included in aggregate %.

133 of 161 new or added lines in 12 files covered. (82.61%)

4 existing lines in 2 files now uncovered.

30099 of 38261 relevant lines covered (78.67%)

149526.8 hits per line

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

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

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

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

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

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

33
                public abstract void Read();
34

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

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

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

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

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

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

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

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

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

242
                                        this._reader.ReadNext();
×
243

244
                                        do
245
                                        {
×
246
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
×
247
                                                {
×
248
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
×
249
                                                        if (isExtendedData)
×
250
                                                                continue;
×
251
                                                }
×
252

253
                                                this._reader.ReadNext();
×
254
                                        }
×
255
                                        while (this._reader.DxfCode != DxfCode.Start);
×
256

257
                                        return unknownEntityTemplate;
×
258
                        }
259
                }
145,967✔
260

261
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
262
                        where T : Entity
263
                {
194,785✔
264
                        this._reader.ReadNext();
194,785✔
265

266
                        DxfMap map = DxfMap.Create<T>();
194,785✔
267

268
                        while (this._reader.DxfCode != DxfCode.Start)
2,638,239✔
269
                        {
2,443,454✔
270
                                if (!readEntity(template, map))
2,443,454✔
271
                                {
857,232✔
272
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
857,232✔
273
                                        if (isExtendedData)
857,232✔
274
                                                continue;
13,666✔
275
                                }
843,566✔
276

277
                                if (this.lockPointer)
2,429,788✔
278
                                {
2,992✔
279
                                        this.lockPointer = false;
2,992✔
280
                                        continue;
2,992✔
281
                                }
282

283
                                if (this._reader.DxfCode != DxfCode.Start)
2,426,796✔
284
                                        this._reader.ReadNext();
2,426,322✔
285
                        }
2,426,796✔
286

287
                        return template;
194,785✔
288
                }
194,785✔
289

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

325
                [Obsolete("use lockpointer instead")]
326
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
327
                {
2,900✔
328
                        if (this._reader.DxfCode == DxfCode.Start)
2,900!
329
                        {
×
330
                                return true;
×
331
                        }
332
                        else
333
                        {
2,900✔
334
                                return func.Invoke(template, map);
2,900✔
335
                        }
336
                }
2,900✔
337

338
                protected bool checkEntityEnd(CadEntityTemplate template, DxfMap map, string subclass, Func<CadEntityTemplate, DxfMap, string, bool> func)
339
                {
408✔
340
                        if (this._reader.DxfCode == DxfCode.Start)
408!
341
                        {
408✔
342
                                return true;
408✔
343
                        }
344
                        else
345
                        {
×
346
                                return func.Invoke(template, map, subclass);
×
347
                        }
348
                }
408✔
349

350
                private bool readCircle(CadEntityTemplate template, DxfMap map, string subclass = null)
351
                {
35,945✔
352
                        Circle circle = template.CadObject as Circle;
35,945✔
353

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

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

385
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
386
                {
33,438✔
387
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
33,438✔
388
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
33,438✔
389

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

411
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
412
                {
134,334✔
413
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
134,334!
414
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
134,334✔
415
                        TableEntity table = tmp.CadObject as TableEntity;
134,334✔
416

417
                        switch (this._reader.Code)
134,334!
418
                        {
419
                                case 1:
420
                                        TableEntity.CellContent content;
421
                                        if (tmp.CurrentCell.Content == null)
2,652!
422
                                        {
2,652✔
423
                                                content = new TableEntity.CellContent();
2,652✔
424
                                                content.CadValue.ValueType = CadValueType.String;
2,652✔
425
                                                tmp.CurrentCell.Contents.Add(content);
2,652✔
426
                                        }
2,652✔
427
                                        else
428
                                        {
×
429
                                                content = tmp.CurrentCell.Content;
×
430
                                        }
×
431

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

585
                protected CadValueTemplate readCadValue(CadValue value)
586
                {
9,288✔
587
                        this._reader.ReadNext();
9,288✔
588

589
                        CadValueTemplate template = new(value);
9,288✔
590
                        var map = DxfClassMap.Create(value.GetType(), "CadValue");
9,288✔
591

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

639
                                this._reader.ReadNext();
52,376✔
640
                        }
52,376✔
641

642
                        return template;
9,288✔
643
                }
9,288✔
644

645
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
646
                {
288,982✔
647
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,982✔
648
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
288,982✔
649

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

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

724
                                this._reader.ReadNext();
2,448✔
725
                        }
2,448✔
726
                }
136✔
727

728
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
729
                {
6,120✔
730
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,120✔
731

732
                        switch (this._reader.Code)
6,120✔
733
                        {
734
                                case 3:
735
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
612✔
736
                                        return true;
612✔
737
                                default:
738
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,508✔
739
                        }
740
                }
6,120✔
741

742
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
743
                {
68,476✔
744
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
68,476✔
745

746
                        switch (this._reader.Code)
68,476✔
747
                        {
748
                                case 2:
749
                                        tmp.BlockName = this._reader.ValueAsString;
2,618✔
750
                                        return true;
2,618✔
751
                                case 3:
752
                                        tmp.StyleName = this._reader.ValueAsString;
2,244✔
753
                                        return true;
2,244✔
754
                                case 50:
755
                                        var dim = new DimensionLinear();
238✔
756
                                        tmp.SetDimensionObject(dim);
238✔
757
                                        dim.Rotation = this._reader.ValueAsAngle;
238✔
758
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
238✔
759
                                        return true;
238✔
760
                                case 70:
761
                                        //Flags do not have set
762
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,618✔
763
                                        return true;
2,618✔
764
                                //Measurement - read only
765
                                case 42:
766
                                        return true;
2,244✔
767
                                //Undocumented codes
768
                                case 73:
769
                                case 74:
770
                                case 75:
771
                                case 90:
772
                                case 361:
773
                                        return true;
4,488✔
774
                                case 100:
775
                                        switch (this._reader.ValueAsString)
7,344✔
776
                                        {
777
                                                case DxfSubclassMarker.Dimension:
778
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,244✔
779
                                                case DxfSubclassMarker.AlignedDimension:
780
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,020✔
781
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,020✔
782
                                                        return true;
1,020✔
783
                                                case DxfSubclassMarker.DiametricDimension:
784
                                                        tmp.SetDimensionObject(new DimensionDiameter());
204✔
785
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
204✔
786
                                                        return true;
204✔
787
                                                case DxfSubclassMarker.Angular2LineDimension:
788
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
204✔
789
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
204✔
790
                                                        return true;
204✔
791
                                                case DxfSubclassMarker.Angular3PointDimension:
792
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
204✔
793
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
204✔
794
                                                        return true;
204✔
795
                                                case DxfSubclassMarker.RadialDimension:
796
                                                        tmp.SetDimensionObject(new DimensionRadius());
204✔
797
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
204✔
798
                                                        return true;
204✔
799
                                                case DxfSubclassMarker.OrdinateDimension:
800
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
408✔
801
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
408✔
802
                                                        return true;
408✔
803
                                                case DxfSubclassMarker.LinearDimension:
804
                                                        return true;
612✔
805
                                                default:
806
                                                        return false;
2,244✔
807
                                        }
808
                                default:
809
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
46,682✔
810
                        }
811
                }
68,476✔
812

813
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
814
                {
43,656✔
815
                        CadHatchTemplate tmp = template as CadHatchTemplate;
43,656✔
816
                        Hatch hatch = tmp.CadObject;
43,656✔
817

818
                        XY seedPoint = new XY();
43,656✔
819

820
                        switch (this._reader.Code)
43,656!
821
                        {
822
                                case 2:
823
                                        hatch.Pattern.Name = this._reader.ValueAsString;
1,632✔
824
                                        return true;
1,632✔
825
                                case 10:
826
                                        seedPoint.X = this._reader.ValueAsDouble;
3,264✔
827
                                        hatch.SeedPoints.Add(seedPoint);
3,264✔
828
                                        return true;
3,264✔
829
                                case 20:
830
                                        seedPoint = hatch.SeedPoints.LastOrDefault();
3,264✔
831
                                        seedPoint.Y = this._reader.ValueAsDouble;
3,264✔
832
                                        hatch.SeedPoints[hatch.SeedPoints.Count - 1] = seedPoint;
3,264✔
833
                                        return true;
3,264✔
834
                                case 30:
835
                                        hatch.Elevation = this._reader.ValueAsDouble;
1,632✔
836
                                        return true;
1,632✔
837
                                case 53:
838
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
839
                                        return true;
×
840
                                //TODO: Check hatch undocumented codes
841
                                case 90:
842
                                        return true;
×
843
                                //Information about the hatch pattern
844
                                case 75:
845
                                        return true;
1,632✔
846
                                //Number of pattern definition lines
847
                                case 78:
848
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,224✔
849
                                        this.lockPointer = true;
1,224✔
850
                                        return true;
1,224✔
851
                                //Number of boundary paths (loops)
852
                                case 91:
853
                                        this.readLoops(tmp, this._reader.ValueAsInt);
1,632✔
854
                                        this.lockPointer = true;
1,632✔
855
                                        return true;
1,632✔
856
                                //Number of seed points
857
                                case 98:
858
                                        return true;
1,020✔
859
                                case 450:
860
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
340✔
861
                                        return true;
340✔
862
                                case 451:
863
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
340✔
864
                                        return true;
340✔
865
                                case 452:
866
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
340✔
867
                                        return true;
340✔
868
                                case 453:
869
                                        //Number of colors
870
                                        return true;
340✔
871
                                case 460:
872
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
340✔
873
                                        return true;
340✔
874
                                case 461:
875
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
340✔
876
                                        return true;
340✔
877
                                case 462:
878
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
340✔
879
                                        return true;
340✔
880
                                case 463:
881
                                        GradientColor gradient = new GradientColor();
680✔
882
                                        gradient.Value = this._reader.ValueAsDouble;
680✔
883
                                        hatch.GradientColor.Colors.Add(gradient);
680✔
884
                                        return true;
680✔
885
                                case 63:
886
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
680✔
887
                                        if (colorByIndex != null)
680✔
888
                                        {
680✔
889
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
680✔
890
                                        }
680✔
891
                                        return true;
680✔
892
                                case 421:
893
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
680✔
894
                                        if (colorByRgb != null)
680✔
895
                                        {
680✔
896
                                                //TODO: Hatch assign color by true color
897
                                                //TODO: Is always duplicated by 63, is it needed??
898
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
899
                                        }
680✔
900
                                        return true;
680✔
901
                                case 470:
902
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
340✔
903
                                        return true;
340✔
904
                                default:
905
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
23,596✔
906
                        }
907
                }
43,656✔
908

909
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
910
                {
59,000✔
911
                        CadInsertTemplate tmp = template as CadInsertTemplate;
59,000✔
912

913
                        switch (this._reader.Code)
59,000✔
914
                        {
915
                                case 2:
916
                                        tmp.BlockName = this._reader.ValueAsString;
5,517✔
917
                                        return true;
5,517✔
918
                                case 100:
919
                                        //AcDbEntity
920
                                        //AcDbBlockReference
921
                                        //AcDbMInsertBlock
922
                                        return true;
5,542✔
923
                                case 66:
924
                                        return true;
476✔
925
                                default:
926
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
47,465✔
927
                        }
928
                }
59,000✔
929

930
                private CadEntityTemplate readPolyline()
931
                {
10,444✔
932
                        if (this._builder.Version == ACadVersion.Unknown
10,444!
933
                                || this._builder.Version == ACadVersion.AC1009)
10,444✔
934
                        {
10,036✔
935
                                return this.readLegacyPolyline();
10,036✔
936
                        }
937

938
                        CadPolyLineTemplate template = null;
408✔
939
                        template = new CadPolyLineTemplate();
408✔
940
                        this.readEntityCodes<Entity>(template, this.readPolyline);
408✔
941

942
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
408!
943
                        {
×
944
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
945
                                return null;
×
946
                        }
947

948
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
2,856!
949
                        {
2,448✔
950
                                var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,448✔
951

952
                                if (vertexTemplate.OwnerHandle == null)
2,448!
953
                                {
×
954
                                        vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
955
                                }
×
956

957
                                template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,448✔
958
                                _builder.AddTemplate(vertexTemplate);
2,448✔
959
                        }
2,448✔
960

961
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
816!
962
                        {
408✔
963
                                var seqend = new Seqend();
408✔
964
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
408✔
965
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
408✔
966

967
                                if (seqendTemplate.OwnerHandle == null)
408!
968
                                {
×
969
                                        seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
970
                                }
×
971

972
                                template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
408✔
973
                                _builder.AddTemplate(seqendTemplate);
408✔
974
                        }
408✔
975

976
                        return template;
408✔
977
                }
10,444✔
978

979
                private CadEntityTemplate readLegacyPolyline()
980
                {
10,036✔
981
                        var polyline = new Polyline2D();
10,036✔
982
                        CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,036✔
983
                        this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,036✔
984

985
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
45,896!
986
                        {
35,860✔
987
                                Vertex2D v = new Vertex2D();
35,860✔
988
                                CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
35,860✔
989
                                this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
35,860✔
990

991
                                if (vertexTemplate.Vertex.Handle == 0)
35,860!
992
                                {
×
993
                                        polyline.Vertices.Add(v);
×
994
                                }
×
995
                                else
996
                                {
35,860✔
997
                                        template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
35,860✔
998
                                        this._builder.AddTemplate(vertexTemplate);
35,860✔
999
                                }
35,860✔
1000
                        }
35,860✔
1001

1002
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
20,072!
1003
                        {
10,036✔
1004
                                var seqend = new Seqend();
10,036✔
1005
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,036✔
1006
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,036✔
1007

1008
                                polyline.Vertices.Seqend = seqend;
10,036✔
1009
                        }
10,036✔
1010

1011
                        return template;
10,036✔
1012
                }
10,036✔
1013

1014
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1015
                {
75,008✔
1016
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
75,008✔
1017

1018
                        switch (this._reader.Code)
75,008✔
1019
                        {
1020
                                //DXF: always 0
1021
                                //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)
1022
                                case 10:
1023
                                case 20:
1024
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1025
                                case 66:
1026
                                        return true;
31,332✔
1027
                                case 100:
1028
                                        switch (this._reader.ValueAsString)
816!
1029
                                        {
1030
                                                case DxfSubclassMarker.Polyline:
1031
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
1032
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
1033
                                                        return true;
×
1034
                                                case DxfSubclassMarker.Polyline3d:
1035
                                                        tmp.SetPolyLineObject(new Polyline3D());
204✔
1036
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
204✔
1037
                                                        return true;
204✔
1038
                                                case DxfSubclassMarker.PolyfaceMesh:
1039
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
204✔
1040
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
204✔
1041
                                                        return true;
204✔
1042
                                                case DxfSubclassMarker.PolygonMesh:
1043
                                                        tmp.SetPolyLineObject(new PolygonMesh());
×
1044
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
1045
                                                        return true;
×
1046
                                                default:
1047
                                                        return false;
408✔
1048
                                        }
1049
                                default:
1050
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
42,860✔
1051
                        }
1052
                }
75,008✔
1053

1054
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1055
                {
5,100✔
1056
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
1057

1058
                        switch (this._reader.Code)
5,100✔
1059
                        {
1060
                                case 3:
1061
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
204✔
1062
                                        return true;
204✔
1063
                                case 10:
1064
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
816✔
1065
                                        return true;
816✔
1066
                                case 20:
1067
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1068
                                        y.Y = this._reader.ValueAsDouble;
816✔
1069
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
816✔
1070
                                        return true;
816✔
1071
                                case 30:
1072
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1073
                                        z.Z = this._reader.ValueAsDouble;
816✔
1074
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
816✔
1075
                                        return true;
816✔
1076
                                case 340:
1077
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
204✔
1078
                                        return true;
204✔
1079
                                //Hook line flag - read only
1080
                                case 75:
1081
                                //Vertices count
1082
                                case 76:
1083
                                        return true;
408✔
1084
                                default:
1085
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,836✔
1086
                        }
1087
                }
5,100✔
1088

1089
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1090
                {
87,399✔
1091
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
87,399✔
1092

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

1095
                        switch (this._reader.Code)
87,399!
1096
                        {
1097
                                case 10:
1098
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
20,788✔
1099
                                        return true;
20,788✔
1100
                                case 20:
1101
                                        if (last is not null)
20,788✔
1102
                                        {
20,788✔
1103
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
20,788✔
1104
                                        }
20,788✔
1105
                                        return true;
20,788✔
1106
                                case 40:
1107
                                        if (last is not null)
2,040✔
1108
                                        {
2,040✔
1109
                                                last.StartWidth = this._reader.ValueAsDouble;
2,040✔
1110
                                        }
2,040✔
1111
                                        return true;
2,040✔
1112
                                case 41:
1113
                                        if (last is not null)
2,040✔
1114
                                        {
2,040✔
1115
                                                last.EndWidth = this._reader.ValueAsDouble;
2,040✔
1116
                                        }
2,040✔
1117
                                        return true;
2,040✔
1118
                                case 42:
1119
                                        if (last is not null)
2,784✔
1120
                                        {
2,784✔
1121
                                                last.Bulge = this._reader.ValueAsDouble;
2,784✔
1122
                                        }
2,784✔
1123
                                        return true;
2,784✔
1124
                                case 50:
1125
                                        if (last is not null)
×
1126
                                        {
×
1127
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
1128
                                        }
×
1129
                                        return true;
×
1130
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1131
                                case 66:
1132
                                //Vertex count
1133
                                case 90:
1134
                                        return true;
4,690✔
1135
                                case 91:
1136
                                        if (last is not null)
×
1137
                                        {
×
1138
                                                last.Id = this._reader.ValueAsInt;
×
1139
                                        }
×
1140
                                        return true;
×
1141
                                default:
1142
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,269✔
1143
                        }
1144
                }
87,399✔
1145

1146
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1147
                {
35,904✔
1148
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
1149

1150
                        switch (this._reader.Code)
35,904✔
1151
                        {
1152
                                case 100:
1153
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
1154
                                        {
408✔
1155
                                                tmp.SubclassMarker = true;
408✔
1156
                                        }
408✔
1157
                                        return true;
816✔
1158
                                //Count of sub-entity which property has been overridden
1159
                                case 90:
1160
                                        //TODO: process further entities
1161
                                        return true;
408✔
1162
                                case 92:
1163
                                        if (!tmp.SubclassMarker)
612✔
1164
                                        {
204✔
1165
                                                return false;
204✔
1166
                                        }
1167

1168
                                        int nvertices = this._reader.ValueAsInt;
408✔
1169
                                        for (int i = 0; i < nvertices; i++)
52,224✔
1170
                                        {
25,704✔
1171
                                                this._reader.ReadNext();
25,704✔
1172
                                                double x = this._reader.ValueAsDouble;
25,704✔
1173
                                                this._reader.ReadNext();
25,704✔
1174
                                                double y = this._reader.ValueAsDouble;
25,704✔
1175
                                                this._reader.ReadNext();
25,704✔
1176
                                                double z = this._reader.ValueAsDouble;
25,704✔
1177
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
1178
                                        }
25,704✔
1179
                                        return true;
408✔
1180
                                case 93:
1181
                                        int size = this._reader.ValueAsInt;
408✔
1182
                                        this._reader.ReadNext();
408✔
1183

1184
                                        int indexes = 0;
408✔
1185
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
1186
                                        {
27,744✔
1187
                                                indexes = this._reader.ValueAsInt;
27,744✔
1188
                                                this._reader.ReadNext();
27,744✔
1189

1190
                                                int[] face = new int[indexes];
27,744✔
1191
                                                for (int j = 0; j < indexes; j++)
267,648✔
1192
                                                {
106,080✔
1193
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
1194

1195
                                                        if ((i + j + 2) < size)
106,080✔
1196
                                                        {
105,672✔
1197
                                                                this._reader.ReadNext();
105,672✔
1198
                                                        }
105,672✔
1199
                                                }
106,080✔
1200

1201
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1202
                                        }
27,744✔
1203

1204
                                        Debug.Assert(this._reader.Code == 90);
408✔
1205

1206
                                        return true;
408✔
1207
                                case 94:
1208
                                        int numEdges = this._reader.ValueAsInt;
408✔
1209
                                        this._reader.ReadNext();
408✔
1210
                                        for (int i = 0; i < numEdges; i++)
106,896✔
1211
                                        {
53,040✔
1212
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
1213

1214
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
1215
                                                this._reader.ReadNext();
53,040✔
1216
                                                edge.End = this._reader.ValueAsInt;
53,040✔
1217

1218
                                                if (i < numEdges - 1)
53,040✔
1219
                                                {
52,632✔
1220
                                                        this._reader.ReadNext();
52,632✔
1221
                                                }
52,632✔
1222

1223
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1224
                                        }
53,040✔
1225

1226
                                        Debug.Assert(this._reader.Code == 90);
408✔
1227

1228
                                        return true;
408✔
1229
                                case 95:
1230
                                        this._reader.ReadNext();
408✔
1231
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
1232
                                        {
53,040✔
1233
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
1234
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
1235

1236
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1237

1238
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
1239
                                                {
52,632✔
1240
                                                        this._reader.ReadNext();
52,632✔
1241
                                                }
52,632✔
1242
                                        }
53,040✔
1243

1244
                                        Debug.Assert(this._reader.Code == 140);
408✔
1245

1246
                                        return true;
408✔
1247
                                default:
1248
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1249
                        }
1250
                }
35,904✔
1251

1252
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1253
                {
53,040✔
1254
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1255

1256
                        switch (this._reader.Code)
53,040✔
1257
                        {
1258
                                // 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.
1259
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1260
                                case 2:
1261
                                        tmp.MLineStyleName = this._reader.ValueAsString;
612✔
1262
                                        return true;
612✔
1263
                                case 72:
1264
                                        tmp.NVertex = this._reader.ValueAsInt;
612✔
1265
                                        return true;
612✔
1266
                                case 73:
1267
                                        tmp.NElements = this._reader.ValueAsInt;
612✔
1268
                                        return true;
612✔
1269
                                case 340:
1270
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
612✔
1271
                                        return true;
612✔
1272
                                default:
1273
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
50,592✔
1274
                                        {
8,568✔
1275
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
8,568✔
1276
                                        }
1277
                                        return true;
42,024✔
1278
                        }
1279
                }
53,040✔
1280

1281
                private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1282
                {
144,024✔
1283
                        CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
144,024✔
1284

1285
                        switch (this._reader.Code)
144,024✔
1286
                        {
1287
                                case 270:
1288
                                        //f270 Version
1289
                                        return true;
1,530✔
1290
                                case 300:
1291
                                        this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,060✔
1292
                                        return true;
3,060✔
1293
                                case 340:
1294
                                        tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,060✔
1295
                                        return true;
3,060✔
1296
                                case 341:
1297
                                        tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,060✔
1298
                                        return true;
3,060✔
1299
                                case 343:
1300
                                        tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1301
                                        return true;
3,060✔
1302
                                default:
1303
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
130,254✔
1304
                        }
1305
                }
144,024✔
1306

1307
                private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1308
                {
3,060✔
1309
                        this._reader.ReadNext();
3,060✔
1310

1311
                        var map = DxfClassMap.Create<MultiLeaderObjectContextData>();
3,060✔
1312
                        var contextData = template.CadObject as MultiLeaderObjectContextData;
3,060✔
1313

1314
                        bool end = false;
3,060✔
1315
                        while (this._reader.DxfCode != DxfCode.Start)
171,360✔
1316
                        {
171,360✔
1317
                                switch (this._reader.Code)
171,360✔
1318
                                {
1319
                                        case 301 when this._reader.ValueAsString.Equals("}"):
3,060✔
1320
                                                end = true;
3,060✔
1321
                                                break;
3,060✔
1322
                                        case 302 when this._reader.ValueAsString.Equals("LEADER{"):
3,060✔
1323
                                                contextData.LeaderRoots.Add(this.readMultiLeaderLeader(template));
3,060✔
1324
                                                break;
3,060✔
1325
                                        case 340:
1326
                                                template.TextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1327
                                                break;
3,060✔
1328
                                        default:
1329
                                                if (!this.tryAssignCurrentValue(contextData, map))
162,180!
1330
                                                {
×
1331
                                                        this._builder.Notify($"[AcDbMLeaderObjectContextData] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1332
                                                }
×
1333
                                                break;
162,180✔
1334
                                }
1335

1336
                                if (end)
171,360✔
1337
                                {
3,060✔
1338
                                        break;
3,060✔
1339
                                }
1340

1341
                                this._reader.ReadNext();
168,300✔
1342
                        }
168,300✔
1343
                }
3,060✔
1344

1345
                private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1346
                {
3,060✔
1347
                        MultiLeaderObjectContextData.LeaderRoot root = new();
3,060✔
1348
                        var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,060✔
1349

1350
                        this._reader.ReadNext();
3,060✔
1351

1352
                        bool end = false;
3,060✔
1353
                        while (this._reader.DxfCode != DxfCode.Start)
38,250✔
1354
                        {
38,250✔
1355
                                switch (this._reader.Code)
38,250✔
1356
                                {
1357
                                        case 303 when this._reader.ValueAsString.Equals("}"):
3,060✔
1358
                                                end = true;
3,060✔
1359
                                                break;
3,060✔
1360
                                        case 304 when this._reader.ValueAsString.Equals("LEADER_LINE{"):
3,060✔
1361
                                                var lineTemplate = new LeaderLineTemplate();
3,060✔
1362
                                                template.LeaderLineTemplates.Add(lineTemplate);
3,060✔
1363
                                                root.Lines.Add(this.readMultiLeaderLine(lineTemplate));
3,060✔
1364
                                                break;
3,060✔
1365
                                        default:
1366
                                                if (!this.tryAssignCurrentValue(root, map))
32,130!
1367
                                                {
×
1368
                                                        this._builder.Notify($"[LeaderRoot] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1369
                                                }
×
1370
                                                break;
32,130✔
1371
                                }
1372

1373
                                if (end)
38,250✔
1374
                                {
3,060✔
1375
                                        break;
3,060✔
1376
                                }
1377

1378
                                this._reader.ReadNext();
35,190✔
1379
                        }
35,190✔
1380

1381
                        return root;
3,060✔
1382
                }
3,060✔
1383

1384
                private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1385
                {
3,060✔
1386
                        MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,060✔
1387
                        var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,060✔
1388

1389
                        this._reader.ReadNext();
3,060✔
1390

1391
                        bool end = false;
3,060✔
1392
                        while (this._reader.DxfCode != DxfCode.Start)
15,300✔
1393
                        {
15,300✔
1394
                                switch (this._reader.Code)
15,300✔
1395
                                {
1396
                                        case 10:
1397
                                                XYZ pt = new XYZ(this._reader.ValueAsDouble, 0, 0);
3,060✔
1398
                                                line.Points.Add(pt);
3,060✔
1399
                                                break;
3,060✔
1400
                                        case 20:
1401
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1402
                                                pt.Y = this._reader.ValueAsDouble;
3,060✔
1403
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1404
                                                break;
3,060✔
1405
                                        case 30:
1406
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1407
                                                pt.Z = this._reader.ValueAsDouble;
3,060✔
1408
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1409
                                                break;
3,060✔
1410
                                        case 305 when this._reader.ValueAsString.Equals("}"):
3,060✔
1411
                                                end = true;
3,060✔
1412
                                                break;
3,060✔
1413
                                        default:
1414
                                                if (!this.tryAssignCurrentValue(line, map))
3,060!
1415
                                                {
×
1416
                                                        this._builder.Notify($"[LeaderLine] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1417
                                                }
×
1418
                                                break;
3,060✔
1419
                                }
1420

1421
                                if (end)
15,300✔
1422
                                {
3,060✔
1423
                                        break;
3,060✔
1424
                                }
1425

1426
                                this._reader.ReadNext();
12,240✔
1427
                        }
12,240✔
1428

1429
                        return line;
3,060✔
1430
                }
3,060✔
1431

1432
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1433
                {
2,278✔
1434
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1435

1436
                        switch (this._reader.Code)
2,278✔
1437
                        {
1438
                                case 2:
1439
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1440
                                        return true;
238✔
1441
                                default:
1442
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1443
                        }
1444
                }
2,278✔
1445

1446
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1447
                {
12,036✔
1448
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,036✔
1449
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,036✔
1450

1451
                        switch (this._reader.Code)
12,036✔
1452
                        {
1453
                                case 91:
1454
                                        var nvertices = this._reader.ValueAsInt;
408✔
1455
                                        for (int i = 0; i < nvertices; i++)
3,672✔
1456
                                        {
1,428✔
1457
                                                this._reader.ReadNext();
1,428✔
1458
                                                var x = this._reader.ValueAsDouble;
1,428✔
1459
                                                this._reader.ReadNext();
1,428✔
1460
                                                var y = this._reader.ValueAsDouble;
1,428✔
1461

1462
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,428✔
1463
                                        }
1,428✔
1464

1465
                                        this._reader.ReadNext();
408✔
1466

1467
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
408✔
1468
                                case 340:
1469
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
408✔
1470
                                        return true;
408✔
1471
                                case 360:
1472
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
408✔
1473
                                        return true;
408✔
1474
                                default:
1475
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,812✔
1476
                        }
1477
                }
12,036✔
1478

1479
                private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1480
                {
×
1481
                        CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1482

1483
                        switch (this._reader.Code)
×
1484
                        {
1485
                                //End of data
1486
                                case 1:
1487
                                //Length of binary data
1488
                                case 90:
1489
                                //Undocumented
1490
                                case 73:
1491
                                        return true;
×
1492
                                case 310:
1493
                                        tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
1494
                                        return true;
×
1495
                                default:
1496
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1497
                        }
1498
                }
×
1499

1500
                private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1501
                {
288,776✔
1502
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
288,776✔
1503
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,776✔
1504
                        var geometry = template.CadObject as ModelerGeometry;
288,776✔
1505

1506
                        switch (this._reader.Code)
288,776✔
1507
                        {
1508
                                case 1:
1509
                                case 3:
1510
                                        geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
37,706✔
1511
                                        return true;
37,706✔
1512
                                case 2:
1513
                                        geometry.Guid = new Guid(this._reader.ValueAsString);
204✔
1514
                                        return true;
204✔
1515
                                case 290:
1516
                                        return true;
204✔
1517
                                default:
1518
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
250,662✔
1519
                        }
1520
                }
288,776✔
1521

1522
                private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1523
                {
34,884✔
1524
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
34,884✔
1525

1526
                        switch (this._reader.Code)
34,884✔
1527
                        {
1528
                                case 350:
1529
                                        tmp.HistoryHandle = this._reader.ValueAsHandle;
272✔
1530
                                        return true;
272✔
1531
                                default:
1532
                                        return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
34,612✔
1533
                        }
1534
                }
34,884✔
1535

1536
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1537
                {
14,280✔
1538
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1539

1540
                        XYZ controlPoint;
1541
                        XYZ fitPoint;
1542

1543
                        switch (this._reader.Code)
14,280!
1544
                        {
1545
                                case 10:
1546
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,632✔
1547
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,632✔
1548
                                        return true;
1,632✔
1549
                                case 20:
1550
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1551
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,632✔
1552
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1553
                                        return true;
1,632✔
1554
                                case 30:
1555
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1556
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,632✔
1557
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1558
                                        return true;
1,632✔
1559
                                case 11:
1560
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1561
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1562
                                        return true;
×
1563
                                case 21:
1564
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1565
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1566
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1567
                                        return true;
×
1568
                                case 31:
1569
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1570
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1571
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1572
                                        return true;
×
1573
                                case 40:
1574
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,264✔
1575
                                        return true;
3,264✔
1576
                                case 41:
1577
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1578
                                        return true;
×
1579
                                case 72:
1580
                                case 73:
1581
                                case 74:
1582
                                        return true;
1,224✔
1583
                                default:
1584
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,896✔
1585
                        }
1586
                }
14,280✔
1587

1588
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1589
                        where T : PdfUnderlayDefinition
1590
                {
3,230✔
1591
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,230✔
1592

1593
                        switch (this._reader.Code)
3,230✔
1594
                        {
1595
                                case 340:
1596
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
204✔
1597
                                        return true;
204✔
1598
                                default:
1599
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,026✔
1600
                        }
1601
                }
3,230✔
1602

1603
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1604
                {
238,252✔
1605
                        CadVertexTemplate tmp = template as CadVertexTemplate;
238,252✔
1606

1607
                        switch (this._reader.Code)
238,252✔
1608
                        {
1609
                                case 100:
1610
                                        switch (this._reader.ValueAsString)
6,936!
1611
                                        {
1612
                                                case DxfSubclassMarker.Vertex:
1613
                                                        return true;
2,040✔
1614
                                                case DxfSubclassMarker.PolylineVertex:
1615
                                                        tmp.SetVertexObject(new Vertex2D());
×
1616
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1617
                                                        return true;
×
1618
                                                case DxfSubclassMarker.Polyline3dVertex:
1619
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1620
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1621
                                                        return true;
1,020✔
1622
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1623
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1624
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1625
                                                        return true;
1,020✔
1626
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1627
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1628
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1629
                                                        return true;
408✔
1630
                                                case DxfSubclassMarker.PolygonMeshVertex:
1631
                                                        tmp.SetVertexObject(new PolygonMeshVertex());
×
1632
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1633
                                                        return true;
×
1634
                                                default:
1635
                                                        return false;
2,448✔
1636
                                        }
1637
                                default:
1638
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
231,316✔
1639
                        }
1640
                }
238,252✔
1641

1642
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1643
                {
67,976✔
1644
                        CadViewportTemplate tmp = template as CadViewportTemplate;
67,976✔
1645

1646
                        switch (this._reader.Code)
67,976!
1647
                        {
1648
                                //Undocumented
1649
                                case 67:
1650
                                case 68:
1651
                                        return true;
2,488✔
1652
                                case 69:
1653
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,244✔
1654
                                        return true;
1,244✔
1655
                                case 331:
1656
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1657
                                        return true;
×
1658
                                case 348:
1659
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1660
                                        return true;
784✔
1661
                                default:
1662
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
63,460✔
1663
                        }
1664
                }
67,976✔
1665

1666
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1667
                {
806,016✔
1668
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
806,016✔
1669

1670
                        switch (this._reader.Code)
806,016✔
1671
                        {
1672
                                default:
1673
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
806,016✔
1674
                        }
1675
                }
806,016✔
1676

1677
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1678
                {
34,227✔
1679
                        List<ExtendedDataRecord> records = new();
34,227✔
1680
                        edata.Add(this._reader.ValueAsString, records);
34,227✔
1681

1682
                        this._reader.ReadNext();
34,227✔
1683

1684
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,832✔
1685
                        {
256,472✔
1686
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,472✔
1687
                                {
10,867✔
1688
                                        this.readExtendedData(edata);
10,867✔
1689
                                        break;
10,867✔
1690
                                }
1691

1692
                                ExtendedDataRecord record = null;
245,605✔
1693
                                double x = 0;
245,605✔
1694
                                double y = 0;
245,605✔
1695
                                double z = 0;
245,605✔
1696

1697
                                switch (this._reader.DxfCode)
245,605✔
1698
                                {
1699
                                        case DxfCode.ExtendedDataAsciiString:
1700
                                        case DxfCode.ExtendedDataRegAppName:
1701
                                                record = new ExtendedDataString(this._reader.ValueAsString);
23,506✔
1702
                                                break;
23,506✔
1703
                                        case DxfCode.ExtendedDataControlString:
1704
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,484✔
1705
                                                break;
13,484✔
1706
                                        case DxfCode.ExtendedDataLayerName:
1707
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1708
                                                {
224✔
1709
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1710
                                                }
224✔
1711
                                                else
1712
                                                {
14✔
1713
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1714
                                                }
14✔
1715
                                                break;
238✔
1716
                                        case DxfCode.ExtendedDataBinaryChunk:
1717
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1718
                                                break;
68✔
1719
                                        case DxfCode.ExtendedDataHandle:
1720
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,611✔
1721
                                                break;
2,611✔
1722
                                        case DxfCode.ExtendedDataXCoordinate:
1723
                                                x = this._reader.ValueAsDouble;
2,541✔
1724
                                                this._reader.ReadNext();
2,541✔
1725
                                                y = this._reader.ValueAsDouble;
2,541✔
1726
                                                this._reader.ReadNext();
2,541✔
1727
                                                z = this._reader.ValueAsDouble;
2,541✔
1728

1729
                                                record = new ExtendedDataCoordinate(
2,541✔
1730
                                                        new XYZ(
2,541✔
1731
                                                                x,
2,541✔
1732
                                                                y,
2,541✔
1733
                                                                z)
2,541✔
1734
                                                        );
2,541✔
1735
                                                break;
2,541✔
1736
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1737
                                                x = this._reader.ValueAsDouble;
1,224✔
1738
                                                this._reader.ReadNext();
1,224✔
1739
                                                y = this._reader.ValueAsDouble;
1,224✔
1740
                                                this._reader.ReadNext();
1,224✔
1741
                                                z = this._reader.ValueAsDouble;
1,224✔
1742

1743
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1744
                                                        new XYZ(
1,224✔
1745
                                                                x,
1,224✔
1746
                                                                y,
1,224✔
1747
                                                                z)
1,224✔
1748
                                                        );
1,224✔
1749
                                                break;
1,224✔
1750
                                        case DxfCode.ExtendedDataWorldXDisp:
1751
                                                x = this._reader.ValueAsDouble;
238✔
1752
                                                this._reader.ReadNext();
238✔
1753
                                                y = this._reader.ValueAsDouble;
238✔
1754
                                                this._reader.ReadNext();
238✔
1755
                                                z = this._reader.ValueAsDouble;
238✔
1756

1757
                                                record = new ExtendedDataDisplacement(
238✔
1758
                                                        new XYZ(
238✔
1759
                                                                x,
238✔
1760
                                                                y,
238✔
1761
                                                                z)
238✔
1762
                                                        );
238✔
1763
                                                break;
238✔
1764
                                        case DxfCode.ExtendedDataWorldXDir:
1765
                                                x = this._reader.ValueAsDouble;
238✔
1766
                                                this._reader.ReadNext();
238✔
1767
                                                y = this._reader.ValueAsDouble;
238✔
1768
                                                this._reader.ReadNext();
238✔
1769
                                                z = this._reader.ValueAsDouble;
238✔
1770

1771
                                                record = new ExtendedDataDirection(
238✔
1772
                                                        new XYZ(
238✔
1773
                                                                x,
238✔
1774
                                                                y,
238✔
1775
                                                                z)
238✔
1776
                                                        );
238✔
1777
                                                break;
238✔
1778
                                        case DxfCode.ExtendedDataReal:
1779
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
119,449✔
1780
                                                break;
119,449✔
1781
                                        case DxfCode.ExtendedDataDist:
1782
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1783
                                                break;
238✔
1784
                                        case DxfCode.ExtendedDataScale:
1785
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1786
                                                break;
238✔
1787
                                        case DxfCode.ExtendedDataInteger16:
1788
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
69,751✔
1789
                                                break;
69,751✔
1790
                                        case DxfCode.ExtendedDataInteger32:
1791
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
9,605✔
1792
                                                break;
9,605✔
1793
                                        default:
1794
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1795
                                                break;
2,176✔
1796
                                }
1797

1798
                                if (record != null)
245,605✔
1799
                                {
243,415✔
1800
                                        records.Add(record);
243,415✔
1801
                                }
243,415✔
1802

1803
                                this._reader.ReadNext();
245,605✔
1804
                        }
245,605✔
1805
                }
34,227✔
1806

1807
                private void readPattern(HatchPattern pattern, int nlines)
1808
                {
1,224✔
1809
                        //Jump 78 code
1810
                        this._reader.ReadNext();
1,224✔
1811

1812
                        for (int i = 0; i < nlines; i++)
185,640✔
1813
                        {
91,596✔
1814
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1815
                                XY basePoint = new XY();
91,596✔
1816
                                XY offset = new XY();
91,596✔
1817

1818
                                bool end = false;
91,596✔
1819
                                HashSet<int> codes = new();
91,596✔
1820

1821
                                while (!end)
642,396✔
1822
                                {
641,172✔
1823
                                        if (codes.Contains(this._reader.Code))
641,172✔
1824
                                        {
90,372✔
1825
                                                break;
90,372✔
1826
                                        }
1827
                                        else
1828
                                        {
550,800✔
1829
                                                codes.Add(this._reader.Code);
550,800✔
1830
                                        }
550,800✔
1831

1832
                                        switch (this._reader.Code)
550,800!
1833
                                        {
1834
                                                case 53:
1835
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1836
                                                        break;
91,596✔
1837
                                                case 43:
1838
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1839
                                                        break;
91,596✔
1840
                                                case 44:
1841
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1842
                                                        line.BasePoint = basePoint;
91,596✔
1843
                                                        break;
91,596✔
1844
                                                case 45:
1845
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1846
                                                        line.Offset = offset;
91,596✔
1847
                                                        break;
91,596✔
1848
                                                case 46:
1849
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1850
                                                        line.Offset = offset;
91,596✔
1851
                                                        break;
91,596✔
1852
                                                //Number of dash length items
1853
                                                case 79:
1854
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1855
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1856
                                                        {
182,784✔
1857
                                                                this._reader.ReadNext();
182,784✔
1858
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1859
                                                        }
182,784✔
1860
                                                        break;
91,596✔
1861
                                                case 49:
1862
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1863
                                                        break;
×
1864
                                                default:
1865
                                                        end = true;
1,224✔
1866
                                                        break;
1,224✔
1867
                                        }
1868
                                        this._reader.ReadNext();
550,800✔
1869
                                }
550,800✔
1870

1871
                                pattern.Lines.Add(line);
91,596✔
1872
                        }
91,596✔
1873
                }
1,224✔
1874

1875
                private void readLoops(CadHatchTemplate template, int count)
1876
                {
1,632✔
1877
                        if (this._reader.Code == 91)
1,632✔
1878
                                this._reader.ReadNext();
1,632✔
1879

1880
                        for (int i = 0; i < count; i++)
6,528✔
1881
                        {
1,632✔
1882
                                if (this._reader.Code != 92)
1,632!
1883
                                {
×
1884
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1885
                                        break;
×
1886
                                }
1887

1888
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1889
                                if (path != null)
1,632✔
1890
                                        template.PathTemplates.Add(path);
1,632✔
1891
                        }
1,632✔
1892
                }
1,632✔
1893

1894
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1895
                {
1,632✔
1896
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1897
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1898
                        template.Path.Flags = flags;
1,632✔
1899

1900
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1901
                        {
612✔
1902
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1903
                                template.Path.Edges.Add(pl);
612✔
1904
                        }
612✔
1905
                        else
1906
                        {
1,020✔
1907
                                this._reader.ReadNext();
1,020✔
1908

1909
                                if (this._reader.Code != 93)
1,020!
1910
                                {
×
1911
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1912
                                        return null;
×
1913
                                }
1914

1915
                                int edges = this._reader.ValueAsInt;
1,020✔
1916
                                this._reader.ReadNext();
1,020✔
1917

1918
                                for (int i = 0; i < edges; i++)
10,200✔
1919
                                {
4,080✔
1920
                                        var edge = this.readEdge();
4,080✔
1921
                                        if (edge != null)
4,080✔
1922
                                                template.Path.Edges.Add(edge);
4,080✔
1923
                                }
4,080✔
1924
                        }
1,020✔
1925

1926
                        bool end = false;
1,632✔
1927
                        while (!end)
6,324✔
1928
                        {
4,692✔
1929
                                switch (this._reader.Code)
4,692✔
1930
                                {
1931
                                        //Number of source boundary objects
1932
                                        case 97:
1933
                                                break;
1,632✔
1934
                                        case 330:
1935
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1936
                                                break;
1,428✔
1937
                                        default:
1938
                                                end = true;
1,632✔
1939
                                                continue;
1,632✔
1940
                                }
1941

1942
                                this._reader.ReadNext();
3,060✔
1943
                        }
3,060✔
1944

1945
                        return template;
1,632✔
1946
                }
1,632✔
1947

1948
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1949
                {
612✔
1950
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
1951

1952
                        this._reader.ReadNext();
612✔
1953

1954
                        if (this._reader.Code != 72)
612!
1955
                        {
×
1956
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1957
                                return null;
×
1958
                        }
1959

1960
                        bool end = false;
612✔
1961
                        bool hasBulge = false;
612✔
1962
                        while (!end)
3,060✔
1963
                        {
2,448✔
1964
                                switch (this._reader.Code)
2,448✔
1965
                                {
1966
                                        case 72:
1967
                                                hasBulge = this._reader.ValueAsBool;
612✔
1968
                                                break;
612✔
1969
                                        case 73:
1970
                                                boundary.IsClosed = this._reader.ValueAsBool;
612✔
1971
                                                break;
612✔
1972
                                        case 93:
1973
                                                int nvertices = this._reader.ValueAsInt;
612✔
1974
                                                this._reader.ReadNext();
612✔
1975

1976
                                                for (int i = 0; i < nvertices; i++)
6,120✔
1977
                                                {
2,448✔
1978
                                                        double bulge = 0.0;
2,448✔
1979

1980
                                                        //10
1981
                                                        double x = this._reader.ValueAsDouble;
2,448✔
1982
                                                        this._reader.ReadNext();
2,448✔
1983
                                                        //20
1984
                                                        double y = this._reader.ValueAsDouble;
2,448✔
1985
                                                        this._reader.ReadNext();
2,448✔
1986

1987
                                                        if (hasBulge)
2,448!
1988
                                                        {
×
1989
                                                                //42
1990
                                                                bulge = this._reader.ValueAsDouble;
×
1991
                                                                this._reader.ReadNext();
×
1992
                                                        }
×
1993

1994
                                                        boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
1995
                                                }
2,448✔
1996
                                                continue;
612✔
1997
                                        default:
1998
                                                end = true;
612✔
1999
                                                continue;
612✔
2000
                                }
2001

2002
                                this._reader.ReadNext();
1,224✔
2003
                        }
1,224✔
2004

2005
                        return boundary;
612✔
2006
                }
612✔
2007

2008
                private Hatch.BoundaryPath.Edge readEdge()
2009
                {
4,080✔
2010
                        if (this._reader.Code != 72)
4,080!
2011
                        {
×
2012
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
2013
                                return null;
×
2014
                        }
2015

2016
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
2017
                        this._reader.ReadNext();
4,080✔
2018

2019
                        switch (type)
4,080!
2020
                        {
2021
                                case Hatch.BoundaryPath.EdgeType.Line:
2022
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,080✔
2023
                                        while (true)
20,400✔
2024
                                        {
20,400✔
2025
                                                switch (this._reader.Code)
20,400✔
2026
                                                {
2027
                                                        case 10:
2028
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,080✔
2029
                                                                break;
4,080✔
2030
                                                        case 20:
2031
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,080✔
2032
                                                                break;
4,080✔
2033
                                                        case 11:
2034
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,080✔
2035
                                                                break;
4,080✔
2036
                                                        case 21:
2037
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,080✔
2038
                                                                break;
4,080✔
2039
                                                        default:
2040
                                                                return line;
4,080✔
2041
                                                }
2042

2043
                                                this._reader.ReadNext();
16,320✔
2044
                                        }
16,320✔
2045
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
2046
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
2047
                                        while (true)
×
2048
                                        {
×
2049
                                                switch (this._reader.Code)
×
2050
                                                {
2051
                                                        case 10:
2052
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
2053
                                                                break;
×
2054
                                                        case 20:
2055
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
2056
                                                                break;
×
2057
                                                        case 40:
2058
                                                                arc.Radius = this._reader.ValueAsDouble;
×
2059
                                                                break;
×
2060
                                                        case 50:
2061
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
2062
                                                                break;
×
2063
                                                        case 51:
2064
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
2065
                                                                break;
×
2066
                                                        case 73:
2067
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
2068
                                                                break;
×
2069
                                                        default:
2070
                                                                return arc;
×
2071
                                                }
2072

2073
                                                this._reader.ReadNext();
×
2074
                                        }
×
2075
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
2076
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
2077
                                        while (true)
×
2078
                                        {
×
2079
                                                switch (this._reader.Code)
×
2080
                                                {
2081
                                                        case 10:
2082
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2083
                                                                break;
×
2084
                                                        case 20:
2085
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2086
                                                                break;
×
2087
                                                        case 11:
2088
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2089
                                                                break;
×
2090
                                                        case 21:
2091
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2092
                                                                break;
×
2093
                                                        case 40:
2094
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
2095
                                                                break;
×
2096
                                                        case 50:
2097
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
2098
                                                                break;
×
2099
                                                        case 51:
2100
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
2101
                                                                break;
×
2102
                                                        case 73:
2103
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
2104
                                                                break;
×
2105
                                                        default:
2106
                                                                return ellipse;
×
2107
                                                }
2108

2109
                                                this._reader.ReadNext();
×
2110
                                        }
×
2111
                                case Hatch.BoundaryPath.EdgeType.Spline:
2112
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
2113
                                        int nKnots = 0;
×
2114
                                        int nCtrlPoints = 0;
×
2115
                                        int nFitPoints = 0;
×
2116

2117
                                        XYZ controlPoint = new XYZ();
×
2118
                                        XY fitPoint = new XY();
×
2119

2120
                                        while (true)
×
2121
                                        {
×
2122
                                                switch (this._reader.Code)
×
2123
                                                {
2124
                                                        case 10:
2125
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
2126
                                                                break;
×
2127
                                                        case 20:
2128
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
2129
                                                                spline.ControlPoints.Add(controlPoint);
×
2130
                                                                break;
×
2131
                                                        case 11:
2132
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
2133
                                                                break;
×
2134
                                                        case 21:
2135
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
2136
                                                                spline.FitPoints.Add(fitPoint);
×
2137
                                                                break;
×
2138
                                                        case 42:
2139
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
2140
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
2141
                                                                break;
×
2142
                                                        case 12:
2143
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
2144
                                                                break;
×
2145
                                                        case 22:
2146
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
2147
                                                                break;
×
2148
                                                        case 13:
2149
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
2150
                                                                break;
×
2151
                                                        case 23:
2152
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
2153
                                                                break;
×
2154
                                                        case 94:
2155
                                                                spline.Degree = this._reader.ValueAsInt;
×
2156
                                                                break;
×
2157
                                                        case 73:
2158
                                                                spline.IsRational = this._reader.ValueAsBool;
×
2159
                                                                break;
×
2160
                                                        case 74:
2161
                                                                spline.IsPeriodic = this._reader.ValueAsBool;
×
2162
                                                                break;
×
2163
                                                        case 95:
2164
                                                                nKnots = this._reader.ValueAsInt;
×
2165
                                                                break;
×
2166
                                                        case 96:
2167
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
2168
                                                                break;
×
2169
                                                        case 97:
2170
                                                                nFitPoints = this._reader.ValueAsInt;
×
2171
                                                                break;
×
2172
                                                        case 40:
2173
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
2174
                                                                break;
×
2175
                                                        default:
2176
                                                                return spline;
×
2177
                                                }
2178

2179
                                                this._reader.ReadNext();
×
2180
                                        }
×
2181
                        }
2182

2183
                        return null;
×
2184
                }
4,080✔
2185

2186
                private void readDefinedGroups(CadTemplate template)
2187
                {
68,231✔
2188
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
68,231✔
2189

2190
                        if (xdict.HasValue)
68,231✔
2191
                        {
9,871✔
2192
                                template.XDictHandle = xdict;
9,871✔
2193
                        }
9,871✔
2194
                        template.ReactorsHandles.UnionWith(reactorsHandles);
68,231✔
2195
                }
68,231✔
2196

2197
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2198
                {
68,440✔
2199
                        xdictHandle = null;
68,440✔
2200
                        reactors = new HashSet<ulong>();
68,440✔
2201

2202
                        switch (this._reader.ValueAsString)
68,440✔
2203
                        {
2204
                                case DxfFileToken.DictionaryToken:
2205
                                        this._reader.ReadNext();
10,080✔
2206
                                        xdictHandle = this._reader.ValueAsHandle;
10,080✔
2207
                                        this._reader.ReadNext();
10,080✔
2208
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,080✔
2209
                                        return;
10,080✔
2210
                                case DxfFileToken.ReactorsToken:
2211
                                        reactors = this.readReactors();
56,309✔
2212
                                        break;
56,309✔
2213
                                case DxfFileToken.BlkRefToken:
2214
                                default:
2215
                                        do
2216
                                        {
5,326✔
2217
                                                this._reader.ReadNext();
5,326✔
2218
                                        }
5,326✔
2219
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,326✔
2220
                                        return;
2,051✔
2221
                        }
2222
                }
68,440✔
2223

2224
                private HashSet<ulong> readReactors()
2225
                {
56,309✔
2226
                        HashSet<ulong> reactors = new();
56,309✔
2227

2228
                        this._reader.ReadNext();
56,309✔
2229

2230
                        while (this._reader.DxfCode != DxfCode.ControlString)
119,122✔
2231
                        {
62,813✔
2232
                                reactors.Add(this._reader.ValueAsHandle);
62,813✔
2233

2234
                                this._reader.ReadNext();
62,813✔
2235
                        }
62,813✔
2236

2237
                        return reactors;
56,309✔
2238
                }
56,309✔
2239

2240
                protected bool tryAssignCurrentValue(object cadObject, DxfMap map)
2241
                {
59✔
2242
                        if (string.IsNullOrEmpty(this.currentSubclass))
59✔
2243
                        {
6✔
2244
                                return false;
6✔
2245
                        }
2246

2247
                        if (map.SubClasses.TryGetValue(this.currentSubclass, out var subClass))
53!
2248
                        {
53✔
2249
                                return this.tryAssignCurrentValue(cadObject, subClass);
53✔
2250
                        }
2251
                        else
2252
                        {
×
2253
                                return false;
×
2254
                        }
2255
                }
59✔
2256

2257
                protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2258
                {
4,224,233✔
2259
                        try
2260
                        {
4,224,233✔
2261
                                //Use this method only if the value is not a link between objects
2262
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,224,233✔
2263
                                {
2,227,384✔
2264
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,227,384✔
2265
                                        {
12,767✔
2266
                                                return true;
12,767✔
2267
                                        }
2268

2269
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,214,617✔
2270
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,214,617✔
2271
                                        {
16,352✔
2272
                                                return false;
16,352✔
2273
                                        }
2274

2275
                                        object value = this._reader.Value;
2,198,265✔
2276

2277
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,198,265✔
2278
                                        {
24,820✔
2279
                                                value = MathHelper.DegToRad((double)value);
24,820✔
2280
                                        }
24,820✔
2281

2282
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,198,265✔
2283

2284
                                        return true;
2,198,265✔
2285
                                }
2286
                        }
1,996,849✔
2287
                        catch (Exception ex)
×
2288
                        {
×
2289
                                if (!this._builder.Configuration.Failsafe)
×
2290
                                {
×
2291
                                        throw ex;
×
2292
                                }
2293
                                else
2294
                                {
×
2295
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2296
                                }
×
2297
                        }
×
2298

2299
                        return false;
1,996,849✔
2300
                }
4,224,233✔
2301
        }
2302
}
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