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

DomCR / ACadSharp / 12950899724

24 Jan 2025 01:47PM UTC coverage: 76.029% (+0.06%) from 75.974%
12950899724

push

github

DomCR
Merge branch 'master' of https://github.com/DomCR/ACadSharp

5286 of 7676 branches covered (68.86%)

Branch coverage included in aggregate %.

7 of 8 new or added lines in 3 files covered. (87.5%)

11 existing lines in 2 files now uncovered.

21099 of 27028 relevant lines covered (78.06%)

39039.17 hits per line

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

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

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

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

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

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

55
                        DxfMap map = DxfMap.Create<Block>();
2,879✔
56

57
                        Block blckEntity = new Block();
2,879✔
58
                        CadEntityTemplate template = new CadEntityTemplate(blckEntity);
2,879✔
59

60
                        string name = null;
2,879✔
61
                        BlockRecord record = null;
2,879✔
62
                        CadBlockRecordTemplate recordTemplate = null;
2,879✔
63

64
                        while (this._reader.DxfCode != DxfCode.Start)
34,410✔
65
                        {
31,531✔
66
                                switch (this._reader.Code)
31,531✔
67
                                {
68
                                        case 2:
69
                                        case 3:
70
                                                name = this._reader.ValueAsString;
5,758✔
71
                                                if (name.Equals("$MODEL_SPACE", StringComparison.OrdinalIgnoreCase))
5,758✔
72
                                                {
40✔
73
                                                        name = BlockRecord.ModelSpaceName;
40✔
74
                                                }
40✔
75
                                                else if (name.Equals("$PAPER_SPACE", StringComparison.OrdinalIgnoreCase))
5,718✔
76
                                                {
40✔
77
                                                        name = BlockRecord.PaperSpaceName;
40✔
78
                                                }
40✔
79

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

109
                                this._reader.ReadNext();
31,531✔
110
                        }
31,531✔
111

112
                        if (record == null)
2,879✔
113
                        {
880✔
114
                                record = new BlockRecord(name);
880✔
115
                                record.BlockEntity = blckEntity;
880✔
116
                                recordTemplate = new CadBlockRecordTemplate(record);
880✔
117

118
                                this._builder.BlockRecords.Add(record);
880✔
119

120
                                if (recordTemplate.CadObject.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
880✔
121
                                {
20✔
122
                                        this._builder.ModelSpaceTemplate = recordTemplate;
20✔
123
                                }
20✔
124
                        }
880✔
125
                        else
126
                        {
1,999✔
127
                                recordTemplate = new CadBlockRecordTemplate(record);
1,999✔
128
                        }
1,999✔
129

130
                        while (this._reader.ValueAsString != DxfFileToken.EndBlock)
53,441✔
131
                        {
50,562✔
132
                                CadEntityTemplate entityTemplate = null;
50,562✔
133

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

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

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

149
                                if (entityTemplate == null)
50,562✔
150
                                        continue;
5,280✔
151

152
                                //Add the object and the template to the builder
153
                                this._builder.AddTemplate(entityTemplate);
45,282✔
154
                                recordTemplate.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
45,282✔
155
                        }
45,282✔
156

157
                        this.readBlockEnd(record.BlockEnd);
2,879✔
158
                        this._builder.AddTemplate(template);
2,879✔
159
                }
2,879✔
160

161
                private void readBlockEnd(BlockEnd block)
162
                {
2,879✔
163
                        DxfMap map = DxfMap.Create<BlockEnd>();
2,879✔
164
                        CadEntityTemplate template = new CadEntityTemplate(block);
2,879✔
165

166
                        if (this._reader.DxfCode == DxfCode.Start)
2,879✔
167
                        {
2,879✔
168
                                this._reader.ReadNext();
2,879✔
169
                        }
2,879✔
170

171
                        while (this._reader.DxfCode != DxfCode.Start)
15,040✔
172
                        {
12,161✔
173
                                switch (this._reader.Code)
12,161✔
174
                                {
175
                                        default:
176
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockEnd]))
12,161✔
177
                                                {
12,161✔
178
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
12,161✔
179
                                                        if (isExtendedData)
12,161✔
UNCOV
180
                                                                continue;
×
181
                                                }
12,161✔
182
                                                break;
12,161✔
183
                                }
184

185
                                this._reader.ReadNext();
12,161✔
186
                        }
12,161✔
187

188
                        this._builder.AddTemplate(template);
2,879✔
189
                }
2,879✔
190
        }
191
}
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