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

DomCR / ACadSharp / 22540418587

01 Mar 2026 09:23AM UTC coverage: 76.557% (+0.003%) from 76.554%
22540418587

Pull #990

github

web-flow
Merge 4f2ea7da4 into 90684cc55
Pull Request #990: issue-989 Refactor DXF polyline boundary

8202 of 11664 branches covered (70.32%)

Branch coverage included in aggregate %.

25 of 29 new or added lines in 1 file covered. (86.21%)

9 existing lines in 1 file now uncovered.

29715 of 37864 relevant lines covered (78.48%)

150233.19 hits per line

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

80.61
/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

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

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

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

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

32
                public abstract void Read();
33

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

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

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

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

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

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

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

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

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

241
                                        this._reader.ReadNext();
×
242

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

582
                private void readCellValue(TableEntity.CellContent content)
583
                {
5,576✔
584
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
5,576!
585
                        {
5,576✔
586
                                this._reader.ReadNext();
5,576✔
587
                        }
5,576✔
588
                        else
589
                        {
×
590
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
591
                        }
592

593
                        while (this._reader.Code != 304
36,448✔
594
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
36,448✔
595
                        {
30,872✔
596
                                switch (this._reader.Code)
30,872!
597
                                {
598
                                        case 1:
599
                                                content.Value.Text = this._reader.ValueAsString;
1,632✔
600
                                                break;
1,632✔
601
                                        case 2:
602
                                                content.Value.Text += this._reader.ValueAsString;
×
603
                                                break;
×
604
                                        case 11:
605
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
136✔
606
                                                break;
136✔
607
                                        case 21:
608
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
136✔
609
                                                break;
136✔
610
                                        case 31:
611
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
136✔
612
                                                break;
136✔
613
                                        case 302:
614
                                                //TODO: Fix this assignation to cell value
615
                                                content.Value.Value = this._reader.ValueAsString;
5,576✔
616
                                                break;
5,576✔
617
                                        case 90:
618
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
5,576✔
619
                                                break;
5,576✔
620
                                        case 91:
621
                                                content.Value.Value = this._reader.ValueAsInt;
136✔
622
                                                break;
136✔
623
                                        case 92:
624
                                                //Extended cell flags (from AutoCAD 2007)
625
                                                break;
136✔
626
                                        case 93:
627
                                                content.Value.Flags = this._reader.ValueAsInt;
5,576✔
628
                                                break;
5,576✔
629
                                        case 94:
630
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
5,576✔
631
                                                break;
5,576✔
632
                                        case 140:
633
                                                content.Value.Value = this._reader.ValueAsDouble;
544✔
634
                                                break;
544✔
635
                                        case 300:
636
                                                content.Value.Format = this._reader.ValueAsString;
5,576✔
637
                                                break;
5,576✔
638
                                        case 310:
639
                                                //Data for proxy entity graphics (multiple lines; 256-character maximum per line)
640
                                                break;
136✔
641
                                        default:
642
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
643
                                                break;
×
644
                                }
645

646
                                this._reader.ReadNext();
30,872✔
647
                        }
30,872✔
648
                }
5,576✔
649

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

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

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

726
                                this._reader.ReadNext();
2,448✔
727
                        }
2,448✔
728
                }
136✔
729

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

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

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

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

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

820
                        XY seedPoint = new XY();
43,656✔
821

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

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

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

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

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

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

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

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

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

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

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

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

978
                        return template;
408✔
979
                }
10,444✔
980

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

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

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

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

1010
                                polyline.Vertices.Seqend = seqend;
10,036✔
1011
                        }
10,036✔
1012

1013
                        return template;
10,036✔
1014
                }
10,036✔
1015

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

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

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

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

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

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

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

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

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

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

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

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

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

1203
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1204
                                        }
27,744✔
1205

1206
                                        Debug.Assert(this._reader.Code == 90);
408✔
1207

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

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

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

1225
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1226
                                        }
53,040✔
1227

1228
                                        Debug.Assert(this._reader.Code == 90);
408✔
1229

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

1238
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1239

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

1246
                                        Debug.Assert(this._reader.Code == 140);
408✔
1247

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

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

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

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

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

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

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

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

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

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

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

1352
                        this._reader.ReadNext();
3,060✔
1353

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

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

1380
                                this._reader.ReadNext();
35,190✔
1381
                        }
35,190✔
1382

1383
                        return root;
3,060✔
1384
                }
3,060✔
1385

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

1391
                        this._reader.ReadNext();
3,060✔
1392

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

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

1428
                                this._reader.ReadNext();
12,240✔
1429
                        }
12,240✔
1430

1431
                        return line;
3,060✔
1432
                }
3,060✔
1433

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

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

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

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

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

1467
                                        this._reader.ReadNext();
408✔
1468

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

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

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

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

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

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

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

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

1542
                        XYZ controlPoint;
1543
                        XYZ fitPoint;
1544

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

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

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

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

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

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

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

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

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

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

1684
                        this._reader.ReadNext();
34,227✔
1685

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1944
                                this._reader.ReadNext();
3,060✔
1945
                        }
3,060✔
1946

1947
                        return template;
1,632✔
1948
                }
1,632✔
1949

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

1954
                        this._reader.ReadNext();
612✔
1955

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

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

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

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

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

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

2004
                                this._reader.ReadNext();
1,224✔
2005
                        }
1,224✔
2006

2007
                        return boundary;
612✔
2008
                }
612✔
2009

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

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

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

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

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

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

2119
                                        XYZ controlPoint = new XYZ();
×
2120
                                        XY fitPoint = new XY();
×
2121

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

2181
                                                this._reader.ReadNext();
×
2182
                                        }
×
2183
                        }
2184

2185
                        return null;
×
2186
                }
4,080✔
2187

2188
                private void readDefinedGroups(CadTemplate template)
2189
                {
67,727✔
2190
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
67,727✔
2191

2192
                        if (xdict.HasValue)
67,727✔
2193
                        {
9,871✔
2194
                                template.XDictHandle = xdict;
9,871✔
2195
                        }
9,871✔
2196
                        template.ReactorsHandles.UnionWith(reactorsHandles);
67,727✔
2197
                }
67,727✔
2198

2199
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2200
                {
67,936✔
2201
                        xdictHandle = null;
67,936✔
2202
                        reactors = new HashSet<ulong>();
67,936✔
2203

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

2226
                private HashSet<ulong> readReactors()
2227
                {
55,805✔
2228
                        HashSet<ulong> reactors = new();
55,805✔
2229

2230
                        this._reader.ReadNext();
55,805✔
2231

2232
                        while (this._reader.DxfCode != DxfCode.ControlString)
118,114✔
2233
                        {
62,309✔
2234
                                reactors.Add(this._reader.ValueAsHandle);
62,309✔
2235

2236
                                this._reader.ReadNext();
62,309✔
2237
                        }
62,309✔
2238

2239
                        return reactors;
55,805✔
2240
                }
55,805✔
2241

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

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

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

2271
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,218,698✔
2272
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,218,698✔
2273
                                        {
14,969✔
2274
                                                return false;
14,969✔
2275
                                        }
2276

2277
                                        object value = this._reader.Value;
2,203,729✔
2278

2279
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,203,729✔
2280
                                        {
24,820✔
2281
                                                value = MathHelper.DegToRad((double)value);
24,820✔
2282
                                        }
24,820✔
2283

2284
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,203,729✔
2285

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

2301
                        return false;
1,960,378✔
2302
                }
4,191,843✔
2303
        }
2304
}
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