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

DomCR / ACadSharp / 21010648765

14 Jan 2026 09:33PM UTC coverage: 77.031% (+0.09%) from 76.943%
21010648765

push

github

web-flow
Merge pull request #949 from DomCR/issue-948_dynamic-blocks-refactor

issue-948 dynamic properties

8019 of 11259 branches covered (71.22%)

Branch coverage included in aggregate %.

301 of 324 new or added lines in 21 files covered. (92.9%)

19 existing lines in 6 files now uncovered.

29076 of 36897 relevant lines covered (78.8%)

149030.45 hits per line

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

80.31
/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
                {
148,791✔
152
                        switch (this._reader.ValueAsString)
148,791!
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);
884✔
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:
210
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,448✔
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
                }
148,791✔
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!
UNCOV
327
                        {
×
UNCOV
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
                        CadPolyLineTemplate template = null;
10,444✔
881

882
                        if (this._builder.Version == ACadVersion.Unknown
10,444!
883
                                || this._builder.Version == ACadVersion.AC1009)
10,444✔
884
                        {
10,036✔
885
                                var polyline = new Polyline2D();
10,036✔
886
                                template = new CadPolyLineTemplate(polyline);
10,036✔
887
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,036✔
888

889
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
45,896!
890
                                {
35,860✔
891
                                        Vertex2D v = new Vertex2D();
35,860✔
892
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
35,860✔
893
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
35,860✔
894

895
                                        if (vertexTemplate.Vertex.Handle == 0)
35,860!
896
                                        {
×
897
                                                polyline.Vertices.Add(v);
×
898
                                        }
×
899
                                        else
900
                                        {
35,860✔
901
                                                template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
35,860✔
902
                                                this._builder.AddTemplate(vertexTemplate);
35,860✔
903
                                        }
35,860✔
904
                                }
35,860✔
905

906
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
20,072!
907
                                {
10,036✔
908
                                        var seqend = new Seqend();
10,036✔
909
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,036✔
910
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,036✔
911

912
                                        polyline.Vertices.Seqend = seqend;
10,036✔
913
                                }
10,036✔
914
                        }
10,036✔
915
                        else
916
                        {
408✔
917
                                template = new CadPolyLineTemplate();
408✔
918
                                this.readEntityCodes<Entity>(template, this.readPolyline);
408✔
919
                        }
408✔
920

921
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
10,444!
922
                        {
×
923
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
924
                                return null;
×
925
                        }
926

927
                        return template;
10,444✔
928
                }
10,444✔
929

930
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
931
                {
75,008✔
932
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
75,008✔
933

934
                        switch (this._reader.Code)
75,008✔
935
                        {
936
                                //DXF: always 0
937
                                //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)
938
                                case 10:
939
                                case 20:
940
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
941
                                case 66:
942
                                        return true;
31,332✔
943
                                case 100:
944
                                        switch (this._reader.ValueAsString)
816!
945
                                        {
946
                                                case DxfSubclassMarker.Polyline:
947
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
948
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
949
                                                        return true;
×
950
                                                case DxfSubclassMarker.Polyline3d:
951
                                                        tmp.SetPolyLineObject(new Polyline3D());
204✔
952
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
204✔
953
                                                        return true;
204✔
954
                                                case DxfSubclassMarker.PolyfaceMesh:
955
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
204✔
956
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
204✔
957
                                                        return true;
204✔
958
                                                case DxfSubclassMarker.PolygonMesh:
959
                                                        tmp.SetPolyLineObject(new PolygonMesh());
×
960
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMesh, DxfClassMap.Create<PolygonMesh>());
×
961
                                                        return true;
×
962
                                                default:
963
                                                        return false;
408✔
964
                                        }
965
                                default:
966
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
42,860✔
967
                        }
968
                }
75,008✔
969

970
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
971
                {
5,100✔
972
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
973

974
                        switch (this._reader.Code)
5,100✔
975
                        {
976
                                case 3:
977
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
204✔
978
                                        return true;
204✔
979
                                case 10:
980
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
816✔
981
                                        return true;
816✔
982
                                case 20:
983
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
984
                                        y.Y = this._reader.ValueAsDouble;
816✔
985
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
816✔
986
                                        return true;
816✔
987
                                case 30:
988
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
989
                                        z.Z = this._reader.ValueAsDouble;
816✔
990
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
816✔
991
                                        return true;
816✔
992
                                case 340:
993
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
204✔
994
                                        return true;
204✔
995
                                //Hook line flag - read only
996
                                case 75:
997
                                //Vertices count
998
                                case 76:
999
                                        return true;
408✔
1000
                                default:
1001
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,836✔
1002
                        }
1003
                }
5,100✔
1004

1005
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1006
                {
87,399✔
1007
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
87,399✔
1008

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

1011
                        switch (this._reader.Code)
87,399!
1012
                        {
1013
                                case 10:
1014
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
20,788✔
1015
                                        return true;
20,788✔
1016
                                case 20:
1017
                                        if (last is not null)
20,788✔
1018
                                        {
20,788✔
1019
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
20,788✔
1020
                                        }
20,788✔
1021
                                        return true;
20,788✔
1022
                                case 40:
1023
                                        if (last is not null)
2,040✔
1024
                                        {
2,040✔
1025
                                                last.StartWidth = this._reader.ValueAsDouble;
2,040✔
1026
                                        }
2,040✔
1027
                                        return true;
2,040✔
1028
                                case 41:
1029
                                        if (last is not null)
2,040✔
1030
                                        {
2,040✔
1031
                                                last.EndWidth = this._reader.ValueAsDouble;
2,040✔
1032
                                        }
2,040✔
1033
                                        return true;
2,040✔
1034
                                case 42:
1035
                                        if (last is not null)
2,784✔
1036
                                        {
2,784✔
1037
                                                last.Bulge = this._reader.ValueAsDouble;
2,784✔
1038
                                        }
2,784✔
1039
                                        return true;
2,784✔
1040
                                case 50:
1041
                                        if (last is not null)
×
1042
                                        {
×
1043
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
1044
                                        }
×
1045
                                        return true;
×
1046
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
1047
                                case 66:
1048
                                //Vertex count
1049
                                case 90:
1050
                                        return true;
4,690✔
1051
                                case 91:
1052
                                        if (last is not null)
×
1053
                                        {
×
1054
                                                last.Id = this._reader.ValueAsInt;
×
1055
                                        }
×
1056
                                        return true;
×
1057
                                default:
1058
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
34,269✔
1059
                        }
1060
                }
87,399✔
1061

1062
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1063
                {
35,904✔
1064
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
1065

1066
                        switch (this._reader.Code)
35,904✔
1067
                        {
1068
                                case 100:
1069
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
1070
                                        {
408✔
1071
                                                tmp.SubclassMarker = true;
408✔
1072
                                        }
408✔
1073
                                        return true;
816✔
1074
                                //Count of sub-entity which property has been overridden
1075
                                case 90:
1076
                                        //TODO: process further entities
1077
                                        return true;
408✔
1078
                                case 92:
1079
                                        if (!tmp.SubclassMarker)
612✔
1080
                                        {
204✔
1081
                                                return false;
204✔
1082
                                        }
1083

1084
                                        int nvertices = this._reader.ValueAsInt;
408✔
1085
                                        for (int i = 0; i < nvertices; i++)
52,224✔
1086
                                        {
25,704✔
1087
                                                this._reader.ReadNext();
25,704✔
1088
                                                double x = this._reader.ValueAsDouble;
25,704✔
1089
                                                this._reader.ReadNext();
25,704✔
1090
                                                double y = this._reader.ValueAsDouble;
25,704✔
1091
                                                this._reader.ReadNext();
25,704✔
1092
                                                double z = this._reader.ValueAsDouble;
25,704✔
1093
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
1094
                                        }
25,704✔
1095
                                        return true;
408✔
1096
                                case 93:
1097
                                        int size = this._reader.ValueAsInt;
408✔
1098
                                        this._reader.ReadNext();
408✔
1099

1100
                                        int indexes = 0;
408✔
1101
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
1102
                                        {
27,744✔
1103
                                                indexes = this._reader.ValueAsInt;
27,744✔
1104
                                                this._reader.ReadNext();
27,744✔
1105

1106
                                                int[] face = new int[indexes];
27,744✔
1107
                                                for (int j = 0; j < indexes; j++)
267,648✔
1108
                                                {
106,080✔
1109
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
1110

1111
                                                        if ((i + j + 2) < size)
106,080✔
1112
                                                        {
105,672✔
1113
                                                                this._reader.ReadNext();
105,672✔
1114
                                                        }
105,672✔
1115
                                                }
106,080✔
1116

1117
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1118
                                        }
27,744✔
1119

1120
                                        Debug.Assert(this._reader.Code == 90);
408✔
1121

1122
                                        return true;
408✔
1123
                                case 94:
1124
                                        int numEdges = this._reader.ValueAsInt;
408✔
1125
                                        this._reader.ReadNext();
408✔
1126
                                        for (int i = 0; i < numEdges; i++)
106,896✔
1127
                                        {
53,040✔
1128
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
1129

1130
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
1131
                                                this._reader.ReadNext();
53,040✔
1132
                                                edge.End = this._reader.ValueAsInt;
53,040✔
1133

1134
                                                if (i < numEdges - 1)
53,040✔
1135
                                                {
52,632✔
1136
                                                        this._reader.ReadNext();
52,632✔
1137
                                                }
52,632✔
1138

1139
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1140
                                        }
53,040✔
1141

1142
                                        Debug.Assert(this._reader.Code == 90);
408✔
1143

1144
                                        return true;
408✔
1145
                                case 95:
1146
                                        this._reader.ReadNext();
408✔
1147
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
1148
                                        {
53,040✔
1149
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
1150
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
1151

1152
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1153

1154
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
1155
                                                {
52,632✔
1156
                                                        this._reader.ReadNext();
52,632✔
1157
                                                }
52,632✔
1158
                                        }
53,040✔
1159

1160
                                        Debug.Assert(this._reader.Code == 140);
408✔
1161

1162
                                        return true;
408✔
1163
                                default:
1164
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1165
                        }
1166
                }
35,904✔
1167

1168
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1169
                {
53,040✔
1170
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1171

1172
                        switch (this._reader.Code)
53,040✔
1173
                        {
1174
                                // 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.
1175
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1176
                                case 2:
1177
                                        tmp.MLineStyleName = this._reader.ValueAsString;
612✔
1178
                                        return true;
612✔
1179
                                case 72:
1180
                                        tmp.NVertex = this._reader.ValueAsInt;
612✔
1181
                                        return true;
612✔
1182
                                case 73:
1183
                                        tmp.NElements = this._reader.ValueAsInt;
612✔
1184
                                        return true;
612✔
1185
                                case 340:
1186
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
612✔
1187
                                        return true;
612✔
1188
                                default:
1189
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
50,592✔
1190
                                        {
8,568✔
1191
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
8,568✔
1192
                                        }
1193
                                        return true;
42,024✔
1194
                        }
1195
                }
53,040✔
1196

1197
                private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1198
                {
144,024✔
1199
                        CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
144,024✔
1200

1201
                        switch (this._reader.Code)
144,024✔
1202
                        {
1203
                                case 270:
1204
                                        //f270 Version
1205
                                        return true;
1,530✔
1206
                                case 300:
1207
                                        this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,060✔
1208
                                        return true;
3,060✔
1209
                                case 340:
1210
                                        tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,060✔
1211
                                        return true;
3,060✔
1212
                                case 341:
1213
                                        tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,060✔
1214
                                        return true;
3,060✔
1215
                                case 343:
1216
                                        tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1217
                                        return true;
3,060✔
1218
                                default:
1219
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
130,254✔
1220
                        }
1221
                }
144,024✔
1222

1223
                private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1224
                {
3,060✔
1225
                        this._reader.ReadNext();
3,060✔
1226

1227
                        DxfMap map = DxfMap.Create<MultiLeaderObjectContextData>();
3,060✔
1228
                        var contextData = template.CadObject as MultiLeaderObjectContextData;
3,060✔
1229

1230
                        bool end = false;
3,060✔
1231
                        while (this._reader.DxfCode != DxfCode.Start)
171,360✔
1232
                        {
171,360✔
1233
                                switch (this._reader.Code)
171,360✔
1234
                                {
1235
                                        case 301 when this._reader.ValueAsString.Equals("}"):
3,060✔
1236
                                                end = true;
3,060✔
1237
                                                break;
3,060✔
1238
                                        case 302 when this._reader.ValueAsString.Equals("LEADER{"):
3,060✔
1239
                                                contextData.LeaderRoots.Add(this.readMultiLeaderLeader(template));
3,060✔
1240
                                                break;
3,060✔
1241
                                        case 340:
1242
                                                template.TextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1243
                                                break;
3,060✔
1244
                                        default:
1245
                                                if (!this.tryAssignCurrentValue(contextData, map.SubClasses[contextData.SubclassMarker]))
162,180!
1246
                                                {
×
1247
                                                        this._builder.Notify($"[AcDbMLeaderObjectContextData] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1248
                                                }
×
1249
                                                break;
162,180✔
1250
                                }
1251

1252
                                if (end)
171,360✔
1253
                                {
3,060✔
1254
                                        break;
3,060✔
1255
                                }
1256

1257
                                this._reader.ReadNext();
168,300✔
1258
                        }
168,300✔
1259
                }
3,060✔
1260

1261
                private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1262
                {
3,060✔
1263
                        MultiLeaderObjectContextData.LeaderRoot root = new();
3,060✔
1264
                        var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,060✔
1265

1266
                        this._reader.ReadNext();
3,060✔
1267

1268
                        bool end = false;
3,060✔
1269
                        while (this._reader.DxfCode != DxfCode.Start)
38,250✔
1270
                        {
38,250✔
1271
                                switch (this._reader.Code)
38,250✔
1272
                                {
1273
                                        case 303 when this._reader.ValueAsString.Equals("}"):
3,060✔
1274
                                                end = true;
3,060✔
1275
                                                break;
3,060✔
1276
                                        case 304 when this._reader.ValueAsString.Equals("LEADER_LINE{"):
3,060✔
1277
                                                var lineTemplate = new LeaderLineTemplate();
3,060✔
1278
                                                template.LeaderLineTemplates.Add(lineTemplate);
3,060✔
1279
                                                root.Lines.Add(this.readMultiLeaderLine(lineTemplate));
3,060✔
1280
                                                break;
3,060✔
1281
                                        default:
1282
                                                if (!this.tryAssignCurrentValue(root, map))
32,130!
1283
                                                {
×
1284
                                                        this._builder.Notify($"[LeaderRoot] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1285
                                                }
×
1286
                                                break;
32,130✔
1287
                                }
1288

1289
                                if (end)
38,250✔
1290
                                {
3,060✔
1291
                                        break;
3,060✔
1292
                                }
1293

1294
                                this._reader.ReadNext();
35,190✔
1295
                        }
35,190✔
1296

1297
                        return root;
3,060✔
1298
                }
3,060✔
1299

1300
                private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1301
                {
3,060✔
1302
                        MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,060✔
1303
                        var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,060✔
1304

1305
                        this._reader.ReadNext();
3,060✔
1306

1307
                        bool end = false;
3,060✔
1308
                        while (this._reader.DxfCode != DxfCode.Start)
15,300✔
1309
                        {
15,300✔
1310
                                switch (this._reader.Code)
15,300✔
1311
                                {
1312
                                        case 10:
1313
                                                XYZ pt = new XYZ(this._reader.ValueAsDouble, 0, 0);
3,060✔
1314
                                                line.Points.Add(pt);
3,060✔
1315
                                                break;
3,060✔
1316
                                        case 20:
1317
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1318
                                                pt.Y = this._reader.ValueAsDouble;
3,060✔
1319
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1320
                                                break;
3,060✔
1321
                                        case 30:
1322
                                                pt = line.Points[line.Points.Count - 1];
3,060✔
1323
                                                pt.Z = this._reader.ValueAsDouble;
3,060✔
1324
                                                line.Points[line.Points.Count - 1] = pt;
3,060✔
1325
                                                break;
3,060✔
1326
                                        case 305 when this._reader.ValueAsString.Equals("}"):
3,060✔
1327
                                                end = true;
3,060✔
1328
                                                break;
3,060✔
1329
                                        default:
1330
                                                if (!this.tryAssignCurrentValue(line, map))
3,060!
1331
                                                {
×
1332
                                                        this._builder.Notify($"[LeaderLine] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
1333
                                                }
×
1334
                                                break;
3,060✔
1335
                                }
1336

1337
                                if (end)
15,300✔
1338
                                {
3,060✔
1339
                                        break;
3,060✔
1340
                                }
1341

1342
                                this._reader.ReadNext();
12,240✔
1343
                        }
12,240✔
1344

1345
                        return line;
3,060✔
1346
                }
3,060✔
1347

1348
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1349
                {
2,278✔
1350
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1351

1352
                        switch (this._reader.Code)
2,278✔
1353
                        {
1354
                                case 2:
1355
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1356
                                        return true;
238✔
1357
                                default:
1358
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1359
                        }
1360
                }
2,278✔
1361

1362
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1363
                {
12,036✔
1364
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,036✔
1365
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,036✔
1366

1367
                        switch (this._reader.Code)
12,036✔
1368
                        {
1369
                                case 91:
1370
                                        var nvertices = this._reader.ValueAsInt;
408✔
1371
                                        for (int i = 0; i < nvertices; i++)
3,672✔
1372
                                        {
1,428✔
1373
                                                this._reader.ReadNext();
1,428✔
1374
                                                var x = this._reader.ValueAsDouble;
1,428✔
1375
                                                this._reader.ReadNext();
1,428✔
1376
                                                var y = this._reader.ValueAsDouble;
1,428✔
1377

1378
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,428✔
1379
                                        }
1,428✔
1380

1381
                                        this._reader.ReadNext();
408✔
1382

1383
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
408✔
1384
                                case 340:
1385
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
408✔
1386
                                        return true;
408✔
1387
                                case 360:
1388
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
408✔
1389
                                        return true;
408✔
1390
                                default:
1391
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,812✔
1392
                        }
1393
                }
12,036✔
1394

1395
                private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1396
                {
×
1397
                        CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1398

1399
                        switch (this._reader.Code)
×
1400
                        {
1401
                                //End of data
1402
                                case 1:
1403
                                //Length of binary data
1404
                                case 90:
1405
                                //Undocumented
1406
                                case 73:
1407
                                        return true;
×
1408
                                case 310:
1409
                                        tmp.Chunks.Add(this._reader.ValueAsBinaryChunk);
×
1410
                                        return true;
×
1411
                                default:
1412
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1413
                        }
1414
                }
×
1415

1416
                private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1417
                {
288,776✔
1418
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
288,776✔
1419
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,776✔
1420
                        var geometry = template.CadObject as ModelerGeometry;
288,776✔
1421

1422
                        switch (this._reader.Code)
288,776✔
1423
                        {
1424
                                case 1:
1425
                                case 3:
1426
                                        geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
37,706✔
1427
                                        return true;
37,706✔
1428
                                case 2:
1429
                                        geometry.Guid = new Guid(this._reader.ValueAsString);
204✔
1430
                                        return true;
204✔
1431
                                case 290:
1432
                                        return true;
204✔
1433
                                default:
1434
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
250,662✔
1435
                        }
1436
                }
288,776✔
1437

1438
                private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1439
                {
34,884✔
1440
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
34,884✔
1441

1442
                        switch (this._reader.Code)
34,884✔
1443
                        {
1444
                                case 350:
1445
                                        tmp.HistoryHandle = this._reader.ValueAsHandle;
272✔
1446
                                        return true;
272✔
1447
                                default:
1448
                                        return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
34,612✔
1449
                        }
1450
                }
34,884✔
1451

1452
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1453
                {
14,280✔
1454
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1455

1456
                        XYZ controlPoint;
1457
                        XYZ fitPoint;
1458

1459
                        switch (this._reader.Code)
14,280!
1460
                        {
1461
                                case 10:
1462
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,632✔
1463
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,632✔
1464
                                        return true;
1,632✔
1465
                                case 20:
1466
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1467
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,632✔
1468
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1469
                                        return true;
1,632✔
1470
                                case 30:
1471
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1472
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,632✔
1473
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1474
                                        return true;
1,632✔
1475
                                case 11:
1476
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1477
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1478
                                        return true;
×
1479
                                case 21:
1480
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1481
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1482
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1483
                                        return true;
×
1484
                                case 31:
1485
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1486
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1487
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1488
                                        return true;
×
1489
                                case 40:
1490
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,264✔
1491
                                        return true;
3,264✔
1492
                                case 41:
1493
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1494
                                        return true;
×
1495
                                case 72:
1496
                                case 73:
1497
                                case 74:
1498
                                        return true;
1,224✔
1499
                                default:
1500
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,896✔
1501
                        }
1502
                }
14,280✔
1503

1504
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1505
                        where T : PdfUnderlayDefinition
1506
                {
3,230✔
1507
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,230✔
1508

1509
                        switch (this._reader.Code)
3,230✔
1510
                        {
1511
                                case 340:
1512
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
204✔
1513
                                        return true;
204✔
1514
                                default:
1515
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,026✔
1516
                        }
1517
                }
3,230✔
1518

1519
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1520
                {
238,252✔
1521
                        CadVertexTemplate tmp = template as CadVertexTemplate;
238,252✔
1522

1523
                        switch (this._reader.Code)
238,252✔
1524
                        {
1525
                                case 100:
1526
                                        switch (this._reader.ValueAsString)
6,936!
1527
                                        {
1528
                                                case DxfSubclassMarker.Vertex:
1529
                                                        return true;
2,040✔
1530
                                                case DxfSubclassMarker.PolylineVertex:
1531
                                                        tmp.SetVertexObject(new Vertex2D());
×
1532
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1533
                                                        return true;
×
1534
                                                case DxfSubclassMarker.Polyline3dVertex:
1535
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1536
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1537
                                                        return true;
1,020✔
1538
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1539
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1540
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1541
                                                        return true;
1,020✔
1542
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1543
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1544
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1545
                                                        return true;
408✔
1546
                                                case DxfSubclassMarker.PolygonMeshVertex:
1547
                                                        tmp.SetVertexObject(new PolygonMeshVertex());
×
1548
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1549
                                                        return true;
×
1550
                                                default:
1551
                                                        return false;
2,448✔
1552
                                        }
1553
                                default:
1554
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
231,316✔
1555
                        }
1556
                }
238,252✔
1557

1558
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1559
                {
67,976✔
1560
                        CadViewportTemplate tmp = template as CadViewportTemplate;
67,976✔
1561

1562
                        switch (this._reader.Code)
67,976!
1563
                        {
1564
                                //Undocumented
1565
                                case 67:
1566
                                case 68:
1567
                                        return true;
2,488✔
1568
                                case 69:
1569
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,244✔
1570
                                        return true;
1,244✔
1571
                                case 331:
1572
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1573
                                        return true;
×
1574
                                case 348:
1575
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1576
                                        return true;
784✔
1577
                                default:
1578
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
63,460✔
1579
                        }
1580
                }
67,976✔
1581

1582
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1583
                {
805,784✔
1584
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
805,784✔
1585

1586
                        switch (this._reader.Code)
805,784✔
1587
                        {
1588
                                default:
1589
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
805,784✔
1590
                        }
1591
                }
805,784✔
1592

1593
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1594
                {
34,174✔
1595
                        List<ExtendedDataRecord> records = new();
34,174✔
1596
                        edata.Add(this._reader.ValueAsString, records);
34,174✔
1597

1598
                        this._reader.ReadNext();
34,174✔
1599

1600
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,635✔
1601
                        {
256,318✔
1602
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,318✔
1603
                                {
10,857✔
1604
                                        this.readExtendedData(edata);
10,857✔
1605
                                        break;
10,857✔
1606
                                }
1607

1608
                                ExtendedDataRecord record = null;
245,461✔
1609
                                double x = 0;
245,461✔
1610
                                double y = 0;
245,461✔
1611
                                double z = 0;
245,461✔
1612

1613
                                switch (this._reader.DxfCode)
245,461✔
1614
                                {
1615
                                        case DxfCode.ExtendedDataAsciiString:
1616
                                        case DxfCode.ExtendedDataRegAppName:
1617
                                                record = new ExtendedDataString(this._reader.ValueAsString);
23,492✔
1618
                                                break;
23,492✔
1619
                                        case DxfCode.ExtendedDataControlString:
1620
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,476✔
1621
                                                break;
13,476✔
1622
                                        case DxfCode.ExtendedDataLayerName:
1623
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1624
                                                {
224✔
1625
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1626
                                                }
224✔
1627
                                                else
1628
                                                {
14✔
1629
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1630
                                                }
14✔
1631
                                                break;
238✔
1632
                                        case DxfCode.ExtendedDataBinaryChunk:
1633
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1634
                                                break;
68✔
1635
                                        case DxfCode.ExtendedDataHandle:
1636
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,581✔
1637
                                                break;
2,581✔
1638
                                        case DxfCode.ExtendedDataXCoordinate:
1639
                                                x = this._reader.ValueAsDouble;
2,540✔
1640
                                                this._reader.ReadNext();
2,540✔
1641
                                                y = this._reader.ValueAsDouble;
2,540✔
1642
                                                this._reader.ReadNext();
2,540✔
1643
                                                z = this._reader.ValueAsDouble;
2,540✔
1644

1645
                                                record = new ExtendedDataCoordinate(
2,540✔
1646
                                                        new XYZ(
2,540✔
1647
                                                                x,
2,540✔
1648
                                                                y,
2,540✔
1649
                                                                z)
2,540✔
1650
                                                        );
2,540✔
1651
                                                break;
2,540✔
1652
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1653
                                                x = this._reader.ValueAsDouble;
1,224✔
1654
                                                this._reader.ReadNext();
1,224✔
1655
                                                y = this._reader.ValueAsDouble;
1,224✔
1656
                                                this._reader.ReadNext();
1,224✔
1657
                                                z = this._reader.ValueAsDouble;
1,224✔
1658

1659
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1660
                                                        new XYZ(
1,224✔
1661
                                                                x,
1,224✔
1662
                                                                y,
1,224✔
1663
                                                                z)
1,224✔
1664
                                                        );
1,224✔
1665
                                                break;
1,224✔
1666
                                        case DxfCode.ExtendedDataWorldXDisp:
1667
                                                x = this._reader.ValueAsDouble;
238✔
1668
                                                this._reader.ReadNext();
238✔
1669
                                                y = this._reader.ValueAsDouble;
238✔
1670
                                                this._reader.ReadNext();
238✔
1671
                                                z = this._reader.ValueAsDouble;
238✔
1672

1673
                                                record = new ExtendedDataDisplacement(
238✔
1674
                                                        new XYZ(
238✔
1675
                                                                x,
238✔
1676
                                                                y,
238✔
1677
                                                                z)
238✔
1678
                                                        );
238✔
1679
                                                break;
238✔
1680
                                        case DxfCode.ExtendedDataWorldXDir:
1681
                                                x = this._reader.ValueAsDouble;
238✔
1682
                                                this._reader.ReadNext();
238✔
1683
                                                y = this._reader.ValueAsDouble;
238✔
1684
                                                this._reader.ReadNext();
238✔
1685
                                                z = this._reader.ValueAsDouble;
238✔
1686

1687
                                                record = new ExtendedDataDirection(
238✔
1688
                                                        new XYZ(
238✔
1689
                                                                x,
238✔
1690
                                                                y,
238✔
1691
                                                                z)
238✔
1692
                                                        );
238✔
1693
                                                break;
238✔
1694
                                        case DxfCode.ExtendedDataReal:
1695
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
119,447✔
1696
                                                break;
119,447✔
1697
                                        case DxfCode.ExtendedDataDist:
1698
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1699
                                                break;
238✔
1700
                                        case DxfCode.ExtendedDataScale:
1701
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1702
                                                break;
238✔
1703
                                        case DxfCode.ExtendedDataInteger16:
1704
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
69,695✔
1705
                                                break;
69,695✔
1706
                                        case DxfCode.ExtendedDataInteger32:
1707
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
9,572✔
1708
                                                break;
9,572✔
1709
                                        default:
1710
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1711
                                                break;
2,176✔
1712
                                }
1713

1714
                                if (record != null)
245,461✔
1715
                                {
243,271✔
1716
                                        records.Add(record);
243,271✔
1717
                                }
243,271✔
1718

1719
                                this._reader.ReadNext();
245,461✔
1720
                        }
245,461✔
1721
                }
34,174✔
1722

1723
                private void readPattern(HatchPattern pattern, int nlines)
1724
                {
1,224✔
1725
                        //Jump 78 code
1726
                        this._reader.ReadNext();
1,224✔
1727

1728
                        for (int i = 0; i < nlines; i++)
185,640✔
1729
                        {
91,596✔
1730
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1731
                                XY basePoint = new XY();
91,596✔
1732
                                XY offset = new XY();
91,596✔
1733

1734
                                bool end = false;
91,596✔
1735
                                HashSet<int> codes = new();
91,596✔
1736

1737
                                while (!end)
642,396✔
1738
                                {
641,172✔
1739
                                        if (codes.Contains(this._reader.Code))
641,172✔
1740
                                        {
90,372✔
1741
                                                break;
90,372✔
1742
                                        }
1743
                                        else
1744
                                        {
550,800✔
1745
                                                codes.Add(this._reader.Code);
550,800✔
1746
                                        }
550,800✔
1747

1748
                                        switch (this._reader.Code)
550,800!
1749
                                        {
1750
                                                case 53:
1751
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1752
                                                        break;
91,596✔
1753
                                                case 43:
1754
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1755
                                                        break;
91,596✔
1756
                                                case 44:
1757
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1758
                                                        line.BasePoint = basePoint;
91,596✔
1759
                                                        break;
91,596✔
1760
                                                case 45:
1761
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1762
                                                        line.Offset = offset;
91,596✔
1763
                                                        break;
91,596✔
1764
                                                case 46:
1765
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1766
                                                        line.Offset = offset;
91,596✔
1767
                                                        break;
91,596✔
1768
                                                //Number of dash length items
1769
                                                case 79:
1770
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1771
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1772
                                                        {
182,784✔
1773
                                                                this._reader.ReadNext();
182,784✔
1774
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1775
                                                        }
182,784✔
1776
                                                        break;
91,596✔
1777
                                                case 49:
1778
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1779
                                                        break;
×
1780
                                                default:
1781
                                                        end = true;
1,224✔
1782
                                                        break;
1,224✔
1783
                                        }
1784
                                        this._reader.ReadNext();
550,800✔
1785
                                }
550,800✔
1786

1787
                                pattern.Lines.Add(line);
91,596✔
1788
                        }
91,596✔
1789
                }
1,224✔
1790

1791
                private void readLoops(CadHatchTemplate template, int count)
1792
                {
1,632✔
1793
                        if (this._reader.Code == 91)
1,632✔
1794
                                this._reader.ReadNext();
1,632✔
1795

1796
                        for (int i = 0; i < count; i++)
6,528✔
1797
                        {
1,632✔
1798
                                if (this._reader.Code != 92)
1,632!
1799
                                {
×
1800
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1801
                                        break;
×
1802
                                }
1803

1804
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1805
                                if (path != null)
1,632✔
1806
                                        template.PathTemplates.Add(path);
1,632✔
1807
                        }
1,632✔
1808
                }
1,632✔
1809

1810
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1811
                {
1,632✔
1812
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1813
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1814
                        template.Path.Flags = flags;
1,632✔
1815

1816
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1817
                        {
612✔
1818
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1819
                                template.Path.Edges.Add(pl);
612✔
1820
                        }
612✔
1821
                        else
1822
                        {
1,020✔
1823
                                this._reader.ReadNext();
1,020✔
1824

1825
                                if (this._reader.Code != 93)
1,020!
1826
                                {
×
1827
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1828
                                        return null;
×
1829
                                }
1830

1831
                                int edges = this._reader.ValueAsInt;
1,020✔
1832
                                this._reader.ReadNext();
1,020✔
1833

1834
                                for (int i = 0; i < edges; i++)
10,200✔
1835
                                {
4,080✔
1836
                                        var edge = this.readEdge();
4,080✔
1837
                                        if (edge != null)
4,080✔
1838
                                                template.Path.Edges.Add(edge);
4,080✔
1839
                                }
4,080✔
1840
                        }
1,020✔
1841

1842
                        bool end = false;
1,632✔
1843
                        while (!end)
6,324✔
1844
                        {
4,692✔
1845
                                switch (this._reader.Code)
4,692✔
1846
                                {
1847
                                        //Number of source boundary objects
1848
                                        case 97:
1849
                                                break;
1,632✔
1850
                                        case 330:
1851
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1852
                                                break;
1,428✔
1853
                                        default:
1854
                                                end = true;
1,632✔
1855
                                                continue;
1,632✔
1856
                                }
1857

1858
                                this._reader.ReadNext();
3,060✔
1859
                        }
3,060✔
1860

1861
                        return template;
1,632✔
1862
                }
1,632✔
1863

1864
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1865
                {
612✔
1866
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
1867

1868
                        this._reader.ReadNext();
612✔
1869

1870
                        if (this._reader.Code != 72)
612!
1871
                        {
×
1872
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1873
                                return null;
×
1874
                        }
1875

1876
                        //72
1877
                        bool hasBulge = this._reader.ValueAsBool;
612✔
1878
                        this._reader.ReadNext();
612✔
1879

1880
                        //73
1881
                        bool isClosed = this._reader.ValueAsBool;
612✔
1882
                        this._reader.ReadNext();
612✔
1883

1884
                        //93
1885
                        int nvertices = this._reader.ValueAsInt;
612✔
1886
                        this._reader.ReadNext();
612✔
1887

1888
                        for (int i = 0; i < nvertices; i++)
6,120✔
1889
                        {
2,448✔
1890
                                double bulge = 0.0;
2,448✔
1891

1892
                                //10
1893
                                double x = this._reader.ValueAsDouble;
2,448✔
1894
                                this._reader.ReadNext();
2,448✔
1895
                                //20
1896
                                double y = this._reader.ValueAsDouble;
2,448✔
1897
                                this._reader.ReadNext();
2,448✔
1898

1899
                                if (hasBulge)
2,448!
1900
                                {
×
1901
                                        //42
1902
                                        bulge = this._reader.ValueAsDouble;
×
1903
                                        this._reader.ReadNext();
×
1904
                                }
×
1905

1906
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
1907
                        }
2,448✔
1908

1909
                        return boundary;
612✔
1910
                }
612✔
1911

1912
                private Hatch.BoundaryPath.Edge readEdge()
1913
                {
4,080✔
1914
                        if (this._reader.Code != 72)
4,080!
1915
                        {
×
1916
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1917
                                return null;
×
1918
                        }
1919

1920
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
1921
                        this._reader.ReadNext();
4,080✔
1922

1923
                        switch (type)
4,080!
1924
                        {
1925
                                case Hatch.BoundaryPath.EdgeType.Line:
1926
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,080✔
1927
                                        while (true)
20,400✔
1928
                                        {
20,400✔
1929
                                                switch (this._reader.Code)
20,400✔
1930
                                                {
1931
                                                        case 10:
1932
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,080✔
1933
                                                                break;
4,080✔
1934
                                                        case 20:
1935
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,080✔
1936
                                                                break;
4,080✔
1937
                                                        case 11:
1938
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,080✔
1939
                                                                break;
4,080✔
1940
                                                        case 21:
1941
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,080✔
1942
                                                                break;
4,080✔
1943
                                                        default:
1944
                                                                return line;
4,080✔
1945
                                                }
1946

1947
                                                this._reader.ReadNext();
16,320✔
1948
                                        }
16,320✔
1949
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1950
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1951
                                        while (true)
×
1952
                                        {
×
1953
                                                switch (this._reader.Code)
×
1954
                                                {
1955
                                                        case 10:
1956
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1957
                                                                break;
×
1958
                                                        case 20:
1959
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1960
                                                                break;
×
1961
                                                        case 40:
1962
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1963
                                                                break;
×
1964
                                                        case 50:
1965
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1966
                                                                break;
×
1967
                                                        case 51:
1968
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1969
                                                                break;
×
1970
                                                        case 73:
1971
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1972
                                                                break;
×
1973
                                                        default:
1974
                                                                return arc;
×
1975
                                                }
1976

1977
                                                this._reader.ReadNext();
×
1978
                                        }
×
1979
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1980
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1981
                                        while (true)
×
1982
                                        {
×
1983
                                                switch (this._reader.Code)
×
1984
                                                {
1985
                                                        case 10:
1986
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1987
                                                                break;
×
1988
                                                        case 20:
1989
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1990
                                                                break;
×
1991
                                                        case 11:
1992
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1993
                                                                break;
×
1994
                                                        case 21:
1995
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1996
                                                                break;
×
1997
                                                        case 40:
1998
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1999
                                                                break;
×
2000
                                                        case 50:
2001
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
2002
                                                                break;
×
2003
                                                        case 51:
2004
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
2005
                                                                break;
×
2006
                                                        case 73:
2007
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
2008
                                                                break;
×
2009
                                                        default:
2010
                                                                return ellipse;
×
2011
                                                }
2012

2013
                                                this._reader.ReadNext();
×
2014
                                        }
×
2015
                                case Hatch.BoundaryPath.EdgeType.Spline:
2016
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
2017
                                        int nKnots = 0;
×
2018
                                        int nCtrlPoints = 0;
×
2019
                                        int nFitPoints = 0;
×
2020

2021
                                        XYZ controlPoint = new XYZ();
×
2022
                                        XY fitPoint = new XY();
×
2023

2024
                                        while (true)
×
2025
                                        {
×
2026
                                                switch (this._reader.Code)
×
2027
                                                {
2028
                                                        case 10:
2029
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
2030
                                                                break;
×
2031
                                                        case 20:
2032
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
2033
                                                                spline.ControlPoints.Add(controlPoint);
×
2034
                                                                break;
×
2035
                                                        case 11:
2036
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
2037
                                                                break;
×
2038
                                                        case 21:
2039
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
2040
                                                                spline.FitPoints.Add(fitPoint);
×
2041
                                                                break;
×
2042
                                                        case 42:
2043
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
2044
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
2045
                                                                break;
×
2046
                                                        case 12:
2047
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
2048
                                                                break;
×
2049
                                                        case 22:
2050
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
2051
                                                                break;
×
2052
                                                        case 13:
2053
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
2054
                                                                break;
×
2055
                                                        case 23:
2056
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
2057
                                                                break;
×
2058
                                                        case 94:
2059
                                                                spline.Degree = this._reader.ValueAsInt;
×
2060
                                                                break;
×
2061
                                                        case 73:
2062
                                                                spline.IsRational = this._reader.ValueAsBool;
×
2063
                                                                break;
×
2064
                                                        case 74:
2065
                                                                spline.IsPeriodic = this._reader.ValueAsBool;
×
2066
                                                                break;
×
2067
                                                        case 95:
2068
                                                                nKnots = this._reader.ValueAsInt;
×
2069
                                                                break;
×
2070
                                                        case 96:
2071
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
2072
                                                                break;
×
2073
                                                        case 97:
2074
                                                                nFitPoints = this._reader.ValueAsInt;
×
2075
                                                                break;
×
2076
                                                        case 40:
2077
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
2078
                                                                break;
×
2079
                                                        default:
2080
                                                                return spline;
×
2081
                                                }
2082

2083
                                                this._reader.ReadNext();
×
2084
                                        }
×
2085
                        }
2086

2087
                        return null;
×
2088
                }
4,080✔
2089

2090
                private void readDefinedGroups(CadTemplate template)
2091
                {
67,506✔
2092
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
67,506✔
2093

2094
                        template.XDictHandle = xdict;
67,506✔
2095
                        template.ReactorsHandles.UnionWith(reactorsHandles);
67,506✔
2096
                }
67,506✔
2097

2098
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2099
                {
67,713✔
2100
                        xdictHandle = null;
67,713✔
2101
                        reactors = new HashSet<ulong>();
67,713✔
2102

2103
                        switch (this._reader.ValueAsString)
67,713✔
2104
                        {
2105
                                case DxfFileToken.DictionaryToken:
2106
                                        this._reader.ReadNext();
10,052✔
2107
                                        xdictHandle = this._reader.ValueAsHandle;
10,052✔
2108
                                        this._reader.ReadNext();
10,052✔
2109
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,052✔
2110
                                        return;
10,052✔
2111
                                case DxfFileToken.ReactorsToken:
2112
                                        reactors = this.readReactors();
55,617✔
2113
                                        break;
55,617✔
2114
                                case DxfFileToken.BlkRefToken:
2115
                                default:
2116
                                        do
2117
                                        {
5,312✔
2118
                                                this._reader.ReadNext();
5,312✔
2119
                                        }
5,312✔
2120
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,312✔
2121
                                        return;
2,044✔
2122
                        }
2123
                }
67,713✔
2124

2125
                private HashSet<ulong> readReactors()
2126
                {
55,617✔
2127
                        HashSet<ulong> reactors = new();
55,617✔
2128

2129
                        this._reader.ReadNext();
55,617✔
2130

2131
                        while (this._reader.DxfCode != DxfCode.ControlString)
117,738✔
2132
                        {
62,121✔
2133
                                reactors.Add(this._reader.ValueAsHandle);
62,121✔
2134

2135
                                this._reader.ReadNext();
62,121✔
2136
                        }
62,121✔
2137

2138
                        return reactors;
55,617✔
2139
                }
55,617✔
2140

2141
                protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2142
                {
4,190,439✔
2143
                        try
2144
                        {
4,190,439✔
2145
                                //Use this method only if the value is not a link between objects
2146
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,190,439✔
2147
                                {
2,232,120✔
2148
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,232,120✔
2149
                                        {
12,764✔
2150
                                                return true;
12,764✔
2151
                                        }
2152

2153
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,219,356✔
2154
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,219,356✔
2155
                                        {
14,964✔
2156
                                                return false;
14,964✔
2157
                                        }
2158

2159
                                        object value = this._reader.Value;
2,204,392✔
2160

2161
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,204,392✔
2162
                                        {
24,802✔
2163
                                                value = MathHelper.DegToRad((double)value);
24,802✔
2164
                                        }
24,802✔
2165

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

2168
                                        return true;
2,204,392✔
2169
                                }
2170
                        }
1,958,319✔
2171
                        catch (Exception ex)
×
2172
                        {
×
2173
                                if (!this._builder.Configuration.Failsafe)
×
2174
                                {
×
2175
                                        throw ex;
×
2176
                                }
2177
                                else
2178
                                {
×
2179
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2180
                                }
×
2181
                        }
×
2182

2183
                        return false;
1,958,319✔
2184
                }
4,190,439✔
2185
        }
2186
}
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