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

DomCR / ACadSharp / 17330604477

29 Aug 2025 05:43PM UTC coverage: 78.251% (+0.02%) from 78.229%
17330604477

push

github

web-flow
Merge pull request #761 from DomCR/dxf-dimensionstyle-flags

Dxf dimensionstyle

6561 of 9113 branches covered (72.0%)

Branch coverage included in aggregate %.

12 of 12 new or added lines in 3 files covered. (100.0%)

7 existing lines in 3 files now uncovered.

25425 of 31763 relevant lines covered (80.05%)

105864.24 hits per line

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

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

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

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

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

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

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

39

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

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

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

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

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

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

89
                                        if (this._reader.DxfCode == DxfCode.Start)
4,788✔
90
                                                break;
432✔
91

92
                                        this._reader.ReadNext();
4,356✔
93
                                }
4,356✔
94
                        }
2,178✔
95
                        else if (this._reader.ValueAsString == DxfFileToken.EndTable)
304✔
96
                        {
38✔
97
                                return;
38✔
98
                        }
99
                        else
100
                        {
266✔
101
                                this._reader.ReadNext();
266✔
102
                        }
266✔
103

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

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

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

171
                        //Add the object and the template to the builder
172
                        this._builder.AddTemplate(template);
2,444✔
173
                }
2,482✔
174

175
                private void readEntries<T>(CadTableTemplate<T> tableTemplate)
176
                        where T : TableEntry
177
                {
2,444✔
178
                        //Read all the entries until the end of the table
179
                        while (this._reader.ValueAsString != DxfFileToken.EndTable)
29,582✔
180
                        {
27,138✔
181
                                this._reader.ReadNext();
27,138✔
182

183
                                ICadTableEntryTemplate template = null;
27,138✔
184

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

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

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

227

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

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

240
                                //Add the object and the template to the builder
241
                                this._builder.AddTemplate(template);
27,138✔
242
                        }
27,138✔
243
                }
2,444✔
244

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

250
                        while (this._reader.DxfCode != DxfCode.Start)
308,219✔
251
                        {
281,081✔
252
                                if (!readEntry(template, map.SubClasses[template.CadObject.SubclassMarker]))
281,081✔
253
                                {
109,594✔
254
                                        this.readCommonTableEntryCodes(template, out bool isExtendedData, map);
109,594✔
255
                                        if (isExtendedData)
109,594✔
256
                                                continue;
7,228✔
257
                                }
102,366✔
258

259
                                if (this._reader.DxfCode != DxfCode.Start)
273,853✔
260
                                        this._reader.ReadNext();
272,523✔
261
                        }
273,853✔
262

263
                        return template;
27,138✔
264
                }
27,138✔
265

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

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

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

298
                private bool readBlockRecord(CadTableEntryTemplate<BlockRecord> template, DxfClassMap map)
299
                {
69,532✔
300
                        CadBlockRecordTemplate tmp = (CadBlockRecordTemplate)template;
69,532✔
301

302
                        switch (this._reader.Code)
69,532✔
303
                        {
304
                                case 340:
305
                                        tmp.LayoutHandle = this._reader.ValueAsHandle;
6,186✔
306
                                        return true;
6,186✔
307
                                default:
308
                                        return this.tryAssignCurrentValue(template.CadObject, map);
63,346✔
309
                        }
310
                }
69,532✔
311

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

316
                        CadDimensionStyleTemplate tmp = (CadDimensionStyleTemplate)template;
33,310✔
317

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

574
                private bool readLayer(CadTableEntryTemplate<Layer> template, DxfClassMap map)
575
                {
59,323✔
576
                        Debug.Assert(map.Name == DxfSubclassMarker.Layer);
59,323✔
577

578
                        CadLayerTemplate tmp = (CadLayerTemplate)template;
59,323✔
579

580
                        switch (this._reader.Code)
59,323✔
581
                        {
582
                                case 6:
583
                                        tmp.LineTypeName = this._reader.ValueAsString;
5,372✔
584
                                        return true;
5,372✔
585
                                case 62:
586
                                        short index = this._reader.ValueAsShort;
5,372✔
587
                                        if (index < 0)
5,372✔
588
                                        {
266✔
589
                                                template.CadObject.IsOn = false;
266✔
590
                                                index = Math.Abs(index);
266✔
591
                                        }
266✔
592

593
                                        var color = new Color(index);
5,372✔
594
                                        if (color.IsByBlock || color.IsByLayer)
5,372!
595
                                        {
×
596
                                                this._builder.Notify($"Wrong index {index} for layer {template.CadObject.Name}", NotificationType.Warning);
×
597
                                        }
×
598
                                        else
599
                                        {
5,372✔
600
                                                template.CadObject.Color = new Color(index);
5,372✔
601
                                        }
5,372✔
602
                                        return true;
5,372✔
603
                                case 347:
604
                                        tmp.MaterialHandle = this._reader.ValueAsHandle;
2,966✔
605
                                        return true;
2,966✔
606
                                case 348:
607
                                        //Unknown code value, always 0
608
                                        return true;
1,445✔
609
                                case 390:
610
                                        template.CadObject.PlotStyleName = this._reader.ValueAsHandle;
4,574✔
611
                                        return true;
4,574✔
612
                                case 430:
613
                                        tmp.TrueColorName = this._reader.ValueAsString;
190✔
614
                                        return true;
190✔
615
                                default:
616
                                        return this.tryAssignCurrentValue(template.CadObject, map);
39,404✔
617
                        }
618
                }
59,323✔
619

620
                private bool readLineType(CadTableEntryTemplate<LineType> template, DxfClassMap map)
621
                {
21,436✔
622
                        Debug.Assert(map.Name == DxfSubclassMarker.Linetype);
21,436✔
623

624
                        CadLineTypeTemplate tmp = (CadLineTypeTemplate)template;
21,436✔
625

626
                        switch (this._reader.Code)
21,436✔
627
                        {
628
                                case 40:
629
                                        tmp.TotalLen = this._reader.ValueAsDouble;
2,094✔
630
                                        return true;
2,094✔
631
                                case 49:
632
                                        do
633
                                        {
3,990✔
634
                                                tmp.SegmentTemplates.Add(this.readLineTypeSegment());
3,990✔
635
                                        }
3,990✔
636
                                        while (this._reader.Code == 49);
3,990✔
637
                                        return true;
1,330✔
638
                                case 73:
639
                                        //number of segments
640
                                        return true;
2,094✔
641
                                default:
642
                                        return this.tryAssignCurrentValue(template.CadObject, map);
15,918✔
643
                        }
644
                }
21,436✔
645

646
                private SegmentTemplate readLineTypeSegment()
647
                {
3,990✔
648
                        SegmentTemplate template = new SegmentTemplate();
3,990✔
649
                        template.Segment.Length = this._reader.ValueAsDouble;
3,990✔
650

651
                        //Jump the 49 code
652
                        this._reader.ReadNext();
3,990✔
653

654
                        while (this._reader.Code != 49 && this._reader.Code != 0)
15,846✔
655
                        {
11,856✔
656
                                switch (this._reader.Code)
11,856!
657
                                {
658
                                        case 9:
659
                                                template.Segment.Text = this._reader.ValueAsString;
228✔
660
                                                break;
228✔
661
                                        case 44:
662
                                                template.Segment.Offset = new CSMath.XY(this._reader.ValueAsDouble, template.Segment.Offset.Y);
1,368✔
663
                                                break;
1,368✔
664
                                        case 45:
665
                                                template.Segment.Offset = new CSMath.XY(template.Segment.Offset.X, this._reader.ValueAsDouble);
1,368✔
666
                                                break;
1,368✔
667
                                        case 46:
668
                                                template.Segment.Scale = this._reader.ValueAsDouble;
1,368✔
669
                                                break;
1,368✔
670
                                        case 50:
671
                                                template.Segment.Rotation = this._reader.ValueAsAngle;
1,368✔
672
                                                break;
1,368✔
673
                                        case 74:
674
                                                template.Segment.Shapeflag = (LinetypeShapeFlags)this._reader.ValueAsUShort;
3,420✔
675
                                                break;
3,420✔
676
                                        case 75:
677
                                                template.Segment.ShapeNumber = (short)this._reader.ValueAsInt;
1,368✔
678
                                                break;
1,368✔
679
                                        case 340:
680
                                                break;
1,368✔
681
                                        default:
682
                                                this._builder.Notify($"[LineTypeSegment] Unhandeled dxf code {this._reader.Code} with value {this._reader.ValueAsString}, positon {this._reader.Position}", NotificationType.None);
×
683
                                                break;
×
684
                                }
685

686
                                this._reader.ReadNext();
11,856✔
687
                        }
11,856✔
688

689
                        return template;
3,990✔
690
                }
3,990✔
691

692
                private bool readTextStyle(CadTableEntryTemplate<TextStyle> template, DxfClassMap map)
693
                {
20,898✔
694
                        Debug.Assert(map.Name == DxfSubclassMarker.TextStyle);
20,898✔
695

696
                        switch (this._reader.Code)
20,898✔
697
                        {
698
                                case 2:
699
                                        if (!this._reader.ValueAsString.IsNullOrEmpty())
1,574✔
700
                                        {
1,042✔
701
                                                //In some files the TextStyle is an empty string
702
                                                template.CadObject.Name = this._reader.ValueAsString;
1,042✔
703
                                        }
1,042✔
704
                                        return true;
1,574✔
705
                                default:
706
                                        return this.tryAssignCurrentValue(template.CadObject, map);
19,324✔
707
                        }
708
                }
20,898✔
709

710
                private bool readUcs(CadTableEntryTemplate<UCS> template, DxfClassMap map)
711
                {
×
712
                        Debug.Assert(map.Name == DxfSubclassMarker.Ucs);
×
713

714
                        switch (this._reader.Code)
×
715
                        {
716
                                default:
717
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
718
                        }
719
                }
×
720

721
                private bool readView(CadTableEntryTemplate<View> template, DxfClassMap map)
722
                {
8,892✔
723
                        Debug.Assert(map.Name == DxfSubclassMarker.View);
8,892✔
724

725
                        CadViewTemplate tmp = template as CadViewTemplate;
8,892✔
726

727
                        switch (this._reader.Code)
8,892✔
728
                        {
729
                                case 348:
730
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
152✔
731
                                        return true;
152✔
732
                                default:
733
                                        return this.tryAssignCurrentValue(template.CadObject, map);
8,740✔
734
                        }
735
                }
8,892✔
736

737
                private bool readVPort(CadTableEntryTemplate<VPort> template, DxfClassMap map)
738
                {
15,208✔
739
                        Debug.Assert(map.Name == DxfSubclassMarker.VPort);
15,208✔
740

741
                        CadVPortTemplate tmp = template as CadVPortTemplate;
15,208✔
742

743
                        switch (this._reader.Code)
15,208✔
744
                        {
745
                                //NOTE: Undocumented codes
746
                                case 65:
747
                                case 73:
748
                                        return true;
498✔
749
                                case 348:
750
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
154✔
751
                                        return true;
154✔
752
                                default:
753
                                        return this.tryAssignCurrentValue(template.CadObject, map);
14,556✔
754
                        }
755
                }
15,208✔
756
        }
757
}
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