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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

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

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

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

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

39

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

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

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

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

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

60
                        if (this._reader.DxfCode == DxfCode.Subclass)
×
61
                        {
×
62
                                while (this._reader.DxfCode != DxfCode.Start)
×
63
                                {
×
64
                                        switch (this._reader.Code)
×
65
                                        {
66
                                                //Maximum number of entries in table
67
                                                case 70:
68
                                                        nentries = this._reader.ValueAsInt;
×
69
                                                        break;
×
70
                                                case 100 when this._reader.ValueAsString == DxfSubclassMarker.DimensionStyleTable:
×
71
                                                        while (this._reader.DxfCode != DxfCode.Start)
×
72
                                                        {
×
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();
×
76
                                                        }
×
77
                                                        break;
×
78
                                                case 100:
79
                                                        Debug.Assert(this._reader.ValueAsString == DxfSubclassMarker.Table);
×
80
                                                        break;
×
81
                                                case 1001:
82
                                                        this.readExtendedData(edata);
×
83
                                                        break;
×
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)
×
90
                                                break;
×
91

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

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

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

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

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

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

183
                                CadTemplate template = null;
×
184

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

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

200
                                                break;
×
201
                                        case DxfFileToken.TableDimstyle:
202
                                                template = this.readTableEntry(new CadDimensionStyleTemplate(), this.readDimensionStyle);
×
203
                                                break;
×
204
                                        case DxfFileToken.TableLayer:
205
                                                template = this.readTableEntry(new CadLayerTemplate(), this.readLayer);
×
206
                                                break;
×
207
                                        case DxfFileToken.TableLinetype:
208
                                                template = this.readTableEntry(new CadLineTypeTemplate(), this.readLineType);
×
209
                                                break;
×
210
                                        case DxfFileToken.TableStyle:
211
                                                template = this.readTableEntry(new CadTableEntryTemplate<TextStyle>(new TextStyle()), this.readTextStyle);
×
212
                                                break;
×
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);
×
218
                                                break;
×
219
                                        case DxfFileToken.TableVport:
220
                                                template = this.readTableEntry(new CadVPortTemplate(), this.readVPort);
×
221
                                                break;
×
222
                                        default:
223
                                                Debug.Fail($"Unhandeled table {tableTemplate.CadObject.ObjectName}.");
×
224
                                                break;
×
225
                                }
226

227
                                //tableTemplate.EntryHandles.Add(template.CadObject.Handle);
228
                                tableTemplate.CadObject.Add((T)template.CadObject);
×
229

230
                                //Add the object and the template to the builder
231
                                this._builder.AddTemplate(template);
×
232
                        }
×
233
                }
×
234

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

240
                        while (this._reader.DxfCode != DxfCode.Start)
×
241
                        {
×
242
                                if (!readEntry(template, map.SubClasses[template.CadObject.SubclassMarker]))
×
243
                                {
×
244
                                        this.readCommonTableEntryCodes(template, out bool isExtendedData, map);
×
245
                                        if (isExtendedData)
×
246
                                                continue;
×
247
                                }
×
248

249
                                if (this._reader.DxfCode != DxfCode.Start)
×
250
                                        this._reader.ReadNext();
×
251
                        }
×
252

253
                        return template;
×
254
                }
×
255

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

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

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

288
                private bool readBlockRecord(CadTableEntryTemplate<BlockRecord> template, DxfClassMap map)
289
                {
×
290
                        CadBlockRecordTemplate tmp = (CadBlockRecordTemplate)template;
×
291

292
                        switch (this._reader.Code)
×
293
                        {
294
                                case 340:
295
                                        tmp.LayoutHandle = this._reader.ValueAsHandle;
×
296
                                        return true;
×
297
                                default:
298
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
299
                        }
300
                }
×
301

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

306
                        CadDimensionStyleTemplate tmp = (CadDimensionStyleTemplate)template;
×
307

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

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

548
                        CadLayerTemplate tmp = (CadLayerTemplate)template;
×
549

550
                        switch (this._reader.Code)
×
551
                        {
552
                                case 6:
553
                                        tmp.LineTypeName = this._reader.ValueAsString;
×
554
                                        return true;
×
555
                                case 62:
556
                                        short index = this._reader.ValueAsShort;
×
557
                                        if (index < 0)
×
558
                                        {
×
559
                                                template.CadObject.IsOn = false;
×
560
                                                index = Math.Abs(index);
×
561
                                        }
×
562
                                        template.CadObject.Color = new Color(index);
×
563
                                        return true;
×
564
                                case 347:
565
                                        tmp.MaterialHandle = this._reader.ValueAsHandle;
×
566
                                        return true;
×
567
                                case 348:
568
                                        //Unknown code value, always 0
569
                                        return true;
×
570
                                case 390:
571
                                        template.CadObject.PlotStyleName = this._reader.ValueAsHandle;
×
572
                                        return true;
×
573
                                case 430:
574
                                        tmp.TrueColorName = this._reader.ValueAsString;
×
575
                                        return true;
×
576
                                default:
577
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
578
                        }
579
                }
×
580

581
                private bool readLineType(CadTableEntryTemplate<LineType> template, DxfClassMap map)
582
                {
×
583
                        Debug.Assert(map.Name == DxfSubclassMarker.Linetype);
×
584

585
                        CadLineTypeTemplate tmp = (CadLineTypeTemplate)template;
×
586

587
                        switch (this._reader.Code)
×
588
                        {
589
                                case 40:
590
                                        tmp.TotalLen = this._reader.ValueAsDouble;
×
591
                                        return true;
×
592
                                case 49:
593
                                        do
594
                                        {
×
595
                                                tmp.SegmentTemplates.Add(this.readLineTypeSegment());
×
596
                                        }
×
597
                                        while (this._reader.Code == 49);
×
598
                                        return true;
×
599
                                case 73:
600
                                        //number of segments
601
                                        return true;
×
602
                                default:
603
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
604
                        }
605
                }
×
606

607
                private SegmentTemplate readLineTypeSegment()
608
                {
×
609
                        SegmentTemplate template = new SegmentTemplate();
×
610
                        template.Segment.Length = this._reader.ValueAsDouble;
×
611

612
                        //Jump the 49 code
613
                        this._reader.ReadNext();
×
614

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

647
                                this._reader.ReadNext();
×
648
                        }
×
649

650
                        return template;
×
651
                }
×
652

653
                private bool readTextStyle(CadTableEntryTemplate<TextStyle> template, DxfClassMap map)
654
                {
×
655
                        Debug.Assert(map.Name == DxfSubclassMarker.TextStyle);
×
656

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

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

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

682
                private bool readView(CadTableEntryTemplate<View> template, DxfClassMap map)
683
                {
×
684
                        Debug.Assert(map.Name == DxfSubclassMarker.View);
×
685

686
                        CadViewTemplate tmp = template as CadViewTemplate;
×
687

688
                        switch (this._reader.Code)
×
689
                        {
690
                                case 348:
691
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
×
692
                                        return true;
×
693
                                default:
694
                                        return this.tryAssignCurrentValue(template.CadObject, map);
×
695
                        }
696
                }
×
697

698
                private bool readVPort(CadTableEntryTemplate<VPort> template, DxfClassMap map)
699
                {
×
700
                        Debug.Assert(map.Name == DxfSubclassMarker.VPort);
×
701

702
                        CadVPortTemplate tmp = template as CadVPortTemplate;
×
703

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