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

DomCR / ACadSharp / 21412530216

27 Jan 2026 08:12PM UTC coverage: 77.048% (+0.01%) from 77.035%
21412530216

Pull #965

github

web-flow
Merge 19698f416 into 49b21ffd0
Pull Request #965: Issue-964 polyline vertices owner

8037 of 11279 branches covered (71.26%)

Branch coverage included in aggregate %.

64 of 80 new or added lines in 5 files covered. (80.0%)

3 existing lines in 1 file now uncovered.

29100 of 36921 relevant lines covered (78.82%)

149149.01 hits per line

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

80.05
/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;
952✔
24
                protected string currentSubclass = null;
952✔
25

26
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
952✔
27
                {
952✔
28
                        this._reader = reader;
952✔
29
                        this._builder = builder;
952✔
30
                }
952✔
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,243✔
36
                        name = null;
2,243✔
37
                        handle = 0;
2,243✔
38
                        ownerHandle = null;
2,243✔
39
                        xdictHandle = null;
2,243✔
40
                        reactors = new HashSet<ulong>();
2,243✔
41

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

46
                        //Loop until the common data end
47
                        while (this._reader.DxfCode != DxfCode.Start
8,907✔
48
                                        && this._reader.DxfCode != DxfCode.Subclass)
8,907✔
49
                        {
6,664✔
50
                                switch (this._reader.Code)
6,664!
51
                                {
52
                                        //Table name
53
                                        case 2:
54
                                                name = this._reader.ValueAsString;
2,243✔
55
                                                break;
2,243✔
56
                                        //Handle
57
                                        case 5:
58
                                        case 105:
59
                                                handle = this._reader.ValueAsHandle;
1,971✔
60
                                                break;
1,971✔
61
                                        //Start of application - defined group
62
                                        case 102:
63
                                                this.readDefinedGroups(out xdictHandle, out reactors);
207✔
64
                                                break;
207✔
65
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
66
                                        case 330:
67
                                                ownerHandle = this._reader.ValueAsHandle;
1,971✔
68
                                                break;
1,971✔
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,664✔
79
                        }
6,664✔
80
                }
2,243✔
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
                {
791,421✔
116
                        isExtendedData = false;
791,421✔
117

118
                        switch (this._reader.Code)
791,421✔
119
                        {
120
                                //Handle
121
                                case 5:
122
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
297,040✔
123
                                        break;
297,040✔
124
                                //Check with mapper
125
                                case 100:
126
                                        this.currentSubclass = this._reader.ValueAsString;
206,282✔
127
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
206,282!
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,282✔
132
                                //Start of application - defined group
133
                                case 102:
134
                                        this.readDefinedGroups(template);
66,930✔
135
                                        break;
66,930✔
136
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
137
                                case 330:
138
                                        template.OwnerHandle = this._reader.ValueAsHandle;
167,067✔
139
                                        break;
167,067✔
140
                                case 1001:
141
                                        isExtendedData = true;
23,132✔
142
                                        this.readExtendedData(template.EDataTemplateByAppName);
23,132✔
143
                                        break;
23,132✔
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
                }
791,421✔
149

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

240
                                        this._reader.ReadNext();
×
241

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

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

255
                                        return unknownEntityTemplate;
×
256
                        }
257
                }
145,935✔
258

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

264
                        DxfMap map = DxfMap.Create<T>();
194,753✔
265

266
                        while (this._reader.DxfCode != DxfCode.Start)
2,640,285✔
267
                        {
2,445,532✔
268
                                if (!readEntity(template, map))
2,445,532✔
269
                                {
857,040✔
270
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
857,040✔
271
                                        if (isExtendedData)
857,040✔
272
                                                continue;
13,641✔
273
                                }
843,399✔
274

275
                                if (this.lockPointer)
2,431,891✔
276
                                {
2,856✔
277
                                        this.lockPointer = false;
2,856✔
278
                                        continue;
2,856✔
279
                                }
280

281
                                if (this._reader.DxfCode != DxfCode.Start)
2,429,035✔
282
                                        this._reader.ReadNext();
2,428,561✔
283
                        }
2,429,035✔
284

285
                        return template;
194,753✔
286
                }
194,753✔
287

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

654
                        switch (this._reader.Code)
291,430✔
655
                        {
656
                                //TODO: Implement multiline text def codes
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 = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
662
                                        mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
663
                                        return true;
×
664
                                case 70:
665
                                case 74:
666
                                case 101:
667
                                        return true;
408✔
668
                                case 7:
669
                                        tmp.StyleName = this._reader.ValueAsString;
2,856✔
670
                                        return true;
2,856✔
671
                                default:
672
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
278,476✔
673
                        }
674
                }
291,430✔
675

676
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
677
                {
6,120✔
678
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,120✔
679

680
                        switch (this._reader.Code)
6,120✔
681
                        {
682
                                case 3:
683
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
612✔
684
                                        return true;
612✔
685
                                default:
686
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,508✔
687
                        }
688
                }
6,120✔
689

690
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
691
                {
68,476✔
692
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
68,476✔
693

694
                        switch (this._reader.Code)
68,476✔
695
                        {
696
                                case 2:
697
                                        tmp.BlockName = this._reader.ValueAsString;
2,618✔
698
                                        return true;
2,618✔
699
                                case 3:
700
                                        tmp.StyleName = this._reader.ValueAsString;
2,244✔
701
                                        return true;
2,244✔
702
                                case 50:
703
                                        var dim = new DimensionLinear();
238✔
704
                                        tmp.SetDimensionObject(dim);
238✔
705
                                        dim.Rotation = this._reader.ValueAsAngle;
238✔
706
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
238✔
707
                                        return true;
238✔
708
                                case 70:
709
                                        //Flags do not have set
710
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,618✔
711
                                        return true;
2,618✔
712
                                //Measurement - read only
713
                                case 42:
714
                                        return true;
2,244✔
715
                                //Undocumented codes
716
                                case 73:
717
                                case 74:
718
                                case 75:
719
                                case 90:
720
                                case 361:
721
                                        return true;
4,488✔
722
                                case 100:
723
                                        switch (this._reader.ValueAsString)
7,344✔
724
                                        {
725
                                                case DxfSubclassMarker.Dimension:
726
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,244✔
727
                                                case DxfSubclassMarker.AlignedDimension:
728
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,020✔
729
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,020✔
730
                                                        return true;
1,020✔
731
                                                case DxfSubclassMarker.DiametricDimension:
732
                                                        tmp.SetDimensionObject(new DimensionDiameter());
204✔
733
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
204✔
734
                                                        return true;
204✔
735
                                                case DxfSubclassMarker.Angular2LineDimension:
736
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
204✔
737
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
204✔
738
                                                        return true;
204✔
739
                                                case DxfSubclassMarker.Angular3PointDimension:
740
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
204✔
741
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
204✔
742
                                                        return true;
204✔
743
                                                case DxfSubclassMarker.RadialDimension:
744
                                                        tmp.SetDimensionObject(new DimensionRadius());
204✔
745
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
204✔
746
                                                        return true;
204✔
747
                                                case DxfSubclassMarker.OrdinateDimension:
748
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
408✔
749
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
408✔
750
                                                        return true;
408✔
751
                                                case DxfSubclassMarker.LinearDimension:
752
                                                        return true;
612✔
753
                                                default:
754
                                                        return false;
2,244✔
755
                                        }
756
                                default:
757
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
46,682✔
758
                        }
759
                }
68,476✔
760

761
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
762
                {
43,656✔
763
                        CadHatchTemplate tmp = template as CadHatchTemplate;
43,656✔
764
                        Hatch hatch = tmp.CadObject;
43,656✔
765

766
                        XY seedPoint = new XY();
43,656✔
767

768
                        switch (this._reader.Code)
43,656!
769
                        {
770
                                case 2:
771
                                        hatch.Pattern.Name = this._reader.ValueAsString;
1,632✔
772
                                        return true;
1,632✔
773
                                case 10:
774
                                        seedPoint.X = this._reader.ValueAsDouble;
3,264✔
775
                                        hatch.SeedPoints.Add(seedPoint);
3,264✔
776
                                        return true;
3,264✔
777
                                case 20:
778
                                        seedPoint = hatch.SeedPoints.LastOrDefault();
3,264✔
779
                                        seedPoint.Y = this._reader.ValueAsDouble;
3,264✔
780
                                        hatch.SeedPoints[hatch.SeedPoints.Count - 1] = seedPoint;
3,264✔
781
                                        return true;
3,264✔
782
                                case 30:
783
                                        hatch.Elevation = this._reader.ValueAsDouble;
1,632✔
784
                                        return true;
1,632✔
785
                                case 53:
786
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
787
                                        return true;
×
788
                                //TODO: Check hatch undocumented codes
789
                                case 90:
790
                                        return true;
×
791
                                //Information about the hatch pattern
792
                                case 75:
793
                                        return true;
1,632✔
794
                                //Number of pattern definition lines
795
                                case 78:
796
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,224✔
797
                                        this.lockPointer = true;
1,224✔
798
                                        return true;
1,224✔
799
                                //Number of boundary paths (loops)
800
                                case 91:
801
                                        this.readLoops(tmp, this._reader.ValueAsInt);
1,632✔
802
                                        this.lockPointer = true;
1,632✔
803
                                        return true;
1,632✔
804
                                //Number of seed points
805
                                case 98:
806
                                        return true;
1,020✔
807
                                case 450:
808
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
340✔
809
                                        return true;
340✔
810
                                case 451:
811
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
340✔
812
                                        return true;
340✔
813
                                case 452:
814
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
340✔
815
                                        return true;
340✔
816
                                case 453:
817
                                        //Number of colors
818
                                        return true;
340✔
819
                                case 460:
820
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
340✔
821
                                        return true;
340✔
822
                                case 461:
823
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
340✔
824
                                        return true;
340✔
825
                                case 462:
826
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
340✔
827
                                        return true;
340✔
828
                                case 463:
829
                                        GradientColor gradient = new GradientColor();
680✔
830
                                        gradient.Value = this._reader.ValueAsDouble;
680✔
831
                                        hatch.GradientColor.Colors.Add(gradient);
680✔
832
                                        return true;
680✔
833
                                case 63:
834
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
680✔
835
                                        if (colorByIndex != null)
680✔
836
                                        {
680✔
837
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
680✔
838
                                        }
680✔
839
                                        return true;
680✔
840
                                case 421:
841
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
680✔
842
                                        if (colorByRgb != null)
680✔
843
                                        {
680✔
844
                                                //TODO: Hatch assign color by true color
845
                                                //TODO: Is always duplicated by 63, is it needed??
846
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
847
                                        }
680✔
848
                                        return true;
680✔
849
                                case 470:
850
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
340✔
851
                                        return true;
340✔
852
                                default:
853
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
23,596✔
854
                        }
855
                }
43,656✔
856

857
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
858
                {
58,932✔
859
                        CadInsertTemplate tmp = template as CadInsertTemplate;
58,932✔
860

861
                        switch (this._reader.Code)
58,932✔
862
                        {
863
                                case 2:
864
                                        tmp.BlockName = this._reader.ValueAsString;
5,510✔
865
                                        return true;
5,510✔
866
                                case 100:
867
                                        //AcDbEntity
868
                                        //AcDbBlockReference
869
                                        //AcDbMInsertBlock
870
                                        return true;
5,528✔
871
                                case 66:
872
                                        return true;
476✔
873
                                default:
874
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
47,418✔
875
                        }
876
                }
58,932✔
877

878
                private CadEntityTemplate readPolyline()
879
                {
10,444✔
880
                        if (this._builder.Version == ACadVersion.Unknown
10,444!
881
                                || this._builder.Version == ACadVersion.AC1009)
10,444✔
882
                        {
10,036✔
883
                                return this.readLegacyPolyline();
10,036✔
884
                        }
885

886
                        CadPolyLineTemplate template = null;
408✔
887
                        template = new CadPolyLineTemplate();
408✔
888
                        this.readEntityCodes<Entity>(template, this.readPolyline);
408✔
889

890
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
408!
NEW
891
                        {
×
NEW
892
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
NEW
893
                                return null;
×
894
                        }
895

896
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
2,856!
897
                        {
2,448✔
898
                                var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,448✔
899

900
                                if (vertexTemplate.OwnerHandle == null)
2,448!
UNCOV
901
                                {
×
NEW
902
                                        vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
NEW
903
                                }
×
904

905
                                template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,448✔
906
                                _builder.AddTemplate(vertexTemplate);
2,448✔
907
                        }
2,448✔
908

909
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
816!
910
                        {
408✔
911
                                var seqend = new Seqend();
408✔
912
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
408✔
913
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
408✔
914

915
                                if (seqendTemplate.OwnerHandle == null)
408!
NEW
916
                                {
×
NEW
917
                                        seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
UNCOV
918
                                }
×
919

920
                                template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
408✔
921
                                _builder.AddTemplate(seqendTemplate);
408✔
922
                        }
408✔
923

924
                        return template;
408✔
925
                }
10,444✔
926

927
                private CadEntityTemplate readLegacyPolyline()
928
                {
10,036✔
929
                        var polyline = new Polyline2D();
10,036✔
930
                        CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,036✔
931
                        this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,036✔
932

933
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
45,896!
934
                        {
35,860✔
935
                                Vertex2D v = new Vertex2D();
35,860✔
936
                                CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
35,860✔
937
                                this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
35,860✔
938

939
                                if (vertexTemplate.Vertex.Handle == 0)
35,860!
NEW
940
                                {
×
NEW
941
                                        polyline.Vertices.Add(v);
×
NEW
942
                                }
×
943
                                else
944
                                {
35,860✔
945
                                        template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
35,860✔
946
                                        this._builder.AddTemplate(vertexTemplate);
35,860✔
947
                                }
35,860✔
948
                        }
35,860✔
949

950
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
20,072!
951
                        {
10,036✔
952
                                var seqend = new Seqend();
10,036✔
953
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,036✔
954
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,036✔
955

956
                                polyline.Vertices.Seqend = seqend;
10,036✔
957
                        }
10,036✔
958

959
                        return template;
10,036✔
960
                }
10,036✔
961

962
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
963
                {
75,008✔
964
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
75,008✔
965

966
                        switch (this._reader.Code)
75,008✔
967
                        {
968
                                //DXF: always 0
969
                                //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)
970
                                case 10:
971
                                case 20:
972
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
973
                                case 66:
974
                                        return true;
31,332✔
975
                                case 100:
976
                                        switch (this._reader.ValueAsString)
816!
977
                                        {
978
                                                case DxfSubclassMarker.Polyline:
979
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
980
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
981
                                                        return true;
×
982
                                                case DxfSubclassMarker.Polyline3d:
983
                                                        tmp.SetPolyLineObject(new Polyline3D());
204✔
984
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
204✔
985
                                                        return true;
204✔
986
                                                case DxfSubclassMarker.PolyfaceMesh:
987
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
204✔
988
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
204✔
989
                                                        return true;
204✔
990
                                                case DxfSubclassMarker.PolygonMesh:
991
                                                        tmp.SetPolyLineObject(new PolygonMesh());
×
992
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
993
                                                        return true;
×
994
                                                default:
995
                                                        return false;
408✔
996
                                        }
997
                                default:
998
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
42,860✔
999
                        }
1000
                }
75,008✔
1001

1002
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1003
                {
5,100✔
1004
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
1005

1006
                        switch (this._reader.Code)
5,100✔
1007
                        {
1008
                                case 3:
1009
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
204✔
1010
                                        return true;
204✔
1011
                                case 10:
1012
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
816✔
1013
                                        return true;
816✔
1014
                                case 20:
1015
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1016
                                        y.Y = this._reader.ValueAsDouble;
816✔
1017
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
816✔
1018
                                        return true;
816✔
1019
                                case 30:
1020
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
1021
                                        z.Z = this._reader.ValueAsDouble;
816✔
1022
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
816✔
1023
                                        return true;
816✔
1024
                                case 340:
1025
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
204✔
1026
                                        return true;
204✔
1027
                                //Hook line flag - read only
1028
                                case 75:
1029
                                //Vertices count
1030
                                case 76:
1031
                                        return true;
408✔
1032
                                default:
1033
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,836✔
1034
                        }
1035
                }
5,100✔
1036

1037
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1038
                {
87,399✔
1039
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
87,399✔
1040

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

1043
                        switch (this._reader.Code)
87,399!
1044
                        {
1045
                                case 10:
1046
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
20,788✔
1047
                                        return true;
20,788✔
1048
                                case 20:
1049
                                        if (last is not null)
20,788✔
1050
                                        {
20,788✔
1051
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
20,788✔
1052
                                        }
20,788✔
1053
                                        return true;
20,788✔
1054
                                case 40:
1055
                                        if (last is not null)
2,040✔
1056
                                        {
2,040✔
1057
                                                last.StartWidth = this._reader.ValueAsDouble;
2,040✔
1058
                                        }
2,040✔
1059
                                        return true;
2,040✔
1060
                                case 41:
1061
                                        if (last is not null)
2,040✔
1062
                                        {
2,040✔
1063
                                                last.EndWidth = this._reader.ValueAsDouble;
2,040✔
1064
                                        }
2,040✔
1065
                                        return true;
2,040✔
1066
                                case 42:
1067
                                        if (last is not null)
2,784✔
1068
                                        {
2,784✔
1069
                                                last.Bulge = this._reader.ValueAsDouble;
2,784✔
1070
                                        }
2,784✔
1071
                                        return true;
2,784✔
1072
                                case 50:
1073
                                        if (last is not null)
×
1074
                                        {
×
1075
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
1076
                                        }
×
1077
                                        return true;
×
1078
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1079
                                case 66:
1080
                                //Vertex count
1081
                                case 90:
1082
                                        return true;
4,690✔
1083
                                case 91:
1084
                                        if (last is not null)
×
1085
                                        {
×
1086
                                                last.Id = this._reader.ValueAsInt;
×
1087
                                        }
×
1088
                                        return true;
×
1089
                                default:
1090
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,269✔
1091
                        }
1092
                }
87,399✔
1093

1094
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1095
                {
35,904✔
1096
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
1097

1098
                        switch (this._reader.Code)
35,904✔
1099
                        {
1100
                                case 100:
1101
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
1102
                                        {
408✔
1103
                                                tmp.SubclassMarker = true;
408✔
1104
                                        }
408✔
1105
                                        return true;
816✔
1106
                                //Count of sub-entity which property has been overridden
1107
                                case 90:
1108
                                        //TODO: process further entities
1109
                                        return true;
408✔
1110
                                case 92:
1111
                                        if (!tmp.SubclassMarker)
612✔
1112
                                        {
204✔
1113
                                                return false;
204✔
1114
                                        }
1115

1116
                                        int nvertices = this._reader.ValueAsInt;
408✔
1117
                                        for (int i = 0; i < nvertices; i++)
52,224✔
1118
                                        {
25,704✔
1119
                                                this._reader.ReadNext();
25,704✔
1120
                                                double x = this._reader.ValueAsDouble;
25,704✔
1121
                                                this._reader.ReadNext();
25,704✔
1122
                                                double y = this._reader.ValueAsDouble;
25,704✔
1123
                                                this._reader.ReadNext();
25,704✔
1124
                                                double z = this._reader.ValueAsDouble;
25,704✔
1125
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
1126
                                        }
25,704✔
1127
                                        return true;
408✔
1128
                                case 93:
1129
                                        int size = this._reader.ValueAsInt;
408✔
1130
                                        this._reader.ReadNext();
408✔
1131

1132
                                        int indexes = 0;
408✔
1133
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
1134
                                        {
27,744✔
1135
                                                indexes = this._reader.ValueAsInt;
27,744✔
1136
                                                this._reader.ReadNext();
27,744✔
1137

1138
                                                int[] face = new int[indexes];
27,744✔
1139
                                                for (int j = 0; j < indexes; j++)
267,648✔
1140
                                                {
106,080✔
1141
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
1142

1143
                                                        if ((i + j + 2) < size)
106,080✔
1144
                                                        {
105,672✔
1145
                                                                this._reader.ReadNext();
105,672✔
1146
                                                        }
105,672✔
1147
                                                }
106,080✔
1148

1149
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1150
                                        }
27,744✔
1151

1152
                                        Debug.Assert(this._reader.Code == 90);
408✔
1153

1154
                                        return true;
408✔
1155
                                case 94:
1156
                                        int numEdges = this._reader.ValueAsInt;
408✔
1157
                                        this._reader.ReadNext();
408✔
1158
                                        for (int i = 0; i < numEdges; i++)
106,896✔
1159
                                        {
53,040✔
1160
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
1161

1162
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
1163
                                                this._reader.ReadNext();
53,040✔
1164
                                                edge.End = this._reader.ValueAsInt;
53,040✔
1165

1166
                                                if (i < numEdges - 1)
53,040✔
1167
                                                {
52,632✔
1168
                                                        this._reader.ReadNext();
52,632✔
1169
                                                }
52,632✔
1170

1171
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1172
                                        }
53,040✔
1173

1174
                                        Debug.Assert(this._reader.Code == 90);
408✔
1175

1176
                                        return true;
408✔
1177
                                case 95:
1178
                                        this._reader.ReadNext();
408✔
1179
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
1180
                                        {
53,040✔
1181
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
1182
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
1183

1184
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1185

1186
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
1187
                                                {
52,632✔
1188
                                                        this._reader.ReadNext();
52,632✔
1189
                                                }
52,632✔
1190
                                        }
53,040✔
1191

1192
                                        Debug.Assert(this._reader.Code == 140);
408✔
1193

1194
                                        return true;
408✔
1195
                                default:
1196
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1197
                        }
1198
                }
35,904✔
1199

1200
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1201
                {
53,040✔
1202
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1203

1204
                        switch (this._reader.Code)
53,040✔
1205
                        {
1206
                                // 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.
1207
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1208
                                case 2:
1209
                                        tmp.MLineStyleName = this._reader.ValueAsString;
612✔
1210
                                        return true;
612✔
1211
                                case 72:
1212
                                        tmp.NVertex = this._reader.ValueAsInt;
612✔
1213
                                        return true;
612✔
1214
                                case 73:
1215
                                        tmp.NElements = this._reader.ValueAsInt;
612✔
1216
                                        return true;
612✔
1217
                                case 340:
1218
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
612✔
1219
                                        return true;
612✔
1220
                                default:
1221
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
50,592✔
1222
                                        {
8,568✔
1223
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
8,568✔
1224
                                        }
1225
                                        return true;
42,024✔
1226
                        }
1227
                }
53,040✔
1228

1229
                private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1230
                {
144,024✔
1231
                        CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
144,024✔
1232

1233
                        switch (this._reader.Code)
144,024✔
1234
                        {
1235
                                case 270:
1236
                                        //f270 Version
1237
                                        return true;
1,530✔
1238
                                case 300:
1239
                                        this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,060✔
1240
                                        return true;
3,060✔
1241
                                case 340:
1242
                                        tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,060✔
1243
                                        return true;
3,060✔
1244
                                case 341:
1245
                                        tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,060✔
1246
                                        return true;
3,060✔
1247
                                case 343:
1248
                                        tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1249
                                        return true;
3,060✔
1250
                                default:
1251
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
130,254✔
1252
                        }
1253
                }
144,024✔
1254

1255
                private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1256
                {
3,060✔
1257
                        this._reader.ReadNext();
3,060✔
1258

1259
                        DxfMap map = DxfMap.Create<MultiLeaderObjectContextData>();
3,060✔
1260
                        var contextData = template.CadObject as MultiLeaderObjectContextData;
3,060✔
1261

1262
                        bool end = false;
3,060✔
1263
                        while (this._reader.DxfCode != DxfCode.Start)
171,360✔
1264
                        {
171,360✔
1265
                                switch (this._reader.Code)
171,360✔
1266
                                {
1267
                                        case 301 when this._reader.ValueAsString.Equals("}"):
3,060✔
1268
                                                end = true;
3,060✔
1269
                                                break;
3,060✔
1270
                                        case 302 when this._reader.ValueAsString.Equals("LEADER{"):
3,060✔
1271
                                                contextData.LeaderRoots.Add(this.readMultiLeaderLeader(template));
3,060✔
1272
                                                break;
3,060✔
1273
                                        case 340:
1274
                                                template.TextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1275
                                                break;
3,060✔
1276
                                        default:
1277
                                                if (!this.tryAssignCurrentValue(contextData, map.SubClasses[contextData.SubclassMarker]))
162,180!
1278
                                                {
×
1279
                                                        this._builder.Notify($"[AcDbMLeaderObjectContextData] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1280
                                                }
×
1281
                                                break;
162,180✔
1282
                                }
1283

1284
                                if (end)
171,360✔
1285
                                {
3,060✔
1286
                                        break;
3,060✔
1287
                                }
1288

1289
                                this._reader.ReadNext();
168,300✔
1290
                        }
168,300✔
1291
                }
3,060✔
1292

1293
                private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1294
                {
3,060✔
1295
                        MultiLeaderObjectContextData.LeaderRoot root = new();
3,060✔
1296
                        var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,060✔
1297

1298
                        this._reader.ReadNext();
3,060✔
1299

1300
                        bool end = false;
3,060✔
1301
                        while (this._reader.DxfCode != DxfCode.Start)
38,250✔
1302
                        {
38,250✔
1303
                                switch (this._reader.Code)
38,250✔
1304
                                {
1305
                                        case 303 when this._reader.ValueAsString.Equals("}"):
3,060✔
1306
                                                end = true;
3,060✔
1307
                                                break;
3,060✔
1308
                                        case 304 when this._reader.ValueAsString.Equals("LEADER_LINE{"):
3,060✔
1309
                                                var lineTemplate = new LeaderLineTemplate();
3,060✔
1310
                                                template.LeaderLineTemplates.Add(lineTemplate);
3,060✔
1311
                                                root.Lines.Add(this.readMultiLeaderLine(lineTemplate));
3,060✔
1312
                                                break;
3,060✔
1313
                                        default:
1314
                                                if (!this.tryAssignCurrentValue(root, map))
32,130!
1315
                                                {
×
1316
                                                        this._builder.Notify($"[LeaderRoot] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1317
                                                }
×
1318
                                                break;
32,130✔
1319
                                }
1320

1321
                                if (end)
38,250✔
1322
                                {
3,060✔
1323
                                        break;
3,060✔
1324
                                }
1325

1326
                                this._reader.ReadNext();
35,190✔
1327
                        }
35,190✔
1328

1329
                        return root;
3,060✔
1330
                }
3,060✔
1331

1332
                private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1333
                {
3,060✔
1334
                        MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,060✔
1335
                        var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,060✔
1336

1337
                        this._reader.ReadNext();
3,060✔
1338

1339
                        bool end = false;
3,060✔
1340
                        while (this._reader.DxfCode != DxfCode.Start)
15,300✔
1341
                        {
15,300✔
1342
                                switch (this._reader.Code)
15,300✔
1343
                                {
1344
                                        case 10:
1345
                                                XYZ pt = new XYZ(this._reader.ValueAsDouble, 0, 0);
3,060✔
1346
                                                line.Points.Add(pt);
3,060✔
1347
                                                break;
3,060✔
1348
                                        case 20:
1349
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1350
                                                pt.Y = this._reader.ValueAsDouble;
3,060✔
1351
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1352
                                                break;
3,060✔
1353
                                        case 30:
1354
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1355
                                                pt.Z = this._reader.ValueAsDouble;
3,060✔
1356
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1357
                                                break;
3,060✔
1358
                                        case 305 when this._reader.ValueAsString.Equals("}"):
3,060✔
1359
                                                end = true;
3,060✔
1360
                                                break;
3,060✔
1361
                                        default:
1362
                                                if (!this.tryAssignCurrentValue(line, map))
3,060!
1363
                                                {
×
1364
                                                        this._builder.Notify($"[LeaderLine] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1365
                                                }
×
1366
                                                break;
3,060✔
1367
                                }
1368

1369
                                if (end)
15,300✔
1370
                                {
3,060✔
1371
                                        break;
3,060✔
1372
                                }
1373

1374
                                this._reader.ReadNext();
12,240✔
1375
                        }
12,240✔
1376

1377
                        return line;
3,060✔
1378
                }
3,060✔
1379

1380
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1381
                {
2,278✔
1382
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1383

1384
                        switch (this._reader.Code)
2,278✔
1385
                        {
1386
                                case 2:
1387
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1388
                                        return true;
238✔
1389
                                default:
1390
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1391
                        }
1392
                }
2,278✔
1393

1394
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1395
                {
12,036✔
1396
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,036✔
1397
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,036✔
1398

1399
                        switch (this._reader.Code)
12,036✔
1400
                        {
1401
                                case 91:
1402
                                        var nvertices = this._reader.ValueAsInt;
408✔
1403
                                        for (int i = 0; i < nvertices; i++)
3,672✔
1404
                                        {
1,428✔
1405
                                                this._reader.ReadNext();
1,428✔
1406
                                                var x = this._reader.ValueAsDouble;
1,428✔
1407
                                                this._reader.ReadNext();
1,428✔
1408
                                                var y = this._reader.ValueAsDouble;
1,428✔
1409

1410
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,428✔
1411
                                        }
1,428✔
1412

1413
                                        this._reader.ReadNext();
408✔
1414

1415
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
408✔
1416
                                case 340:
1417
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
408✔
1418
                                        return true;
408✔
1419
                                case 360:
1420
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
408✔
1421
                                        return true;
408✔
1422
                                default:
1423
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,812✔
1424
                        }
1425
                }
12,036✔
1426

1427
                private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1428
                {
×
1429
                        CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1430

1431
                        switch (this._reader.Code)
×
1432
                        {
1433
                                //End of data
1434
                                case 1:
1435
                                //Length of binary data
1436
                                case 90:
1437
                                //Undocumented
1438
                                case 73:
1439
                                        return true;
×
1440
                                case 310:
1441
                                        tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
1442
                                        return true;
×
1443
                                default:
1444
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1445
                        }
1446
                }
×
1447

1448
                private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1449
                {
288,776✔
1450
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
288,776✔
1451
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,776✔
1452
                        var geometry = template.CadObject as ModelerGeometry;
288,776✔
1453

1454
                        switch (this._reader.Code)
288,776✔
1455
                        {
1456
                                case 1:
1457
                                case 3:
1458
                                        geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
37,706✔
1459
                                        return true;
37,706✔
1460
                                case 2:
1461
                                        geometry.Guid = new Guid(this._reader.ValueAsString);
204✔
1462
                                        return true;
204✔
1463
                                case 290:
1464
                                        return true;
204✔
1465
                                default:
1466
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
250,662✔
1467
                        }
1468
                }
288,776✔
1469

1470
                private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1471
                {
34,884✔
1472
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
34,884✔
1473

1474
                        switch (this._reader.Code)
34,884✔
1475
                        {
1476
                                case 350:
1477
                                        tmp.HistoryHandle = this._reader.ValueAsHandle;
272✔
1478
                                        return true;
272✔
1479
                                default:
1480
                                        return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
34,612✔
1481
                        }
1482
                }
34,884✔
1483

1484
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1485
                {
14,280✔
1486
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1487

1488
                        XYZ controlPoint;
1489
                        XYZ fitPoint;
1490

1491
                        switch (this._reader.Code)
14,280!
1492
                        {
1493
                                case 10:
1494
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,632✔
1495
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,632✔
1496
                                        return true;
1,632✔
1497
                                case 20:
1498
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1499
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,632✔
1500
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1501
                                        return true;
1,632✔
1502
                                case 30:
1503
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1504
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,632✔
1505
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1506
                                        return true;
1,632✔
1507
                                case 11:
1508
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1509
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1510
                                        return true;
×
1511
                                case 21:
1512
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1513
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1514
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1515
                                        return true;
×
1516
                                case 31:
1517
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1518
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1519
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1520
                                        return true;
×
1521
                                case 40:
1522
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,264✔
1523
                                        return true;
3,264✔
1524
                                case 41:
1525
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1526
                                        return true;
×
1527
                                case 72:
1528
                                case 73:
1529
                                case 74:
1530
                                        return true;
1,224✔
1531
                                default:
1532
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,896✔
1533
                        }
1534
                }
14,280✔
1535

1536
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1537
                        where T : PdfUnderlayDefinition
1538
                {
3,230✔
1539
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,230✔
1540

1541
                        switch (this._reader.Code)
3,230✔
1542
                        {
1543
                                case 340:
1544
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
204✔
1545
                                        return true;
204✔
1546
                                default:
1547
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,026✔
1548
                        }
1549
                }
3,230✔
1550

1551
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1552
                {
238,252✔
1553
                        CadVertexTemplate tmp = template as CadVertexTemplate;
238,252✔
1554

1555
                        switch (this._reader.Code)
238,252✔
1556
                        {
1557
                                case 100:
1558
                                        switch (this._reader.ValueAsString)
6,936!
1559
                                        {
1560
                                                case DxfSubclassMarker.Vertex:
1561
                                                        return true;
2,040✔
1562
                                                case DxfSubclassMarker.PolylineVertex:
1563
                                                        tmp.SetVertexObject(new Vertex2D());
×
1564
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1565
                                                        return true;
×
1566
                                                case DxfSubclassMarker.Polyline3dVertex:
1567
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1568
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1569
                                                        return true;
1,020✔
1570
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1571
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1572
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1573
                                                        return true;
1,020✔
1574
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1575
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1576
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1577
                                                        return true;
408✔
1578
                                                case DxfSubclassMarker.PolygonMeshVertex:
1579
                                                        tmp.SetVertexObject(new PolygonMeshVertex());
×
1580
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1581
                                                        return true;
×
1582
                                                default:
1583
                                                        return false;
2,448✔
1584
                                        }
1585
                                default:
1586
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
231,316✔
1587
                        }
1588
                }
238,252✔
1589

1590
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1591
                {
67,976✔
1592
                        CadViewportTemplate tmp = template as CadViewportTemplate;
67,976✔
1593

1594
                        switch (this._reader.Code)
67,976!
1595
                        {
1596
                                //Undocumented
1597
                                case 67:
1598
                                case 68:
1599
                                        return true;
2,488✔
1600
                                case 69:
1601
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,244✔
1602
                                        return true;
1,244✔
1603
                                case 331:
1604
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1605
                                        return true;
×
1606
                                case 348:
1607
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1608
                                        return true;
784✔
1609
                                default:
1610
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
63,460✔
1611
                        }
1612
                }
67,976✔
1613

1614
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1615
                {
805,784✔
1616
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
805,784✔
1617

1618
                        switch (this._reader.Code)
805,784✔
1619
                        {
1620
                                default:
1621
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
805,784✔
1622
                        }
1623
                }
805,784✔
1624

1625
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1626
                {
34,174✔
1627
                        List<ExtendedDataRecord> records = new();
34,174✔
1628
                        edata.Add(this._reader.ValueAsString, records);
34,174✔
1629

1630
                        this._reader.ReadNext();
34,174✔
1631

1632
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,635✔
1633
                        {
256,318✔
1634
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,318✔
1635
                                {
10,857✔
1636
                                        this.readExtendedData(edata);
10,857✔
1637
                                        break;
10,857✔
1638
                                }
1639

1640
                                ExtendedDataRecord record = null;
245,461✔
1641
                                double x = 0;
245,461✔
1642
                                double y = 0;
245,461✔
1643
                                double z = 0;
245,461✔
1644

1645
                                switch (this._reader.DxfCode)
245,461✔
1646
                                {
1647
                                        case DxfCode.ExtendedDataAsciiString:
1648
                                        case DxfCode.ExtendedDataRegAppName:
1649
                                                record = new ExtendedDataString(this._reader.ValueAsString);
23,492✔
1650
                                                break;
23,492✔
1651
                                        case DxfCode.ExtendedDataControlString:
1652
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,476✔
1653
                                                break;
13,476✔
1654
                                        case DxfCode.ExtendedDataLayerName:
1655
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1656
                                                {
224✔
1657
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1658
                                                }
224✔
1659
                                                else
1660
                                                {
14✔
1661
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1662
                                                }
14✔
1663
                                                break;
238✔
1664
                                        case DxfCode.ExtendedDataBinaryChunk:
1665
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1666
                                                break;
68✔
1667
                                        case DxfCode.ExtendedDataHandle:
1668
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,581✔
1669
                                                break;
2,581✔
1670
                                        case DxfCode.ExtendedDataXCoordinate:
1671
                                                x = this._reader.ValueAsDouble;
2,540✔
1672
                                                this._reader.ReadNext();
2,540✔
1673
                                                y = this._reader.ValueAsDouble;
2,540✔
1674
                                                this._reader.ReadNext();
2,540✔
1675
                                                z = this._reader.ValueAsDouble;
2,540✔
1676

1677
                                                record = new ExtendedDataCoordinate(
2,540✔
1678
                                                        new XYZ(
2,540✔
1679
                                                                x,
2,540✔
1680
                                                                y,
2,540✔
1681
                                                                z)
2,540✔
1682
                                                        );
2,540✔
1683
                                                break;
2,540✔
1684
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1685
                                                x = this._reader.ValueAsDouble;
1,224✔
1686
                                                this._reader.ReadNext();
1,224✔
1687
                                                y = this._reader.ValueAsDouble;
1,224✔
1688
                                                this._reader.ReadNext();
1,224✔
1689
                                                z = this._reader.ValueAsDouble;
1,224✔
1690

1691
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1692
                                                        new XYZ(
1,224✔
1693
                                                                x,
1,224✔
1694
                                                                y,
1,224✔
1695
                                                                z)
1,224✔
1696
                                                        );
1,224✔
1697
                                                break;
1,224✔
1698
                                        case DxfCode.ExtendedDataWorldXDisp:
1699
                                                x = this._reader.ValueAsDouble;
238✔
1700
                                                this._reader.ReadNext();
238✔
1701
                                                y = this._reader.ValueAsDouble;
238✔
1702
                                                this._reader.ReadNext();
238✔
1703
                                                z = this._reader.ValueAsDouble;
238✔
1704

1705
                                                record = new ExtendedDataDisplacement(
238✔
1706
                                                        new XYZ(
238✔
1707
                                                                x,
238✔
1708
                                                                y,
238✔
1709
                                                                z)
238✔
1710
                                                        );
238✔
1711
                                                break;
238✔
1712
                                        case DxfCode.ExtendedDataWorldXDir:
1713
                                                x = this._reader.ValueAsDouble;
238✔
1714
                                                this._reader.ReadNext();
238✔
1715
                                                y = this._reader.ValueAsDouble;
238✔
1716
                                                this._reader.ReadNext();
238✔
1717
                                                z = this._reader.ValueAsDouble;
238✔
1718

1719
                                                record = new ExtendedDataDirection(
238✔
1720
                                                        new XYZ(
238✔
1721
                                                                x,
238✔
1722
                                                                y,
238✔
1723
                                                                z)
238✔
1724
                                                        );
238✔
1725
                                                break;
238✔
1726
                                        case DxfCode.ExtendedDataReal:
1727
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
119,447✔
1728
                                                break;
119,447✔
1729
                                        case DxfCode.ExtendedDataDist:
1730
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1731
                                                break;
238✔
1732
                                        case DxfCode.ExtendedDataScale:
1733
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1734
                                                break;
238✔
1735
                                        case DxfCode.ExtendedDataInteger16:
1736
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
69,695✔
1737
                                                break;
69,695✔
1738
                                        case DxfCode.ExtendedDataInteger32:
1739
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
9,572✔
1740
                                                break;
9,572✔
1741
                                        default:
1742
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1743
                                                break;
2,176✔
1744
                                }
1745

1746
                                if (record != null)
245,461✔
1747
                                {
243,271✔
1748
                                        records.Add(record);
243,271✔
1749
                                }
243,271✔
1750

1751
                                this._reader.ReadNext();
245,461✔
1752
                        }
245,461✔
1753
                }
34,174✔
1754

1755
                private void readPattern(HatchPattern pattern, int nlines)
1756
                {
1,224✔
1757
                        //Jump 78 code
1758
                        this._reader.ReadNext();
1,224✔
1759

1760
                        for (int i = 0; i < nlines; i++)
185,640✔
1761
                        {
91,596✔
1762
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1763
                                XY basePoint = new XY();
91,596✔
1764
                                XY offset = new XY();
91,596✔
1765

1766
                                bool end = false;
91,596✔
1767
                                HashSet<int> codes = new();
91,596✔
1768

1769
                                while (!end)
642,396✔
1770
                                {
641,172✔
1771
                                        if (codes.Contains(this._reader.Code))
641,172✔
1772
                                        {
90,372✔
1773
                                                break;
90,372✔
1774
                                        }
1775
                                        else
1776
                                        {
550,800✔
1777
                                                codes.Add(this._reader.Code);
550,800✔
1778
                                        }
550,800✔
1779

1780
                                        switch (this._reader.Code)
550,800!
1781
                                        {
1782
                                                case 53:
1783
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1784
                                                        break;
91,596✔
1785
                                                case 43:
1786
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1787
                                                        break;
91,596✔
1788
                                                case 44:
1789
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1790
                                                        line.BasePoint = basePoint;
91,596✔
1791
                                                        break;
91,596✔
1792
                                                case 45:
1793
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1794
                                                        line.Offset = offset;
91,596✔
1795
                                                        break;
91,596✔
1796
                                                case 46:
1797
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1798
                                                        line.Offset = offset;
91,596✔
1799
                                                        break;
91,596✔
1800
                                                //Number of dash length items
1801
                                                case 79:
1802
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1803
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1804
                                                        {
182,784✔
1805
                                                                this._reader.ReadNext();
182,784✔
1806
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1807
                                                        }
182,784✔
1808
                                                        break;
91,596✔
1809
                                                case 49:
1810
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1811
                                                        break;
×
1812
                                                default:
1813
                                                        end = true;
1,224✔
1814
                                                        break;
1,224✔
1815
                                        }
1816
                                        this._reader.ReadNext();
550,800✔
1817
                                }
550,800✔
1818

1819
                                pattern.Lines.Add(line);
91,596✔
1820
                        }
91,596✔
1821
                }
1,224✔
1822

1823
                private void readLoops(CadHatchTemplate template, int count)
1824
                {
1,632✔
1825
                        if (this._reader.Code == 91)
1,632✔
1826
                                this._reader.ReadNext();
1,632✔
1827

1828
                        for (int i = 0; i < count; i++)
6,528✔
1829
                        {
1,632✔
1830
                                if (this._reader.Code != 92)
1,632!
1831
                                {
×
1832
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1833
                                        break;
×
1834
                                }
1835

1836
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1837
                                if (path != null)
1,632✔
1838
                                        template.PathTemplates.Add(path);
1,632✔
1839
                        }
1,632✔
1840
                }
1,632✔
1841

1842
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1843
                {
1,632✔
1844
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1845
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1846
                        template.Path.Flags = flags;
1,632✔
1847

1848
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1849
                        {
612✔
1850
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1851
                                template.Path.Edges.Add(pl);
612✔
1852
                        }
612✔
1853
                        else
1854
                        {
1,020✔
1855
                                this._reader.ReadNext();
1,020✔
1856

1857
                                if (this._reader.Code != 93)
1,020!
1858
                                {
×
1859
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1860
                                        return null;
×
1861
                                }
1862

1863
                                int edges = this._reader.ValueAsInt;
1,020✔
1864
                                this._reader.ReadNext();
1,020✔
1865

1866
                                for (int i = 0; i < edges; i++)
10,200✔
1867
                                {
4,080✔
1868
                                        var edge = this.readEdge();
4,080✔
1869
                                        if (edge != null)
4,080✔
1870
                                                template.Path.Edges.Add(edge);
4,080✔
1871
                                }
4,080✔
1872
                        }
1,020✔
1873

1874
                        bool end = false;
1,632✔
1875
                        while (!end)
6,324✔
1876
                        {
4,692✔
1877
                                switch (this._reader.Code)
4,692✔
1878
                                {
1879
                                        //Number of source boundary objects
1880
                                        case 97:
1881
                                                break;
1,632✔
1882
                                        case 330:
1883
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1884
                                                break;
1,428✔
1885
                                        default:
1886
                                                end = true;
1,632✔
1887
                                                continue;
1,632✔
1888
                                }
1889

1890
                                this._reader.ReadNext();
3,060✔
1891
                        }
3,060✔
1892

1893
                        return template;
1,632✔
1894
                }
1,632✔
1895

1896
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1897
                {
612✔
1898
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
1899

1900
                        this._reader.ReadNext();
612✔
1901

1902
                        if (this._reader.Code != 72)
612!
1903
                        {
×
1904
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1905
                                return null;
×
1906
                        }
1907

1908
                        //72
1909
                        bool hasBulge = this._reader.ValueAsBool;
612✔
1910
                        this._reader.ReadNext();
612✔
1911

1912
                        //73
1913
                        bool isClosed = this._reader.ValueAsBool;
612✔
1914
                        this._reader.ReadNext();
612✔
1915

1916
                        //93
1917
                        int nvertices = this._reader.ValueAsInt;
612✔
1918
                        this._reader.ReadNext();
612✔
1919

1920
                        for (int i = 0; i < nvertices; i++)
6,120✔
1921
                        {
2,448✔
1922
                                double bulge = 0.0;
2,448✔
1923

1924
                                //10
1925
                                double x = this._reader.ValueAsDouble;
2,448✔
1926
                                this._reader.ReadNext();
2,448✔
1927
                                //20
1928
                                double y = this._reader.ValueAsDouble;
2,448✔
1929
                                this._reader.ReadNext();
2,448✔
1930

1931
                                if (hasBulge)
2,448!
1932
                                {
×
1933
                                        //42
1934
                                        bulge = this._reader.ValueAsDouble;
×
1935
                                        this._reader.ReadNext();
×
1936
                                }
×
1937

1938
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
1939
                        }
2,448✔
1940

1941
                        return boundary;
612✔
1942
                }
612✔
1943

1944
                private Hatch.BoundaryPath.Edge readEdge()
1945
                {
4,080✔
1946
                        if (this._reader.Code != 72)
4,080!
1947
                        {
×
1948
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1949
                                return null;
×
1950
                        }
1951

1952
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
1953
                        this._reader.ReadNext();
4,080✔
1954

1955
                        switch (type)
4,080!
1956
                        {
1957
                                case Hatch.BoundaryPath.EdgeType.Line:
1958
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,080✔
1959
                                        while (true)
20,400✔
1960
                                        {
20,400✔
1961
                                                switch (this._reader.Code)
20,400✔
1962
                                                {
1963
                                                        case 10:
1964
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,080✔
1965
                                                                break;
4,080✔
1966
                                                        case 20:
1967
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,080✔
1968
                                                                break;
4,080✔
1969
                                                        case 11:
1970
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,080✔
1971
                                                                break;
4,080✔
1972
                                                        case 21:
1973
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,080✔
1974
                                                                break;
4,080✔
1975
                                                        default:
1976
                                                                return line;
4,080✔
1977
                                                }
1978

1979
                                                this._reader.ReadNext();
16,320✔
1980
                                        }
16,320✔
1981
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1982
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1983
                                        while (true)
×
1984
                                        {
×
1985
                                                switch (this._reader.Code)
×
1986
                                                {
1987
                                                        case 10:
1988
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1989
                                                                break;
×
1990
                                                        case 20:
1991
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1992
                                                                break;
×
1993
                                                        case 40:
1994
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1995
                                                                break;
×
1996
                                                        case 50:
1997
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1998
                                                                break;
×
1999
                                                        case 51:
2000
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
2001
                                                                break;
×
2002
                                                        case 73:
2003
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
2004
                                                                break;
×
2005
                                                        default:
2006
                                                                return arc;
×
2007
                                                }
2008

2009
                                                this._reader.ReadNext();
×
2010
                                        }
×
2011
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
2012
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
2013
                                        while (true)
×
2014
                                        {
×
2015
                                                switch (this._reader.Code)
×
2016
                                                {
2017
                                                        case 10:
2018
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2019
                                                                break;
×
2020
                                                        case 20:
2021
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2022
                                                                break;
×
2023
                                                        case 11:
2024
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
2025
                                                                break;
×
2026
                                                        case 21:
2027
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
2028
                                                                break;
×
2029
                                                        case 40:
2030
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
2031
                                                                break;
×
2032
                                                        case 50:
2033
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
2034
                                                                break;
×
2035
                                                        case 51:
2036
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
2037
                                                                break;
×
2038
                                                        case 73:
2039
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
2040
                                                                break;
×
2041
                                                        default:
2042
                                                                return ellipse;
×
2043
                                                }
2044

2045
                                                this._reader.ReadNext();
×
2046
                                        }
×
2047
                                case Hatch.BoundaryPath.EdgeType.Spline:
2048
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
2049
                                        int nKnots = 0;
×
2050
                                        int nCtrlPoints = 0;
×
2051
                                        int nFitPoints = 0;
×
2052

2053
                                        XYZ controlPoint = new XYZ();
×
2054
                                        XY fitPoint = new XY();
×
2055

2056
                                        while (true)
×
2057
                                        {
×
2058
                                                switch (this._reader.Code)
×
2059
                                                {
2060
                                                        case 10:
2061
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
2062
                                                                break;
×
2063
                                                        case 20:
2064
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
2065
                                                                spline.ControlPoints.Add(controlPoint);
×
2066
                                                                break;
×
2067
                                                        case 11:
2068
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
2069
                                                                break;
×
2070
                                                        case 21:
2071
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
2072
                                                                spline.FitPoints.Add(fitPoint);
×
2073
                                                                break;
×
2074
                                                        case 42:
2075
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
2076
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
2077
                                                                break;
×
2078
                                                        case 12:
2079
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
2080
                                                                break;
×
2081
                                                        case 22:
2082
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
2083
                                                                break;
×
2084
                                                        case 13:
2085
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
2086
                                                                break;
×
2087
                                                        case 23:
2088
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
2089
                                                                break;
×
2090
                                                        case 94:
2091
                                                                spline.Degree = this._reader.ValueAsInt;
×
2092
                                                                break;
×
2093
                                                        case 73:
2094
                                                                spline.IsRational = this._reader.ValueAsBool;
×
2095
                                                                break;
×
2096
                                                        case 74:
2097
                                                                spline.IsPeriodic = this._reader.ValueAsBool;
×
2098
                                                                break;
×
2099
                                                        case 95:
2100
                                                                nKnots = this._reader.ValueAsInt;
×
2101
                                                                break;
×
2102
                                                        case 96:
2103
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
2104
                                                                break;
×
2105
                                                        case 97:
2106
                                                                nFitPoints = this._reader.ValueAsInt;
×
2107
                                                                break;
×
2108
                                                        case 40:
2109
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
2110
                                                                break;
×
2111
                                                        default:
2112
                                                                return spline;
×
2113
                                                }
2114

2115
                                                this._reader.ReadNext();
×
2116
                                        }
×
2117
                        }
2118

2119
                        return null;
×
2120
                }
4,080✔
2121

2122
                private void readDefinedGroups(CadTemplate template)
2123
                {
67,506✔
2124
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
67,506✔
2125

2126
                        template.XDictHandle = xdict;
67,506✔
2127
                        template.ReactorsHandles.UnionWith(reactorsHandles);
67,506✔
2128
                }
67,506✔
2129

2130
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2131
                {
67,713✔
2132
                        xdictHandle = null;
67,713✔
2133
                        reactors = new HashSet<ulong>();
67,713✔
2134

2135
                        switch (this._reader.ValueAsString)
67,713✔
2136
                        {
2137
                                case DxfFileToken.DictionaryToken:
2138
                                        this._reader.ReadNext();
10,052✔
2139
                                        xdictHandle = this._reader.ValueAsHandle;
10,052✔
2140
                                        this._reader.ReadNext();
10,052✔
2141
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,052✔
2142
                                        return;
10,052✔
2143
                                case DxfFileToken.ReactorsToken:
2144
                                        reactors = this.readReactors();
55,617✔
2145
                                        break;
55,617✔
2146
                                case DxfFileToken.BlkRefToken:
2147
                                default:
2148
                                        do
2149
                                        {
5,312✔
2150
                                                this._reader.ReadNext();
5,312✔
2151
                                        }
5,312✔
2152
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,312✔
2153
                                        return;
2,044✔
2154
                        }
2155
                }
67,713✔
2156

2157
                private HashSet<ulong> readReactors()
2158
                {
55,617✔
2159
                        HashSet<ulong> reactors = new();
55,617✔
2160

2161
                        this._reader.ReadNext();
55,617✔
2162

2163
                        while (this._reader.DxfCode != DxfCode.ControlString)
117,738✔
2164
                        {
62,121✔
2165
                                reactors.Add(this._reader.ValueAsHandle);
62,121✔
2166

2167
                                this._reader.ReadNext();
62,121✔
2168
                        }
62,121✔
2169

2170
                        return reactors;
55,617✔
2171
                }
55,617✔
2172

2173
                protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2174
                {
4,190,439✔
2175
                        try
2176
                        {
4,190,439✔
2177
                                //Use this method only if the value is not a link between objects
2178
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,190,439✔
2179
                                {
2,232,120✔
2180
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,232,120✔
2181
                                        {
12,764✔
2182
                                                return true;
12,764✔
2183
                                        }
2184

2185
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,219,356✔
2186
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,219,356✔
2187
                                        {
14,964✔
2188
                                                return false;
14,964✔
2189
                                        }
2190

2191
                                        object value = this._reader.Value;
2,204,392✔
2192

2193
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,204,392✔
2194
                                        {
24,802✔
2195
                                                value = MathHelper.DegToRad((double)value);
24,802✔
2196
                                        }
24,802✔
2197

2198
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,204,392✔
2199

2200
                                        return true;
2,204,392✔
2201
                                }
2202
                        }
1,958,319✔
2203
                        catch (Exception ex)
×
2204
                        {
×
2205
                                if (!this._builder.Configuration.Failsafe)
×
2206
                                {
×
2207
                                        throw ex;
×
2208
                                }
2209
                                else
2210
                                {
×
2211
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2212
                                }
×
2213
                        }
×
2214

2215
                        return false;
1,958,319✔
2216
                }
4,190,439✔
2217
        }
2218
}
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