• 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/DxfSectionReaderBase.cs
1
using ACadSharp.Entities;
2
using ACadSharp.IO.Templates;
3
using ACadSharp.Objects;
4
using ACadSharp.Tables;
5
using ACadSharp.XData;
6
using CSMath;
7
using CSUtilities.Converters;
8
using System;
9
using System.Collections.Generic;
10
using System.Diagnostics;
11
using System.Linq;
12

13
namespace ACadSharp.IO.DXF
14
{
15
        internal abstract class DxfSectionReaderBase
16
        {
17
                public delegate bool ReadEntityDelegate<T>(CadEntityTemplate template, DxfMap map, string subclass = null) where T : Entity;
18

19
                protected readonly IDxfStreamReader _reader;
20
                protected readonly DxfDocumentBuilder _builder;
21

UNCOV
22
                public DxfSectionReaderBase(IDxfStreamReader reader, DxfDocumentBuilder builder)
×
UNCOV
23
                {
×
UNCOV
24
                        this._reader = reader;
×
UNCOV
25
                        this._builder = builder;
×
UNCOV
26
                }
×
27

28
                public abstract void Read();
29

30
                protected void readCommonObjectData(out string name, out ulong handle, out ulong? ownerHandle, out ulong? xdictHandle, out HashSet<ulong> reactors)
UNCOV
31
                {
×
UNCOV
32
                        name = null;
×
UNCOV
33
                        handle = 0;
×
UNCOV
34
                        ownerHandle = null;
×
UNCOV
35
                        xdictHandle = null;
×
UNCOV
36
                        reactors = new HashSet<ulong>();
×
37

UNCOV
38
                        if (this._reader.DxfCode == DxfCode.Start
×
UNCOV
39
                                        || this._reader.DxfCode == DxfCode.Subclass)
×
40
                                this._reader.ReadNext();
×
41

42
                        //Loop until the common data end
UNCOV
43
                        while (this._reader.DxfCode != DxfCode.Start
×
UNCOV
44
                                        && this._reader.DxfCode != DxfCode.Subclass)
×
UNCOV
45
                        {
×
UNCOV
46
                                switch (this._reader.Code)
×
47
                                {
48
                                        //Table name
49
                                        case 2:
UNCOV
50
                                                name = this._reader.ValueAsString;
×
UNCOV
51
                                                break;
×
52
                                        //Handle
53
                                        case 5:
54
                                        case 105:
UNCOV
55
                                                handle = this._reader.ValueAsHandle;
×
UNCOV
56
                                                break;
×
57
                                        //Start of application - defined group
58
                                        case 102:
UNCOV
59
                                                this.readDefinedGroups(out xdictHandle, out reactors);
×
UNCOV
60
                                                break;
×
61
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
62
                                        case 330:
UNCOV
63
                                                ownerHandle = this._reader.ValueAsHandle;
×
UNCOV
64
                                                break;
×
65
                                        case 71:
66
                                        //Number of entries for dimension style table
67
                                        case 340:
68
                                        //Dimension table has the handles of the styles at the begining
69
                                        default:
UNCOV
70
                                                this._builder.Notify($"Unhandled dxf code {this._reader.Code} at line {this._reader.Position}.");
×
UNCOV
71
                                                break;
×
72
                                }
73

UNCOV
74
                                this._reader.ReadNext();
×
UNCOV
75
                        }
×
UNCOV
76
                }
×
77

78
                [Obsolete("Only needed for SortEntitiesTable but it should be removed")]
79
                protected void readCommonObjectData(CadTemplate template)
UNCOV
80
                {
×
UNCOV
81
                        while (this._reader.DxfCode != DxfCode.Subclass)
×
UNCOV
82
                        {
×
UNCOV
83
                                switch (this._reader.Code)
×
84
                                {
85
                                        //object name
86
                                        case 0:
87
                                                Debug.Assert(template.CadObject.ObjectName == this._reader.ValueAsString);
×
88
                                                break;
×
89
                                        //Handle
90
                                        case 5:
UNCOV
91
                                                template.CadObject.Handle = this._reader.ValueAsHandle;
×
UNCOV
92
                                                break;
×
93
                                        //Start of application - defined group
94
                                        case 102:
UNCOV
95
                                                this.readDefinedGroups(template);
×
UNCOV
96
                                                break;
×
97
                                        //Soft - pointer ID / handle to owner BLOCK_RECORD object
98
                                        case 330:
UNCOV
99
                                                template.OwnerHandle = this._reader.ValueAsHandle;
×
UNCOV
100
                                                break;
×
101
                                        default:
102
                                                this._builder.Notify($"Unhandled dxf code {this._reader.Code} at line {this._reader.Position}.", NotificationType.None);
×
103
                                                break;
×
104
                                }
105

UNCOV
106
                                this._reader.ReadNext();
×
UNCOV
107
                        }
×
UNCOV
108
                }
×
109

110
                protected void readCommonCodes(CadTemplate template, out bool isExtendedData, DxfMap map = null)
UNCOV
111
                {
×
UNCOV
112
                        isExtendedData = false;
×
113

UNCOV
114
                        switch (this._reader.Code)
×
115
                        {
116
                                //Handle
117
                                case 5:
UNCOV
118
                                        template.CadObject.Handle = this._reader.ValueAsHandle;
×
UNCOV
119
                                        break;
×
120
                                //Check with mapper
121
                                case 100:
UNCOV
122
                                        if (map != null && !map.SubClasses.ContainsKey(this._reader.ValueAsString))
×
UNCOV
123
                                        {
×
UNCOV
124
                                                this._builder.Notify($"[{template.CadObject.ObjectName}] Unidentified subclass {this._reader.ValueAsString}", NotificationType.Warning);
×
UNCOV
125
                                        }
×
UNCOV
126
                                        break;
×
127
                                //Start of application - defined group
128
                                case 102:
UNCOV
129
                                        this.readDefinedGroups(template);
×
UNCOV
130
                                        break;
×
131
                                //Soft - pointer ID / handle to owner BLOCK_RECORD object
132
                                case 330:
UNCOV
133
                                        template.OwnerHandle = this._reader.ValueAsHandle;
×
UNCOV
134
                                        break;
×
135
                                case 1001:
UNCOV
136
                                        isExtendedData = true;
×
UNCOV
137
                                        this.readExtendedData(template.EDataTemplateByAppName);
×
UNCOV
138
                                        break;
×
139
                                default:
UNCOV
140
                                        this._builder.Notify($"[{template.CadObject.SubclassMarker}] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
UNCOV
141
                                        break;
×
142
                        }
UNCOV
143
                }
×
144

145
                protected CadEntityTemplate readEntity()
UNCOV
146
                {
×
UNCOV
147
                        switch (this._reader.ValueAsString)
×
148
                        {
149
                                case DxfFileToken.EntityAttribute:
UNCOV
150
                                        return this.readEntityCodes<AttributeEntity>(new CadAttributeTemplate(new AttributeEntity()), this.readAttributeDefinition);
×
151
                                case DxfFileToken.EntityAttributeDefinition:
UNCOV
152
                                        return this.readEntityCodes<AttributeDefinition>(new CadAttributeTemplate(new AttributeDefinition()), this.readAttributeDefinition);
×
153
                                case DxfFileToken.EntityArc:
UNCOV
154
                                        return this.readEntityCodes<Arc>(new CadEntityTemplate<Arc>(), this.readArc);
×
155
                                case DxfFileToken.EntityCircle:
UNCOV
156
                                        return this.readEntityCodes<Circle>(new CadEntityTemplate<Circle>(), this.readEntitySubclassMap);
×
157
                                case DxfFileToken.EntityDimension:
UNCOV
158
                                        return this.readEntityCodes<Dimension>(new CadDimensionTemplate(), this.readDimension);
×
159
                                case DxfFileToken.Entity3DFace:
UNCOV
160
                                        return this.readEntityCodes<Face3D>(new CadEntityTemplate<Face3D>(), this.readEntitySubclassMap);
×
161
                                case DxfFileToken.EntityEllipse:
UNCOV
162
                                        return this.readEntityCodes<Ellipse>(new CadEntityTemplate<Ellipse>(), this.readEntitySubclassMap);
×
163
                                case DxfFileToken.EntityLeader:
UNCOV
164
                                        return this.readEntityCodes<Leader>(new CadLeaderTemplate(), this.readLeader);
×
165
                                case DxfFileToken.EntityLine:
UNCOV
166
                                        return this.readEntityCodes<Line>(new CadEntityTemplate<Line>(), this.readEntitySubclassMap);
×
167
                                case DxfFileToken.EntityLwPolyline:
UNCOV
168
                                        return this.readEntityCodes<LwPolyline>(new CadEntityTemplate<LwPolyline>(), this.readLwPolyline);
×
169
                                case DxfFileToken.EntityMesh:
UNCOV
170
                                        return this.readEntityCodes<Mesh>(new CadMeshTemplate(), this.readMesh);
×
171
                                case DxfFileToken.EntityHatch:
UNCOV
172
                                        return this.readEntityCodes<Hatch>(new CadHatchTemplate(), this.readHatch);
×
173
                                case DxfFileToken.EntityInsert:
UNCOV
174
                                        return this.readEntityCodes<Insert>(new CadInsertTemplate(), this.readInsert);
×
175
                                case DxfFileToken.EntityMText:
UNCOV
176
                                        return this.readEntityCodes<MText>(new CadTextEntityTemplate(new MText()), this.readTextEntity);
×
177
                                case DxfFileToken.EntityMLine:
UNCOV
178
                                        return this.readEntityCodes<MLine>(new CadMLineTemplate(), this.readMLine);
×
179
                                case DxfFileToken.EntityPdfUnderlay:
UNCOV
180
                                        return this.readEntityCodes<PdfUnderlay>(new CadUnderlayTemplate<PdfUnderlayDefinition>(new PdfUnderlay()), this.readUnderlayEntity<PdfUnderlayDefinition>);
×
181
                                case DxfFileToken.EntityPoint:
UNCOV
182
                                        return this.readEntityCodes<Point>(new CadEntityTemplate<Point>(), this.readEntitySubclassMap);
×
183
                                case DxfFileToken.EntityPolyline:
UNCOV
184
                                        return this.readPolyline();
×
185
                                case DxfFileToken.EntityRay:
UNCOV
186
                                        return this.readEntityCodes<Ray>(new CadEntityTemplate<Ray>(), this.readEntitySubclassMap);
×
187
                                case DxfFileToken.EndSequence:
UNCOV
188
                                        return this.readEntityCodes<Seqend>(new CadEntityTemplate<Seqend>(), this.readEntitySubclassMap);
×
189
                                case DxfFileToken.EntitySolid:
UNCOV
190
                                        return this.readEntityCodes<Solid>(new CadEntityTemplate<Solid>(), this.readEntitySubclassMap);
×
191
                                case DxfFileToken.EntityTable:
UNCOV
192
                                        return this.readEntityCodes<TableEntity>(new CadTableEntityTemplate(), this.readTableEntity);
×
193
                                case DxfFileToken.EntityText:
UNCOV
194
                                        return this.readEntityCodes<TextEntity>(new CadTextEntityTemplate(new TextEntity()), this.readTextEntity);
×
195
                                case DxfFileToken.EntityTolerance:
UNCOV
196
                                        return this.readEntityCodes<Tolerance>(new CadToleranceTemplate(new Tolerance()), this.readTolerance);
×
197
                                case DxfFileToken.EntityVertex:
UNCOV
198
                                        return this.readEntityCodes<Entity>(new CadVertexTemplate(), this.readVertex);
×
199
                                case DxfFileToken.EntityViewport:
UNCOV
200
                                        return this.readEntityCodes<Viewport>(new CadViewportTemplate(), this.readViewport);
×
201
                                case DxfFileToken.EntityShape:
UNCOV
202
                                        return this.readEntityCodes<Shape>(new CadShapeTemplate(new Shape()), this.readShape);
×
203
                                case DxfFileToken.EntitySpline:
UNCOV
204
                                        return this.readEntityCodes<Spline>(new CadSplineTemplate(), this.readSpline);
×
205
                                case DxfFileToken.EntityXline:
UNCOV
206
                                        return this.readEntityCodes<XLine>(new CadEntityTemplate<XLine>(), this.readEntitySubclassMap);
×
207
                                default:
UNCOV
208
                                        DxfMap map = DxfMap.Create<Entity>();
×
UNCOV
209
                                        CadUnknownEntityTemplate unknownEntityTemplate = null;
×
UNCOV
210
                                        if (this._builder.DocumentToBuild.Classes.TryGetByName(this._reader.ValueAsString, out Classes.DxfClass dxfClass))
×
UNCOV
211
                                        {
×
UNCOV
212
                                                this._builder.Notify($"Entity not supported read as an UnknownEntity: {this._reader.ValueAsString}", NotificationType.NotImplemented);
×
UNCOV
213
                                                unknownEntityTemplate = new CadUnknownEntityTemplate(new UnknownEntity(dxfClass));
×
UNCOV
214
                                        }
×
215
                                        else
UNCOV
216
                                        {
×
UNCOV
217
                                                this._builder.Notify($"Entity not supported: {this._reader.ValueAsString}", NotificationType.NotImplemented);
×
UNCOV
218
                                        }
×
219

UNCOV
220
                                        this._reader.ReadNext();
×
221

222
                                        do
UNCOV
223
                                        {
×
UNCOV
224
                                                if (unknownEntityTemplate != null && this._builder.KeepUnknownEntities)
×
UNCOV
225
                                                {
×
UNCOV
226
                                                        this.readCommonEntityCodes(unknownEntityTemplate, out bool isExtendedData, map);
×
UNCOV
227
                                                        if (isExtendedData)
×
UNCOV
228
                                                                continue;
×
UNCOV
229
                                                }
×
230

UNCOV
231
                                                this._reader.ReadNext();
×
UNCOV
232
                                        }
×
UNCOV
233
                                        while (this._reader.DxfCode != DxfCode.Start);
×
234

UNCOV
235
                                        return unknownEntityTemplate;
×
236
                        }
UNCOV
237
                }
×
238

239
                protected CadEntityTemplate readEntityCodes<T>(CadEntityTemplate template, ReadEntityDelegate<T> readEntity)
240
                        where T : Entity
UNCOV
241
                {
×
UNCOV
242
                        this._reader.ReadNext();
×
243

UNCOV
244
                        DxfMap map = DxfMap.Create<T>();
×
245

UNCOV
246
                        while (this._reader.DxfCode != DxfCode.Start)
×
UNCOV
247
                        {
×
UNCOV
248
                                if (!readEntity(template, map))
×
UNCOV
249
                                {
×
UNCOV
250
                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
×
UNCOV
251
                                        if (isExtendedData)
×
UNCOV
252
                                                continue;
×
UNCOV
253
                                }
×
254

UNCOV
255
                                if (this._reader.DxfCode != DxfCode.Start)
×
UNCOV
256
                                        this._reader.ReadNext();
×
UNCOV
257
                        }
×
258

UNCOV
259
                        return template;
×
UNCOV
260
                }
×
261

262
                protected void readCommonEntityCodes(CadEntityTemplate template, out bool isExtendedData, DxfMap map = null)
UNCOV
263
                {
×
UNCOV
264
                        isExtendedData = false;
×
UNCOV
265
                        switch (this._reader.Code)
×
266
                        {
267
                                case 6:
UNCOV
268
                                        template.LineTypeName = this._reader.ValueAsString;
×
UNCOV
269
                                        break;
×
270
                                case 8:
UNCOV
271
                                        template.LayerName = this._reader.ValueAsString;
×
UNCOV
272
                                        break;
×
273
                                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
274
                                case 67:
UNCOV
275
                                        break;
×
276
                                //Number of bytes Proxy entity graphics data
277
                                case 92:
278
                                case 160:
279
                                //Proxy entity graphics data
280
                                case 310:
UNCOV
281
                                        break;
×
282
                                case 347:
UNCOV
283
                                        template.MaterialHandle = this._reader.ValueAsHandle;
×
UNCOV
284
                                        break;
×
285
                                case 430:
UNCOV
286
                                        template.BookColorName = this._reader.ValueAsString;
×
UNCOV
287
                                        break;
×
288
                                default:
UNCOV
289
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Entity]))
×
UNCOV
290
                                        {
×
UNCOV
291
                                                this.readCommonCodes(template, out isExtendedData, map);
×
UNCOV
292
                                        }
×
UNCOV
293
                                        break;
×
294
                        }
UNCOV
295
                }
×
296

297
                protected bool checkObjectEnd(CadTemplate template, DxfMap map, Func<CadTemplate, DxfMap, bool> func)
UNCOV
298
                {
×
UNCOV
299
                        if (this._reader.DxfCode == DxfCode.Start)
×
UNCOV
300
                        {
×
UNCOV
301
                                return true;
×
302
                        }
303
                        else
UNCOV
304
                        {
×
UNCOV
305
                                return func.Invoke(template, map);
×
306
                        }
UNCOV
307
                }
×
308

309
                private bool readArc(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
310
                {
×
UNCOV
311
                        switch (this._reader.Code)
×
312
                        {
313
                                default:
UNCOV
314
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Arc]))
×
UNCOV
315
                                        {
×
UNCOV
316
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.Circle);
×
317
                                        }
UNCOV
318
                                        return true;
×
319
                        }
UNCOV
320
                }
×
321

322
                private bool readAttributeDefinition(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
323
                {
×
UNCOV
324
                        DxfClassMap emap = map.SubClasses[template.CadObject.SubclassMarker];
×
UNCOV
325
                        CadAttributeTemplate tmp = template as CadAttributeTemplate;
×
326

UNCOV
327
                        switch (this._reader.Code)
×
328
                        {
329
                                case 44:
330
                                case 46:
331
                                        return true;
×
332
                                case 101:
UNCOV
333
                                        var att = tmp.CadObject as AttributeBase;
×
UNCOV
334
                                        att.MText = new MText();
×
UNCOV
335
                                        CadTextEntityTemplate mtextTemplate = new CadTextEntityTemplate(att.MText);
×
UNCOV
336
                                        tmp.MTextTemplate = mtextTemplate;
×
UNCOV
337
                                        this.readEntityCodes<MText>(mtextTemplate, this.readTextEntity);
×
UNCOV
338
                                        return true;
×
339
                                default:
UNCOV
340
                                        if (!this.tryAssignCurrentValue(template.CadObject, emap))
×
UNCOV
341
                                        {
×
UNCOV
342
                                                return this.readTextEntity(template, map, DxfSubclassMarker.Text);
×
343
                                        }
UNCOV
344
                                        return true;
×
345
                        }
UNCOV
346
                }
×
347

348
                private bool readTableEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
349
                {
×
UNCOV
350
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
×
UNCOV
351
                        CadTableEntityTemplate tmp = template as CadTableEntityTemplate;
×
UNCOV
352
                        TableEntity table = tmp.CadObject as TableEntity;
×
353

UNCOV
354
                        switch (this._reader.Code)
×
355
                        {
356
                                case 2:
UNCOV
357
                                        tmp.BlockName = this._reader.ValueAsString;
×
UNCOV
358
                                        return true;
×
359
                                case 342:
UNCOV
360
                                        tmp.StyleHandle = this._reader.ValueAsHandle;
×
UNCOV
361
                                        return true;
×
362
                                case 343:
UNCOV
363
                                        tmp.BlockOwnerHandle = this._reader.ValueAsHandle;
×
UNCOV
364
                                        return true;
×
365
                                case 141:
UNCOV
366
                                        var row = new TableEntity.Row();
×
UNCOV
367
                                        row.Height = this._reader.ValueAsDouble;
×
UNCOV
368
                                        table.Rows.Add(row);
×
UNCOV
369
                                        return true;
×
370
                                case 142:
UNCOV
371
                                        var col = new TableEntity.Column();
×
UNCOV
372
                                        col.Width = this._reader.ValueAsDouble;
×
UNCOV
373
                                        table.Columns.Add(col);
×
UNCOV
374
                                        return true;
×
375
                                case 144:
UNCOV
376
                                        tmp.CurrentCellTemplate.FormatTextHeight = this._reader.ValueAsDouble;
×
UNCOV
377
                                        return true;
×
378
                                case 145:
UNCOV
379
                                        tmp.CurrentCell.Rotation = this._reader.ValueAsDouble;
×
UNCOV
380
                                        return true;
×
381
                                case 170:
382
                                        //Has data flag
UNCOV
383
                                        return true;
×
384
                                case 171:
UNCOV
385
                                        tmp.CreateCell((TableEntity.CellType)this._reader.ValueAsInt);
×
UNCOV
386
                                        return true;
×
387
                                case 172:
UNCOV
388
                                        tmp.CurrentCell.FlagValue = this._reader.ValueAsInt;
×
UNCOV
389
                                        return true;
×
390
                                case 173:
UNCOV
391
                                        tmp.CurrentCell.MergedValue = this._reader.ValueAsInt;
×
UNCOV
392
                                        return true;
×
393
                                case 174:
UNCOV
394
                                        tmp.CurrentCell.Autofit = this._reader.ValueAsBool;
×
UNCOV
395
                                        return true;
×
396
                                case 175:
UNCOV
397
                                        tmp.CurrentCell.BorderWidth = this._reader.ValueAsInt;
×
UNCOV
398
                                        return true;
×
399
                                case 176:
UNCOV
400
                                        tmp.CurrentCell.BorderHeight = this._reader.ValueAsInt;
×
UNCOV
401
                                        return true;
×
402
                                case 178:
UNCOV
403
                                        tmp.CurrentCell.VirtualEdgeFlag = this._reader.ValueAsShort;
×
UNCOV
404
                                        return true;
×
405
                                case 179:
406
                                        //Unknown value
UNCOV
407
                                        return true;
×
408
                                case 301:
UNCOV
409
                                        var content = new TableEntity.CellContent();
×
UNCOV
410
                                        tmp.CurrentCell.Contents.Add(content);
×
UNCOV
411
                                        this.readCellValue(content);
×
UNCOV
412
                                        return true;
×
413
                                case 340:
UNCOV
414
                                        tmp.CurrentCellTemplate.BlockRecordHandle = this._reader.ValueAsHandle;
×
UNCOV
415
                                        return true;
×
416
                                default:
UNCOV
417
                                        if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]))
×
UNCOV
418
                                        {
×
UNCOV
419
                                                return this.readEntitySubclassMap(template, map, DxfSubclassMarker.TableEntity);
×
420
                                        }
UNCOV
421
                                        return true;
×
422
                        }
UNCOV
423
                }
×
424

425
                private void readCellValue(TableEntity.CellContent content)
UNCOV
426
                {
×
UNCOV
427
                        if (this._reader.ValueAsString.Equals("CELL_VALUE", StringComparison.OrdinalIgnoreCase))
×
UNCOV
428
                        {
×
UNCOV
429
                                this._reader.ReadNext();
×
UNCOV
430
                        }
×
431
                        else
432
                        {
×
433
                                throw new Exceptions.DxfException($"Expected value not found CELL_VALUE", this._reader.Position);
×
434
                        }
435

UNCOV
436
                        while (this._reader.Code != 304
×
UNCOV
437
                                && !this._reader.ValueAsString.Equals("ACVALUE_END", StringComparison.OrdinalIgnoreCase))
×
UNCOV
438
                        {
×
UNCOV
439
                                switch (this._reader.Code)
×
440
                                {
441
                                        case 1:
UNCOV
442
                                                content.Value.Text = this._reader.ValueAsString;
×
UNCOV
443
                                                break;
×
444
                                        case 2:
445
                                                content.Value.Text += this._reader.ValueAsString;
×
446
                                                break;
×
447
                                        case 11:
UNCOV
448
                                                content.Value.Value = new XYZ(this._reader.ValueAsDouble, 0, 0);
×
UNCOV
449
                                                break;
×
450
                                        case 21:
UNCOV
451
                                                content.Value.Value = new XYZ(0, this._reader.ValueAsDouble, 0);
×
UNCOV
452
                                                break;
×
453
                                        case 31:
UNCOV
454
                                                content.Value.Value = new XYZ(0, 0, this._reader.ValueAsDouble);
×
UNCOV
455
                                                break;
×
456
                                        case 302:
457
                                                //TODO: Fix this assignation to cell value
UNCOV
458
                                                content.Value.Value = this._reader.ValueAsString;
×
UNCOV
459
                                                break;
×
460
                                        case 90:
UNCOV
461
                                                content.Value.ValueType = (TableEntity.CellValueType)this._reader.ValueAsInt;
×
UNCOV
462
                                                break;
×
463
                                        case 91:
UNCOV
464
                                                content.Value.Value = this._reader.ValueAsInt;
×
UNCOV
465
                                                break;
×
466
                                        case 93:
UNCOV
467
                                                content.Value.Flags = this._reader.ValueAsInt;
×
UNCOV
468
                                                break;
×
469
                                        case 94:
UNCOV
470
                                                content.Value.Units = (TableEntity.ValueUnitType)this._reader.ValueAsInt;
×
UNCOV
471
                                                break;
×
472
                                        case 140:
UNCOV
473
                                                content.Value.Value = this._reader.ValueAsDouble;
×
UNCOV
474
                                                break;
×
475
                                        case 300:
UNCOV
476
                                                content.Value.Format = this._reader.ValueAsString;
×
UNCOV
477
                                                break;
×
478
                                        default:
UNCOV
479
                                                this._builder.Notify($"[CELL_VALUE] Unhandled dxf code {this._reader.Code} with value {this._reader.ValueAsString}", NotificationType.None);
×
UNCOV
480
                                                break;
×
481
                                }
482

UNCOV
483
                                this._reader.ReadNext();
×
UNCOV
484
                        }
×
UNCOV
485
                }
×
486

487
                private bool readTextEntity(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
488
                {
×
UNCOV
489
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
×
UNCOV
490
                        CadTextEntityTemplate tmp = template as CadTextEntityTemplate;
×
491

UNCOV
492
                        switch (this._reader.Code)
×
493
                        {
494
                                //TODO: Implement multiline text def codes
UNCOV
495
                                case 1 or 3 when tmp.CadObject is MText mtext:
×
UNCOV
496
                                        mtext.Value += this._reader.ValueAsString;
×
UNCOV
497
                                        return true;
×
UNCOV
498
                                case 50 when tmp.CadObject is MText://Read only for MText
×
499
                                case 70:
500
                                case 74:
501
                                case 101:
UNCOV
502
                                        return true;
×
503
                                case 7:
UNCOV
504
                                        tmp.StyleName = this._reader.ValueAsString;
×
UNCOV
505
                                        return true;
×
506
                                default:
UNCOV
507
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
×
508
                        }
UNCOV
509
                }
×
510

511
                private bool readTolerance(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
512
                {
×
UNCOV
513
                        CadToleranceTemplate tmp = template as CadToleranceTemplate;
×
514

UNCOV
515
                        switch (this._reader.Code)
×
516
                        {
517
                                case 3:
UNCOV
518
                                        tmp.DimensionStyleName = this._reader.ValueAsString;
×
UNCOV
519
                                        return true;
×
520
                                default:
UNCOV
521
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
×
522
                        }
UNCOV
523
                }
×
524

525
                private bool readDimension(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
526
                {
×
UNCOV
527
                        CadDimensionTemplate tmp = template as CadDimensionTemplate;
×
528

UNCOV
529
                        switch (this._reader.Code)
×
530
                        {
531
                                case 2:
UNCOV
532
                                        tmp.BlockName = this._reader.ValueAsString;
×
UNCOV
533
                                        return true;
×
534
                                case 3:
UNCOV
535
                                        tmp.StyleName = this._reader.ValueAsString;
×
UNCOV
536
                                        return true;
×
537
                                case 50:
UNCOV
538
                                        var dim = new DimensionLinear();
×
UNCOV
539
                                        tmp.SetDimensionObject(dim);
×
UNCOV
540
                                        dim.Rotation = this._reader.ValueAsAngle;
×
UNCOV
541
                                        map.SubClasses.Add(DxfSubclassMarker.LinearDimension, DxfClassMap.Create<DimensionLinear>());
×
UNCOV
542
                                        return true;
×
543
                                case 70:
544
                                        //Flags do not have set
UNCOV
545
                                        tmp.SetDimensionFlags((DimensionType)this._reader.ValueAsShort);
×
UNCOV
546
                                        return true;
×
547
                                //Measurement - read only
548
                                case 42:
UNCOV
549
                                        return true;
×
550
                                //Undocumented codes
551
                                case 73:
552
                                case 74:
553
                                case 75:
554
                                case 90:
555
                                case 361:
UNCOV
556
                                        return true;
×
557
                                case 100:
UNCOV
558
                                        switch (this._reader.ValueAsString)
×
559
                                        {
560
                                                case DxfSubclassMarker.Dimension:
UNCOV
561
                                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Dimension]);
×
562
                                                case DxfSubclassMarker.AlignedDimension:
UNCOV
563
                                                        tmp.SetDimensionObject(new DimensionAligned());
×
UNCOV
564
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAligned>());
×
UNCOV
565
                                                        return true;
×
566
                                                case DxfSubclassMarker.DiametricDimension:
UNCOV
567
                                                        tmp.SetDimensionObject(new DimensionDiameter());
×
UNCOV
568
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionDiameter>());
×
UNCOV
569
                                                        return true;
×
570
                                                case DxfSubclassMarker.Angular2LineDimension:
UNCOV
571
                                                        tmp.SetDimensionObject(new DimensionAngular2Line());
×
UNCOV
572
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular2Line>());
×
UNCOV
573
                                                        return true;
×
574
                                                case DxfSubclassMarker.Angular3PointDimension:
UNCOV
575
                                                        tmp.SetDimensionObject(new DimensionAngular3Pt());
×
UNCOV
576
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionAngular3Pt>());
×
UNCOV
577
                                                        return true;
×
578
                                                case DxfSubclassMarker.RadialDimension:
UNCOV
579
                                                        tmp.SetDimensionObject(new DimensionRadius());
×
UNCOV
580
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionRadius>());
×
UNCOV
581
                                                        return true;
×
582
                                                case DxfSubclassMarker.OrdinateDimension:
UNCOV
583
                                                        tmp.SetDimensionObject(new DimensionOrdinate());
×
UNCOV
584
                                                        map.SubClasses.Add(this._reader.ValueAsString, DxfClassMap.Create<DimensionOrdinate>());
×
UNCOV
585
                                                        return true;
×
586
                                                case DxfSubclassMarker.LinearDimension:
UNCOV
587
                                                        return true;
×
588
                                                default:
UNCOV
589
                                                        return false;
×
590
                                        }
591
                                default:
UNCOV
592
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
593
                        }
UNCOV
594
                }
×
595

596
                protected bool readHatch(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
597
                {
×
UNCOV
598
                        CadHatchTemplate tmp = template as CadHatchTemplate;
×
UNCOV
599
                        Hatch hatch = tmp.CadObject;
×
600

UNCOV
601
                        bool isFirstSeed = true;
×
UNCOV
602
                        XY seedPoint = new XY();
×
603

UNCOV
604
                        switch (this._reader.Code)
×
605
                        {
606
                                case 2:
UNCOV
607
                                        hatch.Pattern.Name = this._reader.ValueAsString;
×
UNCOV
608
                                        return true;
×
609
                                case 10:
UNCOV
610
                                        seedPoint.X = this._reader.ValueAsDouble;
×
UNCOV
611
                                        return true;
×
612
                                case 20:
UNCOV
613
                                        if (!isFirstSeed)
×
614
                                        {
×
615
                                                seedPoint.Y = this._reader.ValueAsDouble;
×
616
                                                hatch.SeedPoints.Add(seedPoint);
×
617
                                        }
×
UNCOV
618
                                        return true;
×
619
                                case 30:
UNCOV
620
                                        hatch.Elevation = this._reader.ValueAsDouble;
×
UNCOV
621
                                        isFirstSeed = false;
×
UNCOV
622
                                        return true;
×
623
                                case 53:
624
                                        hatch.PatternAngle = this._reader.ValueAsAngle;
×
625
                                        return true;
×
626
                                //TODO: Check hatch undocumented codes
627
                                case 90:
628
                                        return true;
×
629
                                //Information about the hatch pattern
630
                                case 75:
631
                                        return true;
×
632
                                //Number of pattern definition lines
633
                                case 78:
UNCOV
634
                                        this.readPattern(hatch.Pattern, this._reader.ValueAsInt);
×
UNCOV
635
                                        return true;
×
636
                                //Number of boundary paths (loops)
637
                                case 91:
UNCOV
638
                                        this.readLoops(tmp, this._reader.ValueAsInt);
×
UNCOV
639
                                        return true;
×
640
                                //Number of seed points
641
                                case 98:
UNCOV
642
                                        return true;
×
643
                                case 450:
UNCOV
644
                                        hatch.GradientColor.Enabled = this._reader.ValueAsBool;
×
UNCOV
645
                                        return true;
×
646
                                case 451:
UNCOV
647
                                        hatch.GradientColor.Reserved = this._reader.ValueAsInt;
×
UNCOV
648
                                        return true;
×
649
                                case 452:
UNCOV
650
                                        hatch.GradientColor.IsSingleColorGradient = this._reader.ValueAsBool;
×
UNCOV
651
                                        return true;
×
652
                                case 453:
653
                                        //Number of colors
UNCOV
654
                                        return true;
×
655
                                case 460:
UNCOV
656
                                        hatch.GradientColor.Angle = this._reader.ValueAsDouble;
×
UNCOV
657
                                        return true;
×
658
                                case 461:
UNCOV
659
                                        hatch.GradientColor.Shift = this._reader.ValueAsDouble;
×
UNCOV
660
                                        return true;
×
661
                                case 462:
UNCOV
662
                                        hatch.GradientColor.ColorTint = this._reader.ValueAsDouble;
×
UNCOV
663
                                        return true;
×
664
                                case 463:
UNCOV
665
                                        GradientColor gradient = new GradientColor();
×
UNCOV
666
                                        gradient.Value = this._reader.ValueAsDouble;
×
UNCOV
667
                                        hatch.GradientColor.Colors.Add(gradient);
×
UNCOV
668
                                        return true;
×
669
                                case 63:
UNCOV
670
                                        GradientColor colorByIndex = hatch.GradientColor.Colors.LastOrDefault();
×
UNCOV
671
                                        if (colorByIndex != null)
×
UNCOV
672
                                        {
×
UNCOV
673
                                                colorByIndex.Color = new Color((short)this._reader.ValueAsUShort);
×
UNCOV
674
                                        }
×
UNCOV
675
                                        return true;
×
676
                                case 421:
UNCOV
677
                                        GradientColor colorByRgb = hatch.GradientColor.Colors.LastOrDefault();
×
UNCOV
678
                                        if (colorByRgb != null)
×
UNCOV
679
                                        {
×
680
                                                //TODO: Hatch assign color by true color
681
                                                //TODO: Is always duplicated by 63, is it needed??
682
                                                //colorByRgb.Color = new Color(this._reader.LastValueAsShort);
UNCOV
683
                                        }
×
UNCOV
684
                                        return true;
×
685
                                case 470:
UNCOV
686
                                        hatch.GradientColor.Name = this._reader.ValueAsString;
×
UNCOV
687
                                        return true;
×
688
                                default:
UNCOV
689
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[template.CadObject.SubclassMarker]);
×
690
                        }
UNCOV
691
                }
×
692

693
                private bool readInsert(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
694
                {
×
UNCOV
695
                        CadInsertTemplate tmp = template as CadInsertTemplate;
×
696

UNCOV
697
                        switch (this._reader.Code)
×
698
                        {
699
                                case 2:
UNCOV
700
                                        tmp.BlockName = this._reader.ValueAsString;
×
UNCOV
701
                                        return true;
×
702
                                case 100:
703
                                        //AcDbEntity
704
                                        //AcDbBlockReference
705
                                        //AcDbMInsertBlock
UNCOV
706
                                        return true;
×
707
                                case 66:
UNCOV
708
                                        return true;
×
709
                                default:
UNCOV
710
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Insert]);
×
711
                        }
UNCOV
712
                }
×
713

714
                private CadEntityTemplate readPolyline()
UNCOV
715
                {
×
UNCOV
716
                        CadPolyLineTemplate template = null;
×
717

UNCOV
718
                        if (this._builder.Version == ACadVersion.Unknown)
×
719
                        {
×
720
                                var polyline = new Polyline2D();
×
721
                                template = new CadPolyLineTemplate(polyline);
×
722
                                this.readEntityCodes<Polyline2D>(template, this.readPolyline);
×
723

724
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EntityVertex)
×
725
                                {
×
726
                                        Vertex2D v = new Vertex2D();
×
727
                                        CadVertexTemplate vertexTemplate = new CadVertexTemplate(v);
×
728
                                        this.readEntityCodes<Vertex2D>(vertexTemplate, this.readVertex);
×
729

730
                                        if (vertexTemplate.Vertex.Handle == 0)
×
731
                                        {
×
732
                                                template.PolyLine.Vertices.Add(vertexTemplate.Vertex);
×
733
                                        }
×
734
                                        else
735
                                        {
×
736
                                                template.VertexHandles.Add(vertexTemplate.Vertex.Handle);
×
737
                                                this._builder.AddTemplate(vertexTemplate);
×
738
                                        }
×
739
                                }
×
740

741
                                while (this._reader.Code == 0 && this._reader.ValueAsString == DxfFileToken.EndSequence)
×
742
                                {
×
743
                                        var seqend = new Seqend();
×
744
                                        var seqendTemplate = new CadEntityTemplate<Seqend>(seqend);
×
745
                                        this.readEntityCodes<Seqend>(seqendTemplate, this.readEntitySubclassMap);
×
746

747
                                        template.PolyLine.Vertices.Seqend = seqend;
×
748
                                }
×
749
                        }
×
750
                        else
UNCOV
751
                        {
×
UNCOV
752
                                template = new CadPolyLineTemplate();
×
UNCOV
753
                                this.readEntityCodes<Entity>(template, this.readPolyline);
×
UNCOV
754
                        }
×
755

UNCOV
756
                        if (template.CadObject is CadPolyLineTemplate.PolyLinePlaceholder)
×
UNCOV
757
                        {
×
UNCOV
758
                                this._builder.Notify($"[{DxfFileToken.EntityPolyline}] Subclass not found, entity discarded", NotificationType.Warning);
×
UNCOV
759
                                return null;
×
760
                        }
761

UNCOV
762
                        return template;
×
UNCOV
763
                }
×
764

765
                private bool readPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
766
                {
×
UNCOV
767
                        CadPolyLineTemplate tmp = template as CadPolyLineTemplate;
×
768

UNCOV
769
                        switch (this._reader.Code)
×
770
                        {
771
                                //DXF: always 0
772
                                //APP: a “dummy” point; the X and Y values are always 0, and the Z value is the polyline's elevation (in OCS when 2D, WCS when 3D)
773
                                case 10:
774
                                case 20:
775
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
776
                                case 66:
777
                                //Polygon mesh M vertex count (optional; default = 0)
778
                                case 71:
779
                                //Polygon mesh N vertex count(optional; default = 0)
780
                                case 72:
781
                                //Smooth surface M density(optional; default = 0)
782
                                case 73:
783
                                //Smooth surface N density (optional; default = 0)
784
                                case 74:
UNCOV
785
                                        return true;
×
786
                                case 100:
UNCOV
787
                                        switch (this._reader.ValueAsString)
×
788
                                        {
789
                                                case DxfSubclassMarker.Polyline:
790
                                                        tmp.SetPolyLineObject(new Polyline2D());
×
791
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline, DxfClassMap.Create<Polyline2D>());
×
792
                                                        return true;
×
793
                                                case DxfSubclassMarker.Polyline3d:
UNCOV
794
                                                        tmp.SetPolyLineObject(new Polyline3D());
×
UNCOV
795
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3d, DxfClassMap.Create<Polyline3D>());
×
UNCOV
796
                                                        return true;
×
797
                                                case DxfSubclassMarker.PolyfaceMesh:
UNCOV
798
                                                        tmp.SetPolyLineObject(new PolyfaceMesh());
×
UNCOV
799
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMesh, DxfClassMap.Create<PolyfaceMesh>());
×
UNCOV
800
                                                        return true;
×
801
                                                default:
UNCOV
802
                                                        return false;
×
803
                                        }
804
                                default:
UNCOV
805
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
806
                        }
UNCOV
807
                }
×
808

809
                private bool readLeader(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
810
                {
×
UNCOV
811
                        CadLeaderTemplate tmp = template as CadLeaderTemplate;
×
812

UNCOV
813
                        switch (this._reader.Code)
×
814
                        {
815
                                case 3:
UNCOV
816
                                        tmp.DIMSTYLEName = this._reader.ValueAsString;
×
UNCOV
817
                                        return true;
×
818
                                case 10:
UNCOV
819
                                        tmp.CadObject.Vertices.Add(new XYZ(this._reader.ValueAsDouble, 0, 0));
×
UNCOV
820
                                        return true;
×
821
                                case 20:
UNCOV
822
                                        XYZ y = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
×
UNCOV
823
                                        y.Y = this._reader.ValueAsDouble;
×
UNCOV
824
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = y;
×
UNCOV
825
                                        return true;
×
826
                                case 30:
UNCOV
827
                                        XYZ z = tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1];
×
UNCOV
828
                                        z.Z = this._reader.ValueAsDouble;
×
UNCOV
829
                                        tmp.CadObject.Vertices[tmp.CadObject.Vertices.Count - 1] = z;
×
UNCOV
830
                                        return true;
×
831
                                case 340:
UNCOV
832
                                        tmp.AnnotationHandle = this._reader.ValueAsHandle;
×
UNCOV
833
                                        return true;
×
834
                                //Hook line flag - read only
835
                                case 75:
836
                                //Vertices count
837
                                case 76:
UNCOV
838
                                        return true;
×
839
                                default:
UNCOV
840
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
841
                        }
UNCOV
842
                }
×
843

844
                private bool readLwPolyline(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
845
                {
×
UNCOV
846
                        CadEntityTemplate<LwPolyline> tmp = template as CadEntityTemplate<LwPolyline>;
×
847

UNCOV
848
                        LwPolyline.Vertex last = tmp.CadObject.Vertices.LastOrDefault();
×
849

UNCOV
850
                        switch (this._reader.Code)
×
851
                        {
852
                                case 10:
UNCOV
853
                                        tmp.CadObject.Vertices.Add(new LwPolyline.Vertex(new XY(this._reader.ValueAsDouble, 0)));
×
UNCOV
854
                                        return true;
×
855
                                case 20:
UNCOV
856
                                        if (last is not null)
×
UNCOV
857
                                        {
×
UNCOV
858
                                                last.Location = new XY(last.Location.X, this._reader.ValueAsDouble);
×
UNCOV
859
                                        }
×
UNCOV
860
                                        return true;
×
861
                                case 40:
UNCOV
862
                                        if (last is not null)
×
UNCOV
863
                                        {
×
UNCOV
864
                                                last.StartWidth = this._reader.ValueAsDouble;
×
UNCOV
865
                                        }
×
UNCOV
866
                                        return true;
×
867
                                case 41:
UNCOV
868
                                        if (last is not null)
×
UNCOV
869
                                        {
×
UNCOV
870
                                                last.EndWidth = this._reader.ValueAsDouble;
×
UNCOV
871
                                        }
×
UNCOV
872
                                        return true;
×
873
                                case 42:
UNCOV
874
                                        if (last is not null)
×
UNCOV
875
                                        {
×
UNCOV
876
                                                last.Bulge = this._reader.ValueAsDouble;
×
UNCOV
877
                                        }
×
UNCOV
878
                                        return true;
×
879
                                case 50:
880
                                        if (last is not null)
×
881
                                        {
×
882
                                                last.CurveTangent = this._reader.ValueAsDouble;
×
883
                                        }
×
884
                                        return true;
×
885
                                //Obsolete; formerly an “entities follow flag” (optional; ignore if present)
886
                                case 66:
887
                                //Vertex count
888
                                case 90:
UNCOV
889
                                        return true;
×
890
                                case 91:
891
                                        if (last is not null)
×
892
                                        {
×
893
                                                last.Id = this._reader.ValueAsInt;
×
894
                                        }
×
895
                                        return true;
×
896
                                default:
UNCOV
897
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
898
                        }
UNCOV
899
                }
×
900

901
                private bool readMesh(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
902
                {
×
UNCOV
903
                        CadMeshTemplate tmp = template as CadMeshTemplate;
×
904

UNCOV
905
                        switch (this._reader.Code)
×
906
                        {
907
                                case 100:
UNCOV
908
                                        if (this._reader.ValueAsString.Equals(DxfSubclassMarker.Mesh, StringComparison.OrdinalIgnoreCase))
×
UNCOV
909
                                        {
×
UNCOV
910
                                                tmp.SubclassMarker = true;
×
UNCOV
911
                                        }
×
UNCOV
912
                                        return true;
×
913
                                //Count of sub-entity which property has been overridden
914
                                case 90:
915
                                        //TODO: process further entities
UNCOV
916
                                        return true;
×
917
                                case 92:
UNCOV
918
                                        if (!tmp.SubclassMarker)
×
UNCOV
919
                                        {
×
UNCOV
920
                                                return false;
×
921
                                        }
922

UNCOV
923
                                        int nvertices = this._reader.ValueAsInt;
×
UNCOV
924
                                        for (int i = 0; i < nvertices; i++)
×
UNCOV
925
                                        {
×
UNCOV
926
                                                this._reader.ReadNext();
×
UNCOV
927
                                                double x = this._reader.ValueAsDouble;
×
UNCOV
928
                                                this._reader.ReadNext();
×
UNCOV
929
                                                double y = this._reader.ValueAsDouble;
×
UNCOV
930
                                                this._reader.ReadNext();
×
UNCOV
931
                                                double z = this._reader.ValueAsDouble;
×
UNCOV
932
                                                tmp.CadObject.Vertices.Add(new XYZ(x, y, z));
×
UNCOV
933
                                        }
×
UNCOV
934
                                        return true;
×
935
                                case 93:
UNCOV
936
                                        int size = this._reader.ValueAsInt;
×
UNCOV
937
                                        this._reader.ReadNext();
×
938

UNCOV
939
                                        int indexes = 0;
×
UNCOV
940
                                        for (int i = 0; i < size; i += indexes + 1)
×
UNCOV
941
                                        {
×
UNCOV
942
                                                indexes = this._reader.ValueAsInt;
×
UNCOV
943
                                                this._reader.ReadNext();
×
944

UNCOV
945
                                                int[] face = new int[indexes];
×
UNCOV
946
                                                for (int j = 0; j < indexes; j++)
×
UNCOV
947
                                                {
×
UNCOV
948
                                                        face[j] = this._reader.ValueAsInt;
×
949

UNCOV
950
                                                        if ((i + j + 2) < size)
×
UNCOV
951
                                                        {
×
UNCOV
952
                                                                this._reader.ReadNext();
×
UNCOV
953
                                                        }
×
UNCOV
954
                                                }
×
955

UNCOV
956
                                                tmp.CadObject.Faces.Add(face);
×
UNCOV
957
                                        }
×
958

UNCOV
959
                                        Debug.Assert(this._reader.Code == 90);
×
960

UNCOV
961
                                        return true;
×
962
                                case 94:
UNCOV
963
                                        int numEdges = this._reader.ValueAsInt;
×
UNCOV
964
                                        this._reader.ReadNext();
×
UNCOV
965
                                        for (int i = 0; i < numEdges; i++)
×
UNCOV
966
                                        {
×
UNCOV
967
                                                Mesh.Edge edge = new Mesh.Edge();
×
968

UNCOV
969
                                                edge.Start = this._reader.ValueAsInt;
×
UNCOV
970
                                                this._reader.ReadNext();
×
UNCOV
971
                                                edge.End = this._reader.ValueAsInt;
×
972

UNCOV
973
                                                if (i < numEdges - 1)
×
UNCOV
974
                                                {
×
UNCOV
975
                                                        this._reader.ReadNext();
×
UNCOV
976
                                                }
×
977

UNCOV
978
                                                tmp.CadObject.Edges.Add(edge);
×
UNCOV
979
                                        }
×
980

UNCOV
981
                                        Debug.Assert(this._reader.Code == 90);
×
982

UNCOV
983
                                        return true;
×
984
                                case 95:
UNCOV
985
                                        this._reader.ReadNext();
×
UNCOV
986
                                        for (int i = 0; i < tmp.CadObject.Edges.Count; i++)
×
UNCOV
987
                                        {
×
UNCOV
988
                                                Mesh.Edge edge = tmp.CadObject.Edges[i];
×
UNCOV
989
                                                edge.Crease = this._reader.ValueAsDouble;
×
990

UNCOV
991
                                                tmp.CadObject.Edges[i] = edge;
×
992

UNCOV
993
                                                if (i < tmp.CadObject.Edges.Count - 1)
×
UNCOV
994
                                                {
×
UNCOV
995
                                                        this._reader.ReadNext();
×
UNCOV
996
                                                }
×
UNCOV
997
                                        }
×
998

UNCOV
999
                                        Debug.Assert(this._reader.Code == 140);
×
1000

UNCOV
1001
                                        return true;
×
1002
                                default:
UNCOV
1003
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1004
                        }
UNCOV
1005
                }
×
1006

1007
                private bool readMLine(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1008
                {
×
UNCOV
1009
                        CadMLineTemplate tmp = template as CadMLineTemplate;
×
1010

UNCOV
1011
                        switch (this._reader.Code)
×
1012
                        {
1013
                                // String of up to 32 characters. The name of the style used for this mline. An entry for this style must exist in the MLINESTYLE dictionary.
1014
                                // Do not modify this field without also updating the associated entry in the MLINESTYLE dictionary
1015
                                case 2:
UNCOV
1016
                                        tmp.MLineStyleName = this._reader.ValueAsString;
×
UNCOV
1017
                                        return true;
×
1018
                                case 72:
UNCOV
1019
                                        tmp.NVertex = this._reader.ValueAsInt;
×
UNCOV
1020
                                        return true;
×
1021
                                case 73:
UNCOV
1022
                                        tmp.NElements = this._reader.ValueAsInt;
×
UNCOV
1023
                                        return true;
×
1024
                                case 340:
UNCOV
1025
                                        tmp.MLineStyleHandle = this._reader.ValueAsHandle;
×
UNCOV
1026
                                        return true;
×
1027
                                default:
UNCOV
1028
                                        if (!tmp.TryReadVertex(this._reader.Code, this._reader.Value))
×
UNCOV
1029
                                        {
×
UNCOV
1030
                                                return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1031
                                        }
UNCOV
1032
                                        return true;
×
1033
                        }
UNCOV
1034
                }
×
1035

1036
                private bool readShape(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1037
                {
×
UNCOV
1038
                        CadShapeTemplate tmp = template as CadShapeTemplate;
×
1039

UNCOV
1040
                        switch (this._reader.Code)
×
1041
                        {
1042
                                case 2:
UNCOV
1043
                                        tmp.ShapeFileName = this._reader.ValueAsString;
×
UNCOV
1044
                                        return true;
×
1045
                                default:
UNCOV
1046
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1047
                        }
UNCOV
1048
                }
×
1049

1050
                private bool readSpline(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1051
                {
×
UNCOV
1052
                        CadSplineTemplate tmp = template as CadSplineTemplate;
×
1053

1054
                        XYZ controlPoint;
1055
                        XYZ fitPoint;
1056

UNCOV
1057
                        switch (this._reader.Code)
×
1058
                        {
1059
                                case 10:
UNCOV
1060
                                        controlPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
UNCOV
1061
                                        tmp.CadObject.ControlPoints.Add(controlPoint);
×
UNCOV
1062
                                        return true;
×
1063
                                case 20:
UNCOV
1064
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
×
UNCOV
1065
                                        controlPoint.Y = this._reader.ValueAsDouble;
×
UNCOV
1066
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
×
UNCOV
1067
                                        return true;
×
1068
                                case 30:
UNCOV
1069
                                        controlPoint = tmp.CadObject.ControlPoints.LastOrDefault();
×
UNCOV
1070
                                        controlPoint.Z = this._reader.ValueAsDouble;
×
UNCOV
1071
                                        tmp.CadObject.ControlPoints[tmp.CadObject.ControlPoints.Count - 1] = controlPoint;
×
UNCOV
1072
                                        return true;
×
1073
                                case 11:
1074
                                        fitPoint = new CSMath.XYZ(this._reader.ValueAsDouble, 0, 0);
×
1075
                                        tmp.CadObject.FitPoints.Add(fitPoint);
×
1076
                                        return true;
×
1077
                                case 21:
1078
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1079
                                        fitPoint.Y = this._reader.ValueAsDouble;
×
1080
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1081
                                        return true;
×
1082
                                case 31:
1083
                                        fitPoint = tmp.CadObject.FitPoints.LastOrDefault();
×
1084
                                        fitPoint.Z = this._reader.ValueAsDouble;
×
1085
                                        tmp.CadObject.FitPoints[tmp.CadObject.FitPoints.Count - 1] = fitPoint;
×
1086
                                        return true;
×
1087
                                case 40:
UNCOV
1088
                                        tmp.CadObject.Knots.Add(this._reader.ValueAsDouble);
×
UNCOV
1089
                                        return true;
×
1090
                                case 41:
1091
                                        tmp.CadObject.Weights.Add(this._reader.ValueAsDouble);
×
1092
                                        return true;
×
1093
                                case 72:
1094
                                case 73:
1095
                                case 74:
UNCOV
1096
                                        return true;
×
1097
                                default:
UNCOV
1098
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1099
                        }
UNCOV
1100
                }
×
1101

1102
                private bool readUnderlayEntity<T>(CadEntityTemplate template, DxfMap map, string subclass = null)
1103
                        where T : PdfUnderlayDefinition
UNCOV
1104
                {
×
UNCOV
1105
                        CadUnderlayTemplate<T> tmp = template as CadUnderlayTemplate<T>;
×
1106

UNCOV
1107
                        switch (this._reader.Code)
×
1108
                        {
1109
                                case 340:
UNCOV
1110
                                        tmp.DefinitionHandle = this._reader.ValueAsHandle;
×
UNCOV
1111
                                        return true;
×
1112
                                default:
UNCOV
1113
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1114
                        }
UNCOV
1115
                }
×
1116

1117
                private bool readVertex(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1118
                {
×
UNCOV
1119
                        CadVertexTemplate tmp = template as CadVertexTemplate;
×
1120

UNCOV
1121
                        switch (this._reader.Code)
×
1122
                        {
1123
                                //Polyface mesh vertex index
1124
                                case 71:
1125
                                case 72:
1126
                                case 73:
1127
                                case 74:
UNCOV
1128
                                        return true;
×
1129
                                case 100:
UNCOV
1130
                                        switch (this._reader.ValueAsString)
×
1131
                                        {
1132
                                                case DxfSubclassMarker.Vertex:
UNCOV
1133
                                                        return true;
×
1134
                                                case DxfSubclassMarker.PolylineVertex:
1135
                                                        tmp.SetVertexObject(new Vertex2D());
×
1136
                                                        map.SubClasses.Add(DxfSubclassMarker.PolylineVertex, DxfClassMap.Create<Vertex2D>());
×
1137
                                                        return true;
×
1138
                                                case DxfSubclassMarker.Polyline3dVertex:
UNCOV
1139
                                                        tmp.SetVertexObject(new Vertex3D());
×
UNCOV
1140
                                                        map.SubClasses.Add(DxfSubclassMarker.Polyline3dVertex, DxfClassMap.Create<Vertex3D>());
×
UNCOV
1141
                                                        return true;
×
1142
                                                case DxfSubclassMarker.PolyfaceMeshVertex:
UNCOV
1143
                                                        tmp.SetVertexObject(new VertexFaceMesh());
×
UNCOV
1144
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshVertex, DxfClassMap.Create<VertexFaceMesh>());
×
UNCOV
1145
                                                        return true;
×
1146
                                                case DxfSubclassMarker.PolyfaceMeshFace:
UNCOV
1147
                                                        tmp.SetVertexObject(new VertexFaceRecord());
×
UNCOV
1148
                                                        map.SubClasses.Add(DxfSubclassMarker.PolyfaceMeshFace, DxfClassMap.Create<VertexFaceRecord>());
×
UNCOV
1149
                                                        return true;
×
1150
                                                default:
UNCOV
1151
                                                        return false;
×
1152
                                        }
1153
                                default:
UNCOV
1154
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[tmp.CadObject.SubclassMarker]);
×
1155
                        }
UNCOV
1156
                }
×
1157

1158
                private bool readViewport(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1159
                {
×
UNCOV
1160
                        CadViewportTemplate tmp = template as CadViewportTemplate;
×
1161

UNCOV
1162
                        switch (this._reader.Code)
×
1163
                        {
1164
                                //Undocumented
1165
                                case 67:
1166
                                case 68:
UNCOV
1167
                                        return true;
×
1168
                                case 69:
UNCOV
1169
                                        tmp.ViewportId = this._reader.ValueAsShort;
×
UNCOV
1170
                                        return true;
×
1171
                                case 331:
1172
                                        tmp.FrozenLayerHandles.Add(this._reader.ValueAsHandle);
×
1173
                                        return true;
×
1174
                                case 348:
UNCOV
1175
                                        tmp.VisualStyleHandle = this._reader.ValueAsHandle;
×
UNCOV
1176
                                        return true;
×
1177
                                default:
UNCOV
1178
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.Viewport]);
×
1179
                        }
UNCOV
1180
                }
×
1181

1182
                private bool readEntitySubclassMap(CadEntityTemplate template, DxfMap map, string subclass = null)
UNCOV
1183
                {
×
UNCOV
1184
                        string mapName = string.IsNullOrEmpty(subclass) ? template.CadObject.SubclassMarker : subclass;
×
1185

UNCOV
1186
                        switch (this._reader.Code)
×
1187
                        {
1188
                                default:
UNCOV
1189
                                        return this.tryAssignCurrentValue(template.CadObject, map.SubClasses[mapName]);
×
1190
                        }
UNCOV
1191
                }
×
1192

1193
                protected void readExtendedData(Dictionary<string, List<ExtendedDataRecord>> edata)
UNCOV
1194
                {
×
UNCOV
1195
                        List<ExtendedDataRecord> records = new();
×
UNCOV
1196
                        edata.Add(this._reader.ValueAsString, records);
×
1197

UNCOV
1198
                        this._reader.ReadNext();
×
1199

UNCOV
1200
                        while (this._reader.DxfCode >= DxfCode.ExtendedDataAsciiString)
×
UNCOV
1201
                        {
×
UNCOV
1202
                                if (this._reader.DxfCode == DxfCode.ExtendedDataRegAppName)
×
UNCOV
1203
                                {
×
UNCOV
1204
                                        this.readExtendedData(edata);
×
UNCOV
1205
                                        break;
×
1206
                                }
1207

UNCOV
1208
                                ExtendedDataRecord record = null;
×
UNCOV
1209
                                double x = 0;
×
UNCOV
1210
                                double y = 0;
×
UNCOV
1211
                                double z = 0;
×
1212

UNCOV
1213
                                switch (this._reader.DxfCode)
×
1214
                                {
1215
                                        case DxfCode.ExtendedDataAsciiString:
1216
                                        case DxfCode.ExtendedDataRegAppName:
UNCOV
1217
                                                record = new ExtendedDataString(this._reader.ValueAsString);
×
UNCOV
1218
                                                break;
×
1219
                                        case DxfCode.ExtendedDataControlString:
UNCOV
1220
                                                record = new ExtendedDataControlString(this._reader.ValueAsString == "}");
×
UNCOV
1221
                                                break;
×
1222
                                        case DxfCode.ExtendedDataLayerName:
UNCOV
1223
                                                if (this._builder.Layers.TryGetValue(this._reader.ValueAsString, out Layer layer))
×
UNCOV
1224
                                                {
×
UNCOV
1225
                                                        record = new ExtendedDataLayer(layer.Handle);
×
UNCOV
1226
                                                }
×
1227
                                                else
UNCOV
1228
                                                {
×
UNCOV
1229
                                                        this._builder.Notify($"[XData] Could not found the linked Layer {this._reader.ValueAsString}.", NotificationType.Warning);
×
UNCOV
1230
                                                }
×
UNCOV
1231
                                                break;
×
1232
                                        case DxfCode.ExtendedDataBinaryChunk:
UNCOV
1233
                                                record = new ExtendedDataBinaryChunk(this._reader.ValueAsBinaryChunk);
×
UNCOV
1234
                                                break;
×
1235
                                        case DxfCode.ExtendedDataHandle:
UNCOV
1236
                                                record = new ExtendedDataHandle(this._reader.ValueAsHandle);
×
UNCOV
1237
                                                break;
×
1238
                                        case DxfCode.ExtendedDataXCoordinate:
UNCOV
1239
                                                x = this._reader.ValueAsDouble;
×
UNCOV
1240
                                                this._reader.ReadNext();
×
UNCOV
1241
                                                y = this._reader.ValueAsDouble;
×
UNCOV
1242
                                                this._reader.ReadNext();
×
UNCOV
1243
                                                z = this._reader.ValueAsDouble;
×
1244

UNCOV
1245
                                                record = new ExtendedDataCoordinate(
×
UNCOV
1246
                                                        new XYZ(
×
UNCOV
1247
                                                                x,
×
UNCOV
1248
                                                                y,
×
UNCOV
1249
                                                                z)
×
UNCOV
1250
                                                        );
×
UNCOV
1251
                                                break;
×
1252
                                        case DxfCode.ExtendedDataWorldXCoordinate:
UNCOV
1253
                                                x = this._reader.ValueAsDouble;
×
UNCOV
1254
                                                this._reader.ReadNext();
×
UNCOV
1255
                                                y = this._reader.ValueAsDouble;
×
UNCOV
1256
                                                this._reader.ReadNext();
×
UNCOV
1257
                                                z = this._reader.ValueAsDouble;
×
1258

UNCOV
1259
                                                record = new ExtendedDataWorldCoordinate(
×
UNCOV
1260
                                                        new XYZ(
×
UNCOV
1261
                                                                x,
×
UNCOV
1262
                                                                y,
×
UNCOV
1263
                                                                z)
×
UNCOV
1264
                                                        );
×
UNCOV
1265
                                                break;
×
1266
                                        case DxfCode.ExtendedDataWorldXDisp:
UNCOV
1267
                                                x = this._reader.ValueAsDouble;
×
UNCOV
1268
                                                this._reader.ReadNext();
×
UNCOV
1269
                                                y = this._reader.ValueAsDouble;
×
UNCOV
1270
                                                this._reader.ReadNext();
×
UNCOV
1271
                                                z = this._reader.ValueAsDouble;
×
1272

UNCOV
1273
                                                record = new ExtendedDataDisplacement(
×
UNCOV
1274
                                                        new XYZ(
×
UNCOV
1275
                                                                x,
×
UNCOV
1276
                                                                y,
×
UNCOV
1277
                                                                z)
×
UNCOV
1278
                                                        );
×
UNCOV
1279
                                                break;
×
1280
                                        case DxfCode.ExtendedDataWorldXDir:
UNCOV
1281
                                                x = this._reader.ValueAsDouble;
×
UNCOV
1282
                                                this._reader.ReadNext();
×
UNCOV
1283
                                                y = this._reader.ValueAsDouble;
×
UNCOV
1284
                                                this._reader.ReadNext();
×
UNCOV
1285
                                                z = this._reader.ValueAsDouble;
×
1286

UNCOV
1287
                                                record = new ExtendedDataDirection(
×
UNCOV
1288
                                                        new XYZ(
×
UNCOV
1289
                                                                x,
×
UNCOV
1290
                                                                y,
×
UNCOV
1291
                                                                z)
×
UNCOV
1292
                                                        );
×
UNCOV
1293
                                                break;
×
1294
                                        case DxfCode.ExtendedDataReal:
UNCOV
1295
                                                record = new ExtendedDataReal(this._reader.ValueAsDouble);
×
UNCOV
1296
                                                break;
×
1297
                                        case DxfCode.ExtendedDataDist:
UNCOV
1298
                                                record = new ExtendedDataDistance(this._reader.ValueAsDouble);
×
UNCOV
1299
                                                break;
×
1300
                                        case DxfCode.ExtendedDataScale:
UNCOV
1301
                                                record = new ExtendedDataScale(this._reader.ValueAsDouble);
×
UNCOV
1302
                                                break;
×
1303
                                        case DxfCode.ExtendedDataInteger16:
UNCOV
1304
                                                record = new ExtendedDataInteger16(this._reader.ValueAsShort);
×
UNCOV
1305
                                                break;
×
1306
                                        case DxfCode.ExtendedDataInteger32:
UNCOV
1307
                                                record = new ExtendedDataInteger32((int)this._reader.ValueAsInt);
×
UNCOV
1308
                                                break;
×
1309
                                        default:
UNCOV
1310
                                                this._builder.Notify($"Unknown code for extended data: {this._reader.DxfCode}", NotificationType.Warning);
×
UNCOV
1311
                                                break;
×
1312
                                }
1313

UNCOV
1314
                                if (record != null)
×
UNCOV
1315
                                {
×
UNCOV
1316
                                        records.Add(record);
×
UNCOV
1317
                                }
×
1318

UNCOV
1319
                                this._reader.ReadNext();
×
UNCOV
1320
                        }
×
UNCOV
1321
                }
×
1322

1323
                private void readPattern(HatchPattern pattern, int nlines)
UNCOV
1324
                {
×
1325
                        //Jump 78 code
UNCOV
1326
                        this._reader.ReadNext();
×
1327

UNCOV
1328
                        for (int i = 0; i < nlines; i++)
×
UNCOV
1329
                        {
×
UNCOV
1330
                                HatchPattern.Line line = new HatchPattern.Line();
×
UNCOV
1331
                                XY basePoint = new XY();
×
UNCOV
1332
                                XY offset = new XY();
×
1333

UNCOV
1334
                                bool end = false;
×
UNCOV
1335
                                HashSet<int> codes = new();
×
1336

UNCOV
1337
                                while (!end)
×
UNCOV
1338
                                {
×
UNCOV
1339
                                        if (codes.Contains(this._reader.Code))
×
UNCOV
1340
                                        {
×
UNCOV
1341
                                                break;
×
1342
                                        }
1343
                                        else
UNCOV
1344
                                        {
×
UNCOV
1345
                                                codes.Add(this._reader.Code);
×
UNCOV
1346
                                        }
×
1347

UNCOV
1348
                                        switch (this._reader.Code)
×
1349
                                        {
1350
                                                case 53:
UNCOV
1351
                                                        line.Angle = this._reader.ValueAsAngle;
×
UNCOV
1352
                                                        break;
×
1353
                                                case 43:
UNCOV
1354
                                                        basePoint.X = this._reader.ValueAsDouble;
×
UNCOV
1355
                                                        break;
×
1356
                                                case 44:
UNCOV
1357
                                                        basePoint.Y = this._reader.ValueAsDouble;
×
UNCOV
1358
                                                        line.BasePoint = basePoint;
×
UNCOV
1359
                                                        break;
×
1360
                                                case 45:
UNCOV
1361
                                                        offset.X = this._reader.ValueAsDouble;
×
UNCOV
1362
                                                        line.Offset = offset;
×
UNCOV
1363
                                                        break;
×
1364
                                                case 46:
UNCOV
1365
                                                        offset.Y = this._reader.ValueAsDouble;
×
UNCOV
1366
                                                        line.Offset = offset;
×
UNCOV
1367
                                                        break;
×
1368
                                                //Number of dash length items
1369
                                                case 79:
UNCOV
1370
                                                        int ndash = this._reader.ValueAsInt;
×
UNCOV
1371
                                                        for (int j = 0; j < ndash; j++)
×
UNCOV
1372
                                                        {
×
UNCOV
1373
                                                                this._reader.ReadNext();
×
UNCOV
1374
                                                                line.DashLengths.Add(this._reader.ValueAsDouble);
×
UNCOV
1375
                                                        }
×
UNCOV
1376
                                                        break;
×
1377
                                                case 49:
1378
                                                        line.DashLengths.Add(this._reader.ValueAsDouble);
×
1379
                                                        break;
×
1380
                                                default:
UNCOV
1381
                                                        end = true;
×
UNCOV
1382
                                                        break;
×
1383
                                        }
UNCOV
1384
                                        this._reader.ReadNext();
×
UNCOV
1385
                                }
×
1386

UNCOV
1387
                                pattern.Lines.Add(line);
×
UNCOV
1388
                        }
×
UNCOV
1389
                }
×
1390

1391
                private void readLoops(CadHatchTemplate template, int count)
UNCOV
1392
                {
×
UNCOV
1393
                        if (this._reader.Code == 91)
×
UNCOV
1394
                                this._reader.ReadNext();
×
1395

UNCOV
1396
                        for (int i = 0; i < count; i++)
×
UNCOV
1397
                        {
×
UNCOV
1398
                                if (this._reader.Code != 92)
×
1399
                                {
×
1400
                                        this._builder.Notify($"Boundary path should start with code 92 but was {this._reader.Code}");
×
1401
                                        break;
×
1402
                                }
1403

UNCOV
1404
                                CadHatchTemplate.CadBoundaryPathTemplate path = this.readLoop();
×
UNCOV
1405
                                if (path != null)
×
UNCOV
1406
                                        template.PathTempaltes.Add(path);
×
UNCOV
1407
                        }
×
UNCOV
1408
                }
×
1409

1410
                private CadHatchTemplate.CadBoundaryPathTemplate readLoop()
UNCOV
1411
                {
×
UNCOV
1412
                        CadHatchTemplate.CadBoundaryPathTemplate template = new CadHatchTemplate.CadBoundaryPathTemplate();
×
UNCOV
1413
                        var flags = (BoundaryPathFlags)this._reader.ValueAsInt;
×
UNCOV
1414
                        template.Path.Flags = flags;
×
1415

UNCOV
1416
                        if (flags.HasFlag(BoundaryPathFlags.Polyline))
×
UNCOV
1417
                        {
×
UNCOV
1418
                                Hatch.BoundaryPath.Polyline pl = this.readPolylineBoundary();
×
UNCOV
1419
                                template.Path.Edges.Add(pl);
×
UNCOV
1420
                        }
×
1421
                        else
UNCOV
1422
                        {
×
UNCOV
1423
                                this._reader.ReadNext();
×
1424

UNCOV
1425
                                if (this._reader.Code != 93)
×
1426
                                {
×
1427
                                        this._builder.Notify($"Edge Boundary path should start with code 93 but was {this._reader.Code}");
×
1428
                                        return null;
×
1429
                                }
1430

UNCOV
1431
                                int edges = this._reader.ValueAsInt;
×
UNCOV
1432
                                this._reader.ReadNext();
×
1433

UNCOV
1434
                                for (int i = 0; i < edges; i++)
×
UNCOV
1435
                                {
×
UNCOV
1436
                                        var edge = this.readEdge();
×
UNCOV
1437
                                        if (edge != null)
×
UNCOV
1438
                                                template.Path.Edges.Add(edge);
×
UNCOV
1439
                                }
×
UNCOV
1440
                        }
×
1441

UNCOV
1442
                        bool end = false;
×
UNCOV
1443
                        while (!end)
×
UNCOV
1444
                        {
×
UNCOV
1445
                                switch (this._reader.Code)
×
1446
                                {
1447
                                        //Number of source boundary objects
1448
                                        case 97:
UNCOV
1449
                                                break;
×
1450
                                        case 330:
UNCOV
1451
                                                template.Handles.Add(this._reader.ValueAsHandle);
×
UNCOV
1452
                                                break;
×
1453
                                        default:
UNCOV
1454
                                                end = true;
×
UNCOV
1455
                                                continue;
×
1456
                                }
1457

UNCOV
1458
                                this._reader.ReadNext();
×
UNCOV
1459
                        }
×
1460

UNCOV
1461
                        return template;
×
UNCOV
1462
                }
×
1463

1464
                private Hatch.BoundaryPath.Polyline readPolylineBoundary()
UNCOV
1465
                {
×
UNCOV
1466
                        Hatch.BoundaryPath.Polyline boundary = new Hatch.BoundaryPath.Polyline();
×
1467

UNCOV
1468
                        this._reader.ReadNext();
×
1469

UNCOV
1470
                        if (this._reader.Code != 72)
×
1471
                        {
×
1472
                                this._builder.Notify($"Polyline Boundary path should start with code 72 but was {this._reader.Code}");
×
1473
                                return null;
×
1474
                        }
1475

1476
                        //72
UNCOV
1477
                        bool hasBulge = this._reader.ValueAsBool;
×
UNCOV
1478
                        this._reader.ReadNext();
×
1479

1480
                        //73
UNCOV
1481
                        bool isClosed = this._reader.ValueAsBool;
×
UNCOV
1482
                        this._reader.ReadNext();
×
1483

1484
                        //93
UNCOV
1485
                        int nvertices = this._reader.ValueAsInt;
×
UNCOV
1486
                        this._reader.ReadNext();
×
1487

UNCOV
1488
                        for (int i = 0; i < nvertices; i++)
×
UNCOV
1489
                        {
×
UNCOV
1490
                                double bulge = 0.0;
×
1491

1492
                                //10
UNCOV
1493
                                double x = this._reader.ValueAsDouble;
×
UNCOV
1494
                                this._reader.ReadNext();
×
1495
                                //20
UNCOV
1496
                                double y = this._reader.ValueAsDouble;
×
UNCOV
1497
                                this._reader.ReadNext();
×
1498

UNCOV
1499
                                if (hasBulge)
×
1500
                                {
×
1501
                                        //42
1502
                                        bulge = this._reader.ValueAsDouble;
×
1503
                                        this._reader.ReadNext();
×
1504
                                }
×
1505

UNCOV
1506
                                boundary.Vertices.Add(new XYZ(x, y, bulge));
×
UNCOV
1507
                        }
×
1508

UNCOV
1509
                        return boundary;
×
UNCOV
1510
                }
×
1511

1512
                private Hatch.BoundaryPath.Edge readEdge()
UNCOV
1513
                {
×
UNCOV
1514
                        if (this._reader.Code != 72)
×
1515
                        {
×
1516
                                this._builder.Notify($"Edge Boundary path should define the type with code 72 but was {this._reader.Code}");
×
1517
                                return null;
×
1518
                        }
1519

UNCOV
1520
                        Hatch.BoundaryPath.EdgeType type = (Hatch.BoundaryPath.EdgeType)this._reader.ValueAsInt;
×
UNCOV
1521
                        this._reader.ReadNext();
×
1522

UNCOV
1523
                        switch (type)
×
1524
                        {
1525
                                case Hatch.BoundaryPath.EdgeType.Line:
UNCOV
1526
                                        Hatch.BoundaryPath.Line line = new Hatch.BoundaryPath.Line();
×
UNCOV
1527
                                        while (true)
×
UNCOV
1528
                                        {
×
UNCOV
1529
                                                switch (this._reader.Code)
×
1530
                                                {
1531
                                                        case 10:
UNCOV
1532
                                                                line.Start = new XY(this._reader.ValueAsDouble, line.Start.Y);
×
UNCOV
1533
                                                                break;
×
1534
                                                        case 20:
UNCOV
1535
                                                                line.Start = new XY(line.Start.X, this._reader.ValueAsDouble);
×
UNCOV
1536
                                                                break;
×
1537
                                                        case 11:
UNCOV
1538
                                                                line.End = new XY(this._reader.ValueAsDouble, line.End.Y);
×
UNCOV
1539
                                                                break;
×
1540
                                                        case 21:
UNCOV
1541
                                                                line.End = new XY(line.End.X, this._reader.ValueAsDouble);
×
UNCOV
1542
                                                                break;
×
1543
                                                        default:
UNCOV
1544
                                                                return line;
×
1545
                                                }
1546

UNCOV
1547
                                                this._reader.ReadNext();
×
UNCOV
1548
                                        }
×
1549
                                case Hatch.BoundaryPath.EdgeType.CircularArc:
1550
                                        Hatch.BoundaryPath.Arc arc = new Hatch.BoundaryPath.Arc();
×
1551
                                        while (true)
×
1552
                                        {
×
1553
                                                switch (this._reader.Code)
×
1554
                                                {
1555
                                                        case 10:
1556
                                                                arc.Center = new XY(this._reader.ValueAsDouble, arc.Center.Y);
×
1557
                                                                break;
×
1558
                                                        case 20:
1559
                                                                arc.Center = new XY(arc.Center.X, this._reader.ValueAsDouble);
×
1560
                                                                break;
×
1561
                                                        case 40:
1562
                                                                arc.Radius = this._reader.ValueAsDouble;
×
1563
                                                                break;
×
1564
                                                        case 50:
1565
                                                                arc.StartAngle = this._reader.ValueAsDouble;
×
1566
                                                                break;
×
1567
                                                        case 51:
1568
                                                                arc.EndAngle = this._reader.ValueAsDouble;
×
1569
                                                                break;
×
1570
                                                        case 73:
1571
                                                                arc.CounterClockWise = this._reader.ValueAsBool;
×
1572
                                                                break;
×
1573
                                                        default:
1574
                                                                return arc;
×
1575
                                                }
1576

1577
                                                this._reader.ReadNext();
×
1578
                                        }
×
1579
                                case Hatch.BoundaryPath.EdgeType.EllipticArc:
1580
                                        Hatch.BoundaryPath.Ellipse ellipse = new Hatch.BoundaryPath.Ellipse();
×
1581
                                        while (true)
×
1582
                                        {
×
1583
                                                switch (this._reader.Code)
×
1584
                                                {
1585
                                                        case 10:
1586
                                                                ellipse.Center = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1587
                                                                break;
×
1588
                                                        case 20:
1589
                                                                ellipse.Center = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1590
                                                                break;
×
1591
                                                        case 11:
1592
                                                                ellipse.MajorAxisEndPoint = new XY(this._reader.ValueAsDouble, ellipse.Center.Y);
×
1593
                                                                break;
×
1594
                                                        case 21:
1595
                                                                ellipse.MajorAxisEndPoint = new XY(ellipse.Center.X, this._reader.ValueAsDouble);
×
1596
                                                                break;
×
1597
                                                        case 40:
1598
                                                                ellipse.MinorToMajorRatio = this._reader.ValueAsDouble;
×
1599
                                                                break;
×
1600
                                                        case 50:
1601
                                                                ellipse.StartAngle = this._reader.ValueAsDouble;
×
1602
                                                                break;
×
1603
                                                        case 51:
1604
                                                                ellipse.EndAngle = this._reader.ValueAsDouble;
×
1605
                                                                break;
×
1606
                                                        case 73:
1607
                                                                ellipse.IsCounterclockwise = this._reader.ValueAsBool;
×
1608
                                                                break;
×
1609
                                                        default:
1610
                                                                return ellipse;
×
1611
                                                }
1612

1613
                                                this._reader.ReadNext();
×
1614
                                        }
×
1615
                                case Hatch.BoundaryPath.EdgeType.Spline:
1616
                                        Hatch.BoundaryPath.Spline spline = new Hatch.BoundaryPath.Spline();
×
1617
                                        int nKnots = 0;
×
1618
                                        int nCtrlPoints = 0;
×
1619
                                        int nFitPoints = 0;
×
1620

1621
                                        XYZ controlPoint = new XYZ();
×
1622
                                        XY fitPoint = new XY();
×
1623

1624
                                        while (true)
×
1625
                                        {
×
1626
                                                switch (this._reader.Code)
×
1627
                                                {
1628
                                                        case 10:
1629
                                                                controlPoint = new XYZ(this._reader.ValueAsDouble, 0, 1);
×
1630
                                                                break;
×
1631
                                                        case 20:
1632
                                                                controlPoint = new XYZ(controlPoint.X, this._reader.ValueAsDouble, controlPoint.Z);
×
1633
                                                                spline.ControlPoints.Add(controlPoint);
×
1634
                                                                break;
×
1635
                                                        case 11:
1636
                                                                fitPoint = new XY(this._reader.ValueAsDouble, 0);
×
1637
                                                                break;
×
1638
                                                        case 21:
1639
                                                                fitPoint = new XY(fitPoint.X, this._reader.ValueAsDouble);
×
1640
                                                                spline.FitPoints.Add(fitPoint);
×
1641
                                                                break;
×
1642
                                                        case 42:
1643
                                                                var last = spline.ControlPoints[spline.ControlPoints.Count - 1];
×
1644
                                                                spline.ControlPoints[spline.ControlPoints.Count - 1] = new XYZ(last.X, last.Y, this._reader.ValueAsDouble);
×
1645
                                                                break;
×
1646
                                                        case 12:
1647
                                                                spline.StartTangent = new XY(this._reader.ValueAsDouble, spline.StartTangent.Y);
×
1648
                                                                break;
×
1649
                                                        case 22:
1650
                                                                spline.StartTangent = new XY(spline.StartTangent.X, this._reader.ValueAsDouble);
×
1651
                                                                break;
×
1652
                                                        case 13:
1653
                                                                spline.EndTangent = new XY(this._reader.ValueAsDouble, spline.EndTangent.Y);
×
1654
                                                                break;
×
1655
                                                        case 23:
1656
                                                                spline.EndTangent = new XY(spline.EndTangent.X, this._reader.ValueAsDouble);
×
1657
                                                                break;
×
1658
                                                        case 94:
1659
                                                                spline.Degree = this._reader.ValueAsInt;
×
1660
                                                                break;
×
1661
                                                        case 73:
1662
                                                                spline.Rational = this._reader.ValueAsBool;
×
1663
                                                                break;
×
1664
                                                        case 74:
1665
                                                                spline.Periodic = this._reader.ValueAsBool;
×
1666
                                                                break;
×
1667
                                                        case 95:
1668
                                                                nKnots = this._reader.ValueAsInt;
×
1669
                                                                break;
×
1670
                                                        case 96:
1671
                                                                nCtrlPoints = this._reader.ValueAsInt;
×
1672
                                                                break;
×
1673
                                                        case 97:
1674
                                                                nFitPoints = this._reader.ValueAsInt;
×
1675
                                                                break;
×
1676
                                                        case 40:
1677
                                                                spline.Knots.Add(this._reader.ValueAsDouble);
×
1678
                                                                break;
×
1679
                                                        default:
1680
                                                                return spline;
×
1681
                                                }
1682

1683
                                                this._reader.ReadNext();
×
1684
                                        }
×
1685
                        }
1686

1687
                        return null;
×
UNCOV
1688
                }
×
1689

1690
                private void readDefinedGroups(CadTemplate template)
UNCOV
1691
                {
×
UNCOV
1692
                        this.readDefinedGroups(out ulong? xdict, out HashSet<ulong> reactorsHandles);
×
1693

UNCOV
1694
                        template.XDictHandle = xdict;
×
UNCOV
1695
                        template.ReactorsHandles.UnionWith(reactorsHandles);
×
UNCOV
1696
                }
×
1697

1698
                private void readDefinedGroups(out ulong? xdictHandle, out HashSet<ulong> reactors)
UNCOV
1699
                {
×
UNCOV
1700
                        xdictHandle = null;
×
UNCOV
1701
                        reactors = new HashSet<ulong>();
×
1702

UNCOV
1703
                        switch (this._reader.ValueAsString)
×
1704
                        {
1705
                                case DxfFileToken.DictionaryToken:
UNCOV
1706
                                        this._reader.ReadNext();
×
UNCOV
1707
                                        xdictHandle = this._reader.ValueAsHandle;
×
UNCOV
1708
                                        this._reader.ReadNext();
×
UNCOV
1709
                                        Debug.Assert(this._reader.DxfCode == DxfCode.ControlString);
×
UNCOV
1710
                                        return;
×
1711
                                case DxfFileToken.ReactorsToken:
UNCOV
1712
                                        reactors = this.readReactors();
×
UNCOV
1713
                                        break;
×
1714
                                case DxfFileToken.BlkRefToken:
1715
                                default:
1716
                                        do
UNCOV
1717
                                        {
×
UNCOV
1718
                                                this._reader.ReadNext();
×
UNCOV
1719
                                        }
×
UNCOV
1720
                                        while (this._reader.DxfCode != DxfCode.ControlString);
×
UNCOV
1721
                                        return;
×
1722
                        }
UNCOV
1723
                }
×
1724

1725
                private HashSet<ulong> readReactors()
UNCOV
1726
                {
×
UNCOV
1727
                        HashSet<ulong> reactors = new();
×
1728

UNCOV
1729
                        this._reader.ReadNext();
×
1730

UNCOV
1731
                        while (this._reader.DxfCode != DxfCode.ControlString)
×
UNCOV
1732
                        {
×
UNCOV
1733
                                this._reader.ReadNext();
×
UNCOV
1734
                        }
×
1735

UNCOV
1736
                        return reactors;
×
UNCOV
1737
                }
×
1738

1739
                protected bool tryAssignCurrentValue(CadObject cadObject, DxfClassMap map)
UNCOV
1740
                {
×
1741
                        try
UNCOV
1742
                        {
×
1743
                                //Use this method only if the value is not a link between objects
UNCOV
1744
                                if (map.DxfProperties.TryGetValue(this._reader.Code, out DxfProperty dxfProperty))
×
UNCOV
1745
                                {
×
UNCOV
1746
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Count))
×
UNCOV
1747
                                        {
×
UNCOV
1748
                                                return true;
×
1749
                                        }
1750

UNCOV
1751
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Handle)
×
UNCOV
1752
                                                || dxfProperty.ReferenceType.HasFlag(DxfReferenceType.Name))
×
UNCOV
1753
                                        {
×
UNCOV
1754
                                                return false;
×
1755
                                        }
1756

UNCOV
1757
                                        object value = this._reader.Value;
×
1758

UNCOV
1759
                                        if (dxfProperty.ReferenceType.HasFlag(DxfReferenceType.IsAngle))
×
UNCOV
1760
                                        {
×
UNCOV
1761
                                                value = MathHelper.DegToRad((double)value);
×
UNCOV
1762
                                        }
×
1763

UNCOV
1764
                                        dxfProperty.SetValue(this._reader.Code, cadObject, value);
×
1765

UNCOV
1766
                                        return true;
×
1767
                                }
UNCOV
1768
                        }
×
1769
                        catch (Exception ex)
×
1770
                        {
×
1771
                                if (!this._builder.Configuration.Failsafe)
×
1772
                                {
×
1773
                                        throw ex;
×
1774
                                }
1775
                                else
1776
                                {
×
1777
                                        this._builder.Notify("An error occurred while assigning a property using mapper", NotificationType.Error, ex);
×
1778
                                }
×
1779
                        }
×
1780

UNCOV
1781
                        return false;
×
UNCOV
1782
                }
×
1783
        }
1784
}
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