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

DomCR / ACadSharp / 27057848958

06 Jun 2026 08:48AM UTC coverage: 77.026% (+0.04%) from 76.989%
27057848958

Pull #1097

github

web-flow
Merge 7eeb8a47a into 2addb6ad2
Pull Request #1097: Add DWG reading for BLOCKLINEARPARAMETER

8628 of 12157 branches covered (70.97%)

Branch coverage included in aggregate %.

28 of 32 new or added lines in 4 files covered. (87.5%)

270 existing lines in 6 files now uncovered.

31155 of 39492 relevant lines covered (78.89%)

157274.27 hits per line

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

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

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

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

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

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

40
                                        while (!(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.EndSection)
×
41
                                                        && !(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.Block))
×
42
                                        {
×
43
                                                this._reader.ReadNext();
×
44
                                        }
×
UNCOV
45
                                }
×
46
                        }
8,797✔
47
                }
255✔
48

49
                private void readBlock()
50
                {
8,797✔
51
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.Block);
8,797✔
52

53
                        //Read the table name
54
                        this._reader.ReadNext();
8,797✔
55

56
                        DxfMap map = DxfMap.Create<Block>();
8,797✔
57

58
                        Block blckEntity = new Block();
8,797✔
59
                        CadBlockEntityTemplate template = new CadBlockEntityTemplate(blckEntity);
8,797✔
60

61
                        string name = null;
8,797✔
62
                        BlockRecord record = null;
8,797✔
63
                        CadBlockRecordTemplate recordTemplate = null;
8,797✔
64

65
                        while (this._reader.DxfCode != DxfCode.Start)
107,662✔
66
                        {
98,865✔
67
                                switch (this._reader.Code)
98,865✔
68
                                {
69
                                        case 2:
70
                                        case 3:
71
                                                name = this._reader.ValueAsString;
17,594✔
72
                                                if (name.Equals("$MODEL_SPACE", StringComparison.OrdinalIgnoreCase))
17,594✔
73
                                                {
68✔
74
                                                        name = BlockRecord.ModelSpaceName;
68✔
75
                                                }
68✔
76
                                                else if (name.Equals("$PAPER_SPACE", StringComparison.OrdinalIgnoreCase))
17,526✔
77
                                                {
68✔
78
                                                        name = BlockRecord.PaperSpaceName;
68✔
79
                                                }
68✔
80

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

110
                                this._reader.ReadNext();
98,865✔
111
                        }
98,865✔
112

113
                        if (record == null)
8,797✔
114
                        {
3,230✔
115
                                record = new BlockRecord(name);
3,230✔
116
                                record.BlockEntity = blckEntity;
3,230✔
117
                                recordTemplate = new CadBlockRecordTemplate(record);
3,230✔
118

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

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

132
                        //Add the entity template for owner information
133
                        recordTemplate.BlockEntityTemplate = template;
8,797✔
134

135
                        while (this._reader.ValueAsString != DxfFileToken.EndBlock)
120,845✔
136
                        {
112,048✔
137
                                CadEntityTemplate entityTemplate = null;
112,048✔
138

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

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

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

154
                                if (entityTemplate == null)
112,048✔
UNCOV
155
                                        continue;
×
156

157
                                //Add the object and the template to the builder
158
                                this._builder.AddTemplate(entityTemplate);
112,048✔
159

160
                                if (entityTemplate.OwnerHandle == null)
112,048✔
161
                                {
76,058✔
162
                                        recordTemplate.ReferenceTemplates.Add(entityTemplate);
76,058✔
163
                                }
76,058✔
164
                                else if (this._builder.TryGetObjectTemplate(entityTemplate.OwnerHandle, out ICadOwnerTemplate owner))
35,990!
165
                                {
35,990✔
166
                                        owner.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
35,990✔
167
                                }
35,990✔
168
                                else
169
                                {
×
170
                                        this._builder.OrphanTemplates.Add(entityTemplate);
×
UNCOV
171
                                }
×
172
                        }
112,048✔
173

174
                        this.readBlockEnd(record.BlockEnd);
8,797✔
175
                        this._builder.AddTemplate(template);
8,797✔
176
                }
8,797✔
177

178
                private void readBlockEnd(BlockEnd block)
179
                {
8,797✔
180
                        DxfMap map = DxfMap.Create<BlockEnd>();
8,797✔
181
                        CadEntityTemplate template = new CadEntityTemplate(block);
8,797✔
182

183
                        if (this._reader.DxfCode == DxfCode.Start)
8,797✔
184
                        {
8,797✔
185
                                this._reader.ReadNext();
8,797✔
186
                        }
8,797✔
187

188
                        while (this._reader.DxfCode != DxfCode.Start)
48,987✔
189
                        {
40,190✔
190
                                switch (this._reader.Code)
40,190✔
191
                                {
192
                                        default:
193
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockEnd]))
40,190✔
194
                                                {
40,190✔
195
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
40,190✔
196
                                                        if (isExtendedData)
40,190✔
UNCOV
197
                                                                continue;
×
198
                                                }
40,190✔
199
                                                break;
40,190✔
200
                                }
201

202
                                this._reader.ReadNext();
40,190✔
203
                        }
40,190✔
204

205
                        this._builder.AddTemplate(template);
8,797✔
206
                }
8,797✔
207
        }
208
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc