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

DomCR / ACadSharp / 12950091812

24 Jan 2025 12:57PM UTC coverage: 75.997% (+74.0%) from 2.0%
12950091812

Pull #541

github

web-flow
Merge 0f5f2d236 into 5c1c15065
Pull Request #541: XData for DxfReader fix

5283 of 7676 branches covered (68.82%)

Branch coverage included in aggregate %.

11 of 12 new or added lines in 5 files covered. (91.67%)

1 existing line in 1 file now uncovered.

21094 of 27032 relevant lines covered (78.03%)

39032.22 hits per line

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

90.86
/src/ACadSharp/IO/DXF/DxfStreamReader/DxfTablesSectionReader.cs
1
using ACadSharp.Exceptions;
2
using ACadSharp.IO.Templates;
3
using ACadSharp.Tables;
4
using ACadSharp.Tables.Collections;
5
using ACadSharp.Types.Units;
6
using ACadSharp.XData;
7
using CSMath;
8
using CSUtilities.Extensions;
9
using System;
10
using System.Collections.Generic;
11
using System.Diagnostics;
12
using static ACadSharp.IO.Templates.CadLineTypeTemplate;
13

14
namespace ACadSharp.IO.DXF
15
{
16
        internal class DxfTablesSectionReader : DxfSectionReaderBase
17
        {
18
                public delegate bool ReadEntryDelegate<T>(CadTableEntryTemplate<T> template, DxfClassMap map) where T : TableEntry;
19

20
                public DxfTablesSectionReader(IDxfStreamReader reader, DxfDocumentBuilder builder)
21
                        : base(reader, builder)
179✔
22
                {
179✔
23
                }
179✔
24

25
                public override void Read()
26
                {
179✔
27
                        //Advance to the first value in the section
28
                        this._reader.ReadNext();
179✔
29

30
                        //Loop until the section ends
31
                        while (this._reader.ValueAsString != DxfFileToken.EndSection)
1,768✔
32
                        {
1,589✔
33

34
                                if (this._reader.ValueAsString == DxfFileToken.TableEntry)
1,589!
35
                                        this.readTable();
1,589✔
36
                                else
NEW
37
                                        throw new DxfException($"Unexpected token at the beginning of a table: {this._reader.ValueAsString}", this._reader.Position);
×
38

39

40
                                if (this._reader.ValueAsString == DxfFileToken.EndTable)
1,589!
41
                                        this._reader.ReadNext();
1,589✔
42
                                else
43
                                        throw new DxfException($"Unexpected token at the end of a table: {this._reader.ValueAsString}", this._reader.Position);
×
44
                        }
1,589✔
45
                }
179✔
46

47
                private void readTable()
48
                {
1,589✔
49
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.TableEntry);
1,589✔
50

51
                        //Read the table name
52
                        this._reader.ReadNext();
1,589✔
53

54
                        int nentries = 0;
1,589✔
55
                        CadTemplate template = null;
1,589✔
56
                        Dictionary<string, List<ExtendedDataRecord>> edata = new();
1,589✔
57

58
                        this.readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out List<ulong> reactors);
1,589✔
59

60
                        if (this._reader.DxfCode == DxfCode.Subclass)
1,589✔
61
                        {
1,413✔
62
                                while (this._reader.DxfCode != DxfCode.Start)
4,239✔
63
                                {
3,112✔
64
                                        switch (this._reader.Code)
3,112!
65
                                        {
66
                                                //Maximum number of entries in table
67
                                                case 70:
68
                                                        nentries = this._reader.ValueAsInt;
1,413✔
69
                                                        break;
1,413✔
70
                                                case 100 when this._reader.ValueAsString == DxfSubclassMarker.DimensionStyleTable:
1,570✔
71
                                                        while (this._reader.DxfCode != DxfCode.Start)
759✔
72
                                                        {
602✔
73
                                                                //template.CadObject has the code 71 for the count of entries
74
                                                                //Also has 340 codes for each entry with the handles
75
                                                                this._reader.ReadNext();
602✔
76
                                                        }
602✔
77
                                                        break;
157✔
78
                                                case 100:
79
                                                        Debug.Assert(this._reader.ValueAsString == DxfSubclassMarker.Table);
1,413✔
80
                                                        break;
1,413✔
81
                                                case 1001:
82
                                                        this.readExtendedData(edata);
129✔
83
                                                        break;
129✔
84
                                                default:
85
                                                        this._builder.Notify($"[AcDbSymbolTable] Unhandeled dxf code {this._reader.Code} at line {this._reader.Position}.");
×
86
                                                        break;
×
87
                                        }
88

89
                                        if (this._reader.DxfCode == DxfCode.Start)
3,112✔
90
                                                break;
286✔
91

92
                                        this._reader.ReadNext();
2,826✔
93
                                }
2,826✔
94
                        }
1,413✔
95
                        else if (this._reader.ValueAsString == DxfFileToken.EndTable)
176✔
96
                        {
22✔
97
                                return;
22✔
98
                        }
99
                        else
100
                        {
154✔
101
                                this._reader.ReadNext();
154✔
102
                        }
154✔
103

104
                        switch (name)
1,567!
105
                        {
106
                                case DxfFileToken.TableAppId:
107
                                        template = new CadTableTemplate<AppId>(new AppIdsTable());
179✔
108
                                        this.readEntries((CadTableTemplate<AppId>)template);
179✔
109
                                        template.CadObject.Handle = handle;
179✔
110
                                        this._builder.AppIds = (AppIdsTable)template.CadObject;
179✔
111
                                        break;
179✔
112
                                case DxfFileToken.TableBlockRecord:
113
                                        template = new CadBlockCtrlObjectTemplate(new BlockRecordsTable());
157✔
114
                                        this.readEntries((CadBlockCtrlObjectTemplate)template);
157✔
115
                                        template.CadObject.Handle = handle;
157✔
116
                                        this._builder.BlockRecords = (BlockRecordsTable)template.CadObject;
157✔
117
                                        break;
157✔
118
                                case DxfFileToken.TableVport:
119
                                        template = new CadTableTemplate<VPort>(new VPortsTable());
179✔
120
                                        this.readEntries((CadTableTemplate<VPort>)template);
179✔
121
                                        template.CadObject.Handle = handle;
179✔
122
                                        this._builder.VPorts = (VPortsTable)template.CadObject;
179✔
123
                                        break;
179✔
124
                                case DxfFileToken.TableLinetype:
125
                                        template = new CadTableTemplate<LineType>(new LineTypesTable());
179✔
126
                                        this.readEntries((CadTableTemplate<LineType>)template);
179✔
127
                                        template.CadObject.Handle = handle;
179✔
128
                                        this._builder.LineTypesTable = (LineTypesTable)template.CadObject;
179✔
129
                                        break;
179✔
130
                                case DxfFileToken.TableLayer:
131
                                        template = new CadTableTemplate<Layer>(new LayersTable());
179✔
132
                                        this.readEntries((CadTableTemplate<Layer>)template);
179✔
133
                                        template.CadObject.Handle = handle;
179✔
134
                                        this._builder.Layers = (LayersTable)template.CadObject;
179✔
135
                                        break;
179✔
136
                                case DxfFileToken.TableStyle:
137
                                        template = new CadTableTemplate<TextStyle>(new TextStylesTable());
179✔
138
                                        this.readEntries((CadTableTemplate<TextStyle>)template);
179✔
139
                                        template.CadObject.Handle = handle;
179✔
140
                                        this._builder.TextStyles = (TextStylesTable)template.CadObject;
179✔
141
                                        break;
179✔
142
                                case DxfFileToken.TableView:
143
                                        template = new CadTableTemplate<View>(new ViewsTable());
179✔
144
                                        this.readEntries((CadTableTemplate<View>)template);
179✔
145
                                        template.CadObject.Handle = handle;
179✔
146
                                        this._builder.Views = (ViewsTable)template.CadObject;
179✔
147
                                        break;
179✔
148
                                case DxfFileToken.TableUcs:
149
                                        template = new CadTableTemplate<UCS>(new UCSTable());
157✔
150
                                        this.readEntries((CadTableTemplate<UCS>)template);
157✔
151
                                        template.CadObject.Handle = handle;
157✔
152
                                        this._builder.UCSs = (UCSTable)template.CadObject;
157✔
153
                                        break;
157✔
154
                                case DxfFileToken.TableDimstyle:
155
                                        template = new CadTableTemplate<DimensionStyle>(new DimensionStylesTable());
179✔
156
                                        this.readEntries((CadTableTemplate<DimensionStyle>)template);
179✔
157
                                        template.CadObject.Handle = handle;
179✔
158
                                        this._builder.DimensionStyles = (DimensionStylesTable)template.CadObject;
179✔
159
                                        break;
179✔
160
                                default:
161
                                        throw new DxfException($"Unknown table name {name}");
×
162
                        }
163

164
                        Debug.Assert(ownerHandle == null || ownerHandle.Value == 0);
1,567✔
165

166
                        template.OwnerHandle = ownerHandle;
1,567✔
167
                        template.XDictHandle = xdictHandle;
1,567✔
168
                        template.ReactorsHandles = reactors;
1,567✔
169
                        template.EDataTemplateByAppName = edata;
1,567✔
170

171
                        //Add the object and the template to the builder
172
                        this._builder.AddTemplate(template);
1,567✔
173
                }
1,589✔
174

175
                private void readEntries<T>(CadTableTemplate<T> tableTemplate)
176
                        where T : TableEntry
177
                {
1,567✔
178
                        //Read all the entries until the end of the table
179
                        while (this._reader.ValueAsString != DxfFileToken.EndTable)
12,310✔
180
                        {
10,743✔
181
                                this._reader.ReadNext();
10,743✔
182

183
                                CadTemplate template = null;
10,743✔
184

185
                                //Get the entry
186
                                switch (tableTemplate.CadObject.ObjectName)
10,743!
187
                                {
188
                                        case DxfFileToken.TableAppId:
189
                                                template = this.readTableEntry(new CadTableEntryTemplate<AppId>(new AppId()), this.readAppId);
2,664✔
190
                                                break;
2,664✔
191
                                        case DxfFileToken.TableBlockRecord:
192
                                                CadBlockRecordTemplate block = new CadBlockRecordTemplate();
2,191✔
193
                                                template = this.readTableEntry(block, this.readBlockRecord);
2,191✔
194

195
                                                if (block.CadObject.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
2,191✔
196
                                                {
157✔
197
                                                        this._builder.ModelSpaceTemplate = block;
157✔
198
                                                }
157✔
199

200
                                                break;
2,191✔
201
                                        case DxfFileToken.TableDimstyle:
202
                                                template = this.readTableEntry(new CadDimensionStyleTemplate(), this.readDimensionStyle);
510✔
203
                                                break;
510✔
204
                                        case DxfFileToken.TableLayer:
205
                                                template = this.readTableEntry(new CadLayerTemplate(), this.readLayer);
2,841✔
206
                                                break;
2,841✔
207
                                        case DxfFileToken.TableLinetype:
208
                                                template = this.readTableEntry(new CadLineTypeTemplate(), this.readLineType);
1,263✔
209
                                                break;
1,263✔
210
                                        case DxfFileToken.TableStyle:
211
                                                template = this.readTableEntry(new CadTableEntryTemplate<TextStyle>(new TextStyle()), this.readTextStyle);
941✔
212
                                                break;
941✔
213
                                        case DxfFileToken.TableUcs:
214
                                                template = this.readTableEntry(new CadUcsTemplate(), this.readUcs);
×
215
                                                break;
×
216
                                        case DxfFileToken.TableView:
217
                                                template = this.readTableEntry(new CadViewTemplate(), this.readView);
154✔
218
                                                break;
154✔
219
                                        case DxfFileToken.TableVport:
220
                                                template = this.readTableEntry(new CadVPortTemplate(), this.readVPort);
179✔
221
                                                break;
179✔
222
                                        default:
223
                                                Debug.Fail($"Unhandeled table {tableTemplate.CadObject.ObjectName}.");
×
224
                                                break;
×
225
                                }
226

227
                                //tableTemplate.EntryHandles.Add(template.CadObject.Handle);
228
                                tableTemplate.CadObject.Add((T)template.CadObject);
10,743✔
229

230
                                //Add the object and the template to the builder
231
                                this._builder.AddTemplate(template);
10,743✔
232
                        }
10,743✔
233
                }
1,567✔
234

235
                private CadTemplate readTableEntry<T>(CadTableEntryTemplate<T> template, ReadEntryDelegate<T> readEntry)
236
                        where T : TableEntry
237
                {
10,743✔
238
                        DxfMap map = DxfMap.Create<T>();
10,743✔
239

240
                        while (this._reader.DxfCode != DxfCode.Start)
129,309✔
241
                        {
118,566✔
242
                                if (!readEntry(template, map.SubClasses[template.CadObject.SubclassMarker]))
118,566✔
243
                                {
43,776✔
244
                                        this.readCommonTableEntryCodes(template, out bool isExtendedData, map);
43,776✔
245
                                        if (isExtendedData)
43,776✔
246
                                                continue;
3,177✔
247
                                }
40,599✔
248

249
                                if (this._reader.DxfCode != DxfCode.Start)
115,389✔
250
                                        this._reader.ReadNext();
114,619✔
251
                        }
115,389✔
252

253
                        return template;
10,743✔
254
                }
10,743✔
255

256
                private void readCommonTableEntryCodes<T>(CadTableEntryTemplate<T> template, out bool isExtendedData, DxfMap map = null)
257
                        where T : TableEntry
258
                {
43,776✔
259
                        isExtendedData = false;
43,776✔
260
                        switch (this._reader.Code)
43,776✔
261
                        {
262
                                case 2:
263
                                        template.CadObject.Name = this._reader.ValueAsString;
488✔
264
                                        break;
488✔
265
                                case 70:
266
                                        template.CadObject.Flags = (StandardFlags)this._reader.ValueAsUShort;
530✔
267
                                        break;
530✔
268
                                case 100:
269
                                        Debug.Assert(map.SubClasses.ContainsKey(this._reader.ValueAsString));
19,154✔
270
                                        break;
19,154✔
271
                                default:
272
                                        this.readCommonCodes(template, out isExtendedData, map);
23,604✔
273
                                        break;
23,604✔
274
                        }
275
                }
43,776✔
276

277
                private bool readAppId(CadTableEntryTemplate<AppId> template, DxfClassMap map)
278
                {
14,378✔
279
                        Debug.Assert(map.Name == DxfSubclassMarker.ApplicationId);
14,378✔
280

281
                        switch (this._reader.Code)
14,378✔
282
                        {
283
                                default:
284
                                        return this.tryAssignCurrentValue(template.CadObject, map);
14,378✔
285
                        }
286
                }
14,378✔
287

288
                private bool readBlockRecord(CadTableEntryTemplate<BlockRecord> template, DxfClassMap map)
289
                {
23,099✔
290
                        CadBlockRecordTemplate tmp = (CadBlockRecordTemplate)template;
23,099✔
291

292
                        switch (this._reader.Code)
23,099✔
293
                        {
294
                                case 340:
295
                                        tmp.LayoutHandle = this._reader.ValueAsHandle;
2,191✔
296
                                        return true;
2,191✔
297
                                default:
298
                                        return this.tryAssignCurrentValue(template.CadObject, map);
20,908✔
299
                        }
300
                }
23,099✔
301

302
                private bool readDimensionStyle(CadTableEntryTemplate<DimensionStyle> template, DxfClassMap map)
303
                {
9,690✔
304
                        Debug.Assert(map.Name == DxfSubclassMarker.DimensionStyle);
9,690✔
305

306
                        CadDimensionStyleTemplate tmp = (CadDimensionStyleTemplate)template;
9,690✔
307

308
                        switch (this._reader.Code)
9,690!
309
                        {
310
                                case 3:
311
                                        template.CadObject.PostFix = this._reader.ValueAsString;
78✔
312
                                        return true;
78✔
313
                                case 4:
314
                                        template.CadObject.AlternateDimensioningSuffix = this._reader.ValueAsString;
78✔
315
                                        return true;
78✔
316
                                case 5:
317
                                        //5        DIMBLK(obsolete, now object ID)
318
                                        tmp.DIMBL_Name = this._reader.ValueAsString;
66✔
319
                                        return true;
66✔
320
                                case 6:
321
                                        //6        DIMBLK1(obsolete, now object ID)
322
                                        tmp.DIMBLK1_Name = this._reader.ValueAsString;
66✔
323
                                        return true;
66✔
324
                                case 7:
325
                                        //7        DIMBLK2(obsolete, now object ID)
326
                                        tmp.DIMBLK2_Name = this._reader.ValueAsString;
66✔
327
                                        return true;
66✔
328
                                case 40:
329
                                        //Somethimes is 0 but it shouldn't be allowed
330
                                        template.CadObject.ScaleFactor = this._reader.ValueAsDouble <= 0 ? 1.0d : this._reader.ValueAsDouble;
223✔
331
                                        return true;
223✔
332
                                case 41:
333
                                        template.CadObject.ArrowSize = this._reader.ValueAsDouble;
210✔
334
                                        return true;
210✔
335
                                case 42:
336
                                        template.CadObject.ExtensionLineOffset = this._reader.ValueAsDouble;
210✔
337
                                        return true;
210✔
338
                                case 43:
339
                                        template.CadObject.DimensionLineIncrement = this._reader.ValueAsDouble;
210✔
340
                                        return true;
210✔
341
                                case 44:
342
                                        template.CadObject.ExtensionLineExtension = this._reader.ValueAsDouble;
210✔
343
                                        return true;
210✔
344
                                case 45:
345
                                        template.CadObject.Rounding = this._reader.ValueAsDouble;
78✔
346
                                        return true;
78✔
347
                                case 46:
348
                                        template.CadObject.DimensionLineExtension = this._reader.ValueAsDouble;
78✔
349
                                        return true;
78✔
350
                                case 47:
351
                                        template.CadObject.PlusTolerance = this._reader.ValueAsDouble;
78✔
352
                                        return true;
78✔
353
                                case 48:
354
                                        template.CadObject.MinusTolerance = this._reader.ValueAsDouble;
78✔
355
                                        return true;
78✔
356
                                case 49:
357
                                        template.CadObject.FixedExtensionLineLength = this._reader.ValueAsDouble;
12✔
358
                                        return true;
12✔
359
                                case 50:
360
                                        template.CadObject.JoggedRadiusDimensionTransverseSegmentAngle = CSMath.MathHelper.DegToRad(this._reader.ValueAsDouble);
12✔
361
                                        return true;
12✔
362
                                case 69:
363
                                        template.CadObject.TextBackgroundFillMode = (DimensionTextBackgroundFillMode)this._reader.ValueAsShort;
8✔
364
                                        return true;
8✔
365
                                case 71:
366
                                        template.CadObject.GenerateTolerances = this._reader.ValueAsBool;
78✔
367
                                        return true;
78✔
368
                                case 72:
369
                                        template.CadObject.LimitsGeneration = this._reader.ValueAsBool;
78✔
370
                                        return true;
78✔
371
                                case 73:
372
                                        template.CadObject.TextInsideHorizontal = this._reader.ValueAsBool;
210✔
373
                                        return true;
210✔
374
                                case 74:
375
                                        template.CadObject.TextOutsideHorizontal = this._reader.ValueAsBool;
210✔
376
                                        return true;
210✔
377
                                case 75:
378
                                        template.CadObject.SuppressFirstExtensionLine = this._reader.ValueAsBool;
78✔
379
                                        return true;
78✔
380
                                case 76:
381
                                        template.CadObject.SuppressSecondExtensionLine = this._reader.ValueAsBool;
78✔
382
                                        return true;
78✔
383
                                case 77:
384
                                        template.CadObject.TextVerticalAlignment = (DimensionTextVerticalAlignment)this._reader.ValueAsShort;
210✔
385
                                        return true;
210✔
386
                                case 78:
387
                                        template.CadObject.ZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
210✔
388
                                        return true;
210✔
389
                                case 79:
390
                                        template.CadObject.AngularZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
12✔
391
                                        return true;
12✔
392
                                case 90:
393
                                        template.CadObject.ArcLengthSymbolPosition = (ArcLengthSymbolPosition)(int)this._reader.ValueAsShort;
12✔
394
                                        return true;
12✔
395
                                case 105:
396
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
444✔
397
                                        return true;
444✔
398
                                case 140:
399
                                        template.CadObject.TextHeight = this._reader.ValueAsDouble;
210✔
400
                                        return true;
210✔
401
                                case 141:
402
                                        template.CadObject.CenterMarkSize = this._reader.ValueAsDouble;
210✔
403
                                        return true;
210✔
404
                                case 142:
405
                                        template.CadObject.TickSize = this._reader.ValueAsDouble;
78✔
406
                                        return true;
78✔
407
                                case 143:
408
                                        template.CadObject.AlternateUnitScaleFactor = this._reader.ValueAsDouble;
210✔
409
                                        return true;
210✔
410
                                case 144:
411
                                        template.CadObject.LinearScaleFactor = this._reader.ValueAsDouble;
78✔
412
                                        return true;
78✔
413
                                case 145:
414
                                        template.CadObject.TextVerticalPosition = this._reader.ValueAsDouble;
78✔
415
                                        return true;
78✔
416
                                case 146:
417
                                        template.CadObject.ToleranceScaleFactor = this._reader.ValueAsDouble;
78✔
418
                                        return true;
78✔
419
                                case 147:
420
                                        template.CadObject.DimensionLineGap = this._reader.ValueAsDouble;
210✔
421
                                        return true;
210✔
422
                                case 148:
423
                                        template.CadObject.AlternateUnitRounding = this._reader.ValueAsDouble;
12✔
424
                                        return true;
12✔
425
                                case 170:
426
                                        template.CadObject.AlternateUnitDimensioning = this._reader.ValueAsBool;
78✔
427
                                        return true;
78✔
428
                                case 171:
429
                                        template.CadObject.AlternateUnitDecimalPlaces = this._reader.ValueAsShort;
210✔
430
                                        return true;
210✔
431
                                case 172:
432
                                        template.CadObject.TextOutsideExtensions = this._reader.ValueAsBool;
210✔
433
                                        return true;
210✔
434
                                case 173:
435
                                        template.CadObject.SeparateArrowBlocks = this._reader.ValueAsBool;
78✔
436
                                        return true;
78✔
437
                                case 174:
438
                                        template.CadObject.TextInsideExtensions = this._reader.ValueAsBool;
78✔
439
                                        return true;
78✔
440
                                case 175:
441
                                        template.CadObject.SuppressOutsideExtensions = this._reader.ValueAsBool;
78✔
442
                                        return true;
78✔
443
                                case 176:
444
                                        template.CadObject.DimensionLineColor = new Color(this._reader.ValueAsShort);
88✔
445
                                        return true;
88✔
446
                                case 177:
447
                                        template.CadObject.ExtensionLineColor = new Color(this._reader.ValueAsShort);
88✔
448
                                        return true;
88✔
449
                                case 178:
450
                                        template.CadObject.TextColor = new Color(this._reader.ValueAsShort);
88✔
451
                                        return true;
88✔
452
                                case 179:
453
                                        template.CadObject.AngularDimensionDecimalPlaces = this._reader.ValueAsShort;
12✔
454
                                        return true;
12✔
455
                                case 270:
456
                                        template.CadObject.LinearUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
×
457
                                        return true;
×
458
                                case 271:
459
                                        template.CadObject.DecimalPlaces = this._reader.ValueAsShort;
144✔
460
                                        return true;
144✔
461
                                case 272:
462
                                        template.CadObject.ToleranceDecimalPlaces = this._reader.ValueAsShort;
144✔
463
                                        return true;
144✔
464
                                case 273:
465
                                        template.CadObject.AlternateUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
12✔
466
                                        return true;
12✔
467
                                case 274:
468
                                        template.CadObject.AlternateUnitToleranceDecimalPlaces = this._reader.ValueAsShort;
144✔
469
                                        return true;
144✔
470
                                case 275:
471
                                        template.CadObject.AngularUnit = (AngularUnitFormat)this._reader.ValueAsShort;
12✔
472
                                        return true;
12✔
473
                                case 276:
474
                                        template.CadObject.FractionFormat = (FractionFormat)this._reader.ValueAsShort;
12✔
475
                                        return true;
12✔
476
                                case 277:
477
                                        template.CadObject.LinearUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
12✔
478
                                        return true;
12✔
479
                                case 278:
480
                                        template.CadObject.DecimalSeparator = (char)this._reader.ValueAsShort;
144✔
481
                                        return true;
144✔
482
                                case 279:
483
                                        template.CadObject.TextMovement = (TextMovement)this._reader.ValueAsShort;
12✔
484
                                        return true;
12✔
485
                                case 280:
486
                                        template.CadObject.TextHorizontalAlignment = (DimensionTextHorizontalAlignment)this._reader.ValueAsShort;
12✔
487
                                        return true;
12✔
488
                                case 281:
489
                                        template.CadObject.SuppressFirstDimensionLine = this._reader.ValueAsBool;
12✔
490
                                        return true;
12✔
491
                                case 282:
492
                                        template.CadObject.SuppressSecondDimensionLine = this._reader.ValueAsBool;
12✔
493
                                        return true;
12✔
494
                                case 283:
495
                                        template.CadObject.ToleranceAlignment = (ToleranceAlignment)this._reader.ValueAsShort;
144✔
496
                                        return true;
144✔
497
                                case 284:
498
                                        template.CadObject.ToleranceZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
144✔
499
                                        return true;
144✔
500
                                case 285:
501
                                        template.CadObject.AlternateUnitZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
12✔
502
                                        return true;
12✔
503
                                case 286:
504
                                        template.CadObject.AlternateUnitToleranceZeroHandling = (ZeroHandling)(byte)this._reader.ValueAsShort;
12✔
505
                                        return true;
12✔
506
                                case 287:
507
                                        template.CadObject.DimensionFit = this._reader.ValueAsShort;
12✔
508
                                        return true;
12✔
509
                                case 288:
510
                                        template.CadObject.CursorUpdate = this._reader.ValueAsBool;
12✔
511
                                        return true;
12✔
512
                                case 289:
513
                                        template.CadObject.DimensionTextArrowFit = (TextArrowFitType)this._reader.ValueAsShort;
12✔
514
                                        return true;
12✔
515
                                case 290:
516
                                        template.CadObject.IsExtensionLineLengthFixed = this._reader.ValueAsBool;
12✔
517
                                        return true;
12✔
518
                                case 340:
519
                                        tmp.TextStyleHandle = this._reader.ValueAsHandle;
444✔
520
                                        return true;
444✔
521
                                case 341:
522
                                        tmp.DIMLDRBLK = this._reader.ValueAsHandle;
×
523
                                        return true;
×
524
                                case 342:
525
                                        tmp.DIMBLK = this._reader.ValueAsHandle;
×
526
                                        return true;
×
527
                                case 343:
528
                                        tmp.DIMBLK1 = this._reader.ValueAsHandle;
×
529
                                        return true;
×
530
                                case 344:
531
                                        tmp.DIMBLK2 = this._reader.ValueAsHandle;
×
532
                                        return true;
×
533
                                case 371:
534
                                        template.CadObject.DimensionLineWeight = (LineweightType)this._reader.ValueAsShort;
12✔
535
                                        return true;
12✔
536
                                case 372:
537
                                        template.CadObject.ExtensionLineWeight = (LineweightType)this._reader.ValueAsShort;
12✔
538
                                        return true;
12✔
539
                                default:
540
                                        return false;
2,637✔
541
                        }
542
                }
9,690✔
543

544
                private bool readLayer(CadTableEntryTemplate<Layer> template, DxfClassMap map)
545
                {
31,387✔
546
                        Debug.Assert(map.Name == DxfSubclassMarker.Layer);
31,387✔
547

548
                        CadLayerTemplate tmp = (CadLayerTemplate)template;
31,387✔
549

550
                        switch (this._reader.Code)
31,387✔
551
                        {
552
                                case 6:
553
                                        tmp.LineTypeName = this._reader.ValueAsString;
2,841✔
554
                                        return true;
2,841✔
555
                                case 62:
556
                                        short index = this._reader.ValueAsShort;
2,841✔
557
                                        if (index < 0)
2,841✔
558
                                        {
154✔
559
                                                template.CadObject.IsOn = false;
154✔
560
                                                index = Math.Abs(index);
154✔
561
                                        }
154✔
562
                                        template.CadObject.Color = new Color(index);
2,841✔
563
                                        return true;
2,841✔
564
                                case 347:
565
                                        tmp.MaterialHandle = this._reader.ValueAsHandle;
1,569✔
566
                                        return true;
1,569✔
567
                                case 348:
568
                                        //Unknown code value, always 0
569
                                        return true;
765✔
570
                                case 390:
571
                                        template.CadObject.PlotStyleName = this._reader.ValueAsHandle;
2,423✔
572
                                        return true;
2,423✔
573
                                case 430:
574
                                        tmp.TrueColorName = this._reader.ValueAsString;
118✔
575
                                        return true;
118✔
576
                                default:
577
                                        return this.tryAssignCurrentValue(template.CadObject, map);
20,830✔
578
                        }
579
                }
31,387✔
580

581
                private bool readLineType(CadTableEntryTemplate<LineType> template, DxfClassMap map)
582
                {
12,902✔
583
                        Debug.Assert(map.Name == DxfSubclassMarker.Linetype);
12,902✔
584

585
                        CadLineTypeTemplate tmp = (CadLineTypeTemplate)template;
12,902✔
586

587
                        switch (this._reader.Code)
12,902✔
588
                        {
589
                                case 40:
590
                                        tmp.TotalLen = this._reader.ValueAsDouble;
1,263✔
591
                                        return true;
1,263✔
592
                                case 49:
593
                                        do
594
                                        {
2,310✔
595
                                                tmp.SegmentTemplates.Add(this.readLineTypeSegment());
2,310✔
596
                                        }
2,310✔
597
                                        while (this._reader.Code == 49);
2,310✔
598
                                        return true;
770✔
599
                                case 73:
600
                                        //number of segments
601
                                        return true;
1,263✔
602
                                default:
603
                                        return this.tryAssignCurrentValue(template.CadObject, map);
9,606✔
604
                        }
605
                }
12,902✔
606

607
                private SegmentTemplate readLineTypeSegment()
608
                {
2,310✔
609
                        SegmentTemplate template = new SegmentTemplate();
2,310✔
610
                        template.Segment.Length = this._reader.ValueAsDouble;
2,310✔
611

612
                        //Jump the 49 code
613
                        this._reader.ReadNext();
2,310✔
614

615
                        while (this._reader.Code != 49 && this._reader.Code != 0)
9,174✔
616
                        {
6,864✔
617
                                switch (this._reader.Code)
6,864!
618
                                {
619
                                        case 9:
620
                                                template.Segment.Text = this._reader.ValueAsString;
132✔
621
                                                break;
132✔
622
                                        case 44:
623
                                                template.Segment.Offset = new CSMath.XY(this._reader.ValueAsDouble, template.Segment.Offset.Y);
792✔
624
                                                break;
792✔
625
                                        case 45:
626
                                                template.Segment.Offset = new CSMath.XY(template.Segment.Offset.X, this._reader.ValueAsDouble);
792✔
627
                                                break;
792✔
628
                                        case 46:
629
                                                template.Segment.Scale = this._reader.ValueAsDouble;
792✔
630
                                                break;
792✔
631
                                        case 50:
632
                                                template.Segment.Rotation = this._reader.ValueAsAngle;
792✔
633
                                                break;
792✔
634
                                        case 74:
635
                                                template.Segment.Shapeflag = (LinetypeShapeFlags)this._reader.ValueAsUShort;
1,980✔
636
                                                break;
1,980✔
637
                                        case 75:
638
                                                template.Segment.ShapeNumber = (short)this._reader.ValueAsInt;
792✔
639
                                                break;
792✔
640
                                        case 340:
641
                                                break;
792✔
642
                                        default:
643
                                                this._builder.Notify($"[LineTypeSegment] Unhandeled dxf code {this._reader.Code} with value {this._reader.ValueAsString}, positon {this._reader.Position}", NotificationType.None);
×
644
                                                break;
×
645
                                }
646

647
                                this._reader.ReadNext();
6,864✔
648
                        }
6,864✔
649

650
                        return template;
2,310✔
651
                }
2,310✔
652

653
                private bool readTextStyle(CadTableEntryTemplate<TextStyle> template, DxfClassMap map)
654
                {
12,302✔
655
                        Debug.Assert(map.Name == DxfSubclassMarker.TextStyle);
12,302✔
656

657
                        switch (this._reader.Code)
12,302✔
658
                        {
659
                                case 2:
660
                                        if (!this._reader.ValueAsString.IsNullOrEmpty())
919✔
661
                                        {
633✔
662
                                                //In some files the TextStyle is an empty string
663
                                                template.CadObject.Name = this._reader.ValueAsString;
633✔
664
                                        }
633✔
665
                                        return true;
919✔
666
                                default:
667
                                        return this.tryAssignCurrentValue(template.CadObject, map);
11,383✔
668
                        }
669
                }
12,302✔
670

671
                private bool readUcs(CadTableEntryTemplate<UCS> template, DxfClassMap map)
672
                {
×
673
                        Debug.Assert(map.Name == DxfSubclassMarker.Ucs);
×
674

675
                        switch (this._reader.Code)
×
676
                        {
677
                                default:
678
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
679
                        }
680
                }
×
681

682
                private bool readView(CadTableEntryTemplate<View> template, DxfClassMap map)
683
                {
5,148✔
684
                        Debug.Assert(map.Name == DxfSubclassMarker.View);
5,148✔
685

686
                        CadViewTemplate tmp = template as CadViewTemplate;
5,148✔
687

688
                        switch (this._reader.Code)
5,148✔
689
                        {
690
                                case 348:
691
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
88✔
692
                                        return true;
88✔
693
                                default:
694
                                        return this.tryAssignCurrentValue(template.CadObject, map);
5,060✔
695
                        }
696
                }
5,148✔
697

698
                private bool readVPort(CadTableEntryTemplate<VPort> template, DxfClassMap map)
699
                {
9,660✔
700
                        Debug.Assert(map.Name == DxfSubclassMarker.VPort);
9,660✔
701

702
                        CadVPortTemplate tmp = template as CadVPortTemplate;
9,660✔
703

704
                        switch (this._reader.Code)
9,660✔
705
                        {
706
                                //NOTE: Undocumented codes
707
                                case 65:
708
                                case 73:
709
                                        return true;
312✔
710
                                case 348:
711
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
99✔
712
                                        return true;
99✔
713
                                default:
714
                                        return this.tryAssignCurrentValue(template.CadObject, map);
9,249✔
715
                        }
716
                }
9,660✔
717
        }
718
}
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