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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

0.0
/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)
UNCOV
21
                        : base(reader, builder)
×
UNCOV
22
                {
×
UNCOV
23
                }
×
24

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

30
                        //Loop until the section ends
UNCOV
31
                        while (this._reader.ValueAsString != DxfFileToken.EndSection)
×
UNCOV
32
                        {
×
33

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

39

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

47
                private void readTable()
UNCOV
48
                {
×
UNCOV
49
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.TableEntry);
×
50

51
                        //Read the table name
UNCOV
52
                        this._reader.ReadNext();
×
53

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

UNCOV
58
                        this.readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out HashSet<ulong> reactors);
×
59

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

UNCOV
89
                                        if (this._reader.DxfCode == DxfCode.Start)
×
UNCOV
90
                                                break;
×
91

UNCOV
92
                                        this._reader.ReadNext();
×
UNCOV
93
                                }
×
UNCOV
94
                        }
×
UNCOV
95
                        else if (this._reader.ValueAsString == DxfFileToken.EndTable)
×
UNCOV
96
                        {
×
UNCOV
97
                                return;
×
98
                        }
99
                        else
UNCOV
100
                        {
×
UNCOV
101
                                this._reader.ReadNext();
×
UNCOV
102
                        }
×
103

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

UNCOV
164
                        Debug.Assert(ownerHandle == null || ownerHandle.Value == 0);
×
165

UNCOV
166
                        template.OwnerHandle = ownerHandle;
×
UNCOV
167
                        template.XDictHandle = xdictHandle;
×
UNCOV
168
                        template.ReactorsHandles = reactors;
×
UNCOV
169
                        template.EDataTemplateByAppName = edata;
×
170

171
                        //Add the object and the template to the builder
UNCOV
172
                        this._builder.AddTemplate(template);
×
UNCOV
173
                }
×
174

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

UNCOV
183
                                ICadTableEntryTemplate template = null;
×
184

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

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

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

227

UNCOV
228
                                if (tableTemplate.CadObject.Contains(template.Name) && this._builder.Configuration.Failsafe)
×
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
UNCOV
236
                                {
×
UNCOV
237
                                        tableTemplate.CadObject.Add((T)template.CadObject);
×
UNCOV
238
                                }
×
239

240
                                //Add the object and the template to the builder
UNCOV
241
                                this._builder.AddTemplate(template);
×
UNCOV
242
                        }
×
UNCOV
243
                }
×
244

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

UNCOV
250
                        while (this._reader.DxfCode != DxfCode.Start)
×
UNCOV
251
                        {
×
UNCOV
252
                                if (!readEntry(template, map.SubClasses[template.CadObject.SubclassMarker]))
×
UNCOV
253
                                {
×
UNCOV
254
                                        this.readCommonTableEntryCodes(template, out bool isExtendedData, map);
×
UNCOV
255
                                        if (isExtendedData)
×
UNCOV
256
                                                continue;
×
UNCOV
257
                                }
×
258

UNCOV
259
                                if (this._reader.DxfCode != DxfCode.Start)
×
UNCOV
260
                                        this._reader.ReadNext();
×
UNCOV
261
                        }
×
262

UNCOV
263
                        return template;
×
UNCOV
264
                }
×
265

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

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

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

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

UNCOV
302
                        switch (this._reader.Code)
×
303
                        {
304
                                case 340:
UNCOV
305
                                        tmp.LayoutHandle = this._reader.ValueAsHandle;
×
UNCOV
306
                                        return true;
×
307
                                default:
UNCOV
308
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
309
                        }
UNCOV
310
                }
×
311

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

UNCOV
316
                        CadDimensionStyleTemplate tmp = (CadDimensionStyleTemplate)template;
×
317

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

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

UNCOV
578
                        CadLayerTemplate tmp = (CadLayerTemplate)template;
×
579

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

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

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

UNCOV
624
                        CadLineTypeTemplate tmp = (CadLineTypeTemplate)template;
×
625

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

646
                private SegmentTemplate readLineTypeSegment()
UNCOV
647
                {
×
UNCOV
648
                        SegmentTemplate template = new SegmentTemplate();
×
UNCOV
649
                        template.Segment.Length = this._reader.ValueAsDouble;
×
650

651
                        //Jump the 49 code
UNCOV
652
                        this._reader.ReadNext();
×
653

UNCOV
654
                        while (this._reader.Code != 49 && this._reader.Code != 0)
×
UNCOV
655
                        {
×
UNCOV
656
                                switch (this._reader.Code)
×
657
                                {
658
                                        case 9:
UNCOV
659
                                                template.Segment.Text = this._reader.ValueAsString;
×
UNCOV
660
                                                break;
×
661
                                        case 44:
UNCOV
662
                                                template.Segment.Offset = new CSMath.XY(this._reader.ValueAsDouble, template.Segment.Offset.Y);
×
UNCOV
663
                                                break;
×
664
                                        case 45:
UNCOV
665
                                                template.Segment.Offset = new CSMath.XY(template.Segment.Offset.X, this._reader.ValueAsDouble);
×
UNCOV
666
                                                break;
×
667
                                        case 46:
UNCOV
668
                                                template.Segment.Scale = this._reader.ValueAsDouble;
×
UNCOV
669
                                                break;
×
670
                                        case 50:
UNCOV
671
                                                template.Segment.Rotation = this._reader.ValueAsAngle;
×
UNCOV
672
                                                break;
×
673
                                        case 74:
UNCOV
674
                                                template.Segment.Flags = (LineTypeShapeFlags)this._reader.ValueAsUShort;
×
UNCOV
675
                                                break;
×
676
                                        case 75:
UNCOV
677
                                                template.Segment.ShapeNumber = (short)this._reader.ValueAsInt;
×
UNCOV
678
                                                break;
×
679
                                        case 340:
UNCOV
680
                                                break;
×
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

UNCOV
686
                                this._reader.ReadNext();
×
UNCOV
687
                        }
×
688

UNCOV
689
                        return template;
×
UNCOV
690
                }
×
691

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

UNCOV
696
                        switch (this._reader.Code)
×
697
                        {
698
                                case 2:
UNCOV
699
                                        if (!this._reader.ValueAsString.IsNullOrEmpty())
×
UNCOV
700
                                        {
×
701
                                                //In some files the TextStyle is an empty string
UNCOV
702
                                                template.CadObject.Name = this._reader.ValueAsString;
×
UNCOV
703
                                        }
×
UNCOV
704
                                        return true;
×
705
                                default:
UNCOV
706
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
707
                        }
UNCOV
708
                }
×
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)
UNCOV
722
                {
×
UNCOV
723
                        Debug.Assert(map.Name == DxfSubclassMarker.View);
×
724

UNCOV
725
                        CadViewTemplate tmp = template as CadViewTemplate;
×
726

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

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

UNCOV
741
                        CadVPortTemplate tmp = template as CadVPortTemplate;
×
742

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