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

DomCR / ACadSharp / 22357303530

24 Feb 2026 03:20PM UTC coverage: 76.903% (-0.4%) from 77.295%
22357303530

Pull #982

github

web-flow
Merge 83a48047e into 0ec85e9b1
Pull Request #982: Refactor Field, FieldList, and CadValue handling

8177 of 11532 branches covered (70.91%)

Branch coverage included in aggregate %.

3038 of 3786 new or added lines in 11 files covered. (80.24%)

47 existing lines in 3 files now uncovered.

29587 of 37574 relevant lines covered (78.74%)

150413.53 hits per line

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

51.91
/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.Objects.cs
1
using ACadSharp.IO.Templates;
2
using ACadSharp.Objects;
3
using ACadSharp.Objects.Evaluations;
4
using System;
5

6
namespace ACadSharp.IO.DWG;
7

8
internal partial class DwgObjectReader : DwgSectionIO
9
{
10
        private void readAnnotScaleObjectContextData(CadAnnotScaleObjectContextDataTemplate template)
11
        {
×
12
                this.readObjectContextData(template);
×
13

14
                template.ScaleHandle = this.handleReference();
×
15
        }
×
16

17
        private CadTemplate readBlkRefObjectContextData()
18
        {
×
19
                BlockReferenceObjectContextData contextData = new BlockReferenceObjectContextData();
×
20
                CadAnnotScaleObjectContextDataTemplate template = new CadAnnotScaleObjectContextDataTemplate(contextData);
×
21

22
                this.readAnnotScaleObjectContextData(template);
×
23

24
                contextData.Rotation = this._mergedReaders.ReadBitDouble();
×
25
                contextData.InsertionPoint = this._mergedReaders.Read3BitDouble();
×
26
                contextData.XScale = this._mergedReaders.ReadBitDouble();
×
27
                contextData.YScale = this._mergedReaders.ReadBitDouble();
×
28
                contextData.ZScale = this._mergedReaders.ReadBitDouble();
×
29

30
                return template;
×
31
        }
×
32

33
        private void readBlock1PtParameter(CadBlock1PtParameterTemplate template)
34
        {
134✔
35
                this.readBlockParameter(template);
134✔
36

37
                //1010 1020 1030
38
                template.Block1PtParameter.Location = this._mergedReaders.Read3BitDouble();
134✔
39
                //170
40
                template.Block1PtParameter.Value170 = this._mergedReaders.ReadBitShort();
134✔
41
                //171
42
                template.Block1PtParameter.Value171 = this._mergedReaders.ReadBitShort();
134✔
43
                //93
44
                template.Block1PtParameter.Value93 = this._mergedReaders.ReadBitLong();
134✔
45
        }
134✔
46

47
        private void readBlock2PtParameter(CadBlock2PtParameterTemplate template)
48
        {
1✔
49
                this.readBlockParameter(template);
1✔
50

51
                //1010 1020 1030
52
                template.Block2PtParameter.FirstPoint = this._mergedReaders.Read3BitDouble();
1✔
53
                //1011 1021 1031
54
                template.Block2PtParameter.SecondPoint = this._mergedReaders.Read3BitDouble();
1✔
55

56
                //170 (always 4)
57
                for (int i = 0; i < 4; i++)
10✔
58
                {
4✔
59
                        //171 172 173 174
60
                        short n = this._mergedReaders.ReadBitShort();
4✔
61
                        for (int j = 0; j < n; j++)
12✔
62
                        {
2✔
63
                                //94 95 (I guess 96 97)
64
                                var d = this._mergedReaders.ReadBitLong();
2✔
65
                                //303 304
66
                                var e = this._mergedReaders.ReadVariableText();
2✔
67
                        }
2✔
68
                }
4✔
69

70
                for (int k = 0; k < 4; k++)
10✔
71
                {
4✔
72
                        //91 values
73
                        var f = this._mergedReaders.ReadBitLong();
4✔
74
                }
4✔
75

76
                var value177 = this._mergedReaders.ReadBitShort();
1✔
77
        }
1✔
78

79
        private void readBlockAction(CadBlockActionTemplate template)
80
        {
1✔
81
                this.readBlockElement(template);
1✔
82

83
                BlockAction blockAction = template.BlockAction;
1✔
84

85
                // 1010, 1020, 1030
86
                blockAction.ActionPoint = this._mergedReaders.Read3BitDouble();
1✔
87

88
                //71
89
                short entityCount = this._objectReader.ReadBitShort();
1✔
90
                for (int i = 0; i < entityCount; i++)
4✔
91
                {
1✔
92
                        ulong entityHandle = this.handleReference();
1✔
93
                        template.EntityHandles.Add(entityHandle);
1✔
94
                }
1✔
95

96
                // 70
97
                blockAction.Value70 = this._mergedReaders.ReadBitShort();
1✔
98
        }
1✔
99

100
        private void readBlockActionBasePt(CadBlockActionBasePtTemplate template)
101
        {
1✔
102
                this.readBlockAction(template);
1✔
103

104
                BlockActionBasePt blockActionBasePt = template.CadObject as BlockActionBasePt;
1✔
105

106
                blockActionBasePt.Value1011 = this._mergedReaders.Read3BitDouble();
1✔
107

108
                blockActionBasePt.Value92 = this._mergedReaders.ReadBitLong();
1✔
109
                blockActionBasePt.Value301 = this._mergedReaders.ReadVariableText();
1✔
110
                blockActionBasePt.Value93 = this._mergedReaders.ReadBitLong();
1✔
111
                blockActionBasePt.Value302 = this._mergedReaders.ReadVariableText();
1✔
112

113
                blockActionBasePt.Value280 = this._mergedReaders.ReadBit();
1✔
114
                blockActionBasePt.Value1012 = this._mergedReaders.Read3BitDouble();
1✔
115
        }
1✔
116

117
        private void readBlockElement(CadBlockElementTemplate template)
118
        {
271✔
119
                this.readEvaluationExpression(template);
271✔
120

121
                //300 name
122
                template.BlockElement.ElementName = this._mergedReaders.ReadVariableText();
271✔
123
                //98
124
                template.BlockElement.Value98 = this._mergedReaders.ReadBitLong();
271✔
125
                //99
126
                template.BlockElement.Value99 = this._mergedReaders.ReadBitLong();
271✔
127
                //1071
128
                template.BlockElement.Value1071 = this._mergedReaders.ReadBitLong();
271✔
129
        }
271✔
130

131
        private void readBlockGrip(CadBlockGripTemplate template)
132
        {
135✔
133
                this.readBlockElement(template);
135✔
134

135
                var blockGrip = template.CadObject as BlockGrip;
135✔
136

137
                blockGrip.Value91 = this._mergedReaders.ReadBitLong();
135✔
138
                blockGrip.Value92 = this._mergedReaders.ReadBitLong();
135✔
139
                blockGrip.Location = this._mergedReaders.Read3BitDouble();
135✔
140
                blockGrip.Value280 = this._mergedReaders.ReadBitAsShort();
135✔
141
                blockGrip.Value93 = this._mergedReaders.ReadBitLong();
135✔
142
        }
135✔
143

144
        private CadTemplate readBlockGripLocationComponent()
145
        {
804✔
146
                BlockGripExpression gripExpression = new BlockGripExpression();
804✔
147
                CadBlockGripExpressionTemplate template = new CadBlockGripExpressionTemplate(gripExpression);
804✔
148

149
                this.readEvaluationExpression(template);
804✔
150

151
                return template;
804✔
152
        }
804✔
153

154
        private void readBlockParameter(CadBlockParameterTemplate template)
155
        {
135✔
156
                this.readBlockElement(template);
135✔
157

158
                //280
159
                template.BlockParameter.Value280 = this._mergedReaders.ReadBit();
135✔
160
                //281
161
                template.BlockParameter.Value281 = this._mergedReaders.ReadBit();
135✔
162
        }
135✔
163

164
        private CadTemplate readBlockRepresentationData()
165
        {
275✔
166
                BlockRepresentationData representation = new BlockRepresentationData();
275✔
167
                CadBlockRepresentationDataTemplate template = new CadBlockRepresentationDataTemplate(representation);
275✔
168

169
                this.readCommonNonEntityData(template);
275✔
170

171
                representation.Value70 = this._mergedReaders.ReadBitShort();
275✔
172
                template.BlockHandle = this.handleReference();
275✔
173

174
                return template;
275✔
175
        }
275✔
176

177
        private CadTemplate readBlockRotateAction()
178
        {
1✔
179
                BlockRotationAction rotationAction = new();
1✔
180
                CadBlockRotationActionTemplate template = new(rotationAction);
1✔
181

182
                this.readBlockActionBasePt(template);
1✔
183

184
                rotationAction.Value94 = this._mergedReaders.ReadBitLong();
1✔
185
                rotationAction.Value303 = this._mergedReaders.ReadVariableText();
1✔
186

187
                return template;
1✔
188
        }
1✔
189

190
        private CadTemplate readBlockRotationParameter()
191
        {
1✔
192
                BlockRotationParameter blockRotationParameter = new();
1✔
193
                CadBlockRotationParameterTemplate template = new CadBlockRotationParameterTemplate(blockRotationParameter);
1✔
194

195
                this.readBlock2PtParameter(template);
1✔
196

197
                //1011 1021 1031
198
                blockRotationParameter.Point = this._mergedReaders.Read3BitDouble();
1✔
199
                //305
200
                blockRotationParameter.Name = this._mergedReaders.ReadVariableText();
1✔
201
                //306
202
                blockRotationParameter.Description = this._mergedReaders.ReadVariableText();
1✔
203
                //140
204
                blockRotationParameter.NameOffset = this._mergedReaders.ReadBitDouble();
1✔
205

206
                //307 missing text?
207

208
                blockRotationParameter.Value96 = this._mergedReaders.ReadBitLong();
1✔
209
                blockRotationParameter.Value141 = this._mergedReaders.ReadBitDouble();
1✔
210
                blockRotationParameter.Value142 = this._mergedReaders.ReadBitDouble();
1✔
211
                blockRotationParameter.Value143 = this._mergedReaders.ReadBitDouble();
1✔
212

213
                blockRotationParameter.Value175 = this._mergedReaders.ReadBitLong();
1✔
214

215
                return template;
1✔
216
        }
1✔
217

218
        private CadTemplate readBlockVisibilityParameter()
219
        {
134✔
220
                BlockVisibilityParameter blockVisibilityParameter = new BlockVisibilityParameter();
134✔
221
                CadBlockVisibilityParameterTemplate template = new CadBlockVisibilityParameterTemplate(blockVisibilityParameter);
134✔
222

223
                this.readBlock1PtParameter(template);
134✔
224

225
                //281
226
                blockVisibilityParameter.Value281 = this._mergedReaders.ReadBit();
134✔
227
                //301
228
                blockVisibilityParameter.Name = this._mergedReaders.ReadVariableText();
134✔
229
                //302
230
                blockVisibilityParameter.Description = this._mergedReaders.ReadVariableText();
134✔
231
                //missing bit??        91 should be an int
232
                blockVisibilityParameter.Value91 = this._mergedReaders.ReadBit();
134✔
233

234
                //DXF 93 Total entities count
235
                var totalEntitiesCount = this._objectReader.ReadBitLong();
134✔
236
                for (int i = 0; i < totalEntitiesCount; i++)
544✔
237
                {
138✔
238
                        //331
239
                        template.EntityHandles.Add(this.handleReference());
138✔
240
                }
138✔
241

242
                //DXF 92 states count
243
                var nstates = this._objectReader.ReadBitLong();
134✔
244
                for (int j = 0; j < nstates; j++)
1,340✔
245
                {
536✔
246
                        template.StateTemplates.Add(this.readState());
536✔
247
                }
536✔
248

249
                return template;
134✔
250
        }
134✔
251

252
        private void readEvaluationExpression(CadEvaluationExpressionTemplate template)
253
        {
1,075✔
254
                this.readCommonNonEntityData(template);
1,075✔
255

256
                //AcDbEvalExpr
257
                var unknown = this._objectReader.ReadBitLong();
1,075✔
258

259
                //98
260
                template.CadObject.Value98 = this._objectReader.ReadBitLong();
1,075✔
261
                //99
262
                template.CadObject.Value99 = this._objectReader.ReadBitLong();
1,075✔
263

264
                //Code value
265
                short code = this._mergedReaders.ReadBitShort();
1,075✔
266
                if (code > 0)
1,075✔
267
                {
804✔
268
                        var groupValue = GroupCodeValue.TransformValue(code);
804✔
269
                        switch (groupValue)
804!
270
                        {
271
                                case GroupCodeValueType.Double:
272
                                case GroupCodeValueType.ExtendedDataDouble:
273
                                        this._mergedReaders.ReadBitDouble();
804✔
274
                                        break;
804✔
275
                                default:
276
                                        throw new System.NotImplementedException($"[EvaluationExpression] Code not implemented {groupValue}");
×
277
                        }
278
                }
804✔
279

280
                //90
281
                template.CadObject.Id = this._objectReader.ReadBitLong();
1,075✔
282
        }
1,075✔
283

284
        private CadTemplate readField()
NEW
285
        {
×
NEW
286
                var field = new Field();
×
NEW
287
                CadFieldTemplate template = new CadFieldTemplate(field);
×
288

NEW
289
                this.readCommonNonEntityData(template);
×
290

291
                //TV 1 Evaluator ID TV 2,3 Field code(in DXF strings longer than 255 characters
292
                //are written in chunks of 255 characters in one 2 group and one or
293
                //more 3 groups).
NEW
294
                field.EvaluatorId = this._mergedReaders.ReadVariableText();
×
NEW
295
                field.FieldCode = this._mergedReaders.ReadVariableText();
×
296
                //BL 90 Number of child fields
NEW
297
                int nchild = this._mergedReaders.ReadBitLong();
×
NEW
298
                for (int i = 0; i < nchild; i++)
×
NEW
299
                {
×
300
                        //H 360 Child field handle (hard owner)
NEW
301
                        template.ChildrenHandles.Add(this.handleReference());
×
NEW
302
                }
×
303

304
                //BL 97 Number of field objects
NEW
305
                int nfields = this._mergedReaders.ReadBitLong();
×
NEW
306
                for (int j = 0; j < nfields; j++)
×
NEW
307
                {
×
308
                        //H 331 Field object handle (soft pointer)
NEW
309
                        template.CadObjectsHandles.Add(this.handleReference());
×
NEW
310
                }
×
311

312
                //-R2004
NEW
313
                if (this._version < ACadVersion.AC1021)
×
NEW
314
                {
×
315
                        //TV 4 Format string. After R2004 the format became part of the value object.
NEW
316
                        field.FormatString = this._mergedReaders.ReadVariableText();
×
NEW
317
                }
×
318

319
                //Common BL 91 Evaluation option flags:
NEW
320
                field.EvaluationOptionFlags = (EvaluationOptionFlags)this._mergedReaders.ReadBitLong();
×
321
                //BL 92 Filing option flags:
NEW
322
                field.FilingOptionFlags = (FilingOptionFlags)this._mergedReaders.ReadBitLong();
×
323
                //BL 96 Evaluation error code
NEW
324
                field.FieldStateFlags = (FieldStateFlags)this._mergedReaders.ReadBitLong();
×
325
                //BL 94 Field state flags:
NEW
326
                field.EvaluationStatusFlags = (EvaluationStatusFlags)this._mergedReaders.ReadBitLong();
×
327
                //BL 96 Evaluation error code
NEW
328
                field.EvaluationErrorCode = this._mergedReaders.ReadBitLong();
×
329
                //TV 300 Evaluation error message
NEW
330
                field.EvaluationErrorMessage = this._mergedReaders.ReadVariableText();
×
331

332
                //... ... The field value, see paragraph 20.4.99.
NEW
333
                template.CadValueTemplates.Add(this.readCadValue(field.Value));
×
334

335
                //TV 301,9 Value string(DXF: written in 255 character chunks)
NEW
336
                field.FormatString = this._mergedReaders.ReadVariableText();
×
NEW
337
                this._mergedReaders.ReadBitLong();
×
NEW
338
                int num3 = this._mergedReaders.ReadBitLong();
×
NEW
339
                for (int k = 0; k < num3; k++)
×
NEW
340
                {
×
341
                        //TV 6 Child field key
NEW
342
                        string key = this._mergedReaders.ReadVariableText();
×
NEW
343
                        CadValue value = new CadValue();
×
NEW
344
                        template.CadValueTemplates.Add(this.readCadValue(value));
×
NEW
345
                        field.Values.Add(key, value);
×
NEW
346
                }
×
347

NEW
348
                return template;
×
NEW
349
        }
×
350

351
        private CadValueTemplate readCadValue(CadValue value)
NEW
352
        {
×
NEW
353
                CadValueTemplate template = new CadValueTemplate(value);
×
354

355
                //R2007+:
NEW
356
                if (this.R2007Plus)
×
NEW
357
                {
×
358
                        //Flags BL 93 Flags & 0x01 => type is kGeneral
NEW
359
                        value.Flags = this._mergedReaders.ReadBitLong();
×
NEW
360
                }
×
361

362
                //Common:
363
                //Data type BL 90
NEW
364
                value.ValueType = (CadValueType)this._mergedReaders.ReadBitLong();
×
NEW
365
                if (!this.R2007Plus || !value.IsEmpty)
×
NEW
366
                {
×
367
                        //Varies by type: Not present in case bit 1 in Flags is set
NEW
368
                        switch (value.ValueType)
×
369
                        {
370
                                case CadValueType.Unknown:
371
                                case CadValueType.Long:
NEW
372
                                        value.Value = this._mergedReaders.ReadBitLong();
×
NEW
373
                                        break;
×
374
                                case CadValueType.Double:
NEW
375
                                        value.Value = this._mergedReaders.ReadBitDouble();
×
NEW
376
                                        break;
×
377
                                case CadValueType.General:
378
                                case CadValueType.String:
NEW
379
                                        value.Value = this.readStringCellValue();
×
NEW
380
                                        break;
×
381
                                case CadValueType.Date:
NEW
382
                                        System.DateTime? dateTime = this.readDateCellValue();
×
NEW
383
                                        if (dateTime.HasValue)
×
NEW
384
                                        {
×
NEW
385
                                                value.Value = dateTime.Value;
×
NEW
386
                                        }
×
NEW
387
                                        break;
×
388
                                case CadValueType.Point2D:
NEW
389
                                        value.Value = this.readCellValueXY();
×
NEW
390
                                        break;
×
391
                                case CadValueType.Point3D:
NEW
392
                                        value.Value = this.readCellValueXYZ();
×
NEW
393
                                        break;
×
394
                                case CadValueType.Handle:
NEW
395
                                        template.ValueHandle = this.handleReference();
×
NEW
396
                                        break;
×
397
                                case CadValueType.Buffer:
398
                                case CadValueType.ResultBuffer:
399
                                default:
NEW
400
                                        throw new NotImplementedException();
×
401
                        }
NEW
402
                }
×
403

404
                //R2007+:
NEW
405
                if (this.R2007Plus)
×
NEW
406
                {
×
407
                        //Unit type BL 94 0 = no units, 1 = distance, 2 = angle, 4 = area, 8 = volume
NEW
408
                        value.Units = (CadValueUnitType)this._mergedReaders.ReadBitLong();
×
409
                        //Format String TV 300
NEW
410
                        value.Format = this._mergedReaders.ReadVariableText();
×
411
                        //Value String TV 302
NEW
412
                        value.FormattedValue = this._mergedReaders.ReadVariableText();
×
NEW
413
                }
×
414

NEW
415
                return template;
×
NEW
416
        }
×
417

418
        private CadTemplate readFieldList()
NEW
419
        {
×
NEW
420
                FieldList fieldList = new FieldList();
×
NEW
421
                CadFieldListTemplate template = new CadFieldListTemplate(fieldList);
×
422

NEW
423
                this.readCommonNonEntityData(template);
×
424

425
                //BL Number of fields
NEW
426
                int nhandles = this._mergedReaders.ReadBitLong();
×
427
                //B Unknown
NEW
428
                this._mergedReaders.ReadBit();
×
NEW
429
                for (int i = 0; i < nhandles; i++)
×
NEW
430
                {
×
431
                        //H 330 Field handle (soft pointer)
NEW
432
                        template.OwnedObjectsHandlers.Add(this.handleReference());
×
NEW
433
                }
×
434

NEW
435
                return template;
×
NEW
436
        }
×
437

438
        private CadTemplate readMTextAttributeObjectContextData()
NEW
439
        {
×
440
                //TODO: MTextAttributeObjectContextData for dwg
NEW
441
                MTextAttributeObjectContextData contextData = new();
×
NEW
442
                CadAnnotScaleObjectContextDataTemplate template = new CadAnnotScaleObjectContextDataTemplate(contextData);
×
443

444
                //this.readAnnotScaleObjectContextData(template);
445

NEW
446
                return null;
×
NEW
447
        }
×
448

449
        private void readObjectContextData(CadTemplate template)
450
        {
×
451
                this.readCommonNonEntityData(template);
×
452

453
                ObjectContextData contextData = (ObjectContextData)template.CadObject;
×
454

455
                //BS        70        Version (default value is 3).
456
                contextData.Version = _objectReader.ReadBitShort();
×
457
                //B        290        Default flag (default value is false).
458
                contextData.Default = _objectReader.ReadBit();
×
459
        }
×
460

461
        private CadBlockVisibilityParameterTemplate.StateTemplate readState()
462
        {
536✔
463
                CadBlockVisibilityParameterTemplate.StateTemplate template = new CadBlockVisibilityParameterTemplate.StateTemplate();
536✔
464

465
                template.State.Name = this._textReader.ReadVariableText();
536✔
466

467
                //DXF 94 subset count 1
468
                int n1 = this._objectReader.ReadBitLong();
536✔
469
                for (int i = 0; i < n1; i++)
1,894✔
470
                {
411✔
471
                        //332
472
                        template.EntityHandles.Add(this.handleReference());
411✔
473
                }
411✔
474

475
                //DXF 95 subset count 2
476
                var n2 = this._objectReader.ReadBitLong();
536✔
477
                for (int i = 0; i < n2; i++)
4,264✔
478
                {
1,596✔
479
                        //333
480
                        template.ExpressionHandles.Add(this.handleReference());
1,596✔
481
                }
1,596✔
482

483
                return template;
536✔
484
        }
536✔
485
}
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