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

DomCR / ACadSharp / 20929700608

12 Jan 2026 05:59PM UTC coverage: 76.896% (-0.2%) from 77.059%
20929700608

push

github

web-flow
Merge pull request #470 from DomCR/issue-458_POLYLINE_MESH

Implement Polyline mesh

7923 of 11161 branches covered (70.99%)

Branch coverage included in aggregate %.

52 of 132 new or added lines in 11 files covered. (39.39%)

5 existing lines in 2 files now uncovered.

28865 of 36680 relevant lines covered (78.69%)

149225.77 hits per line

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

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

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

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

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

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

32
                public abstract void Read();
33

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

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

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

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

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

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

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

118
                        switch (this._reader.Code)
786,013✔
119
                        {
120
                                //Handle
121
                                case 5:
122
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
295,211✔
123
                                        break;
295,211✔
124
                                //Check with mapper
125
                                case 100:
126
                                        this.currentSubclass = this._reader.ValueAsString;
202,217✔
127
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
202,217!
128
                                        {
1,672✔
129
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
1,672✔
130
                                        }
1,672✔
131
                                        break;
202,217✔
132
                                //Start of application - defined group
133
                                case 102:
134
                                        this.readDefinedGroups(template);
66,579✔
135
                                        break;
66,579✔
136
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
137
                                case 330:
138
                                        template.OwnerHandle = this._reader.ValueAsHandle;
165,255✔
139
                                        break;
165,255✔
140
                                case 1001:
141
                                        isExtendedData = true;
23,053✔
142
                                        this.readExtendedData(template.EDataTemplateByAppName);
23,053✔
143
                                        break;
23,053✔
144
                                default:
145
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
33,698✔
146
                                        break;
33,698✔
147
                        }
148
                }
786,013✔
149

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

240
                                        this._reader.ReadNext();
×
241

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

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

255
                                        return unknownEntityTemplate;
×
256
                        }
257
                }
148,726✔
258

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

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

266
                        while (this._reader.DxfCode != DxfCode.Start)
2,639,324✔
267
                        {
2,444,636✔
268
                                if (!readEntity(template, map))
2,444,636✔
269
                                {
856,630✔
270
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
856,630✔
271
                                        if (isExtendedData)
856,630✔
272
                                                continue;
13,580✔
273
                                }
843,050✔
274

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

281
                                if (this._reader.DxfCode != DxfCode.Start)
2,428,200✔
282
                                        this._reader.ReadNext();
2,427,726✔
283
                        }
2,428,200✔
284

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

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

323
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
324
                {
3,528✔
325
                        if (this._reader.DxfCode == DxfCode.Start)
3,528✔
326
                        {
448✔
327
                                return true;
448✔
328
                        }
329
                        else
330
                        {
3,080✔
331
                                return func.Invoke(template, map);
3,080✔
332
                        }
333
                }
3,528✔
334

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

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

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

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

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

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

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

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

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

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

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

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

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

653
                        switch (this._reader.Code)
291,430✔
654
                        {
655
                                //TODO: Implement multiline text def codes
656
                                case 1 or 3 when tmp.CadObject is MText mtext:
25,928✔
657
                                        mtext.Value += this._reader.ValueAsString;
9,690✔
658
                                        return true;
9,690✔
659
                                case 50 when tmp.CadObject is MText mtext://Read only for MText
480!
660
                                        double angle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
661
                                        mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
662
                                        return true;
×
663
                                case 70:
664
                                case 74:
665
                                case 101:
666
                                        return true;
408✔
667
                                case 7:
668
                                        tmp.StyleName = this._reader.ValueAsString;
2,856✔
669
                                        return true;
2,856✔
670
                                default:
671
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
278,476✔
672
                        }
673
                }
291,430✔
674

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

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

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

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

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

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

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

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

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

877
                private CadEntityTemplate readPolyline()
878
                {
10,444✔
879
                        CadPolyLineTemplate template = null;
10,444✔
880

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1455
                        XYZ controlPoint;
1456
                        XYZ fitPoint;
1457

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

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

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

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

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

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

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

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

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

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

1597
                        this._reader.ReadNext();
34,090✔
1598

1599
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
279,315✔
1600
                        {
256,077✔
1601
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
256,077✔
1602
                                {
10,852✔
1603
                                        this.readExtendedData(edata);
10,852✔
1604
                                        break;
10,852✔
1605
                                }
1606

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

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

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

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

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

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

1713
                                if (record != null)
245,225✔
1714
                                {
243,035✔
1715
                                        records.Add(record);
243,035✔
1716
                                }
243,035✔
1717

1718
                                this._reader.ReadNext();
245,225✔
1719
                        }
245,225✔
1720
                }
34,090✔
1721

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1908
                        return boundary;
612✔
1909
                }
612✔
1910

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2128
                        this._reader.ReadNext();
55,294✔
2129

2130
                        while (this._reader.DxfCode != DxfCode.ControlString)
117,092✔
2131
                        {
61,798✔
2132
                                reactors.Add(this._reader.ValueAsHandle);
61,798✔
2133

2134
                                this._reader.ReadNext();
61,798✔
2135
                        }
61,798✔
2136

2137
                        return reactors;
55,294✔
2138
                }
55,294✔
2139

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

2152
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
2,205,918✔
2153
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
2,205,918✔
2154
                                        {
14,704✔
2155
                                                return false;
14,704✔
2156
                                        }
2157

2158
                                        object value = this._reader.Value;
2,191,214✔
2159

2160
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
2,191,214✔
2161
                                        {
24,794✔
2162
                                                value = MathHelper.DegToRad((double)value);
24,794✔
2163
                                        }
24,794✔
2164

2165
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
2,191,214✔
2166

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

2182
                        return false;
1,918,431✔
2183
                }
4,136,919✔
2184
        }
2185
}
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