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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

0.0
/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)
UNCOV
13
                        : base(reader, builder)
×
UNCOV
14
                {
×
UNCOV
15
                }
×
16

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

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

48
                private void readBlock()
UNCOV
49
                {
×
UNCOV
50
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.Block);
×
51

52
                        //Read the table name
UNCOV
53
                        this._reader.ReadNext();
×
54

UNCOV
55
                        DxfMap map = DxfMap.Create<Block>();
×
56

UNCOV
57
                        Block blckEntity = new Block();
×
UNCOV
58
                        CadEntityTemplate template = new CadEntityTemplate(blckEntity);
×
59

UNCOV
60
                        string name = null;
×
UNCOV
61
                        BlockRecord record = null;
×
UNCOV
62
                        CadBlockRecordTemplate recordTemplate = null;
×
63

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

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

UNCOV
109
                                this._reader.ReadNext();
×
UNCOV
110
                        }
×
111

UNCOV
112
                        if (record == null)
×
UNCOV
113
                        {
×
UNCOV
114
                                record = new BlockRecord(name);
×
UNCOV
115
                                record.BlockEntity = blckEntity;
×
UNCOV
116
                                recordTemplate = new CadBlockRecordTemplate(record);
×
117

UNCOV
118
                                this._builder.AddTemplate(recordTemplate);
×
UNCOV
119
                                this._builder.BlockRecords.Add(record);
×
120

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

UNCOV
131
                        while (this._reader.ValueAsString != DxfFileToken.EndBlock)
×
UNCOV
132
                        {
×
UNCOV
133
                                CadEntityTemplate entityTemplate = null;
×
134

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

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();
×
148
                                }
×
149

UNCOV
150
                                if (entityTemplate == null)
×
UNCOV
151
                                        continue;
×
152

153
                                //Add the object and the template to the builder
UNCOV
154
                                this._builder.AddTemplate(entityTemplate);
×
155

UNCOV
156
                                if (entityTemplate.OwnerHandle == null)
×
UNCOV
157
                                {
×
UNCOV
158
                                        recordTemplate.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
×
UNCOV
159
                                }
×
UNCOV
160
                                else if (this._builder.TryGetObjectTemplate(entityTemplate.OwnerHandle, out CadBlockRecordTemplate owner))
×
UNCOV
161
                                {
×
UNCOV
162
                                        owner.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
×
UNCOV
163
                                }
×
UNCOV
164
                        }
×
165

UNCOV
166
                        this.readBlockEnd(record.BlockEnd);
×
UNCOV
167
                        this._builder.AddTemplate(template);
×
UNCOV
168
                }
×
169

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

UNCOV
175
                        if (this._reader.DxfCode == DxfCode.Start)
×
UNCOV
176
                        {
×
UNCOV
177
                                this._reader.ReadNext();
×
UNCOV
178
                        }
×
179

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

UNCOV
194
                                this._reader.ReadNext();
×
UNCOV
195
                        }
×
196

UNCOV
197
                        this._builder.AddTemplate(template);
×
UNCOV
198
                }
×
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