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

DomCR / ACadSharp / 15897276345

26 Jun 2025 08:47AM UTC coverage: 75.362% (-0.01%) from 75.376%
15897276345

Pull #698

github

web-flow
Merge 86df493eb into f019166b3
Pull Request #698: Layer safe color

5834 of 8537 branches covered (68.34%)

Branch coverage included in aggregate %.

5 of 8 new or added lines in 1 file covered. (62.5%)

6 existing lines in 1 file now uncovered.

23237 of 30038 relevant lines covered (77.36%)

82077.38 hits per line

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

90.07
/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,807✔
64
                                        switch (this._reader.Code)
4,807!
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);
209✔
83
                                                        break;
209✔
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,807✔
90
                                                break;
451✔
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,316✔
180
                        {
26,872✔
181
                                this._reader.ReadNext();
26,872✔
182

183
                                ICadTableEntryTemplate template = null;
26,872✔
184

185
                                //Get the entry
186
                                switch (tableTemplate.CadObject.ObjectName)
26,872!
187
                                {
188
                                        case DxfFileToken.TableAppId:
189
                                                template = this.readTableEntry(new CadTableEntryTemplate<AppId>(new AppId()), this.readAppId);
9,450✔
190
                                                break;
9,450✔
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)
26,872!
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
                                {
26,872✔
237
                                        tableTemplate.CadObject.Add((T)template.CadObject);
26,872✔
238
                                }
26,872✔
239

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

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

250
                        while (this._reader.DxfCode != DxfCode.Start)
306,509✔
251
                        {
279,637✔
252
                                if (!readEntry(template, map.SubClasses[template.CadObject.SubclassMarker]))
279,637✔
253
                                {
110,458✔
254
                                        this.readCommonTableEntryCodes(template, out bool isExtendedData, map);
110,458✔
255
                                        if (isExtendedData)
110,458✔
256
                                                continue;
7,228✔
257
                                }
103,230✔
258

259
                                if (this._reader.DxfCode != DxfCode.Start)
272,409✔
260
                                        this._reader.ReadNext();
271,079✔
261
                        }
272,409✔
262

263
                        return template;
26,872✔
264
                }
26,872✔
265

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

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

291
                        switch (this._reader.Code)
51,038✔
292
                        {
293
                                default:
294
                                        return this.tryAssignCurrentValue(template.CadObject, map);
51,038✔
295
                        }
296
                }
51,038✔
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 71:
376
                                        template.CadObject.GenerateTolerances = this._reader.ValueAsBool;
240✔
377
                                        return true;
240✔
378
                                case 72:
379
                                        template.CadObject.LimitsGeneration = this._reader.ValueAsBool;
240✔
380
                                        return true;
240✔
381
                                case 73:
382
                                        template.CadObject.TextInsideHorizontal = this._reader.ValueAsBool;
696✔
383
                                        return true;
696✔
384
                                case 74:
385
                                        template.CadObject.TextOutsideHorizontal = this._reader.ValueAsBool;
696✔
386
                                        return true;
696✔
387
                                case 75:
388
                                        template.CadObject.SuppressFirstExtensionLine = this._reader.ValueAsBool;
240✔
389
                                        return true;
240✔
390
                                case 76:
391
                                        template.CadObject.SuppressSecondExtensionLine = this._reader.ValueAsBool;
240✔
392
                                        return true;
240✔
393
                                case 77:
394
                                        template.CadObject.TextVerticalAlignment = (DimensionTextVerticalAlignment)this._reader.ValueAsShort;
696✔
395
                                        return true;
696✔
396
                                case 78:
397
                                        template.CadObject.ZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
696✔
398
                                        return true;
696✔
399
                                case 79:
400
                                        template.CadObject.AngularZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
12✔
401
                                        return true;
12✔
402
                                case 90:
403
                                        template.CadObject.ArcLengthSymbolPosition = (ArcLengthSymbolPosition)(int)this._reader.ValueAsShort;
12✔
404
                                        return true;
12✔
405
                                case 105:
406
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
1,384✔
407
                                        return true;
1,384✔
408
                                case 140:
409
                                        template.CadObject.TextHeight = this._reader.ValueAsDouble;
696✔
410
                                        return true;
696✔
411
                                case 141:
412
                                        template.CadObject.CenterMarkSize = this._reader.ValueAsDouble;
696✔
413
                                        return true;
696✔
414
                                case 142:
415
                                        template.CadObject.TickSize = this._reader.ValueAsDouble;
240✔
416
                                        return true;
240✔
417
                                case 143:
418
                                        template.CadObject.AlternateUnitScaleFactor = this._reader.ValueAsDouble;
696✔
419
                                        return true;
696✔
420
                                case 144:
421
                                        template.CadObject.LinearScaleFactor = this._reader.ValueAsDouble;
240✔
422
                                        return true;
240✔
423
                                case 145:
424
                                        template.CadObject.TextVerticalPosition = this._reader.ValueAsDouble;
240✔
425
                                        return true;
240✔
426
                                case 146:
427
                                        template.CadObject.ToleranceScaleFactor = this._reader.ValueAsDouble;
240✔
428
                                        return true;
240✔
429
                                case 147:
430
                                        template.CadObject.DimensionLineGap = this._reader.ValueAsDouble;
696✔
431
                                        return true;
696✔
432
                                case 148:
433
                                        template.CadObject.AlternateUnitRounding = this._reader.ValueAsDouble;
12✔
434
                                        return true;
12✔
435
                                case 170:
436
                                        template.CadObject.AlternateUnitDimensioning = this._reader.ValueAsBool;
240✔
437
                                        return true;
240✔
438
                                case 171:
439
                                        template.CadObject.AlternateUnitDecimalPlaces = this._reader.ValueAsShort;
696✔
440
                                        return true;
696✔
441
                                case 172:
442
                                        template.CadObject.TextOutsideExtensions = this._reader.ValueAsBool;
696✔
443
                                        return true;
696✔
444
                                case 173:
445
                                        template.CadObject.SeparateArrowBlocks = this._reader.ValueAsBool;
240✔
446
                                        return true;
240✔
447
                                case 174:
448
                                        template.CadObject.TextInsideExtensions = this._reader.ValueAsBool;
240✔
449
                                        return true;
240✔
450
                                case 175:
451
                                        template.CadObject.SuppressOutsideExtensions = this._reader.ValueAsBool;
240✔
452
                                        return true;
240✔
453
                                case 176:
454
                                        template.CadObject.DimensionLineColor = new Color(this._reader.ValueAsShort);
696✔
455
                                        return true;
696✔
456
                                case 177:
457
                                        template.CadObject.ExtensionLineColor = new Color(this._reader.ValueAsShort);
696✔
458
                                        return true;
696✔
459
                                case 178:
460
                                        template.CadObject.TextColor = new Color(this._reader.ValueAsShort);
468✔
461
                                        return true;
468✔
462
                                case 179:
463
                                        template.CadObject.AngularDecimalPlaces = this._reader.ValueAsShort;
12✔
464
                                        return true;
12✔
465
                                case 270:
466
                                        template.CadObject.LinearUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
×
467
                                        return true;
×
468
                                case 271:
469
                                        template.CadObject.DecimalPlaces = this._reader.ValueAsShort;
468✔
470
                                        return true;
468✔
471
                                case 272:
472
                                        template.CadObject.ToleranceDecimalPlaces = this._reader.ValueAsShort;
468✔
473
                                        return true;
468✔
474
                                case 273:
475
                                        template.CadObject.AlternateUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
12✔
476
                                        return true;
12✔
477
                                case 274:
478
                                        template.CadObject.AlternateUnitToleranceDecimalPlaces = this._reader.ValueAsShort;
468✔
479
                                        return true;
468✔
480
                                case 275:
481
                                        template.CadObject.AngularUnit = (AngularUnitFormat)this._reader.ValueAsShort;
12✔
482
                                        return true;
12✔
483
                                case 276:
484
                                        template.CadObject.FractionFormat = (FractionFormat)this._reader.ValueAsShort;
12✔
485
                                        return true;
12✔
486
                                case 277:
487
                                        template.CadObject.LinearUnitFormat = (LinearUnitFormat)this._reader.ValueAsShort;
12✔
488
                                        return true;
12✔
489
                                case 278:
490
                                        template.CadObject.DecimalSeparator = (char)this._reader.ValueAsShort;
468✔
491
                                        return true;
468✔
492
                                case 279:
493
                                        template.CadObject.TextMovement = (TextMovement)this._reader.ValueAsShort;
12✔
494
                                        return true;
12✔
495
                                case 280:
496
                                        template.CadObject.TextHorizontalAlignment = (DimensionTextHorizontalAlignment)this._reader.ValueAsShort;
12✔
497
                                        return true;
12✔
498
                                case 281:
499
                                        template.CadObject.SuppressFirstDimensionLine = this._reader.ValueAsBool;
12✔
500
                                        return true;
12✔
501
                                case 282:
502
                                        template.CadObject.SuppressSecondDimensionLine = this._reader.ValueAsBool;
12✔
503
                                        return true;
12✔
504
                                case 283:
505
                                        template.CadObject.ToleranceAlignment = (ToleranceAlignment)this._reader.ValueAsShort;
468✔
506
                                        return true;
468✔
507
                                case 284:
508
                                        template.CadObject.ToleranceZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
468✔
509
                                        return true;
468✔
510
                                case 285:
511
                                        template.CadObject.AlternateUnitZeroHandling = (ZeroHandling)this._reader.ValueAsShort;
12✔
512
                                        return true;
12✔
513
                                case 286:
514
                                        template.CadObject.AlternateUnitToleranceZeroHandling = (ZeroHandling)(byte)this._reader.ValueAsShort;
12✔
515
                                        return true;
12✔
516
                                case 287:
517
                                        template.CadObject.DimensionFit = this._reader.ValueAsShort;
12✔
518
                                        return true;
12✔
519
                                case 288:
520
                                        template.CadObject.CursorUpdate = this._reader.ValueAsBool;
12✔
521
                                        return true;
12✔
522
                                case 289:
523
                                        template.CadObject.DimensionTextArrowFit = (TextArrowFitType)this._reader.ValueAsShort;
12✔
524
                                        return true;
12✔
525
                                case 290:
526
                                        template.CadObject.IsExtensionLineLengthFixed = this._reader.ValueAsBool;
12✔
527
                                        return true;
12✔
528
                                case 340:
529
                                        tmp.TextStyleHandle = this._reader.ValueAsHandle;
1,384✔
530
                                        return true;
1,384✔
531
                                case 341:
532
                                        tmp.DIMLDRBLK = this._reader.ValueAsHandle;
×
533
                                        return true;
×
534
                                case 342:
535
                                        tmp.DIMBLK = this._reader.ValueAsHandle;
228✔
536
                                        return true;
228✔
537
                                case 343:
538
                                        tmp.DIMBLK1 = this._reader.ValueAsHandle;
×
539
                                        return true;
×
540
                                case 344:
541
                                        tmp.DIMBLK2 = this._reader.ValueAsHandle;
×
542
                                        return true;
×
543
                                case 345:
544
                                        tmp.Dimltype = this._reader.ValueAsHandle;
152✔
545
                                        return true;
152✔
546
                                case 346:
547
                                        tmp.Dimltex1 = this._reader.ValueAsHandle;
152✔
548
                                        return true;
152✔
549
                                case 347:
550
                                        tmp.Dimltex2 = this._reader.ValueAsHandle;
152✔
551
                                        return true;
152✔
552
                                case 371:
553
                                        template.CadObject.DimensionLineWeight = (LineweightType)this._reader.ValueAsShort;
240✔
554
                                        return true;
240✔
555
                                case 372:
556
                                        template.CadObject.ExtensionLineWeight = (LineweightType)this._reader.ValueAsShort;
12✔
557
                                        return true;
12✔
558
                                default:
559
                                        return false;
9,100✔
560
                        }
561
                }
33,310✔
562

563
                private bool readLayer(CadTableEntryTemplate<Layer> template, DxfClassMap map)
564
                {
59,323✔
565
                        Debug.Assert(map.Name == DxfSubclassMarker.Layer);
59,323✔
566

567
                        CadLayerTemplate tmp = (CadLayerTemplate)template;
59,323✔
568

569
                        switch (this._reader.Code)
59,323✔
570
                        {
571
                                case 6:
572
                                        tmp.LineTypeName = this._reader.ValueAsString;
5,372✔
573
                                        return true;
5,372✔
574
                                case 62:
575
                                        short index = this._reader.ValueAsShort;
5,372✔
576
                                        if (index < 0)
5,372✔
577
                                        {
266✔
578
                                                template.CadObject.IsOn = false;
266✔
579
                                                index = Math.Abs(index);
266✔
580
                                        }
266✔
581

582
                                        var color = new Color(index);
5,372✔
583
                                        if (color.IsByBlock || color.IsByLayer)
5,372!
NEW
584
                                        {
×
NEW
585
                                                this._builder.Notify($"Wrong index {index} for layer {template.CadObject.Name}", NotificationType.Warning);
×
NEW
586
                                        }
×
587
                                        else
588
                                        {
5,372✔
589
                                                template.CadObject.Color = new Color(index);
5,372✔
590
                                        }
5,372✔
591
                                        return true;
5,372✔
592
                                case 347:
593
                                        tmp.MaterialHandle = this._reader.ValueAsHandle;
2,966✔
594
                                        return true;
2,966✔
595
                                case 348:
596
                                        //Unknown code value, always 0
597
                                        return true;
1,445✔
598
                                case 390:
599
                                        template.CadObject.PlotStyleName = this._reader.ValueAsHandle;
4,574✔
600
                                        return true;
4,574✔
601
                                case 430:
602
                                        tmp.TrueColorName = this._reader.ValueAsString;
190✔
603
                                        return true;
190✔
604
                                default:
605
                                        return this.tryAssignCurrentValue(template.CadObject, map);
39,404✔
606
                        }
607
                }
59,323✔
608

609
                private bool readLineType(CadTableEntryTemplate<LineType> template, DxfClassMap map)
610
                {
21,436✔
611
                        Debug.Assert(map.Name == DxfSubclassMarker.Linetype);
21,436✔
612

613
                        CadLineTypeTemplate tmp = (CadLineTypeTemplate)template;
21,436✔
614

615
                        switch (this._reader.Code)
21,436✔
616
                        {
617
                                case 40:
618
                                        tmp.TotalLen = this._reader.ValueAsDouble;
2,094✔
619
                                        return true;
2,094✔
620
                                case 49:
621
                                        do
622
                                        {
3,990✔
623
                                                tmp.SegmentTemplates.Add(this.readLineTypeSegment());
3,990✔
624
                                        }
3,990✔
625
                                        while (this._reader.Code == 49);
3,990✔
626
                                        return true;
1,330✔
627
                                case 73:
628
                                        //number of segments
629
                                        return true;
2,094✔
630
                                default:
631
                                        return this.tryAssignCurrentValue(template.CadObject, map);
15,918✔
632
                        }
633
                }
21,436✔
634

635
                private SegmentTemplate readLineTypeSegment()
636
                {
3,990✔
637
                        SegmentTemplate template = new SegmentTemplate();
3,990✔
638
                        template.Segment.Length = this._reader.ValueAsDouble;
3,990✔
639

640
                        //Jump the 49 code
641
                        this._reader.ReadNext();
3,990✔
642

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

675
                                this._reader.ReadNext();
11,856✔
676
                        }
11,856✔
677

678
                        return template;
3,990✔
679
                }
3,990✔
680

681
                private bool readTextStyle(CadTableEntryTemplate<TextStyle> template, DxfClassMap map)
682
                {
20,898✔
683
                        Debug.Assert(map.Name == DxfSubclassMarker.TextStyle);
20,898✔
684

685
                        switch (this._reader.Code)
20,898✔
686
                        {
687
                                case 2:
688
                                        if (!this._reader.ValueAsString.IsNullOrEmpty())
1,574✔
689
                                        {
1,042✔
690
                                                //In some files the TextStyle is an empty string
691
                                                template.CadObject.Name = this._reader.ValueAsString;
1,042✔
692
                                        }
1,042✔
693
                                        return true;
1,574✔
694
                                default:
695
                                        return this.tryAssignCurrentValue(template.CadObject, map);
19,324✔
696
                        }
697
                }
20,898✔
698

699
                private bool readUcs(CadTableEntryTemplate<UCS> template, DxfClassMap map)
700
                {
×
701
                        Debug.Assert(map.Name == DxfSubclassMarker.Ucs);
×
702

703
                        switch (this._reader.Code)
×
704
                        {
705
                                default:
706
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
707
                        }
708
                }
×
709

710
                private bool readView(CadTableEntryTemplate<View> template, DxfClassMap map)
711
                {
8,892✔
712
                        Debug.Assert(map.Name == DxfSubclassMarker.View);
8,892✔
713

714
                        CadViewTemplate tmp = template as CadViewTemplate;
8,892✔
715

716
                        switch (this._reader.Code)
8,892✔
717
                        {
718
                                case 348:
719
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
152✔
720
                                        return true;
152✔
721
                                default:
722
                                        return this.tryAssignCurrentValue(template.CadObject, map);
8,740✔
723
                        }
724
                }
8,892✔
725

726
                private bool readVPort(CadTableEntryTemplate<VPort> template, DxfClassMap map)
727
                {
15,208✔
728
                        Debug.Assert(map.Name == DxfSubclassMarker.VPort);
15,208✔
729

730
                        CadVPortTemplate tmp = template as CadVPortTemplate;
15,208✔
731

732
                        switch (this._reader.Code)
15,208✔
733
                        {
734
                                //NOTE: Undocumented codes
735
                                case 65:
736
                                case 73:
737
                                        return true;
498✔
738
                                case 348:
739
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
154✔
740
                                        return true;
154✔
741
                                default:
742
                                        return this.tryAssignCurrentValue(template.CadObject, map);
14,556✔
743
                        }
744
                }
15,208✔
745
        }
746
}
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