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

DomCR / ACadSharp / 13952945691

19 Mar 2025 05:30PM UTC coverage: 76.278% (+0.06%) from 76.22%
13952945691

Pull #581

github

web-flow
Merge 6252e0906 into 791c7d93a
Pull Request #581: Implement Material

5522 of 7947 branches covered (69.49%)

Branch coverage included in aggregate %.

115 of 143 new or added lines in 4 files covered. (80.42%)

45 existing lines in 3 files now uncovered.

21790 of 27859 relevant lines covered (78.22%)

75259.07 hits per line

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

89.52
/src/ACadSharp/IO/DXF/DxfStreamReader/DxfObjectsSectionReader.cs
1
using ACadSharp.IO.Templates;
2
using ACadSharp.Objects;
3
using ACadSharp.Objects.Evaluations;
4
using System;
5
using System.Collections.Generic;
6
using System.Diagnostics;
7
using System.Linq;
8
using static ACadSharp.IO.Templates.CadEvaluationGraphTemplate;
9

10
namespace ACadSharp.IO.DXF
11
{
12
        internal class DxfObjectsSectionReader : DxfSectionReaderBase
13
        {
14
                public delegate bool ReadObjectDelegate<T>(CadTemplate template, DxfMap map) where T : CadObject;
15

16
                public DxfObjectsSectionReader(IDxfStreamReader reader, DxfDocumentBuilder builder)
17
                        : base(reader, builder)
206✔
18
                {
206✔
19
                }
206✔
20

21
                public override void Read()
22
                {
206✔
23
                        //Advance to the first value in the section
24
                        this._reader.ReadNext();
206✔
25

26
                        //Loop until the section ends
27
                        while (this._reader.ValueAsString != DxfFileToken.EndSection)
58,841✔
28
                        {
58,635✔
29
                                CadTemplate template = null;
58,635✔
30

31
                                try
32
                                {
58,635✔
33
                                        template = this.readObject();
58,635✔
34
                                }
58,635✔
35
                                catch (Exception ex)
×
36
                                {
×
37
                                        if (!this._builder.Configuration.Failsafe)
×
38
                                                throw;
×
39

40
                                        this._builder.Notify($"Error while reading an object at line {this._reader.Position}", NotificationType.Error, ex);
×
41

42
                                        while (this._reader.DxfCode != DxfCode.Start)
×
43
                                                this._reader.ReadNext();
×
44
                                }
×
45

46
                                if (template == null)
58,635✔
47
                                        continue;
368✔
48

49
                                //Add the object and the template to the builder
50
                                this._builder.AddTemplate(template);
58,267✔
51
                        }
58,267✔
52
                }
206✔
53

54
                private CadTemplate readObject()
55
                {
58,635✔
56
                        switch (this._reader.ValueAsString)
58,635!
57
                        {
58
                                case DxfFileToken.ObjectDBColor:
59
                                        return this.readObjectCodes<BookColor>(new CadNonGraphicalObjectTemplate(new BookColor()), this.readBookColor);
192✔
60
                                case DxfFileToken.ObjectDictionary:
61
                                        return this.readObjectCodes<CadDictionary>(new CadDictionaryTemplate(), this.readDictionary);
19,268✔
62
                                case DxfFileToken.ObjectDictionaryWithDefault:
63
                                        return this.readObjectCodes<CadDictionaryWithDefault>(new CadDictionaryWithDefaultTemplate(), this.readDictionaryWithDefault);
194✔
64
                                case DxfFileToken.ObjectLayout:
65
                                        return this.readObjectCodes<Layout>(new CadLayoutTemplate(), this.readLayout);
798✔
66
                                case DxfFileToken.ObjectEvalGraph:
67
                                        return this.readObjectCodes<EvaluationGraph>(new CadEvaluationGraphTemplate(), this.readEvaluationGraph);
192✔
68
                                case DxfFileToken.ObjectDictionaryVar:
69
                                        return this.readObjectCodes<DictionaryVariable>(new CadTemplate<DictionaryVariable>(new DictionaryVariable()), this.readObjectSubclassMap);
2,757✔
70
                                case DxfFileToken.ObjectPdfDefinition:
71
                                        return this.readObjectCodes<PdfUnderlayDefinition>(new CadNonGraphicalObjectTemplate(new PdfUnderlayDefinition()), this.readObjectSubclassMap);
×
72
                                case DxfFileToken.ObjectSortEntsTable:
73
                                        return this.readSortentsTable();
576✔
74
                                case DxfFileToken.ObjectGroup:
75
                                        return this.readObjectCodes<Group>(new CadGroupTemplate(), this.readGroup);
384✔
76
                                case DxfFileToken.ObjectGeoData:
77
                                        return this.readObjectCodes<GeoData>(new CadGeoDataTemplate(), this.readGeoData);
2✔
78
                                case DxfFileToken.ObjectMaterial:
79
                                        return this.readObjectCodes<Material>(new CadMaterialTemplate(), this.readMaterial);
582✔
80
                                case DxfFileToken.ObjectScale:
81
                                        return this.readObjectCodes<Scale>(new CadTemplate<Scale>(new Scale()), this.readScale);
6,606✔
82
                                case DxfFileToken.ObjectTableContent:
83
                                        return this.readObjectCodes<TableContent>(new CadTableContentTemplate(), this.readTableContent);
384✔
84
                                case DxfFileToken.ObjectVisualStyle:
85
                                        return this.readObjectCodes<VisualStyle>(new CadTemplate<VisualStyle>(new VisualStyle()), this.readVisualStyle);
4,656✔
86
                                case DxfFileToken.ObjectXRecord:
87
                                        return this.readObjectCodes<XRecord>(new CadXRecordTemplate(), this.readXRecord);
15,154✔
88
                                default:
89
                                        DxfMap map = DxfMap.Create<CadObject>();
6,890✔
90
                                        CadUnknownNonGraphicalObjectTemplate unknownEntityTemplate = null;
6,890✔
91
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
6,890✔
92
                                        {
6,522✔
93
                                                this._builder.Notify($"NonGraphicalObject not supported read as an UnknownNonGraphicalObject: {this._reader.ValueAsString}", NotificationType.NotImplemented);
6,522✔
94
                                                unknownEntityTemplate = new CadUnknownNonGraphicalObjectTemplate(new UnknownNonGraphicalObject(dxfClass));
6,522✔
95
                                        }
6,522✔
96
                                        else
97
                                        {
368✔
98
                                                this._builder.Notify($"UnknownNonGraphicalObject not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
368✔
99
                                        }
368✔
100

101
                                        this._reader.ReadNext();
6,890✔
102

103
                                        do
104
                                        {
362,040✔
105
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
362,040✔
106
                                                {
43,048✔
107
                                                        this.readCommonCodes(unknownEntityTemplate, out bool isExtendedData, map);
43,048✔
108
                                                        if (isExtendedData)
43,048✔
109
                                                                continue;
48✔
110
                                                }
43,000✔
111

112
                                                this._reader.ReadNext();
361,992✔
113
                                        }
361,992✔
114
                                        while (this._reader.DxfCode != DxfCode.Start);
362,040✔
115

116
                                        return unknownEntityTemplate;
6,890✔
117
                        }
118
                }
58,635✔
119

120
                protected CadTemplate readObjectCodes<T>(CadTemplate template, ReadObjectDelegate<T> readObject)
121
                        where T : CadObject
122
                {
51,169✔
123
                        this._reader.ReadNext();
51,169✔
124

125
                        DxfMap map = DxfMap.Create<T>();
51,169✔
126

127
                        while (this._reader.DxfCode != DxfCode.Start)
1,664,818✔
128
                        {
1,613,649✔
129
                                if (!readObject(template, map))
1,613,649✔
130
                                {
946,557✔
131
                                        this.readCommonCodes(template, out bool isExtendedData, map);
946,557✔
132
                                        if (isExtendedData)
946,557✔
133
                                                continue;
5,115✔
134
                                }
941,442✔
135

136
                                if (this._reader.DxfCode != DxfCode.Start)
1,608,534✔
137
                                        this._reader.ReadNext();
1,593,188✔
138
                        }
1,608,534✔
139

140
                        return template;
51,169✔
141
                }
51,169✔
142

143
                private bool readObjectSubclassMap(CadTemplate template, DxfMap map)
144
                {
16,542✔
145
                        switch (this._reader.Code)
16,542✔
146
                        {
147
                                default:
148
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
16,542✔
149
                        }
150
                }
16,542✔
151

152
                private bool readPlotSettings(CadTemplate template, DxfMap map)
153
                {
25,252✔
154
                        switch (this._reader.Code)
25,252✔
155
                        {
156
                                default:
157
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.PlotSettings]);
25,252✔
158
                        }
159
                }
25,252✔
160

161
                private bool readEvaluationGraph(CadTemplate template, DxfMap map)
162
                {
1,536✔
163
                        CadEvaluationGraphTemplate tmp = template as CadEvaluationGraphTemplate;
1,536✔
164
                        EvaluationGraph evGraph = tmp.CadObject;
1,536✔
165

166
                        switch (this._reader.Code)
1,536✔
167
                        {
168
                                case 91:
169
                                        while (this._reader.Code == 91)
2,496✔
170
                                        {
2,304✔
171
                                                GraphNodeTemplate nodeTemplate = new GraphNodeTemplate();
2,304✔
172
                                                EvaluationGraph.Node node = nodeTemplate.Node;
2,304✔
173

174
                                                node.Index = this._reader.ValueAsInt;
2,304✔
175

176
                                                this._reader.ExpectedCode(93);
2,304✔
177
                                                node.Flags = this._reader.ValueAsInt;
2,304✔
178

179
                                                this._reader.ExpectedCode(95);
2,304✔
180
                                                node.NextNodeIndex = this._reader.ValueAsInt;
2,304✔
181

182
                                                this._reader.ExpectedCode(360);
2,304✔
183
                                                nodeTemplate.ExpressionHandle = this._reader.ValueAsHandle;
2,304✔
184

185
                                                this._reader.ExpectedCode(92);
2,304✔
186
                                                node.Data1 = this._reader.ValueAsInt;
2,304✔
187
                                                this._reader.ExpectedCode(92);
2,304✔
188
                                                node.Data2 = this._reader.ValueAsInt;
2,304✔
189
                                                this._reader.ExpectedCode(92);
2,304✔
190
                                                node.Data3 = this._reader.ValueAsInt;
2,304✔
191
                                                this._reader.ExpectedCode(92);
2,304✔
192
                                                node.Data4 = this._reader.ValueAsInt;
2,304✔
193

194
                                                this._reader.ReadNext();
2,304✔
195

196
                                                tmp.NodeTemplates.Add(nodeTemplate);
2,304✔
197
                                        }
2,304✔
198

199
                                        return this.checkObjectEnd(template, map, this.readEvaluationGraph);
192✔
200
                                case 92:
201
                                        //Edges
202
                                        while (this._reader.Code == 92)
2,112✔
203
                                        {
1,920✔
204
                                                this._reader.ExpectedCode(93);
1,920✔
205
                                                this._reader.ExpectedCode(94);
1,920✔
206
                                                this._reader.ExpectedCode(91);
1,920✔
207
                                                this._reader.ExpectedCode(91);
1,920✔
208
                                                this._reader.ExpectedCode(92);
1,920✔
209
                                                this._reader.ExpectedCode(92);
1,920✔
210
                                                this._reader.ExpectedCode(92);
1,920✔
211
                                                this._reader.ExpectedCode(92);
1,920✔
212
                                                this._reader.ExpectedCode(92);
1,920✔
213

214
                                                this._reader.ReadNext();
1,920✔
215
                                        }
1,920✔
216

217
                                        return this.checkObjectEnd(template, map, this.readEvaluationGraph);
192✔
218
                                default:
219
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.EvalGraph]);
1,152✔
220
                        }
221
                }
1,536✔
222

223
                private bool readLayout(CadTemplate template, DxfMap map)
224
                {
51,406✔
225
                        CadLayoutTemplate tmp = template as CadLayoutTemplate;
51,406✔
226

227
                        switch (this._reader.Code)
51,406✔
228
                        {
229
                                case 330:
230
                                        tmp.PaperSpaceBlockHandle = this._reader.ValueAsHandle;
1,596✔
231
                                        return true;
1,596✔
232
                                case 331:
233
                                        tmp.LasActiveViewportHandle = (this._reader.ValueAsHandle);
770✔
234
                                        return true;
770✔
235
                                default:
236
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Layout]))
49,040✔
237
                                        {
25,252✔
238
                                                return this.readPlotSettings(template, map);
25,252✔
239
                                        }
240
                                        return true;
23,788✔
241
                        }
242
                }
51,406✔
243

244
                private bool readGroup(CadTemplate template, DxfMap map)
245
                {
4,992✔
246
                        CadGroupTemplate tmp = template as CadGroupTemplate;
4,992✔
247

248
                        switch (this._reader.Code)
4,992✔
249
                        {
250
                                case 70:
251
                                        return true;
384✔
252
                                case 340:
253
                                        tmp.Handles.Add(this._reader.ValueAsHandle);
2,304✔
254
                                        return true;
2,304✔
255
                                default:
256
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
2,304✔
257
                        }
258
                }
4,992✔
259

260
                private bool readGeoData(CadTemplate template, DxfMap map)
261
                {
102✔
262
                        CadGeoDataTemplate tmp = template as CadGeoDataTemplate;
102✔
263

264
                        switch (this._reader.Code)
102✔
265
                        {
266
                                case 40 when tmp.CadObject.Version == GeoDataVersion.R2009:
2✔
267
                                        tmp.CadObject.ReferencePoint = new CSMath.XYZ(
1✔
268
                                                tmp.CadObject.ReferencePoint.X,
1✔
269
                                                this._reader.ValueAsDouble,
1✔
270
                                                tmp.CadObject.ReferencePoint.Z
1✔
271
                                                );
1✔
272
                                        return true;
1✔
273
                                case 41 when tmp.CadObject.Version == GeoDataVersion.R2009:
2✔
274
                                        tmp.CadObject.ReferencePoint = new CSMath.XYZ(
1✔
275
                                                this._reader.ValueAsDouble,
1✔
276
                                                tmp.CadObject.ReferencePoint.Y,
1✔
277
                                                tmp.CadObject.ReferencePoint.Z
1✔
278
                                                );
1✔
279
                                        return true;
1✔
280
                                case 42 when tmp.CadObject.Version == GeoDataVersion.R2009:
1✔
281
                                        tmp.CadObject.ReferencePoint = new CSMath.XYZ(
1✔
282
                                                tmp.CadObject.ReferencePoint.X,
1✔
283
                                                tmp.CadObject.ReferencePoint.Y,
1✔
284
                                                this._reader.ValueAsDouble
1✔
285
                                                );
1✔
286
                                        return true;
1✔
287
                                case 46 when tmp.CadObject.Version == GeoDataVersion.R2009:
1✔
288
                                        tmp.CadObject.HorizontalUnitScale = this._reader.ValueAsDouble;
1✔
289
                                        return true;
1✔
290
                                case 52 when tmp.CadObject.Version == GeoDataVersion.R2009:
1✔
291
                                        double angle = System.Math.PI / 2.0 - this._reader.ValueAsAngle;
1✔
292
                                        tmp.CadObject.NorthDirection = new CSMath.XY(Math.Cos(angle), Math.Sin(angle));
1✔
293
                                        return true;
1✔
294
                                // Number of Geo-Mesh points
295
                                case 93:
296
                                        var npts = this._reader.ValueAsInt;
3✔
297
                                        for (int i = 0; i < npts; i++)
54✔
298
                                        {
24✔
299
                                                this._reader.ReadNext();
24✔
300
                                                double sourceX = this._reader.ValueAsDouble;
24✔
301
                                                this._reader.ReadNext();
24✔
302
                                                double sourceY = this._reader.ValueAsDouble;
24✔
303

304
                                                this._reader.ReadNext();
24✔
305
                                                double destX = this._reader.ValueAsDouble;
24✔
306
                                                this._reader.ReadNext();
24✔
307
                                                double destY = this._reader.ValueAsDouble;
24✔
308

309
                                                tmp.CadObject.Points.Add(new GeoData.GeoMeshPoint
24✔
310
                                                {
24✔
311
                                                        Source = new CSMath.XY(sourceX, sourceY),
24✔
312
                                                        Destination = new CSMath.XY(destX, destY)
24✔
313
                                                });
24✔
314
                                        }
24✔
315
                                        return true;
3✔
316
                                // Number of Geo-Mesh points
317
                                case 96:
318
                                        var nfaces = this._reader.ValueAsInt;
2✔
319
                                        for (int i = 0; i < nfaces; i++)
4!
320
                                        {
×
321
                                                this._reader.ReadNext();
×
322
                                                Debug.Assert(this._reader.Code == 97);
×
323
                                                int index1 = this._reader.ValueAsInt;
×
324
                                                this._reader.ReadNext();
×
325
                                                Debug.Assert(this._reader.Code == 98);
×
326
                                                int index2 = this._reader.ValueAsInt;
×
327
                                                this._reader.ReadNext();
×
328
                                                Debug.Assert(this._reader.Code == 99);
×
329
                                                int index3 = this._reader.ValueAsInt;
×
330

331
                                                tmp.CadObject.Faces.Add(new GeoData.GeoMeshFace
×
332
                                                {
×
333
                                                        Index1 = index1,
×
334
                                                        Index2 = index2,
×
335
                                                        Index3 = index3
×
336
                                                });
×
337
                                        }
×
338
                                        return true;
2✔
339
                                case 303:
340
                                        tmp.CadObject.CoordinateSystemDefinition += this._reader.ValueAsString;
13✔
341
                                        return true;
13✔
342
                                //Obsolete codes for version GeoDataVersion.R2009
343
                                case 3:
344
                                case 4:
345
                                case 14:
346
                                case 24:
347
                                case 15:
348
                                case 25:
349
                                case 43:
350
                                case 44:
351
                                case 45:
352
                                case 94:
353
                                case 293:
354
                                case 16:
355
                                case 26:
356
                                case 17:
357
                                case 27:
358
                                case 54:
359
                                case 140:
360
                                case 304:
361
                                case 292:
362
                                        return true;
19✔
363
                                default:
364
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
60✔
365
                        }
366
                }
102✔
367

368
                private bool readMaterial(CadTemplate template, DxfMap map)
369
                {
4,852✔
370
                        CadMaterialTemplate tmp = template as CadMaterialTemplate;
4,852✔
371
                        List<double> arr = null;
4,852✔
372

373
                        switch (this._reader.Code)
4,852!
374
                        {
375
                                case 43:
376
                                        arr = new();
194✔
377
                                        for (int i = 0; i < 16; i++)
6,596✔
378
                                        {
3,104✔
379
                                                Debug.Assert(this._reader.Code == 43);
3,104✔
380

381
                                                arr.Add(this._reader.ValueAsDouble);
3,104✔
382

383
                                                this._reader.ReadNext();
3,104✔
384
                                        }
3,104✔
385

386
                                        tmp.CadObject.DiffuseMatrix = new CSMath.Matrix4(arr.ToArray());
194✔
387
                                        return this.checkObjectEnd(template, map, this.readMaterial);
194✔
388
                                case 47:
NEW
389
                                        arr = new();
×
NEW
390
                                        for (int i = 0; i < 16; i++)
×
NEW
391
                                        {
×
NEW
392
                                                Debug.Assert(this._reader.Code == 47);
×
393

NEW
394
                                                arr.Add(this._reader.ValueAsDouble);
×
395

NEW
396
                                                this._reader.ReadNext();
×
NEW
397
                                        }
×
398

NEW
399
                                        tmp.CadObject.SpecularMatrix = new CSMath.Matrix4(arr.ToArray());
×
NEW
400
                                        return this.checkObjectEnd(template, map, this.readMaterial);
×
401
                                case 49:
402
                                        arr = new();
194✔
403
                                        for (int i = 0; i < 16; i++)
6,596✔
404
                                        {
3,104✔
405
                                                Debug.Assert(this._reader.Code == 49);
3,104✔
406

407
                                                arr.Add(this._reader.ValueAsDouble);
3,104✔
408

409
                                                this._reader.ReadNext();
3,104✔
410
                                        }
3,104✔
411

412
                                        tmp.CadObject.ReflectionMatrix = new CSMath.Matrix4(arr.ToArray());
194✔
413
                                        return this.checkObjectEnd(template, map, this.readMaterial);
194✔
414
                                case 142:
415
                                        arr = new();
194✔
416
                                        for (int i = 0; i < 16; i++)
6,596✔
417
                                        {
3,104✔
418
                                                Debug.Assert(this._reader.Code == 142);
3,104✔
419

420
                                                arr.Add(this._reader.ValueAsDouble);
3,104✔
421

422
                                                this._reader.ReadNext();
3,104✔
423
                                        }
3,104✔
424

425
                                        tmp.CadObject.OpacityMatrix = new CSMath.Matrix4(arr.ToArray());
194✔
426
                                        return this.checkObjectEnd(template, map, this.readMaterial);
194✔
427
                                case 144:
428
                                        arr = new();
194✔
429
                                        for (int i = 0; i < 16; i++)
6,596✔
430
                                        {
3,104✔
431
                                                Debug.Assert(this._reader.Code == 144);
3,104✔
432

433
                                                arr.Add(this._reader.ValueAsDouble);
3,104✔
434

435
                                                this._reader.ReadNext();
3,104✔
436
                                        }
3,104✔
437

438
                                        tmp.CadObject.BumpMatrix = new CSMath.Matrix4(arr.ToArray());
194✔
439
                                        return this.checkObjectEnd(template, map, this.readMaterial);
194✔
440
                                case 147:
NEW
441
                                        arr = new();
×
NEW
442
                                        for (int i = 0; i < 16; i++)
×
NEW
443
                                        {
×
NEW
444
                                                Debug.Assert(this._reader.Code == 147);
×
445

NEW
446
                                                arr.Add(this._reader.ValueAsDouble);
×
447

NEW
448
                                                this._reader.ReadNext();
×
NEW
449
                                        }
×
450

NEW
451
                                        tmp.CadObject.RefractionMatrix = new CSMath.Matrix4(arr.ToArray());
×
NEW
452
                                        return this.checkObjectEnd(template, map, this.readMaterial);
×
453
                                default:
454
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
4,076✔
455
                        }
456
                }
4,852✔
457

458
                private bool readScale(CadTemplate template, DxfMap map)
459
                {
59,250✔
460
                        switch (this._reader.Code)
59,250✔
461
                        {
462
                                // Undocumented codes
463
                                case 70:
464
                                        //Always 0
465
                                        return true;
6,606✔
466
                                default:
467
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Scale]);
52,644✔
468
                        }
469
                }
59,250✔
470

471
                private bool readTableContent(CadTemplate template, DxfMap map)
472
                {
888,576✔
473
                        switch (this._reader.Code)
888,576✔
474
                        {
475
                                default:
476
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.TableContent]);
888,576✔
477
                        }
478
                }
888,576✔
479

480
                private bool readVisualStyle(CadTemplate template, DxfMap map)
481
                {
346,908✔
482
                        switch (this._reader.Code)
346,908✔
483
                        {
484
                                // Undocumented codes
485
                                case 176:
486
                                case 177:
487
                                case 420:
488
                                        return true;
119,122✔
489
                                default:
490
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.VisualStyle]);
227,786✔
491
                        }
492
                }
346,908✔
493

494
                private bool readXRecord(CadTemplate template, DxfMap map)
495
                {
58,184✔
496
                        CadXRecordTemplate tmp = template as CadXRecordTemplate;
58,184✔
497

498
                        switch (this._reader.Code)
58,184✔
499
                        {
500
                                case 100 when this._reader.ValueAsString == DxfSubclassMarker.XRecord:
15,154✔
501
                                        this.readXRecordEntries(tmp);
15,154✔
502
                                        return true;
15,154✔
503
                                default:
504
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.XRecord]);
43,030✔
505
                        }
506
                }
58,184✔
507

508
                private void readXRecordEntries(CadXRecordTemplate template)
509
                {
15,154✔
510
                        this._reader.ReadNext();
15,154✔
511

512
                        while (this._reader.DxfCode != DxfCode.Start)
830,680✔
513
                        {
815,526✔
514
                                switch (this._reader.GroupCodeValue)
815,526!
515
                                {
516
                                        case GroupCodeValueType.Handle:
517
                                                template.AddHandleReference(this._reader.Code, this._reader.ValueAsHandle);
×
518
                                                break;
×
519
                                        default:
520
                                                template.CadObject.CreateEntry(this._reader.Code, this._reader.Value);
815,526✔
521
                                                break;
815,526✔
522
                                }
523

524
                                this._reader.ReadNext();
815,526✔
525
                        }
815,526✔
526
                }
15,154✔
527

528
                private bool readBookColor(CadTemplate template, DxfMap map)
529
                {
1,376✔
530
                        CadNonGraphicalObjectTemplate tmp = template as CadNonGraphicalObjectTemplate;
1,376✔
531
                        BookColor color = tmp.CadObject as BookColor;
1,376✔
532

533
                        switch (this._reader.Code)
1,376✔
534
                        {
535
                                case 430:
536
                                        color.Name = this._reader.ValueAsString;
160✔
537
                                        return true;
160✔
538
                                default:
539
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.DbColor]);
1,216✔
540
                        }
541
                }
1,376✔
542

543
                private bool readDictionary(CadTemplate template, DxfMap map)
544
                {
180,699✔
545
                        CadDictionaryTemplate tmp = template as CadDictionaryTemplate;
180,699✔
546
                        CadDictionary cadDictionary = tmp.CadObject;
180,699✔
547

548
                        switch (this._reader.Code)
180,699✔
549
                        {
550
                                case 280:
551
                                        cadDictionary.HardOwnerFlag = this._reader.ValueAsBool;
13,185✔
552
                                        return true;
13,185✔
553
                                case 281:
554
                                        cadDictionary.ClonningFlags = (DictionaryCloningFlags)this._reader.Value;
19,462✔
555
                                        return true;
19,462✔
556
                                case 3:
557
                                        tmp.Entries.Add(this._reader.ValueAsString, null);
40,814✔
558
                                        return true;
40,814✔
559
                                case 350: // Soft-owner ID/handle to entry object 
560
                                case 360: // Hard-owner ID/handle to entry object
561
                                        tmp.Entries[tmp.Entries.LastOrDefault().Key] = this._reader.ValueAsHandle;
40,814✔
562
                                        return true;
40,814✔
563
                                default:
564
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dictionary]);
66,424✔
565
                        }
566
                }
180,699✔
567

568
                private bool readDictionaryWithDefault(CadTemplate template, DxfMap map)
569
                {
1,746✔
570
                        CadDictionaryWithDefaultTemplate tmp = template as CadDictionaryWithDefaultTemplate;
1,746✔
571

572
                        switch (this._reader.Code)
1,746✔
573
                        {
574
                                case 340:
575
                                        tmp.DefaultEntryHandle = this._reader.ValueAsHandle;
194✔
576
                                        return true;
194✔
577
                                default:
578
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.DictionaryWithDefault]))
1,552!
579
                                        {
1,552✔
580
                                                return this.readDictionary(template, map);
1,552✔
581
                                        }
582
                                        return true;
×
583
                        }
584
                }
1,746✔
585

586
                private CadTemplate readSortentsTable()
587
                {
576✔
588
                        SortEntitiesTable sortTable = new SortEntitiesTable();
576✔
589
                        CadSortensTableTemplate template = new CadSortensTableTemplate(sortTable);
576✔
590

591
                        //Jump the 0 marker
592
                        this._reader.ReadNext();
576✔
593

594
                        this.readCommonObjectData(template);
576✔
595

596
                        System.Diagnostics.Debug.Assert(DxfSubclassMarker.SortentsTable == this._reader.ValueAsString);
576✔
597

598
                        //Jump the 100 marker
599
                        this._reader.ReadNext();
576✔
600

601
                        (ulong?, ulong?) pair = (null, null);
576✔
602

603
                        while (this._reader.DxfCode != DxfCode.Start)
4,224✔
604
                        {
3,648✔
605
                                switch (this._reader.Code)
3,648!
606
                                {
607
                                        case 5:
608
                                                pair.Item1 = this._reader.ValueAsHandle;
1,536✔
609
                                                break;
1,536✔
610
                                        case 330:
611
                                                template.BlockOwnerHandle = this._reader.ValueAsHandle;
576✔
612
                                                break;
576✔
613
                                        case 331:
614
                                                pair.Item2 = this._reader.ValueAsHandle;
1,536✔
615
                                                break;
1,536✔
616
                                        default:
617
                                                this._builder.Notify($"Group Code not handled {this._reader.GroupCodeValue} for {typeof(SortEntitiesTable)}, code : {this._reader.Code} | value : {this._reader.ValueAsString}");
×
618
                                                break;
×
619
                                }
620

621
                                if (pair.Item1.HasValue && pair.Item2.HasValue)
3,648✔
622
                                {
1,536✔
623
                                        template.Values.Add((pair.Item1.Value, pair.Item2.Value));
1,536✔
624
                                        pair = (null, null);
1,536✔
625
                                }
1,536✔
626

627
                                this._reader.ReadNext();
3,648✔
628
                        }
3,648✔
629

630
                        return template;
576✔
631
                }
576✔
632
        }
633
}
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