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

DomCR / ACadSharp / 24607642351

18 Apr 2026 03:17PM UTC coverage: 77.076% (+0.006%) from 77.07%
24607642351

push

github

web-flow
Merge pull request #1032 from DomCR/issue/1018_hatch-ellipse-boundary-properties

Standardize ellipse ratio property as RadiusRatio

8441 of 11901 branches covered (70.93%)

Branch coverage included in aggregate %.

60 of 111 new or added lines in 6 files covered. (54.05%)

10 existing lines in 2 files now uncovered.

30367 of 38449 relevant lines covered (78.98%)

150908.87 hits per line

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

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

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

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

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

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

33
                public abstract void Read();
34

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

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

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

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

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

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

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

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

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

248
                                        this._reader.ReadNext();
×
249

250
                                        do
251
                                        {
×
252
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
×
253
                                                {
×
254
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
×
255
                                                        if (isExtendedData)
×
256
                                                                continue;
×
257
                                                }
×
258

259
                                                this._reader.ReadNext();
×
260
                                        }
×
261
                                        while (this._reader.DxfCode != DxfCode.Start);
×
262

263
                                        return unknownEntityTemplate;
×
264
                        }
265
                }
145,979✔
266

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

272
                        DxfMap map = DxfMap.Create<T>();
194,797✔
273

274
                        while (this._reader.DxfCode != DxfCode.Start)
2,638,827✔
275
                        {
2,444,030✔
276
                                if (!readEntity(template, map))
2,444,030✔
277
                                {
855,482✔
278
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
855,482✔
279
                                        if (isExtendedData)
855,482✔
280
                                                continue;
13,666✔
281
                                }
841,816✔
282

283
                                if (this.lockPointer)
2,430,364✔
284
                                {
2,992✔
285
                                        this.lockPointer = false;
2,992✔
286
                                        continue;
2,992✔
287
                                }
288

289
                                if (this._reader.DxfCode != DxfCode.Start)
2,427,372✔
290
                                        this._reader.ReadNext();
2,426,898✔
291
                        }
2,427,372✔
292

293
                        return template;
194,797✔
294
                }
194,797✔
295

296
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
297
                {
923,031✔
298
                        isExtendedData = false;
923,031✔
299
                        switch (this._reader.Code)
923,031✔
300
                        {
301
                                case 6:
302
                                        template.LineTypeName = this._reader.ValueAsString;
25,688✔
303
                                        break;
25,688✔
304
                                case 8:
305
                                        template.LayerName = this._reader.ValueAsString;
211,297✔
306
                                        break;
211,297✔
307
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
308
                                case 67:
309
                                        break;
1,260✔
310
                                //Number of bytes Proxy entity graphics data
311
                                case 92:
312
                                case 160:
313
                                //Proxy entity graphics data
314
                                case 310:
315
                                        break;
76,568✔
316
                                case 347:
317
                                        template.MaterialHandle = this._reader.ValueAsHandle;
680✔
318
                                        break;
680✔
319
                                case 430:
320
                                        template.BookColorName = this._reader.ValueAsString;
170✔
321
                                        break;
170✔
322
                                default:
323
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
607,368✔
324
                                        {
473,122✔
325
                                                this.readCommonCodes(template, out isExtendedData, map);
473,122✔
326
                                        }
473,122✔
327
                                        break;
607,368✔
328
                        }
329
                }
923,031✔
330

331
                [Obsolete("use lockpointer instead")]
332
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
333
                {
2,900✔
334
                        if (this._reader.DxfCode == DxfCode.Start)
2,900!
335
                        {
×
336
                                return true;
×
337
                        }
338
                        else
339
                        {
2,900✔
340
                                return func.Invoke(template, map);
2,900✔
341
                        }
342
                }
2,900✔
343

344
                protected bool checkEntityEnd(CadEntityTemplate template, DxfMap map, string subclass, Func<CadEntityTemplate, DxfMap, string, bool> func)
345
                {
408✔
346
                        if (this._reader.DxfCode == DxfCode.Start)
408!
347
                        {
408✔
348
                                return true;
408✔
349
                        }
350
                        else
351
                        {
×
352
                                return func.Invoke(template, map, subclass);
×
353
                        }
354
                }
408✔
355

356
                private bool readCircle(CadEntityTemplate template, DxfMap map, string subclass = null)
357
                {
35,945✔
358
                        Circle circle = template.CadObject as Circle;
35,945✔
359

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

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

391
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
392
                {
33,438✔
393
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
33,438✔
394
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
33,438✔
395

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

417
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
418
                {
134,334✔
419
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
134,334!
420
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
134,334✔
421
                        TableEntity table = tmp.CadObject as TableEntity;
134,334✔
422

423
                        switch (this._reader.Code)
134,334!
424
                        {
425
                                case 1:
426
                                        TableEntity.CellContent content;
427
                                        if (tmp.CurrentCell.Content == null)
2,652!
428
                                        {
2,652✔
429
                                                content = new TableEntity.CellContent();
2,652✔
430
                                                content.CadValue.ValueType = CadValueType.String;
2,652✔
431
                                                tmp.CurrentCell.Contents.Add(content);
2,652✔
432
                                        }
2,652✔
433
                                        else
434
                                        {
×
435
                                                content = tmp.CurrentCell.Content;
×
436
                                        }
×
437

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

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

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

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

651
                                this._reader.ReadNext();
52,376✔
652
                        }
52,376✔
653

654
                        return template;
9,288✔
655
                }
9,288✔
656

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

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

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

736
                                this._reader.ReadNext();
2,448✔
737
                        }
2,448✔
738
                }
136✔
739

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

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

754
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
755
                {
68,476✔
756
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
68,476✔
757

758
                        switch (this._reader.Code)
68,476✔
759
                        {
760
                                case 2:
761
                                        tmp.BlockName = this._reader.ValueAsString;
2,618✔
762
                                        return true;
2,618✔
763
                                case 3:
764
                                        tmp.StyleName = this._reader.ValueAsString;
2,244✔
765
                                        return true;
2,244✔
766
                                case 50:
767
                                        var dim = new DimensionLinear();
238✔
768
                                        tmp.SetDimensionObject(dim);
238✔
769
                                        dim.Rotation = this._reader.ValueAsAngle;
238✔
770
                                        if (!map.SubClasses.ContainsKey(DxfSubclassMarker.LinearDimension))
238✔
771
                                        {
204✔
772
                                                map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
204✔
773
                                        }
204✔
774
                                        return true;
238✔
775
                                case 70:
776
                                        //Flags do not have set
777
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,618✔
778

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

870
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
871
                {
43,656✔
872
                        CadHatchTemplate tmp = template as CadHatchTemplate;
43,656✔
873
                        Hatch hatch = tmp.CadObject;
43,656✔
874

875
                        XY seedPoint = new XY();
43,656✔
876

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

966
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
967
                {
59,000✔
968
                        CadInsertTemplate tmp = template as CadInsertTemplate;
59,000✔
969

970
                        switch (this._reader.Code)
59,000✔
971
                        {
972
                                case 2:
973
                                        tmp.BlockName = this._reader.ValueAsString;
5,517✔
974
                                        return true;
5,517✔
975
                                case 100:
976
                                        //AcDbEntity
977
                                        //AcDbBlockReference
978
                                        //AcDbMInsertBlock
979
                                        return true;
5,542✔
980
                                case 66:
981
                                        return true;
476✔
982
                                default:
983
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
47,465✔
984
                        }
985
                }
59,000✔
986

987
                private CadEntityTemplate readPolyline()
988
                {
10,444✔
989
                        if (this._builder.Version == ACadVersion.Unknown
10,444!
990
                                || this._builder.Version == ACadVersion.AC1009)
10,444✔
991
                        {
10,036✔
992
                                return this.readLegacyPolyline();
10,036✔
993
                        }
994

995
                        CadPolyLineTemplate template = null;
408✔
996
                        template = new CadPolyLineTemplate();
408✔
997
                        this.readEntityCodes<Entity>(template, this.readPolyline);
408✔
998

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

1005
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
2,856!
1006
                        {
2,448✔
1007
                                var vertexTemplate = this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
2,448✔
1008

1009
                                if (vertexTemplate.OwnerHandle == null)
2,448!
1010
                                {
×
1011
                                        vertexTemplate.OwnerHandle = template.CadObject.Handle;
×
1012
                                }
×
1013

1014
                                template.OwnedObjectsHandlers.Add(vertexTemplate.CadObject.Handle);
2,448✔
1015
                                _builder.AddTemplate(vertexTemplate);
2,448✔
1016
                        }
2,448✔
1017

1018
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
816!
1019
                        {
408✔
1020
                                var seqend = new Seqend();
408✔
1021
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
408✔
1022
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
408✔
1023

1024
                                if (seqendTemplate.OwnerHandle == null)
408!
1025
                                {
×
1026
                                        seqendTemplate.OwnerHandle = template.CadObject.Handle;
×
1027
                                }
×
1028

1029
                                template.OwnedObjectsHandlers.Add(seqendTemplate.CadObject.Handle);
408✔
1030
                                _builder.AddTemplate(seqendTemplate);
408✔
1031
                        }
408✔
1032

1033
                        return template;
408✔
1034
                }
10,444✔
1035

1036
                private CadEntityTemplate readLegacyPolyline()
1037
                {
10,036✔
1038
                        var polyline = new Polyline2D();
10,036✔
1039
                        CadPolyLineTemplate template = new CadPolyLineTemplate(polyline);
10,036✔
1040
                        this.readEntityCodes<Polyline2D>(template, this.readPolyline);
10,036✔
1041

1042
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
45,896!
1043
                        {
35,860✔
1044
                                Vertex2D v = new Vertex2D();
35,860✔
1045
                                CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
35,860✔
1046
                                this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
35,860✔
1047

1048
                                if (vertexTemplate.Vertex.Handle == 0)
35,860!
1049
                                {
×
1050
                                        polyline.Vertices.Add(v);
×
1051
                                }
×
1052
                                else
1053
                                {
35,860✔
1054
                                        template.OwnedObjectsHandlers.Add(vertexTemplate.Vertex.Handle);
35,860✔
1055
                                        this._builder.AddTemplate(vertexTemplate);
35,860✔
1056
                                }
35,860✔
1057
                        }
35,860✔
1058

1059
                        while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
20,072!
1060
                        {
10,036✔
1061
                                var seqend = new Seqend();
10,036✔
1062
                                var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
10,036✔
1063
                                this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
10,036✔
1064

1065
                                polyline.Vertices.Seqend = seqend;
10,036✔
1066
                        }
10,036✔
1067

1068
                        return template;
10,036✔
1069
                }
10,036✔
1070

1071
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1072
                {
75,008✔
1073
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
75,008✔
1074

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

1111
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1112
                {
5,100✔
1113
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
1114

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

1146
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
1147
                {
87,399✔
1148
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
87,399✔
1149

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

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

1203
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
1204
                {
35,904✔
1205
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
1206

1207
                        switch (this._reader.Code)
35,904✔
1208
                        {
1209
                                case 100:
1210
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
1211
                                        {
408✔
1212
                                                tmp.SubclassMarker = true;
408✔
1213
                                        }
408✔
1214
                                        return true;
816✔
1215
                                //Count of sub-entity which property has been overridden
1216
                                case 90:
1217
                                        //TODO: process further entities
1218
                                        return true;
408✔
1219
                                case 92:
1220
                                        if (!tmp.SubclassMarker)
612✔
1221
                                        {
204✔
1222
                                                return false;
204✔
1223
                                        }
1224

1225
                                        int nvertices = this._reader.ValueAsInt;
408✔
1226
                                        for (int i = 0; i < nvertices; i++)
52,224✔
1227
                                        {
25,704✔
1228
                                                this._reader.ReadNext();
25,704✔
1229
                                                double x = this._reader.ValueAsDouble;
25,704✔
1230
                                                this._reader.ReadNext();
25,704✔
1231
                                                double y = this._reader.ValueAsDouble;
25,704✔
1232
                                                this._reader.ReadNext();
25,704✔
1233
                                                double z = this._reader.ValueAsDouble;
25,704✔
1234
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
1235
                                        }
25,704✔
1236
                                        return true;
408✔
1237
                                case 93:
1238
                                        int size = this._reader.ValueAsInt;
408✔
1239
                                        this._reader.ReadNext();
408✔
1240

1241
                                        int indexes = 0;
408✔
1242
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
1243
                                        {
27,744✔
1244
                                                indexes = this._reader.ValueAsInt;
27,744✔
1245
                                                this._reader.ReadNext();
27,744✔
1246

1247
                                                int[] face = new int[indexes];
27,744✔
1248
                                                for (int j = 0; j < indexes; j++)
267,648✔
1249
                                                {
106,080✔
1250
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
1251

1252
                                                        if ((i + j + 2) < size)
106,080✔
1253
                                                        {
105,672✔
1254
                                                                this._reader.ReadNext();
105,672✔
1255
                                                        }
105,672✔
1256
                                                }
106,080✔
1257

1258
                                                tmp.CadObject.Faces.Add(face);
27,744✔
1259
                                        }
27,744✔
1260

1261
                                        Debug.Assert(this._reader.Code == 90);
408✔
1262

1263
                                        return true;
408✔
1264
                                case 94:
1265
                                        int numEdges = this._reader.ValueAsInt;
408✔
1266
                                        this._reader.ReadNext();
408✔
1267
                                        for (int i = 0; i < numEdges; i++)
106,896✔
1268
                                        {
53,040✔
1269
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
1270

1271
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
1272
                                                this._reader.ReadNext();
53,040✔
1273
                                                edge.End = this._reader.ValueAsInt;
53,040✔
1274

1275
                                                if (i < numEdges - 1)
53,040✔
1276
                                                {
52,632✔
1277
                                                        this._reader.ReadNext();
52,632✔
1278
                                                }
52,632✔
1279

1280
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
1281
                                        }
53,040✔
1282

1283
                                        Debug.Assert(this._reader.Code == 90);
408✔
1284

1285
                                        return true;
408✔
1286
                                case 95:
1287
                                        this._reader.ReadNext();
408✔
1288
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
1289
                                        {
53,040✔
1290
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
1291
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
1292

1293
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
1294

1295
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
1296
                                                {
52,632✔
1297
                                                        this._reader.ReadNext();
52,632✔
1298
                                                }
52,632✔
1299
                                        }
53,040✔
1300

1301
                                        Debug.Assert(this._reader.Code == 140);
408✔
1302

1303
                                        return true;
408✔
1304
                                default:
1305
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1306
                        }
1307
                }
35,904✔
1308

1309
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1310
                {
53,040✔
1311
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1312

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

1338
                private bool readMLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
1339
                {
144,024✔
1340
                        CadMLeaderTemplate tmp = template as CadMLeaderTemplate;
144,024✔
1341

1342
                        switch (this._reader.Code)
144,024✔
1343
                        {
1344
                                case 270:
1345
                                        //f270 Version
1346
                                        return true;
1,530✔
1347
                                case 300:
1348
                                        this.readMultiLeaderObjectContextData(tmp.CadMLeaderAnnotContextTemplate);
3,060✔
1349
                                        return true;
3,060✔
1350
                                case 340:
1351
                                        tmp.LeaderStyleHandle = this._reader.ValueAsHandle;
3,060✔
1352
                                        return true;
3,060✔
1353
                                case 341:
1354
                                        tmp.LeaderLineTypeHandle = this._reader.ValueAsHandle;
3,060✔
1355
                                        return true;
3,060✔
1356
                                case 343:
1357
                                        tmp.MTextStyleHandle = this._reader.ValueAsHandle;
3,060✔
1358
                                        return true;
3,060✔
1359
                                default:
1360
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
130,254✔
1361
                        }
1362
                }
144,024✔
1363

1364
                private void readMultiLeaderObjectContextData(CadMLeaderAnnotContextTemplate template)
1365
                {
3,060✔
1366
                        this._reader.ReadNext();
3,060✔
1367

1368
                        var map = DxfClassMap.Create<MultiLeaderObjectContextData>();
3,060✔
1369
                        var contextData = template.CadObject as MultiLeaderObjectContextData;
3,060✔
1370

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

1393
                                if (end)
171,360✔
1394
                                {
3,060✔
1395
                                        break;
3,060✔
1396
                                }
1397

1398
                                this._reader.ReadNext();
168,300✔
1399
                        }
168,300✔
1400
                }
3,060✔
1401

1402
                private MultiLeaderObjectContextData.LeaderRoot readMultiLeaderLeader(CadMLeaderAnnotContextTemplate template)
1403
                {
3,060✔
1404
                        MultiLeaderObjectContextData.LeaderRoot root = new();
3,060✔
1405
                        var map = DxfClassMap.Create(root.GetType(), nameof(MultiLeaderObjectContextData.LeaderRoot));
3,060✔
1406

1407
                        this._reader.ReadNext();
3,060✔
1408

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

1430
                                if (end)
38,250✔
1431
                                {
3,060✔
1432
                                        break;
3,060✔
1433
                                }
1434

1435
                                this._reader.ReadNext();
35,190✔
1436
                        }
35,190✔
1437

1438
                        return root;
3,060✔
1439
                }
3,060✔
1440

1441
                private MultiLeaderObjectContextData.LeaderLine readMultiLeaderLine(LeaderLineTemplate template)
1442
                {
3,060✔
1443
                        MultiLeaderObjectContextData.LeaderLine line = template.LeaderLine;
3,060✔
1444
                        var map = DxfClassMap.Create(line.GetType(), nameof(MultiLeaderObjectContextData.LeaderLine));
3,060✔
1445

1446
                        this._reader.ReadNext();
3,060✔
1447

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

1478
                                if (end)
15,300✔
1479
                                {
3,060✔
1480
                                        break;
3,060✔
1481
                                }
1482

1483
                                this._reader.ReadNext();
12,240✔
1484
                        }
12,240✔
1485

1486
                        return line;
3,060✔
1487
                }
3,060✔
1488

1489
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1490
                {
2,278✔
1491
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1492

1493
                        switch (this._reader.Code)
2,278✔
1494
                        {
1495
                                case 2:
1496
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1497
                                        return true;
238✔
1498
                                default:
1499
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1500
                        }
1501
                }
2,278✔
1502

1503
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1504
                {
12,036✔
1505
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
12,036✔
1506
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
12,036✔
1507

1508
                        switch (this._reader.Code)
12,036✔
1509
                        {
1510
                                case 91:
1511
                                        var nvertices = this._reader.ValueAsInt;
408✔
1512
                                        for (int i = 0; i < nvertices; i++)
3,672✔
1513
                                        {
1,428✔
1514
                                                this._reader.ReadNext();
1,428✔
1515
                                                var x = this._reader.ValueAsDouble;
1,428✔
1516
                                                this._reader.ReadNext();
1,428✔
1517
                                                var y = this._reader.ValueAsDouble;
1,428✔
1518

1519
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,428✔
1520
                                        }
1,428✔
1521

1522
                                        this._reader.ReadNext();
408✔
1523

1524
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
408✔
1525
                                case 340:
1526
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
408✔
1527
                                        return true;
408✔
1528
                                case 360:
1529
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
408✔
1530
                                        return true;
408✔
1531
                                default:
1532
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,812✔
1533
                        }
1534
                }
12,036✔
1535

1536
                private bool readOle2Frame(CadEntityTemplate template, DxfMap map, string subclass = null)
1537
                {
×
1538
                        CadOle2FrameTemplate tmp = template as CadOle2FrameTemplate;
×
1539

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

1557
                private bool readModelerGeometry(CadEntityTemplate template, DxfMap map, string subclass = null)
1558
                {
288,776✔
1559
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
288,776✔
1560
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
288,776✔
1561
                        var geometry = template.CadObject as ModelerGeometry;
288,776✔
1562

1563
                        switch (this._reader.Code)
288,776✔
1564
                        {
1565
                                case 1:
1566
                                case 3:
1567
                                        geometry.ProprietaryData.AppendLine(this._reader.ValueAsString);
37,706✔
1568
                                        return true;
37,706✔
1569
                                case 2:
1570
                                        geometry.Guid = new Guid(this._reader.ValueAsString);
204✔
1571
                                        return true;
204✔
1572
                                case 290:
1573
                                        return true;
204✔
1574
                                default:
1575
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
250,662✔
1576
                        }
1577
                }
288,776✔
1578

1579
                private bool readSolid3d(CadEntityTemplate template, DxfMap map, string subclass = null)
1580
                {
34,884✔
1581
                        CadSolid3DTemplate tmp = template as CadSolid3DTemplate;
34,884✔
1582

1583
                        switch (this._reader.Code)
34,884✔
1584
                        {
1585
                                case 350:
1586
                                        tmp.HistoryHandle = this._reader.ValueAsHandle;
272✔
1587
                                        return true;
272✔
1588
                                default:
1589
                                        return this.readModelerGeometry(template, map, DxfSubclassMarker.ModelerGeometry);
34,612✔
1590
                        }
1591
                }
34,884✔
1592

1593
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1594
                {
14,280✔
1595
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1596

1597
                        XYZ controlPoint;
1598
                        XYZ fitPoint;
1599

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

1645
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1646
                        where T : PdfUnderlayDefinition
1647
                {
3,230✔
1648
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,230✔
1649

1650
                        switch (this._reader.Code)
3,230✔
1651
                        {
1652
                                case 340:
1653
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
204✔
1654
                                        return true;
204✔
1655
                                default:
1656
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,026✔
1657
                        }
1658
                }
3,230✔
1659

1660
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1661
                {
238,252✔
1662
                        CadVertexTemplate tmp = template as CadVertexTemplate;
238,252✔
1663

1664
                        switch (this._reader.Code)
238,252✔
1665
                        {
1666
                                case 100:
1667
                                        switch (this._reader.ValueAsString)
6,936!
1668
                                        {
1669
                                                case DxfSubclassMarker.Vertex:
1670
                                                        return true;
2,040✔
1671
                                                case DxfSubclassMarker.PolylineVertex:
1672
                                                        tmp.SetVertexObject(new Vertex2D());
×
1673
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1674
                                                        return true;
×
1675
                                                case DxfSubclassMarker.Polyline3dVertex:
1676
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1677
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1678
                                                        return true;
1,020✔
1679
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1680
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1681
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1682
                                                        return true;
1,020✔
1683
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1684
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1685
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1686
                                                        return true;
408✔
1687
                                                case DxfSubclassMarker.PolygonMeshVertex:
1688
                                                        tmp.SetVertexObject(new PolygonMeshVertex());
×
1689
                                                        map.SubClasses.Add(DxfSubclassMarker.PolygonMeshVertex, DxfClassMap.Create<PolygonMeshVertex>());
×
1690
                                                        return true;
×
1691
                                                default:
1692
                                                        return false;
2,448✔
1693
                                        }
1694
                                default:
1695
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
231,316✔
1696
                        }
1697
                }
238,252✔
1698

1699
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1700
                {
68,552✔
1701
                        CadViewportTemplate tmp = template as CadViewportTemplate;
68,552✔
1702

1703
                        switch (this._reader.Code)
68,552!
1704
                        {
1705
                                //Undocumented
1706
                                case 67:
1707
                                case 68:
1708
                                        return true;
2,500✔
1709
                                case 69:
1710
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,256✔
1711
                                        return true;
1,256✔
1712
                                case 331:
1713
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1714
                                        return true;
×
1715
                                case 348:
1716
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1717
                                        return true;
784✔
1718
                                default:
1719
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
64,012✔
1720
                        }
1721
                }
68,552✔
1722

1723
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1724
                {
806,016✔
1725
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
806,016✔
1726

1727
                        switch (this._reader.Code)
806,016✔
1728
                        {
1729
                                default:
1730
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
806,016✔
1731
                        }
1732
                }
806,016✔
1733

1734
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1735
                {
34,227✔
1736
                        List<ExtendedDataRecord> records = new();
34,227✔
1737
                        edata.Add(this._reader.ValueAsString, records);
34,227✔
1738

1739
                        this._reader.ReadNext();
34,227✔
1740

1741
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,832✔
1742
                        {
256,472✔
1743
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,472✔
1744
                                {
10,867✔
1745
                                        this.readExtendedData(edata);
10,867✔
1746
                                        break;
10,867✔
1747
                                }
1748

1749
                                ExtendedDataRecord record = null;
245,605✔
1750
                                double x = 0;
245,605✔
1751
                                double y = 0;
245,605✔
1752
                                double z = 0;
245,605✔
1753

1754
                                switch (this._reader.DxfCode)
245,605✔
1755
                                {
1756
                                        case DxfCode.ExtendedDataAsciiString:
1757
                                        case DxfCode.ExtendedDataRegAppName:
1758
                                                record = new ExtendedDataString(this._reader.ValueAsString);
23,506✔
1759
                                                break;
23,506✔
1760
                                        case DxfCode.ExtendedDataControlString:
1761
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,484✔
1762
                                                break;
13,484✔
1763
                                        case DxfCode.ExtendedDataLayerName:
1764
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1765
                                                {
224✔
1766
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1767
                                                }
224✔
1768
                                                else
1769
                                                {
14✔
1770
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1771
                                                }
14✔
1772
                                                break;
238✔
1773
                                        case DxfCode.ExtendedDataBinaryChunk:
1774
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1775
                                                break;
68✔
1776
                                        case DxfCode.ExtendedDataHandle:
1777
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,611✔
1778
                                                break;
2,611✔
1779
                                        case DxfCode.ExtendedDataXCoordinate:
1780
                                                x = this._reader.ValueAsDouble;
2,541✔
1781
                                                this._reader.ReadNext();
2,541✔
1782
                                                y = this._reader.ValueAsDouble;
2,541✔
1783
                                                this._reader.ReadNext();
2,541✔
1784
                                                z = this._reader.ValueAsDouble;
2,541✔
1785

1786
                                                record = new ExtendedDataCoordinate(
2,541✔
1787
                                                        new XYZ(
2,541✔
1788
                                                                x,
2,541✔
1789
                                                                y,
2,541✔
1790
                                                                z)
2,541✔
1791
                                                        );
2,541✔
1792
                                                break;
2,541✔
1793
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1794
                                                x = this._reader.ValueAsDouble;
1,224✔
1795
                                                this._reader.ReadNext();
1,224✔
1796
                                                y = this._reader.ValueAsDouble;
1,224✔
1797
                                                this._reader.ReadNext();
1,224✔
1798
                                                z = this._reader.ValueAsDouble;
1,224✔
1799

1800
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1801
                                                        new XYZ(
1,224✔
1802
                                                                x,
1,224✔
1803
                                                                y,
1,224✔
1804
                                                                z)
1,224✔
1805
                                                        );
1,224✔
1806
                                                break;
1,224✔
1807
                                        case DxfCode.ExtendedDataWorldXDisp:
1808
                                                x = this._reader.ValueAsDouble;
238✔
1809
                                                this._reader.ReadNext();
238✔
1810
                                                y = this._reader.ValueAsDouble;
238✔
1811
                                                this._reader.ReadNext();
238✔
1812
                                                z = this._reader.ValueAsDouble;
238✔
1813

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

1828
                                                record = new ExtendedDataDirection(
238✔
1829
                                                        new XYZ(
238✔
1830
                                                                x,
238✔
1831
                                                                y,
238✔
1832
                                                                z)
238✔
1833
                                                        );
238✔
1834
                                                break;
238✔
1835
                                        case DxfCode.ExtendedDataReal:
1836
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
119,449✔
1837
                                                break;
119,449✔
1838
                                        case DxfCode.ExtendedDataDist:
1839
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1840
                                                break;
238✔
1841
                                        case DxfCode.ExtendedDataScale:
1842
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1843
                                                break;
238✔
1844
                                        case DxfCode.ExtendedDataInteger16:
1845
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
69,751✔
1846
                                                break;
69,751✔
1847
                                        case DxfCode.ExtendedDataInteger32:
1848
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
9,605✔
1849
                                                break;
9,605✔
1850
                                        default:
1851
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1852
                                                break;
2,176✔
1853
                                }
1854

1855
                                if (record != null)
245,605✔
1856
                                {
243,415✔
1857
                                        records.Add(record);
243,415✔
1858
                                }
243,415✔
1859

1860
                                this._reader.ReadNext();
245,605✔
1861
                        }
245,605✔
1862
                }
34,227✔
1863

1864
                private void readPattern(HatchPattern pattern, int nlines)
1865
                {
1,224✔
1866
                        //Jump 78 code
1867
                        this._reader.ReadNext();
1,224✔
1868

1869
                        for (int i = 0; i < nlines; i++)
185,640✔
1870
                        {
91,596✔
1871
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1872
                                XY basePoint = new XY();
91,596✔
1873
                                XY offset = new XY();
91,596✔
1874

1875
                                bool end = false;
91,596✔
1876
                                HashSet<int> codes = new();
91,596✔
1877

1878
                                while (!end)
642,396✔
1879
                                {
641,172✔
1880
                                        if (codes.Contains(this._reader.Code))
641,172✔
1881
                                        {
90,372✔
1882
                                                break;
90,372✔
1883
                                        }
1884
                                        else
1885
                                        {
550,800✔
1886
                                                codes.Add(this._reader.Code);
550,800✔
1887
                                        }
550,800✔
1888

1889
                                        switch (this._reader.Code)
550,800!
1890
                                        {
1891
                                                case 53:
1892
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1893
                                                        break;
91,596✔
1894
                                                case 43:
1895
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1896
                                                        break;
91,596✔
1897
                                                case 44:
1898
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1899
                                                        line.BasePoint = basePoint;
91,596✔
1900
                                                        break;
91,596✔
1901
                                                case 45:
1902
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1903
                                                        line.Offset = offset;
91,596✔
1904
                                                        break;
91,596✔
1905
                                                case 46:
1906
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1907
                                                        line.Offset = offset;
91,596✔
1908
                                                        break;
91,596✔
1909
                                                //Number of dash length items
1910
                                                case 79:
1911
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1912
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1913
                                                        {
182,784✔
1914
                                                                this._reader.ReadNext();
182,784✔
1915
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1916
                                                        }
182,784✔
1917
                                                        break;
91,596✔
1918
                                                case 49:
1919
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1920
                                                        break;
×
1921
                                                default:
1922
                                                        end = true;
1,224✔
1923
                                                        break;
1,224✔
1924
                                        }
1925
                                        this._reader.ReadNext();
550,800✔
1926
                                }
550,800✔
1927

1928
                                pattern.Lines.Add(line);
91,596✔
1929
                        }
91,596✔
1930
                }
1,224✔
1931

1932
                private void readLoops(CadHatchTemplate template, int count)
1933
                {
1,632✔
1934
                        if (this._reader.Code == 91)
1,632✔
1935
                                this._reader.ReadNext();
1,632✔
1936

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

1945
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1946
                                if (path != null)
1,632✔
1947
                                        template.PathTemplates.Add(path);
1,632✔
1948
                        }
1,632✔
1949
                }
1,632✔
1950

1951
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1952
                {
1,632✔
1953
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1954
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1955
                        template.Path.Flags = flags;
1,632✔
1956

1957
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1958
                        {
612✔
1959
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1960
                                template.Path.Edges.Add(pl);
612✔
1961
                        }
612✔
1962
                        else
1963
                        {
1,020✔
1964
                                this._reader.ReadNext();
1,020✔
1965

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

1972
                                int edges = this._reader.ValueAsInt;
1,020✔
1973
                                this._reader.ReadNext();
1,020✔
1974

1975
                                for (int i = 0; i < edges; i++)
10,200✔
1976
                                {
4,080✔
1977
                                        var edge = this.readEdge();
4,080✔
1978
                                        if (edge != null)
4,080✔
1979
                                                template.Path.Edges.Add(edge);
4,080✔
1980
                                }
4,080✔
1981
                        }
1,020✔
1982

1983
                        bool end = false;
1,632✔
1984
                        while (!end)
6,324✔
1985
                        {
4,692✔
1986
                                switch (this._reader.Code)
4,692✔
1987
                                {
1988
                                        //Number of source boundary objects
1989
                                        case 97:
1990
                                                break;
1,632✔
1991
                                        case 330:
1992
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1993
                                                break;
1,428✔
1994
                                        default:
1995
                                                end = true;
1,632✔
1996
                                                continue;
1,632✔
1997
                                }
1998

1999
                                this._reader.ReadNext();
3,060✔
2000
                        }
3,060✔
2001

2002
                        return template;
1,632✔
2003
                }
1,632✔
2004

2005
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
2006
                {
612✔
2007
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
2008

2009
                        this._reader.ReadNext();
612✔
2010

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

2017
                        bool end = false;
612✔
2018
                        bool hasBulge = false;
612✔
2019
                        while (!end)
3,060✔
2020
                        {
2,448✔
2021
                                switch (this._reader.Code)
2,448✔
2022
                                {
2023
                                        case 72:
2024
                                                hasBulge = this._reader.ValueAsBool;
612✔
2025
                                                break;
612✔
2026
                                        case 73:
2027
                                                boundary.IsClosed = this._reader.ValueAsBool;
612✔
2028
                                                break;
612✔
2029
                                        case 93:
2030
                                                int nvertices = this._reader.ValueAsInt;
612✔
2031
                                                this._reader.ReadNext();
612✔
2032

2033
                                                for (int i = 0; i < nvertices; i++)
6,120✔
2034
                                                {
2,448✔
2035
                                                        double bulge = 0.0;
2,448✔
2036

2037
                                                        //10
2038
                                                        double x = this._reader.ValueAsDouble;
2,448✔
2039
                                                        this._reader.ReadNext();
2,448✔
2040
                                                        //20
2041
                                                        double y = this._reader.ValueAsDouble;
2,448✔
2042
                                                        this._reader.ReadNext();
2,448✔
2043

2044
                                                        if (hasBulge)
2,448!
2045
                                                        {
×
2046
                                                                //42
2047
                                                                bulge = this._reader.ValueAsDouble;
×
2048
                                                                this._reader.ReadNext();
×
2049
                                                        }
×
2050

2051
                                                        boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
2052
                                                }
2,448✔
2053
                                                continue;
612✔
2054
                                        default:
2055
                                                end = true;
612✔
2056
                                                continue;
612✔
2057
                                }
2058

2059
                                this._reader.ReadNext();
1,224✔
2060
                        }
1,224✔
2061

2062
                        return boundary;
612✔
2063
                }
612✔
2064

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

2073
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
2074
                        this._reader.ReadNext();
4,080✔
2075

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

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

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

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

2174
                                        XYZ controlPoint = new XYZ();
×
2175
                                        XY fitPoint = new XY();
×
2176

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

2236
                                                this._reader.ReadNext();
×
2237
                                        }
×
2238
                        }
2239

2240
                        return null;
×
2241
                }
4,080✔
2242

2243
                private void readDefinedGroups(CadTemplate template)
2244
                {
68,231✔
2245
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
68,231✔
2246

2247
                        if (xdict.HasValue)
68,231✔
2248
                        {
9,871✔
2249
                                template.XDictHandle = xdict;
9,871✔
2250
                        }
9,871✔
2251
                        template.ReactorsHandles.UnionWith(reactorsHandles);
68,231✔
2252
                }
68,231✔
2253

2254
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
2255
                {
68,440✔
2256
                        xdictHandle = null;
68,440✔
2257
                        reactors = new HashSet<ulong>();
68,440✔
2258

2259
                        switch (this._reader.ValueAsString)
68,440✔
2260
                        {
2261
                                case DxfFileToken.DictionaryToken:
2262
                                        this._reader.ReadNext();
10,080✔
2263
                                        xdictHandle = this._reader.ValueAsHandle;
10,080✔
2264
                                        this._reader.ReadNext();
10,080✔
2265
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,080✔
2266
                                        return;
10,080✔
2267
                                case DxfFileToken.ReactorsToken:
2268
                                        reactors = this.readReactors();
56,309✔
2269
                                        break;
56,309✔
2270
                                case DxfFileToken.BlkRefToken:
2271
                                default:
2272
                                        do
2273
                                        {
5,326✔
2274
                                                this._reader.ReadNext();
5,326✔
2275
                                        }
5,326✔
2276
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,326✔
2277
                                        return;
2,051✔
2278
                        }
2279
                }
68,440✔
2280

2281
                private HashSet<ulong> readReactors()
2282
                {
56,309✔
2283
                        HashSet<ulong> reactors = new();
56,309✔
2284

2285
                        this._reader.ReadNext();
56,309✔
2286

2287
                        while (this._reader.DxfCode != DxfCode.ControlString)
119,122✔
2288
                        {
62,813✔
2289
                                reactors.Add(this._reader.ValueAsHandle);
62,813✔
2290

2291
                                this._reader.ReadNext();
62,813✔
2292
                        }
62,813✔
2293

2294
                        return reactors;
56,309✔
2295
                }
56,309✔
2296

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

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

2314
                protected bool tryAssignCurrentValue(object cadObject, DxfClassMap map)
2315
                {
4,204,459✔
2316
                        try
2317
                        {
4,204,459✔
2318
                                //Use this method only if the value is not a link between objects
2319
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,204,459✔
2320
                                {
2,211,158✔
2321
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
2,211,158✔
2322
                                        {
12,971✔
2323
                                                return true;
12,971✔
2324
                                        }
2325

2326
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,198,187✔
2327
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,198,187✔
2328
                                        {
16,352✔
2329
                                                return false;
16,352✔
2330
                                        }
2331

2332
                                        object value = this._reader.Value;
2,181,835✔
2333

2334
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,181,835✔
2335
                                        {
24,844✔
2336
                                                value = MathHelper.DegToRad((double)value);
24,844✔
2337
                                        }
24,844✔
2338

2339
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,181,835✔
2340

2341
                                        return true;
2,181,835✔
2342
                                }
2343
                        }
1,993,301✔
2344
                        catch (Exception ex)
×
2345
                        {
×
2346
                                if (!this._builder.Configuration.Failsafe)
×
2347
                                {
×
2348
                                        throw ex;
×
2349
                                }
2350
                                else
2351
                                {
×
2352
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
2353
                                }
×
2354
                        }
×
2355

2356
                        return false;
1,993,301✔
2357
                }
4,204,459✔
2358
        }
2359
}
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