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

DomCR / ACadSharp / 20848017817

09 Jan 2026 09:53AM UTC coverage: 77.151% (-0.06%) from 77.208%
20848017817

Pull #941

github

web-flow
Merge 4fec70e6d into fd9200aa7
Pull Request #941: issue 940

7906 of 11099 branches covered (71.23%)

Branch coverage included in aggregate %.

4 of 17 new or added lines in 1 file covered. (23.53%)

7 existing lines in 2 files now uncovered.

28788 of 36462 relevant lines covered (78.95%)

149666.61 hits per line

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

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

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

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

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

31
                        //Loop until the section ends
32
                        while (this._reader.ValueAsString != DxfFileToken.EndSection)
2,486✔
33
                        {
2,234✔
34

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

40

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

48
                private void readTable()
49
                {
2,234✔
50
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.TableEntry);
2,234✔
51

52
                        //Read the table name
53
                        this._reader.ReadNext();
2,234✔
54

55
                        int nentries = 0;
2,234✔
56
                        CadTemplate template = null;
2,234✔
57
                        Dictionary<string, List<ExtendedDataRecord>> edata = new();
2,234✔
58

59
                        this.readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out HashSet<ulong> reactors);
2,234✔
60

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

90
                                        if (this._reader.DxfCode == DxfCode.Start)
4,327✔
91
                                                break;
403✔
92

93
                                        this._reader.ReadNext();
3,924✔
94
                                }
3,924✔
95
                        }
1,962✔
96
                        else if (this._reader.ValueAsString == DxfFileToken.EndTable)
272✔
97
                        {
34✔
98
                                return;
34✔
99
                        }
100
                        else
101
                        {
238✔
102
                                this._reader.ReadNext();
238✔
103
                        }
238✔
104

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

165
                        Debug.Assert(ownerHandle == null || ownerHandle.Value == 0);
2,200✔
166

167
                        template.OwnerHandle = ownerHandle;
2,200✔
168
                        template.XDictHandle = xdictHandle;
2,200✔
169
                        template.ReactorsHandles = reactors;
2,200✔
170
                        template.EDataTemplateByAppName = edata;
2,200✔
171

172
                        //Add the object and the template to the builder
173
                        this._builder.AddTemplate(template);
2,200✔
174
                }
2,234✔
175

176
                private void readEntries<T>(CadTableTemplate<T> tableTemplate)
177
                        where T : TableEntry
178
                {
2,200✔
179
                        //Read all the entries until the end of the table
180
                        while (this._reader.ValueAsString != DxfFileToken.EndTable)
26,634✔
181
                        {
24,434✔
182
                                this._reader.ReadNext();
24,434✔
183

184
                                ICadTableEntryTemplate template = null;
24,434✔
185

186
                                //Get the entry
187
                                switch (tableTemplate.CadObject.ObjectName)
24,434!
188
                                {
189
                                        case DxfFileToken.TableAppId:
190
                                                template = this.readTableEntry(new CadTableEntryTemplate<AppId>(new AppId()), this.readAppId);
8,832✔
191
                                                break;
8,832✔
192
                                        case DxfFileToken.TableBlockRecord:
193
                                                CadBlockRecordTemplate block = new CadBlockRecordTemplate();
5,538✔
194
                                                template = this.readTableEntry(block, this.readBlockRecord);
5,538✔
195

196
                                                if (block.CadObject.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
5,538✔
197
                                                {
218✔
198
                                                        this._builder.ModelSpaceTemplate = block;
218✔
199
                                                }
218✔
200

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

228

229
                                if (tableTemplate.CadObject.Contains(template.Name) && this._builder.Configuration.Failsafe)
24,434!
230
                                {
×
231
                                        this._builder.Notify($"Duplicated entry with name {template.Name} found in {template.CadObject.ObjectName}", NotificationType.Warning);
×
232

233
                                        tableTemplate.CadObject.Remove(template.Name);
×
234
                                        tableTemplate.CadObject.Add((T)template.CadObject);
×
235
                                }
×
236
                                else
237
                                {
24,434✔
238
                                        tableTemplate.CadObject.Add((T)template.CadObject);
24,434✔
239
                                }
24,434✔
240

241
                                //Add the object and the template to the builder
242
                                this._builder.AddTemplate(template);
24,434✔
243
                        }
24,434✔
244
                }
2,200✔
245

246
                private ICadTableEntryTemplate readTableEntry<T>(CadTableEntryTemplate<T> template, ReadEntryDelegate<T> readEntry)
247
                        where T : TableEntry
248
                {
24,434✔
249
                        DxfMap map = DxfMap.Create<T>();
24,434✔
250

251
                        while (this._reader.DxfCode != DxfCode.Start)
277,011✔
252
                        {
252,577✔
253
                                if (!readEntry(template, map.SubClasses[template.CadObject.SubclassMarker]))
252,577✔
254
                                {
98,670✔
255
                                        this.readCommonTableEntryCodes(template, out bool isExtendedData, map);
98,670✔
256
                                        if (isExtendedData)
98,670✔
257
                                                continue;
6,468✔
258
                                }
92,202✔
259

260
                                if (this._reader.DxfCode != DxfCode.Start)
246,109✔
261
                                        this._reader.ReadNext();
244,919✔
262
                        }
246,109✔
263

264
                        return template;
24,434✔
265
                }
24,434✔
266

267
                private void readCommonTableEntryCodes<T>(CadTableEntryTemplate<T> template, out bool isExtendedData, DxfMap map = null)
268
                        where T : TableEntry
269
                {
98,670✔
270
                        isExtendedData = false;
98,670✔
271
                        switch (this._reader.Code)
98,670!
272
                        {
273
                                case 2:
274
                                        template.CadObject.Name = this._reader.ValueAsString;
1,410✔
275
                                        break;
1,410✔
276
                                case 70:
277
                                        template.CadObject.Flags = (StandardFlags)this._reader.ValueAsUShort;
×
278
                                        break;
×
279
                                case 100:
280
                                        Debug.Assert(map.SubClasses.ContainsKey(this._reader.ValueAsString));
43,496✔
281
                                        break;
43,496✔
282
                                default:
283
                                        this.readCommonCodes(template, out isExtendedData, map);
53,764✔
284
                                        break;
53,764✔
285
                        }
286
                }
98,670✔
287

288
                private bool readAppId(CadTableEntryTemplate<AppId> template, DxfClassMap map)
289
                {
47,790✔
290
                        Debug.Assert(map.Name == DxfSubclassMarker.ApplicationId);
47,790✔
291

292
                        switch (this._reader.Code)
47,790✔
293
                        {
294
                                default:
295
                                        return this.tryAssignCurrentValue(template.CadObject, map);
47,790✔
296
                        }
297
                }
47,790✔
298

299
                private bool readBlockRecord(CadTableEntryTemplate<BlockRecord> template, DxfClassMap map)
300
                {
62,244✔
301
                        CadBlockRecordTemplate tmp = (CadBlockRecordTemplate)template;
62,244✔
302

303
                        switch (this._reader.Code)
62,244✔
304
                        {
305
                                case 340:
306
                                        tmp.LayoutHandle = this._reader.ValueAsHandle;
5,538✔
307
                                        return true;
5,538✔
308
                                default:
309
                                        return this.tryAssignCurrentValue(template.CadObject, map);
56,706✔
310
                        }
311
                }
62,244✔
312

313
                private bool readDimensionStyle(CadTableEntryTemplate<DimensionStyle> template, DxfClassMap map)
314
                {
29,898✔
315
                        Debug.Assert(map.Name == DxfSubclassMarker.DimensionStyle);
29,898✔
316

317
                        CadDimensionStyleTemplate tmp = (CadDimensionStyleTemplate)template;
29,898✔
318

319
                        switch (this._reader.Code)
29,898!
320
                        {
321
                                case 3:
322
                                        template.CadObject.PostFix = this._reader.ValueAsString;
216✔
323
                                        return true;
216✔
324
                                case 4:
325
                                        template.CadObject.AlternateDimensioningSuffix = this._reader.ValueAsString;
216✔
326
                                        return true;
216✔
327
                                case 5:
328
                                        //5        DIMBLK(obsolete, now object ID)
329
                                        tmp.DIMBL_Name = this._reader.ValueAsString;
204✔
330
                                        return true;
204✔
331
                                case 6:
332
                                        //6        DIMBLK1(obsolete, now object ID)
333
                                        tmp.DIMBLK1_Name = this._reader.ValueAsString;
204✔
334
                                        return true;
204✔
335
                                case 7:
336
                                        //7        DIMBLK2(obsolete, now object ID)
337
                                        tmp.DIMBLK2_Name = this._reader.ValueAsString;
204✔
338
                                        return true;
204✔
339
                                case 40:
340
                                        if (!Try.Do(() => template.CadObject.ScaleFactor = this._reader.ValueAsDouble, out Exception ex))
1,252!
NEW
341
                                        {
×
NEW
342
                                                template.CadObject.ScaleFactor = MathHelper.Epsilon;
×
NEW
343
                                                this._builder.Notify($"[{template.CadObject.SubclassMarker}] Assignation error for {nameof(DimensionStyle.ScaleFactor)}.", NotificationType.Warning, ex);
×
NEW
344
                                        }
×
345
                                        return true;
626✔
346
                                case 41:
347
                                        if (!Try.Do(() => template.CadObject.ArrowSize = this._reader.ValueAsDouble, out ex))
1,248!
NEW
348
                                        {
×
NEW
349
                                                this._builder.Notify($"[{template.CadObject.SubclassMarker}] Assignation error for {nameof(DimensionStyle.ArrowSize)}.", NotificationType.Warning, ex);
×
NEW
350
                                        }
×
351
                                        return true;
624✔
352
                                case 42:
353
                                        template.CadObject.ExtensionLineOffset = this._reader.ValueAsDouble;
624✔
354
                                        return true;
624✔
355
                                case 43:
356
                                        template.CadObject.DimensionLineIncrement = this._reader.ValueAsDouble;
624✔
357
                                        return true;
624✔
358
                                case 44:
359
                                        template.CadObject.ExtensionLineExtension = this._reader.ValueAsDouble;
624✔
360
                                        return true;
624✔
361
                                case 45:
362
                                        template.CadObject.Rounding = this._reader.ValueAsDouble;
216✔
363
                                        return true;
216✔
364
                                case 46:
365
                                        template.CadObject.DimensionLineExtension = this._reader.ValueAsDouble;
216✔
366
                                        return true;
216✔
367
                                case 47:
368
                                        template.CadObject.PlusTolerance = this._reader.ValueAsDouble;
216✔
369
                                        return true;
216✔
370
                                case 48:
371
                                        template.CadObject.MinusTolerance = this._reader.ValueAsDouble;
216✔
372
                                        return true;
216✔
373
                                case 49:
374
                                        template.CadObject.FixedExtensionLineLength = this._reader.ValueAsDouble;
12✔
375
                                        return true;
12✔
376
                                case 50:
377
                                        if (!Try.Do(() => template.CadObject.JoggedRadiusDimensionTransverseSegmentAngle = this._reader.ValueAsAngle, out ex))
24!
NEW
378
                                        {
×
NEW
379
                                                this._builder.Notify($"[{template.CadObject.SubclassMarker}] Assignation error for {nameof(DimensionStyle.JoggedRadiusDimensionTransverseSegmentAngle)}.", NotificationType.Warning, ex);
×
NEW
380
                                        }
×
381
                                        return true;
12✔
382
                                case 69:
383
                                        template.CadObject.TextBackgroundFillMode = (DimensionTextBackgroundFillMode)this._reader.ValueAsShort;
136✔
384
                                        return true;
136✔
385
                                case 70:
386
                                        if (!tmp.DxfFlagsAssigned)
1,592✔
387
                                        {
1,444✔
388
                                                tmp.DxfFlagsAssigned = true;
1,444✔
389
                                                return true;
1,444✔
390
                                        }
391
                                        else if (this._reader.ValueAsShort >= 0)
148✔
392
                                        {
148✔
393
                                                template.CadObject.TextBackgroundColor = new Color(this._reader.ValueAsShort);
148✔
394
                                        }
148✔
395
                                        return true;
148✔
396
                                case 71:
397
                                        template.CadObject.GenerateTolerances = this._reader.ValueAsBool;
216✔
398
                                        return true;
216✔
399
                                case 72:
400
                                        template.CadObject.LimitsGeneration = this._reader.ValueAsBool;
216✔
401
                                        return true;
216✔
402
                                case 73:
403
                                        template.CadObject.TextInsideHorizontal = this._reader.ValueAsBool;
624✔
404
                                        return true;
624✔
405
                                case 74:
406
                                        template.CadObject.TextOutsideHorizontal = this._reader.ValueAsBool;
624✔
407
                                        return true;
624✔
408
                                case 75:
409
                                        template.CadObject.SuppressFirstExtensionLine = this._reader.ValueAsBool;
216✔
410
                                        return true;
216✔
411
                                case 76:
412
                                        template.CadObject.SuppressSecondExtensionLine = this._reader.ValueAsBool;
216✔
413
                                        return true;
216✔
414
                                case 77:
415
                                        template.CadObject.TextVerticalAlignment = (DimensionTextVerticalAlignment)this._reader.ValueAsShort;
624✔
416
                                        return true;
624✔
417
                                case 78:
418
                                        template.CadObject.ZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
624✔
419
                                        return true;
624✔
420
                                case 79:
421
                                        template.CadObject.AngularZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
12✔
422
                                        return true;
12✔
423
                                case 90:
424
                                        template.CadObject.ArcLengthSymbolPosition = (ArcLengthSymbolPosition)(int)this._reader.ValueAsShort;
12✔
425
                                        return true;
12✔
426
                                case 105:
427
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
1,240✔
428
                                        return true;
1,240✔
429
                                case 140:
430
                                        if (!Try.Do(() => template.CadObject.TextHeight = this._reader.ValueAsDouble, out ex))
1,248!
NEW
431
                                        {
×
NEW
432
                                                this._builder.Notify($"[{template.CadObject.SubclassMarker}] Assignation error for {nameof(DimensionStyle.TextHeight)}.", NotificationType.Warning, ex);
×
NEW
433
                                        }
×
434
                                        return true;
624✔
435
                                case 141:
436
                                        template.CadObject.CenterMarkSize = this._reader.ValueAsDouble;
624✔
437
                                        return true;
624✔
438
                                case 142:
439
                                        template.CadObject.TickSize = this._reader.ValueAsDouble;
216✔
440
                                        return true;
216✔
441
                                case 143:
442
                                        template.CadObject.AlternateUnitScaleFactor = this._reader.ValueAsDouble;
624✔
443
                                        return true;
624✔
444
                                case 144:
445
                                        template.CadObject.LinearScaleFactor = this._reader.ValueAsDouble;
216✔
446
                                        return true;
216✔
447
                                case 145:
448
                                        template.CadObject.TextVerticalPosition = this._reader.ValueAsDouble;
216✔
449
                                        return true;
216✔
450
                                case 146:
451
                                        template.CadObject.ToleranceScaleFactor = this._reader.ValueAsDouble;
216✔
452
                                        return true;
216✔
453
                                case 147:
454
                                        template.CadObject.DimensionLineGap = this._reader.ValueAsDouble;
624✔
455
                                        return true;
624✔
456
                                case 148:
457
                                        template.CadObject.AlternateUnitRounding = this._reader.ValueAsDouble;
12✔
458
                                        return true;
12✔
459
                                case 170:
460
                                        template.CadObject.AlternateUnitDimensioning = this._reader.ValueAsBool;
216✔
461
                                        return true;
216✔
462
                                case 171:
463
                                        template.CadObject.AlternateUnitDecimalPlaces = this._reader.ValueAsShort;
624✔
464
                                        return true;
624✔
465
                                case 172:
466
                                        template.CadObject.TextOutsideExtensions = this._reader.ValueAsBool;
624✔
467
                                        return true;
624✔
468
                                case 173:
469
                                        template.CadObject.SeparateArrowBlocks = this._reader.ValueAsBool;
216✔
470
                                        return true;
216✔
471
                                case 174:
472
                                        template.CadObject.TextInsideExtensions = this._reader.ValueAsBool;
216✔
473
                                        return true;
216✔
474
                                case 175:
475
                                        template.CadObject.SuppressOutsideExtensions = this._reader.ValueAsBool;
216✔
476
                                        return true;
216✔
477
                                case 176:
478
                                        template.CadObject.DimensionLineColor = new Color(this._reader.ValueAsShort);
624✔
479
                                        return true;
624✔
480
                                case 177:
481
                                        template.CadObject.ExtensionLineColor = new Color(this._reader.ValueAsShort);
624✔
482
                                        return true;
624✔
483
                                case 178:
484
                                        template.CadObject.TextColor = new Color(this._reader.ValueAsShort);
420✔
485
                                        return true;
420✔
486
                                case 179:
487
                                        template.CadObject.AngularDecimalPlaces = this._reader.ValueAsShort;
12✔
488
                                        return true;
12✔
489
                                case 270:
490
                                        template.CadObject.LinearUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
×
491
                                        return true;
×
492
                                case 271:
493
                                        template.CadObject.DecimalPlaces = this._reader.ValueAsShort;
420✔
494
                                        return true;
420✔
495
                                case 272:
496
                                        template.CadObject.ToleranceDecimalPlaces = this._reader.ValueAsShort;
420✔
497
                                        return true;
420✔
498
                                case 273:
499
                                        template.CadObject.AlternateUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
12✔
500
                                        return true;
12✔
501
                                case 274:
502
                                        template.CadObject.AlternateUnitToleranceDecimalPlaces = this._reader.ValueAsShort;
420✔
503
                                        return true;
420✔
504
                                case 275:
505
                                        template.CadObject.AngularUnit = (AngularUnitFormat)this._reader.ValueAsShort;
12✔
506
                                        return true;
12✔
507
                                case 276:
508
                                        template.CadObject.FractionFormat = (FractionFormat)this._reader.ValueAsShort;
12✔
509
                                        return true;
12✔
510
                                case 277:
511
                                        template.CadObject.LinearUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
12✔
512
                                        return true;
12✔
513
                                case 278:
514
                                        template.CadObject.DecimalSeparator = (char)this._reader.ValueAsShort;
420✔
515
                                        return true;
420✔
516
                                case 279:
517
                                        template.CadObject.TextMovement = (TextMovement)this._reader.ValueAsShort;
12✔
518
                                        return true;
12✔
519
                                case 280:
520
                                        template.CadObject.TextHorizontalAlignment = (DimensionTextHorizontalAlignment)this._reader.ValueAsShort;
12✔
521
                                        return true;
12✔
522
                                case 281:
523
                                        template.CadObject.SuppressFirstDimensionLine = this._reader.ValueAsBool;
12✔
524
                                        return true;
12✔
525
                                case 282:
526
                                        template.CadObject.SuppressSecondDimensionLine = this._reader.ValueAsBool;
12✔
527
                                        return true;
12✔
528
                                case 283:
529
                                        template.CadObject.ToleranceAlignment = (ToleranceAlignment)this._reader.ValueAsShort;
420✔
530
                                        return true;
420✔
531
                                case 284:
532
                                        template.CadObject.ToleranceZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
420✔
533
                                        return true;
420✔
534
                                case 285:
535
                                        template.CadObject.AlternateUnitZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
12✔
536
                                        return true;
12✔
537
                                case 286:
538
                                        template.CadObject.AlternateUnitToleranceZeroHandling = (ZeroHandling)(byte)this._reader.ValueAsShort;
12✔
539
                                        return true;
12✔
540
                                case 287:
541
                                        template.CadObject.DimensionFit = this._reader.ValueAsShort;
12✔
542
                                        return true;
12✔
543
                                case 288:
544
                                        template.CadObject.CursorUpdate = this._reader.ValueAsBool;
12✔
545
                                        return true;
12✔
546
                                case 289:
547
                                        template.CadObject.DimensionTextArrowFit = (TextArrowFitType)this._reader.ValueAsShort;
12✔
548
                                        return true;
12✔
549
                                case 290:
550
                                        template.CadObject.IsExtensionLineLengthFixed = this._reader.ValueAsBool;
12✔
551
                                        return true;
12✔
552
                                case 340:
553
                                        tmp.TextStyleHandle = this._reader.ValueAsHandle;
1,240✔
554
                                        return true;
1,240✔
555
                                case 341:
556
                                        tmp.DIMLDRBLK = this._reader.ValueAsHandle;
×
557
                                        return true;
×
558
                                case 342:
559
                                        tmp.DIMBLK = this._reader.ValueAsHandle;
204✔
560
                                        return true;
204✔
561
                                case 343:
562
                                        tmp.DIMBLK1 = this._reader.ValueAsHandle;
×
563
                                        return true;
×
564
                                case 344:
565
                                        tmp.DIMBLK2 = this._reader.ValueAsHandle;
×
566
                                        return true;
×
567
                                case 345:
568
                                        tmp.Dimltype = this._reader.ValueAsHandle;
136✔
569
                                        return true;
136✔
570
                                case 346:
571
                                        tmp.Dimltex1 = this._reader.ValueAsHandle;
136✔
572
                                        return true;
136✔
573
                                case 347:
574
                                        tmp.Dimltex2 = this._reader.ValueAsHandle;
136✔
575
                                        return true;
136✔
576
                                case 371:
577
                                        template.CadObject.DimensionLineWeight = (LineWeightType)this._reader.ValueAsShort;
216✔
578
                                        return true;
216✔
579
                                case 372:
580
                                        template.CadObject.ExtensionLineWeight = (LineWeightType)this._reader.ValueAsShort;
12✔
581
                                        return true;
12✔
582
                                default:
583
                                        return false;
6,560✔
584
                        }
585
                }
29,898✔
586

587
                private bool readLayer(CadTableEntryTemplate<Layer> template, DxfClassMap map)
588
                {
53,095✔
589
                        Debug.Assert(map.Name == DxfSubclassMarker.Layer);
53,095✔
590

591
                        CadLayerTemplate tmp = (CadLayerTemplate)template;
53,095✔
592

593
                        switch (this._reader.Code)
53,095✔
594
                        {
595
                                case 6:
596
                                        tmp.LineTypeName = this._reader.ValueAsString;
4,808✔
597
                                        return true;
4,808✔
598
                                case 62:
599
                                        short index = this._reader.ValueAsShort;
4,808✔
600
                                        if (index < 0)
4,808✔
601
                                        {
238✔
602
                                                template.CadObject.IsOn = false;
238✔
603
                                                index = Math.Abs(index);
238✔
604
                                        }
238✔
605

606
                                        var color = new Color(index);
4,808✔
607
                                        if (color.IsByBlock || color.IsByLayer)
4,808!
608
                                        {
×
609
                                                this._builder.Notify($"Wrong index {index} for layer {template.CadObject.Name}", NotificationType.Warning);
×
610
                                        }
×
611
                                        else
612
                                        {
4,808✔
613
                                                template.CadObject.Color = new Color(index);
4,808✔
614
                                        }
4,808✔
615
                                        return true;
4,808✔
616
                                case 347:
617
                                        tmp.MaterialHandle = this._reader.ValueAsHandle;
2,654✔
618
                                        return true;
2,654✔
619
                                case 348:
620
                                        //Unknown code value, always 0
621
                                        return true;
1,293✔
622
                                case 390:
623
                                        template.CadObject.PlotStyleName = this._reader.ValueAsHandle;
4,094✔
624
                                        return true;
4,094✔
625
                                case 430:
626
                                        tmp.TrueColorName = this._reader.ValueAsString;
170✔
627
                                        return true;
170✔
628
                                default:
629
                                        return this.tryAssignCurrentValue(template.CadObject, map);
35,268✔
630
                        }
631
                }
53,095✔
632

633
                private bool readLineType(CadTableEntryTemplate<LineType> template, DxfClassMap map)
634
                {
19,220✔
635
                        Debug.Assert(map.Name == DxfSubclassMarker.Linetype);
19,220✔
636

637
                        CadLineTypeTemplate tmp = (CadLineTypeTemplate)template;
19,220✔
638

639
                        switch (this._reader.Code)
19,220✔
640
                        {
641
                                case 40:
642
                                        tmp.TotalLen = this._reader.ValueAsDouble;
1,878✔
643
                                        return true;
1,878✔
644
                                case 49:
645
                                        do
646
                                        {
3,570✔
647
                                                tmp.SegmentTemplates.Add(this.readLineTypeSegment());
3,570✔
648
                                        }
3,570✔
649
                                        while (this._reader.Code == 49);
3,570✔
650
                                        return true;
1,190✔
651
                                case 73:
652
                                        //number of segments
653
                                        return true;
1,878✔
654
                                default:
655
                                        return this.tryAssignCurrentValue(template.CadObject, map);
14,274✔
656
                        }
657
                }
19,220✔
658

659
                private SegmentTemplate readLineTypeSegment()
660
                {
3,570✔
661
                        SegmentTemplate template = new SegmentTemplate();
3,570✔
662
                        template.Segment.Length = this._reader.ValueAsDouble;
3,570✔
663

664
                        //Jump the 49 code
665
                        this._reader.ReadNext();
3,570✔
666

667
                        while (this._reader.Code != 49 && this._reader.Code != 0)
14,178✔
668
                        {
10,608✔
669
                                switch (this._reader.Code)
10,608!
670
                                {
671
                                        case 9:
672
                                                template.Segment.Text = this._reader.ValueAsString;
204✔
673
                                                break;
204✔
674
                                        case 44:
675
                                                template.Segment.Offset = new CSMath.XY(this._reader.ValueAsDouble, template.Segment.Offset.Y);
1,224✔
676
                                                break;
1,224✔
677
                                        case 45:
678
                                                template.Segment.Offset = new CSMath.XY(template.Segment.Offset.X, this._reader.ValueAsDouble);
1,224✔
679
                                                break;
1,224✔
680
                                        case 46:
681
                                                template.Segment.Scale = this._reader.ValueAsDouble;
1,224✔
682
                                                break;
1,224✔
683
                                        case 50:
684
                                                template.Segment.Rotation = this._reader.ValueAsAngle;
1,224✔
685
                                                break;
1,224✔
686
                                        case 74:
687
                                                template.Segment.Flags = (LineTypeShapeFlags)this._reader.ValueAsUShort;
3,060✔
688
                                                break;
3,060✔
689
                                        case 75:
690
                                                template.Segment.ShapeNumber = (short)this._reader.ValueAsInt;
1,224✔
691
                                                break;
1,224✔
692
                                        case 340:
693
                                                break;
1,224✔
694
                                        default:
695
                                                this._builder.Notify($"[LineTypeSegment] Unhandeled dxf code {this._reader.Code} with value {this._reader.ValueAsString}, positon {this._reader.Position}", NotificationType.None);
×
696
                                                break;
×
697
                                }
698

699
                                this._reader.ReadNext();
10,608✔
700
                        }
10,608✔
701

702
                        return template;
3,570✔
703
                }
3,570✔
704

705
                private bool readTextStyle(CadTableEntryTemplate<TextStyle> template, DxfClassMap map)
706
                {
18,718✔
707
                        Debug.Assert(map.Name == DxfSubclassMarker.TextStyle);
18,718✔
708

709
                        switch (this._reader.Code)
18,718✔
710
                        {
711
                                case 2:
712
                                        if (!this._reader.ValueAsString.IsNullOrEmpty())
1,410✔
713
                                        {
934✔
714
                                                //In some files the TextStyle is an empty string
715
                                                template.CadObject.Name = this._reader.ValueAsString;
934✔
716
                                        }
934✔
717
                                        return true;
1,410✔
718
                                default:
719
                                        return this.tryAssignCurrentValue(template.CadObject, map);
17,308✔
720
                        }
721
                }
18,718✔
722

723
                private bool readUcs(CadTableEntryTemplate<UCS> template, DxfClassMap map)
724
                {
×
725
                        Debug.Assert(map.Name == DxfSubclassMarker.Ucs);
×
726

727
                        switch (this._reader.Code)
×
728
                        {
729
                                default:
730
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
731
                        }
732
                }
×
733

734
                private bool readView(CadTableEntryTemplate<View> template, DxfClassMap map)
735
                {
7,956✔
736
                        Debug.Assert(map.Name == DxfSubclassMarker.View);
7,956✔
737

738
                        CadViewTemplate tmp = template as CadViewTemplate;
7,956✔
739

740
                        switch (this._reader.Code)
7,956✔
741
                        {
742
                                case 348:
743
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
136✔
744
                                        return true;
136✔
745
                                default:
746
                                        return this.tryAssignCurrentValue(template.CadObject, map);
7,820✔
747
                        }
748
                }
7,956✔
749

750
                private bool readVPort(CadTableEntryTemplate<VPort> template, DxfClassMap map)
751
                {
13,656✔
752
                        Debug.Assert(map.Name == DxfSubclassMarker.VPort);
13,656✔
753

754
                        CadVPortTemplate tmp = template as CadVPortTemplate;
13,656✔
755

756
                        switch (this._reader.Code)
13,656✔
757
                        {
758
                                //NOTE: Undocumented codes
759
                                case 65:
760
                                case 73:
761
                                        return true;
446✔
762
                                case 348:
763
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
138✔
764
                                        return true;
138✔
765
                                default:
766
                                        return this.tryAssignCurrentValue(template.CadObject, map);
13,072✔
767
                        }
768
                }
13,656✔
769
        }
770
}
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