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

DomCR / ACadSharp / 19747691062

27 Nov 2025 08:58PM UTC coverage: 77.833% (-0.2%) from 78.079%
19747691062

Pull #898

github

web-flow
Merge 7246c0e16 into b4f4477ec
Pull Request #898: DimensionStyle Overrides

7643 of 10693 branches covered (71.48%)

Branch coverage included in aggregate %.

481 of 674 new or added lines in 7 files covered. (71.36%)

54 existing lines in 7 files now uncovered.

28210 of 35371 relevant lines covered (79.75%)

134840.38 hits per line

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

74.27
/src/ACadSharp/IO/DXF/DxfStreamReader/DxfBlockSectionReader.cs
1
using ACadSharp.Blocks;
2
using ACadSharp.Exceptions;
3
using ACadSharp.IO.Templates;
4
using ACadSharp.Tables;
5
using System;
6
using System.Diagnostics;
7

8
namespace ACadSharp.IO.DXF
9
{
10
        internal class DxfBlockSectionReader : DxfSectionReaderBase
11
        {
12
                public DxfBlockSectionReader(IDxfStreamReader reader, DxfDocumentBuilder builder)
13
                        : base(reader, builder)
354✔
14
                {
354✔
15
                }
354✔
16

17
                public override void Read()
18
                {
354✔
19
                        //Advance to the first value in the section
20
                        this._reader.ReadNext();
354✔
21

22
                        //Loop until the section ends
23
                        while (this._reader.ValueAsString != DxfFileToken.EndSection)
10,264✔
24
                        {
9,910✔
25
                                try
26
                                {
9,910✔
27
                                        if (this._reader.ValueAsString == DxfFileToken.Block)
9,910!
28
                                                this.readBlock();
9,910✔
29
                                        else
30
                                                throw new DxfException($"Unexpected token at the BLOCKS table: {this._reader.ValueAsString}", this._reader.Position);
×
31
                                }
9,910✔
32
                                catch (Exception ex)
×
33
                                {
×
34
                                        if (!this._builder.Configuration.Failsafe)
×
35
                                                throw;
×
36

37
                                        this._builder.Notify($"Error while reading a block at line {this._reader.Position}", NotificationType.Error, ex);
×
38

39
                                        while (!(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.EndSection)
×
40
                                                        && !(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.Block))
×
41
                                        {
×
42
                                                this._reader.ReadNext();
×
43
                                        }
×
44
                                }
×
45
                        }
9,910✔
46
                }
354✔
47

48
                private void readBlock()
49
                {
9,910✔
50
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.Block);
9,910✔
51

52
                        //Read the table name
53
                        this._reader.ReadNext();
9,910✔
54

55
                        DxfMap map = DxfMap.Create<Block>();
9,910✔
56

57
                        Block blckEntity = new Block();
9,910✔
58
                        CadBlockEntityTemplate template = new CadBlockEntityTemplate(blckEntity);
9,910✔
59

60
                        string name = null;
9,910✔
61
                        BlockRecord record = null;
9,910✔
62
                        CadBlockRecordTemplate recordTemplate = null;
9,910✔
63

64
                        while (this._reader.DxfCode != DxfCode.Start)
122,014✔
65
                        {
112,104✔
66
                                switch (this._reader.Code)
112,104✔
67
                                {
68
                                        case 2:
69
                                        case 3:
70
                                                name = this._reader.ValueAsString;
19,820✔
71
                                                if (name.Equals("$MODEL_SPACE", StringComparison.OrdinalIgnoreCase))
19,820✔
72
                                                {
76✔
73
                                                        name = BlockRecord.ModelSpaceName;
76✔
74
                                                }
76✔
75
                                                else if (name.Equals("$PAPER_SPACE", StringComparison.OrdinalIgnoreCase))
19,744✔
76
                                                {
76✔
77
                                                        name = BlockRecord.PaperSpaceName;
76✔
78
                                                }
76✔
79

80
                                                if (record == null && this._builder.TryGetTableEntry(name, out record))
19,820!
81
                                                {
×
82
                                                        record.BlockEntity = blckEntity;
×
83
                                                }
×
84
                                                else if (record == null)
19,820✔
85
                                                {
7,144✔
86
                                                        this._builder.Notify($"Block record [{name}] not found at line {this._reader.Position}", NotificationType.Warning);
7,144✔
87
                                                }
7,144✔
88
                                                break;
19,820✔
89
                                        case 330:
90
                                                if (record == null && this._builder.TryGetCadObject(this._reader.ValueAsHandle, out record))
6,338!
91
                                                {
6,338✔
92
                                                        record.BlockEntity = blckEntity;
6,338✔
93
                                                }
6,338✔
94
                                                else if (record == null)
×
95
                                                {
×
96
                                                        this._builder.Notify($"Block record with handle [{this._reader.ValueAsString}] not found at line {this._reader.Position}", NotificationType.Warning);
×
97
                                                }
×
98
                                                break;
6,338✔
99
                                        default:
100
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockBegin]))
85,946✔
101
                                                {
36,344✔
102
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
36,344✔
103
                                                        if (isExtendedData)
36,344✔
104
                                                                continue;
×
105
                                                }
36,344✔
106
                                                break;
85,946✔
107
                                }
108

109
                                this._reader.ReadNext();
112,104✔
110
                        }
112,104✔
111

112
                        if (record == null)
9,910✔
113
                        {
3,572✔
114
                                record = new BlockRecord(name);
3,572✔
115
                                record.BlockEntity = blckEntity;
3,572✔
116
                                recordTemplate = new CadBlockRecordTemplate(record);
3,572✔
117

118
                                this._builder.AddTemplate(recordTemplate);
3,572✔
119
                                this._builder.BlockRecords.Add(record);
3,572✔
120

121
                                if (recordTemplate.CadObject.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
3,572✔
122
                                {
38✔
123
                                        this._builder.ModelSpaceTemplate = recordTemplate;
38✔
124
                                }
38✔
125
                        }
3,572✔
126
                        else if (!this._builder.TryGetObjectTemplate<CadBlockRecordTemplate>(record.Handle, out recordTemplate))
6,338!
127
                        {
×
128
                                recordTemplate = new CadBlockRecordTemplate(record);
×
129
                        }
×
130

131
                        //Add the entity template for owner information
132
                        recordTemplate.BlockEntityTemplate = template;
9,910✔
133

134
                        while (this._reader.ValueAsString != DxfFileToken.EndBlock)
134,968✔
135
                        {
125,058✔
136
                                CadEntityTemplate entityTemplate = null;
125,058✔
137

138
                                try
139
                                {
125,058✔
140
                                        entityTemplate = this.readEntity();
125,058✔
141
                                }
125,058✔
142
                                catch (Exception ex)
×
UNCOV
143
                                {
×
144
                                        if (!this._builder.Configuration.Failsafe)
×
UNCOV
145
                                                throw;
×
146

147
                                        this._builder.Notify($"Error while reading a block with name {record.Name} at line {this._reader.Position}", NotificationType.Error, ex);
×
148

UNCOV
149
                                        while (this._reader.DxfCode != DxfCode.Start)
×
UNCOV
150
                                                this._reader.ReadNext();
×
151
                                }
×
152

153
                                if (entityTemplate == null)
125,058✔
UNCOV
154
                                        continue;
×
155

156
                                //Add the object and the template to the builder
157
                                this._builder.AddTemplate(entityTemplate);
125,058✔
158

159
                                if (entityTemplate.OwnerHandle == null)
125,058✔
160
                                {
84,930✔
161
                                        recordTemplate.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
84,930✔
162
                                }
84,930✔
163
                                else if (this._builder.TryGetObjectTemplate(entityTemplate.OwnerHandle, out CadBlockRecordTemplate owner))
40,128✔
164
                                {
40,128✔
165
                                        owner.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
40,128✔
166
                                }
40,128✔
167
                        }
125,058✔
168

169
                        this.readBlockEnd(record.BlockEnd);
9,910✔
170
                        this._builder.AddTemplate(template);
9,910✔
171
                }
9,910✔
172

173
                private void readBlockEnd(BlockEnd block)
174
                {
9,910✔
175
                        DxfMap map = DxfMap.Create<BlockEnd>();
9,910✔
176
                        CadEntityTemplate template = new CadEntityTemplate(block);
9,910✔
177

178
                        if (this._reader.DxfCode == DxfCode.Start)
9,910✔
179
                        {
9,910✔
180
                                this._reader.ReadNext();
9,910✔
181
                        }
9,910✔
182

183
                        while (this._reader.DxfCode != DxfCode.Start)
55,284✔
184
                        {
45,374✔
185
                                switch (this._reader.Code)
45,374✔
186
                                {
187
                                        default:
188
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockEnd]))
45,374✔
189
                                                {
45,374✔
190
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
45,374✔
191
                                                        if (isExtendedData)
45,374✔
UNCOV
192
                                                                continue;
×
193
                                                }
45,374✔
194
                                                break;
45,374✔
195
                                }
196

197
                                this._reader.ReadNext();
45,374✔
198
                        }
45,374✔
199

200
                        this._builder.AddTemplate(template);
9,910✔
201
                }
9,910✔
202
        }
203
}
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