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

DomCR / ACadSharp / 17978770450

24 Sep 2025 01:47PM UTC coverage: 78.346% (-0.07%) from 78.418%
17978770450

push

github

web-flow
Merge pull request #191 from DomCR/Solid3D-Entity

Solid3D entity

6746 of 9343 branches covered (72.2%)

Branch coverage included in aggregate %.

245 of 322 new or added lines in 11 files covered. (76.09%)

6 existing lines in 3 files now uncovered.

25991 of 32442 relevant lines covered (80.12%)

110353.01 hits per line

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

83.66
/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,203✔
112
                        isExtendedData = false;
1,965,203✔
113

114
                        switch (this._reader.Code)
1,965,203✔
115
                        {
116
                                //Handle
117
                                case 5:
118
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
311,277✔
119
                                        break;
311,277✔
120
                                //Check with mapper
121
                                case 100:
122
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
218,691!
123
                                        {
3,552✔
124
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
3,552✔
125
                                        }
3,552✔
126
                                        break;
218,691✔
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,027✔
134
                                        break;
166,027✔
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,179,876✔
141
                                        break;
1,179,876✔
142
                        }
143
                }
1,965,203✔
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:
NEW
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.EntityXline:
212
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
228✔
213
                                default:
214
                                        DxfMap map = DxfMap.Create<Entity>();
3,876✔
215
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
3,876✔
216
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
3,876✔
217
                                        {
3,672✔
218
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
3,672✔
219
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
3,672✔
220
                                        }
3,672✔
221
                                        else
222
                                        {
204✔
223
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
204✔
224
                                        }
204✔
225

226
                                        this._reader.ReadNext();
3,876✔
227

228
                                        do
229
                                        {
430,716✔
230
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
430,716✔
231
                                                {
45,156✔
232
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
45,156✔
233
                                                        if (isExtendedData)
45,156✔
234
                                                                continue;
180✔
235
                                                }
44,976✔
236

237
                                                this._reader.ReadNext();
430,536✔
238
                                        }
430,536✔
239
                                        while (this._reader.DxfCode != DxfCode.Start);
430,716✔
240

241
                                        return unknownEntityTemplate;
3,876✔
242
                        }
243
                }
216,644✔
244

245
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
246
                        where T : Entity
247
                {
212,842✔
248
                        this._reader.ReadNext();
212,842✔
249

250
                        DxfMap map = DxfMap.Create<T>();
212,842✔
251

252
                        while (this._reader.DxfCode != DxfCode.Start)
2,759,440✔
253
                        {
2,546,598✔
254
                                if (!readEntity(template, map))
2,546,598✔
255
                                {
1,136,872✔
256
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
1,136,872✔
257
                                        if (isExtendedData)
1,136,872✔
258
                                                continue;
13,490✔
259
                                }
1,123,382✔
260

261
                                if (this._reader.DxfCode != DxfCode.Start)
2,533,108✔
262
                                        this._reader.ReadNext();
2,533,034✔
263
                        }
2,533,108✔
264

265
                        return template;
212,842✔
266
                }
212,842✔
267

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

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

315
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
316
                {
10,096✔
317
                        switch (this._reader.Code)
10,096✔
318
                        {
319
                                default:
320
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
10,096✔
321
                                        {
8,556✔
322
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
8,556✔
323
                                        }
324
                                        return true;
1,540✔
325
                        }
326
                }
10,096✔
327

328
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
329
                {
37,510✔
330
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
37,510✔
331
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
37,510✔
332

333
                        switch (this._reader.Code)
37,510!
334
                        {
335
                                case 44:
336
                                case 46:
337
                                        return true;
×
338
                                case 101:
339
                                        var att = tmp.CadObject as AttributeBase;
74✔
340
                                        att.MText = new MText();
74✔
341
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
74✔
342
                                        tmp.MTextTemplate = mtextTemplate;
74✔
343
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
74✔
344
                                        return true;
74✔
345
                                default:
346
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
37,436✔
347
                                        {
28,322✔
348
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
28,322✔
349
                                        }
350
                                        return true;
9,114✔
351
                        }
352
                }
37,510✔
353

354
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
355
                {
150,138✔
356
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
150,138!
357
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
150,138✔
358
                        TableEntity table = tmp.CadObject as TableEntity;
150,138✔
359

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

431
                private void readCellValue(TableEntity.CellContent content)
432
                {
6,232✔
433
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
6,232!
434
                        {
6,232✔
435
                                this._reader.ReadNext();
6,232✔
436
                        }
6,232✔
437
                        else
438
                        {
×
439
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
440
                        }
441

442
                        while (this._reader.Code != 304
40,736✔
443
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
40,736✔
444
                        {
34,504✔
445
                                switch (this._reader.Code)
34,504!
446
                                {
447
                                        case 1:
448
                                                content.Value.Text = this._reader.ValueAsString;
1,824✔
449
                                                break;
1,824✔
450
                                        case 2:
451
                                                content.Value.Text += this._reader.ValueAsString;
×
452
                                                break;
×
453
                                        case 11:
454
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
152✔
455
                                                break;
152✔
456
                                        case 21:
457
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
152✔
458
                                                break;
152✔
459
                                        case 31:
460
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
152✔
461
                                                break;
152✔
462
                                        case 302:
463
                                                //TODO: Fix this assignation to cell value
464
                                                content.Value.Value = this._reader.ValueAsString;
6,232✔
465
                                                break;
6,232✔
466
                                        case 90:
467
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
6,232✔
468
                                                break;
6,232✔
469
                                        case 91:
470
                                                content.Value.Value = this._reader.ValueAsInt;
152✔
471
                                                break;
152✔
472
                                        case 93:
473
                                                content.Value.Flags = this._reader.ValueAsInt;
6,232✔
474
                                                break;
6,232✔
475
                                        case 94:
476
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
6,232✔
477
                                                break;
6,232✔
478
                                        case 140:
479
                                                content.Value.Value = this._reader.ValueAsDouble;
608✔
480
                                                break;
608✔
481
                                        case 300:
482
                                                content.Value.Format = this._reader.ValueAsString;
6,232✔
483
                                                break;
6,232✔
484
                                        default:
485
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
304✔
486
                                                break;
304✔
487
                                }
488

489
                                this._reader.ReadNext();
34,504✔
490
                        }
34,504✔
491
                }
6,232✔
492

493
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
494
                {
323,406✔
495
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
323,406✔
496
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
323,406✔
497

498
                        switch (this._reader.Code)
323,406✔
499
                        {
500
                                //TODO: Implement multiline text def codes
501
                                case 1 or 3 when tmp.CadObject is MText mtext:
28,746✔
502
                                        mtext.Value += this._reader.ValueAsString;
10,874✔
503
                                        return true;
10,874✔
504
                                case 50 when tmp.CadObject is MText://Read only for MText
540✔
505
                                case 70:
506
                                case 74:
507
                                case 101:
508
                                        return true;
456✔
509
                                case 7:
510
                                        tmp.StyleName = this._reader.ValueAsString;
2,926✔
511
                                        return true;
2,926✔
512
                                default:
513
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
309,150✔
514
                        }
515
                }
323,406✔
516

517
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
518
                {
6,840✔
519
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,840✔
520

521
                        switch (this._reader.Code)
6,840✔
522
                        {
523
                                case 3:
524
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
684✔
525
                                        return true;
684✔
526
                                default:
527
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
6,156✔
528
                        }
529
                }
6,840✔
530

531
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
532
                {
76,532✔
533
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
76,532✔
534

535
                        switch (this._reader.Code)
76,532✔
536
                        {
537
                                case 2:
538
                                        tmp.BlockName = this._reader.ValueAsString;
2,926✔
539
                                        return true;
2,926✔
540
                                case 3:
541
                                        tmp.StyleName = this._reader.ValueAsString;
2,508✔
542
                                        return true;
2,508✔
543
                                case 50:
544
                                        var dim = new DimensionLinear();
266✔
545
                                        tmp.SetDimensionObject(dim);
266✔
546
                                        dim.Rotation = this._reader.ValueAsAngle;
266✔
547
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
266✔
548
                                        return true;
266✔
549
                                case 70:
550
                                        //Flags do not have set
551
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,926✔
552
                                        return true;
2,926✔
553
                                //Measurement - read only
554
                                case 42:
555
                                        return true;
2,508✔
556
                                //Undocumented codes
557
                                case 73:
558
                                case 74:
559
                                case 75:
560
                                case 90:
561
                                case 361:
562
                                        return true;
5,016✔
563
                                case 100:
564
                                        switch (this._reader.ValueAsString)
8,208✔
565
                                        {
566
                                                case DxfSubclassMarker.Dimension:
567
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
2,508✔
568
                                                case DxfSubclassMarker.AlignedDimension:
569
                                                        tmp.SetDimensionObject(new DimensionAligned());
1,140✔
570
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
1,140✔
571
                                                        return true;
1,140✔
572
                                                case DxfSubclassMarker.DiametricDimension:
573
                                                        tmp.SetDimensionObject(new DimensionDiameter());
228✔
574
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
228✔
575
                                                        return true;
228✔
576
                                                case DxfSubclassMarker.Angular2LineDimension:
577
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
228✔
578
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
228✔
579
                                                        return true;
228✔
580
                                                case DxfSubclassMarker.Angular3PointDimension:
581
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
228✔
582
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
228✔
583
                                                        return true;
228✔
584
                                                case DxfSubclassMarker.RadialDimension:
585
                                                        tmp.SetDimensionObject(new DimensionRadius());
228✔
586
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
228✔
587
                                                        return true;
228✔
588
                                                case DxfSubclassMarker.OrdinateDimension:
589
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
456✔
590
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
456✔
591
                                                        return true;
456✔
592
                                                case DxfSubclassMarker.LinearDimension:
593
                                                        return true;
684✔
594
                                                default:
595
                                                        return false;
2,508✔
596
                                        }
597
                                default:
598
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
52,174✔
599
                        }
600
                }
76,532✔
601

602
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
603
                {
45,600✔
604
                        CadHatchTemplate tmp = template as CadHatchTemplate;
45,600✔
605
                        Hatch hatch = tmp.CadObject;
45,600✔
606

607
                        bool isFirstSeed = true;
45,600✔
608
                        XY seedPoint = new XY();
45,600✔
609

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

699
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
700
                {
66,044✔
701
                        CadInsertTemplate tmp = template as CadInsertTemplate;
66,044✔
702

703
                        switch (this._reader.Code)
66,044✔
704
                        {
705
                                case 2:
706
                                        tmp.BlockName = this._reader.ValueAsString;
6,174✔
707
                                        return true;
6,174✔
708
                                case 100:
709
                                        //AcDbEntity
710
                                        //AcDbBlockReference
711
                                        //AcDbMInsertBlock
712
                                        return true;
6,192✔
713
                                case 66:
714
                                        return true;
532✔
715
                                default:
716
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
53,146✔
717
                        }
718
                }
66,044✔
719

720
                private CadEntityTemplate readPolyline()
721
                {
11,702✔
722
                        CadPolyLineTemplate template = null;
11,702✔
723

724
                        if (this._builder.Version == ACadVersion.Unknown)
11,702!
725
                        {
×
726
                                var polyline = new Polyline2D();
×
727
                                template = new CadPolyLineTemplate(polyline);
×
728
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
×
729

730
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
×
731
                                {
×
732
                                        Vertex2D v = new Vertex2D();
×
733
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
×
734
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
×
735

736
                                        if (vertexTemplate.Vertex.Handle == 0)
×
737
                                        {
×
738
                                                template.PolyLine.Vertices.Add(vertexTemplate.Vertex);
×
739
                                        }
×
740
                                        else
741
                                        {
×
742
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
743
                                                this._builder.AddTemplate(vertexTemplate);
×
744
                                        }
×
745
                                }
×
746

747
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
×
748
                                {
×
749
                                        var seqend = new Seqend();
×
750
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
×
751
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
×
752

753
                                        template.PolyLine.Vertices.Seqend = seqend;
×
754
                                }
×
755
                        }
×
756
                        else
757
                        {
11,702✔
758
                                template = new CadPolyLineTemplate();
11,702✔
759
                                this.readEntityCodes<Entity>(template, this.readPolyline);
11,702✔
760
                        }
11,702✔
761

762
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
11,702✔
763
                        {
11,246✔
764
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
11,246✔
765
                                return null;
11,246✔
766
                        }
767

768
                        return template;
456✔
769
                }
11,702✔
770

771
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
772
                {
84,038✔
773
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
84,038✔
774

775
                        switch (this._reader.Code)
84,038✔
776
                        {
777
                                //DXF: always 0
778
                                //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)
779
                                case 10:
780
                                case 20:
781
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
782
                                case 66:
783
                                //Polygon mesh M vertex count (optional; default = 0)
784
                                case 71:
785
                                //Polygon mesh N vertex count(optional; default = 0)
786
                                case 72:
787
                                //Smooth surface M density(optional; default = 0)
788
                                case 73:
789
                                //Smooth surface N density (optional; default = 0)
790
                                case 74:
791
                                        return true;
35,638✔
792
                                case 100:
793
                                        switch (this._reader.ValueAsString)
912!
794
                                        {
795
                                                case DxfSubclassMarker.Polyline:
796
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
797
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
798
                                                        return true;
×
799
                                                case DxfSubclassMarker.Polyline3d:
800
                                                        tmp.SetPolyLineObject(new Polyline3D());
228✔
801
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
228✔
802
                                                        return true;
228✔
803
                                                case DxfSubclassMarker.PolyfaceMesh:
804
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
228✔
805
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
228✔
806
                                                        return true;
228✔
807
                                                default:
808
                                                        return false;
456✔
809
                                        }
810
                                default:
811
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
47,488✔
812
                        }
813
                }
84,038✔
814

815
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
816
                {
5,700✔
817
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,700✔
818

819
                        switch (this._reader.Code)
5,700✔
820
                        {
821
                                case 3:
822
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
228✔
823
                                        return true;
228✔
824
                                case 10:
825
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
912✔
826
                                        return true;
912✔
827
                                case 20:
828
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
912✔
829
                                        y.Y = this._reader.ValueAsDouble;
912✔
830
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
912✔
831
                                        return true;
912✔
832
                                case 30:
833
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
912✔
834
                                        z.Z = this._reader.ValueAsDouble;
912✔
835
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
912✔
836
                                        return true;
912✔
837
                                case 340:
838
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
228✔
839
                                        return true;
228✔
840
                                //Hook line flag - read only
841
                                case 75:
842
                                //Vertices count
843
                                case 76:
844
                                        return true;
456✔
845
                                default:
846
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,052✔
847
                        }
848
                }
5,700✔
849

850
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
851
                {
93,660✔
852
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
93,660✔
853

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

856
                        switch (this._reader.Code)
93,660!
857
                        {
858
                                case 10:
859
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
22,236✔
860
                                        return true;
22,236✔
861
                                case 20:
862
                                        if (last is not null)
22,236✔
863
                                        {
22,236✔
864
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
22,236✔
865
                                        }
22,236✔
866
                                        return true;
22,236✔
867
                                case 40:
868
                                        if (last is not null)
2,280✔
869
                                        {
2,280✔
870
                                                last.StartWidth = this._reader.ValueAsDouble;
2,280✔
871
                                        }
2,280✔
872
                                        return true;
2,280✔
873
                                case 41:
874
                                        if (last is not null)
2,280✔
875
                                        {
2,280✔
876
                                                last.EndWidth = this._reader.ValueAsDouble;
2,280✔
877
                                        }
2,280✔
878
                                        return true;
2,280✔
879
                                case 42:
880
                                        if (last is not null)
3,120✔
881
                                        {
3,120✔
882
                                                last.Bulge = this._reader.ValueAsDouble;
3,120✔
883
                                        }
3,120✔
884
                                        return true;
3,120✔
885
                                case 50:
886
                                        if (last is not null)
×
887
                                        {
×
888
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
889
                                        }
×
890
                                        return true;
×
891
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
892
                                case 66:
893
                                //Vertex count
894
                                case 90:
895
                                        return true;
4,992✔
896
                                case 91:
897
                                        if (last is not null)
×
898
                                        {
×
899
                                                last.Id = this._reader.ValueAsInt;
×
900
                                        }
×
901
                                        return true;
×
902
                                default:
903
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
36,516✔
904
                        }
905
                }
93,660✔
906

907
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
908
                {
40,128✔
909
                        CadMeshTemplate tmp = template as CadMeshTemplate;
40,128✔
910

911
                        switch (this._reader.Code)
40,128✔
912
                        {
913
                                case 100:
914
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
912✔
915
                                        {
456✔
916
                                                tmp.SubclassMarker = true;
456✔
917
                                        }
456✔
918
                                        return true;
912✔
919
                                //Count of sub-entity which property has been overridden
920
                                case 90:
921
                                        //TODO: process further entities
922
                                        return true;
456✔
923
                                case 92:
924
                                        if (!tmp.SubclassMarker)
684✔
925
                                        {
228✔
926
                                                return false;
228✔
927
                                        }
928

929
                                        int nvertices = this._reader.ValueAsInt;
456✔
930
                                        for (int i = 0; i < nvertices; i++)
58,368✔
931
                                        {
28,728✔
932
                                                this._reader.ReadNext();
28,728✔
933
                                                double x = this._reader.ValueAsDouble;
28,728✔
934
                                                this._reader.ReadNext();
28,728✔
935
                                                double y = this._reader.ValueAsDouble;
28,728✔
936
                                                this._reader.ReadNext();
28,728✔
937
                                                double z = this._reader.ValueAsDouble;
28,728✔
938
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
28,728✔
939
                                        }
28,728✔
940
                                        return true;
456✔
941
                                case 93:
942
                                        int size = this._reader.ValueAsInt;
456✔
943
                                        this._reader.ReadNext();
456✔
944

945
                                        int indexes = 0;
456✔
946
                                        for (int i = 0; i < size; i += indexes + 1)
62,928✔
947
                                        {
31,008✔
948
                                                indexes = this._reader.ValueAsInt;
31,008✔
949
                                                this._reader.ReadNext();
31,008✔
950

951
                                                int[] face = new int[indexes];
31,008✔
952
                                                for (int j = 0; j < indexes; j++)
299,136✔
953
                                                {
118,560✔
954
                                                        face[j] = this._reader.ValueAsInt;
118,560✔
955

956
                                                        if ((i + j + 2) < size)
118,560✔
957
                                                        {
118,104✔
958
                                                                this._reader.ReadNext();
118,104✔
959
                                                        }
118,104✔
960
                                                }
118,560✔
961

962
                                                tmp.CadObject.Faces.Add(face);
31,008✔
963
                                        }
31,008✔
964

965
                                        Debug.Assert(this._reader.Code == 90);
456✔
966

967
                                        return true;
456✔
968
                                case 94:
969
                                        int numEdges = this._reader.ValueAsInt;
456✔
970
                                        this._reader.ReadNext();
456✔
971
                                        for (int i = 0; i < numEdges; i++)
119,472✔
972
                                        {
59,280✔
973
                                                Mesh.Edge edge = new Mesh.Edge();
59,280✔
974

975
                                                edge.Start = this._reader.ValueAsInt;
59,280✔
976
                                                this._reader.ReadNext();
59,280✔
977
                                                edge.End = this._reader.ValueAsInt;
59,280✔
978

979
                                                if (i < numEdges - 1)
59,280✔
980
                                                {
58,824✔
981
                                                        this._reader.ReadNext();
58,824✔
982
                                                }
58,824✔
983

984
                                                tmp.CadObject.Edges.Add(edge);
59,280✔
985
                                        }
59,280✔
986

987
                                        Debug.Assert(this._reader.Code == 90);
456✔
988

989
                                        return true;
456✔
990
                                case 95:
991
                                        this._reader.ReadNext();
456✔
992
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
119,472✔
993
                                        {
59,280✔
994
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
59,280✔
995
                                                edge.Crease = this._reader.ValueAsDouble;
59,280✔
996

997
                                                tmp.CadObject.Edges[i] = edge;
59,280✔
998

999
                                                if (i < tmp.CadObject.Edges.Count - 1)
59,280✔
1000
                                                {
58,824✔
1001
                                                        this._reader.ReadNext();
58,824✔
1002
                                                }
58,824✔
1003
                                        }
59,280✔
1004

1005
                                        Debug.Assert(this._reader.Code == 140);
456✔
1006

1007
                                        return true;
456✔
1008
                                default:
1009
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
36,708✔
1010
                        }
1011
                }
40,128✔
1012

1013
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1014
                {
59,280✔
1015
                        CadMLineTemplate tmp = template as CadMLineTemplate;
59,280✔
1016

1017
                        switch (this._reader.Code)
59,280✔
1018
                        {
1019
                                // 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.
1020
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1021
                                case 2:
1022
                                        tmp.MLineStyleName = this._reader.ValueAsString;
684✔
1023
                                        return true;
684✔
1024
                                case 72:
1025
                                        tmp.NVertex = this._reader.ValueAsInt;
684✔
1026
                                        return true;
684✔
1027
                                case 73:
1028
                                        tmp.NElements = this._reader.ValueAsInt;
684✔
1029
                                        return true;
684✔
1030
                                case 340:
1031
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
684✔
1032
                                        return true;
684✔
1033
                                default:
1034
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
56,544✔
1035
                                        {
9,576✔
1036
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
9,576✔
1037
                                        }
1038
                                        return true;
46,968✔
1039
                        }
1040
                }
59,280✔
1041

1042
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1043
                {
2,546✔
1044
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,546✔
1045

1046
                        switch (this._reader.Code)
2,546✔
1047
                        {
1048
                                case 2:
1049
                                        tmp.ShapeFileName = this._reader.ValueAsString;
266✔
1050
                                        return true;
266✔
1051
                                default:
1052
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,280✔
1053
                        }
1054
                }
2,546✔
1055

1056
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1057
                {
15,960✔
1058
                        CadSplineTemplate tmp = template as CadSplineTemplate;
15,960✔
1059

1060
                        XYZ controlPoint;
1061
                        XYZ fitPoint;
1062

1063
                        switch (this._reader.Code)
15,960!
1064
                        {
1065
                                case 10:
1066
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,824✔
1067
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,824✔
1068
                                        return true;
1,824✔
1069
                                case 20:
1070
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1071
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,824✔
1072
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1073
                                        return true;
1,824✔
1074
                                case 30:
1075
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,824✔
1076
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,824✔
1077
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,824✔
1078
                                        return true;
1,824✔
1079
                                case 11:
1080
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1081
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1082
                                        return true;
×
1083
                                case 21:
1084
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1085
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1086
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1087
                                        return true;
×
1088
                                case 31:
1089
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1090
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1091
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1092
                                        return true;
×
1093
                                case 40:
1094
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,648✔
1095
                                        return true;
3,648✔
1096
                                case 41:
1097
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1098
                                        return true;
×
1099
                                case 72:
1100
                                case 73:
1101
                                case 74:
1102
                                        return true;
1,368✔
1103
                                default:
1104
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
5,472✔
1105
                        }
1106
                }
15,960✔
1107

1108
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1109
                        where T : PdfUnderlayDefinition
1110
                {
3,610✔
1111
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
3,610✔
1112

1113
                        switch (this._reader.Code)
3,610✔
1114
                        {
1115
                                case 340:
1116
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
228✔
1117
                                        return true;
228✔
1118
                                default:
1119
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,382✔
1120
                        }
1121
                }
3,610✔
1122

1123
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1124
                {
266,368✔
1125
                        CadVertexTemplate tmp = template as CadVertexTemplate;
266,368✔
1126

1127
                        switch (this._reader.Code)
266,368✔
1128
                        {
1129
                                //Polyface mesh vertex index
1130
                                case 71:
1131
                                case 72:
1132
                                case 73:
1133
                                case 74:
1134
                                        return true;
1,862✔
1135
                                case 100:
1136
                                        switch (this._reader.ValueAsString)
7,752!
1137
                                        {
1138
                                                case DxfSubclassMarker.Vertex:
1139
                                                        return true;
2,280✔
1140
                                                case DxfSubclassMarker.PolylineVertex:
1141
                                                        tmp.SetVertexObject(new Vertex2D());
×
1142
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1143
                                                        return true;
×
1144
                                                case DxfSubclassMarker.Polyline3dVertex:
1145
                                                        tmp.SetVertexObject(new Vertex3D());
1,140✔
1146
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,140✔
1147
                                                        return true;
1,140✔
1148
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1149
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,140✔
1150
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,140✔
1151
                                                        return true;
1,140✔
1152
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1153
                                                        tmp.SetVertexObject(new VertexFaceRecord());
456✔
1154
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
456✔
1155
                                                        return true;
456✔
1156
                                                default:
1157
                                                        return false;
2,736✔
1158
                                        }
1159
                                default:
1160
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
256,754✔
1161
                        }
1162
                }
266,368✔
1163

1164
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1165
                {
76,296✔
1166
                        CadViewportTemplate tmp = template as CadViewportTemplate;
76,296✔
1167

1168
                        switch (this._reader.Code)
76,296!
1169
                        {
1170
                                //Undocumented
1171
                                case 67:
1172
                                case 68:
1173
                                        return true;
2,792✔
1174
                                case 69:
1175
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,396✔
1176
                                        return true;
1,396✔
1177
                                case 331:
1178
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1179
                                        return true;
×
1180
                                case 348:
1181
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
880✔
1182
                                        return true;
880✔
1183
                                default:
1184
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
71,228✔
1185
                        }
1186
                }
76,296✔
1187

1188
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1189
                {
1,279,498✔
1190
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
1,279,498✔
1191

1192
                        switch (this._reader.Code)
1,279,498✔
1193
                        {
1194
                                default:
1195
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
1,279,498✔
1196
                        }
1197
                }
1,279,498✔
1198

1199
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1200
                {
38,840✔
1201
                        List<ExtendedDataRecord> records = new();
38,840✔
1202
                        edata.Add(this._reader.ValueAsString, records);
38,840✔
1203

1204
                        this._reader.ReadNext();
38,840✔
1205

1206
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
308,541✔
1207
                        {
281,829✔
1208
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
281,829✔
1209
                                {
12,128✔
1210
                                        this.readExtendedData(edata);
12,128✔
1211
                                        break;
12,128✔
1212
                                }
1213

1214
                                ExtendedDataRecord record = null;
269,701✔
1215
                                double x = 0;
269,701✔
1216
                                double y = 0;
269,701✔
1217
                                double z = 0;
269,701✔
1218

1219
                                switch (this._reader.DxfCode)
269,701✔
1220
                                {
1221
                                        case DxfCode.ExtendedDataAsciiString:
1222
                                        case DxfCode.ExtendedDataRegAppName:
1223
                                                record = new ExtendedDataString(this._reader.ValueAsString);
28,727✔
1224
                                                break;
28,727✔
1225
                                        case DxfCode.ExtendedDataControlString:
1226
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
15,056✔
1227
                                                break;
15,056✔
1228
                                        case DxfCode.ExtendedDataLayerName:
1229
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
266✔
1230
                                                {
252✔
1231
                                                        record = new ExtendedDataLayer(layer.Handle);
252✔
1232
                                                }
252✔
1233
                                                else
1234
                                                {
14✔
1235
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1236
                                                }
14✔
1237
                                                break;
266✔
1238
                                        case DxfCode.ExtendedDataBinaryChunk:
1239
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
76✔
1240
                                                break;
76✔
1241
                                        case DxfCode.ExtendedDataHandle:
1242
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,808✔
1243
                                                break;
2,808✔
1244
                                        case DxfCode.ExtendedDataXCoordinate:
1245
                                                x = this._reader.ValueAsDouble;
2,836✔
1246
                                                this._reader.ReadNext();
2,836✔
1247
                                                y = this._reader.ValueAsDouble;
2,836✔
1248
                                                this._reader.ReadNext();
2,836✔
1249
                                                z = this._reader.ValueAsDouble;
2,836✔
1250

1251
                                                record = new ExtendedDataCoordinate(
2,836✔
1252
                                                        new XYZ(
2,836✔
1253
                                                                x,
2,836✔
1254
                                                                y,
2,836✔
1255
                                                                z)
2,836✔
1256
                                                        );
2,836✔
1257
                                                break;
2,836✔
1258
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1259
                                                x = this._reader.ValueAsDouble;
1,368✔
1260
                                                this._reader.ReadNext();
1,368✔
1261
                                                y = this._reader.ValueAsDouble;
1,368✔
1262
                                                this._reader.ReadNext();
1,368✔
1263
                                                z = this._reader.ValueAsDouble;
1,368✔
1264

1265
                                                record = new ExtendedDataWorldCoordinate(
1,368✔
1266
                                                        new XYZ(
1,368✔
1267
                                                                x,
1,368✔
1268
                                                                y,
1,368✔
1269
                                                                z)
1,368✔
1270
                                                        );
1,368✔
1271
                                                break;
1,368✔
1272
                                        case DxfCode.ExtendedDataWorldXDisp:
1273
                                                x = this._reader.ValueAsDouble;
266✔
1274
                                                this._reader.ReadNext();
266✔
1275
                                                y = this._reader.ValueAsDouble;
266✔
1276
                                                this._reader.ReadNext();
266✔
1277
                                                z = this._reader.ValueAsDouble;
266✔
1278

1279
                                                record = new ExtendedDataDisplacement(
266✔
1280
                                                        new XYZ(
266✔
1281
                                                                x,
266✔
1282
                                                                y,
266✔
1283
                                                                z)
266✔
1284
                                                        );
266✔
1285
                                                break;
266✔
1286
                                        case DxfCode.ExtendedDataWorldXDir:
1287
                                                x = this._reader.ValueAsDouble;
266✔
1288
                                                this._reader.ReadNext();
266✔
1289
                                                y = this._reader.ValueAsDouble;
266✔
1290
                                                this._reader.ReadNext();
266✔
1291
                                                z = this._reader.ValueAsDouble;
266✔
1292

1293
                                                record = new ExtendedDataDirection(
266✔
1294
                                                        new XYZ(
266✔
1295
                                                                x,
266✔
1296
                                                                y,
266✔
1297
                                                                z)
266✔
1298
                                                        );
266✔
1299
                                                break;
266✔
1300
                                        case DxfCode.ExtendedDataReal:
1301
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
133,506✔
1302
                                                break;
133,506✔
1303
                                        case DxfCode.ExtendedDataDist:
1304
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
266✔
1305
                                                break;
266✔
1306
                                        case DxfCode.ExtendedDataScale:
1307
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
266✔
1308
                                                break;
266✔
1309
                                        case DxfCode.ExtendedDataInteger16:
1310
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
72,837✔
1311
                                                break;
72,837✔
1312
                                        case DxfCode.ExtendedDataInteger32:
1313
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
8,725✔
1314
                                                break;
8,725✔
1315
                                        default:
1316
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,432✔
1317
                                                break;
2,432✔
1318
                                }
1319

1320
                                if (record != null)
269,701✔
1321
                                {
267,255✔
1322
                                        records.Add(record);
267,255✔
1323
                                }
267,255✔
1324

1325
                                this._reader.ReadNext();
269,701✔
1326
                        }
269,701✔
1327
                }
38,840✔
1328

1329
                private void readPattern(HatchPattern pattern, int nlines)
1330
                {
1,368✔
1331
                        //Jump 78 code
1332
                        this._reader.ReadNext();
1,368✔
1333

1334
                        for (int i = 0; i < nlines; i++)
207,480✔
1335
                        {
102,372✔
1336
                                HatchPattern.Line line = new HatchPattern.Line();
102,372✔
1337
                                XY basePoint = new XY();
102,372✔
1338
                                XY offset = new XY();
102,372✔
1339

1340
                                bool end = false;
102,372✔
1341
                                HashSet<int> codes = new();
102,372✔
1342

1343
                                while (!end)
717,972✔
1344
                                {
716,604✔
1345
                                        if (codes.Contains(this._reader.Code))
716,604✔
1346
                                        {
101,004✔
1347
                                                break;
101,004✔
1348
                                        }
1349
                                        else
1350
                                        {
615,600✔
1351
                                                codes.Add(this._reader.Code);
615,600✔
1352
                                        }
615,600✔
1353

1354
                                        switch (this._reader.Code)
615,600!
1355
                                        {
1356
                                                case 53:
1357
                                                        line.Angle = this._reader.ValueAsAngle;
102,372✔
1358
                                                        break;
102,372✔
1359
                                                case 43:
1360
                                                        basePoint.X = this._reader.ValueAsDouble;
102,372✔
1361
                                                        break;
102,372✔
1362
                                                case 44:
1363
                                                        basePoint.Y = this._reader.ValueAsDouble;
102,372✔
1364
                                                        line.BasePoint = basePoint;
102,372✔
1365
                                                        break;
102,372✔
1366
                                                case 45:
1367
                                                        offset.X = this._reader.ValueAsDouble;
102,372✔
1368
                                                        line.Offset = offset;
102,372✔
1369
                                                        break;
102,372✔
1370
                                                case 46:
1371
                                                        offset.Y = this._reader.ValueAsDouble;
102,372✔
1372
                                                        line.Offset = offset;
102,372✔
1373
                                                        break;
102,372✔
1374
                                                //Number of dash length items
1375
                                                case 79:
1376
                                                        int ndash = this._reader.ValueAsInt;
102,372✔
1377
                                                        for (int j = 0; j < ndash; j++)
613,320✔
1378
                                                        {
204,288✔
1379
                                                                this._reader.ReadNext();
204,288✔
1380
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
204,288✔
1381
                                                        }
204,288✔
1382
                                                        break;
102,372✔
1383
                                                case 49:
1384
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1385
                                                        break;
×
1386
                                                default:
1387
                                                        end = true;
1,368✔
1388
                                                        break;
1,368✔
1389
                                        }
1390
                                        this._reader.ReadNext();
615,600✔
1391
                                }
615,600✔
1392

1393
                                pattern.Lines.Add(line);
102,372✔
1394
                        }
102,372✔
1395
                }
1,368✔
1396

1397
                private void readLoops(CadHatchTemplate template, int count)
1398
                {
1,824✔
1399
                        if (this._reader.Code == 91)
1,824✔
1400
                                this._reader.ReadNext();
1,824✔
1401

1402
                        for (int i = 0; i < count; i++)
7,296✔
1403
                        {
1,824✔
1404
                                if (this._reader.Code != 92)
1,824!
1405
                                {
×
1406
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1407
                                        break;
×
1408
                                }
1409

1410
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,824✔
1411
                                if (path != null)
1,824✔
1412
                                        template.PathTempaltes.Add(path);
1,824✔
1413
                        }
1,824✔
1414
                }
1,824✔
1415

1416
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1417
                {
1,824✔
1418
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,824✔
1419
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,824✔
1420
                        template.Path.Flags = flags;
1,824✔
1421

1422
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,824✔
1423
                        {
684✔
1424
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
684✔
1425
                                template.Path.Edges.Add(pl);
684✔
1426
                        }
684✔
1427
                        else
1428
                        {
1,140✔
1429
                                this._reader.ReadNext();
1,140✔
1430

1431
                                if (this._reader.Code != 93)
1,140!
1432
                                {
×
1433
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1434
                                        return null;
×
1435
                                }
1436

1437
                                int edges = this._reader.ValueAsInt;
1,140✔
1438
                                this._reader.ReadNext();
1,140✔
1439

1440
                                for (int i = 0; i < edges; i++)
11,400✔
1441
                                {
4,560✔
1442
                                        var edge = this.readEdge();
4,560✔
1443
                                        if (edge != null)
4,560✔
1444
                                                template.Path.Edges.Add(edge);
4,560✔
1445
                                }
4,560✔
1446
                        }
1,140✔
1447

1448
                        bool end = false;
1,824✔
1449
                        while (!end)
7,068✔
1450
                        {
5,244✔
1451
                                switch (this._reader.Code)
5,244✔
1452
                                {
1453
                                        //Number of source boundary objects
1454
                                        case 97:
1455
                                                break;
1,824✔
1456
                                        case 330:
1457
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,596✔
1458
                                                break;
1,596✔
1459
                                        default:
1460
                                                end = true;
1,824✔
1461
                                                continue;
1,824✔
1462
                                }
1463

1464
                                this._reader.ReadNext();
3,420✔
1465
                        }
3,420✔
1466

1467
                        return template;
1,824✔
1468
                }
1,824✔
1469

1470
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1471
                {
684✔
1472
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
684✔
1473

1474
                        this._reader.ReadNext();
684✔
1475

1476
                        if (this._reader.Code != 72)
684!
1477
                        {
×
1478
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1479
                                return null;
×
1480
                        }
1481

1482
                        //72
1483
                        bool hasBulge = this._reader.ValueAsBool;
684✔
1484
                        this._reader.ReadNext();
684✔
1485

1486
                        //73
1487
                        bool isClosed = this._reader.ValueAsBool;
684✔
1488
                        this._reader.ReadNext();
684✔
1489

1490
                        //93
1491
                        int nvertices = this._reader.ValueAsInt;
684✔
1492
                        this._reader.ReadNext();
684✔
1493

1494
                        for (int i = 0; i < nvertices; i++)
6,840✔
1495
                        {
2,736✔
1496
                                double bulge = 0.0;
2,736✔
1497

1498
                                //10
1499
                                double x = this._reader.ValueAsDouble;
2,736✔
1500
                                this._reader.ReadNext();
2,736✔
1501
                                //20
1502
                                double y = this._reader.ValueAsDouble;
2,736✔
1503
                                this._reader.ReadNext();
2,736✔
1504

1505
                                if (hasBulge)
2,736!
1506
                                {
×
1507
                                        //42
1508
                                        bulge = this._reader.ValueAsDouble;
×
1509
                                        this._reader.ReadNext();
×
1510
                                }
×
1511

1512
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,736✔
1513
                        }
2,736✔
1514

1515
                        return boundary;
684✔
1516
                }
684✔
1517

1518
                private Hatch.BoundaryPath.Edge readEdge()
1519
                {
4,560✔
1520
                        if (this._reader.Code != 72)
4,560!
1521
                        {
×
1522
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1523
                                return null;
×
1524
                        }
1525

1526
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,560✔
1527
                        this._reader.ReadNext();
4,560✔
1528

1529
                        switch (type)
4,560!
1530
                        {
1531
                                case Hatch.BoundaryPath.EdgeType.Line:
1532
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,560✔
1533
                                        while (true)
22,800✔
1534
                                        {
22,800✔
1535
                                                switch (this._reader.Code)
22,800✔
1536
                                                {
1537
                                                        case 10:
1538
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,560✔
1539
                                                                break;
4,560✔
1540
                                                        case 20:
1541
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,560✔
1542
                                                                break;
4,560✔
1543
                                                        case 11:
1544
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,560✔
1545
                                                                break;
4,560✔
1546
                                                        case 21:
1547
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,560✔
1548
                                                                break;
4,560✔
1549
                                                        default:
1550
                                                                return line;
4,560✔
1551
                                                }
1552

1553
                                                this._reader.ReadNext();
18,240✔
1554
                                        }
18,240✔
1555
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1556
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1557
                                        while (true)
×
1558
                                        {
×
1559
                                                switch (this._reader.Code)
×
1560
                                                {
1561
                                                        case 10:
1562
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1563
                                                                break;
×
1564
                                                        case 20:
1565
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1566
                                                                break;
×
1567
                                                        case 40:
1568
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1569
                                                                break;
×
1570
                                                        case 50:
1571
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1572
                                                                break;
×
1573
                                                        case 51:
1574
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1575
                                                                break;
×
1576
                                                        case 73:
1577
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1578
                                                                break;
×
1579
                                                        default:
1580
                                                                return arc;
×
1581
                                                }
1582

1583
                                                this._reader.ReadNext();
×
1584
                                        }
×
1585
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1586
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1587
                                        while (true)
×
1588
                                        {
×
1589
                                                switch (this._reader.Code)
×
1590
                                                {
1591
                                                        case 10:
1592
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1593
                                                                break;
×
1594
                                                        case 20:
1595
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1596
                                                                break;
×
1597
                                                        case 11:
1598
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1599
                                                                break;
×
1600
                                                        case 21:
1601
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1602
                                                                break;
×
1603
                                                        case 40:
1604
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1605
                                                                break;
×
1606
                                                        case 50:
1607
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1608
                                                                break;
×
1609
                                                        case 51:
1610
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
1611
                                                                break;
×
1612
                                                        case 73:
1613
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
1614
                                                                break;
×
1615
                                                        default:
1616
                                                                return ellipse;
×
1617
                                                }
1618

1619
                                                this._reader.ReadNext();
×
1620
                                        }
×
1621
                                case Hatch.BoundaryPath.EdgeType.Spline:
1622
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1623
                                        int nKnots = 0;
×
1624
                                        int nCtrlPoints = 0;
×
1625
                                        int nFitPoints = 0;
×
1626

1627
                                        XYZ controlPoint = new XYZ();
×
1628
                                        XY fitPoint = new XY();
×
1629

1630
                                        while (true)
×
1631
                                        {
×
1632
                                                switch (this._reader.Code)
×
1633
                                                {
1634
                                                        case 10:
1635
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1636
                                                                break;
×
1637
                                                        case 20:
1638
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1639
                                                                spline.ControlPoints.Add(controlPoint);
×
1640
                                                                break;
×
1641
                                                        case 11:
1642
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
1643
                                                                break;
×
1644
                                                        case 21:
1645
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
1646
                                                                spline.FitPoints.Add(fitPoint);
×
1647
                                                                break;
×
1648
                                                        case 42:
1649
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
1650
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1651
                                                                break;
×
1652
                                                        case 12:
1653
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1654
                                                                break;
×
1655
                                                        case 22:
1656
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
1657
                                                                break;
×
1658
                                                        case 13:
1659
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1660
                                                                break;
×
1661
                                                        case 23:
1662
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1663
                                                                break;
×
1664
                                                        case 94:
1665
                                                                spline.Degree = this._reader.ValueAsInt;
×
1666
                                                                break;
×
1667
                                                        case 73:
1668
                                                                spline.Rational = this._reader.ValueAsBool;
×
1669
                                                                break;
×
1670
                                                        case 74:
1671
                                                                spline.Periodic = this._reader.ValueAsBool;
×
1672
                                                                break;
×
1673
                                                        case 95:
1674
                                                                nKnots = this._reader.ValueAsInt;
×
1675
                                                                break;
×
1676
                                                        case 96:
1677
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1678
                                                                break;
×
1679
                                                        case 97:
1680
                                                                nFitPoints = this._reader.ValueAsInt;
×
1681
                                                                break;
×
1682
                                                        case 40:
1683
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
1684
                                                                break;
×
1685
                                                        default:
1686
                                                                return spline;
×
1687
                                                }
1688

1689
                                                this._reader.ReadNext();
×
1690
                                        }
×
1691
                        }
1692

1693
                        return null;
×
1694
                }
4,560✔
1695

1696
                private void readDefinedGroups(CadTemplate template)
1697
                {
63,477✔
1698
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
63,477✔
1699

1700
                        template.XDictHandle = xdict;
63,477✔
1701
                        template.ReactorsHandles.UnionWith(reactorsHandles);
63,477✔
1702
                }
63,477✔
1703

1704
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
1705
                {
63,707✔
1706
                        xdictHandle = null;
63,707✔
1707
                        reactors = new HashSet<ulong>();
63,707✔
1708

1709
                        switch (this._reader.ValueAsString)
63,707✔
1710
                        {
1711
                                case DxfFileToken.DictionaryToken:
1712
                                        this._reader.ReadNext();
12,097✔
1713
                                        xdictHandle = this._reader.ValueAsHandle;
12,097✔
1714
                                        this._reader.ReadNext();
12,097✔
1715
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
12,097✔
1716
                                        return;
12,097✔
1717
                                case DxfFileToken.ReactorsToken:
1718
                                        reactors = this.readReactors();
49,330✔
1719
                                        break;
49,330✔
1720
                                case DxfFileToken.BlkRefToken:
1721
                                default:
1722
                                        do
1723
                                        {
5,928✔
1724
                                                this._reader.ReadNext();
5,928✔
1725
                                        }
5,928✔
1726
                                        while (this._reader.DxfCode != DxfCode.ControlString);
5,928✔
1727
                                        return;
2,280✔
1728
                        }
1729
                }
63,707✔
1730

1731
                private HashSet<ulong> readReactors()
1732
                {
49,330✔
1733
                        HashSet<ulong> reactors = new();
49,330✔
1734

1735
                        this._reader.ReadNext();
49,330✔
1736

1737
                        while (this._reader.DxfCode != DxfCode.ControlString)
102,500✔
1738
                        {
53,170✔
1739
                                this._reader.ReadNext();
53,170✔
1740
                        }
53,170✔
1741

1742
                        return reactors;
49,330✔
1743
                }
49,330✔
1744

1745
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
1746
                {
5,141,260✔
1747
                        try
1748
                        {
5,141,260✔
1749
                                //Use this method only if the value is not a link between objects
1750
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
5,141,260✔
1751
                                {
1,917,145✔
1752
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
1,917,145✔
1753
                                        {
13,820✔
1754
                                                return true;
13,820✔
1755
                                        }
1756

1757
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
1,903,325!
1758
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
1,903,325✔
1759
                                        {
69,188✔
1760
                                                return false;
69,188✔
1761
                                        }
1762

1763
                                        object value = this._reader.Value;
1,834,137✔
1764

1765
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
1,834,137✔
1766
                                        {
9,258✔
1767
                                                value = MathHelper.DegToRad((double)value);
9,258✔
1768
                                        }
9,258✔
1769

1770
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
1,834,137✔
1771

1772
                                        return true;
1,834,137✔
1773
                                }
1774
                        }
3,224,115✔
1775
                        catch (Exception ex)
×
1776
                        {
×
1777
                                if (!this._builder.Configuration.Failsafe)
×
1778
                                {
×
1779
                                        throw ex;
×
1780
                                }
1781
                                else
1782
                                {
×
1783
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
1784
                                }
×
1785
                        }
×
1786

1787
                        return false;
3,224,115✔
1788
                }
5,141,260✔
1789
        }
1790
}
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