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

DomCR / ACadSharp / 10438237818

18 Aug 2024 05:48AM UTC coverage: 75.966% (+0.08%) from 75.891%
10438237818

push

github

web-flow
Merge pull request #425 from DomCR/Issue-421_dxf-irregular-no-header

Issue-421_dxf-irregular-no-header

4815 of 7003 branches covered (68.76%)

Branch coverage included in aggregate %.

16 of 33 new or added lines in 9 files covered. (48.48%)

19 existing lines in 6 files now uncovered.

19217 of 24632 relevant lines covered (78.02%)

33169.42 hits per line

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

90.53
/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 CSMath;
7
using CSUtilities.Extensions;
8
using System;
9
using System.Collections.Generic;
10
using System.Diagnostics;
11
using static ACadSharp.IO.Templates.CadLineTypeTemplate;
12

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

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

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

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

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

38

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

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

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

53
                        int nentries = 0;
1,224✔
54
                        CadTemplate template = null;
1,224✔
55
                        Dictionary<string, ExtendedData> edata = new Dictionary<string, ExtendedData>();
1,224✔
56

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

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

88
                                        if (this._reader.DxfCode == DxfCode.Start)
2,379✔
89
                                                break;
219✔
90

91
                                        this._reader.ReadNext();
2,160✔
92
                                }
2,160✔
93
                        }
1,080✔
94
                        else if(this._reader.ValueAsString == DxfFileToken.EndTable)
144✔
95
                        {
18✔
96
                                return;
18✔
97
                        }
98
                        else
99
                        {
126✔
100
                                this._reader.ReadNext();
126✔
101
                        }
126✔
102

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

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

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

170
                        //Add the object and the template to the builder
171
                        this._builder.AddTemplate(template);
1,206✔
172
                }
1,224✔
173

174
                private void readEntries<T>(CadTableTemplate<T> tableTemplate)
175
                        where T : TableEntry
176
                {
1,206✔
177
                        //Read all the entries until the end of the table
178
                        while (this._reader.ValueAsString != DxfFileToken.EndTable)
9,714✔
179
                        {
8,508✔
180
                                this._reader.ReadNext();
8,508✔
181

182
                                CadTemplate template = null;
8,508✔
183

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

194
                                                if (block.CadObject.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
1,752✔
195
                                                {
120✔
196
                                                        this._builder.ModelSpaceTemplate = block;
120✔
197
                                                }
120✔
198

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

226
                                //tableTemplate.EntryHandles.Add(template.CadObject.Handle);
227
                                tableTemplate.CadObject.Add((T)template.CadObject);
8,508✔
228

229
                                //Add the object and the template to the builder
230
                                this._builder.AddTemplate(template);
8,508✔
231
                        }
8,508✔
232
                }
1,206✔
233

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

239
                        while (this._reader.DxfCode != DxfCode.Start)
102,702✔
240
                        {
94,194✔
241
                                if (!readEntry(template, map.SubClasses[template.CadObject.SubclassMarker]))
94,194✔
242
                                {
34,542✔
243
                                        this.readCommonTableEntryCodes(template, out bool isExtendedData, map);
34,542✔
244
                                        if (isExtendedData)
34,542✔
245
                                                continue;
2,520✔
246
                                }
32,022✔
247

248
                                if (this._reader.DxfCode != DxfCode.Start)
91,674✔
249
                                        this._reader.ReadNext();
91,044✔
250
                        }
91,674✔
251

252
                        return template;
8,508✔
253
                }
8,508✔
254

255
                private void readCommonTableEntryCodes<T>(CadTableEntryTemplate<T> template, out bool isExtendedData, DxfMap map = null)
256
                        where T : TableEntry
257
                {
34,542✔
258
                        isExtendedData = false;
34,542✔
259
                        switch (this._reader.Code)
34,542✔
260
                        {
261
                                case 2:
262
                                        template.CadObject.Name = this._reader.ValueAsString;
372✔
263
                                        break;
372✔
264
                                case 70:
265
                                        template.CadObject.Flags = (StandardFlags)this._reader.ValueAsUShort;
402✔
266
                                        break;
402✔
267
                                case 100:
268
                                        Debug.Assert(map.SubClasses.ContainsKey(this._reader.ValueAsString));
15,108✔
269
                                        break;
15,108✔
270
                                default:
271
                                        this.readCommonCodes(template, out isExtendedData, map);
18,660✔
272
                                        break;
18,660✔
273
                        }
274
                }
34,542✔
275

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

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

287
                private bool readBlockRecord(CadTableEntryTemplate<BlockRecord> template, DxfClassMap map)
288
                {
18,480✔
289
                        CadBlockRecordTemplate tmp = (CadBlockRecordTemplate)template;
18,480✔
290

291
                        switch (this._reader.Code)
18,480✔
292
                        {
293
                                case 340:
294
                                        tmp.LayoutHandle = this._reader.ValueAsHandle;
1,752✔
295
                                        return true;
1,752✔
296
                                default:
297
                                        return this.tryAssignCurrentValue(template.CadObject, map);
16,728✔
298
                        }
299
                }
18,480✔
300

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

305
                        CadDimensionStyleTemplate tmp = (CadDimensionStyleTemplate)template;
7,812✔
306

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

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

547
                        CadLayerTemplate tmp = (CadLayerTemplate)template;
25,332✔
548

549
                        switch (this._reader.Code)
25,332✔
550
                        {
551
                                case 6:
552
                                        tmp.LineTypeName = this._reader.ValueAsString;
2,298✔
553
                                        return true;
2,298✔
554
                                case 62:
555
                                        short index = this._reader.ValueAsShort;
2,298✔
556
                                        if (index < 0)
2,298✔
557
                                        {
126✔
558
                                                template.CadObject.IsOn = false;
126✔
559
                                                index = Math.Abs(index);
126✔
560
                                        }
126✔
561
                                        template.CadObject.Color = new Color(index);
2,298✔
562
                                        return true;
2,298✔
563
                                case 347:
564
                                        tmp.MaterialHandle = this._reader.ValueAsHandle;
1,260✔
565
                                        return true;
1,260✔
566
                                case 348:
567
                                        //Unknown code value, always 0
568
                                        return true;
612✔
569
                                case 390:
570
                                        template.CadObject.PlotStyleName = this._reader.ValueAsHandle;
1,956✔
571
                                        return true;
1,956✔
572
                                case 420:
573
                                        template.CadObject.Color = Color.FromTrueColor((uint)this._reader.ValueAsInt);
180✔
574
                                        return true;
180✔
575
                                case 430:
576
                                        tmp.TrueColorName = this._reader.ValueAsString;
90✔
577
                                        return true;
90✔
578
                                default:
579
                                        return this.tryAssignCurrentValue(template.CadObject, map);
16,638✔
580
                        }
581
                }
25,332✔
582

583
                private bool readLineType(CadTableEntryTemplate<LineType> template, DxfClassMap map)
584
                {
10,296✔
585
                        Debug.Assert(map.Name == DxfSubclassMarker.Linetype);
10,296✔
586

587
                        CadLineTypeTemplate tmp = (CadLineTypeTemplate)template;
10,296✔
588

589
                        switch (this._reader.Code)
10,296✔
590
                        {
591
                                case 40:
592
                                        tmp.TotalLen = this._reader.ValueAsDouble;
1,008✔
593
                                        return true;
1,008✔
594
                                case 49:
595
                                        do
596
                                        {
1,890✔
597
                                                tmp.SegmentTemplates.Add(this.readLineTypeSegment());
1,890✔
598
                                        }
1,890✔
599
                                        while (this._reader.Code == 49);
1,890✔
600
                                        return true;
630✔
601
                                case 73:
602
                                        //number of segments
603
                                        return true;
1,008✔
604
                                default:
605
                                        return this.tryAssignCurrentValue(template.CadObject, map);
7,650✔
606
                        }
607
                }
10,296✔
608

609
                private SegmentTemplate readLineTypeSegment()
610
                {
1,890✔
611
                        SegmentTemplate template = new SegmentTemplate();
1,890✔
612
                        template.Segment.Length = this._reader.ValueAsDouble;
1,890✔
613

614
                        //Jump the 49 code
615
                        this._reader.ReadNext();
1,890✔
616

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

649
                                this._reader.ReadNext();
5,616✔
650
                        }
5,616✔
651

652
                        return template;
1,890✔
653
                }
1,890✔
654

655
                private bool readTextStyle(CadTableEntryTemplate<TextStyle> template, DxfClassMap map)
656
                {
9,780✔
657
                        Debug.Assert(map.Name == DxfSubclassMarker.TextStyle);
9,780✔
658

659
                        switch (this._reader.Code)
9,780✔
660
                        {
661
                                case 2:
662
                                        if (!this._reader.ValueAsString.IsNullOrEmpty())
732✔
663
                                        {
498✔
664
                                                //In some files the TextStyle is an empty string
665
                                                template.CadObject.Name = this._reader.ValueAsString;
498✔
666
                                        }
498✔
667
                                        return true;
732✔
668
                                default:
669
                                        return this.tryAssignCurrentValue(template.CadObject, map);
9,048✔
670
                        }
671
                }
9,780✔
672

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

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

684
                private bool readView(CadTableEntryTemplate<View> template, DxfClassMap map)
685
                {
4,212✔
686
                        Debug.Assert(map.Name == DxfSubclassMarker.View);
4,212✔
687

688
                        CadViewTemplate tmp = template as CadViewTemplate;
4,212✔
689

690
                        switch (this._reader.Code)
4,212✔
691
                        {
692
                                case 348:
693
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
72✔
694
                                        return true;
72✔
695
                                default:
696
                                        return this.tryAssignCurrentValue(template.CadObject, map);
4,140✔
697
                        }
698
                }
4,212✔
699

700
                private bool readVPort(CadTableEntryTemplate<VPort> template, DxfClassMap map)
701
                {
7,320✔
702
                        Debug.Assert(map.Name == DxfSubclassMarker.VPort);
7,320✔
703

704
                        CadVPortTemplate tmp = template as CadVPortTemplate;
7,320✔
705

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