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

DomCR / ACadSharp / 18588619962

17 Oct 2025 09:30AM UTC coverage: 78.11% (+0.003%) from 78.107%
18588619962

push

github

web-flow
Merge pull request #826 from DomCR/svg-text

Svg text

6877 of 9561 branches covered (71.93%)

Branch coverage included in aggregate %.

3 of 12 new or added lines in 2 files covered. (25.0%)

3 existing lines in 1 file now uncovered.

26475 of 33138 relevant lines covered (79.89%)

108149.8 hits per line

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

83.48
/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:
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 mtext://Read only for MText
540!
NEW
505
                                        double angle = MathHelper.DegToRad(this._reader.ValueAsDouble);
×
NEW
506
                                        mtext.AlignmentPoint = new XYZ(System.Math.Cos(angle), System.Math.Sin(angle), 0.0);
×
NEW
507
                                        return true;
×
508
                                case 70:
509
                                case 74:
510
                                case 101:
511
                                        return true;
456✔
512
                                case 7:
513
                                        tmp.StyleName = this._reader.ValueAsString;
2,926✔
514
                                        return true;
2,926✔
515
                                default:
516
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
309,150✔
517
                        }
518
                }
323,406✔
519

520
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
521
                {
6,840✔
522
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,840✔
523

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

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

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

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

610
                        bool isFirstSeed = true;
45,600✔
611
                        XY seedPoint = new XY();
45,600✔
612

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

702
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
703
                {
66,044✔
704
                        CadInsertTemplate tmp = template as CadInsertTemplate;
66,044✔
705

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

723
                private CadEntityTemplate readPolyline()
724
                {
11,702✔
725
                        CadPolyLineTemplate template = null;
11,702✔
726

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

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

739
                                        if (vertexTemplate.Vertex.Handle == 0)
×
740
                                        {
×
741
                                                polyline.Vertices.Add(v);
×
742
                                        }
×
743
                                        else
744
                                        {
×
745
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
746
                                                this._builder.AddTemplate(vertexTemplate);
×
747
                                        }
×
748
                                }
×
749

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

756
                                        polyline.Vertices.Seqend = seqend;
×
757
                                }
×
758
                        }
×
759
                        else
760
                        {
11,702✔
761
                                template = new CadPolyLineTemplate();
11,702✔
762
                                this.readEntityCodes<Entity>(template, this.readPolyline);
11,702✔
763
                        }
11,702✔
764

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

771
                        return template;
456✔
772
                }
11,702✔
773

774
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
775
                {
84,038✔
776
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
84,038✔
777

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

818
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
819
                {
5,700✔
820
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,700✔
821

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

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

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

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

910
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
911
                {
40,128✔
912
                        CadMeshTemplate tmp = template as CadMeshTemplate;
40,128✔
913

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

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

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

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

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

965
                                                tmp.CadObject.Faces.Add(face);
31,008✔
966
                                        }
31,008✔
967

968
                                        Debug.Assert(this._reader.Code == 90);
456✔
969

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

978
                                                edge.Start = this._reader.ValueAsInt;
59,280✔
979
                                                this._reader.ReadNext();
59,280✔
980
                                                edge.End = this._reader.ValueAsInt;
59,280✔
981

982
                                                if (i < numEdges - 1)
59,280✔
983
                                                {
58,824✔
984
                                                        this._reader.ReadNext();
58,824✔
985
                                                }
58,824✔
986

987
                                                tmp.CadObject.Edges.Add(edge);
59,280✔
988
                                        }
59,280✔
989

990
                                        Debug.Assert(this._reader.Code == 90);
456✔
991

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

1000
                                                tmp.CadObject.Edges[i] = edge;
59,280✔
1001

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

1008
                                        Debug.Assert(this._reader.Code == 140);
456✔
1009

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

1016
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1017
                {
59,280✔
1018
                        CadMLineTemplate tmp = template as CadMLineTemplate;
59,280✔
1019

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

1045
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1046
                {
2,546✔
1047
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,546✔
1048

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

1059
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1060
                {
15,960✔
1061
                        CadSplineTemplate tmp = template as CadSplineTemplate;
15,960✔
1062

1063
                        XYZ controlPoint;
1064
                        XYZ fitPoint;
1065

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

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

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

1126
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1127
                {
266,368✔
1128
                        CadVertexTemplate tmp = template as CadVertexTemplate;
266,368✔
1129

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

1167
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1168
                {
76,296✔
1169
                        CadViewportTemplate tmp = template as CadViewportTemplate;
76,296✔
1170

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

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

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

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

1207
                        this._reader.ReadNext();
38,840✔
1208

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

1217
                                ExtendedDataRecord record = null;
269,701✔
1218
                                double x = 0;
269,701✔
1219
                                double y = 0;
269,701✔
1220
                                double z = 0;
269,701✔
1221

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

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

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

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

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

1323
                                if (record != null)
269,701✔
1324
                                {
267,255✔
1325
                                        records.Add(record);
267,255✔
1326
                                }
267,255✔
1327

1328
                                this._reader.ReadNext();
269,701✔
1329
                        }
269,701✔
1330
                }
38,840✔
1331

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

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

1343
                                bool end = false;
102,372✔
1344
                                HashSet<int> codes = new();
102,372✔
1345

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

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

1396
                                pattern.Lines.Add(line);
102,372✔
1397
                        }
102,372✔
1398
                }
1,368✔
1399

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

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

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

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

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

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

1440
                                int edges = this._reader.ValueAsInt;
1,140✔
1441
                                this._reader.ReadNext();
1,140✔
1442

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

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

1467
                                this._reader.ReadNext();
3,420✔
1468
                        }
3,420✔
1469

1470
                        return template;
1,824✔
1471
                }
1,824✔
1472

1473
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1474
                {
684✔
1475
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
684✔
1476

1477
                        this._reader.ReadNext();
684✔
1478

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

1485
                        //72
1486
                        bool hasBulge = this._reader.ValueAsBool;
684✔
1487
                        this._reader.ReadNext();
684✔
1488

1489
                        //73
1490
                        bool isClosed = this._reader.ValueAsBool;
684✔
1491
                        this._reader.ReadNext();
684✔
1492

1493
                        //93
1494
                        int nvertices = this._reader.ValueAsInt;
684✔
1495
                        this._reader.ReadNext();
684✔
1496

1497
                        for (int i = 0; i < nvertices; i++)
6,840✔
1498
                        {
2,736✔
1499
                                double bulge = 0.0;
2,736✔
1500

1501
                                //10
1502
                                double x = this._reader.ValueAsDouble;
2,736✔
1503
                                this._reader.ReadNext();
2,736✔
1504
                                //20
1505
                                double y = this._reader.ValueAsDouble;
2,736✔
1506
                                this._reader.ReadNext();
2,736✔
1507

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

1515
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,736✔
1516
                        }
2,736✔
1517

1518
                        return boundary;
684✔
1519
                }
684✔
1520

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

1529
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,560✔
1530
                        this._reader.ReadNext();
4,560✔
1531

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

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

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

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

1630
                                        XYZ controlPoint = new XYZ();
×
1631
                                        XY fitPoint = new XY();
×
1632

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

1692
                                                this._reader.ReadNext();
×
1693
                                        }
×
1694
                        }
1695

1696
                        return null;
×
1697
                }
4,560✔
1698

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

1703
                        template.XDictHandle = xdict;
63,477✔
1704
                        template.ReactorsHandles.UnionWith(reactorsHandles);
63,477✔
1705
                }
63,477✔
1706

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

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

1734
                private HashSet<ulong> readReactors()
1735
                {
49,330✔
1736
                        HashSet<ulong> reactors = new();
49,330✔
1737

1738
                        this._reader.ReadNext();
49,330✔
1739

1740
                        while (this._reader.DxfCode != DxfCode.ControlString)
102,500✔
1741
                        {
53,170✔
1742
                                this._reader.ReadNext();
53,170✔
1743
                        }
53,170✔
1744

1745
                        return reactors;
49,330✔
1746
                }
49,330✔
1747

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

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

1766
                                        object value = this._reader.Value;
1,834,137✔
1767

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

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

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

1790
                        return false;
3,224,115✔
1791
                }
5,141,260✔
1792
        }
1793
}
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