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

DomCR / ACadSharp / 12804163838

16 Jan 2025 07:33AM UTC coverage: 75.876% (+0.1%) from 75.732%
12804163838

Pull #523

github

web-flow
Merge 0e0ca78e3 into 639b4e770
Pull Request #523: Issue 521 predefined patterns

5270 of 7670 branches covered (68.71%)

Branch coverage included in aggregate %.

96 of 104 new or added lines in 4 files covered. (92.31%)

5 existing lines in 3 files now uncovered.

21052 of 27021 relevant lines covered (77.91%)

39205.94 hits per line

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

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

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

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

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

26
                public abstract void Read();
27

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

36
                        if (this._reader.DxfCode == DxfCode.Start
1,625!
37
                                        || this._reader.DxfCode == DxfCode.Subclass)
1,625✔
38
                                this._reader.ReadNext();
×
39

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

72
                                this._reader.ReadNext();
4,848✔
73
                        }
4,848✔
74
                }
1,625✔
75

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

104
                                this._reader.ReadNext();
738✔
105
                        }
738✔
106
                }
246✔
107

108
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
109
                {
774,280✔
110
                        isExtendedData = false;
774,280✔
111

112
                        switch (this._reader.Code)
774,280✔
113
                        {
114
                                //Handle
115
                                case 5:
116
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
120,709✔
117
                                        break;
120,709✔
118
                                //Check with mapper
119
                                case 100:
120
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
85,691!
121
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
744✔
122
                                        break;
85,691✔
123
                                //Start of application - defined group
124
                                case 102:
125
                                        this.readDefinedGroups(template);
30,011✔
126
                                        break;
30,011✔
127
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
128
                                case 330:
129
                                        template.OwnerHandle = this._reader.ValueAsHandle;
68,061✔
130
                                        break;
68,061✔
131
                                case 1001:
132
                                        isExtendedData = true;
9,641✔
133
                                        this.readExtendedData(template.EDataTemplateByAppName);
9,641✔
134
                                        break;
9,641✔
135
                                default:
136
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
460,167✔
137
                                        break;
460,167✔
138
                        }
139
                }
774,280✔
140

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

216
                                        this._reader.ReadNext();
396✔
217

218
                                        do
219
                                        {
25,448✔
220
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
25,448✔
221
                                                {
2,308✔
222
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
2,308✔
223
                                                        if (isExtendedData)
2,308✔
224
                                                                continue;
6✔
225
                                                }
2,302✔
226

227
                                                this._reader.ReadNext();
25,442✔
228
                                        }
25,442✔
229
                                        while (this._reader.DxfCode != DxfCode.Start);
25,448✔
230

231
                                        return unknownEntityTemplate;
396✔
232
                        }
233
                }
78,081✔
234

235
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
236
                        where T : Entity
237
                {
77,727✔
238
                        this._reader.ReadNext();
77,727✔
239

240
                        DxfMap map = DxfMap.Create<T>();
77,727✔
241

242
                        while (this._reader.DxfCode != DxfCode.Start)
1,003,975✔
243
                        {
926,248✔
244
                                if (!readEntity(template, map))
926,248✔
245
                                {
420,630✔
246
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
420,630✔
247
                                        if (isExtendedData)
420,630✔
248
                                                continue;
3,231✔
249
                                }
417,399✔
250

251
                                if (this._reader.DxfCode != DxfCode.Start)
923,017✔
252
                                        this._reader.ReadNext();
922,975✔
253
                        }
923,017✔
254

255
                        return template;
77,727✔
256
                }
77,727✔
257

258
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
259
                {
444,625✔
260
                        isExtendedData = false;
444,625✔
261
                        switch (this._reader.Code)
444,625✔
262
                        {
263
                                case 6:
264
                                        template.LineTypeName = this._reader.ValueAsString;
11,379✔
265
                                        break;
11,379✔
266
                                case 8:
267
                                        template.LayerName = this._reader.ValueAsString;
83,503✔
268
                                        break;
83,503✔
269
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
270
                                case 67:
271
                                        break;
828✔
272
                                //Number of bytes Proxy entity graphics data
273
                                case 92:
274
                                case 160:
275
                                //Proxy entity graphics data
276
                                case 310:
277
                                        break;
24,950✔
278
                                case 347:
279
                                        template.MaterialHandle = this._reader.ValueAsHandle;
88✔
280
                                        break;
88✔
281
                                case 430:
282
                                        template.BookColorName = this._reader.ValueAsString;
8✔
283
                                        break;
8✔
284
                                default:
285
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
323,869✔
286
                                        {
288,552✔
287
                                                this.readCommonCodes(template, out isExtendedData, map);
288,552✔
288
                                        }
288,552✔
289
                                        break;
323,869✔
290
                        }
291
                }
444,625✔
292

293
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
294
                {
5,680✔
295
                        switch (this._reader.Code)
5,680✔
296
                        {
297
                                default:
298
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
5,680✔
299
                                        {
4,812✔
300
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
4,812✔
301
                                        }
302
                                        return true;
868✔
303
                        }
304
                }
5,680✔
305

306
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
307
                {
21,222✔
308
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
21,222✔
309
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
21,222✔
310

311
                        switch (this._reader.Code)
21,222!
312
                        {
313
                                case 44:
314
                                case 46:
315
                                        return true;
×
316
                                case 101:
317
                                        var att = tmp.CadObject as AttributeBase;
42✔
318
                                        att.MText = new MText();
42✔
319
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
42✔
320
                                        tmp.MTextTemplate = mtextTemplate;
42✔
321
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
42✔
322
                                        return true;
42✔
323
                                default:
324
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
21,180✔
325
                                        {
16,034✔
326
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
16,034✔
327
                                        }
328
                                        return true;
5,146✔
329
                        }
330
                }
21,222✔
331

332
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
333
                {
47,195✔
334
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
47,195!
335
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
47,195✔
336
                        TableEntity table = tmp.CadObject as TableEntity;
47,195✔
337

338
                        switch (this._reader.Code)
47,195✔
339
                        {
340
                                case 2:
341
                                        tmp.BlockName = this._reader.ValueAsString;
133✔
342
                                        return true;
133✔
343
                                case 342:
344
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
133✔
345
                                        return true;
133✔
346
                                case 343:
347
                                        tmp.BlockOwnerHandle = this._reader.ValueAsHandle;
133✔
348
                                        return true;
133✔
349
                                case 141:
350
                                        var row = new TableEntity.Row();
928✔
351
                                        row.Height = this._reader.ValueAsDouble;
928✔
352
                                        table.Rows.Add(row);
928✔
353
                                        return true;
928✔
354
                                case 142:
355
                                        var col = new TableEntity.Column();
401✔
356
                                        col.Width = this._reader.ValueAsDouble;
401✔
357
                                        table.Columns.Add(col);
401✔
358
                                        return true;
401✔
359
                                case 144:
360
                                        tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
2✔
361
                                        return true;
2✔
362
                                case 145:
363
                                        tmp.CurrentCell.Rotation = this._reader.ValueAsDouble;
2,792✔
364
                                        return true;
2,792✔
365
                                case 170:
366
                                        //Has data flag
367
                                        return true;
134✔
368
                                case 171:
369
                                        tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
2,792✔
370
                                        return true;
2,792✔
371
                                case 172:
372
                                        tmp.CurrentCell.FlagValue = this._reader.ValueAsInt;
2,792✔
373
                                        return true;
2,792✔
374
                                case 173:
375
                                        tmp.CurrentCell.MergedValue = this._reader.ValueAsInt;
2,792✔
376
                                        return true;
2,792✔
377
                                case 174:
378
                                        tmp.CurrentCell.Autofit = this._reader.ValueAsBool;
2,792✔
379
                                        return true;
2,792✔
380
                                case 175:
381
                                        tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
2,792✔
382
                                        return true;
2,792✔
383
                                case 176:
384
                                        tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
2,792✔
385
                                        return true;
2,792✔
386
                                case 178:
387
                                        tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
2,792✔
388
                                        return true;
2,792✔
389
                                case 179:
390
                                        //Unknown value
391
                                        return true;
2✔
392
                                case 301:
393
                                        var content = new TableEntity.CellContent();
1,868✔
394
                                        tmp.CurrentCell.Contents.Add(content);
1,868✔
395
                                        this.readCellValue(content);
1,868✔
396
                                        return true;
1,868✔
397
                                case 340:
398
                                        tmp.CurrentCellTemplate.BlockRecordHandle = this._reader.ValueAsHandle;
2✔
399
                                        return true;
2✔
400
                                default:
401
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
21,123✔
402
                                        {
20,592✔
403
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
20,592✔
404
                                        }
405
                                        return true;
531✔
406
                        }
407
                }
47,195✔
408

409
                private void readCellValue(TableEntity.CellContent content)
410
                {
1,868✔
411
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
1,868!
412
                        {
1,868✔
413
                                this._reader.ReadNext();
1,868✔
414
                        }
1,868✔
415
                        else
416
                        {
×
417
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
418
                        }
419

420
                        while (this._reader.Code != 304
11,926✔
421
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
11,926✔
422
                        {
10,058✔
423
                                switch (this._reader.Code)
10,058!
424
                                {
425
                                        case 1:
426
                                                content.Value.Text = this._reader.ValueAsString;
708✔
427
                                                break;
708✔
428
                                        case 2:
429
                                                content.Value.Text += this._reader.ValueAsString;
×
430
                                                break;
×
431
                                        case 11:
432
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
1✔
433
                                                break;
1✔
434
                                        case 21:
435
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
1✔
436
                                                break;
1✔
437
                                        case 31:
438
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
1✔
439
                                                break;
1✔
440
                                        case 302:
441
                                                //TODO: Fix this assignation to cell value
442
                                                content.Value.Value = this._reader.ValueAsString;
1,868✔
443
                                                break;
1,868✔
444
                                        case 90:
445
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
1,868✔
446
                                                break;
1,868✔
447
                                        case 91:
448
                                                content.Value.Value = this._reader.ValueAsInt;
1✔
449
                                                break;
1✔
450
                                        case 93:
451
                                                content.Value.Flags = this._reader.ValueAsInt;
1,868✔
452
                                                break;
1,868✔
453
                                        case 94:
454
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
1,868✔
455
                                                break;
1,868✔
456
                                        case 140:
457
                                                content.Value.Value = this._reader.ValueAsDouble;
4✔
458
                                                break;
4✔
459
                                        case 300:
460
                                                content.Value.Format = this._reader.ValueAsString;
1,868✔
461
                                                break;
1,868✔
462
                                        default:
463
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
2✔
464
                                                break;
2✔
465
                                }
466

467
                                this._reader.ReadNext();
10,058✔
468
                        }
10,058✔
469
                }
1,868✔
470

471
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
472
                {
104,550✔
473
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
104,550✔
474
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
104,550✔
475

476
                        switch (this._reader.Code)
104,550✔
477
                        {
478
                                //TODO: Implement multiline text def codes
479
                                case 1 or 3 when tmp.CadObject is MText mtext:
10,058✔
480
                                        mtext.Value += this._reader.ValueAsString;
4,350✔
481
                                        return true;
4,350✔
482
                                case 70:
483
                                case 74:
484
                                case 101:
485
                                        return true;
264✔
486
                                case 7:
487
                                        tmp.StyleName = this._reader.ValueAsString;
616✔
488
                                        return true;
616✔
489
                                default:
490
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
99,320✔
491
                        }
492
                }
104,550✔
493

494
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
495
                {
3,960✔
496
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
3,960✔
497

498
                        switch (this._reader.Code)
3,960✔
499
                        {
500
                                case 3:
501
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
396✔
502
                                        return true;
396✔
503
                                default:
504
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
3,564✔
505
                        }
506
                }
3,960✔
507

508
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
509
                {
31,834✔
510
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
31,834✔
511

512
                        switch (this._reader.Code)
31,834✔
513
                        {
514
                                case 2:
515
                                        tmp.BlockName = this._reader.ValueAsString;
1,232✔
516
                                        return true;
1,232✔
517
                                case 3:
518
                                        tmp.StyleName = this._reader.ValueAsString;
1,056✔
519
                                        return true;
1,056✔
520
                                case 50:
521
                                        var dim = new DimensionLinear();
154✔
522
                                        tmp.SetDimensionObject(dim);
154✔
523
                                        dim.Rotation = CSMath.MathHelper.DegToRad(this._reader.ValueAsDouble);
154✔
524
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
154✔
525
                                        return true;
154✔
526
                                case 70:
527
                                        //Flags do not have set
528
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
1,232✔
529
                                        return true;
1,232✔
530
                                //Measurement - read only
531
                                case 42:
532
                                        return true;
1,056✔
533
                                //Undocumented codes
534
                                case 73:
535
                                case 74:
536
                                case 75:
537
                                case 90:
538
                                case 361:
539
                                        return true;
2,112✔
540
                                case 100:
541
                                        switch (this._reader.ValueAsString)
3,300✔
542
                                        {
543
                                                case DxfSubclassMarker.Dimension:
544
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
1,056✔
545
                                                case DxfSubclassMarker.AlignedDimension:
546
                                                        tmp.SetDimensionObject(new DimensionAligned());
264✔
547
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
264✔
548
                                                        return true;
264✔
549
                                                case DxfSubclassMarker.DiametricDimension:
550
                                                        tmp.SetDimensionObject(new DimensionDiameter());
132✔
551
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
132✔
552
                                                        return true;
132✔
553
                                                case DxfSubclassMarker.Angular2LineDimension:
554
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
132✔
555
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
132✔
556
                                                        return true;
132✔
557
                                                case DxfSubclassMarker.Angular3PointDimension:
558
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
132✔
559
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
132✔
560
                                                        return true;
132✔
561
                                                case DxfSubclassMarker.RadialDimension:
562
                                                        tmp.SetDimensionObject(new DimensionRadius());
132✔
563
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
132✔
564
                                                        return true;
132✔
565
                                                case DxfSubclassMarker.OrdinateDimension:
566
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
264✔
567
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
264✔
568
                                                        return true;
264✔
569
                                                case DxfSubclassMarker.LinearDimension:
570
                                                        return true;
132✔
571
                                                default:
572
                                                        return false;
1,056✔
573
                                        }
574
                                default:
575
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
21,692✔
576
                        }
577
                }
31,834✔
578

579
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
580
                {
14,716✔
581
                        CadHatchTemplate tmp = template as CadHatchTemplate;
14,716✔
582
                        Hatch hatch = tmp.CadObject;
14,716✔
583

584
                        bool isFirstSeed = true;
14,716✔
585
                        XY seedPoint = new XY();
14,716✔
586

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

679
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
680
                {
13,973✔
681
                        CadInsertTemplate tmp = template as CadInsertTemplate;
13,973✔
682

683
                        switch (this._reader.Code)
13,973✔
684
                        {
685
                                case 2:
686
                                        tmp.BlockName = this._reader.ValueAsString;
1,382✔
687
                                        return true;
1,382✔
688
                                case 66:
689
                                        return true;
308✔
690
                                default:
691
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
12,283✔
692
                        }
693
                }
13,973✔
694

695
                private CadEntityTemplate readPolyline()
696
                {
5,852✔
697
                        CadPolyLineTemplate template = null;
5,852✔
698

699
                        if (this._builder.Version == ACadVersion.Unknown)
5,852!
700
                        {
×
701
                                var polyline = new Polyline2D();
×
702
                                template = new CadPolyLineTemplate(polyline);
×
703
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
×
704

705
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
×
706
                                {
×
707
                                        Vertex2D v = new Vertex2D();
×
708
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
×
709
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
×
710

711
                                        if (vertexTemplate.Vertex.Handle == 0)
×
712
                                        {
×
713
                                                template.PolyLine.Vertices.Add(vertexTemplate.Vertex);
×
714
                                        }
×
715
                                        else
716
                                        {
×
717
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
718
                                                this._builder.AddTemplate(vertexTemplate);
×
719
                                        }
×
720
                                }
×
721

722
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
×
723
                                {
×
724
                                        var seqend = new Seqend();
×
725
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
×
726
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
×
727

728
                                        this._builder.AddTemplate(seqendTemplate);
×
729

730
                                        template.SeqendHandle = seqend.Handle;
×
731
                                }
×
732
                        }
×
733
                        else
734
                        {
5,852✔
735
                                template = new CadPolyLineTemplate();
5,852✔
736
                                this.readEntityCodes<Entity>(template, this.readPolyline);
5,852✔
737
                        }
5,852✔
738

739
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
5,852✔
740
                        {
5,588✔
741
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
5,588✔
742
                                return null;
5,588✔
743
                        }
744

745
                        return template;
264✔
746
                }
5,852✔
747

748
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
749
                {
42,126✔
750
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
42,126✔
751

752
                        switch (this._reader.Code)
42,126✔
753
                        {
754
                                //DXF: always 0
755
                                //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)
756
                                case 10:
757
                                case 20:
758
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
759
                                case 66:
760
                                //Polygon mesh M vertex count (optional; default = 0)
761
                                case 71:
762
                                //Polygon mesh N vertex count(optional; default = 0)
763
                                case 72:
764
                                //Smooth surface M density(optional; default = 0)
765
                                case 73:
766
                                //Smooth surface N density (optional; default = 0)
767
                                case 74:
768
                                        return true;
17,864✔
769
                                case 100:
770
                                        switch (this._reader.ValueAsString)
528!
771
                                        {
772
                                                case DxfSubclassMarker.Polyline:
773
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
774
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
775
                                                        return true;
×
776
                                                case DxfSubclassMarker.Polyline3d:
777
                                                        tmp.SetPolyLineObject(new Polyline3D());
132✔
778
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
132✔
779
                                                        return true;
132✔
780
                                                case DxfSubclassMarker.PolyfaceMesh:
781
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
132✔
782
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
132✔
783
                                                        return true;
132✔
784
                                                default:
785
                                                        return false;
264✔
786
                                        }
787
                                default:
788
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
23,734✔
789
                        }
790
                }
42,126✔
791

792
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
793
                {
3,300✔
794
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
3,300✔
795

796
                        switch (this._reader.Code)
3,300✔
797
                        {
798
                                case 3:
799
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
132✔
800
                                        return true;
132✔
801
                                case 10:
802
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
528✔
803
                                        return true;
528✔
804
                                case 20:
805
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
528✔
806
                                        y.Y = this._reader.ValueAsDouble;
528✔
807
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
528✔
808
                                        return true;
528✔
809
                                case 30:
810
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
528✔
811
                                        z.Z = this._reader.ValueAsDouble;
528✔
812
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
528✔
813
                                        return true;
528✔
814
                                case 340:
815
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
132✔
816
                                        return true;
132✔
817
                                //Vertices count
818
                                case 76:
819
                                        return true;
132✔
820
                                default:
821
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,320✔
822
                        }
823
                }
3,300✔
824

825
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
826
                {
30,719✔
827
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
30,719✔
828

829
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
30,719✔
830

831
                        switch (this._reader.Code)
30,719!
832
                        {
833
                                case 10:
834
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
7,100✔
835
                                        return true;
7,100✔
836
                                case 20:
837
                                        if (last is not null)
7,100✔
838
                                        {
7,100✔
839
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
7,100✔
840
                                        }
7,100✔
841
                                        return true;
7,100✔
842
                                case 40:
843
                                        if (last is not null)
1,320✔
844
                                        {
1,320✔
845
                                                last.StartWidth = this._reader.ValueAsDouble;
1,320✔
846
                                        }
1,320✔
847
                                        return true;
1,320✔
848
                                case 41:
849
                                        if (last is not null)
1,320✔
850
                                        {
1,320✔
851
                                                last.EndWidth = this._reader.ValueAsDouble;
1,320✔
852
                                        }
1,320✔
853
                                        return true;
1,320✔
854
                                case 42:
855
                                        if (last is not null)
1,776✔
856
                                        {
1,776✔
857
                                                last.Bulge = this._reader.ValueAsDouble;
1,776✔
858
                                        }
1,776✔
859
                                        return true;
1,776✔
860
                                case 50:
861
                                        if (last is not null)
×
862
                                        {
×
863
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
864
                                        }
×
865
                                        return true;
×
866
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
867
                                case 66:
868
                                //Vertex count
869
                                case 90:
870
                                        return true;
1,448✔
871
                                case 91:
872
                                        if (last is not null)
×
873
                                        {
×
874
                                                last.Id = this._reader.ValueAsInt;
×
875
                                        }
×
876
                                        return true;
×
877
                                default:
878
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
10,655✔
879
                        }
880
                }
30,719✔
881

882
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
883
                {
23,232✔
884
                        CadMeshTemplate tmp = template as CadMeshTemplate;
23,232✔
885

886
                        switch (this._reader.Code)
23,232✔
887
                        {
888
                                case 100:
889
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
528✔
890
                                        {
264✔
891
                                                tmp.SubclassMarker = true;
264✔
892
                                        }
264✔
893
                                        return true;
528✔
894
                                //Count of sub-entity which property has been overridden
895
                                case 90:
896
                                        //TODO: process further entities
897
                                        return true;
264✔
898
                                case 92:
899
                                        if (!tmp.SubclassMarker)
396✔
900
                                        {
132✔
901
                                                return false;
132✔
902
                                        }
903

904
                                        int nvertices = this._reader.ValueAsInt;
264✔
905
                                        for (int i = 0; i < nvertices; i++)
33,792✔
906
                                        {
16,632✔
907
                                                this._reader.ReadNext();
16,632✔
908
                                                double x = this._reader.ValueAsDouble;
16,632✔
909
                                                this._reader.ReadNext();
16,632✔
910
                                                double y = this._reader.ValueAsDouble;
16,632✔
911
                                                this._reader.ReadNext();
16,632✔
912
                                                double z = this._reader.ValueAsDouble;
16,632✔
913
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
16,632✔
914
                                        }
16,632✔
915
                                        return true;
264✔
916
                                case 93:
917
                                        int size = this._reader.ValueAsInt;
264✔
918
                                        this._reader.ReadNext();
264✔
919

920
                                        int indexes = 0;
264✔
921
                                        for (int i = 0; i < size; i += indexes + 1)
36,432✔
922
                                        {
17,952✔
923
                                                indexes = this._reader.ValueAsInt;
17,952✔
924
                                                this._reader.ReadNext();
17,952✔
925

926
                                                int[] face = new int[indexes];
17,952✔
927
                                                for (int j = 0; j < indexes; j++)
173,184✔
928
                                                {
68,640✔
929
                                                        face[j] = this._reader.ValueAsInt;
68,640✔
930

931
                                                        if ((i + j + 2) < size)
68,640✔
932
                                                        {
68,376✔
933
                                                                this._reader.ReadNext();
68,376✔
934
                                                        }
68,376✔
935
                                                }
68,640✔
936

937
                                                tmp.CadObject.Faces.Add(face);
17,952✔
938
                                        }
17,952✔
939

940
                                        Debug.Assert(this._reader.Code == 90);
264✔
941

942
                                        return true;
264✔
943
                                case 94:
944
                                        int numEdges = this._reader.ValueAsInt;
264✔
945
                                        this._reader.ReadNext();
264✔
946
                                        for (int i = 0; i < numEdges; i++)
69,168✔
947
                                        {
34,320✔
948
                                                Mesh.Edge edge = new Mesh.Edge();
34,320✔
949

950
                                                edge.Start = this._reader.ValueAsInt;
34,320✔
951
                                                this._reader.ReadNext();
34,320✔
952
                                                edge.End = this._reader.ValueAsInt;
34,320✔
953

954
                                                if (i < numEdges - 1)
34,320✔
955
                                                {
34,056✔
956
                                                        this._reader.ReadNext();
34,056✔
957
                                                }
34,056✔
958

959
                                                tmp.CadObject.Edges.Add(edge);
34,320✔
960
                                        }
34,320✔
961

962
                                        Debug.Assert(this._reader.Code == 90);
264✔
963

964
                                        return true;
264✔
965
                                case 95:
966
                                        this._reader.ReadNext();
264✔
967
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
69,168✔
968
                                        {
34,320✔
969
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
34,320✔
970
                                                edge.Crease = this._reader.ValueAsDouble;
34,320✔
971

972
                                                tmp.CadObject.Edges[i] = edge;
34,320✔
973

974
                                                if (i < tmp.CadObject.Edges.Count - 1)
34,320✔
975
                                                {
34,056✔
976
                                                        this._reader.ReadNext();
34,056✔
977
                                                }
34,056✔
978
                                        }
34,320✔
979

980
                                        Debug.Assert(this._reader.Code == 140);
264✔
981

982
                                        return true;
264✔
983
                                default:
984
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
21,252✔
985
                        }
986
                }
23,232✔
987

988
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
989
                {
34,320✔
990
                        CadMLineTemplate tmp = template as CadMLineTemplate;
34,320✔
991

992
                        switch (this._reader.Code)
34,320✔
993
                        {
994
                                // 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.
995
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
996
                                case 2:
997
                                        tmp.MLineStyleName = this._reader.ValueAsString;
396✔
998
                                        return true;
396✔
999
                                case 72:
1000
                                        tmp.NVertex = this._reader.ValueAsInt;
396✔
1001
                                        return true;
396✔
1002
                                case 73:
1003
                                        tmp.NElements = this._reader.ValueAsInt;
396✔
1004
                                        return true;
396✔
1005
                                case 340:
1006
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
396✔
1007
                                        return true;
396✔
1008
                                default:
1009
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
32,736✔
1010
                                        {
5,544✔
1011
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
5,544✔
1012
                                        }
1013
                                        return true;
27,192✔
1014
                        }
1015
                }
34,320✔
1016

1017
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
1018
                {
1,320✔
1019
                        CadShapeTemplate tmp = template as CadShapeTemplate;
1,320✔
1020

1021
                        switch (this._reader.Code)
1,320✔
1022
                        {
1023
                                case 2:
1024
                                        tmp.ShapeFileName = this._reader.ValueAsString;
132✔
1025
                                        return true;
132✔
1026
                                default:
1027
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
1,188✔
1028
                        }
1029
                }
1,320✔
1030

1031
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
1032
                {
9,240✔
1033
                        CadSplineTemplate tmp = template as CadSplineTemplate;
9,240✔
1034

1035
                        XYZ controlPoint;
1036

1037
                        switch (this._reader.Code)
9,240!
1038
                        {
1039
                                case 10:
1040
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
1,056✔
1041
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
1,056✔
1042
                                        return true;
1,056✔
1043
                                case 20:
1044
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,056✔
1045
                                        controlPoint.Y = this._reader.ValueAsDouble;
1,056✔
1046
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,056✔
1047
                                        return true;
1,056✔
1048
                                case 30:
1049
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
1,056✔
1050
                                        controlPoint.Z = this._reader.ValueAsDouble;
1,056✔
1051
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
1,056✔
1052
                                        return true;
1,056✔
1053
                                case 40:
1054
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
2,112✔
1055
                                        return true;
2,112✔
1056
                                case 41:
1057
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1058
                                        return true;
×
1059
                                case 72:
1060
                                case 73:
1061
                                case 74:
1062
                                        return true;
792✔
1063
                                default:
1064
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
3,168✔
1065
                        }
1066
                }
9,240✔
1067

1068
                private bool readUnderlayEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
1069
                {
×
1070
                        CadPdfUnderlayTemplate tmp = template as CadPdfUnderlayTemplate;
×
1071

1072
                        switch (this._reader.Code)
×
1073
                        {
1074
                                case 340:
1075
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
×
1076
                                        return true;
×
1077
                                default:
1078
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1079
                        }
1080
                }
×
1081

1082
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
1083
                {
138,544✔
1084
                        CadVertexTemplate tmp = template as CadVertexTemplate;
138,544✔
1085

1086
                        switch (this._reader.Code)
138,544✔
1087
                        {
1088
                                //Polyface mesh vertex index
1089
                                case 71:
1090
                                case 72:
1091
                                case 73:
1092
                                case 74:
1093
                                        return true;
1,078✔
1094
                                case 100:
1095
                                        switch (this._reader.ValueAsString)
4,488!
1096
                                        {
1097
                                                case DxfSubclassMarker.Vertex:
1098
                                                        return true;
1,320✔
1099
                                                case DxfSubclassMarker.PolylineVertex:
1100
                                                        tmp.SetVertexObject(new Vertex2D());
×
1101
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1102
                                                        return true;
×
1103
                                                case DxfSubclassMarker.Polyline3dVertex:
1104
                                                        tmp.SetVertexObject(new Vertex3D());
660✔
1105
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
660✔
1106
                                                        return true;
660✔
1107
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
1108
                                                        tmp.SetVertexObject(new VertexFaceMesh());
660✔
1109
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
660✔
1110
                                                        return true;
660✔
1111
                                                case DxfSubclassMarker.PolyfaceMeshFace:
1112
                                                        tmp.SetVertexObject(new VertexFaceRecord());
264✔
1113
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
264✔
1114
                                                        return true;
264✔
1115
                                                default:
1116
                                                        return false;
1,584✔
1117
                                        }
1118
                                default:
1119
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
132,978✔
1120
                        }
1121
                }
138,544✔
1122

1123
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
1124
                {
43,016✔
1125
                        CadViewportTemplate tmp = template as CadViewportTemplate;
43,016✔
1126

1127
                        switch (this._reader.Code)
43,016!
1128
                        {
1129
                                //Undocumented
1130
                                case 67:
1131
                                case 68:
1132
                                        return true;
1,576✔
1133
                                case 69:
1134
                                        tmp.ViewportId = this._reader.ValueAsShort;
788✔
1135
                                        return true;
788✔
1136
                                case 331:
1137
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1138
                                        return true;
×
1139
                                case 348:
1140
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
496✔
1141
                                        return true;
496✔
1142
                                default:
1143
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
40,156✔
1144
                        }
1145
                }
43,016✔
1146

1147
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
1148
                {
398,739✔
1149
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
398,739✔
1150

1151
                        switch (this._reader.Code)
398,739✔
1152
                        {
1153
                                default:
1154
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
398,739✔
1155
                        }
1156
                }
398,739✔
1157

1158
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
1159
                {
14,002✔
1160
                        List<ExtendedDataRecord> records = new();
14,002✔
1161
                        edata.Add(this._reader.ValueAsString, records);
14,002✔
1162

1163
                        this._reader.ReadNext();
14,002✔
1164

1165
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
65,688✔
1166
                        {
55,918✔
1167
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
55,918✔
1168
                                {
4,232✔
1169
                                        this.readExtendedData(edata);
4,232✔
1170
                                        break;
4,232✔
1171
                                }
1172

1173
                                ExtendedDataRecord record;
1174
                                double x = 0;
51,686✔
1175
                                double y = 0;
51,686✔
1176
                                double z = 0;
51,686✔
1177

1178
                                switch (this._reader.DxfCode)
51,686!
1179
                                {
1180
                                        case DxfCode.ExtendedDataAsciiString:
1181
                                        case DxfCode.ExtendedDataRegAppName:
1182
                                                record = new ExtendedDataString(this._reader.ValueAsString);
13,096✔
1183
                                                break;
13,096✔
1184
                                        case DxfCode.ExtendedDataControlString:
1185
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
3,730✔
1186
                                                break;
3,730✔
1187
                                        case DxfCode.ExtendedDataLayerName:
1188
                                                record = new ExtendedDataLayer(this._reader.ValueAsHandle);
×
1189
                                                break;
×
1190
                                        case DxfCode.ExtendedDataBinaryChunk:
1191
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
2✔
1192
                                                break;
2✔
1193
                                        case DxfCode.ExtendedDataHandle:
1194
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
465✔
1195
                                                break;
465✔
1196
                                        case DxfCode.ExtendedDataXCoordinate:
1197
                                                x = this._reader.ValueAsDouble;
725✔
1198
                                                this._reader.ReadNext();
725✔
1199
                                                y = this._reader.ValueAsDouble;
725✔
1200
                                                this._reader.ReadNext();
725✔
1201
                                                z = this._reader.ValueAsDouble;
725✔
1202

1203
                                                record = new ExtendedDataCoordinate(
725✔
1204
                                                        new XYZ(
725✔
1205
                                                                x,
725✔
1206
                                                                y,
725✔
1207
                                                                z)
725✔
1208
                                                        );
725✔
1209
                                                break;
725✔
1210
                                        case DxfCode.ExtendedDataWorldXCoordinate:
1211
                                                x = this._reader.ValueAsDouble;
308✔
1212
                                                this._reader.ReadNext();
308✔
1213
                                                y = this._reader.ValueAsDouble;
308✔
1214
                                                this._reader.ReadNext();
308✔
1215
                                                z = this._reader.ValueAsDouble;
308✔
1216

1217
                                                record = new ExtendedDataCoordinate(
308✔
1218
                                                        new XYZ(
308✔
1219
                                                                x,
308✔
1220
                                                                y,
308✔
1221
                                                                z)
308✔
1222
                                                        );
308✔
1223
                                                break;
308✔
1224
                                        case DxfCode.ExtendedDataWorldXDisp:
1225
                                                x = this._reader.ValueAsDouble;
×
1226
                                                this._reader.ReadNext();
×
1227
                                                y = this._reader.ValueAsDouble;
×
1228
                                                this._reader.ReadNext();
×
1229
                                                z = this._reader.ValueAsDouble;
×
1230

1231
                                                record = new ExtendedDataCoordinate(
×
1232
                                                        new XYZ(
×
1233
                                                                x,
×
1234
                                                                y,
×
1235
                                                                z)
×
1236
                                                        );
×
1237
                                                break;
×
1238
                                        case DxfCode.ExtendedDataWorldXDir:
1239
                                                x = this._reader.ValueAsDouble;
×
1240
                                                this._reader.ReadNext();
×
1241
                                                y = this._reader.ValueAsDouble;
×
1242
                                                this._reader.ReadNext();
×
1243
                                                z = this._reader.ValueAsDouble;
×
1244

1245
                                                record = new ExtendedDataCoordinate(
×
1246
                                                        new XYZ(
×
1247
                                                                x,
×
1248
                                                                y,
×
1249
                                                                z)
×
1250
                                                        );
×
1251
                                                break;
×
1252
                                        case DxfCode.ExtendedDataReal:
1253
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
7,661✔
1254
                                                break;
7,661✔
1255
                                        case DxfCode.ExtendedDataDist:
1256
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
×
1257
                                                break;
×
1258
                                        case DxfCode.ExtendedDataScale:
1259
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
×
1260
                                                break;
×
1261
                                        case DxfCode.ExtendedDataInteger16:
1262
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
21,852✔
1263
                                                break;
21,852✔
1264
                                        case DxfCode.ExtendedDataInteger32:
1265
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
3,231✔
1266
                                                break;
3,231✔
1267
                                        default:
1268
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
616✔
1269
                                                break;
616✔
1270
                                }
1271

1272
                                this._reader.ReadNext();
51,686✔
1273
                        }
51,686✔
1274
                }
14,002✔
1275

1276
                private void readPattern(HatchPattern pattern, int nlines)
1277
                {
284✔
1278
                        //Jump 78 code
1279
                        this._reader.ReadNext();
284✔
1280

1281
                        for (int i = 0; i < nlines; i++)
8,868✔
1282
                        {
4,150✔
1283
                                HatchPattern.Line line = new HatchPattern.Line();
4,150✔
1284
                                XY basePoint = new XY();
4,150✔
1285
                                XY offset = new XY();
4,150✔
1286

1287
                                bool end = false;
4,150✔
1288
                                HashSet<int> codes = new();
4,150✔
1289

1290
                                while (!end)
29,334✔
1291
                                {
29,050✔
1292
                                        if (codes.Contains(this._reader.Code))
29,050✔
1293
                                        {
3,866✔
1294
                                                break;
3,866✔
1295
                                        }
1296
                                        else
1297
                                        {
25,184✔
1298
                                                codes.Add(this._reader.Code);
25,184✔
1299
                                        }
25,184✔
1300

1301
                                        switch (this._reader.Code)
25,184!
1302
                                        {
1303
                                                case 53:
1304
                                                        line.Angle = this._reader.ValueAsAngle;
4,150✔
1305
                                                        break;
4,150✔
1306
                                                case 43:
1307
                                                        basePoint.X = this._reader.ValueAsDouble;
4,150✔
1308
                                                        break;
4,150✔
1309
                                                case 44:
1310
                                                        basePoint.Y = this._reader.ValueAsDouble;
4,150✔
1311
                                                        line.BasePoint = basePoint;
4,150✔
1312
                                                        break;
4,150✔
1313
                                                case 45:
1314
                                                        offset.X = this._reader.ValueAsDouble;
4,150✔
1315
                                                        line.Offset = offset;
4,150✔
1316
                                                        break;
4,150✔
1317
                                                case 46:
1318
                                                        offset.Y = this._reader.ValueAsDouble;
4,150✔
1319
                                                        line.Offset = offset;
4,150✔
1320
                                                        break;
4,150✔
1321
                                                //Number of dash length items
1322
                                                case 79:
1323
                                                        int ndash = this._reader.ValueAsInt;
4,150✔
1324
                                                        for (int j = 0; j < ndash; j++)
24,372✔
1325
                                                        {
8,036✔
1326
                                                                this._reader.ReadNext();
8,036✔
1327
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
8,036✔
1328
                                                        }
8,036✔
1329
                                                        break;
4,150✔
1330
                                                case 49:
NEW
1331
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
NEW
1332
                                                        break;
×
1333
                                                default:
1334
                                                        end = true;
284✔
1335
                                                        break;
284✔
1336
                                        }
1337
                                        this._reader.ReadNext();
25,184✔
1338
                                }
25,184✔
1339

1340
                                pattern.Lines.Add(line);
4,150✔
1341
                        }
4,150✔
1342
                }
284✔
1343

1344
                private void readLoops(CadHatchTemplate template, int count)
1345
                {
548✔
1346
                        if (this._reader.Code == 91)
548✔
1347
                                this._reader.ReadNext();
548✔
1348

1349
                        for (int i = 0; i < count; i++)
2,192✔
1350
                        {
548✔
1351
                                if (this._reader.Code != 92)
548!
1352
                                {
×
1353
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1354
                                        break;
×
1355
                                }
1356

1357
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
548✔
1358
                                if (path != null)
548✔
1359
                                        template.PathTempaltes.Add(path);
548✔
1360
                        }
548✔
1361
                }
548✔
1362

1363
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
1364
                {
548✔
1365
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
548✔
1366
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
548✔
1367
                        template.Path.Flags = flags;
548✔
1368

1369
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
548✔
1370
                        {
15✔
1371
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
15✔
1372
                                template.Path.Edges.Add(pl);
15✔
1373
                        }
15✔
1374
                        else
1375
                        {
533✔
1376
                                this._reader.ReadNext();
533✔
1377

1378
                                if (this._reader.Code != 93)
533!
1379
                                {
×
1380
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1381
                                        return null;
×
1382
                                }
1383

1384
                                int edges = this._reader.ValueAsInt;
533✔
1385
                                this._reader.ReadNext();
533✔
1386

1387
                                for (int i = 0; i < edges; i++)
5,330✔
1388
                                {
2,132✔
1389
                                        var edge = this.readEdge();
2,132✔
1390
                                        if (edge != null)
2,132✔
1391
                                                template.Path.Edges.Add(edge);
2,132✔
1392
                                }
2,132✔
1393
                        }
533✔
1394

1395
                        bool end = false;
548✔
1396
                        while (!end)
2,187✔
1397
                        {
1,639✔
1398
                                switch (this._reader.Code)
1,639✔
1399
                                {
1400
                                        //Number of source boundary objects
1401
                                        case 97:
1402
                                                break;
548✔
1403
                                        case 330:
1404
                                                template.Handles.Add(this._reader.ValueAsHandle);
543✔
1405
                                                break;
543✔
1406
                                        default:
1407
                                                end = true;
548✔
1408
                                                continue;
548✔
1409
                                }
1410

1411
                                this._reader.ReadNext();
1,091✔
1412
                        }
1,091✔
1413

1414
                        return template;
548✔
1415
                }
548✔
1416

1417
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
1418
                {
15✔
1419
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
15✔
1420

1421
                        this._reader.ReadNext();
15✔
1422

1423
                        if (this._reader.Code != 72)
15!
1424
                        {
×
1425
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1426
                                return null;
×
1427
                        }
1428

1429
                        //72
1430
                        bool hasBulge = this._reader.ValueAsBool;
15✔
1431
                        this._reader.ReadNext();
15✔
1432

1433
                        //73
1434
                        bool isClosed = this._reader.ValueAsBool;
15✔
1435
                        this._reader.ReadNext();
15✔
1436

1437
                        //93
1438
                        int nvertices = this._reader.ValueAsInt;
15✔
1439
                        this._reader.ReadNext();
15✔
1440

1441
                        for (int i = 0; i < nvertices; i++)
150✔
1442
                        {
60✔
1443
                                double bulge = 0.0;
60✔
1444

1445
                                //10
1446
                                double x = this._reader.ValueAsDouble;
60✔
1447
                                this._reader.ReadNext();
60✔
1448
                                //20
1449
                                double y = this._reader.ValueAsDouble;
60✔
1450
                                this._reader.ReadNext();
60✔
1451

1452
                                if (hasBulge)
60!
1453
                                {
×
1454
                                        //42
1455
                                        bulge = this._reader.ValueAsDouble;
×
1456
                                        this._reader.ReadNext();
×
1457
                                }
×
1458

1459
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
60✔
1460
                        }
60✔
1461

1462
                        return boundary;
15✔
1463
                }
15✔
1464

1465
                private Hatch.BoundaryPath.Edge readEdge()
1466
                {
2,132✔
1467
                        if (this._reader.Code != 72)
2,132!
1468
                        {
×
1469
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1470
                                return null;
×
1471
                        }
1472

1473
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
2,132✔
1474
                        this._reader.ReadNext();
2,132✔
1475

1476
                        switch (type)
2,132!
1477
                        {
1478
                                case Hatch.BoundaryPath.EdgeType.Line:
1479
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
2,132✔
1480
                                        while (true)
10,660✔
1481
                                        {
10,660✔
1482
                                                switch (this._reader.Code)
10,660✔
1483
                                                {
1484
                                                        case 10:
1485
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
2,132✔
1486
                                                                break;
2,132✔
1487
                                                        case 20:
1488
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
2,132✔
1489
                                                                break;
2,132✔
1490
                                                        case 11:
1491
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
2,132✔
1492
                                                                break;
2,132✔
1493
                                                        case 21:
1494
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
2,132✔
1495
                                                                break;
2,132✔
1496
                                                        default:
1497
                                                                return line;
2,132✔
1498
                                                }
1499

1500
                                                this._reader.ReadNext();
8,528✔
1501
                                        }
8,528✔
1502
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1503
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1504
                                        while (true)
×
1505
                                        {
×
1506
                                                switch (this._reader.Code)
×
1507
                                                {
1508
                                                        case 10:
1509
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1510
                                                                break;
×
1511
                                                        case 20:
1512
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1513
                                                                break;
×
1514
                                                        case 40:
1515
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1516
                                                                break;
×
1517
                                                        case 50:
1518
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1519
                                                                break;
×
1520
                                                        case 51:
1521
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1522
                                                                break;
×
1523
                                                        case 73:
1524
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1525
                                                                break;
×
1526
                                                        default:
1527
                                                                return arc;
×
1528
                                                }
1529

1530
                                                this._reader.ReadNext();
×
1531
                                        }
×
1532
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1533
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1534
                                        while (true)
×
1535
                                        {
×
1536
                                                switch (this._reader.Code)
×
1537
                                                {
1538
                                                        case 10:
1539
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1540
                                                                break;
×
1541
                                                        case 20:
1542
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1543
                                                                break;
×
1544
                                                        case 11:
1545
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1546
                                                                break;
×
1547
                                                        case 21:
1548
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1549
                                                                break;
×
1550
                                                        case 40:
1551
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1552
                                                                break;
×
1553
                                                        case 50:
1554
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1555
                                                                break;
×
1556
                                                        case 51:
1557
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
1558
                                                                break;
×
1559
                                                        case 73:
1560
                                                                ellipse.CounterClockWise = this._reader.ValueAsBool;
×
1561
                                                                break;
×
1562
                                                        default:
1563
                                                                return ellipse;
×
1564
                                                }
1565

1566
                                                this._reader.ReadNext();
×
1567
                                        }
×
1568
                                case Hatch.BoundaryPath.EdgeType.Spline:
1569
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1570
                                        int nKnots = 0;
×
1571
                                        int nCtrlPoints = 0;
×
1572
                                        int nFitPoints = 0;
×
1573

1574
                                        XYZ controlPoint = new XYZ();
×
1575
                                        XY fitPoint = new XY();
×
1576

1577
                                        while (true)
×
1578
                                        {
×
1579
                                                switch (this._reader.Code)
×
1580
                                                {
1581
                                                        case 10:
1582
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1583
                                                                break;
×
1584
                                                        case 20:
1585
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1586
                                                                spline.ControlPoints.Add(controlPoint);
×
1587
                                                                break;
×
1588
                                                        case 11:
1589
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
1590
                                                                break;
×
1591
                                                        case 21:
1592
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
1593
                                                                spline.FitPoints.Add(fitPoint);
×
1594
                                                                break;
×
1595
                                                        case 42:
1596
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
1597
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1598
                                                                break;
×
1599
                                                        case 12:
1600
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1601
                                                                break;
×
1602
                                                        case 22:
1603
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
1604
                                                                break;
×
1605
                                                        case 13:
1606
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1607
                                                                break;
×
1608
                                                        case 23:
1609
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1610
                                                                break;
×
1611
                                                        case 94:
1612
                                                                spline.Degree = this._reader.ValueAsInt;
×
1613
                                                                break;
×
1614
                                                        case 73:
1615
                                                                spline.Rational = this._reader.ValueAsBool;
×
1616
                                                                break;
×
1617
                                                        case 74:
1618
                                                                spline.Periodic = this._reader.ValueAsBool;
×
1619
                                                                break;
×
1620
                                                        case 95:
1621
                                                                nKnots = this._reader.ValueAsInt;
×
1622
                                                                break;
×
1623
                                                        case 96:
1624
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1625
                                                                break;
×
1626
                                                        case 97:
1627
                                                                nFitPoints = this._reader.ValueAsInt;
×
1628
                                                                break;
×
1629
                                                        case 40:
1630
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
1631
                                                                break;
×
1632
                                                        default:
1633
                                                                return spline;
×
1634
                                                }
1635

1636
                                                this._reader.ReadNext();
×
1637
                                        }
×
1638
                        }
1639

1640
                        return null;
×
1641
                }
2,132✔
1642

1643
                private void readDefinedGroups(CadTemplate template)
1644
                {
30,257✔
1645
                        this.readDefinedGroups(out ulong? xdict, out List<ulong> reactorsHandles);
30,257✔
1646

1647
                        template.XDictHandle = xdict;
30,257✔
1648
                        template.ReactorsHandles = reactorsHandles;
30,257✔
1649
                }
30,257✔
1650

1651
                private void readDefinedGroups(out ulong? xdictHandle, out List<ulong> reactors)
1652
                {
30,406✔
1653
                        xdictHandle = null;
30,406✔
1654
                        reactors = new List<ulong>();
30,406✔
1655

1656
                        switch (this._reader.ValueAsString)
30,406✔
1657
                        {
1658
                                case DxfFileToken.DictionaryToken:
1659
                                        this._reader.ReadNext();
5,764✔
1660
                                        xdictHandle = this._reader.ValueAsHandle;
5,764✔
1661
                                        this._reader.ReadNext();
5,764✔
1662
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
5,764✔
1663
                                        return;
5,764✔
1664
                                case DxfFileToken.ReactorsToken:
1665
                                        reactors = this.readReactors();
24,109✔
1666
                                        break;
24,109✔
1667
                                case DxfFileToken.BlkRefToken:
1668
                                default:
1669
                                        do
1670
                                        {
1,332✔
1671
                                                this._reader.ReadNext();
1,332✔
1672
                                        }
1,332✔
1673
                                        while (this._reader.DxfCode != DxfCode.ControlString);
1,332✔
1674
                                        return;
533✔
1675
                        }
1676
                }
30,406✔
1677

1678
                private List<ulong> readReactors()
1679
                {
24,109✔
1680
                        List<ulong> reactors = new List<ulong>();
24,109✔
1681

1682
                        this._reader.ReadNext();
24,109✔
1683

1684
                        while (this._reader.DxfCode != DxfCode.ControlString)
49,980✔
1685
                        {
25,871✔
1686
                                this._reader.ReadNext();
25,871✔
1687
                        }
25,871✔
1688

1689
                        return reactors;
24,109✔
1690
                }
24,109✔
1691

1692
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
1693
                {
1,974,318✔
1694
                        try
1695
                        {
1,974,318✔
1696
                                //Use this method only if the value is not a link between objects
1697
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
1,974,318✔
1698
                                {
732,860✔
1699
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
732,860✔
1700
                                        {
4,068✔
1701
                                                return true;
4,068✔
1702
                                        }
1703

1704
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
728,792!
1705
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
728,792✔
1706
                                        {
34,180✔
1707
                                                return false;
34,180✔
1708
                                        }
1709

1710
                                        object value = this._reader.Value;
694,612✔
1711

1712
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
694,612✔
1713
                                        {
4,425✔
1714
                                                value = (double)value * MathUtils.DegToRadFactor;
4,425✔
1715
                                        }
4,425✔
1716

1717
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
694,612✔
1718

1719
                                        return true;
694,612✔
1720
                                }
1721
                        }
1,241,458✔
1722
                        catch (Exception ex)
×
1723
                        {
×
1724
                                if (!this._builder.Configuration.Failsafe)
×
1725
                                {
×
1726
                                        throw ex;
×
1727
                                }
1728
                                else
1729
                                {
×
1730
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
1731
                                }
×
1732
                        }
×
1733

1734
                        return false;
1,241,458✔
1735
                }
1,974,318✔
1736
        }
1737
}
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