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

DomCR / ACadSharp / 14236632495

03 Apr 2025 06:41AM UTC coverage: 76.148% (-0.2%) from 76.343%
14236632495

Pull #525

github

web-flow
Merge 7f8069492 into 04434c5d6
Pull Request #525: Issue-524 Explode Hatch

5584 of 8036 branches covered (69.49%)

Branch coverage included in aggregate %.

6 of 99 new or added lines in 17 files covered. (6.06%)

6 existing lines in 5 files now uncovered.

22073 of 28284 relevant lines covered (78.04%)

74241.2 hits per line

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

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

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

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

21
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
948✔
22
                {
948✔
23
                        this._reader = reader;
948✔
24
                        this._builder = builder;
948✔
25
                }
948✔
26

27
                public abstract void Read();
28

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

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

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

73
                                this._reader.ReadNext();
6,636✔
74
                        }
6,636✔
75
                }
2,234✔
76

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

105
                                this._reader.ReadNext();
1,728✔
106
                        }
1,728✔
107
                }
576✔
108

109
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
110
                {
1,667,983✔
111
                        isExtendedData = false;
1,667,983✔
112

113
                        switch (this._reader.Code)
1,667,983✔
114
                        {
115
                                //Handle
116
                                case 5:
117
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
261,661✔
118
                                        break;
261,661✔
119
                                //Check with mapper
120
                                case 100:
121
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
176,529!
122
                                        {
3,208✔
123
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
3,208✔
124
                                        }
3,208✔
125
                                        break;
176,529✔
126
                                //Start of application - defined group
127
                                case 102:
128
                                        this.readDefinedGroups(template);
53,843✔
129
                                        break;
53,843✔
130
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
131
                                case 330:
132
                                        template.OwnerHandle = this._reader.ValueAsHandle;
136,637✔
133
                                        break;
136,637✔
134
                                case 1001:
135
                                        isExtendedData = true;
23,015✔
136
                                        this.readExtendedData(template.EDataTemplateByAppName);
23,015✔
137
                                        break;
23,015✔
138
                                default:
139
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
1,016,298✔
140
                                        break;
1,016,298✔
141
                        }
142
                }
1,667,983✔
143

144
                protected CadEntityTemplate readEntity()
145
                {
182,458✔
146
                        switch (this._reader.ValueAsString)
182,458!
147
                        {
148
                                case DxfFileToken.EntityAttribute:
149
                                        return this.readEntityCodes<AttributeEntity>(new CadAttributeTemplate(new AttributeEntity()), this.readAttributeDefinition);
952✔
150
                                case DxfFileToken.EntityAttributeDefinition:
151
                                        return this.readEntityCodes<AttributeDefinition>(new CadAttributeTemplate(new AttributeDefinition()), this.readAttributeDefinition);
1,120✔
152
                                case DxfFileToken.EntityArc:
153
                                        return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), this.readArc);
686✔
154
                                case DxfFileToken.EntityCircle:
155
                                        return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), this.readEntitySubclassMap);
2,072✔
156
                                case DxfFileToken.EntityDimension:
157
                                        return this.readEntityCodes<Dimension>(new CadDimensionTemplate(), this.readDimension);
2,142✔
158
                                case DxfFileToken.Entity3DFace:
159
                                        return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), this.readEntitySubclassMap);
238✔
160
                                case DxfFileToken.EntityEllipse:
161
                                        return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), this.readEntitySubclassMap);
204✔
162
                                case DxfFileToken.EntityLeader:
163
                                        return this.readEntityCodes<Leader>(new CadLeaderTemplate(), this.readLeader);
204✔
164
                                case DxfFileToken.EntityLine:
165
                                        return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), this.readEntitySubclassMap);
56,016✔
166
                                case DxfFileToken.EntityLwPolyline:
167
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
4,260✔
168
                                case DxfFileToken.EntityMesh:
169
                                        return this.readEntityCodes<Mesh>(new CadMeshTemplate(), this.readMesh);
408✔
170
                                case DxfFileToken.EntityHatch:
171
                                        return this.readEntityCodes<Hatch>(new CadHatchTemplate(), this.readHatch);
1,632✔
172
                                case DxfFileToken.EntityInsert:
173
                                        return this.readEntityCodes<Insert>(new CadInsertTemplate(), this.readInsert);
4,654✔
174
                                case DxfFileToken.EntityMText:
175
                                        return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), this.readTextEntity);
6,588✔
176
                                case DxfFileToken.EntityMLine:
177
                                        return this.readEntityCodes<MLine>(new CadMLineTemplate(), this.readMLine);
612✔
178
                                case DxfFileToken.EntityPdfUnderlay:
179
                                        return this.readEntityCodes<PdfUnderlay>(new CadPdfUnderlayTemplate(), this.readUnderlayEntity);
×
180
                                case DxfFileToken.EntityPoint:
181
                                        return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), this.readEntitySubclassMap);
7,700✔
182
                                case DxfFileToken.EntityPolyline:
183
                                        return this.readPolyline();
10,376✔
184
                                case DxfFileToken.EntityRay:
185
                                        return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), this.readEntitySubclassMap);
204✔
186
                                case DxfFileToken.EndSequence:
187
                                        return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), this.readEntitySubclassMap);
10,852✔
188
                                case DxfFileToken.EntitySolid:
189
                                        return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), this.readEntitySubclassMap);
13,294✔
190
                                case DxfFileToken.EntityTable:
191
                                        return this.readEntityCodes<TableEntity>(new CadTableEntityTemplate(), this.readTableEntity);
408✔
192
                                case DxfFileToken.EntityText:
193
                                        return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), this.readTextEntity);
13,626✔
194
                                case DxfFileToken.EntityTolerance:
195
                                        return this.readEntityCodes<Tolerance>(new CadToleranceTemplate(new Tolerance()), this.readTolerance);
612✔
196
                                case DxfFileToken.EntityVertex:
197
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
38,036✔
198
                                case DxfFileToken.EntityViewport:
199
                                        return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
1,244✔
200
                                case DxfFileToken.EntityShape:
201
                                        return this.readEntityCodes<Shape>(new CadShapeTemplate(new Shape()), this.readShape);
238✔
202
                                case DxfFileToken.EntitySpline:
203
                                        return this.readEntityCodes<Spline>(new CadSplineTemplate(), this.readSpline);
408✔
204
                                case DxfFileToken.EntityXline:
205
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
204✔
206
                                default:
207
                                        DxfMap map = DxfMap.Create<Entity>();
3,468✔
208
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
3,468✔
209
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
3,468✔
210
                                        {
3,264✔
211
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
3,264✔
212
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
3,264✔
213
                                        }
3,264✔
214
                                        else
215
                                        {
204✔
216
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
204✔
217
                                        }
204✔
218

219
                                        this._reader.ReadNext();
3,468✔
220

221
                                        do
222
                                        {
385,356✔
223
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
385,356✔
224
                                                {
45,156✔
225
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
45,156✔
226
                                                        if (isExtendedData)
45,156✔
227
                                                                continue;
180✔
228
                                                }
44,976✔
229

230
                                                this._reader.ReadNext();
385,176✔
231
                                        }
385,176✔
232
                                        while (this._reader.DxfCode != DxfCode.Start);
385,356✔
233

234
                                        return unknownEntityTemplate;
3,468✔
235
                        }
236
                }
182,458✔
237

238
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
239
                        where T : Entity
240
                {
179,056✔
241
                        this._reader.ReadNext();
179,056✔
242

243
                        DxfMap map = DxfMap.Create<T>();
179,056✔
244

245
                        while (this._reader.DxfCode != DxfCode.Start)
2,274,228✔
246
                        {
2,095,172✔
247
                                if (!readEntity(template, map))
2,095,172✔
248
                                {
912,126✔
249
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
912,126✔
250
                                        if (isExtendedData)
912,126✔
251
                                                continue;
11,578✔
252
                                }
900,548✔
253

254
                                if (this._reader.DxfCode != DxfCode.Start)
2,083,594✔
255
                                        this._reader.ReadNext();
2,083,528✔
256
                        }
2,083,594✔
257

258
                        return template;
179,056✔
259
                }
179,056✔
260

261
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
262
                {
1,013,360✔
263
                        isExtendedData = false;
1,013,360✔
264
                        switch (this._reader.Code)
1,013,360✔
265
                        {
266
                                case 6:
267
                                        template.LineTypeName = this._reader.ValueAsString;
22,988✔
268
                                        break;
22,988✔
269
                                case 8:
270
                                        template.LayerName = this._reader.ValueAsString;
193,794✔
271
                                        break;
193,794✔
272
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
273
                                case 67:
274
                                        break;
1,224✔
275
                                //Number of bytes Proxy entity graphics data
276
                                case 92:
277
                                case 160:
278
                                //Proxy entity graphics data
279
                                case 310:
280
                                        break;
52,490✔
281
                                case 347:
282
                                        template.MaterialHandle = this._reader.ValueAsHandle;
136✔
283
                                        break;
136✔
284
                                case 430:
285
                                        template.BookColorName = this._reader.ValueAsString;
170✔
286
                                        break;
170✔
287
                                default:
288
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
742,558✔
289
                                        {
629,214✔
290
                                                this.readCommonCodes(template, out isExtendedData, map);
629,214✔
291
                                        }
629,214✔
292
                                        break;
742,558✔
293
                        }
294
                }
1,013,360✔
295

296
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
297
                {
384✔
298
                        if (this._reader.DxfCode == DxfCode.Start)
384✔
299
                        {
192✔
300
                                return true;
192✔
301
                        }
302
                        else
303
                        {
192✔
304
                                return func.Invoke(template, map);
192✔
305
                        }
306
                }
384✔
307

308
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
309
                {
8,992✔
310
                        switch (this._reader.Code)
8,992✔
311
                        {
312
                                default:
313
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
8,992✔
314
                                        {
7,620✔
315
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
7,620✔
316
                                        }
317
                                        return true;
1,372✔
318
                        }
319
                }
8,992✔
320

321
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
322
                {
33,438✔
323
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
33,438✔
324
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
33,438✔
325

326
                        switch (this._reader.Code)
33,438!
327
                        {
328
                                case 44:
329
                                case 46:
330
                                        return true;
×
331
                                case 101:
332
                                        var att = tmp.CadObject as AttributeBase;
66✔
333
                                        att.MText = new MText();
66✔
334
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
66✔
335
                                        tmp.MTextTemplate = mtextTemplate;
66✔
336
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
66✔
337
                                        return true;
66✔
338
                                default:
339
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
33,372✔
340
                                        {
25,250✔
341
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
25,250✔
342
                                        }
343
                                        return true;
8,122✔
344
                        }
345
                }
33,438✔
346

347
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
348
                {
134,334✔
349
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
134,334!
350
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
134,334✔
351
                        TableEntity table = tmp.CadObject as TableEntity;
134,334✔
352

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

424
                private void readCellValue(TableEntity.CellContent content)
425
                {
5,576✔
426
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
5,576!
427
                        {
5,576✔
428
                                this._reader.ReadNext();
5,576✔
429
                        }
5,576✔
430
                        else
431
                        {
×
432
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
433
                        }
434

435
                        while (this._reader.Code != 304
36,448✔
436
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
36,448✔
437
                        {
30,872✔
438
                                switch (this._reader.Code)
30,872!
439
                                {
440
                                        case 1:
441
                                                content.Value.Text = this._reader.ValueAsString;
1,632✔
442
                                                break;
1,632✔
443
                                        case 2:
444
                                                content.Value.Text += this._reader.ValueAsString;
×
445
                                                break;
×
446
                                        case 11:
447
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
136✔
448
                                                break;
136✔
449
                                        case 21:
450
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
136✔
451
                                                break;
136✔
452
                                        case 31:
453
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
136✔
454
                                                break;
136✔
455
                                        case 302:
456
                                                //TODO: Fix this assignation to cell value
457
                                                content.Value.Value = this._reader.ValueAsString;
5,576✔
458
                                                break;
5,576✔
459
                                        case 90:
460
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
5,576✔
461
                                                break;
5,576✔
462
                                        case 91:
463
                                                content.Value.Value = this._reader.ValueAsInt;
136✔
464
                                                break;
136✔
465
                                        case 93:
466
                                                content.Value.Flags = this._reader.ValueAsInt;
5,576✔
467
                                                break;
5,576✔
468
                                        case 94:
469
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
5,576✔
470
                                                break;
5,576✔
471
                                        case 140:
472
                                                content.Value.Value = this._reader.ValueAsDouble;
544✔
473
                                                break;
544✔
474
                                        case 300:
475
                                                content.Value.Format = this._reader.ValueAsString;
5,576✔
476
                                                break;
5,576✔
477
                                        default:
478
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
272✔
479
                                                break;
272✔
480
                                }
481

482
                                this._reader.ReadNext();
30,872✔
483
                        }
30,872✔
484
                }
5,576✔
485

486
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
487
                {
277,734✔
488
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
277,734✔
489
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
277,734✔
490

491
                        switch (this._reader.Code)
277,734✔
492
                        {
493
                                //TODO: Implement multiline text def codes
494
                                case 1 or 3 when tmp.CadObject is MText mtext:
25,004✔
495
                                        mtext.Value += this._reader.ValueAsString;
9,306✔
496
                                        return true;
9,306✔
497
                                case 70:
498
                                case 74:
499
                                case 101:
500
                                        return true;
408✔
501
                                case 7:
502
                                        tmp.StyleName = this._reader.ValueAsString;
2,380✔
503
                                        return true;
2,380✔
504
                                default:
505
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
265,640✔
506
                        }
507
                }
277,734✔
508

509
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
510
                {
6,120✔
511
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
6,120✔
512

513
                        switch (this._reader.Code)
6,120✔
514
                        {
515
                                case 3:
516
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
612✔
517
                                        return true;
612✔
518
                                default:
519
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
5,508✔
520
                        }
521
                }
6,120✔
522

523
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
524
                {
55,760✔
525
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
55,760✔
526

527
                        switch (this._reader.Code)
55,760✔
528
                        {
529
                                case 2:
530
                                        tmp.BlockName = this._reader.ValueAsString;
2,142✔
531
                                        return true;
2,142✔
532
                                case 3:
533
                                        tmp.StyleName = this._reader.ValueAsString;
1,836✔
534
                                        return true;
1,836✔
535
                                case 50:
536
                                        var dim = new DimensionLinear();
238✔
537
                                        tmp.SetDimensionObject(dim);
238✔
538
                                        dim.Rotation = this._reader.ValueAsAngle;
238✔
539
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
238✔
540
                                        return true;
238✔
541
                                case 70:
542
                                        //Flags do not have set
543
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
2,142✔
544
                                        return true;
2,142✔
545
                                //Measurement - read only
546
                                case 42:
547
                                        return true;
1,836✔
548
                                //Undocumented codes
549
                                case 73:
550
                                case 74:
551
                                case 75:
552
                                case 90:
553
                                case 361:
554
                                        return true;
3,672✔
555
                                case 100:
556
                                        switch (this._reader.ValueAsString)
5,712✔
557
                                        {
558
                                                case DxfSubclassMarker.Dimension:
559
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
1,836✔
560
                                                case DxfSubclassMarker.AlignedDimension:
561
                                                        tmp.SetDimensionObject(new DimensionAligned());
612✔
562
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
612✔
563
                                                        return true;
612✔
564
                                                case DxfSubclassMarker.DiametricDimension:
565
                                                        tmp.SetDimensionObject(new DimensionDiameter());
204✔
566
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
204✔
567
                                                        return true;
204✔
568
                                                case DxfSubclassMarker.Angular2LineDimension:
569
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
204✔
570
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
204✔
571
                                                        return true;
204✔
572
                                                case DxfSubclassMarker.Angular3PointDimension:
573
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
204✔
574
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
204✔
575
                                                        return true;
204✔
576
                                                case DxfSubclassMarker.RadialDimension:
577
                                                        tmp.SetDimensionObject(new DimensionRadius());
204✔
578
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
204✔
579
                                                        return true;
204✔
580
                                                case DxfSubclassMarker.OrdinateDimension:
581
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
408✔
582
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
408✔
583
                                                        return true;
408✔
584
                                                case DxfSubclassMarker.LinearDimension:
585
                                                        return true;
204✔
586
                                                default:
587
                                                        return false;
1,836✔
588
                                        }
589
                                default:
590
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
38,182✔
591
                        }
592
                }
55,760✔
593

594
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
595
                {
40,800✔
596
                        CadHatchTemplate tmp = template as CadHatchTemplate;
40,800✔
597
                        Hatch hatch = tmp.CadObject;
40,800✔
598

599
                        bool isFirstSeed = true;
40,800✔
600
                        XY seedPoint = new XY();
40,800✔
601

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

691
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
692
                {
47,792✔
693
                        CadInsertTemplate tmp = template as CadInsertTemplate;
47,792✔
694

695
                        switch (this._reader.Code)
47,792✔
696
                        {
697
                                case 2:
698
                                        tmp.BlockName = this._reader.ValueAsString;
4,654✔
699
                                        return true;
4,654✔
700
                                case 100:
701
                                        //AcDbEntity
702
                                        //AcDbBlockReference
703
                                        //AcDbMInsertBlock
704
                                        return true;
4,344✔
705
                                case 66:
706
                                        return true;
476✔
707
                                default:
708
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
38,318✔
709
                        }
710
                }
47,792✔
711

712
                private CadEntityTemplate readPolyline()
713
                {
10,376✔
714
                        CadPolyLineTemplate template = null;
10,376✔
715

716
                        if (this._builder.Version == ACadVersion.Unknown)
10,376!
717
                        {
×
718
                                var polyline = new Polyline2D();
×
719
                                template = new CadPolyLineTemplate(polyline);
×
720
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
×
721

722
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
×
723
                                {
×
724
                                        Vertex2D v = new Vertex2D();
×
725
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
×
726
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
×
727

728
                                        if (vertexTemplate.Vertex.Handle == 0)
×
729
                                        {
×
730
                                                template.PolyLine.Vertices.Add(vertexTemplate.Vertex);
×
731
                                        }
×
732
                                        else
733
                                        {
×
734
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
735
                                                this._builder.AddTemplate(vertexTemplate);
×
736
                                        }
×
737
                                }
×
738

739
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
×
740
                                {
×
741
                                        var seqend = new Seqend();
×
742
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
×
743
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
×
744

745
                                        this._builder.AddTemplate(seqendTemplate);
×
746

747
                                        template.SeqendHandle = seqend.Handle;
×
748
                                }
×
749
                        }
×
750
                        else
751
                        {
10,376✔
752
                                template = new CadPolyLineTemplate();
10,376✔
753
                                this.readEntityCodes<Entity>(template, this.readPolyline);
10,376✔
754
                        }
10,376✔
755

756
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
10,376✔
757
                        {
9,968✔
758
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
9,968✔
759
                                return null;
9,968✔
760
                        }
761

762
                        return template;
408✔
763
                }
10,376✔
764

765
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
766
                {
74,532✔
767
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
74,532✔
768

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

809
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
810
                {
5,100✔
811
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
5,100✔
812

813
                        switch (this._reader.Code)
5,100✔
814
                        {
815
                                case 3:
816
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
204✔
817
                                        return true;
204✔
818
                                case 10:
819
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
816✔
820
                                        return true;
816✔
821
                                case 20:
822
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
823
                                        y.Y = this._reader.ValueAsDouble;
816✔
824
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
816✔
825
                                        return true;
816✔
826
                                case 30:
827
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
816✔
828
                                        z.Z = this._reader.ValueAsDouble;
816✔
829
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
816✔
830
                                        return true;
816✔
831
                                case 340:
832
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
204✔
833
                                        return true;
204✔
834
                                //Vertices count
835
                                case 76:
836
                                        return true;
204✔
837
                                default:
838
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
839
                        }
840
                }
5,100✔
841

842
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
843
                {
80,484✔
844
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
80,484✔
845

846
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
80,484✔
847

848
                        switch (this._reader.Code)
80,484!
849
                        {
850
                                case 10:
851
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
19,068✔
852
                                        return true;
19,068✔
853
                                case 20:
854
                                        if (last is not null)
19,068✔
855
                                        {
19,068✔
856
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
19,068✔
857
                                        }
19,068✔
858
                                        return true;
19,068✔
859
                                case 40:
860
                                        if (last is not null)
2,040✔
861
                                        {
2,040✔
862
                                                last.StartWidth = this._reader.ValueAsDouble;
2,040✔
863
                                        }
2,040✔
864
                                        return true;
2,040✔
865
                                case 41:
866
                                        if (last is not null)
2,040✔
867
                                        {
2,040✔
868
                                                last.EndWidth = this._reader.ValueAsDouble;
2,040✔
869
                                        }
2,040✔
870
                                        return true;
2,040✔
871
                                case 42:
872
                                        if (last is not null)
2,784✔
873
                                        {
2,784✔
874
                                                last.Bulge = this._reader.ValueAsDouble;
2,784✔
875
                                        }
2,784✔
876
                                        return true;
2,784✔
877
                                case 50:
878
                                        if (last is not null)
×
879
                                        {
×
880
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
881
                                        }
×
882
                                        return true;
×
883
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
884
                                case 66:
885
                                //Vertex count
886
                                case 90:
887
                                        return true;
4,260✔
888
                                case 91:
889
                                        if (last is not null)
×
890
                                        {
×
891
                                                last.Id = this._reader.ValueAsInt;
×
892
                                        }
×
893
                                        return true;
×
894
                                default:
895
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
31,224✔
896
                        }
897
                }
80,484✔
898

899
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
900
                {
35,904✔
901
                        CadMeshTemplate tmp = template as CadMeshTemplate;
35,904✔
902

903
                        switch (this._reader.Code)
35,904✔
904
                        {
905
                                case 100:
906
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
816✔
907
                                        {
408✔
908
                                                tmp.SubclassMarker = true;
408✔
909
                                        }
408✔
910
                                        return true;
816✔
911
                                //Count of sub-entity which property has been overridden
912
                                case 90:
913
                                        //TODO: process further entities
914
                                        return true;
408✔
915
                                case 92:
916
                                        if (!tmp.SubclassMarker)
612✔
917
                                        {
204✔
918
                                                return false;
204✔
919
                                        }
920

921
                                        int nvertices = this._reader.ValueAsInt;
408✔
922
                                        for (int i = 0; i < nvertices; i++)
52,224✔
923
                                        {
25,704✔
924
                                                this._reader.ReadNext();
25,704✔
925
                                                double x = this._reader.ValueAsDouble;
25,704✔
926
                                                this._reader.ReadNext();
25,704✔
927
                                                double y = this._reader.ValueAsDouble;
25,704✔
928
                                                this._reader.ReadNext();
25,704✔
929
                                                double z = this._reader.ValueAsDouble;
25,704✔
930
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
25,704✔
931
                                        }
25,704✔
932
                                        return true;
408✔
933
                                case 93:
934
                                        int size = this._reader.ValueAsInt;
408✔
935
                                        this._reader.ReadNext();
408✔
936

937
                                        int indexes = 0;
408✔
938
                                        for (int i = 0; i < size; i += indexes + 1)
56,304✔
939
                                        {
27,744✔
940
                                                indexes = this._reader.ValueAsInt;
27,744✔
941
                                                this._reader.ReadNext();
27,744✔
942

943
                                                int[] face = new int[indexes];
27,744✔
944
                                                for (int j = 0; j < indexes; j++)
267,648✔
945
                                                {
106,080✔
946
                                                        face[j] = this._reader.ValueAsInt;
106,080✔
947

948
                                                        if ((i + j + 2) < size)
106,080✔
949
                                                        {
105,672✔
950
                                                                this._reader.ReadNext();
105,672✔
951
                                                        }
105,672✔
952
                                                }
106,080✔
953

954
                                                tmp.CadObject.Faces.Add(face);
27,744✔
955
                                        }
27,744✔
956

957
                                        Debug.Assert(this._reader.Code == 90);
408✔
958

959
                                        return true;
408✔
960
                                case 94:
961
                                        int numEdges = this._reader.ValueAsInt;
408✔
962
                                        this._reader.ReadNext();
408✔
963
                                        for (int i = 0; i < numEdges; i++)
106,896✔
964
                                        {
53,040✔
965
                                                Mesh.Edge edge = new Mesh.Edge();
53,040✔
966

967
                                                edge.Start = this._reader.ValueAsInt;
53,040✔
968
                                                this._reader.ReadNext();
53,040✔
969
                                                edge.End = this._reader.ValueAsInt;
53,040✔
970

971
                                                if (i < numEdges - 1)
53,040✔
972
                                                {
52,632✔
973
                                                        this._reader.ReadNext();
52,632✔
974
                                                }
52,632✔
975

976
                                                tmp.CadObject.Edges.Add(edge);
53,040✔
977
                                        }
53,040✔
978

979
                                        Debug.Assert(this._reader.Code == 90);
408✔
980

981
                                        return true;
408✔
982
                                case 95:
983
                                        this._reader.ReadNext();
408✔
984
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
106,896✔
985
                                        {
53,040✔
986
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
53,040✔
987
                                                edge.Crease = this._reader.ValueAsDouble;
53,040✔
988

989
                                                tmp.CadObject.Edges[i] = edge;
53,040✔
990

991
                                                if (i < tmp.CadObject.Edges.Count - 1)
53,040✔
992
                                                {
52,632✔
993
                                                        this._reader.ReadNext();
52,632✔
994
                                                }
52,632✔
995
                                        }
53,040✔
996

997
                                        Debug.Assert(this._reader.Code == 140);
408✔
998

999
                                        return true;
408✔
1000
                                default:
1001
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
32,844✔
1002
                        }
1003
                }
35,904✔
1004

1005
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
1006
                {
53,040✔
1007
                        CadMLineTemplate tmp = template as CadMLineTemplate;
53,040✔
1008

1009
                        switch (this._reader.Code)
53,040✔
1010
                        {
1011
                                // 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.
1012
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1013
                                case 2:
1014
                                        tmp.MLineStyleName = this._reader.ValueAsString;
612✔
1015
                                        return true;
612✔
1016
                                case 72:
1017
                                        tmp.NVertex = this._reader.ValueAsInt;
612✔
1018
                                        return true;
612✔
1019
                                case 73:
1020
                                        tmp.NElements = this._reader.ValueAsInt;
612✔
1021
                                        return true;
612✔
1022
                                case 340:
1023
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
612✔
1024
                                        return true;
612✔
1025
                                default:
1026
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
50,592✔
1027
                                        {
8,568✔
1028
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
8,568✔
1029
                                        }
1030
                                        return true;
42,024✔
1031
                        }
1032
                }
53,040✔
1033

1034
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1035
                {
2,278✔
1036
                        CadShapeTemplate tmp = template as CadShapeTemplate;
2,278✔
1037

1038
                        switch (this._reader.Code)
2,278✔
1039
                        {
1040
                                case 2:
1041
                                        tmp.ShapeFileName = this._reader.ValueAsString;
238✔
1042
                                        return true;
238✔
1043
                                default:
1044
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
2,040✔
1045
                        }
1046
                }
2,278✔
1047

1048
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1049
                {
14,280✔
1050
                        CadSplineTemplate tmp = template as CadSplineTemplate;
14,280✔
1051

1052
                        XYZ controlPoint;
1053

1054
                        switch (this._reader.Code)
14,280!
1055
                        {
1056
                                case 10:
1057
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,632✔
1058
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,632✔
1059
                                        return true;
1,632✔
1060
                                case 20:
1061
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1062
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,632✔
1063
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1064
                                        return true;
1,632✔
1065
                                case 30:
1066
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,632✔
1067
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,632✔
1068
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,632✔
1069
                                        return true;
1,632✔
1070
                                case 40:
1071
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
3,264✔
1072
                                        return true;
3,264✔
1073
                                case 41:
1074
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1075
                                        return true;
×
1076
                                case 72:
1077
                                case 73:
1078
                                case 74:
1079
                                        return true;
1,224✔
1080
                                default:
1081
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,896✔
1082
                        }
1083
                }
14,280✔
1084

1085
                private bool readUnderlayEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
1086
                {
×
1087
                        CadPdfUnderlayTemplate tmp = template as CadPdfUnderlayTemplate;
×
1088

1089
                        switch (this._reader.Code)
×
1090
                        {
1091
                                case 340:
1092
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
×
1093
                                        return true;
×
1094
                                default:
1095
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1096
                        }
1097
                }
×
1098

1099
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1100
                {
236,892✔
1101
                        CadVertexTemplate tmp = template as CadVertexTemplate;
236,892✔
1102

1103
                        switch (this._reader.Code)
236,892✔
1104
                        {
1105
                                //Polyface mesh vertex index
1106
                                case 71:
1107
                                case 72:
1108
                                case 73:
1109
                                case 74:
1110
                                        return true;
1,666✔
1111
                                case 100:
1112
                                        switch (this._reader.ValueAsString)
6,936!
1113
                                        {
1114
                                                case DxfSubclassMarker.Vertex:
1115
                                                        return true;
2,040✔
1116
                                                case DxfSubclassMarker.PolylineVertex:
1117
                                                        tmp.SetVertexObject(new Vertex2D());
×
1118
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1119
                                                        return true;
×
1120
                                                case DxfSubclassMarker.Polyline3dVertex:
1121
                                                        tmp.SetVertexObject(new Vertex3D());
1,020✔
1122
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
1,020✔
1123
                                                        return true;
1,020✔
1124
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1125
                                                        tmp.SetVertexObject(new VertexFaceMesh());
1,020✔
1126
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
1,020✔
1127
                                                        return true;
1,020✔
1128
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1129
                                                        tmp.SetVertexObject(new VertexFaceRecord());
408✔
1130
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
408✔
1131
                                                        return true;
408✔
1132
                                                default:
1133
                                                        return false;
2,448✔
1134
                                        }
1135
                                default:
1136
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
228,290✔
1137
                        }
1138
                }
236,892✔
1139

1140
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1141
                {
67,976✔
1142
                        CadViewportTemplate tmp = template as CadViewportTemplate;
67,976✔
1143

1144
                        switch (this._reader.Code)
67,976!
1145
                        {
1146
                                //Undocumented
1147
                                case 67:
1148
                                case 68:
1149
                                        return true;
2,488✔
1150
                                case 69:
1151
                                        tmp.ViewportId = this._reader.ValueAsShort;
1,244✔
1152
                                        return true;
1,244✔
1153
                                case 331:
1154
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1155
                                        return true;
×
1156
                                case 348:
1157
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
784✔
1158
                                        return true;
784✔
1159
                                default:
1160
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
63,460✔
1161
                        }
1162
                }
67,976✔
1163

1164
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1165
                {
1,006,068✔
1166
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
1,006,068✔
1167

1168
                        switch (this._reader.Code)
1,006,068✔
1169
                        {
1170
                                default:
1171
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
1,006,068✔
1172
                        }
1173
                }
1,006,068✔
1174

1175
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1176
                {
33,442✔
1177
                        List<ExtendedDataRecord> records = new();
33,442✔
1178
                        edata.Add(this._reader.ValueAsString, records);
33,442✔
1179

1180
                        this._reader.ReadNext();
33,442✔
1181

1182
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
267,155✔
1183
                        {
243,953✔
1184
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
243,953✔
1185
                                {
10,240✔
1186
                                        this.readExtendedData(edata);
10,240✔
1187
                                        break;
10,240✔
1188
                                }
1189

1190
                                ExtendedDataRecord record = null;
233,713✔
1191
                                double x = 0;
233,713✔
1192
                                double y = 0;
233,713✔
1193
                                double z = 0;
233,713✔
1194

1195
                                switch (this._reader.DxfCode)
233,713✔
1196
                                {
1197
                                        case DxfCode.ExtendedDataAsciiString:
1198
                                        case DxfCode.ExtendedDataRegAppName:
1199
                                                record = new ExtendedDataString(this._reader.ValueAsString);
25,389✔
1200
                                                break;
25,389✔
1201
                                        case DxfCode.ExtendedDataControlString:
1202
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
13,472✔
1203
                                                break;
13,472✔
1204
                                        case DxfCode.ExtendedDataLayerName:
1205
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
238✔
1206
                                                {
224✔
1207
                                                        record = new ExtendedDataLayer(layer.Handle);
224✔
1208
                                                }
224✔
1209
                                                else
1210
                                                {
14✔
1211
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
14✔
1212
                                                }
14✔
1213
                                                break;
238✔
1214
                                        case DxfCode.ExtendedDataBinaryChunk:
1215
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
68✔
1216
                                                break;
68✔
1217
                                        case DxfCode.ExtendedDataHandle:
1218
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
2,304✔
1219
                                                break;
2,304✔
1220
                                        case DxfCode.ExtendedDataXCoordinate:
1221
                                                x = this._reader.ValueAsDouble;
2,540✔
1222
                                                this._reader.ReadNext();
2,540✔
1223
                                                y = this._reader.ValueAsDouble;
2,540✔
1224
                                                this._reader.ReadNext();
2,540✔
1225
                                                z = this._reader.ValueAsDouble;
2,540✔
1226

1227
                                                record = new ExtendedDataCoordinate(
2,540✔
1228
                                                        new XYZ(
2,540✔
1229
                                                                x,
2,540✔
1230
                                                                y,
2,540✔
1231
                                                                z)
2,540✔
1232
                                                        );
2,540✔
1233
                                                break;
2,540✔
1234
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1235
                                                x = this._reader.ValueAsDouble;
1,224✔
1236
                                                this._reader.ReadNext();
1,224✔
1237
                                                y = this._reader.ValueAsDouble;
1,224✔
1238
                                                this._reader.ReadNext();
1,224✔
1239
                                                z = this._reader.ValueAsDouble;
1,224✔
1240

1241
                                                record = new ExtendedDataWorldCoordinate(
1,224✔
1242
                                                        new XYZ(
1,224✔
1243
                                                                x,
1,224✔
1244
                                                                y,
1,224✔
1245
                                                                z)
1,224✔
1246
                                                        );
1,224✔
1247
                                                break;
1,224✔
1248
                                        case DxfCode.ExtendedDataWorldXDisp:
1249
                                                x = this._reader.ValueAsDouble;
238✔
1250
                                                this._reader.ReadNext();
238✔
1251
                                                y = this._reader.ValueAsDouble;
238✔
1252
                                                this._reader.ReadNext();
238✔
1253
                                                z = this._reader.ValueAsDouble;
238✔
1254

1255
                                                record = new ExtendedDataDisplacement(
238✔
1256
                                                        new XYZ(
238✔
1257
                                                                x,
238✔
1258
                                                                y,
238✔
1259
                                                                z)
238✔
1260
                                                        );
238✔
1261
                                                break;
238✔
1262
                                        case DxfCode.ExtendedDataWorldXDir:
1263
                                                x = this._reader.ValueAsDouble;
238✔
1264
                                                this._reader.ReadNext();
238✔
1265
                                                y = this._reader.ValueAsDouble;
238✔
1266
                                                this._reader.ReadNext();
238✔
1267
                                                z = this._reader.ValueAsDouble;
238✔
1268

1269
                                                record = new ExtendedDataDirection(
238✔
1270
                                                        new XYZ(
238✔
1271
                                                                x,
238✔
1272
                                                                y,
238✔
1273
                                                                z)
238✔
1274
                                                        );
238✔
1275
                                                break;
238✔
1276
                                        case DxfCode.ExtendedDataReal:
1277
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
118,942✔
1278
                                                break;
118,942✔
1279
                                        case DxfCode.ExtendedDataDist:
1280
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
238✔
1281
                                                break;
238✔
1282
                                        case DxfCode.ExtendedDataScale:
1283
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
238✔
1284
                                                break;
238✔
1285
                                        case DxfCode.ExtendedDataInteger16:
1286
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
59,109✔
1287
                                                break;
59,109✔
1288
                                        case DxfCode.ExtendedDataInteger32:
1289
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
7,299✔
1290
                                                break;
7,299✔
1291
                                        default:
1292
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
2,176✔
1293
                                                break;
2,176✔
1294
                                }
1295

1296
                                if (record != null)
233,713✔
1297
                                {
231,523✔
1298
                                        records.Add(record);
231,523✔
1299
                                }
231,523✔
1300

1301
                                this._reader.ReadNext();
233,713✔
1302
                        }
233,713✔
1303
                }
33,442✔
1304

1305
                private void readPattern(HatchPattern pattern, int nlines)
1306
                {
1,224✔
1307
                        //Jump 78 code
1308
                        this._reader.ReadNext();
1,224✔
1309

1310
                        for (int i = 0; i < nlines; i++)
185,640✔
1311
                        {
91,596✔
1312
                                HatchPattern.Line line = new HatchPattern.Line();
91,596✔
1313
                                XY basePoint = new XY();
91,596✔
1314
                                XY offset = new XY();
91,596✔
1315

1316
                                bool end = false;
91,596✔
1317
                                HashSet<int> codes = new();
91,596✔
1318

1319
                                while (!end)
642,396✔
1320
                                {
641,172✔
1321
                                        if (codes.Contains(this._reader.Code))
641,172✔
1322
                                        {
90,372✔
1323
                                                break;
90,372✔
1324
                                        }
1325
                                        else
1326
                                        {
550,800✔
1327
                                                codes.Add(this._reader.Code);
550,800✔
1328
                                        }
550,800✔
1329

1330
                                        switch (this._reader.Code)
550,800!
1331
                                        {
1332
                                                case 53:
1333
                                                        line.Angle = this._reader.ValueAsAngle;
91,596✔
1334
                                                        break;
91,596✔
1335
                                                case 43:
1336
                                                        basePoint.X = this._reader.ValueAsDouble;
91,596✔
1337
                                                        break;
91,596✔
1338
                                                case 44:
1339
                                                        basePoint.Y = this._reader.ValueAsDouble;
91,596✔
1340
                                                        line.BasePoint = basePoint;
91,596✔
1341
                                                        break;
91,596✔
1342
                                                case 45:
1343
                                                        offset.X = this._reader.ValueAsDouble;
91,596✔
1344
                                                        line.Offset = offset;
91,596✔
1345
                                                        break;
91,596✔
1346
                                                case 46:
1347
                                                        offset.Y = this._reader.ValueAsDouble;
91,596✔
1348
                                                        line.Offset = offset;
91,596✔
1349
                                                        break;
91,596✔
1350
                                                //Number of dash length items
1351
                                                case 79:
1352
                                                        int ndash = this._reader.ValueAsInt;
91,596✔
1353
                                                        for (int j = 0; j < ndash; j++)
548,760✔
1354
                                                        {
182,784✔
1355
                                                                this._reader.ReadNext();
182,784✔
1356
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
182,784✔
1357
                                                        }
182,784✔
1358
                                                        break;
91,596✔
1359
                                                case 49:
1360
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1361
                                                        break;
×
1362
                                                default:
1363
                                                        end = true;
1,224✔
1364
                                                        break;
1,224✔
1365
                                        }
1366
                                        this._reader.ReadNext();
550,800✔
1367
                                }
550,800✔
1368

1369
                                pattern.Lines.Add(line);
91,596✔
1370
                        }
91,596✔
1371
                }
1,224✔
1372

1373
                private void readLoops(CadHatchTemplate template, int count)
1374
                {
1,632✔
1375
                        if (this._reader.Code == 91)
1,632✔
1376
                                this._reader.ReadNext();
1,632✔
1377

1378
                        for (int i = 0; i < count; i++)
6,528✔
1379
                        {
1,632✔
1380
                                if (this._reader.Code != 92)
1,632!
1381
                                {
×
1382
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1383
                                        break;
×
1384
                                }
1385

1386
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
1,632✔
1387
                                if (path != null)
1,632✔
1388
                                        template.PathTempaltes.Add(path);
1,632✔
1389
                        }
1,632✔
1390
                }
1,632✔
1391

1392
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1393
                {
1,632✔
1394
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
1,632✔
1395
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
1,632✔
1396
                        template.Path.Flags = flags;
1,632✔
1397

1398
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
1,632✔
1399
                        {
612✔
1400
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
612✔
1401
                                template.Path.Edges.Add(pl);
612✔
1402
                        }
612✔
1403
                        else
1404
                        {
1,020✔
1405
                                this._reader.ReadNext();
1,020✔
1406

1407
                                if (this._reader.Code != 93)
1,020!
1408
                                {
×
1409
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1410
                                        return null;
×
1411
                                }
1412

1413
                                int edges = this._reader.ValueAsInt;
1,020✔
1414
                                this._reader.ReadNext();
1,020✔
1415

1416
                                for (int i = 0; i < edges; i++)
10,200✔
1417
                                {
4,080✔
1418
                                        var edge = this.readEdge();
4,080✔
1419
                                        if (edge != null)
4,080✔
1420
                                                template.Path.Edges.Add(edge);
4,080✔
1421
                                }
4,080✔
1422
                        }
1,020✔
1423

1424
                        bool end = false;
1,632✔
1425
                        while (!end)
6,324✔
1426
                        {
4,692✔
1427
                                switch (this._reader.Code)
4,692✔
1428
                                {
1429
                                        //Number of source boundary objects
1430
                                        case 97:
1431
                                                break;
1,632✔
1432
                                        case 330:
1433
                                                template.Handles.Add(this._reader.ValueAsHandle);
1,428✔
1434
                                                break;
1,428✔
1435
                                        default:
1436
                                                end = true;
1,632✔
1437
                                                continue;
1,632✔
1438
                                }
1439

1440
                                this._reader.ReadNext();
3,060✔
1441
                        }
3,060✔
1442

1443
                        return template;
1,632✔
1444
                }
1,632✔
1445

1446
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1447
                {
612✔
1448
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
612✔
1449

1450
                        this._reader.ReadNext();
612✔
1451

1452
                        if (this._reader.Code != 72)
612!
1453
                        {
×
1454
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1455
                                return null;
×
1456
                        }
1457

1458
                        //72
1459
                        bool hasBulge = this._reader.ValueAsBool;
612✔
1460
                        this._reader.ReadNext();
612✔
1461

1462
                        //73
1463
                        bool isClosed = this._reader.ValueAsBool;
612✔
1464
                        this._reader.ReadNext();
612✔
1465

1466
                        //93
1467
                        int nvertices = this._reader.ValueAsInt;
612✔
1468
                        this._reader.ReadNext();
612✔
1469

1470
                        for (int i = 0; i < nvertices; i++)
6,120✔
1471
                        {
2,448✔
1472
                                double bulge = 0.0;
2,448✔
1473

1474
                                //10
1475
                                double x = this._reader.ValueAsDouble;
2,448✔
1476
                                this._reader.ReadNext();
2,448✔
1477
                                //20
1478
                                double y = this._reader.ValueAsDouble;
2,448✔
1479
                                this._reader.ReadNext();
2,448✔
1480

1481
                                if (hasBulge)
2,448!
1482
                                {
×
1483
                                        //42
1484
                                        bulge = this._reader.ValueAsDouble;
×
1485
                                        this._reader.ReadNext();
×
1486
                                }
×
1487

1488
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
2,448✔
1489
                        }
2,448✔
1490

1491
                        return boundary;
612✔
1492
                }
612✔
1493

1494
                private Hatch.BoundaryPath.Edge readEdge()
1495
                {
4,080✔
1496
                        if (this._reader.Code != 72)
4,080!
1497
                        {
×
1498
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1499
                                return null;
×
1500
                        }
1501

1502
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
4,080✔
1503
                        this._reader.ReadNext();
4,080✔
1504

1505
                        switch (type)
4,080!
1506
                        {
1507
                                case Hatch.BoundaryPath.EdgeType.Line:
1508
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
4,080✔
1509
                                        while (true)
20,400✔
1510
                                        {
20,400✔
1511
                                                switch (this._reader.Code)
20,400✔
1512
                                                {
1513
                                                        case 10:
1514
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
4,080✔
1515
                                                                break;
4,080✔
1516
                                                        case 20:
1517
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
4,080✔
1518
                                                                break;
4,080✔
1519
                                                        case 11:
1520
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
4,080✔
1521
                                                                break;
4,080✔
1522
                                                        case 21:
1523
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
4,080✔
1524
                                                                break;
4,080✔
1525
                                                        default:
1526
                                                                return line;
4,080✔
1527
                                                }
1528

1529
                                                this._reader.ReadNext();
16,320✔
1530
                                        }
16,320✔
1531
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1532
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1533
                                        while (true)
×
1534
                                        {
×
1535
                                                switch (this._reader.Code)
×
1536
                                                {
1537
                                                        case 10:
1538
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1539
                                                                break;
×
1540
                                                        case 20:
1541
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1542
                                                                break;
×
1543
                                                        case 40:
1544
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1545
                                                                break;
×
1546
                                                        case 50:
1547
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1548
                                                                break;
×
1549
                                                        case 51:
1550
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1551
                                                                break;
×
1552
                                                        case 73:
1553
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1554
                                                                break;
×
1555
                                                        default:
1556
                                                                return arc;
×
1557
                                                }
1558

1559
                                                this._reader.ReadNext();
×
1560
                                        }
×
1561
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1562
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1563
                                        while (true)
×
1564
                                        {
×
1565
                                                switch (this._reader.Code)
×
1566
                                                {
1567
                                                        case 10:
1568
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1569
                                                                break;
×
1570
                                                        case 20:
1571
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1572
                                                                break;
×
1573
                                                        case 11:
1574
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1575
                                                                break;
×
1576
                                                        case 21:
1577
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1578
                                                                break;
×
1579
                                                        case 40:
1580
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1581
                                                                break;
×
1582
                                                        case 50:
1583
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1584
                                                                break;
×
1585
                                                        case 51:
1586
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
1587
                                                                break;
×
1588
                                                        case 73:
NEW
1589
                                                                ellipse.IsCounterclockwise = this._reader.ValueAsBool;
×
1590
                                                                break;
×
1591
                                                        default:
1592
                                                                return ellipse;
×
1593
                                                }
1594

1595
                                                this._reader.ReadNext();
×
1596
                                        }
×
1597
                                case Hatch.BoundaryPath.EdgeType.Spline:
1598
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1599
                                        int nKnots = 0;
×
1600
                                        int nCtrlPoints = 0;
×
1601
                                        int nFitPoints = 0;
×
1602

1603
                                        XYZ controlPoint = new XYZ();
×
1604
                                        XY fitPoint = new XY();
×
1605

1606
                                        while (true)
×
1607
                                        {
×
1608
                                                switch (this._reader.Code)
×
1609
                                                {
1610
                                                        case 10:
1611
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1612
                                                                break;
×
1613
                                                        case 20:
1614
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1615
                                                                spline.ControlPoints.Add(controlPoint);
×
1616
                                                                break;
×
1617
                                                        case 11:
1618
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
1619
                                                                break;
×
1620
                                                        case 21:
1621
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
1622
                                                                spline.FitPoints.Add(fitPoint);
×
1623
                                                                break;
×
1624
                                                        case 42:
1625
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
1626
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1627
                                                                break;
×
1628
                                                        case 12:
1629
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1630
                                                                break;
×
1631
                                                        case 22:
1632
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
1633
                                                                break;
×
1634
                                                        case 13:
1635
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1636
                                                                break;
×
1637
                                                        case 23:
1638
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1639
                                                                break;
×
1640
                                                        case 94:
1641
                                                                spline.Degree = this._reader.ValueAsInt;
×
1642
                                                                break;
×
1643
                                                        case 73:
1644
                                                                spline.Rational = this._reader.ValueAsBool;
×
1645
                                                                break;
×
1646
                                                        case 74:
1647
                                                                spline.Periodic = this._reader.ValueAsBool;
×
1648
                                                                break;
×
1649
                                                        case 95:
1650
                                                                nKnots = this._reader.ValueAsInt;
×
1651
                                                                break;
×
1652
                                                        case 96:
1653
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1654
                                                                break;
×
1655
                                                        case 97:
1656
                                                                nFitPoints = this._reader.ValueAsInt;
×
1657
                                                                break;
×
1658
                                                        case 40:
1659
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
1660
                                                                break;
×
1661
                                                        default:
1662
                                                                return spline;
×
1663
                                                }
1664

1665
                                                this._reader.ReadNext();
×
1666
                                        }
×
1667
                        }
1668

1669
                        return null;
×
1670
                }
4,080✔
1671

1672
                private void readDefinedGroups(CadTemplate template)
1673
                {
54,419✔
1674
                        this.readDefinedGroups(out ulong? xdict, out List<ulong> reactorsHandles);
54,419✔
1675

1676
                        template.XDictHandle = xdict;
54,419✔
1677
                        template.ReactorsHandles = reactorsHandles;
54,419✔
1678
                }
54,419✔
1679

1680
                private void readDefinedGroups(out ulong? xdictHandle, out List<ulong> reactors)
1681
                {
54,625✔
1682
                        xdictHandle = null;
54,625✔
1683
                        reactors = new List<ulong>();
54,625✔
1684

1685
                        switch (this._reader.ValueAsString)
54,625✔
1686
                        {
1687
                                case DxfFileToken.DictionaryToken:
1688
                                        this._reader.ReadNext();
10,613✔
1689
                                        xdictHandle = this._reader.ValueAsHandle;
10,613✔
1690
                                        this._reader.ReadNext();
10,613✔
1691
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
10,613✔
1692
                                        return;
10,613✔
1693
                                case DxfFileToken.ReactorsToken:
1694
                                        reactors = this.readReactors();
42,176✔
1695
                                        break;
42,176✔
1696
                                case DxfFileToken.BlkRefToken:
1697
                                default:
1698
                                        do
1699
                                        {
4,488✔
1700
                                                this._reader.ReadNext();
4,488✔
1701
                                        }
4,488✔
1702
                                        while (this._reader.DxfCode != DxfCode.ControlString);
4,488✔
1703
                                        return;
1,836✔
1704
                        }
1705
                }
54,625✔
1706

1707
                private List<ulong> readReactors()
1708
                {
42,176✔
1709
                        List<ulong> reactors = new List<ulong>();
42,176✔
1710

1711
                        this._reader.ReadNext();
42,176✔
1712

1713
                        while (this._reader.DxfCode != DxfCode.ControlString)
87,436✔
1714
                        {
45,260✔
1715
                                this._reader.ReadNext();
45,260✔
1716
                        }
45,260✔
1717

1718
                        return reactors;
42,176✔
1719
                }
42,176✔
1720

1721
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
1722
                {
4,285,210✔
1723
                        try
1724
                        {
4,285,210✔
1725
                                //Use this method only if the value is not a link between objects
1726
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
4,285,210✔
1727
                                {
1,611,053✔
1728
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
1,611,053✔
1729
                                        {
12,172✔
1730
                                                return true;
12,172✔
1731
                                        }
1732

1733
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
1,598,881!
1734
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
1,598,881✔
1735
                                        {
61,440✔
1736
                                                return false;
61,440✔
1737
                                        }
1738

1739
                                        object value = this._reader.Value;
1,537,441✔
1740

1741
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
1,537,441✔
1742
                                        {
8,038✔
1743
                                                value = MathHelper.DegToRad((double)value);
8,038✔
1744
                                        }
8,038✔
1745

1746
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
1,537,441✔
1747

1748
                                        return true;
1,537,441✔
1749
                                }
1750
                        }
2,674,157✔
1751
                        catch (Exception ex)
×
1752
                        {
×
1753
                                if (!this._builder.Configuration.Failsafe)
×
1754
                                {
×
1755
                                        throw ex;
×
1756
                                }
1757
                                else
1758
                                {
×
1759
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
1760
                                }
×
1761
                        }
×
1762

1763
                        return false;
2,674,157✔
1764
                }
4,285,210✔
1765
        }
1766
}
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