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

DomCR / ACadSharp / 14887897407

07 May 2025 04:00PM UTC coverage: 75.489% (+0.03%) from 75.458%
14887897407

Pull #657

github

web-flow
Merge 23453c8d4 into eb394c3fa
Pull Request #657: issue-649 XRecord

5741 of 8357 branches covered (68.7%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 1 file covered. (0.0%)

155 existing lines in 10 files now uncovered.

22882 of 29560 relevant lines covered (77.41%)

83098.02 hits per line

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

74.63
/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)
266✔
14
                {
266✔
15
                }
266✔
16

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

22
                        //Loop until the section ends
23
                        while (this._reader.ValueAsString != DxfFileToken.EndSection)
9,368✔
24
                        {
9,102✔
25
                                try
26
                                {
9,102✔
27
                                        if (this._reader.ValueAsString == DxfFileToken.Block)
9,102!
28
                                                this.readBlock();
9,102✔
29
                                        else
30
                                                throw new DxfException($"Unexpected token at the BLOCKS table: {this._reader.ValueAsString}", this._reader.Position);
×
31
                                }
9,102✔
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,102✔
46
                }
266✔
47

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

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

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

57
                        Block blckEntity = new Block();
9,102✔
58
                        CadEntityTemplate template = new CadEntityTemplate(blckEntity);
9,102✔
59

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

64
                        while (this._reader.DxfCode != DxfCode.Start)
111,730✔
65
                        {
102,628✔
66
                                switch (this._reader.Code)
102,628✔
67
                                {
68
                                        case 2:
69
                                        case 3:
70
                                                name = this._reader.ValueAsString;
18,204✔
71
                                                if (name.Equals("$MODEL_SPACE", StringComparison.OrdinalIgnoreCase))
18,204✔
72
                                                {
72✔
73
                                                        name = BlockRecord.ModelSpaceName;
72✔
74
                                                }
72✔
75
                                                else if (name.Equals("$PAPER_SPACE", StringComparison.OrdinalIgnoreCase))
18,132✔
76
                                                {
72✔
77
                                                        name = BlockRecord.PaperSpaceName;
72✔
78
                                                }
72✔
79

80
                                                if (record == null && this._builder.TryGetTableEntry(name, out record))
18,204!
81
                                                {
×
82
                                                        record.BlockEntity = blckEntity;
×
83
                                                }
×
84
                                                else if (record == null)
18,204✔
85
                                                {
6,480✔
86
                                                        this._builder.Notify($"Block record [{name}] not found at line {this._reader.Position}", NotificationType.Warning);
6,480✔
87
                                                }
6,480✔
88
                                                break;
18,204✔
89
                                        case 330:
90
                                                if (record == null && this._builder.TryGetCadObject(this._reader.ValueAsHandle, out record))
5,862!
91
                                                {
5,862✔
92
                                                        record.BlockEntity = blckEntity;
5,862✔
93
                                                }
5,862✔
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;
5,862✔
99
                                        default:
100
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockBegin]))
78,562✔
101
                                                {
32,860✔
102
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
32,860✔
103
                                                        if (isExtendedData)
32,860✔
104
                                                                continue;
×
105
                                                }
32,860✔
106
                                                break;
78,562✔
107
                                }
108

109
                                this._reader.ReadNext();
102,628✔
110
                        }
102,628✔
111

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

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

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

131
                        while (this._reader.ValueAsString != DxfFileToken.EndBlock)
157,206✔
132
                        {
148,104✔
133
                                CadEntityTemplate entityTemplate = null;
148,104✔
134

135
                                try
136
                                {
148,104✔
137
                                        entityTemplate = this.readEntity();
148,104✔
138
                                }
148,104✔
139
                                catch (Exception ex)
×
140
                                {
×
141
                                        if (!this._builder.Configuration.Failsafe)
×
UNCOV
142
                                                throw;
×
143

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

146
                                        while (this._reader.DxfCode != DxfCode.Start)
×
147
                                                this._reader.ReadNext();
×
UNCOV
148
                                }
×
149

150
                                if (entityTemplate == null)
148,104✔
151
                                        continue;
10,296✔
152

153
                                //Add the object and the template to the builder
154
                                this._builder.AddTemplate(entityTemplate);
137,808✔
155

156
                                if (entityTemplate.OwnerHandle == null)
137,808✔
157
                                {
99,792✔
158
                                        recordTemplate.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
99,792✔
159
                                }
99,792✔
160
                                else if (this._builder.TryGetObjectTemplate(entityTemplate.OwnerHandle, out CadBlockRecordTemplate owner))
38,016✔
161
                                {
38,016✔
162
                                        owner.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
38,016✔
163
                                }
38,016✔
164
                        }
137,808✔
165

166
                        this.readBlockEnd(record.BlockEnd);
9,102✔
167
                        this._builder.AddTemplate(template);
9,102✔
168
                }
9,102✔
169

170
                private void readBlockEnd(BlockEnd block)
171
                {
9,102✔
172
                        DxfMap map = DxfMap.Create<BlockEnd>();
9,102✔
173
                        CadEntityTemplate template = new CadEntityTemplate(block);
9,102✔
174

175
                        if (this._reader.DxfCode == DxfCode.Start)
9,102✔
176
                        {
9,102✔
177
                                this._reader.ReadNext();
9,102✔
178
                        }
9,102✔
179

180
                        while (this._reader.DxfCode != DxfCode.Start)
50,944✔
181
                        {
41,842✔
182
                                switch (this._reader.Code)
41,842✔
183
                                {
184
                                        default:
185
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockEnd]))
41,842✔
186
                                                {
41,842✔
187
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
41,842✔
188
                                                        if (isExtendedData)
41,842✔
UNCOV
189
                                                                continue;
×
190
                                                }
41,842✔
191
                                                break;
41,842✔
192
                                }
193

194
                                this._reader.ReadNext();
41,842✔
195
                        }
41,842✔
196

197
                        this._builder.AddTemplate(template);
9,102✔
198
                }
9,102✔
199
        }
200
}
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