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

DomCR / ACadSharp / 18627956477

19 Oct 2025 08:38AM UTC coverage: 78.13% (+0.06%) from 78.075%
18627956477

Pull #829

github

web-flow
Merge ceaee1012 into 2f9a5b70f
Pull Request #829: dxf CadWipeoutBase

6896 of 9583 branches covered (71.96%)

Branch coverage included in aggregate %.

29 of 32 new or added lines in 2 files covered. (90.63%)

2 existing lines in 1 file now uncovered.

26510 of 33174 relevant lines covered (79.91%)

108085.87 hits per line

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

83.73
/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 CSUtilities.Converters;
8
using System;
9
using System.Collections.Generic;
10
using System.Diagnostics;
11
using System.Linq;
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
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
1,056✔
23
                {
1,056✔
24
                        this._reader = reader;
1,056✔
25
                        this._builder = builder;
1,056✔
26
                }
1,056✔
27

28
                public abstract void Read();
29

30
                protected void readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out HashSet<ulong> reactors)
31
                {
2,482✔
32
                        name = null;
2,482✔
33
                        handle = 0;
2,482✔
34
                        ownerHandle = null;
2,482✔
35
                        xdictHandle = null;
2,482✔
36
                        reactors = new HashSet<ulong>();
2,482✔
37

38
                        if (this._reader.DxfCode == DxfCode.Start
2,482!
39
                                        || this._reader.DxfCode == DxfCode.Subclass)
2,482✔
40
                                this._reader.ReadNext();
×
41

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

74
                                this._reader.ReadNext();
7,372✔
75
                        }
7,372✔
76
                }
2,482✔
77

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

106
                                this._reader.ReadNext();
1,944✔
107
                        }
1,944✔
108
                }
648✔
109

110
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
111
                {
1,965,467✔
112
                        isExtendedData = false;
1,965,467✔
113

114
                        switch (this._reader.Code)
1,965,467✔
115
                        {
116
                                //Handle
117
                                case 5:
118
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
311,685✔
119
                                        break;
311,685✔
120
                                //Check with mapper
121
                                case 100:
122
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
219,507!
123
                                        {
3,504✔
124
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
3,504✔
125
                                        }
3,504✔
126
                                        break;
219,507✔
127
                                //Start of application - defined group
128
                                case 102:
129
                                        this.readDefinedGroups(template);
62,829✔
130
                                        break;
62,829✔
131
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
132
                                case 330:
133
                                        template.OwnerHandle = this._reader.ValueAsHandle;
166,435✔
134
                                        break;
166,435✔
135
                                case 1001:
136
                                        isExtendedData = true;
26,503✔
137
                                        this.readExtendedData(template.EDataTemplateByAppName);
26,503✔
138
                                        break;
26,503✔
139
                                default:
140
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
1,178,508✔
141
                                        break;
1,178,508✔
142
                        }
143
                }
1,965,467✔
144

145
                protected CadEntityTemplate readEntity()
146
                {
216,644✔
147
                        switch (this._reader.ValueAsString)
216,644!
148
                        {
149
                                case DxfFileToken.EntityAttribute:
150
                                        return this.readEntityCodes<AttributeEntity>(new CadAttributeTemplate(new AttributeEntity()), this.readAttributeDefinition);
1,064✔
151
                                case DxfFileToken.EntityAttributeDefinition:
152
                                        return this.readEntityCodes<AttributeDefinition>(new CadAttributeTemplate(new AttributeDefinition()), this.readAttributeDefinition);
1,260✔
153
                                case DxfFileToken.EntityArc:
154
                                        return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), this.readArc);
770✔
155
                                case DxfFileToken.EntityBody:
156
                                        return this.readEntityCodes<CadBody>(new CadEntityTemplate<CadBody>(), this.readEntitySubclassMap);
×
157
                                case DxfFileToken.EntityCircle:
158
                                        return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), this.readEntitySubclassMap);
2,324✔
159
                                case DxfFileToken.EntityDimension:
160
                                        return this.readEntityCodes<Dimension>(new CadDimensionTemplate(), this.readDimension);
2,926✔
161
                                case DxfFileToken.Entity3DFace:
162
                                        return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), this.readEntitySubclassMap);
266✔
163
                                case DxfFileToken.EntityEllipse:
164
                                        return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), this.readEntitySubclassMap);
228✔
165
                                case DxfFileToken.EntityLeader:
166
                                        return this.readEntityCodes<Leader>(new CadLeaderTemplate(), this.readLeader);
228✔
167
                                case DxfFileToken.EntityLine:
168
                                        return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), this.readEntitySubclassMap);
69,200✔
169
                                case DxfFileToken.EntityLwPolyline:
170
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
4,992✔
171
                                case DxfFileToken.EntityMesh:
172
                                        return this.readEntityCodes<Mesh>(new CadMeshTemplate(), this.readMesh);
456✔
173
                                case DxfFileToken.EntityHatch:
174
                                        return this.readEntityCodes<Hatch>(new CadHatchTemplate(), this.readHatch);
1,824✔
175
                                case DxfFileToken.EntityInsert:
176
                                        return this.readEntityCodes<Insert>(new CadInsertTemplate(), this.readInsert);
6,174✔
177
                                case DxfFileToken.EntityMText:
178
                                        return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), this.readTextEntity);
7,836✔
179
                                case DxfFileToken.EntityMLine:
180
                                        return this.readEntityCodes<MLine>(new CadMLineTemplate(), this.readMLine);
684✔
181
                                case DxfFileToken.EntityPdfUnderlay:
182
                                        return this.readEntityCodes<PdfUnderlay>(new CadUnderlayTemplate<PdfUnderlayDefinition>(new PdfUnderlay()), this.readUnderlayEntity<PdfUnderlayDefinition>);
228✔
183
                                case DxfFileToken.EntityPoint:
184
                                        return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), this.readEntitySubclassMap);
10,164✔
185
                                case DxfFileToken.EntityPolyline:
186
                                        return this.readPolyline();
11,702✔
187
                                case DxfFileToken.EntityRay:
188
                                        return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), this.readEntitySubclassMap);
228✔
189
                                case DxfFileToken.EndSequence:
190
                                        return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), this.readEntitySubclassMap);
12,234✔
191
                                case DxfFileToken.EntitySolid:
192
                                        return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), this.readEntitySubclassMap);
15,458✔
193
                                case DxfFileToken.EntityTable:
194
                                        return this.readEntityCodes<TableEntity>(new CadTableEntityTemplate(), this.readTableEntity);
456✔
195
                                case DxfFileToken.EntityText:
196
                                        return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), this.readTextEntity);
15,548✔
197
                                case DxfFileToken.EntityTolerance:
198
                                        return this.readEntityCodes<Tolerance>(new CadToleranceTemplate(new Tolerance()), this.readTolerance);
684✔
199
                                case DxfFileToken.EntityVertex:
200
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
42,804✔
201
                                case DxfFileToken.EntityViewport:
202
                                        return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
1,396✔
203
                                case DxfFileToken.EntityShape:
204
                                        return this.readEntityCodes<Shape>(new CadShapeTemplate(new Shape()), this.readShape);
266✔
205
                                case DxfFileToken.EntitySpline:
206
                                        return this.readEntityCodes<Spline>(new CadSplineTemplate(), this.readSpline);
456✔
207
                                case DxfFileToken.Entity3DSolid:
208
                                        return this.readEntityCodes<Solid3D>(new CadSolid3DTemplate(), this.readEntitySubclassMap);
456✔
209
                                case DxfFileToken.EntityRegion:
210
                                        return this.readEntityCodes<Region>(new CadEntityTemplate<Region>(), this.readEntitySubclassMap);
228✔
211
                                case DxfFileToken.EntityImage:
212
                                        return this.readEntityCodes<RasterImage>(new CadWipeoutBaseTemplate(new RasterImage()), this.readWipeoutBase);
228✔
213
                                case DxfFileToken.EntityWipeout:
214
                                        return this.readEntityCodes<Wipeout>(new CadWipeoutBaseTemplate(new Wipeout()), this.readWipeoutBase);
228✔
215
                                case DxfFileToken.EntityXline:
216
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
228✔
217
                                default:
218
                                        DxfMap map = DxfMap.Create<Entity>();
3,420✔
219
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
3,420✔
220
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
3,420✔
221
                                        {
3,240✔
222
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
3,240✔
223
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
3,240✔
224
                                        }
3,240✔
225
                                        else
226
                                        {
180✔
227
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
180✔
228
                                        }
180✔
229

230
                                        this._reader.ReadNext();
3,420✔
231

232
                                        do
233
                                        {
414,072✔
234
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
414,072✔
235
                                                {
43,404✔
236
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
43,404✔
237
                                                        if (isExtendedData)
43,404✔
238
                                                                continue;
180✔
239
                                                }
43,224✔
240

241
                                                this._reader.ReadNext();
413,892✔
242
                                        }
413,892✔
243
                                        while (this._reader.DxfCode != DxfCode.Start);
414,072✔
244

245
                                        return unknownEntityTemplate;
3,420✔
246
                        }
247
                }
216,644✔
248

249
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
250
                        where T : Entity
251
                {
213,298✔
252
                        this._reader.ReadNext();
213,298✔
253

254
                        DxfMap map = DxfMap.Create<T>();
213,298✔
255

256
                        while (this._reader.DxfCode != DxfCode.Start)
2,773,348✔
257
                        {
2,560,050✔
258
                                if (!readEntity(template, map))
2,560,050✔
259
                                {
1,140,520✔
260
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
1,140,520✔
261
                                        if (isExtendedData)
1,140,520✔
262
                                                continue;
13,490✔
263
                                }
1,127,030✔
264

265
                                if (this._reader.DxfCode != DxfCode.Start)
2,546,560✔
266
                                        this._reader.ReadNext();
2,546,030✔
267
                        }
2,546,560✔
268

269
                        return template;
213,298✔
270
                }
213,298✔
271

272
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
273
                {
1,259,346✔
274
                        isExtendedData = false;
1,259,346✔
275
                        switch (this._reader.Code)
1,259,346✔
276
                        {
277
                                case 6:
278
                                        template.LineTypeName = this._reader.ValueAsString;
28,856✔
279
                                        break;
28,856✔
280
                                case 8:
281
                                        template.LayerName = this._reader.ValueAsString;
232,076✔
282
                                        break;
232,076✔
283
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
284
                                case 67:
285
                                        break;
1,376✔
286
                                //Number of bytes Proxy entity graphics data
287
                                case 92:
288
                                case 160:
289
                                //Proxy entity graphics data
290
                                case 310:
291
                                        break;
59,854✔
292
                                case 347:
293
                                        template.MaterialHandle = this._reader.ValueAsHandle;
152✔
294
                                        break;
152✔
295
                                case 430:
296
                                        template.BookColorName = this._reader.ValueAsString;
190✔
297
                                        break;
190✔
298
                                default:
299
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
936,842✔
300
                                        {
788,130✔
301
                                                this.readCommonCodes(template, out isExtendedData, map);
788,130✔
302
                                        }
788,130✔
303
                                        break;
936,842✔
304
                        }
305
                }
1,259,346✔
306

307
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
308
                {
720✔
309
                        if (this._reader.DxfCode == DxfCode.Start)
720✔
310
                        {
504✔
311
                                return true;
504✔
312
                        }
313
                        else
314
                        {
216✔
315
                                return func.Invoke(template, map);
216✔
316
                        }
317
                }
720✔
318

319
                protected bool checkEntityEnd(CadEntityTemplate template, DxfMap map, string subclass, Func<CadEntityTemplate, DxfMap, string, bool> func)
320
                {
456✔
321
                        if (this._reader.DxfCode == DxfCode.Start)
456!
322
                        {
456✔
323
                                return true;
456✔
324
                        }
325
                        else
NEW
326
                        {
×
NEW
327
                                return func.Invoke(template, map, subclass);
×
328
                        }
329
                }
456✔
330

331
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
332
                {
10,096✔
333
                        switch (this._reader.Code)
10,096✔
334
                        {
335
                                default:
336
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
10,096✔
337
                                        {
8,556✔
338
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
8,556✔
339
                                        }
340
                                        return true;
1,540✔
341
                        }
342
                }
10,096✔
343

344
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
345
                {
37,510✔
346
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
37,510✔
347
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
37,510✔
348

349
                        switch (this._reader.Code)
37,510!
350
                        {
351
                                case 44:
352
                                case 46:
353
                                        return true;
×
354
                                case 101:
355
                                        var att = tmp.CadObject as AttributeBase;
74✔
356
                                        att.MText = new MText();
74✔
357
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
74✔
358
                                        tmp.MTextTemplate = mtextTemplate;
74✔
359
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
74✔
360
                                        return true;
74✔
361
                                default:
362
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
37,436✔
363
                                        {
28,322✔
364
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
28,322✔
365
                                        }
366
                                        return true;
9,114✔
367
                        }
368
                }
37,510✔
369

370
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
371
                {
150,138✔
372
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
150,138!
373
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
150,138✔
374
                        TableEntity table = tmp.CadObject as TableEntity;
150,138✔
375

376
                        switch (this._reader.Code)
150,138✔
377
                        {
378
                                case 2:
379
                                        tmp.BlockName = this._reader.ValueAsString;
456✔
380
                                        return true;
456✔
381
                                case 342:
382
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
456✔
383
                                        return true;
456✔
384
                                case 343:
385
                                        tmp.BlockOwnerHandle = this._reader.ValueAsHandle;
456✔
386
                                        return true;
456✔
387
                                case 141:
388
                                        var row = new TableEntity.Row();
2,508✔
389
                                        row.Height = this._reader.ValueAsDouble;
2,508✔
390
                                        table.Rows.Add(row);
2,508✔
391
                                        return true;
2,508✔
392
                                case 142:
393
                                        var col = new TableEntity.Column();
1,824✔
394
                                        col.Width = this._reader.ValueAsDouble;
1,824✔
395
                                        table.Columns.Add(col);
1,824✔
396
                                        return true;
1,824✔
397
                                case 144:
398
                                        tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
456✔
399
                                        return true;
456✔
400
                                case 145:
401
                                        tmp.CurrentCell.Rotation = this._reader.ValueAsDouble;
9,348✔
402
                                        return true;
9,348✔
403
                                case 170:
404
                                        //Has data flag
405
                                        return true;
684✔
406
                                case 171:
407
                                        tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
9,348✔
408
                                        return true;
9,348✔
409
                                case 172:
410
                                        tmp.CurrentCell.FlagValue = this._reader.ValueAsInt;
9,348✔
411
                                        return true;
9,348✔
412
                                case 173:
413
                                        tmp.CurrentCell.MergedValue = this._reader.ValueAsInt;
9,348✔
414
                                        return true;
9,348✔
415
                                case 174:
416
                                        tmp.CurrentCell.Autofit = this._reader.ValueAsBool;
9,348✔
417
                                        return true;
9,348✔
418
                                case 175:
419
                                        tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
9,348✔
420
                                        return true;
9,348✔
421
                                case 176:
422
                                        tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
9,348✔
423
                                        return true;
9,348✔
424
                                case 178:
425
                                        tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
9,348✔
426
                                        return true;
9,348✔
427
                                case 179:
428
                                        //Unknown value
429
                                        return true;
456✔
430
                                case 301:
431
                                        var content = new TableEntity.CellContent();
6,232✔
432
                                        tmp.CurrentCell.Contents.Add(content);
6,232✔
433
                                        this.readCellValue(content);
6,232✔
434
                                        return true;
6,232✔
435
                                case 340:
436
                                        tmp.CurrentCellTemplate.BlockRecordHandle = this._reader.ValueAsHandle;
456✔
437
                                        return true;
456✔
438
                                default:
439
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
61,370✔
440
                                        {
59,774✔
441
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
59,774✔
442
                                        }
443
                                        return true;
1,596✔
444
                        }
445
                }
150,138✔
446

447
                private void readCellValue(TableEntity.CellContent content)
448
                {
6,232✔
449
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
6,232!
450
                        {
6,232✔
451
                                this._reader.ReadNext();
6,232✔
452
                        }
6,232✔
453
                        else
454
                        {
×
455
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
456
                        }
457

458
                        while (this._reader.Code != 304
40,736✔
459
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
40,736✔
460
                        {
34,504✔
461
                                switch (this._reader.Code)
34,504!
462
                                {
463
                                        case 1:
464
                                                content.Value.Text = this._reader.ValueAsString;
1,824✔
465
                                                break;
1,824✔
466
                                        case 2:
467
                                                content.Value.Text += this._reader.ValueAsString;
×
468
                                                break;
×
469
                                        case 11:
470
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
152✔
471
                                                break;
152✔
472
                                        case 21:
473
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
152✔
474
                                                break;
152✔
475
                                        case 31:
476
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
152✔
477
                                                break;
152✔
478
                                        case 302:
479
                                                //TODO: Fix this assignation to cell value
480
                                                content.Value.Value = this._reader.ValueAsString;
6,232✔
481
                                                break;
6,232✔
482
                                        case 90:
483
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
6,232✔
484
                                                break;
6,232✔
485
                                        case 91:
486
                                                content.Value.Value = this._reader.ValueAsInt;
152✔
487
                                                break;
152✔
488
                                        case 93:
489
                                                content.Value.Flags = this._reader.ValueAsInt;
6,232✔
490
                                                break;
6,232✔
491
                                        case 94:
492
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
6,232✔
493
                                                break;
6,232✔
494
                                        case 140:
495
                                                content.Value.Value = this._reader.ValueAsDouble;
608✔
496
                                                break;
608✔
497
                                        case 300:
498
                                                content.Value.Format = this._reader.ValueAsString;
6,232✔
499
                                                break;
6,232✔
500
                                        default:
501
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
304✔
502
                                                break;
304✔
503
                                }
504

505
                                this._reader.ReadNext();
34,504✔
506
                        }
34,504✔
507
                }
6,232✔
508

509
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
510
                {
323,406✔
511
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
323,406✔
512
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
323,406✔
513

514
                        switch (this._reader.Code)
323,406✔
515
                        {
516
                                //TODO: Implement multiline text def codes
517
                                case 1 or 3 when tmp.CadObject is MText mtext:
28,746✔
518
                                        mtext.Value += this._reader.ValueAsString;
10,874✔
519
                                        return true;
10,874✔
520
                                case 50 when tmp.CadObject is MText mtext://Read only for MText
540!
521
                                        double angle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
522
                                        mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
523
                                        return true;
×
524
                                case 70:
525
                                case 74:
526
                                case 101:
527
                                        return true;
456✔
528
                                case 7:
529
                                        tmp.StyleName = this._reader.ValueAsString;
2,926✔
530
                                        return true;
2,926✔
531
                                default:
532
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
309,150✔
533
                        }
534
                }
323,406✔
535

536
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
537
                {
6,840✔
538
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,840✔
539

540
                        switch (this._reader.Code)
6,840✔
541
                        {
542
                                case 3:
543
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
684✔
544
                                        return true;
684✔
545
                                default:
546
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
6,156✔
547
                        }
548
                }
6,840✔
549

550
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
551
                {
76,532✔
552
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
76,532✔
553

554
                        switch (this._reader.Code)
76,532✔
555
                        {
556
                                case 2:
557
                                        tmp.BlockName = this._reader.ValueAsString;
2,926✔
558
                                        return true;
2,926✔
559
                                case 3:
560
                                        tmp.StyleName = this._reader.ValueAsString;
2,508✔
561
                                        return true;
2,508✔
562
                                case 50:
563
                                        var dim = new DimensionLinear();
266✔
564
                                        tmp.SetDimensionObject(dim);
266✔
565
                                        dim.Rotation = this._reader.ValueAsAngle;
266✔
566
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
266✔
567
                                        return true;
266✔
568
                                case 70:
569
                                        //Flags do not have set
570
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,926✔
571
                                        return true;
2,926✔
572
                                //Measurement - read only
573
                                case 42:
574
                                        return true;
2,508✔
575
                                //Undocumented codes
576
                                case 73:
577
                                case 74:
578
                                case 75:
579
                                case 90:
580
                                case 361:
581
                                        return true;
5,016✔
582
                                case 100:
583
                                        switch (this._reader.ValueAsString)
8,208✔
584
                                        {
585
                                                case DxfSubclassMarker.Dimension:
586
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,508✔
587
                                                case DxfSubclassMarker.AlignedDimension:
588
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,140✔
589
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,140✔
590
                                                        return true;
1,140✔
591
                                                case DxfSubclassMarker.DiametricDimension:
592
                                                        tmp.SetDimensionObject(new DimensionDiameter());
228✔
593
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
228✔
594
                                                        return true;
228✔
595
                                                case DxfSubclassMarker.Angular2LineDimension:
596
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
228✔
597
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
228✔
598
                                                        return true;
228✔
599
                                                case DxfSubclassMarker.Angular3PointDimension:
600
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
228✔
601
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
228✔
602
                                                        return true;
228✔
603
                                                case DxfSubclassMarker.RadialDimension:
604
                                                        tmp.SetDimensionObject(new DimensionRadius());
228✔
605
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
228✔
606
                                                        return true;
228✔
607
                                                case DxfSubclassMarker.OrdinateDimension:
608
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
456✔
609
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
456✔
610
                                                        return true;
456✔
611
                                                case DxfSubclassMarker.LinearDimension:
612
                                                        return true;
684✔
613
                                                default:
614
                                                        return false;
2,508✔
615
                                        }
616
                                default:
617
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
52,174✔
618
                        }
619
                }
76,532✔
620

621
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
622
                {
45,600✔
623
                        CadHatchTemplate tmp = template as CadHatchTemplate;
45,600✔
624
                        Hatch hatch = tmp.CadObject;
45,600✔
625

626
                        bool isFirstSeed = true;
45,600✔
627
                        XY seedPoint = new XY();
45,600✔
628

629
                        switch (this._reader.Code)
45,600!
630
                        {
631
                                case 2:
632
                                        hatch.Pattern.Name = this._reader.ValueAsString;
1,824✔
633
                                        return true;
1,824✔
634
                                case 10:
635
                                        seedPoint.X = this._reader.ValueAsDouble;
2,964✔
636
                                        return true;
2,964✔
637
                                case 20:
638
                                        if (!isFirstSeed)
3,648!
639
                                        {
×
640
                                                seedPoint.Y = this._reader.ValueAsDouble;
×
641
                                                hatch.SeedPoints.Add(seedPoint);
×
642
                                        }
×
643
                                        return true;
3,648✔
644
                                case 30:
645
                                        hatch.Elevation = this._reader.ValueAsDouble;
1,824✔
646
                                        isFirstSeed = false;
1,824✔
647
                                        return true;
1,824✔
648
                                case 53:
649
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
650
                                        return true;
×
651
                                //TODO: Check hatch undocumented codes
652
                                case 90:
653
                                        return true;
×
654
                                //Information about the hatch pattern
655
                                case 75:
656
                                        return true;
×
657
                                //Number of pattern definition lines
658
                                case 78:
659
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
1,368✔
660
                                        return true;
1,368✔
661
                                //Number of boundary paths (loops)
662
                                case 91:
663
                                        this.readLoops(tmp, this._reader.ValueAsInt);
1,824✔
664
                                        return true;
1,824✔
665
                                //Number of seed points
666
                                case 98:
667
                                        return true;
456✔
668
                                case 450:
669
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
380✔
670
                                        return true;
380✔
671
                                case 451:
672
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
380✔
673
                                        return true;
380✔
674
                                case 452:
675
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
380✔
676
                                        return true;
380✔
677
                                case 453:
678
                                        //Number of colors
679
                                        return true;
380✔
680
                                case 460:
681
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
380✔
682
                                        return true;
380✔
683
                                case 461:
684
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
380✔
685
                                        return true;
380✔
686
                                case 462:
687
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
380✔
688
                                        return true;
380✔
689
                                case 463:
690
                                        GradientColor gradient = new GradientColor();
760✔
691
                                        gradient.Value = this._reader.ValueAsDouble;
760✔
692
                                        hatch.GradientColor.Colors.Add(gradient);
760✔
693
                                        return true;
760✔
694
                                case 63:
695
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
760✔
696
                                        if (colorByIndex != null)
760✔
697
                                        {
760✔
698
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
760✔
699
                                        }
760✔
700
                                        return true;
760✔
701
                                case 421:
702
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
760✔
703
                                        if (colorByRgb != null)
760✔
704
                                        {
760✔
705
                                                //TODO: Hatch assign color by true color
706
                                                //TODO: Is always duplicated by 63, is it needed??
707
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
708
                                        }
760✔
709
                                        return true;
760✔
710
                                case 470:
711
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
380✔
712
                                        return true;
380✔
713
                                default:
714
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
26,372✔
715
                        }
716
                }
45,600✔
717

718
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
719
                {
66,044✔
720
                        CadInsertTemplate tmp = template as CadInsertTemplate;
66,044✔
721

722
                        switch (this._reader.Code)
66,044✔
723
                        {
724
                                case 2:
725
                                        tmp.BlockName = this._reader.ValueAsString;
6,174✔
726
                                        return true;
6,174✔
727
                                case 100:
728
                                        //AcDbEntity
729
                                        //AcDbBlockReference
730
                                        //AcDbMInsertBlock
731
                                        return true;
6,192✔
732
                                case 66:
733
                                        return true;
532✔
734
                                default:
735
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
53,146✔
736
                        }
737
                }
66,044✔
738

739
                private CadEntityTemplate readPolyline()
740
                {
11,702✔
741
                        CadPolyLineTemplate template = null;
11,702✔
742

743
                        if (this._builder.Version == ACadVersion.Unknown)
11,702!
744
                        {
×
745
                                var polyline = new Polyline2D();
×
746
                                template = new CadPolyLineTemplate(polyline);
×
747
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
×
748

749
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
×
750
                                {
×
751
                                        Vertex2D v = new Vertex2D();
×
752
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
×
753
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
×
754

755
                                        if (vertexTemplate.Vertex.Handle == 0)
×
756
                                        {
×
757
                                                polyline.Vertices.Add(v);
×
758
                                        }
×
759
                                        else
760
                                        {
×
761
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
762
                                                this._builder.AddTemplate(vertexTemplate);
×
763
                                        }
×
764
                                }
×
765

766
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
×
767
                                {
×
768
                                        var seqend = new Seqend();
×
769
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
×
770
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
×
771

772
                                        polyline.Vertices.Seqend = seqend;
×
773
                                }
×
774
                        }
×
775
                        else
776
                        {
11,702✔
777
                                template = new CadPolyLineTemplate();
11,702✔
778
                                this.readEntityCodes<Entity>(template, this.readPolyline);
11,702✔
779
                        }
11,702✔
780

781
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
11,702✔
782
                        {
11,246✔
783
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
11,246✔
784
                                return null;
11,246✔
785
                        }
786

787
                        return template;
456✔
788
                }
11,702✔
789

790
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
791
                {
84,038✔
792
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
84,038✔
793

794
                        switch (this._reader.Code)
84,038✔
795
                        {
796
                                //DXF: always 0
797
                                //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)
798
                                case 10:
799
                                case 20:
800
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
801
                                case 66:
802
                                //Polygon mesh M vertex count (optional; default = 0)
803
                                case 71:
804
                                //Polygon mesh N vertex count(optional; default = 0)
805
                                case 72:
806
                                //Smooth surface M density(optional; default = 0)
807
                                case 73:
808
                                //Smooth surface N density (optional; default = 0)
809
                                case 74:
810
                                        return true;
35,638✔
811
                                case 100:
812
                                        switch (this._reader.ValueAsString)
912!
813
                                        {
814
                                                case DxfSubclassMarker.Polyline:
815
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
816
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
817
                                                        return true;
×
818
                                                case DxfSubclassMarker.Polyline3d:
819
                                                        tmp.SetPolyLineObject(new Polyline3D());
228✔
820
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
228✔
821
                                                        return true;
228✔
822
                                                case DxfSubclassMarker.PolyfaceMesh:
823
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
228✔
824
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
228✔
825
                                                        return true;
228✔
826
                                                default:
827
                                                        return false;
456✔
828
                                        }
829
                                default:
830
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
47,488✔
831
                        }
832
                }
84,038✔
833

834
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
835
                {
5,700✔
836
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,700✔
837

838
                        switch (this._reader.Code)
5,700✔
839
                        {
840
                                case 3:
841
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
228✔
842
                                        return true;
228✔
843
                                case 10:
844
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
912✔
845
                                        return true;
912✔
846
                                case 20:
847
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
912✔
848
                                        y.Y = this._reader.ValueAsDouble;
912✔
849
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
912✔
850
                                        return true;
912✔
851
                                case 30:
852
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
912✔
853
                                        z.Z = this._reader.ValueAsDouble;
912✔
854
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
912✔
855
                                        return true;
912✔
856
                                case 340:
857
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
228✔
858
                                        return true;
228✔
859
                                //Hook line flag - read only
860
                                case 75:
861
                                //Vertices count
862
                                case 76:
863
                                        return true;
456✔
864
                                default:
865
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,052✔
866
                        }
867
                }
5,700✔
868

869
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
870
                {
93,660✔
871
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
93,660✔
872

873
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
93,660✔
874

875
                        switch (this._reader.Code)
93,660!
876
                        {
877
                                case 10:
878
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
22,236✔
879
                                        return true;
22,236✔
880
                                case 20:
881
                                        if (last is not null)
22,236✔
882
                                        {
22,236✔
883
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
22,236✔
884
                                        }
22,236✔
885
                                        return true;
22,236✔
886
                                case 40:
887
                                        if (last is not null)
2,280✔
888
                                        {
2,280✔
889
                                                last.StartWidth = this._reader.ValueAsDouble;
2,280✔
890
                                        }
2,280✔
891
                                        return true;
2,280✔
892
                                case 41:
893
                                        if (last is not null)
2,280✔
894
                                        {
2,280✔
895
                                                last.EndWidth = this._reader.ValueAsDouble;
2,280✔
896
                                        }
2,280✔
897
                                        return true;
2,280✔
898
                                case 42:
899
                                        if (last is not null)
3,120✔
900
                                        {
3,120✔
901
                                                last.Bulge = this._reader.ValueAsDouble;
3,120✔
902
                                        }
3,120✔
903
                                        return true;
3,120✔
904
                                case 50:
905
                                        if (last is not null)
×
906
                                        {
×
907
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
908
                                        }
×
909
                                        return true;
×
910
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
911
                                case 66:
912
                                //Vertex count
913
                                case 90:
914
                                        return true;
4,992✔
915
                                case 91:
916
                                        if (last is not null)
×
917
                                        {
×
918
                                                last.Id = this._reader.ValueAsInt;
×
919
                                        }
×
920
                                        return true;
×
921
                                default:
922
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
36,516✔
923
                        }
924
                }
93,660✔
925

926
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
927
                {
40,128✔
928
                        CadMeshTemplate tmp = template as CadMeshTemplate;
40,128✔
929

930
                        switch (this._reader.Code)
40,128✔
931
                        {
932
                                case 100:
933
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
912✔
934
                                        {
456✔
935
                                                tmp.SubclassMarker = true;
456✔
936
                                        }
456✔
937
                                        return true;
912✔
938
                                //Count of sub-entity which property has been overridden
939
                                case 90:
940
                                        //TODO: process further entities
941
                                        return true;
456✔
942
                                case 92:
943
                                        if (!tmp.SubclassMarker)
684✔
944
                                        {
228✔
945
                                                return false;
228✔
946
                                        }
947

948
                                        int nvertices = this._reader.ValueAsInt;
456✔
949
                                        for (int i = 0; i < nvertices; i++)
58,368✔
950
                                        {
28,728✔
951
                                                this._reader.ReadNext();
28,728✔
952
                                                double x = this._reader.ValueAsDouble;
28,728✔
953
                                                this._reader.ReadNext();
28,728✔
954
                                                double y = this._reader.ValueAsDouble;
28,728✔
955
                                                this._reader.ReadNext();
28,728✔
956
                                                double z = this._reader.ValueAsDouble;
28,728✔
957
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
28,728✔
958
                                        }
28,728✔
959
                                        return true;
456✔
960
                                case 93:
961
                                        int size = this._reader.ValueAsInt;
456✔
962
                                        this._reader.ReadNext();
456✔
963

964
                                        int indexes = 0;
456✔
965
                                        for (int i = 0; i < size; i += indexes + 1)
62,928✔
966
                                        {
31,008✔
967
                                                indexes = this._reader.ValueAsInt;
31,008✔
968
                                                this._reader.ReadNext();
31,008✔
969

970
                                                int[] face = new int[indexes];
31,008✔
971
                                                for (int j = 0; j < indexes; j++)
299,136✔
972
                                                {
118,560✔
973
                                                        face[j] = this._reader.ValueAsInt;
118,560✔
974

975
                                                        if ((i + j + 2) < size)
118,560✔
976
                                                        {
118,104✔
977
                                                                this._reader.ReadNext();
118,104✔
978
                                                        }
118,104✔
979
                                                }
118,560✔
980

981
                                                tmp.CadObject.Faces.Add(face);
31,008✔
982
                                        }
31,008✔
983

984
                                        Debug.Assert(this._reader.Code == 90);
456✔
985

986
                                        return true;
456✔
987
                                case 94:
988
                                        int numEdges = this._reader.ValueAsInt;
456✔
989
                                        this._reader.ReadNext();
456✔
990
                                        for (int i = 0; i < numEdges; i++)
119,472✔
991
                                        {
59,280✔
992
                                                Mesh.Edge edge = new Mesh.Edge();
59,280✔
993

994
                                                edge.Start = this._reader.ValueAsInt;
59,280✔
995
                                                this._reader.ReadNext();
59,280✔
996
                                                edge.End = this._reader.ValueAsInt;
59,280✔
997

998
                                                if (i < numEdges - 1)
59,280✔
999
                                                {
58,824✔
1000
                                                        this._reader.ReadNext();
58,824✔
1001
                                                }
58,824✔
1002

1003
                                                tmp.CadObject.Edges.Add(edge);
59,280✔
1004
                                        }
59,280✔
1005

1006
                                        Debug.Assert(this._reader.Code == 90);
456✔
1007

1008
                                        return true;
456✔
1009
                                case 95:
1010
                                        this._reader.ReadNext();
456✔
1011
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
119,472✔
1012
                                        {
59,280✔
1013
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
59,280✔
1014
                                                edge.Crease = this._reader.ValueAsDouble;
59,280✔
1015

1016
                                                tmp.CadObject.Edges[i] = edge;
59,280✔
1017

1018
                                                if (i < tmp.CadObject.Edges.Count - 1)
59,280✔
1019
                                                {
58,824✔
1020
                                                        this._reader.ReadNext();
58,824✔
1021
                                                }
58,824✔
1022
                                        }
59,280✔
1023

1024
                                        Debug.Assert(this._reader.Code == 140);
456✔
1025

1026
                                        return true;
456✔
1027
                                default:
1028
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
36,708✔
1029
                        }
1030
                }
40,128✔
1031

1032
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1033
                {
59,280✔
1034
                        CadMLineTemplate tmp = template as CadMLineTemplate;
59,280✔
1035

1036
                        switch (this._reader.Code)
59,280✔
1037
                        {
1038
                                // 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.
1039
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1040
                                case 2:
1041
                                        tmp.MLineStyleName = this._reader.ValueAsString;
684✔
1042
                                        return true;
684✔
1043
                                case 72:
1044
                                        tmp.NVertex = this._reader.ValueAsInt;
684✔
1045
                                        return true;
684✔
1046
                                case 73:
1047
                                        tmp.NElements = this._reader.ValueAsInt;
684✔
1048
                                        return true;
684✔
1049
                                case 340:
1050
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
684✔
1051
                                        return true;
684✔
1052
                                default:
1053
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
56,544✔
1054
                                        {
9,576✔
1055
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
9,576✔
1056
                                        }
1057
                                        return true;
46,968✔
1058
                        }
1059
                }
59,280✔
1060

1061
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1062
                {
2,546✔
1063
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,546✔
1064

1065
                        switch (this._reader.Code)
2,546✔
1066
                        {
1067
                                case 2:
1068
                                        tmp.ShapeFileName = this._reader.ValueAsString;
266✔
1069
                                        return true;
266✔
1070
                                default:
1071
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,280✔
1072
                        }
1073
                }
2,546✔
1074

1075
                private bool readWipeoutBase(CadEntityTemplate template, DxfMap map, string subclass = null)
1076
                {
13,452✔
1077
                        CadWipeoutBaseTemplate tmp = template as CadWipeoutBaseTemplate;
13,452✔
1078
                        CadWipeoutBase wipeout = tmp.CadObject as CadWipeoutBase;
13,452✔
1079

1080
                        switch (this._reader.Code)
13,452✔
1081
                        {
1082
                                case 91:
1083
                                        var nvertices = this._reader.ValueAsInt;
456✔
1084
                                        for (int i = 0; i < nvertices; i++)
4,104✔
1085
                                        {
1,596✔
1086
                                                this._reader.ReadNext();
1,596✔
1087
                                                var x = this._reader.ValueAsDouble;
1,596✔
1088
                                                this._reader.ReadNext();
1,596✔
1089
                                                var y = this._reader.ValueAsDouble;
1,596✔
1090

1091
                                                wipeout.ClipBoundaryVertices.Add(new XY(x, y));
1,596✔
1092
                                        }
1,596✔
1093

1094
                                        this._reader.ReadNext();
456✔
1095

1096
                                        return this.checkEntityEnd(template, map, subclass, this.readWipeoutBase);
456✔
1097
                                case 340:
1098
                                        tmp.ImgDefHandle = this._reader.ValueAsHandle;
456✔
1099
                                        return true;
456✔
1100
                                case 360:
1101
                                        tmp.ImgReactorHandle = this._reader.ValueAsHandle;
456✔
1102
                                        return true;
456✔
1103
                                default:
1104
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
12,084✔
1105
                        }
1106
                }
13,452✔
1107

1108
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1109
                {
15,960✔
1110
                        CadSplineTemplate tmp = template as CadSplineTemplate;
15,960✔
1111

1112
                        XYZ controlPoint;
1113
                        XYZ fitPoint;
1114

1115
                        switch (this._reader.Code)
15,960!
1116
                        {
1117
                                case 10:
1118
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,824✔
1119
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,824✔
1120
                                        return true;
1,824✔
1121
                                case 20:
1122
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1123
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,824✔
1124
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1125
                                        return true;
1,824✔
1126
                                case 30:
1127
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1128
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,824✔
1129
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1130
                                        return true;
1,824✔
1131
                                case 11:
1132
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1133
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1134
                                        return true;
×
1135
                                case 21:
1136
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1137
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1138
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1139
                                        return true;
×
1140
                                case 31:
1141
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1142
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1143
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1144
                                        return true;
×
1145
                                case 40:
1146
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,648✔
1147
                                        return true;
3,648✔
1148
                                case 41:
1149
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1150
                                        return true;
×
1151
                                case 72:
1152
                                case 73:
1153
                                case 74:
1154
                                        return true;
1,368✔
1155
                                default:
1156
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
5,472✔
1157
                        }
1158
                }
15,960✔
1159

1160
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1161
                        where T : PdfUnderlayDefinition
1162
                {
3,610✔
1163
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,610✔
1164

1165
                        switch (this._reader.Code)
3,610✔
1166
                        {
1167
                                case 340:
1168
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
228✔
1169
                                        return true;
228✔
1170
                                default:
1171
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,382✔
1172
                        }
1173
                }
3,610✔
1174

1175
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1176
                {
266,368✔
1177
                        CadVertexTemplate tmp = template as CadVertexTemplate;
266,368✔
1178

1179
                        switch (this._reader.Code)
266,368✔
1180
                        {
1181
                                //Polyface mesh vertex index
1182
                                case 71:
1183
                                case 72:
1184
                                case 73:
1185
                                case 74:
1186
                                        return true;
1,862✔
1187
                                case 100:
1188
                                        switch (this._reader.ValueAsString)
7,752!
1189
                                        {
1190
                                                case DxfSubclassMarker.Vertex:
1191
                                                        return true;
2,280✔
1192
                                                case DxfSubclassMarker.PolylineVertex:
1193
                                                        tmp.SetVertexObject(new Vertex2D());
×
1194
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1195
                                                        return true;
×
1196
                                                case DxfSubclassMarker.Polyline3dVertex:
1197
                                                        tmp.SetVertexObject(new Vertex3D());
1,140✔
1198
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,140✔
1199
                                                        return true;
1,140✔
1200
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1201
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,140✔
1202
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,140✔
1203
                                                        return true;
1,140✔
1204
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1205
                                                        tmp.SetVertexObject(new VertexFaceRecord());
456✔
1206
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
456✔
1207
                                                        return true;
456✔
1208
                                                default:
1209
                                                        return false;
2,736✔
1210
                                        }
1211
                                default:
1212
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
256,754✔
1213
                        }
1214
                }
266,368✔
1215

1216
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1217
                {
76,296✔
1218
                        CadViewportTemplate tmp = template as CadViewportTemplate;
76,296✔
1219

1220
                        switch (this._reader.Code)
76,296!
1221
                        {
1222
                                //Undocumented
1223
                                case 67:
1224
                                case 68:
1225
                                        return true;
2,792✔
1226
                                case 69:
1227
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,396✔
1228
                                        return true;
1,396✔
1229
                                case 331:
1230
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1231
                                        return true;
×
1232
                                case 348:
1233
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
880✔
1234
                                        return true;
880✔
1235
                                default:
1236
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
71,228✔
1237
                        }
1238
                }
76,296✔
1239

1240
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1241
                {
1,279,498✔
1242
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
1,279,498✔
1243

1244
                        switch (this._reader.Code)
1,279,498✔
1245
                        {
1246
                                default:
1247
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
1,279,498✔
1248
                        }
1249
                }
1,279,498✔
1250

1251
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1252
                {
38,840✔
1253
                        List<ExtendedDataRecord> records = new();
38,840✔
1254
                        edata.Add(this._reader.ValueAsString, records);
38,840✔
1255

1256
                        this._reader.ReadNext();
38,840✔
1257

1258
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
308,541✔
1259
                        {
281,829✔
1260
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
281,829✔
1261
                                {
12,128✔
1262
                                        this.readExtendedData(edata);
12,128✔
1263
                                        break;
12,128✔
1264
                                }
1265

1266
                                ExtendedDataRecord record = null;
269,701✔
1267
                                double x = 0;
269,701✔
1268
                                double y = 0;
269,701✔
1269
                                double z = 0;
269,701✔
1270

1271
                                switch (this._reader.DxfCode)
269,701✔
1272
                                {
1273
                                        case DxfCode.ExtendedDataAsciiString:
1274
                                        case DxfCode.ExtendedDataRegAppName:
1275
                                                record = new ExtendedDataString(this._reader.ValueAsString);
28,727✔
1276
                                                break;
28,727✔
1277
                                        case DxfCode.ExtendedDataControlString:
1278
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
15,056✔
1279
                                                break;
15,056✔
1280
                                        case DxfCode.ExtendedDataLayerName:
1281
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
266✔
1282
                                                {
252✔
1283
                                                        record = new ExtendedDataLayer(layer.Handle);
252✔
1284
                                                }
252✔
1285
                                                else
1286
                                                {
14✔
1287
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1288
                                                }
14✔
1289
                                                break;
266✔
1290
                                        case DxfCode.ExtendedDataBinaryChunk:
1291
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
76✔
1292
                                                break;
76✔
1293
                                        case DxfCode.ExtendedDataHandle:
1294
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,808✔
1295
                                                break;
2,808✔
1296
                                        case DxfCode.ExtendedDataXCoordinate:
1297
                                                x = this._reader.ValueAsDouble;
2,836✔
1298
                                                this._reader.ReadNext();
2,836✔
1299
                                                y = this._reader.ValueAsDouble;
2,836✔
1300
                                                this._reader.ReadNext();
2,836✔
1301
                                                z = this._reader.ValueAsDouble;
2,836✔
1302

1303
                                                record = new ExtendedDataCoordinate(
2,836✔
1304
                                                        new XYZ(
2,836✔
1305
                                                                x,
2,836✔
1306
                                                                y,
2,836✔
1307
                                                                z)
2,836✔
1308
                                                        );
2,836✔
1309
                                                break;
2,836✔
1310
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1311
                                                x = this._reader.ValueAsDouble;
1,368✔
1312
                                                this._reader.ReadNext();
1,368✔
1313
                                                y = this._reader.ValueAsDouble;
1,368✔
1314
                                                this._reader.ReadNext();
1,368✔
1315
                                                z = this._reader.ValueAsDouble;
1,368✔
1316

1317
                                                record = new ExtendedDataWorldCoordinate(
1,368✔
1318
                                                        new XYZ(
1,368✔
1319
                                                                x,
1,368✔
1320
                                                                y,
1,368✔
1321
                                                                z)
1,368✔
1322
                                                        );
1,368✔
1323
                                                break;
1,368✔
1324
                                        case DxfCode.ExtendedDataWorldXDisp:
1325
                                                x = this._reader.ValueAsDouble;
266✔
1326
                                                this._reader.ReadNext();
266✔
1327
                                                y = this._reader.ValueAsDouble;
266✔
1328
                                                this._reader.ReadNext();
266✔
1329
                                                z = this._reader.ValueAsDouble;
266✔
1330

1331
                                                record = new ExtendedDataDisplacement(
266✔
1332
                                                        new XYZ(
266✔
1333
                                                                x,
266✔
1334
                                                                y,
266✔
1335
                                                                z)
266✔
1336
                                                        );
266✔
1337
                                                break;
266✔
1338
                                        case DxfCode.ExtendedDataWorldXDir:
1339
                                                x = this._reader.ValueAsDouble;
266✔
1340
                                                this._reader.ReadNext();
266✔
1341
                                                y = this._reader.ValueAsDouble;
266✔
1342
                                                this._reader.ReadNext();
266✔
1343
                                                z = this._reader.ValueAsDouble;
266✔
1344

1345
                                                record = new ExtendedDataDirection(
266✔
1346
                                                        new XYZ(
266✔
1347
                                                                x,
266✔
1348
                                                                y,
266✔
1349
                                                                z)
266✔
1350
                                                        );
266✔
1351
                                                break;
266✔
1352
                                        case DxfCode.ExtendedDataReal:
1353
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
133,506✔
1354
                                                break;
133,506✔
1355
                                        case DxfCode.ExtendedDataDist:
1356
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
266✔
1357
                                                break;
266✔
1358
                                        case DxfCode.ExtendedDataScale:
1359
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
266✔
1360
                                                break;
266✔
1361
                                        case DxfCode.ExtendedDataInteger16:
1362
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
72,837✔
1363
                                                break;
72,837✔
1364
                                        case DxfCode.ExtendedDataInteger32:
1365
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
8,725✔
1366
                                                break;
8,725✔
1367
                                        default:
1368
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,432✔
1369
                                                break;
2,432✔
1370
                                }
1371

1372
                                if (record != null)
269,701✔
1373
                                {
267,255✔
1374
                                        records.Add(record);
267,255✔
1375
                                }
267,255✔
1376

1377
                                this._reader.ReadNext();
269,701✔
1378
                        }
269,701✔
1379
                }
38,840✔
1380

1381
                private void readPattern(HatchPattern pattern, int nlines)
1382
                {
1,368✔
1383
                        //Jump 78 code
1384
                        this._reader.ReadNext();
1,368✔
1385

1386
                        for (int i = 0; i < nlines; i++)
207,480✔
1387
                        {
102,372✔
1388
                                HatchPattern.Line line = new HatchPattern.Line();
102,372✔
1389
                                XY basePoint = new XY();
102,372✔
1390
                                XY offset = new XY();
102,372✔
1391

1392
                                bool end = false;
102,372✔
1393
                                HashSet<int> codes = new();
102,372✔
1394

1395
                                while (!end)
717,972✔
1396
                                {
716,604✔
1397
                                        if (codes.Contains(this._reader.Code))
716,604✔
1398
                                        {
101,004✔
1399
                                                break;
101,004✔
1400
                                        }
1401
                                        else
1402
                                        {
615,600✔
1403
                                                codes.Add(this._reader.Code);
615,600✔
1404
                                        }
615,600✔
1405

1406
                                        switch (this._reader.Code)
615,600!
1407
                                        {
1408
                                                case 53:
1409
                                                        line.Angle = this._reader.ValueAsAngle;
102,372✔
1410
                                                        break;
102,372✔
1411
                                                case 43:
1412
                                                        basePoint.X = this._reader.ValueAsDouble;
102,372✔
1413
                                                        break;
102,372✔
1414
                                                case 44:
1415
                                                        basePoint.Y = this._reader.ValueAsDouble;
102,372✔
1416
                                                        line.BasePoint = basePoint;
102,372✔
1417
                                                        break;
102,372✔
1418
                                                case 45:
1419
                                                        offset.X = this._reader.ValueAsDouble;
102,372✔
1420
                                                        line.Offset = offset;
102,372✔
1421
                                                        break;
102,372✔
1422
                                                case 46:
1423
                                                        offset.Y = this._reader.ValueAsDouble;
102,372✔
1424
                                                        line.Offset = offset;
102,372✔
1425
                                                        break;
102,372✔
1426
                                                //Number of dash length items
1427
                                                case 79:
1428
                                                        int ndash = this._reader.ValueAsInt;
102,372✔
1429
                                                        for (int j = 0; j < ndash; j++)
613,320✔
1430
                                                        {
204,288✔
1431
                                                                this._reader.ReadNext();
204,288✔
1432
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
204,288✔
1433
                                                        }
204,288✔
1434
                                                        break;
102,372✔
1435
                                                case 49:
1436
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1437
                                                        break;
×
1438
                                                default:
1439
                                                        end = true;
1,368✔
1440
                                                        break;
1,368✔
1441
                                        }
1442
                                        this._reader.ReadNext();
615,600✔
1443
                                }
615,600✔
1444

1445
                                pattern.Lines.Add(line);
102,372✔
1446
                        }
102,372✔
1447
                }
1,368✔
1448

1449
                private void readLoops(CadHatchTemplate template, int count)
1450
                {
1,824✔
1451
                        if (this._reader.Code == 91)
1,824✔
1452
                                this._reader.ReadNext();
1,824✔
1453

1454
                        for (int i = 0; i < count; i++)
7,296✔
1455
                        {
1,824✔
1456
                                if (this._reader.Code != 92)
1,824!
1457
                                {
×
1458
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1459
                                        break;
×
1460
                                }
1461

1462
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,824✔
1463
                                if (path != null)
1,824✔
1464
                                        template.PathTempaltes.Add(path);
1,824✔
1465
                        }
1,824✔
1466
                }
1,824✔
1467

1468
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1469
                {
1,824✔
1470
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,824✔
1471
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,824✔
1472
                        template.Path.Flags = flags;
1,824✔
1473

1474
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,824✔
1475
                        {
684✔
1476
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
684✔
1477
                                template.Path.Edges.Add(pl);
684✔
1478
                        }
684✔
1479
                        else
1480
                        {
1,140✔
1481
                                this._reader.ReadNext();
1,140✔
1482

1483
                                if (this._reader.Code != 93)
1,140!
1484
                                {
×
1485
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1486
                                        return null;
×
1487
                                }
1488

1489
                                int edges = this._reader.ValueAsInt;
1,140✔
1490
                                this._reader.ReadNext();
1,140✔
1491

1492
                                for (int i = 0; i < edges; i++)
11,400✔
1493
                                {
4,560✔
1494
                                        var edge = this.readEdge();
4,560✔
1495
                                        if (edge != null)
4,560✔
1496
                                                template.Path.Edges.Add(edge);
4,560✔
1497
                                }
4,560✔
1498
                        }
1,140✔
1499

1500
                        bool end = false;
1,824✔
1501
                        while (!end)
7,068✔
1502
                        {
5,244✔
1503
                                switch (this._reader.Code)
5,244✔
1504
                                {
1505
                                        //Number of source boundary objects
1506
                                        case 97:
1507
                                                break;
1,824✔
1508
                                        case 330:
1509
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,596✔
1510
                                                break;
1,596✔
1511
                                        default:
1512
                                                end = true;
1,824✔
1513
                                                continue;
1,824✔
1514
                                }
1515

1516
                                this._reader.ReadNext();
3,420✔
1517
                        }
3,420✔
1518

1519
                        return template;
1,824✔
1520
                }
1,824✔
1521

1522
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1523
                {
684✔
1524
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
684✔
1525

1526
                        this._reader.ReadNext();
684✔
1527

1528
                        if (this._reader.Code != 72)
684!
1529
                        {
×
1530
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1531
                                return null;
×
1532
                        }
1533

1534
                        //72
1535
                        bool hasBulge = this._reader.ValueAsBool;
684✔
1536
                        this._reader.ReadNext();
684✔
1537

1538
                        //73
1539
                        bool isClosed = this._reader.ValueAsBool;
684✔
1540
                        this._reader.ReadNext();
684✔
1541

1542
                        //93
1543
                        int nvertices = this._reader.ValueAsInt;
684✔
1544
                        this._reader.ReadNext();
684✔
1545

1546
                        for (int i = 0; i < nvertices; i++)
6,840✔
1547
                        {
2,736✔
1548
                                double bulge = 0.0;
2,736✔
1549

1550
                                //10
1551
                                double x = this._reader.ValueAsDouble;
2,736✔
1552
                                this._reader.ReadNext();
2,736✔
1553
                                //20
1554
                                double y = this._reader.ValueAsDouble;
2,736✔
1555
                                this._reader.ReadNext();
2,736✔
1556

1557
                                if (hasBulge)
2,736!
1558
                                {
×
1559
                                        //42
1560
                                        bulge = this._reader.ValueAsDouble;
×
1561
                                        this._reader.ReadNext();
×
1562
                                }
×
1563

1564
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,736✔
1565
                        }
2,736✔
1566

1567
                        return boundary;
684✔
1568
                }
684✔
1569

1570
                private Hatch.BoundaryPath.Edge readEdge()
1571
                {
4,560✔
1572
                        if (this._reader.Code != 72)
4,560!
1573
                        {
×
1574
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1575
                                return null;
×
1576
                        }
1577

1578
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,560✔
1579
                        this._reader.ReadNext();
4,560✔
1580

1581
                        switch (type)
4,560!
1582
                        {
1583
                                case Hatch.BoundaryPath.EdgeType.Line:
1584
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,560✔
1585
                                        while (true)
22,800✔
1586
                                        {
22,800✔
1587
                                                switch (this._reader.Code)
22,800✔
1588
                                                {
1589
                                                        case 10:
1590
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,560✔
1591
                                                                break;
4,560✔
1592
                                                        case 20:
1593
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,560✔
1594
                                                                break;
4,560✔
1595
                                                        case 11:
1596
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,560✔
1597
                                                                break;
4,560✔
1598
                                                        case 21:
1599
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,560✔
1600
                                                                break;
4,560✔
1601
                                                        default:
1602
                                                                return line;
4,560✔
1603
                                                }
1604

1605
                                                this._reader.ReadNext();
18,240✔
1606
                                        }
18,240✔
1607
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1608
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1609
                                        while (true)
×
1610
                                        {
×
1611
                                                switch (this._reader.Code)
×
1612
                                                {
1613
                                                        case 10:
1614
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1615
                                                                break;
×
1616
                                                        case 20:
1617
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1618
                                                                break;
×
1619
                                                        case 40:
1620
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1621
                                                                break;
×
1622
                                                        case 50:
1623
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1624
                                                                break;
×
1625
                                                        case 51:
1626
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1627
                                                                break;
×
1628
                                                        case 73:
1629
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1630
                                                                break;
×
1631
                                                        default:
1632
                                                                return arc;
×
1633
                                                }
1634

1635
                                                this._reader.ReadNext();
×
1636
                                        }
×
1637
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1638
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1639
                                        while (true)
×
1640
                                        {
×
1641
                                                switch (this._reader.Code)
×
1642
                                                {
1643
                                                        case 10:
1644
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1645
                                                                break;
×
1646
                                                        case 20:
1647
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1648
                                                                break;
×
1649
                                                        case 11:
1650
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1651
                                                                break;
×
1652
                                                        case 21:
1653
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1654
                                                                break;
×
1655
                                                        case 40:
1656
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1657
                                                                break;
×
1658
                                                        case 50:
1659
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1660
                                                                break;
×
1661
                                                        case 51:
1662
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
1663
                                                                break;
×
1664
                                                        case 73:
1665
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
1666
                                                                break;
×
1667
                                                        default:
1668
                                                                return ellipse;
×
1669
                                                }
1670

1671
                                                this._reader.ReadNext();
×
1672
                                        }
×
1673
                                case Hatch.BoundaryPath.EdgeType.Spline:
1674
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1675
                                        int nKnots = 0;
×
1676
                                        int nCtrlPoints = 0;
×
1677
                                        int nFitPoints = 0;
×
1678

1679
                                        XYZ controlPoint = new XYZ();
×
1680
                                        XY fitPoint = new XY();
×
1681

1682
                                        while (true)
×
1683
                                        {
×
1684
                                                switch (this._reader.Code)
×
1685
                                                {
1686
                                                        case 10:
1687
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1688
                                                                break;
×
1689
                                                        case 20:
1690
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1691
                                                                spline.ControlPoints.Add(controlPoint);
×
1692
                                                                break;
×
1693
                                                        case 11:
1694
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
1695
                                                                break;
×
1696
                                                        case 21:
1697
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
1698
                                                                spline.FitPoints.Add(fitPoint);
×
1699
                                                                break;
×
1700
                                                        case 42:
1701
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
1702
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1703
                                                                break;
×
1704
                                                        case 12:
1705
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1706
                                                                break;
×
1707
                                                        case 22:
1708
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
1709
                                                                break;
×
1710
                                                        case 13:
1711
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1712
                                                                break;
×
1713
                                                        case 23:
1714
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1715
                                                                break;
×
1716
                                                        case 94:
1717
                                                                spline.Degree = this._reader.ValueAsInt;
×
1718
                                                                break;
×
1719
                                                        case 73:
1720
                                                                spline.Rational = this._reader.ValueAsBool;
×
1721
                                                                break;
×
1722
                                                        case 74:
1723
                                                                spline.Periodic = this._reader.ValueAsBool;
×
1724
                                                                break;
×
1725
                                                        case 95:
1726
                                                                nKnots = this._reader.ValueAsInt;
×
1727
                                                                break;
×
1728
                                                        case 96:
1729
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1730
                                                                break;
×
1731
                                                        case 97:
1732
                                                                nFitPoints = this._reader.ValueAsInt;
×
1733
                                                                break;
×
1734
                                                        case 40:
1735
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
1736
                                                                break;
×
1737
                                                        default:
1738
                                                                return spline;
×
1739
                                                }
1740

1741
                                                this._reader.ReadNext();
×
1742
                                        }
×
1743
                        }
1744

1745
                        return null;
×
1746
                }
4,560✔
1747

1748
                private void readDefinedGroups(CadTemplate template)
1749
                {
63,477✔
1750
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
63,477✔
1751

1752
                        template.XDictHandle = xdict;
63,477✔
1753
                        template.ReactorsHandles.UnionWith(reactorsHandles);
63,477✔
1754
                }
63,477✔
1755

1756
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
1757
                {
63,707✔
1758
                        xdictHandle = null;
63,707✔
1759
                        reactors = new HashSet<ulong>();
63,707✔
1760

1761
                        switch (this._reader.ValueAsString)
63,707✔
1762
                        {
1763
                                case DxfFileToken.DictionaryToken:
1764
                                        this._reader.ReadNext();
12,097✔
1765
                                        xdictHandle = this._reader.ValueAsHandle;
12,097✔
1766
                                        this._reader.ReadNext();
12,097✔
1767
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
12,097✔
1768
                                        return;
12,097✔
1769
                                case DxfFileToken.ReactorsToken:
1770
                                        reactors = this.readReactors();
49,330✔
1771
                                        break;
49,330✔
1772
                                case DxfFileToken.BlkRefToken:
1773
                                default:
1774
                                        do
1775
                                        {
5,928✔
1776
                                                this._reader.ReadNext();
5,928✔
1777
                                        }
5,928✔
1778
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,928✔
1779
                                        return;
2,280✔
1780
                        }
1781
                }
63,707✔
1782

1783
                private HashSet<ulong> readReactors()
1784
                {
49,330✔
1785
                        HashSet<ulong> reactors = new();
49,330✔
1786

1787
                        this._reader.ReadNext();
49,330✔
1788

1789
                        while (this._reader.DxfCode != DxfCode.ControlString)
102,500✔
1790
                        {
53,170✔
1791
                                this._reader.ReadNext();
53,170✔
1792
                        }
53,170✔
1793

1794
                        return reactors;
49,330✔
1795
                }
49,330✔
1796

1797
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
1798
                {
5,153,608✔
1799
                        try
1800
                        {
5,153,608✔
1801
                                //Use this method only if the value is not a link between objects
1802
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
5,153,608✔
1803
                                {
1,925,581✔
1804
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
1,925,581✔
1805
                                        {
13,820✔
1806
                                                return true;
13,820✔
1807
                                        }
1808

1809
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
1,911,761!
1810
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
1,911,761✔
1811
                                        {
69,188✔
1812
                                                return false;
69,188✔
1813
                                        }
1814

1815
                                        object value = this._reader.Value;
1,842,573✔
1816

1817
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
1,842,573✔
1818
                                        {
9,258✔
1819
                                                value = MathHelper.DegToRad((double)value);
9,258✔
1820
                                        }
9,258✔
1821

1822
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
1,842,573✔
1823

1824
                                        return true;
1,842,573✔
1825
                                }
1826
                        }
3,228,027✔
1827
                        catch (Exception ex)
×
1828
                        {
×
1829
                                if (!this._builder.Configuration.Failsafe)
×
1830
                                {
×
1831
                                        throw ex;
×
1832
                                }
1833
                                else
1834
                                {
×
1835
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
1836
                                }
×
1837
                        }
×
1838

1839
                        return false;
3,228,027✔
1840
                }
5,153,608✔
1841
        }
1842
}
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